From e8be9e6c628438be499d00ec6d9194ce69c03086 Mon Sep 17 00:00:00 2001 From: Linus Tufvesson Date: Wed, 16 Nov 2022 14:44:27 +0100 Subject: [PATCH] Tell input System Application Overlays are trusted They can only be created by applications holding SYSTEM_APPLICATION_OVERLAY permission, which is signature|recents|role and it was specifically designed to only be used by compontents tightly integrated with the system, such as device intelligence and digital wellbeing. Without this change SAO overlays are in a weird state where they can stay visible on top of apps that are hiding overlays, but the are generating FLAG_WINDOW_IS_PARTIALLY_OBSCURED touch events, causing security sensitve apps to drop the touches. Bug: 199325240 Bug: 200938390 Test: Manully verified that system caption doesn't block interaction with permission dialog Test: atest CtsWindowManagerDeviceTestCases:HideOverlayWindowsTest Change-Id: I2c88bcd1d064758b901dda7d0ef30bc92b9cd56d --- .../java/com/android/server/wm/WindowState.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 1b7bd9e1f36fb..bc382e0b50af5 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -61,6 +61,7 @@ import static android.view.WindowManager.LayoutParams.MATCH_PARENT; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NOT_MAGNIFIABLE; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION; +import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_APPLICATION_OVERLAY; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH; import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; @@ -1152,12 +1153,7 @@ class WindowState extends WindowContainer implements WindowManagerP mInputWindowHandle.setName(getName()); mInputWindowHandle.setPackageName(mAttrs.packageName); mInputWindowHandle.setLayoutParamsType(mAttrs.type); - // Check private trusted overlay flag and window type to set trustedOverlay variable of - // input window handle. - mInputWindowHandle.setTrustedOverlay( - ((mAttrs.privateFlags & PRIVATE_FLAG_TRUSTED_OVERLAY) != 0 - && mOwnerCanAddInternalSystemWindow) - || InputMonitor.isTrustedOverlay(mAttrs.type)); + mInputWindowHandle.setTrustedOverlay(shouldWindowHandleBeTrusted(s)); if (DEBUG) { Slog.v(TAG, "Window " + this + " client=" + c.asBinder() + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a); @@ -1238,6 +1234,14 @@ class WindowState extends WindowContainer implements WindowManagerP : service.mAtmService.getProcessController(s.mPid, s.mUid); } + boolean shouldWindowHandleBeTrusted(Session s) { + return InputMonitor.isTrustedOverlay(mAttrs.type) + || ((mAttrs.privateFlags & PRIVATE_FLAG_TRUSTED_OVERLAY) != 0 + && s.mCanAddInternalSystemWindow) + || ((mAttrs.privateFlags & PRIVATE_FLAG_SYSTEM_APPLICATION_OVERLAY) != 0 + && s.mCanCreateSystemApplicationOverlay); + } + int getTouchOcclusionMode() { if (WindowManager.LayoutParams.isSystemAlertWindowType(mAttrs.type)) { return TouchOcclusionMode.USE_OPACITY;