From 6d1907b855667b5150895425e02349c45adcbde9 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Tue, 16 Jun 2020 22:39:27 +0800 Subject: [PATCH] Check resolved override bounds for attaching IME to activity Since the bounds restricted by fixed aspect ratio are set in resolved override bounds, the requested override bounds can be empty. And the compat display insets can be null if the size compat activity hasn't meet a configuration change. The resolved bounds should be the exact result to check whether the activity uses different bounds than its parent, otherwise IME window may attach to a letterboxed activity that leads to the unexpected offset of IME. Fixes: 157454580 Test: SizeCompatTests#testLetterboxFullscreenBoundsAndNotImeAttachable Change-Id: Ifab3bab307fc0e96400bbabe70a400a48cb06682 --- .../java/com/android/server/wm/ActivityRecord.java | 11 ++++++----- .../src/com/android/server/wm/SizeCompatTests.java | 7 +++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 5668454b7bb63..304860c2588f7 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -6456,14 +6456,15 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A @Override public boolean matchParentBounds() { - if (super.matchParentBounds() && mCompatDisplayInsets == null) { + final Rect overrideBounds = getResolvedOverrideBounds(); + if (overrideBounds.isEmpty()) { return true; } - // An activity in size compatibility mode may have resolved override bounds, so the exact - // bounds should also be checked. Otherwise IME window will show with offset. See - // {@link DisplayContent#isImeAttachedToApp}. + // An activity in size compatibility mode may have override bounds which equals to its + // parent bounds, so the exact bounds should also be checked to allow IME window to attach + // to the activity. See {@link DisplayContent#isImeAttachedToApp}. final WindowContainer parent = getParent(); - return parent == null || parent.getBounds().equals(getResolvedOverrideBounds()); + return parent == null || parent.getBounds().equals(overrideBounds); } @Override diff --git a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java index 15b395c8814e3..e742b32ff4b83 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java @@ -251,6 +251,13 @@ public class SizeCompatTests extends ActivityTestsBase { mActivity.mDisplayContent.mInputMethodTarget = addWindowToActivity(mActivity); // Make sure IME cannot attach to the app, otherwise IME window will also be shifted. assertFalse(mActivity.mDisplayContent.isImeAttachedToApp()); + + // Recompute the natural configuration without resolving size compat configuration. + mActivity.clearSizeCompatMode(); + mActivity.onConfigurationChanged(mTask.getConfiguration()); + // It should keep non-attachable because the resolved bounds will be computed according to + // the aspect ratio that won't match its parent bounds. + assertFalse(mActivity.mDisplayContent.isImeAttachedToApp()); } @Test