Clear last focus of previous display when reparenting
Assume 2 displays:
D0 contains activities A, X
D1 contains an activity B
The update order of focus is from top to bottom. When reparenting
X from D0 to D1, and D1 becomes the top display:
1) D1: X gains focus, B loses focus
2) D0: A gains focus, X loses focus
That results the top activity X on top display 0 does not have focus
(the state in client side view root).
Bug: 119664976
Test: atest DisplayContentTests#testClearLastFocusWhenReparentingFocusedWindow
Test: atest WindowFocusTests
Change-Id: I5bf3546cde3ac6d4be45d1a971cda033663cc919
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index a3e8029..4b93986 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 @@
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);