From e32289b316e882057088dc651f81ab1266780571 Mon Sep 17 00:00:00 2001 From: Tarandeep Singh Date: Thu, 19 Dec 2019 17:18:12 -0800 Subject: [PATCH] Skip IME show on unsecured displays If IME is attempted to be shown on untrusted display, skip it instead of throwing exception. Split and re-use the existing WMS#shouldShowIme(displayId). Since in new Insets world, IME window show is requested by client window, INTERNAL_SYSTEM_WINDOW permission check is not required. Bug: 111084606 Test: atest CtsWindowManagerDeviceTestCases Change-Id: I3231e93b1d4cb79ef70e22cb620f5aaf50e0f3b1 --- .../server/wm/WindowManagerService.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index acaaed9b615c0..6741d2ca354f6 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -6864,21 +6864,12 @@ public class WindowManagerService extends IWindowManager.Stub if (!checkCallingPermission(INTERNAL_SYSTEM_WINDOW, "shouldShowIme()")) { throw new SecurityException("Requires INTERNAL_SYSTEM_WINDOW permission"); } - + boolean show; synchronized (mGlobalLock) { - final DisplayContent displayContent = mRoot.getDisplayContent(displayId); - if (displayContent == null) { - ProtoLog.w(WM_ERROR, - "Attempted to get IME flag of a display that does not exist: %d", - displayId); - return false; - } - if (displayContent.isUntrustedVirtualDisplay()) { - return false; - } - return mDisplayWindowSettings.shouldShowImeLocked(displayContent) - || mForceDesktopModeOnExternalDisplays; + show = shouldShowImeSystemWindowUncheckedLocked(displayId); } + + return show; } @Override @@ -7301,18 +7292,12 @@ public class WindowManagerService extends IWindowManager.Stub if (imeTarget == null) { return; } - final DisplayContent displayContent = imeTarget.getDisplayContent(); - if (displayContent == null) { - Slog.w(TAG_WM, "Attempted to show IME on an IME target that does not exist: " - + imeTarget.getName()); + final int displayId = imeTarget.getDisplayId(); + if (!shouldShowImeSystemWindowUncheckedLocked(displayId)) { return; } - if (displayContent.isUntrustedVirtualDisplay()) { - throw new SecurityException("Attempted to show IME on an untrusted " - + "virtual display: " + displayContent.getDisplayId()); - } - displayContent.getInsetsStateController().getImeSourceProvider() + mRoot.getDisplayContent(displayId).getInsetsStateController().getImeSourceProvider() .scheduleShowImePostLayout(imeTarget); } } @@ -7825,4 +7810,19 @@ public class WindowManagerService extends IWindowManager.Stub return true; } + + private boolean shouldShowImeSystemWindowUncheckedLocked(final int displayId) { + final DisplayContent displayContent = mRoot.getDisplayContent(displayId); + if (displayContent == null) { + ProtoLog.w(WM_ERROR, + "Attempted to get IME flag of a display that does not exist: %d", + displayId); + return false; + } + if (displayContent.isUntrustedVirtualDisplay()) { + return false; + } + return mDisplayWindowSettings.shouldShowImeLocked(displayContent) + || mForceDesktopModeOnExternalDisplays; + } }