status_t TransactionCallbackInvoker::finalizeCallbackHandle(const sp<CallbackHandle>& handle,
const std::vector<JankData>& jankData) {
auto listener = mPendingTransactions.find(handle->listener);
if (listener != mPendingTransactions.end()) {
auto& pendingCallbacks = listener->second;
auto pendingCallback = pendingCallbacks.find(handle->callbackIds);
if (pendingCallback != pendingCallbacks.end()) {
auto& pendingCount = pendingCallback->second;
// Decrease the pending count for this listener
if (--pendingCount == 0) {
pendingCallbacks.erase(pendingCallback);
}
} else {
ALOGW("there are more latched callbacks than there were registered callbacks");
}
if (listener->second.size() == 0) {
mPendingTransactions.erase(listener);
}
} else {
ALOGW("cannot find listener in mPendingTransactions");
}
status_t err = addCallbackHandle(handle, jankData);
if (err != NO_ERROR) {
ALOGE("could not add callback handle");
return err;
}
return NO_ERROR;
}