Loading libs/binder/BackendUnifiedServiceManager.cpp +21 −2 Original line number Diff line number Diff line Loading @@ -123,11 +123,30 @@ binder::Status BackendUnifiedServiceManager::updateCache(const std::string& serv if (!kUseCache) { return binder::Status::ok(); } std::string traceStr; if (atrace_is_tag_enabled(ATRACE_TAG_AIDL)) { traceStr = "BinderCacheWithInvalidation::updateCache : " + serviceName; } binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL, traceStr.c_str()); if (service.getTag() == os::Service::Tag::binder) { sp<IBinder> binder = service.get<os::Service::Tag::binder>(); if (binder && mCacheForGetService->isClientSideCachingEnabled(serviceName) && binder->isBinderAlive()) { if (!binder) { binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL, "BinderCacheWithInvalidation::updateCache failed: binder_null"); } else if (!binder->isBinderAlive()) { binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL, "BinderCacheWithInvalidation::updateCache failed: " "isBinderAlive_false"); } else if (mCacheForGetService->isClientSideCachingEnabled(serviceName)) { binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL, "BinderCacheWithInvalidation::updateCache successful"); return mCacheForGetService->setItem(serviceName, binder); } else { binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL, "BinderCacheWithInvalidation::updateCache failed: " "caching_not_enabled"); } } return binder::Status::ok(); Loading libs/binder/BackendUnifiedServiceManager.h +18 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #include <android/os/BnServiceManager.h> #include <android/os/IServiceManager.h> #include <binder/IPCThreadState.h> #include <binder/Trace.h> #include <map> #include <memory> Loading Loading @@ -59,6 +60,12 @@ public: } bool removeItem(const std::string& key, const sp<IBinder>& who) { std::string traceStr; uint64_t tag = ATRACE_TAG_AIDL; if (atrace_is_tag_enabled(tag)) { traceStr = "BinderCacheWithInvalidation::removeItem " + key; } binder::ScopedTrace aidlTrace(tag, traceStr.c_str()); std::lock_guard<std::mutex> lock(mCacheMutex); if (auto it = mCache.find(key); it != mCache.end()) { if (it->second.service == who) { Loading @@ -81,11 +88,22 @@ public: if (item->localBinder() == nullptr) { status_t status = item->linkToDeath(deathRecipient); if (status != android::OK) { std::string traceStr; uint64_t tag = ATRACE_TAG_AIDL; if (atrace_is_tag_enabled(tag)) { traceStr = "BinderCacheWithInvalidation::setItem Failed LinkToDeath for service " + key + " : " + std::to_string(status); } binder::ScopedTrace aidlTrace(tag, traceStr.c_str()); ALOGE("Failed to linkToDeath binder for service %s. Error: %d", key.c_str(), status); return binder::Status::fromStatusT(status); } } binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL, "BinderCacheWithInvalidation::setItem Successfully Cached"); std::lock_guard<std::mutex> lock(mCacheMutex); Entry entry = {.service = item, .deathRecipient = deathRecipient}; mCache[key] = entry; Loading Loading
libs/binder/BackendUnifiedServiceManager.cpp +21 −2 Original line number Diff line number Diff line Loading @@ -123,11 +123,30 @@ binder::Status BackendUnifiedServiceManager::updateCache(const std::string& serv if (!kUseCache) { return binder::Status::ok(); } std::string traceStr; if (atrace_is_tag_enabled(ATRACE_TAG_AIDL)) { traceStr = "BinderCacheWithInvalidation::updateCache : " + serviceName; } binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL, traceStr.c_str()); if (service.getTag() == os::Service::Tag::binder) { sp<IBinder> binder = service.get<os::Service::Tag::binder>(); if (binder && mCacheForGetService->isClientSideCachingEnabled(serviceName) && binder->isBinderAlive()) { if (!binder) { binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL, "BinderCacheWithInvalidation::updateCache failed: binder_null"); } else if (!binder->isBinderAlive()) { binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL, "BinderCacheWithInvalidation::updateCache failed: " "isBinderAlive_false"); } else if (mCacheForGetService->isClientSideCachingEnabled(serviceName)) { binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL, "BinderCacheWithInvalidation::updateCache successful"); return mCacheForGetService->setItem(serviceName, binder); } else { binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL, "BinderCacheWithInvalidation::updateCache failed: " "caching_not_enabled"); } } return binder::Status::ok(); Loading
libs/binder/BackendUnifiedServiceManager.h +18 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #include <android/os/BnServiceManager.h> #include <android/os/IServiceManager.h> #include <binder/IPCThreadState.h> #include <binder/Trace.h> #include <map> #include <memory> Loading Loading @@ -59,6 +60,12 @@ public: } bool removeItem(const std::string& key, const sp<IBinder>& who) { std::string traceStr; uint64_t tag = ATRACE_TAG_AIDL; if (atrace_is_tag_enabled(tag)) { traceStr = "BinderCacheWithInvalidation::removeItem " + key; } binder::ScopedTrace aidlTrace(tag, traceStr.c_str()); std::lock_guard<std::mutex> lock(mCacheMutex); if (auto it = mCache.find(key); it != mCache.end()) { if (it->second.service == who) { Loading @@ -81,11 +88,22 @@ public: if (item->localBinder() == nullptr) { status_t status = item->linkToDeath(deathRecipient); if (status != android::OK) { std::string traceStr; uint64_t tag = ATRACE_TAG_AIDL; if (atrace_is_tag_enabled(tag)) { traceStr = "BinderCacheWithInvalidation::setItem Failed LinkToDeath for service " + key + " : " + std::to_string(status); } binder::ScopedTrace aidlTrace(tag, traceStr.c_str()); ALOGE("Failed to linkToDeath binder for service %s. Error: %d", key.c_str(), status); return binder::Status::fromStatusT(status); } } binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL, "BinderCacheWithInvalidation::setItem Successfully Cached"); std::lock_guard<std::mutex> lock(mCacheMutex); Entry entry = {.service = item, .deathRecipient = deathRecipient}; mCache[key] = entry; Loading