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

Commit 4329742a authored by Steven Moreland's avatar Steven Moreland Committed by Automerger Merge Worker
Browse files

Merge "libbinder_ndk: fix addService return type" am: 1baf5535

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1416242

Change-Id: I8fa93a0e612ee0a2f45d8877f3c6e78fef1bf1bf
parents 9d078232 1baf5535
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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
+4 −4
Original line number Diff line number Diff line
@@ -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) {
+19 −9
Original line number Diff line number Diff line
@@ -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();
@@ -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) {
@@ -302,11 +303,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());
@@ -353,8 +363,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));
}