Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit db40a751 authored by Steven Moreland's avatar Steven Moreland Committed by android-build-merger
Browse files

Merge "libbinder_ndk: AServiceManager_checkService # apex"

am: 7d3f8168

Change-Id: I13c6895098e3ed908563207860dbe304c63ee681
parents c67192a5 7d3f8168
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -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
+1 −0
Original line number Original line Diff line number Diff line
@@ -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:
    *;
    *;
+12 −0
Original line number Original line Diff line number Diff line
@@ -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;
+13 −0
Original line number Original line Diff line number Diff line
@@ -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);