Cleanup mRearDisplayPresentationController if SecurityException caught

If a SecurityException occurs when invoking
DeviceStateManager#requestState (e.g. if not the caller is not
in foreground, or if it does not have the required permissions),
we should first clean up our local state before re-throwing the
SecurityException to the caller. Otherwise, subsequent attempts
to startRearDisplayPresentationSession will always fail.

Bug: 270671994
Test: atest ExtensionRearDisplayPresentationKeyguardTest
Change-Id: Ie102b03b722f018dc093ef9ab8c5c41b141a5bd0
This commit is contained in:
Kevin Chyn
2023-05-08 22:00:59 +00:00
parent 50f9e8baef
commit 0f6b4e2348

View File

@@ -342,11 +342,22 @@ public class WindowAreaComponentImpl implements WindowAreaComponent,
mRearDisplayPresentationController);
DeviceStateRequest concurrentDisplayStateRequest = DeviceStateRequest.newBuilder(
mConcurrentDisplayState).build();
mDeviceStateManager.requestState(
concurrentDisplayStateRequest,
mExecutor,
deviceStateCallback
);
try {
mDeviceStateManager.requestState(
concurrentDisplayStateRequest,
mExecutor,
deviceStateCallback
);
} catch (SecurityException e) {
// If a SecurityException occurs when invoking DeviceStateManager#requestState
// (e.g. if the caller is not in the foreground, or if it does not have the required
// permissions), we should first clean up our local state before re-throwing the
// SecurityException to the caller. Otherwise, subsequent attempts to
// startRearDisplayPresentationSession will always fail.
mRearDisplayPresentationController = null;
throw e;
}
}
}