diff options
| -rw-r--r-- | services/core/java/com/android/server/wm/DisplayContent.java | 16 | ||||
| -rw-r--r-- | services/tests/servicestests/src/com/android/server/wm/DisplayContentTests.java | 12 |
2 files changed, 23 insertions, 5 deletions
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index a3e80294a53c..4b939862904c 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -980,11 +980,17 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo if (prevDc == this) { return; } - if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null - && token.asAppWindowToken() == null) { - // Removed the token from the map, but made sure it's not an app token before removing - // from parent. - token.getParent().removeChild(token); + if (prevDc != null) { + if (prevDc.mTokenMap.remove(token.token) != null && token.asAppWindowToken() == null) { + // Removed the token from the map, but made sure it's not an app token before + // removing from parent. + token.getParent().removeChild(token); + } + if (prevDc.mLastFocus == mCurrentFocus) { + // The window has become the focus of this display, so it should not be notified + // that it lost focus from the previous display. + prevDc.mLastFocus = null; + } } addWindowToken(token.token, token); diff --git a/services/tests/servicestests/src/com/android/server/wm/DisplayContentTests.java b/services/tests/servicestests/src/com/android/server/wm/DisplayContentTests.java index c1655bcdb451..228ece5ab136 100644 --- a/services/tests/servicestests/src/com/android/server/wm/DisplayContentTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/DisplayContentTests.java @@ -549,6 +549,18 @@ public class DisplayContentTests extends WindowTestsBase { } @Test + public void testClearLastFocusWhenReparentingFocusedWindow() { + final DisplayContent defaultDisplay = mWm.getDefaultDisplayContentLocked(); + final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, + defaultDisplay, "window"); + defaultDisplay.mLastFocus = window; + mDisplayContent.mCurrentFocus = window; + mDisplayContent.reParentWindowToken(window.mToken); + + assertNull(defaultDisplay.mLastFocus); + } + + @Test public void testGetPreferredOptionsPanelGravityFromDifferentDisplays() { final DisplayContent portraitDisplay = createNewDisplay(); portraitDisplay.mInitialDisplayHeight = 2000; |