OSDN Git Service

Update displayId when a window is moved to a new display
authorBrad Stenning <stenning@google.com>
Mon, 2 Apr 2018 19:03:19 +0000 (12:03 -0700)
committerBrad Stenning <stenning@google.com>
Tue, 3 Apr 2018 04:04:51 +0000 (21:04 -0700)
Bug:77474140

Test: Unit or use a single instance app and move it from and activity view to display 0
Change-Id: I780c5af3b9d46d6f67271a100f378a6a51435aff

services/core/java/com/android/server/input/InputWindowHandle.java
services/core/java/com/android/server/wm/WindowState.java
services/tests/servicestests/src/com/android/server/wm/WindowStateTests.java

index 3d6f7ad..720eaaa 100644 (file)
@@ -92,7 +92,7 @@ public final class InputWindowHandle {
     public int inputFeatures;
 
     // Display this input is on.
-    public final int displayId;
+    public int displayId;
 
     private native void nativeDispose();
 
index 30bbfe0..3e9dcdd 100644 (file)
@@ -178,6 +178,7 @@ import android.util.MergedConfiguration;
 import android.util.Slog;
 import android.util.TimeUtils;
 import android.util.proto.ProtoOutputStream;
+import android.view.Display;
 import android.view.DisplayCutout;
 import android.view.DisplayInfo;
 import android.view.Gravity;
@@ -1366,6 +1367,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
         // Window was not laid out for this display yet, so make sure mLayoutSeq does not match.
         if (dc != null) {
             mLayoutSeq = dc.mLayoutSeq - 1;
+            mInputWindowHandle.displayId = dc.getDisplayId();
         }
     }
 
@@ -1378,7 +1380,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
     public int getDisplayId() {
         final DisplayContent displayContent = getDisplayContent();
         if (displayContent == null) {
-            return -1;
+            return Display.INVALID_DISPLAY;
         }
         return displayContent.getDisplayId();
     }
index 1248eae..7c928c9 100644 (file)
@@ -326,6 +326,17 @@ public class WindowStateTests extends WindowTestsBase {
         assertThat(app.mLayoutSeq, not(is(mDisplayContent.mLayoutSeq)));
     }
 
+    @Test
+    public void testDisplayIdUpdatedOnReparent() throws Exception {
+        final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
+        // fake a different display
+        app.mInputWindowHandle.displayId = mDisplayContent.getDisplayId() + 1;
+        app.onDisplayChanged(mDisplayContent);
+
+        assertThat(app.mInputWindowHandle.displayId, is(mDisplayContent.getDisplayId()));
+        assertThat(app.getDisplayId(), is(mDisplayContent.getDisplayId()));
+    }
+
     private void testPrepareWindowToDisplayDuringRelayout(boolean wasVisible) {
         reset(mPowerManagerWrapper);
         final WindowState root = createWindow(null, TYPE_APPLICATION, "root");