Loading libs/binder/LazyServiceRegistrar.cpp +23 −18 Original line number Diff line number Diff line Loading @@ -38,8 +38,7 @@ public: bool allowIsolated, int dumpFlags); void forcePersist(bool persist); void setActiveServicesCountCallback(const std::function<bool(int)>& activeServicesCountCallback); void setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback); bool tryUnregister(); Loading Loading @@ -68,6 +67,9 @@ private: */ size_t mNumConnectedServices; // previous value passed to the active services callback std::optional<bool> mPreviousHasClients; struct Service { sp<IBinder> service; bool allowIsolated; Loading @@ -82,8 +84,8 @@ private: bool mForcePersist; // Callback used to report the number of services with clients std::function<bool(int)> mActiveServicesCountCallback; // Callback used to report if there are services with clients std::function<bool(bool)> mActiveServicesCallback; }; class ClientCounterCallback { Loading @@ -98,8 +100,7 @@ public: */ void forcePersist(bool persist); void setActiveServicesCountCallback(const std::function<bool(int)>& activeServicesCountCallback); void setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback); bool tryUnregister(); Loading Loading @@ -137,7 +138,7 @@ bool ClientCounterCallbackImpl::registerService(const sp<IBinder>& service, cons void ClientCounterCallbackImpl::forcePersist(bool persist) { mForcePersist = persist; if (!mForcePersist && mNumConnectedServices == 0) { if (!mForcePersist) { // Attempt a shutdown in case the number of clients hit 0 while the flag was on maybeTryShutdown(); } Loading Loading @@ -183,8 +184,12 @@ void ClientCounterCallbackImpl::maybeTryShutdown() { } bool handledInCallback = false; if (mActiveServicesCountCallback != nullptr) { handledInCallback = mActiveServicesCountCallback(mNumConnectedServices); if (mActiveServicesCallback != nullptr) { bool hasClients = mNumConnectedServices != 0; if (hasClients != mPreviousHasClients) { handledInCallback = mActiveServicesCallback(hasClients); mPreviousHasClients = hasClients; } } // If there is no callback defined or the callback did not handle this Loading Loading @@ -225,9 +230,9 @@ Status ClientCounterCallbackImpl::onClients(const sp<IBinder>& service, bool cli reRegister(); } void ClientCounterCallbackImpl::setActiveServicesCountCallback(const std::function<bool(int)>& activeServicesCountCallback) { mActiveServicesCountCallback = activeServicesCountCallback; void ClientCounterCallbackImpl::setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback) { mActiveServicesCallback = activeServicesCallback; } ClientCounterCallback::ClientCounterCallback() { Loading @@ -243,9 +248,9 @@ void ClientCounterCallback::forcePersist(bool persist) { mImpl->forcePersist(persist); } void ClientCounterCallback::setActiveServicesCountCallback(const std::function<bool(int)>& activeServicesCountCallback) { mImpl->setActiveServicesCountCallback(activeServicesCountCallback); void ClientCounterCallback::setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback) { mImpl->setActiveServicesCallback(activeServicesCallback); } bool ClientCounterCallback::tryUnregister() { Loading Loading @@ -279,9 +284,9 @@ void LazyServiceRegistrar::forcePersist(bool persist) { mClientCC->forcePersist(persist); } void LazyServiceRegistrar::setActiveServicesCountCallback(const std::function<bool(int)>& activeServicesCountCallback) { mClientCC->setActiveServicesCountCallback(activeServicesCountCallback); void LazyServiceRegistrar::setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback) { mClientCC->setActiveServicesCallback(activeServicesCallback); } bool LazyServiceRegistrar::tryUnregister() { Loading libs/binder/include/binder/LazyServiceRegistrar.h +5 −6 Original line number Diff line number Diff line Loading @@ -56,10 +56,10 @@ class LazyServiceRegistrar { void forcePersist(bool persist); /** * Set a callback that is executed when the total number of services with * clients changes. * The callback takes an argument, which is the number of registered * lazy services for this process which have clients. * Set a callback that is invoked when the active service count (i.e. services with clients) * registered with this process drops to zero (or becomes nonzero). * The callback takes a boolean argument, which is 'true' if there is * at least one service with clients. * * Callback return value: * - false: Default behavior for lazy services (shut down the process if there Loading @@ -73,8 +73,7 @@ class LazyServiceRegistrar { * * This method should be called before 'registerService' to avoid races. */ void setActiveServicesCountCallback(const std::function<bool(int)>& activeServicesCountCallback); void setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback); /** * Try to unregister all services previously registered with 'registerService'. Loading Loading
libs/binder/LazyServiceRegistrar.cpp +23 −18 Original line number Diff line number Diff line Loading @@ -38,8 +38,7 @@ public: bool allowIsolated, int dumpFlags); void forcePersist(bool persist); void setActiveServicesCountCallback(const std::function<bool(int)>& activeServicesCountCallback); void setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback); bool tryUnregister(); Loading Loading @@ -68,6 +67,9 @@ private: */ size_t mNumConnectedServices; // previous value passed to the active services callback std::optional<bool> mPreviousHasClients; struct Service { sp<IBinder> service; bool allowIsolated; Loading @@ -82,8 +84,8 @@ private: bool mForcePersist; // Callback used to report the number of services with clients std::function<bool(int)> mActiveServicesCountCallback; // Callback used to report if there are services with clients std::function<bool(bool)> mActiveServicesCallback; }; class ClientCounterCallback { Loading @@ -98,8 +100,7 @@ public: */ void forcePersist(bool persist); void setActiveServicesCountCallback(const std::function<bool(int)>& activeServicesCountCallback); void setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback); bool tryUnregister(); Loading Loading @@ -137,7 +138,7 @@ bool ClientCounterCallbackImpl::registerService(const sp<IBinder>& service, cons void ClientCounterCallbackImpl::forcePersist(bool persist) { mForcePersist = persist; if (!mForcePersist && mNumConnectedServices == 0) { if (!mForcePersist) { // Attempt a shutdown in case the number of clients hit 0 while the flag was on maybeTryShutdown(); } Loading Loading @@ -183,8 +184,12 @@ void ClientCounterCallbackImpl::maybeTryShutdown() { } bool handledInCallback = false; if (mActiveServicesCountCallback != nullptr) { handledInCallback = mActiveServicesCountCallback(mNumConnectedServices); if (mActiveServicesCallback != nullptr) { bool hasClients = mNumConnectedServices != 0; if (hasClients != mPreviousHasClients) { handledInCallback = mActiveServicesCallback(hasClients); mPreviousHasClients = hasClients; } } // If there is no callback defined or the callback did not handle this Loading Loading @@ -225,9 +230,9 @@ Status ClientCounterCallbackImpl::onClients(const sp<IBinder>& service, bool cli reRegister(); } void ClientCounterCallbackImpl::setActiveServicesCountCallback(const std::function<bool(int)>& activeServicesCountCallback) { mActiveServicesCountCallback = activeServicesCountCallback; void ClientCounterCallbackImpl::setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback) { mActiveServicesCallback = activeServicesCallback; } ClientCounterCallback::ClientCounterCallback() { Loading @@ -243,9 +248,9 @@ void ClientCounterCallback::forcePersist(bool persist) { mImpl->forcePersist(persist); } void ClientCounterCallback::setActiveServicesCountCallback(const std::function<bool(int)>& activeServicesCountCallback) { mImpl->setActiveServicesCountCallback(activeServicesCountCallback); void ClientCounterCallback::setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback) { mImpl->setActiveServicesCallback(activeServicesCallback); } bool ClientCounterCallback::tryUnregister() { Loading Loading @@ -279,9 +284,9 @@ void LazyServiceRegistrar::forcePersist(bool persist) { mClientCC->forcePersist(persist); } void LazyServiceRegistrar::setActiveServicesCountCallback(const std::function<bool(int)>& activeServicesCountCallback) { mClientCC->setActiveServicesCountCallback(activeServicesCountCallback); void LazyServiceRegistrar::setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback) { mClientCC->setActiveServicesCallback(activeServicesCallback); } bool LazyServiceRegistrar::tryUnregister() { Loading
libs/binder/include/binder/LazyServiceRegistrar.h +5 −6 Original line number Diff line number Diff line Loading @@ -56,10 +56,10 @@ class LazyServiceRegistrar { void forcePersist(bool persist); /** * Set a callback that is executed when the total number of services with * clients changes. * The callback takes an argument, which is the number of registered * lazy services for this process which have clients. * Set a callback that is invoked when the active service count (i.e. services with clients) * registered with this process drops to zero (or becomes nonzero). * The callback takes a boolean argument, which is 'true' if there is * at least one service with clients. * * Callback return value: * - false: Default behavior for lazy services (shut down the process if there Loading @@ -73,8 +73,7 @@ class LazyServiceRegistrar { * * This method should be called before 'registerService' to avoid races. */ void setActiveServicesCountCallback(const std::function<bool(int)>& activeServicesCountCallback); void setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback); /** * Try to unregister all services previously registered with 'registerService'. Loading