Loading libs/binder/ndk/include_platform/android/binder_manager.h +2 −2 Original line number Diff line number Diff line Loading @@ -29,9 +29,9 @@ __BEGIN_DECLS * \param binder object to register globally with the service manager. * \param instance identifier of the service. This will be used to lookup the service. * * \return STATUS_OK on success. * \return EX_NONE on success. */ binder_status_t AServiceManager_addService(AIBinder* binder, const char* instance); binder_exception_t AServiceManager_addService(AIBinder* binder, const char* instance); /** * Gets a binder object with this specific instance name. Will return nullptr immediately if the Loading libs/binder/ndk/service_manager.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -29,14 +29,14 @@ using ::android::sp; using ::android::status_t; using ::android::String16; binder_status_t AServiceManager_addService(AIBinder* binder, const char* instance) { binder_exception_t AServiceManager_addService(AIBinder* binder, const char* instance) { if (binder == nullptr || instance == nullptr) { return STATUS_UNEXPECTED_NULL; return EX_ILLEGAL_ARGUMENT; } sp<IServiceManager> sm = defaultServiceManager(); status_t status = sm->addService(String16(instance), binder->getBinder()); return PruneStatusT(status); status_t exception = sm->addService(String16(instance), binder->getBinder()); return PruneException(exception); } AIBinder* AServiceManager_checkService(const char* instance) { if (instance == nullptr) { Loading libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp +19 −9 Original line number Diff line number Diff line Loading @@ -84,10 +84,11 @@ int generatedService() { AIBinder_setRequestingSid(binder.get(), true); binder_status_t status = AServiceManager_addService(binder.get(), kBinderNdkUnitTestService); binder_exception_t exception = AServiceManager_addService(binder.get(), kBinderNdkUnitTestService); if (status != STATUS_OK) { LOG(FATAL) << "Could not register: " << status << " " << kBinderNdkUnitTestService; if (exception != EX_NONE) { LOG(FATAL) << "Could not register: " << exception << " " << kBinderNdkUnitTestService; } ABinderProcess_joinThreadPool(); Loading @@ -111,10 +112,10 @@ class MyFoo : public IFoo { void manualService(const char* instance) { // Strong reference to MyFoo kept by service manager. binder_status_t status = (new MyFoo)->addService(instance); binder_exception_t exception = (new MyFoo)->addService(instance); if (status != STATUS_OK) { LOG(FATAL) << "Could not register: " << status << " " << instance; if (exception != EX_NONE) { LOG(FATAL) << "Could not register: " << exception << " " << instance; } } int manualPollingService(const char* instance) { Loading Loading @@ -322,11 +323,20 @@ class MyTestFoo : public IFoo { } }; TEST(NdkBinder, AddNullService) { EXPECT_EQ(EX_ILLEGAL_ARGUMENT, AServiceManager_addService(nullptr, "any-service-name")); } TEST(NdkBinder, AddInvalidServiceName) { sp<IFoo> foo = new MyTestFoo; EXPECT_EQ(EX_ILLEGAL_ARGUMENT, foo->addService("!@#$%^&")); } TEST(NdkBinder, GetServiceInProcess) { static const char* kInstanceName = "test-get-service-in-process"; sp<IFoo> foo = new MyTestFoo; EXPECT_EQ(STATUS_OK, foo->addService(kInstanceName)); EXPECT_EQ(EX_NONE, foo->addService(kInstanceName)); sp<IFoo> getFoo = IFoo::getService(kInstanceName); EXPECT_EQ(foo.get(), getFoo.get()); Loading Loading @@ -373,8 +383,8 @@ TEST(NdkBinder, AddServiceMultipleTimes) { static const char* kInstanceName1 = "test-multi-1"; static const char* kInstanceName2 = "test-multi-2"; sp<IFoo> foo = new MyTestFoo; EXPECT_EQ(STATUS_OK, foo->addService(kInstanceName1)); EXPECT_EQ(STATUS_OK, foo->addService(kInstanceName2)); EXPECT_EQ(EX_NONE, foo->addService(kInstanceName1)); EXPECT_EQ(EX_NONE, foo->addService(kInstanceName2)); EXPECT_EQ(IFoo::getService(kInstanceName1), IFoo::getService(kInstanceName2)); } Loading Loading
libs/binder/ndk/include_platform/android/binder_manager.h +2 −2 Original line number Diff line number Diff line Loading @@ -29,9 +29,9 @@ __BEGIN_DECLS * \param binder object to register globally with the service manager. * \param instance identifier of the service. This will be used to lookup the service. * * \return STATUS_OK on success. * \return EX_NONE on success. */ binder_status_t AServiceManager_addService(AIBinder* binder, const char* instance); binder_exception_t AServiceManager_addService(AIBinder* binder, const char* instance); /** * Gets a binder object with this specific instance name. Will return nullptr immediately if the Loading
libs/binder/ndk/service_manager.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -29,14 +29,14 @@ using ::android::sp; using ::android::status_t; using ::android::String16; binder_status_t AServiceManager_addService(AIBinder* binder, const char* instance) { binder_exception_t AServiceManager_addService(AIBinder* binder, const char* instance) { if (binder == nullptr || instance == nullptr) { return STATUS_UNEXPECTED_NULL; return EX_ILLEGAL_ARGUMENT; } sp<IServiceManager> sm = defaultServiceManager(); status_t status = sm->addService(String16(instance), binder->getBinder()); return PruneStatusT(status); status_t exception = sm->addService(String16(instance), binder->getBinder()); return PruneException(exception); } AIBinder* AServiceManager_checkService(const char* instance) { if (instance == nullptr) { Loading
libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp +19 −9 Original line number Diff line number Diff line Loading @@ -84,10 +84,11 @@ int generatedService() { AIBinder_setRequestingSid(binder.get(), true); binder_status_t status = AServiceManager_addService(binder.get(), kBinderNdkUnitTestService); binder_exception_t exception = AServiceManager_addService(binder.get(), kBinderNdkUnitTestService); if (status != STATUS_OK) { LOG(FATAL) << "Could not register: " << status << " " << kBinderNdkUnitTestService; if (exception != EX_NONE) { LOG(FATAL) << "Could not register: " << exception << " " << kBinderNdkUnitTestService; } ABinderProcess_joinThreadPool(); Loading @@ -111,10 +112,10 @@ class MyFoo : public IFoo { void manualService(const char* instance) { // Strong reference to MyFoo kept by service manager. binder_status_t status = (new MyFoo)->addService(instance); binder_exception_t exception = (new MyFoo)->addService(instance); if (status != STATUS_OK) { LOG(FATAL) << "Could not register: " << status << " " << instance; if (exception != EX_NONE) { LOG(FATAL) << "Could not register: " << exception << " " << instance; } } int manualPollingService(const char* instance) { Loading Loading @@ -322,11 +323,20 @@ class MyTestFoo : public IFoo { } }; TEST(NdkBinder, AddNullService) { EXPECT_EQ(EX_ILLEGAL_ARGUMENT, AServiceManager_addService(nullptr, "any-service-name")); } TEST(NdkBinder, AddInvalidServiceName) { sp<IFoo> foo = new MyTestFoo; EXPECT_EQ(EX_ILLEGAL_ARGUMENT, foo->addService("!@#$%^&")); } TEST(NdkBinder, GetServiceInProcess) { static const char* kInstanceName = "test-get-service-in-process"; sp<IFoo> foo = new MyTestFoo; EXPECT_EQ(STATUS_OK, foo->addService(kInstanceName)); EXPECT_EQ(EX_NONE, foo->addService(kInstanceName)); sp<IFoo> getFoo = IFoo::getService(kInstanceName); EXPECT_EQ(foo.get(), getFoo.get()); Loading Loading @@ -373,8 +383,8 @@ TEST(NdkBinder, AddServiceMultipleTimes) { static const char* kInstanceName1 = "test-multi-1"; static const char* kInstanceName2 = "test-multi-2"; sp<IFoo> foo = new MyTestFoo; EXPECT_EQ(STATUS_OK, foo->addService(kInstanceName1)); EXPECT_EQ(STATUS_OK, foo->addService(kInstanceName2)); EXPECT_EQ(EX_NONE, foo->addService(kInstanceName1)); EXPECT_EQ(EX_NONE, foo->addService(kInstanceName2)); EXPECT_EQ(IFoo::getService(kInstanceName1), IFoo::getService(kInstanceName2)); } Loading