Loading libs/binder/ndk/include_apex/android/binder_manager.h +9 −0 Original line number Original line Diff line number Diff line Loading @@ -32,6 +32,15 @@ __BEGIN_DECLS */ */ binder_status_t AServiceManager_addService(AIBinder* binder, const char* instance); binder_status_t AServiceManager_addService(AIBinder* binder, const char* instance); /** * Gets a binder object with this specific instance name. Will return nullptr immediately if the * service is not available This also implicitly calls AIBinder_incStrong (so the caller of this * function is responsible for calling AIBinder_decStrong). * * \param instance identifier of the service used to lookup the service. */ __attribute__((warn_unused_result)) AIBinder* AServiceManager_checkService(const char* instance); /** /** * Gets a binder object with this specific instance name. Blocks for a couple of seconds waiting on * Gets a binder object with this specific instance name. Blocks for a couple of seconds waiting on * it. This also implicitly calls AIBinder_incStrong (so the caller of this function is responsible * it. This also implicitly calls AIBinder_incStrong (so the caller of this function is responsible Loading libs/binder/ndk/libbinder_ndk.map.txt +1 −0 Original line number Original line Diff line number Diff line Loading @@ -91,6 +91,7 @@ LIBBINDER_NDK { # introduced=29 ABinderProcess_setThreadPoolMaxThreadCount; # apex ABinderProcess_setThreadPoolMaxThreadCount; # apex ABinderProcess_startThreadPool; # apex ABinderProcess_startThreadPool; # apex AServiceManager_addService; # apex AServiceManager_addService; # apex AServiceManager_checkService; # apex AServiceManager_getService; # apex AServiceManager_getService; # apex local: local: *; *; Loading libs/binder/ndk/service_manager.cpp +12 −0 Original line number Original line Diff line number Diff line Loading @@ -37,6 +37,18 @@ binder_status_t AServiceManager_addService(AIBinder* binder, const char* instanc status_t status = sm->addService(String16(instance), binder->getBinder()); status_t status = sm->addService(String16(instance), binder->getBinder()); return PruneStatusT(status); return PruneStatusT(status); } } AIBinder* AServiceManager_checkService(const char* instance) { if (instance == nullptr) { return nullptr; } sp<IServiceManager> sm = defaultServiceManager(); sp<IBinder> binder = sm->checkService(String16(instance)); sp<AIBinder> ret = ABpBinder::lookupOrCreateFromBinder(binder); AIBinder_incStrong(ret.get()); return ret.get(); } AIBinder* AServiceManager_getService(const char* instance) { AIBinder* AServiceManager_getService(const char* instance) { if (instance == nullptr) { if (instance == nullptr) { return nullptr; return nullptr; Loading libs/binder/ndk/test/main_client.cpp +13 −0 Original line number Original line Diff line number Diff line Loading @@ -35,6 +35,19 @@ constexpr char kExistingNonNdkService[] = "SurfaceFlinger"; // EXPECT_EQ(nullptr, foo.get()); // EXPECT_EQ(nullptr, foo.get()); // } // } TEST(NdkBinder, CheckServiceThatDoesntExist) { AIBinder* binder = AServiceManager_checkService("asdfghkl;"); ASSERT_EQ(nullptr, binder); } TEST(NdkBinder, CheckServiceThatDoesExist) { AIBinder* binder = AServiceManager_checkService(kExistingNonNdkService); EXPECT_NE(nullptr, binder); EXPECT_EQ(STATUS_OK, AIBinder_ping(binder)); AIBinder_decStrong(binder); } TEST(NdkBinder, DoubleNumber) { TEST(NdkBinder, DoubleNumber) { sp<IFoo> foo = IFoo::getService(IFoo::kSomeInstanceName); sp<IFoo> foo = IFoo::getService(IFoo::kSomeInstanceName); ASSERT_NE(foo, nullptr); ASSERT_NE(foo, nullptr); Loading Loading
libs/binder/ndk/include_apex/android/binder_manager.h +9 −0 Original line number Original line Diff line number Diff line Loading @@ -32,6 +32,15 @@ __BEGIN_DECLS */ */ binder_status_t AServiceManager_addService(AIBinder* binder, const char* instance); binder_status_t AServiceManager_addService(AIBinder* binder, const char* instance); /** * Gets a binder object with this specific instance name. Will return nullptr immediately if the * service is not available This also implicitly calls AIBinder_incStrong (so the caller of this * function is responsible for calling AIBinder_decStrong). * * \param instance identifier of the service used to lookup the service. */ __attribute__((warn_unused_result)) AIBinder* AServiceManager_checkService(const char* instance); /** /** * Gets a binder object with this specific instance name. Blocks for a couple of seconds waiting on * Gets a binder object with this specific instance name. Blocks for a couple of seconds waiting on * it. This also implicitly calls AIBinder_incStrong (so the caller of this function is responsible * it. This also implicitly calls AIBinder_incStrong (so the caller of this function is responsible Loading
libs/binder/ndk/libbinder_ndk.map.txt +1 −0 Original line number Original line Diff line number Diff line Loading @@ -91,6 +91,7 @@ LIBBINDER_NDK { # introduced=29 ABinderProcess_setThreadPoolMaxThreadCount; # apex ABinderProcess_setThreadPoolMaxThreadCount; # apex ABinderProcess_startThreadPool; # apex ABinderProcess_startThreadPool; # apex AServiceManager_addService; # apex AServiceManager_addService; # apex AServiceManager_checkService; # apex AServiceManager_getService; # apex AServiceManager_getService; # apex local: local: *; *; Loading
libs/binder/ndk/service_manager.cpp +12 −0 Original line number Original line Diff line number Diff line Loading @@ -37,6 +37,18 @@ binder_status_t AServiceManager_addService(AIBinder* binder, const char* instanc status_t status = sm->addService(String16(instance), binder->getBinder()); status_t status = sm->addService(String16(instance), binder->getBinder()); return PruneStatusT(status); return PruneStatusT(status); } } AIBinder* AServiceManager_checkService(const char* instance) { if (instance == nullptr) { return nullptr; } sp<IServiceManager> sm = defaultServiceManager(); sp<IBinder> binder = sm->checkService(String16(instance)); sp<AIBinder> ret = ABpBinder::lookupOrCreateFromBinder(binder); AIBinder_incStrong(ret.get()); return ret.get(); } AIBinder* AServiceManager_getService(const char* instance) { AIBinder* AServiceManager_getService(const char* instance) { if (instance == nullptr) { if (instance == nullptr) { return nullptr; return nullptr; Loading
libs/binder/ndk/test/main_client.cpp +13 −0 Original line number Original line Diff line number Diff line Loading @@ -35,6 +35,19 @@ constexpr char kExistingNonNdkService[] = "SurfaceFlinger"; // EXPECT_EQ(nullptr, foo.get()); // EXPECT_EQ(nullptr, foo.get()); // } // } TEST(NdkBinder, CheckServiceThatDoesntExist) { AIBinder* binder = AServiceManager_checkService("asdfghkl;"); ASSERT_EQ(nullptr, binder); } TEST(NdkBinder, CheckServiceThatDoesExist) { AIBinder* binder = AServiceManager_checkService(kExistingNonNdkService); EXPECT_NE(nullptr, binder); EXPECT_EQ(STATUS_OK, AIBinder_ping(binder)); AIBinder_decStrong(binder); } TEST(NdkBinder, DoubleNumber) { TEST(NdkBinder, DoubleNumber) { sp<IFoo> foo = IFoo::getService(IFoo::kSomeInstanceName); sp<IFoo> foo = IFoo::getService(IFoo::kSomeInstanceName); ASSERT_NE(foo, nullptr); ASSERT_NE(foo, nullptr); Loading