From 0f6b4e2348ccba918a52074be7321e08ad9d9cb0 Mon Sep 17 00:00:00 2001 From: Kevin Chyn Date: Mon, 8 May 2023 22:00:59 +0000 Subject: [PATCH] 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 --- .../area/WindowAreaComponentImpl.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/area/WindowAreaComponentImpl.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/area/WindowAreaComponentImpl.java index 658d92cc74896..ff423c2c6e390 100644 --- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/area/WindowAreaComponentImpl.java +++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/area/WindowAreaComponentImpl.java @@ -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; + } } }