diff options
author | Vishnu Nair <vishnun@google.com> | 2022-02-02 17:13:21 +0000 |
---|---|---|
committer | Vishnu Nair <vishnun@google.com> | 2022-02-16 19:01:10 +0000 |
commit | 55c1473bf2fedaacf7bb8ac068e6f9b1a625b5e0 (patch) | |
tree | d027023b32dc90e66a1a83cb684d32d2f515c826 | |
parent | 5aa3d2169375ba5fbe3490357df57de35fec9294 (diff) | |
download | base-55c1473bf2fedaacf7bb8ac068e6f9b1a625b5e0.tar.gz |
Drop input for toast and child surfaces
Toasts that do not have the trustedOverlay flag should not receive input.
These windows should not have any children, so force this hierarchy of
windows to drop all input by setting a flag on the toast window state
which will apply the DROP_INPUT flag on all windows with an input
channel. This is to prevent malicious apps from parenting surfaces with
input channels to the toast window.
Test: show toast and check if input feature flag DROP_INPUT id set via dumpsys
Bug: b/197296414
Change-Id: I316b76b685ca5030fd8aa91283555efcce4d6994
Merged-In: I316b76b685ca5030fd8aa91283555efcce4d6994
-rw-r--r-- | services/core/java/com/android/server/wm/DisplayPolicy.java | 15 | ||||
-rw-r--r-- | services/core/java/com/android/server/wm/WindowManagerService.java | 1 |
2 files changed, 16 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java index 05875d971eb5..8a01d90bca29 100644 --- a/services/core/java/com/android/server/wm/DisplayPolicy.java +++ b/services/core/java/com/android/server/wm/DisplayPolicy.java @@ -138,6 +138,7 @@ import android.graphics.Insets; import android.graphics.PixelFormat; import android.graphics.Rect; import android.graphics.Region; +import android.gui.DropInputMode; import android.hardware.input.InputManager; import android.hardware.power.V1_0.PowerHint; import android.os.Handler; @@ -919,6 +920,20 @@ public class DisplayPolicy { } /** + * Add additional policy if needed to ensure the window or its children should not receive any + * input. + */ + public void setDropInputModePolicy(WindowState win, LayoutParams attrs) { + if (attrs.type == TYPE_TOAST + && (attrs.privateFlags & PRIVATE_FLAG_TRUSTED_OVERLAY) == 0) { + // Toasts should not receive input. These windows should not have any children, so + // force this hierarchy of windows to drop all input. + mService.mTransactionFactory.get() + .setDropInputMode(win.getSurfaceControl(), DropInputMode.ALL).apply(); + } + } + + /** * @return {@code true} if the calling activity initiate toast and is visible with * {@link WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} flag. */ diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index aa598d0cfdc6..9cf17e4ece5c 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -1650,6 +1650,7 @@ public class WindowManagerService extends IWindowManager.Stub win.mToken.addWindow(win); displayPolicy.addWindowLw(win, attrs); + displayPolicy.setDropInputModePolicy(win, win.mAttrs); if (type == TYPE_INPUT_METHOD) { displayContent.setInputMethodWindowLocked(win); imMayMove = false; |