diff options
author | 2019-10-22 16:49:19 -0700 | |
---|---|---|
committer | 2019-12-19 20:17:06 -0800 | |
commit | 9f503a4285ea6818a572e56e47f9f6814c2b65c5 (patch) | |
tree | f766e951b6259bb2626478790d12f056c22f8910 /cmds/servicemanager/ServiceManager.h | |
parent | 6b243fdf227f80be3039c193a081e510b5737572 (diff) |
Dynamically stop lazy services
Services can choose to register with the new LazyServiceRegistrar.
ServiceManager perpetually checks the reference counts of services
registered in this way. If ServiceManager detects that a service no
longer has any clients, it will notify the LazyServiceRegistrar, which
will attempt to shut down the service.
Bug: 143108344
Test: aidl_lazy_test
Change-Id: Ic01981b767ab4402e7aecdf1cdf9ed64df1f5af4
Diffstat (limited to 'cmds/servicemanager/ServiceManager.h')
-rw-r--r-- | cmds/servicemanager/ServiceManager.h | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/cmds/servicemanager/ServiceManager.h b/cmds/servicemanager/ServiceManager.h index 7dcdaa4661..d3c89ee2ad 100644 --- a/cmds/servicemanager/ServiceManager.h +++ b/cmds/servicemanager/ServiceManager.h @@ -17,12 +17,14 @@ #pragma once #include <android/os/BnServiceManager.h> +#include <android/os/IClientCallback.h> #include <android/os/IServiceCallback.h> #include "Access.h" namespace android { +using os::IClientCallback; using os::IServiceCallback; class ServiceManager : public os::BnServiceManager, public IBinder::DeathRecipient { @@ -40,9 +42,13 @@ public: const sp<IServiceCallback>& callback) override; binder::Status unregisterForNotifications(const std::string& name, const sp<IServiceCallback>& callback) override; - binder::Status isDeclared(const std::string& name, bool* outReturn) override; + binder::Status isDeclared(const std::string& name, bool* outReturn) override; + binder::Status registerClientCallback(const std::string& name, const sp<IBinder>& service, + const sp<IClientCallback>& cb) override; + binder::Status tryUnregisterService(const std::string& name, const sp<IBinder>& binder) override; void binderDied(const wp<IBinder>& who) override; + void handleClientCallbacks(); protected: virtual void tryStartService(const std::string& name); @@ -52,9 +58,16 @@ private: sp<IBinder> binder; // not null bool allowIsolated; int32_t dumpPriority; + bool hasClients = false; // notifications sent on true -> false. + bool guaranteeClient = false; // forces the client check to true + pid_t debugPid = 0; // the process in which this service runs + + // the number of clients of the service, including servicemanager itself + ssize_t getNodeStrongRefCount(); }; using CallbackMap = std::map<std::string, std::vector<sp<IServiceCallback>>>; + using ClientCallbackMap = std::map<std::string, std::vector<sp<IClientCallback>>>; using ServiceMap = std::map<std::string, Service>; // removes a callback from mNameToCallback, removing it if the vector is empty @@ -62,10 +75,18 @@ private: void removeCallback(const wp<IBinder>& who, CallbackMap::iterator* it, bool* found); + ssize_t handleServiceClientCallback(const std::string& serviceName); + // Also updates mHasClients (of what the last callback was) + void sendClientCallbackNotifications(const std::string& serviceName, bool hasClients); + // removes a callback from mNameToClientCallback, deleting the entry if the vector is empty + // this updates the iterator to the next location + void removeClientCallback(const wp<IBinder>& who, ClientCallbackMap::iterator* it); + sp<IBinder> tryGetService(const std::string& name, bool startIfNotFound); CallbackMap mNameToCallback; ServiceMap mNameToService; + ClientCallbackMap mNameToClientCallback; std::unique_ptr<Access> mAccess; }; |