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

Commit 87a06b7f authored by Alice Wang's avatar Alice Wang Committed by Gerrit Code Review
Browse files

Merge "[native] Restore ServiceManager#checkService() to return IBinder" into main

parents 4ac78a18 2b61344d
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -410,7 +410,16 @@ Status ServiceManager::getService2(const std::string& name, os::Service* outServ
    return Status::ok();
}

Status ServiceManager::checkService(const std::string& name, os::Service* outService) {
Status ServiceManager::checkService(const std::string& name, sp<IBinder>* outBinder) {
    SM_PERFETTO_TRACE_FUNC(PERFETTO_TE_PROTO_FIELDS(
            PERFETTO_TE_PROTO_FIELD_CSTR(kProtoServiceName, name.c_str())));

    *outBinder = tryGetBinder(name, false).service;
    // returns ok regardless of result for legacy reasons
    return Status::ok();
}

Status ServiceManager::checkService2(const std::string& name, os::Service* outService) {
    SM_PERFETTO_TRACE_FUNC(PERFETTO_TE_PROTO_FIELDS(
            PERFETTO_TE_PROTO_FIELD_CSTR(kProtoServiceName, name.c_str())));

+2 −1
Original line number Diff line number Diff line
@@ -46,7 +46,8 @@ public:
    // getService will try to start any services it cannot find
    binder::Status getService(const std::string& name, sp<IBinder>* outBinder) override;
    binder::Status getService2(const std::string& name, os::Service* outService) override;
    binder::Status checkService(const std::string& name, os::Service* outService) override;
    binder::Status checkService(const std::string& name, sp<IBinder>* outBinder) override;
    binder::Status checkService2(const std::string& name, os::Service* outService) override;
    binder::Status addService(const std::string& name, const sp<IBinder>& binder,
                              bool allowIsolated, int32_t dumpPriority) override;
    binder::Status listServices(int32_t dumpPriority, std::vector<std::string>* outList) override;
+5 −0
Original line number Diff line number Diff line
@@ -204,6 +204,11 @@ TEST(GetService, HappyHappy) {
    sp<IBinder> outBinder;
    EXPECT_TRUE(sm->getService("foo", &outBinder).isOk());
    EXPECT_EQ(service, outBinder);

    EXPECT_TRUE(sm->checkService2("foo", &out).isOk());
    EXPECT_EQ(service, out.get<Service::Tag::serviceWithMetadata>().service);
    EXPECT_TRUE(sm->checkService("foo", &outBinder).isOk());
    EXPECT_EQ(service, outBinder);
}

TEST(GetService, NonExistant) {
+12 −2
Original line number Diff line number Diff line
@@ -238,7 +238,17 @@ Status BackendUnifiedServiceManager::getService2(const ::std::string& name, os::
    return status;
}

Status BackendUnifiedServiceManager::checkService(const ::std::string& name, os::Service* _out) {
Status BackendUnifiedServiceManager::checkService(const ::std::string& name,
                                                  sp<IBinder>* _aidl_return) {
    os::Service service;
    Status status = checkService2(name, &service);
    if (status.isOk()) {
        *_aidl_return = service.get<os::Service::Tag::serviceWithMetadata>().service;
    }
    return status;
}

Status BackendUnifiedServiceManager::checkService2(const ::std::string& name, os::Service* _out) {
    os::Service service;
    if (returnIfCached(name, _out)) {
        return Status::ok();
@@ -246,7 +256,7 @@ Status BackendUnifiedServiceManager::checkService(const ::std::string& name, os:

    Status status = Status::ok();
    if (mTheRealServiceManager) {
        status = mTheRealServiceManager->checkService(name, &service);
        status = mTheRealServiceManager->checkService2(name, &service);
    }
    if (status.isOk()) {
        status = toBinderService(name, service, _out);
+2 −1
Original line number Diff line number Diff line
@@ -122,7 +122,8 @@ public:

    binder::Status getService(const ::std::string& name, sp<IBinder>* _aidl_return) override;
    binder::Status getService2(const ::std::string& name, os::Service* out) override;
    binder::Status checkService(const ::std::string& name, os::Service* out) override;
    binder::Status checkService(const ::std::string& name, sp<IBinder>* _aidl_return) override;
    binder::Status checkService2(const ::std::string& name, os::Service* out) override;
    binder::Status addService(const ::std::string& name, const sp<IBinder>& service,
                              bool allowIsolated, int32_t dumpPriority) override;
    binder::Status listServices(int32_t dumpPriority,
Loading