From 6ce0fb8ddbdc726d55c81a4bf797f028e441e448 Mon Sep 17 00:00:00 2001 From: Wale Ogunwale Date: Tue, 13 Dec 2016 14:24:00 -0800 Subject: [PATCH] Fixed issue with ordering of non-app token windows We tried to fix this issue in I83357975c87c704af9d0702c939ca99984462365 but the fix introduced other problems. So, we are going to have sys-ui create a separate binder for object for each type of window it adds. Long term we want to allow one binder object to map to multiple window tokens on the same display in window manager. Change-Id: Iee53b8bf95b87f79ab7a1b574a54111c678f7413 Fixes: 33567674 Fixes: 33538278 Test: bit FrameworksServicesTests:com.android.server.wm.DisplayContentTests --- .../systemui/assist/AssistManager.java | 2 + .../recents/ScreenPinningRequest.java | 2 + .../stackdivider/DividerWindowManager.java | 2 + .../statusbar/phone/PhoneStatusBar.java | 2 + .../phone/StatusBarWindowManager.java | 2 + .../com/android/server/wm/DisplayContent.java | 39 ------------------ .../server/wm/DisplayContentTests.java | 40 ++++++++++++++++++- .../android/server/wm/WindowTestsBase.java | 5 +-- 8 files changed, 51 insertions(+), 43 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java b/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java index 9eceeacc39681..3f9ae55c21845 100644 --- a/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java +++ b/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java @@ -13,6 +13,7 @@ import android.content.pm.PackageManager; import android.content.res.Resources; import android.graphics.PixelFormat; import android.os.AsyncTask; +import android.os.Binder; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; @@ -155,6 +156,7 @@ public class AssistManager { | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); + lp.token = new Binder(); if (ActivityManager.isHighEndGfx()) { lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; } diff --git a/packages/SystemUI/src/com/android/systemui/recents/ScreenPinningRequest.java b/packages/SystemUI/src/com/android/systemui/recents/ScreenPinningRequest.java index cf75c4f50bb6d..002515d10a012 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/ScreenPinningRequest.java +++ b/packages/SystemUI/src/com/android/systemui/recents/ScreenPinningRequest.java @@ -27,6 +27,7 @@ import android.content.res.Configuration; import android.graphics.PixelFormat; import android.graphics.Rect; import android.graphics.drawable.ColorDrawable; +import android.os.Binder; import android.os.RemoteException; import android.util.DisplayMetrics; import android.view.Gravity; @@ -106,6 +107,7 @@ public class ScreenPinningRequest implements View.OnClickListener { | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED , PixelFormat.TRANSLUCENT); + lp.token = new Binder(); lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; lp.setTitle("ScreenPinningConfirmation"); lp.gravity = Gravity.FILL; diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/DividerWindowManager.java b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerWindowManager.java index 3db03d0abf112..cb9453b8846ea 100644 --- a/packages/SystemUI/src/com/android/systemui/stackdivider/DividerWindowManager.java +++ b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerWindowManager.java @@ -18,6 +18,7 @@ package com.android.systemui.stackdivider; import android.content.Context; import android.graphics.PixelFormat; +import android.os.Binder; import android.view.View; import android.view.WindowManager; @@ -51,6 +52,7 @@ public class DividerWindowManager { FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL | FLAG_WATCH_OUTSIDE_TOUCH | FLAG_SPLIT_TOUCH | FLAG_SLIPPERY, PixelFormat.TRANSLUCENT); + mLp.token = new Binder(); mLp.setTitle(WINDOW_TITLE); mLp.privateFlags |= PRIVATE_FLAG_NO_MOVE_ANIMATION; view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index ae9d06888432b..252b5c91bbdc7 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -74,6 +74,7 @@ import android.media.session.MediaSessionManager; import android.media.session.PlaybackState; import android.net.Uri; import android.os.AsyncTask; +import android.os.Binder; import android.os.Bundle; import android.os.Handler; import android.os.HandlerThread; @@ -1531,6 +1532,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH | WindowManager.LayoutParams.FLAG_SLIPPERY, PixelFormat.TRANSLUCENT); + lp.token = new Binder(); // this will allow the navbar to run in an overlay on devices that support this if (ActivityManager.isHighEndGfx()) { lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java index 29c07053e169d..06600541da71a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java @@ -22,6 +22,7 @@ import android.content.Context; import android.content.pm.ActivityInfo; import android.content.res.Resources; import android.graphics.PixelFormat; +import android.os.Binder; import android.os.RemoteException; import android.os.SystemProperties; import android.os.Trace; @@ -97,6 +98,7 @@ public class StatusBarWindowManager implements RemoteInputController.Callback { | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS, PixelFormat.TRANSLUCENT); + mLp.token = new Binder(); mLp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; mLp.gravity = Gravity.TOP; mLp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 73f68f8d61b0e..203137d4d481d 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -2622,22 +2622,6 @@ class DisplayContent extends WindowContainer { - final LinkedList mTmpWindows = new LinkedList(); - - private final ToBooleanFunction mCollectWindowsInOrder = w -> { - int addIndex = mTmpWindows.size(); - for (int i = mTmpWindows.size() - 1; i >= 0; --i) { - final WindowState current = mTmpWindows.get(i); - if (w.mBaseLayer > current.mBaseLayer) { - break; - } - addIndex = i; - } - - mTmpWindows.add(addIndex, w); - return false; - }; - /** * Compares two child window tokens returns -1 if the first is lesser than the second in * terms of z-order and 1 otherwise. @@ -2668,29 +2652,6 @@ class DisplayContent extends WindowContainer callback, - boolean traverseTopToBottom) { - // Hack to work around WindowToken containing windows of various types there by causing - // the windows not to be returned in visual order if there is another token with a - // window that should be z-order in-between the windows of the first token. This is an - // issue due to the various window types sys-ui adds with its token. - // TODO: Have a separate token for each type of window sys-ui wants to add. Would - // require some changes to sys-ui on the token it uses for window creation vs. just - // using the default token of its process. - mTmpWindows.clear(); - super.forAllWindows(mCollectWindowsInOrder, false /* traverseTopToBottom */); - - while(!mTmpWindows.isEmpty()) { - final WindowState current = traverseTopToBottom - ? mTmpWindows.pollLast() : mTmpWindows.pollFirst(); - if (callback.apply(current)) { - return true; - } - } - return false; - } - @Override int getOrientation() { final WindowManagerPolicy policy = mService.mPolicy; 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 0e20c4e222534..01808cb7462d3 100644 --- a/services/tests/servicestests/src/com/android/server/wm/DisplayContentTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/DisplayContentTests.java @@ -83,7 +83,7 @@ public class DisplayContentTests extends WindowTestsBase { } @Test - public void testForAllWindows_WithImeTarget() throws Exception { + public void testForAllWindows_WithAppImeTarget() throws Exception { final WindowState imeAppTarget = createWindow(null, TYPE_BASE_APPLICATION, sDisplayContent, "imeAppTarget"); @@ -125,6 +125,44 @@ public class DisplayContentTests extends WindowTestsBase { imeAppTarget.removeImmediately(); } + @Test + public void testForAllWindows_WithStatusBarImeTarget() throws Exception { + + sWm.mInputMethodTarget = sStatusBarWindow; + + final ArrayList windows = new ArrayList(); + + // Test forward traversal. + sDisplayContent.forAllWindows(w -> {windows.add(w);}, false /* traverseTopToBottom */); + + assertEquals(sWallpaperWindow, windows.get(0)); + assertEquals(sChildAppWindowBelow, windows.get(1)); + assertEquals(sAppWindow, windows.get(2)); + assertEquals(sChildAppWindowAbove, windows.get(3)); + assertEquals(sDockedDividerWindow, windows.get(4)); + assertEquals(sStatusBarWindow, windows.get(5)); + assertEquals(sImeWindow, windows.get(6)); + assertEquals(sImeDialogWindow, windows.get(7)); + assertEquals(sNavBarWindow, windows.get(8)); + + // Test backward traversal. + windows.clear(); + sDisplayContent.forAllWindows(w -> {windows.add(w);}, true /* traverseTopToBottom */); + + assertEquals(sWallpaperWindow, windows.get(8)); + assertEquals(sChildAppWindowBelow, windows.get(7)); + assertEquals(sAppWindow, windows.get(6)); + assertEquals(sChildAppWindowAbove, windows.get(5)); + assertEquals(sDockedDividerWindow, windows.get(4)); + assertEquals(sStatusBarWindow, windows.get(3)); + assertEquals(sImeWindow, windows.get(2)); + assertEquals(sImeDialogWindow, windows.get(1)); + assertEquals(sNavBarWindow, windows.get(0)); + + // Clean-up + sWm.mInputMethodTarget = null; + } + @Test public void testForAllWindows_WithInBetweenWindowToken() throws Exception { // This window is set-up to be z-ordered between some windows that go in the same token like diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowTestsBase.java b/services/tests/servicestests/src/com/android/server/wm/WindowTestsBase.java index 05101e4b9514d..41bf646a6a1da 100644 --- a/services/tests/servicestests/src/com/android/server/wm/WindowTestsBase.java +++ b/services/tests/servicestests/src/com/android/server/wm/WindowTestsBase.java @@ -82,11 +82,10 @@ public class WindowTestsBase { sImeDialogWindow = createWindow(null, TYPE_INPUT_METHOD_DIALOG, sDisplayContent, "sImeDialogWindow"); sStatusBarWindow = createWindow(null, TYPE_STATUS_BAR, sDisplayContent, "sStatusBarWindow"); - final WindowToken statusBarToken = sStatusBarWindow.mToken; sNavBarWindow = - createWindow(null, TYPE_NAVIGATION_BAR, statusBarToken, "sNavBarWindow"); + createWindow(null, TYPE_NAVIGATION_BAR, sDisplayContent, "sNavBarWindow"); sDockedDividerWindow = - createWindow(null, TYPE_DOCK_DIVIDER, statusBarToken, "sDockedDividerWindow"); + createWindow(null, TYPE_DOCK_DIVIDER, sDisplayContent, "sDockedDividerWindow"); sAppWindow = createWindow(null, TYPE_BASE_APPLICATION, sDisplayContent, "sAppWindow"); sChildAppWindowAbove = createWindow(sAppWindow, TYPE_APPLICATION_ATTACHED_DIALOG, sAppWindow.mToken, "sChildAppWindowAbove");