Loading cmds/servicemanager/ServiceManager.cpp +12 −12 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ ServiceManager::ServiceManager(std::unique_ptr<Access>&& access) : mAccess(std:: ServiceManager::~ServiceManager() { // this should only happen in tests for (const auto& [name, callbacks] : mNameToCallback) { for (const auto& [name, callbacks] : mNameToRegistrationCallback) { CHECK(!callbacks.empty()) << name; for (const auto& callback : callbacks) { CHECK(callback != nullptr) << name; Loading Loading @@ -199,8 +199,8 @@ Status ServiceManager::addService(const std::string& name, const sp<IBinder>& bi .debugPid = ctx.debugPid, }); auto it = mNameToCallback.find(name); if (it != mNameToCallback.end()) { auto it = mNameToRegistrationCallback.find(name); if (it != mNameToRegistrationCallback.end()) { for (const sp<IServiceCallback>& cb : it->second) { entry.first->second.guaranteeClient = true; // permission checked in registerForNotifications Loading Loading @@ -259,7 +259,7 @@ Status ServiceManager::registerForNotifications( return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); } mNameToCallback[name].push_back(callback); mNameToRegistrationCallback[name].push_back(callback); if (auto it = mNameToService.find(name); it != mNameToService.end()) { const sp<IBinder>& binder = it->second.binder; Loading @@ -281,9 +281,9 @@ Status ServiceManager::unregisterForNotifications( bool found = false; auto it = mNameToCallback.find(name); if (it != mNameToCallback.end()) { removeCallback(IInterface::asBinder(callback), &it, &found); auto it = mNameToRegistrationCallback.find(name); if (it != mNameToRegistrationCallback.end()) { removeRegistrationCallback(IInterface::asBinder(callback), &it, &found); } if (!found) { Loading @@ -309,8 +309,8 @@ Status ServiceManager::isDeclared(const std::string& name, bool* outReturn) { return Status::ok(); } void ServiceManager::removeCallback(const wp<IBinder>& who, CallbackMap::iterator* it, void ServiceManager::removeRegistrationCallback(const wp<IBinder>& who, ServiceCallbackMap::iterator* it, bool* found) { std::vector<sp<IServiceCallback>>& listeners = (*it)->second; Loading @@ -324,7 +324,7 @@ void ServiceManager::removeCallback(const wp<IBinder>& who, } if (listeners.empty()) { *it = mNameToCallback.erase(*it); *it = mNameToRegistrationCallback.erase(*it); } else { (*it)++; } Loading @@ -339,8 +339,8 @@ void ServiceManager::binderDied(const wp<IBinder>& who) { } } for (auto it = mNameToCallback.begin(); it != mNameToCallback.end();) { removeCallback(who, &it, nullptr /*found*/); for (auto it = mNameToRegistrationCallback.begin(); it != mNameToRegistrationCallback.end();) { removeRegistrationCallback(who, &it, nullptr /*found*/); } for (auto it = mNameToClientCallback.begin(); it != mNameToClientCallback.end();) { Loading cmds/servicemanager/ServiceManager.h +5 −5 Original line number Diff line number Diff line Loading @@ -66,14 +66,14 @@ private: ssize_t getNodeStrongRefCount(); }; using CallbackMap = std::map<std::string, std::vector<sp<IServiceCallback>>>; using ServiceCallbackMap = 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 // removes a callback from mNameToRegistrationCallback, removing it if the vector is empty // this updates iterator to the next location void removeCallback(const wp<IBinder>& who, CallbackMap::iterator* it, void removeRegistrationCallback(const wp<IBinder>& who, ServiceCallbackMap::iterator* it, bool* found); ssize_t handleServiceClientCallback(const std::string& serviceName); // Also updates mHasClients (of what the last callback was) Loading @@ -84,8 +84,8 @@ private: sp<IBinder> tryGetService(const std::string& name, bool startIfNotFound); CallbackMap mNameToCallback; ServiceMap mNameToService; ServiceCallbackMap mNameToRegistrationCallback; ClientCallbackMap mNameToClientCallback; std::unique_ptr<Access> mAccess; Loading Loading
cmds/servicemanager/ServiceManager.cpp +12 −12 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ ServiceManager::ServiceManager(std::unique_ptr<Access>&& access) : mAccess(std:: ServiceManager::~ServiceManager() { // this should only happen in tests for (const auto& [name, callbacks] : mNameToCallback) { for (const auto& [name, callbacks] : mNameToRegistrationCallback) { CHECK(!callbacks.empty()) << name; for (const auto& callback : callbacks) { CHECK(callback != nullptr) << name; Loading Loading @@ -199,8 +199,8 @@ Status ServiceManager::addService(const std::string& name, const sp<IBinder>& bi .debugPid = ctx.debugPid, }); auto it = mNameToCallback.find(name); if (it != mNameToCallback.end()) { auto it = mNameToRegistrationCallback.find(name); if (it != mNameToRegistrationCallback.end()) { for (const sp<IServiceCallback>& cb : it->second) { entry.first->second.guaranteeClient = true; // permission checked in registerForNotifications Loading Loading @@ -259,7 +259,7 @@ Status ServiceManager::registerForNotifications( return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); } mNameToCallback[name].push_back(callback); mNameToRegistrationCallback[name].push_back(callback); if (auto it = mNameToService.find(name); it != mNameToService.end()) { const sp<IBinder>& binder = it->second.binder; Loading @@ -281,9 +281,9 @@ Status ServiceManager::unregisterForNotifications( bool found = false; auto it = mNameToCallback.find(name); if (it != mNameToCallback.end()) { removeCallback(IInterface::asBinder(callback), &it, &found); auto it = mNameToRegistrationCallback.find(name); if (it != mNameToRegistrationCallback.end()) { removeRegistrationCallback(IInterface::asBinder(callback), &it, &found); } if (!found) { Loading @@ -309,8 +309,8 @@ Status ServiceManager::isDeclared(const std::string& name, bool* outReturn) { return Status::ok(); } void ServiceManager::removeCallback(const wp<IBinder>& who, CallbackMap::iterator* it, void ServiceManager::removeRegistrationCallback(const wp<IBinder>& who, ServiceCallbackMap::iterator* it, bool* found) { std::vector<sp<IServiceCallback>>& listeners = (*it)->second; Loading @@ -324,7 +324,7 @@ void ServiceManager::removeCallback(const wp<IBinder>& who, } if (listeners.empty()) { *it = mNameToCallback.erase(*it); *it = mNameToRegistrationCallback.erase(*it); } else { (*it)++; } Loading @@ -339,8 +339,8 @@ void ServiceManager::binderDied(const wp<IBinder>& who) { } } for (auto it = mNameToCallback.begin(); it != mNameToCallback.end();) { removeCallback(who, &it, nullptr /*found*/); for (auto it = mNameToRegistrationCallback.begin(); it != mNameToRegistrationCallback.end();) { removeRegistrationCallback(who, &it, nullptr /*found*/); } for (auto it = mNameToClientCallback.begin(); it != mNameToClientCallback.end();) { Loading
cmds/servicemanager/ServiceManager.h +5 −5 Original line number Diff line number Diff line Loading @@ -66,14 +66,14 @@ private: ssize_t getNodeStrongRefCount(); }; using CallbackMap = std::map<std::string, std::vector<sp<IServiceCallback>>>; using ServiceCallbackMap = 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 // removes a callback from mNameToRegistrationCallback, removing it if the vector is empty // this updates iterator to the next location void removeCallback(const wp<IBinder>& who, CallbackMap::iterator* it, void removeRegistrationCallback(const wp<IBinder>& who, ServiceCallbackMap::iterator* it, bool* found); ssize_t handleServiceClientCallback(const std::string& serviceName); // Also updates mHasClients (of what the last callback was) Loading @@ -84,8 +84,8 @@ private: sp<IBinder> tryGetService(const std::string& name, bool startIfNotFound); CallbackMap mNameToCallback; ServiceMap mNameToService; ServiceCallbackMap mNameToRegistrationCallback; ClientCallbackMap mNameToClientCallback; std::unique_ptr<Access> mAccess; Loading