diff options
| author | 2022-10-05 18:09:56 +0000 | |
|---|---|---|
| committer | 2022-10-05 18:09:56 +0000 | |
| commit | 0f9f9e574ee3d95e8c068d80f756753927f67094 (patch) | |
| tree | ba11a9026f72a5bd4935a58f10d026748d84cf59 | |
| parent | 9380acff0760365494674595396cd79c66d069b7 (diff) | |
| parent | 376193980c30425462ce999641d5c4509e92fb17 (diff) | |
Merge "Make ScopedAIBinder_Weak::promote() a const function." am: 376193980c
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2239069
Change-Id: Ia0ddfa1ee87744c19e7f5a4e8295027a8bab3d77
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | libs/binder/ndk/include_cpp/android/binder_auto_utils.h | 2 | ||||
| -rw-r--r-- | libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp | 20 |
2 files changed, 21 insertions, 1 deletions
diff --git a/libs/binder/ndk/include_cpp/android/binder_auto_utils.h b/libs/binder/ndk/include_cpp/android/binder_auto_utils.h index 7ea9be797b..fccc0afa89 100644 --- a/libs/binder/ndk/include_cpp/android/binder_auto_utils.h +++ b/libs/binder/ndk/include_cpp/android/binder_auto_utils.h @@ -349,7 +349,7 @@ class ScopedAIBinder_Weak /** * See AIBinder_Weak_promote. */ - SpAIBinder promote() { return SpAIBinder(AIBinder_Weak_promote(get())); } + SpAIBinder promote() const { return SpAIBinder(AIBinder_Weak_promote(get())); } }; namespace internal { diff --git a/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp b/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp index 6d29238758..01b94721b2 100644 --- a/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp +++ b/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp @@ -670,6 +670,26 @@ TEST(NdkBinder, ConvertToPlatformParcel) { EXPECT_EQ(42, pparcel->readInt32()); } +TEST(NdkBinder, GetAndVerifyScopedAIBinder_Weak) { + for (const ndk::SpAIBinder& binder : + {// remote + ndk::SpAIBinder(AServiceManager_getService(kBinderNdkUnitTestService)), + // local + ndk::SharedRefBase::make<MyBinderNdkUnitTest>()->asBinder()}) { + // get a const ScopedAIBinder_Weak and verify promote + EXPECT_NE(binder.get(), nullptr); + const ndk::ScopedAIBinder_Weak wkAIBinder = + ndk::ScopedAIBinder_Weak(AIBinder_Weak_new(binder.get())); + EXPECT_EQ(wkAIBinder.promote().get(), binder.get()); + // get another ScopedAIBinder_Weak and verify + ndk::ScopedAIBinder_Weak wkAIBinder2 = + ndk::ScopedAIBinder_Weak(AIBinder_Weak_new(binder.get())); + EXPECT_FALSE(AIBinder_Weak_lt(wkAIBinder.get(), wkAIBinder2.get())); + EXPECT_FALSE(AIBinder_Weak_lt(wkAIBinder2.get(), wkAIBinder.get())); + EXPECT_EQ(wkAIBinder2.promote(), wkAIBinder.promote()); + } +} + class MyResultReceiver : public BnResultReceiver { public: Mutex mMutex; |