From 0eff18732c7d3c3c7c998737f92da86d479486e9 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Fri, 1 Dec 2017 14:27:04 -0800 Subject: [PATCH] Fix support for negatively Z-ordered SubWindows. It turns out the live wallpaper picker is a copy-pasted implementation of the old version of SurfaceView which relies on TYPE_APPLICATION_MEDIA to be placed beneath the main window. This is the last user and we should aim to eliminate it by replacing the wallpaper picker with a SurfaceView or simply a Child Surface. Bug: 69928336 Bug: 70040778 Test: Manual. ZOrderingTests. Change-Id: I462b8f11954ad2e892d23164f41359a73078c21f --- .../java/com/android/server/wm/WindowState.java | 34 ++++++++++++++++------ .../src/com/android/server/wm/ZOrderingTests.java | 19 ++++++++++++ 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index c2ac905219ea..9eab61c40323 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -50,6 +50,7 @@ import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY; +import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; @@ -4331,15 +4332,6 @@ class WindowState extends WindowContainer implements WindowManagerP } } - boolean usesRelativeZOrdering() { - if (!isChildWindow()) { - return false; - } else if (mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) { - return true; - } else { - return false; - } - } @Override boolean shouldMagnify() { @@ -4414,4 +4406,28 @@ class WindowState extends WindowContainer implements WindowManagerP public boolean isDimming() { return mIsDimming; } + + // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA + // then we can drop all negative layering on the windowing side and simply inherit + // the default implementation here. + public void assignChildLayers(Transaction t) { + int layer = 1; + for (int i = 0; i < mChildren.size(); i++) { + final WindowState w = mChildren.get(i); + + // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA + // while they both need to go below the main window. However the + // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never + // been defined and so we can use static layers and leave it that way. + if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) { + w.assignLayer(t, -2); + } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) { + w.assignLayer(t, -1); + } else { + w.assignLayer(t, layer); + } + w.assignChildLayers(t); + layer++; + } + } } diff --git a/services/tests/servicestests/src/com/android/server/wm/ZOrderingTests.java b/services/tests/servicestests/src/com/android/server/wm/ZOrderingTests.java index 04f5e5e919aa..e5cbdba7b507 100644 --- a/services/tests/servicestests/src/com/android/server/wm/ZOrderingTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/ZOrderingTests.java @@ -39,6 +39,7 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; +import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY; import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; @@ -343,4 +344,22 @@ public class ZOrderingTests extends WindowTestsBase { assertWindowLayerGreaterThan(mTransaction, statusBarPanel, mStatusBarWindow); assertWindowLayerGreaterThan(mTransaction, statusBarSubPanel, statusBarPanel); } + + @Test + public void testAssignWindowLayers_ForNegativelyZOrderedSubtype() throws Exception { + // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA + // then we can drop all negative layering on the windowing side. + + final WindowState anyWindow = + createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "anyWindow"); + final WindowState child = createWindow(anyWindow, TYPE_APPLICATION_MEDIA, mDisplayContent, + "TypeApplicationMediaChild"); + final WindowState mediaOverlayChild = createWindow(anyWindow, TYPE_APPLICATION_MEDIA_OVERLAY, + mDisplayContent, "TypeApplicationMediaOverlayChild"); + + mDisplayContent.assignChildLayers(mTransaction); + + assertWindowLayerGreaterThan(mTransaction, anyWindow, mediaOverlayChild); + assertWindowLayerGreaterThan(mTransaction, mediaOverlayChild, child); + } } -- 2.11.0