1818#include < android/os/BnServiceManager.h>
1919#include < android/os/IServiceManager.h>
2020#include < binder/IPCThreadState.h>
21+ #include < binder/Trace.h>
2122#include < map>
2223#include < memory>
2324
@@ -59,6 +60,12 @@ class BinderCacheWithInvalidation
5960 }
6061
6162 bool removeItem (const std::string& key, const sp<IBinder>& who) {
63+ std::string traceStr;
64+ uint64_t tag = ATRACE_TAG_AIDL;
65+ if (atrace_is_tag_enabled (tag)) {
66+ traceStr = " BinderCacheWithInvalidation::removeItem " + key;
67+ }
68+ binder::ScopedTrace aidlTrace (tag, traceStr.c_str ());
6269 std::lock_guard<std::mutex> lock (mCacheMutex );
6370 if (auto it = mCache .find (key); it != mCache .end ()) {
6471 if (it->second .service == who) {
@@ -81,11 +88,22 @@ class BinderCacheWithInvalidation
8188 if (item->localBinder () == nullptr ) {
8289 status_t status = item->linkToDeath (deathRecipient);
8390 if (status != android::OK) {
91+ std::string traceStr;
92+ uint64_t tag = ATRACE_TAG_AIDL;
93+ if (atrace_is_tag_enabled (tag)) {
94+ traceStr =
95+ " BinderCacheWithInvalidation::setItem Failed LinkToDeath for service " +
96+ key + " : " + std::to_string (status);
97+ }
98+ binder::ScopedTrace aidlTrace (tag, traceStr.c_str ());
99+
84100 ALOGE (" Failed to linkToDeath binder for service %s. Error: %d" , key.c_str (),
85101 status);
86102 return binder::Status::fromStatusT (status);
87103 }
88104 }
105+ binder::ScopedTrace aidlTrace (ATRACE_TAG_AIDL,
106+ " BinderCacheWithInvalidation::setItem Successfully Cached" );
89107 std::lock_guard<std::mutex> lock (mCacheMutex );
90108 Entry entry = {.service = item, .deathRecipient = deathRecipient};
91109 mCache [key] = entry;
0 commit comments