Merge "Fix potential for dead binders when calling callbacks"

This commit is contained in:
Benedict Wong 2022-02-03 03:04:52 +00:00 committed by Gerrit Code Review
commit bb0d4256f4

View File

@ -539,7 +539,13 @@ public class VcnManagementService extends IVcnManagementService.Stub {
@GuardedBy("mLock")
private void notifyAllPolicyListenersLocked() {
for (final PolicyListenerBinderDeath policyListener : mRegisteredPolicyListeners.values()) {
Binder.withCleanCallingIdentity(() -> policyListener.mListener.onPolicyChanged());
Binder.withCleanCallingIdentity(() -> {
try {
policyListener.mListener.onPolicyChanged();
} catch (RemoteException e) {
logDbg("VcnStatusCallback threw on VCN status change", e);
}
});
}
}
@ -548,8 +554,13 @@ public class VcnManagementService extends IVcnManagementService.Stub {
@NonNull ParcelUuid subGroup, @VcnStatusCode int statusCode) {
for (final VcnStatusCallbackInfo cbInfo : mRegisteredStatusCallbacks.values()) {
if (isCallbackPermissioned(cbInfo, subGroup)) {
Binder.withCleanCallingIdentity(
() -> cbInfo.mCallback.onVcnStatusChanged(statusCode));
Binder.withCleanCallingIdentity(() -> {
try {
cbInfo.mCallback.onVcnStatusChanged(statusCode);
} catch (RemoteException e) {
logDbg("VcnStatusCallback threw on VCN status change", e);
}
});
}
}
}
@ -1222,13 +1233,17 @@ public class VcnManagementService extends IVcnManagementService.Stub {
// Notify all registered StatusCallbacks for this subGroup
for (VcnStatusCallbackInfo cbInfo : mRegisteredStatusCallbacks.values()) {
if (isCallbackPermissioned(cbInfo, mSubGroup)) {
Binder.withCleanCallingIdentity(
() ->
cbInfo.mCallback.onGatewayConnectionError(
gatewayConnectionName,
errorCode,
exceptionClass,
exceptionMessage));
Binder.withCleanCallingIdentity(() -> {
try {
cbInfo.mCallback.onGatewayConnectionError(
gatewayConnectionName,
errorCode,
exceptionClass,
exceptionMessage);
} catch (RemoteException e) {
logDbg("VcnStatusCallback threw on VCN status change", e);
}
});
}
}
}