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

Commit e9cc9005 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6758226 from b0527022 to rvc-qpr1-release

Change-Id: I75f4f5df44b51b4942c3d3d9c88ed597db4a060c
parents 734e65ad b0527022
Loading
Loading
Loading
Loading
+4 −3
Original line number Original line Diff line number Diff line
@@ -213,17 +213,18 @@ Status ServiceManager::addService(const std::string& name, const sp<IBinder>& bi
        return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE);
        return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE);
    }
    }


    auto entry = mNameToService.emplace(name, Service {
    // Overwrite the old service if it exists
    mNameToService[name] = Service {
        .binder = binder,
        .binder = binder,
        .allowIsolated = allowIsolated,
        .allowIsolated = allowIsolated,
        .dumpPriority = dumpPriority,
        .dumpPriority = dumpPriority,
        .debugPid = ctx.debugPid,
        .debugPid = ctx.debugPid,
    });
    };


    auto it = mNameToRegistrationCallback.find(name);
    auto it = mNameToRegistrationCallback.find(name);
    if (it != mNameToRegistrationCallback.end()) {
    if (it != mNameToRegistrationCallback.end()) {
        for (const sp<IServiceCallback>& cb : it->second) {
        for (const sp<IServiceCallback>& cb : it->second) {
            entry.first->second.guaranteeClient = true;
            mNameToService[name].guaranteeClient = true;
            // permission checked in registerForNotifications
            // permission checked in registerForNotifications
            cb->onRegistration(name, binder);
            cb->onRegistration(name, binder);
        }
        }
+20 −0
Original line number Original line Diff line number Diff line
@@ -135,6 +135,26 @@ TEST(AddService, HappyOverExistingService) {
        IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk());
        IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk());
}
}


TEST(AddService, OverwriteExistingService) {
    auto sm = getPermissiveServiceManager();
    sp<IBinder> serviceA = getBinder();
    EXPECT_TRUE(sm->addService("foo", serviceA, false /*allowIsolated*/,
        IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk());

    sp<IBinder> outA;
    EXPECT_TRUE(sm->getService("foo", &outA).isOk());
    EXPECT_EQ(serviceA, outA);

    // serviceA should be overwritten by serviceB
    sp<IBinder> serviceB = getBinder();
    EXPECT_TRUE(sm->addService("foo", serviceB, false /*allowIsolated*/,
        IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk());

    sp<IBinder> outB;
    EXPECT_TRUE(sm->getService("foo", &outB).isOk());
    EXPECT_EQ(serviceB, outB);
}

TEST(AddService, NoPermissions) {
TEST(AddService, NoPermissions) {
    std::unique_ptr<MockAccess> access = std::make_unique<NiceMock<MockAccess>>();
    std::unique_ptr<MockAccess> access = std::make_unique<NiceMock<MockAccess>>();