From 05ffe52b3368fc71fa0944bf043a7fb7a4a9fbe4 Mon Sep 17 00:00:00 2001 From: Devin Moore Date: Thu, 6 Aug 2020 13:58:29 -0700 Subject: servicemanager: Overwrite old service when a new one is registered We want to overwrite an old service with the same name as a new service that is being added. The old one will be cleaned up as servicemanager loses the reference to it. Test: atest servicemanager_test && additional tests outlined in Bug Bug: 162553096 Change-Id: I8835d9f7505367d83a0f29f1d928a07b3d57e56a --- cmds/servicemanager/ServiceManager.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'cmds/servicemanager/ServiceManager.cpp') diff --git a/cmds/servicemanager/ServiceManager.cpp b/cmds/servicemanager/ServiceManager.cpp index 1f9892a262..e80c3210f0 100644 --- a/cmds/servicemanager/ServiceManager.cpp +++ b/cmds/servicemanager/ServiceManager.cpp @@ -213,17 +213,18 @@ Status ServiceManager::addService(const std::string& name, const sp& bi return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); } - auto entry = mNameToService.emplace(name, Service { + // Overwrite the old service if it exists + mNameToService[name] = Service { .binder = binder, .allowIsolated = allowIsolated, .dumpPriority = dumpPriority, .debugPid = ctx.debugPid, - }); + }; auto it = mNameToRegistrationCallback.find(name); if (it != mNameToRegistrationCallback.end()) { for (const sp& cb : it->second) { - entry.first->second.guaranteeClient = true; + mNameToService[name].guaranteeClient = true; // permission checked in registerForNotifications cb->onRegistration(name, binder); } -- cgit v1.2.3-59-g8ed1b