diff options
| author | 2022-10-05 18:40:33 +0000 | |
|---|---|---|
| committer | 2022-10-05 18:40:33 +0000 | |
| commit | 0730e4ceb670dfa0ea5974e213b087a10ca3c81c (patch) | |
| tree | e5bdc0341fb0caca89f04dfa3ca0bb87c555f489 | |
| parent | e959092df998d71b06b128e60e1bd05467515adf (diff) | |
| parent | 0f9f9e574ee3d95e8c068d80f756753927f67094 (diff) | |
Merge "Make ScopedAIBinder_Weak::promote() a const function." am: 376193980c am: 0f9f9e574e
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2239069
Change-Id: I422778cc0b40f706b6023643c57faf9f1aafc685
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; |