diff options
author | 2024-11-29 10:40:41 +0000 | |
---|---|---|
committer | 2024-12-03 17:46:33 +0000 | |
commit | 5e1b7e1b0a23a47ab76ed022284fd40b67ebe503 (patch) | |
tree | d3a7bb860c95427b32ea175c35ea235847925d94 /cmds/servicemanager/ServiceManager.cpp | |
parent | dc207544897a30fe412ffcc0deab07dd974358d1 (diff) |
Remove static list in libbinder for caching
This adds a new flag to identify Lazy services.
This flag is set when addService is called from
LazyServiceRegistrar.
This flag is then used by libbinder in a client.
When getService is called, libbinder decides if
the binder should be cached or not using this flag.
Doc: go/libbinder-cache-v2
Flag: RELEASE_LIBBINDER_REMOVE_STATIC_LIST
Test: atest binderCacheUnitTest
Bug: 333854840
Change-Id: I5fff0140f635dddb4f5a6d618f4e9abace6feb54
Diffstat (limited to 'cmds/servicemanager/ServiceManager.cpp')
-rw-r--r-- | cmds/servicemanager/ServiceManager.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/cmds/servicemanager/ServiceManager.cpp b/cmds/servicemanager/ServiceManager.cpp index fa7cb64f3a..38a125bb54 100644 --- a/cmds/servicemanager/ServiceManager.cpp +++ b/cmds/servicemanager/ServiceManager.cpp @@ -396,7 +396,7 @@ Status ServiceManager::getService(const std::string& name, sp<IBinder>* outBinde SM_PERFETTO_TRACE_FUNC(PERFETTO_TE_PROTO_FIELDS( PERFETTO_TE_PROTO_FIELD_CSTR(kProtoServiceName, name.c_str()))); - *outBinder = tryGetBinder(name, true); + *outBinder = tryGetBinder(name, true).service; // returns ok regardless of result for legacy reasons return Status::ok(); } @@ -430,13 +430,15 @@ os::Service ServiceManager::tryGetService(const std::string& name, bool startIfN return os::Service::make<os::Service::Tag::accessor>(nullptr); } return os::Service::make<os::Service::Tag::accessor>( - tryGetBinder(*accessorName, startIfNotFound)); + tryGetBinder(*accessorName, startIfNotFound).service); } else { - return os::Service::make<os::Service::Tag::binder>(tryGetBinder(name, startIfNotFound)); + return os::Service::make<os::Service::Tag::serviceWithMetadata>( + tryGetBinder(name, startIfNotFound)); } } -sp<IBinder> ServiceManager::tryGetBinder(const std::string& name, bool startIfNotFound) { +os::ServiceWithMetadata ServiceManager::tryGetBinder(const std::string& name, + bool startIfNotFound) { SM_PERFETTO_TRACE_FUNC(PERFETTO_TE_PROTO_FIELDS( PERFETTO_TE_PROTO_FIELD_CSTR(kProtoServiceName, name.c_str()))); @@ -450,13 +452,13 @@ sp<IBinder> ServiceManager::tryGetBinder(const std::string& name, bool startIfNo if (!service->allowIsolated && is_multiuser_uid_isolated(ctx.uid)) { LOG(WARNING) << "Isolated app with UID " << ctx.uid << " requested '" << name << "', but the service is not allowed for isolated apps."; - return nullptr; + return os::ServiceWithMetadata(); } out = service->binder; } if (!mAccess->canFind(ctx, name)) { - return nullptr; + return os::ServiceWithMetadata(); } if (!out && startIfNotFound) { @@ -473,8 +475,11 @@ sp<IBinder> ServiceManager::tryGetBinder(const std::string& name, bool startIfNo CHECK(handleServiceClientCallback(2 /* sm + transaction */, name, false)); service->guaranteeClient = true; } - - return out; + os::ServiceWithMetadata serviceWithMetadata = os::ServiceWithMetadata(); + serviceWithMetadata.service = out; + serviceWithMetadata.isLazyService = + service ? service->dumpPriority & FLAG_IS_LAZY_SERVICE : false; + return serviceWithMetadata; } bool isValidServiceName(const std::string& name) { |