From 2988f3a1fe956f344dd5c1d76642e0806c036a5e Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Wed, 6 Jul 2022 21:12:12 +0000 Subject: [PATCH] example vibrator for createBinder We don't have a good place to document how to deal with AIDL-generated code yet. Adding an example here so we have one visible on AOSP. Bug: 235448283 Test: builds Change-Id: I719cc06a890402204f476a01180ce4120c60a22c --- tests/extension/vibrator/aidl/default/CustomVibrator.cpp | 8 ++++++++ tests/extension/vibrator/aidl/default/CustomVibrator.h | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/tests/extension/vibrator/aidl/default/CustomVibrator.cpp b/tests/extension/vibrator/aidl/default/CustomVibrator.cpp index 2f3dfcb27f..7a7c58bc9d 100644 --- a/tests/extension/vibrator/aidl/default/CustomVibrator.cpp +++ b/tests/extension/vibrator/aidl/default/CustomVibrator.cpp @@ -57,4 +57,12 @@ ndk::ScopedAStatus CustomVibrator::perform(VendorEffect effect, return ndk::ScopedAStatus::ok(); } +ndk::SpAIBinder CustomVibrator::createBinder() { + auto binder = BnCustomVibrator::createBinder(); + // e.g. AIBinder_setInheritRt(binder.get(), true); + // e.g. AIBinder_setMinSchedulerPolicy(binder.get(), SCHED_NORMAL, 20); + // e.g. AIBinder_setRequestingSid(binder.get(), true); + return binder; +} + } // namespace aidl::android::hardware::tests::extension::vibrator diff --git a/tests/extension/vibrator/aidl/default/CustomVibrator.h b/tests/extension/vibrator/aidl/default/CustomVibrator.h index 6dc57439f5..084a5579cc 100644 --- a/tests/extension/vibrator/aidl/default/CustomVibrator.h +++ b/tests/extension/vibrator/aidl/default/CustomVibrator.h @@ -29,6 +29,12 @@ class CustomVibrator : public BnCustomVibrator { ndk::ScopedAStatus perform(VendorEffect effect, const std::shared_ptr& callback, int32_t* _aidl_return) override; + + private: + // override for AIBinder_setInheritRt, AIBinder_setMinSchedulerPolicy, or + // AIBinder_setRequestingSid calling this in the constructor or elsewhere, the binder would + // immediately be destroyed. + ndk::SpAIBinder createBinder() override; }; } // namespace aidl::android::hardware::tests::extension::vibrator