Loading services/mediaresourcemanager/ResourceManagerService.cpp +15 −9 Original line number Diff line number Diff line Loading @@ -483,7 +483,7 @@ Status ResourceManagerService::addResource(int32_t pid, int32_t uid, int64_t cli } } if (info.cookie == 0 && client != nullptr) { info.cookie = addCookieAndLink_l(client->asBinder(), info.cookie = addCookieAndLink_l(client, new DeathNotifier(ref<ResourceManagerService>(), pid, clientId)); } if (mObserverService != nullptr && !resourceAdded.empty()) { Loading Loading @@ -592,7 +592,7 @@ Status ResourceManagerService::removeResource(int pid, int64_t clientId, bool ch onLastRemoved(it->second, info); } removeCookieAndUnlink_l(info.client->asBinder(), info.cookie); removeCookieAndUnlink_l(info.client, info.cookie); if (mObserverService != nullptr && !info.resources.empty()) { mObserverService->onResourceRemoved(info.uid, pid, info.resources); Loading Loading @@ -812,7 +812,7 @@ Status ResourceManagerService::overrideProcessInfo( return Status::fromServiceSpecificError(BAD_VALUE); } uintptr_t cookie = addCookieAndLink_l(client->asBinder(), uintptr_t cookie = addCookieAndLink_l(client, new OverrideProcessInfoDeathNotifier(ref<ResourceManagerService>(), pid)); mProcessInfoOverrideMap.emplace(pid, ProcessInfoOverride{cookie, client}); Loading @@ -820,23 +820,29 @@ Status ResourceManagerService::overrideProcessInfo( return Status::ok(); } uintptr_t ResourceManagerService::addCookieAndLink_l(::ndk::SpAIBinder binder, const sp<DeathNotifier>& notifier) { uintptr_t ResourceManagerService::addCookieAndLink_l( const std::shared_ptr<IResourceManagerClient>& client, const sp<DeathNotifier>& notifier) { if (client == nullptr) { return 0; } std::scoped_lock lock{sCookieLock}; uintptr_t cookie; // Need to skip cookie 0 (if it wraps around). ResourceInfo has cookie initialized to 0 // indicating the death notifier is not created yet. while ((cookie = ++sCookieCounter) == 0); AIBinder_linkToDeath(binder.get(), mDeathRecipient.get(), (void*)cookie); AIBinder_linkToDeath(client->asBinder().get(), mDeathRecipient.get(), (void*)cookie); sCookieToDeathNotifierMap.emplace(cookie, notifier); return cookie; } void ResourceManagerService::removeCookieAndUnlink_l(::ndk::SpAIBinder binder, uintptr_t cookie) { void ResourceManagerService::removeCookieAndUnlink_l( const std::shared_ptr<IResourceManagerClient>& client, uintptr_t cookie) { std::scoped_lock lock{sCookieLock}; AIBinder_unlinkToDeath(binder.get(), mDeathRecipient.get(), (void*)cookie); if (client != nullptr) { AIBinder_unlinkToDeath(client->asBinder().get(), mDeathRecipient.get(), (void*)cookie); } sCookieToDeathNotifierMap.erase(cookie); } Loading @@ -854,7 +860,7 @@ void ResourceManagerService::removeProcessInfoOverride_l(int pid) { mProcessInfo->removeProcessInfoOverride(pid); removeCookieAndUnlink_l(it->second.client->asBinder(), it->second.cookie); removeCookieAndUnlink_l(it->second.client, it->second.cookie); mProcessInfoOverrideMap.erase(pid); } Loading services/mediaresourcemanager/ResourceManagerService.h +4 −2 Original line number Diff line number Diff line Loading @@ -166,8 +166,10 @@ private: void removeProcessInfoOverride(int pid); void removeProcessInfoOverride_l(int pid); uintptr_t addCookieAndLink_l(::ndk::SpAIBinder binder, const sp<DeathNotifier>& notifier); void removeCookieAndUnlink_l(::ndk::SpAIBinder binder, uintptr_t cookie); uintptr_t addCookieAndLink_l(const std::shared_ptr<IResourceManagerClient>& client, const sp<DeathNotifier>& notifier); void removeCookieAndUnlink_l(const std::shared_ptr<IResourceManagerClient>& client, uintptr_t cookie); mutable Mutex mLock; sp<ProcessInfoInterface> mProcessInfo; Loading Loading
services/mediaresourcemanager/ResourceManagerService.cpp +15 −9 Original line number Diff line number Diff line Loading @@ -483,7 +483,7 @@ Status ResourceManagerService::addResource(int32_t pid, int32_t uid, int64_t cli } } if (info.cookie == 0 && client != nullptr) { info.cookie = addCookieAndLink_l(client->asBinder(), info.cookie = addCookieAndLink_l(client, new DeathNotifier(ref<ResourceManagerService>(), pid, clientId)); } if (mObserverService != nullptr && !resourceAdded.empty()) { Loading Loading @@ -592,7 +592,7 @@ Status ResourceManagerService::removeResource(int pid, int64_t clientId, bool ch onLastRemoved(it->second, info); } removeCookieAndUnlink_l(info.client->asBinder(), info.cookie); removeCookieAndUnlink_l(info.client, info.cookie); if (mObserverService != nullptr && !info.resources.empty()) { mObserverService->onResourceRemoved(info.uid, pid, info.resources); Loading Loading @@ -812,7 +812,7 @@ Status ResourceManagerService::overrideProcessInfo( return Status::fromServiceSpecificError(BAD_VALUE); } uintptr_t cookie = addCookieAndLink_l(client->asBinder(), uintptr_t cookie = addCookieAndLink_l(client, new OverrideProcessInfoDeathNotifier(ref<ResourceManagerService>(), pid)); mProcessInfoOverrideMap.emplace(pid, ProcessInfoOverride{cookie, client}); Loading @@ -820,23 +820,29 @@ Status ResourceManagerService::overrideProcessInfo( return Status::ok(); } uintptr_t ResourceManagerService::addCookieAndLink_l(::ndk::SpAIBinder binder, const sp<DeathNotifier>& notifier) { uintptr_t ResourceManagerService::addCookieAndLink_l( const std::shared_ptr<IResourceManagerClient>& client, const sp<DeathNotifier>& notifier) { if (client == nullptr) { return 0; } std::scoped_lock lock{sCookieLock}; uintptr_t cookie; // Need to skip cookie 0 (if it wraps around). ResourceInfo has cookie initialized to 0 // indicating the death notifier is not created yet. while ((cookie = ++sCookieCounter) == 0); AIBinder_linkToDeath(binder.get(), mDeathRecipient.get(), (void*)cookie); AIBinder_linkToDeath(client->asBinder().get(), mDeathRecipient.get(), (void*)cookie); sCookieToDeathNotifierMap.emplace(cookie, notifier); return cookie; } void ResourceManagerService::removeCookieAndUnlink_l(::ndk::SpAIBinder binder, uintptr_t cookie) { void ResourceManagerService::removeCookieAndUnlink_l( const std::shared_ptr<IResourceManagerClient>& client, uintptr_t cookie) { std::scoped_lock lock{sCookieLock}; AIBinder_unlinkToDeath(binder.get(), mDeathRecipient.get(), (void*)cookie); if (client != nullptr) { AIBinder_unlinkToDeath(client->asBinder().get(), mDeathRecipient.get(), (void*)cookie); } sCookieToDeathNotifierMap.erase(cookie); } Loading @@ -854,7 +860,7 @@ void ResourceManagerService::removeProcessInfoOverride_l(int pid) { mProcessInfo->removeProcessInfoOverride(pid); removeCookieAndUnlink_l(it->second.client->asBinder(), it->second.cookie); removeCookieAndUnlink_l(it->second.client, it->second.cookie); mProcessInfoOverrideMap.erase(pid); } Loading
services/mediaresourcemanager/ResourceManagerService.h +4 −2 Original line number Diff line number Diff line Loading @@ -166,8 +166,10 @@ private: void removeProcessInfoOverride(int pid); void removeProcessInfoOverride_l(int pid); uintptr_t addCookieAndLink_l(::ndk::SpAIBinder binder, const sp<DeathNotifier>& notifier); void removeCookieAndUnlink_l(::ndk::SpAIBinder binder, uintptr_t cookie); uintptr_t addCookieAndLink_l(const std::shared_ptr<IResourceManagerClient>& client, const sp<DeathNotifier>& notifier); void removeCookieAndUnlink_l(const std::shared_ptr<IResourceManagerClient>& client, uintptr_t cookie); mutable Mutex mLock; sp<ProcessInfoInterface> mProcessInfo; Loading