status_t TransactionCallbackInvoker::addCallbackHandle(const sp<CallbackHandle>& handle,
const std::vector<JankData>& jankData) {
// If we can't find the transaction stats something has gone wrong. The client should call
// startRegistration before trying to add a callback handle.
TransactionStats* transactionStats;
status_t err = findTransactionStats(handle->listener, handle->callbackIds, &transactionStats);
if (err != NO_ERROR) {
return err;
}
transactionStats->latchTime = handle->latchTime;
// If the layer has already been destroyed, don't add the SurfaceControl to the callback.
// The client side keeps a sp<> to the SurfaceControl so if the SurfaceControl has been
// destroyed the client side is dead and there won't be anyone to send the callback to.
sp<IBinder> surfaceControl = handle->surfaceControl.promote();
if (surfaceControl) {
FrameEventHistoryStats eventStats(handle->frameNumber,
handle->gpuCompositionDoneFence->getSnapshot().fence,
handle->compositorTiming, handle->refreshStartTime,
handle->dequeueReadyTime);
transactionStats->surfaceStats.emplace_back(surfaceControl, handle->acquireTime,
handle->previousReleaseFence,
handle->transformHint,
handle->currentMaxAcquiredBufferCount,
eventStats, jankData,
handle->previousReleaseCallbackId);
}
return NO_ERROR;
}