Loading libs/binder/ndk/include_cpp/android/binder_interface_utils.h +6 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,12 @@ class SharedRefBase { std::call_once(mFlagThis, [&]() { __assert(__FILE__, __LINE__, "SharedRefBase: no ref created during lifetime"); }); if (ref() != nullptr) { __assert(__FILE__, __LINE__, "SharedRefBase: destructed but still able to lock weak_ptr. Is this object " "double-owned?"); } } /** Loading libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -224,6 +224,17 @@ bool isServiceRunning(const char* serviceName) { return true; } TEST(NdkBinder, DetectDoubleOwn) { auto badService = ndk::SharedRefBase::make<MyBinderNdkUnitTest>(); EXPECT_DEATH(std::shared_ptr<MyBinderNdkUnitTest>(badService.get()), "Is this object double-owned?"); } TEST(NdkBinder, DetectNoSharedRefBaseCreated) { EXPECT_DEATH(std::make_shared<MyBinderNdkUnitTest>(), "SharedRefBase: no ref created during lifetime"); } TEST(NdkBinder, GetServiceThatDoesntExist) { sp<IFoo> foo = IFoo::getService("asdfghkl;"); EXPECT_EQ(nullptr, foo.get()); Loading Loading
libs/binder/ndk/include_cpp/android/binder_interface_utils.h +6 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,12 @@ class SharedRefBase { std::call_once(mFlagThis, [&]() { __assert(__FILE__, __LINE__, "SharedRefBase: no ref created during lifetime"); }); if (ref() != nullptr) { __assert(__FILE__, __LINE__, "SharedRefBase: destructed but still able to lock weak_ptr. Is this object " "double-owned?"); } } /** Loading
libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -224,6 +224,17 @@ bool isServiceRunning(const char* serviceName) { return true; } TEST(NdkBinder, DetectDoubleOwn) { auto badService = ndk::SharedRefBase::make<MyBinderNdkUnitTest>(); EXPECT_DEATH(std::shared_ptr<MyBinderNdkUnitTest>(badService.get()), "Is this object double-owned?"); } TEST(NdkBinder, DetectNoSharedRefBaseCreated) { EXPECT_DEATH(std::make_shared<MyBinderNdkUnitTest>(), "SharedRefBase: no ref created during lifetime"); } TEST(NdkBinder, GetServiceThatDoesntExist) { sp<IFoo> foo = IFoo::getService("asdfghkl;"); EXPECT_EQ(nullptr, foo.get()); Loading