Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Jorim Jaggi | 829b9cd | 2017-01-23 16:20:53 +0100 | [diff] [blame] | 19 | import android.app.ActivityManager.TaskDescription; |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 20 | import android.content.res.Configuration; |
| 21 | import android.graphics.Rect; |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 22 | import android.hardware.display.DisplayManagerGlobal; |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 23 | import android.os.Binder; |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 24 | import android.view.Display; |
| 25 | import android.view.DisplayInfo; |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 26 | import android.view.IApplicationToken; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 27 | import org.junit.Assert; |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 28 | import org.junit.After; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 29 | import org.junit.Before; |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 30 | import org.mockito.MockitoAnnotations; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 31 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 32 | import android.app.ActivityManager.TaskSnapshot; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 33 | import android.content.Context; |
| 34 | import android.os.IBinder; |
| 35 | import android.support.test.InstrumentationRegistry; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 36 | import android.view.IWindow; |
| 37 | import android.view.WindowManager; |
| 38 | |
| 39 | import static android.app.ActivityManager.StackId.FIRST_DYNAMIC_STACK_ID; |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 40 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 41 | import static android.app.AppOpsManager.OP_NONE; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 42 | import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 43 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 44 | import static android.content.res.Configuration.EMPTY; |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 45 | import static android.view.DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 46 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 47 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 48 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 49 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 50 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY; |
| 51 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 52 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
| 53 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 54 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
| 55 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; |
| 56 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
| 57 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 58 | import static com.android.server.wm.WindowContainer.POSITION_TOP; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 59 | import static org.mockito.Mockito.mock; |
| 60 | |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 61 | import com.android.server.AttributeCache; |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 62 | |
| 63 | import java.util.HashSet; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 64 | import java.util.LinkedList; |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 65 | |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 66 | /** |
| 67 | * Common base class for window manager unit test classes. |
| 68 | */ |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 69 | class WindowTestsBase { |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 70 | static WindowManagerService sWm = null; |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 71 | static TestWindowManagerPolicy sPolicy = null; |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 72 | private final static Session sMockSession = mock(Session.class); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 73 | private static int sNextDisplayId = Display.DEFAULT_DISPLAY + 1; |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 74 | static int sNextStackId = FIRST_DYNAMIC_STACK_ID; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 75 | private static int sNextTaskId = 0; |
| 76 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 77 | private static boolean sOneTimeSetupDone = false; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 78 | static DisplayContent sDisplayContent; |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 79 | static DisplayInfo sDisplayInfo = new DisplayInfo(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 80 | static WindowLayersController sLayersController; |
| 81 | static WindowState sWallpaperWindow; |
| 82 | static WindowState sImeWindow; |
| 83 | static WindowState sImeDialogWindow; |
| 84 | static WindowState sStatusBarWindow; |
| 85 | static WindowState sDockedDividerWindow; |
| 86 | static WindowState sNavBarWindow; |
| 87 | static WindowState sAppWindow; |
| 88 | static WindowState sChildAppWindowAbove; |
| 89 | static WindowState sChildAppWindowBelow; |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 90 | static HashSet<WindowState> sCommonWindows; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 91 | |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 92 | @Before |
| 93 | public void setUp() throws Exception { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 94 | if (sOneTimeSetupDone) { |
| 95 | return; |
| 96 | } |
| 97 | sOneTimeSetupDone = true; |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 98 | MockitoAnnotations.initMocks(this); |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 99 | final Context context = InstrumentationRegistry.getTargetContext(); |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 100 | AttributeCache.init(context); |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 101 | sWm = TestWindowManagerPolicy.getWindowManagerService(context); |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 102 | sPolicy = (TestWindowManagerPolicy) sWm.mPolicy; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 103 | sLayersController = new WindowLayersController(sWm); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 104 | sDisplayContent = sWm.mRoot.getDisplayContent(context.getDisplay().getDisplayId()); |
| 105 | if (sDisplayContent != null) { |
| 106 | sDisplayContent.removeImmediately(); |
| 107 | } |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 108 | // Make sure that display ids don't overlap, so there won't be several displays with same |
| 109 | // ids among RootWindowContainer children. |
| 110 | for (DisplayContent dc : sWm.mRoot.mChildren) { |
| 111 | if (dc.getDisplayId() >= sNextDisplayId) { |
| 112 | sNextDisplayId = dc.getDisplayId() + 1; |
| 113 | } |
| 114 | } |
| 115 | context.getDisplay().getDisplayInfo(sDisplayInfo); |
| 116 | sDisplayContent = createNewDisplay(); |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 117 | sWm.mDisplayEnabled = true; |
| 118 | sWm.mDisplayReady = true; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 119 | |
| 120 | // Set-up some common windows. |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 121 | sCommonWindows = new HashSet(); |
| 122 | sWallpaperWindow = createCommonWindow(null, TYPE_WALLPAPER, "wallpaperWindow"); |
| 123 | sImeWindow = createCommonWindow(null, TYPE_INPUT_METHOD, "sImeWindow"); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 124 | sWm.mInputMethodWindow = sImeWindow; |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 125 | sImeDialogWindow = createCommonWindow(null, TYPE_INPUT_METHOD_DIALOG, "sImeDialogWindow"); |
| 126 | sStatusBarWindow = createCommonWindow(null, TYPE_STATUS_BAR, "sStatusBarWindow"); |
| 127 | sNavBarWindow = createCommonWindow(null, TYPE_NAVIGATION_BAR, "sNavBarWindow"); |
| 128 | sDockedDividerWindow = createCommonWindow(null, TYPE_DOCK_DIVIDER, "sDockedDividerWindow"); |
| 129 | sAppWindow = createCommonWindow(null, TYPE_BASE_APPLICATION, "sAppWindow"); |
| 130 | sChildAppWindowAbove = createCommonWindow(sAppWindow, TYPE_APPLICATION_ATTACHED_DIALOG, |
| 131 | "sChildAppWindowAbove"); |
| 132 | sChildAppWindowBelow = createCommonWindow(sAppWindow, TYPE_APPLICATION_MEDIA_OVERLAY, |
| 133 | "sChildAppWindowBelow"); |
| 134 | } |
| 135 | |
| 136 | @After |
| 137 | public void tearDown() throws Exception { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 138 | final LinkedList<WindowState> nonCommonWindows = new LinkedList(); |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 139 | sWm.mRoot.forAllWindows(w -> { |
| 140 | if (!sCommonWindows.contains(w)) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 141 | nonCommonWindows.addLast(w); |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 142 | } |
| 143 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 144 | |
| 145 | while (!nonCommonWindows.isEmpty()) { |
| 146 | nonCommonWindows.pollLast().removeImmediately(); |
| 147 | } |
| 148 | |
| 149 | sWm.mInputMethodTarget = null; |
Wale Ogunwale | daab865 | 2017-02-23 22:11:36 -0800 | [diff] [blame] | 150 | sWm.mInputMethodTargetCandidate = null; |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | private static WindowState createCommonWindow(WindowState parent, int type, String name) { |
| 154 | final WindowState win = createWindow(parent, type, name); |
| 155 | sCommonWindows.add(win); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 156 | // Prevent common windows from been IMe targets |
| 157 | win.mAttrs.flags |= FLAG_NOT_FOCUSABLE; |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 158 | return win; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 159 | } |
| 160 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 161 | /** |
| 162 | * Creates a window for a task on a the given {@param stackId}. |
| 163 | */ |
| 164 | private WindowState createStackWindow(int stackId, String name) { |
| 165 | final StackWindowController stackController = createStackControllerOnStackOnDisplay(stackId, |
| 166 | sDisplayContent); |
| 167 | final TestTaskWindowContainerController taskController = |
| 168 | new TestTaskWindowContainerController(stackController); |
| 169 | TestAppWindowToken appWinToken = new TestAppWindowToken(sDisplayContent); |
| 170 | appWinToken.mTask = taskController.mContainer; |
| 171 | final WindowState win = createWindow(null, TYPE_BASE_APPLICATION, name); |
| 172 | win.mAppToken = appWinToken; |
| 173 | return win; |
| 174 | } |
| 175 | |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 176 | /** Asserts that the first entry is greater than the second entry. */ |
| 177 | void assertGreaterThan(int first, int second) throws Exception { |
| 178 | Assert.assertTrue("Excepted " + first + " to be greater than " + second, first > second); |
| 179 | } |
| 180 | |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 181 | /** |
| 182 | * Waits until the main handler for WM has processed all messages. |
| 183 | */ |
| 184 | void waitUntilHandlerIdle() { |
| 185 | sWm.mH.runWithScissors(() -> { }, 0); |
| 186 | } |
| 187 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 188 | private static WindowToken createWindowToken(DisplayContent dc, int stackId, int type) { |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 189 | if (type < FIRST_APPLICATION_WINDOW || type > LAST_APPLICATION_WINDOW) { |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 190 | return new TestWindowToken(type, dc); |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 191 | } |
| 192 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 193 | final TaskStack stack = stackId == INVALID_STACK_ID |
| 194 | ? createTaskStackOnDisplay(dc) |
| 195 | : createStackControllerOnStackOnDisplay(stackId, dc).mContainer; |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 196 | final Task task = createTaskInStack(stack, 0 /* userId */); |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 197 | final TestAppWindowToken token = new TestAppWindowToken(dc); |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 198 | task.addChild(token, 0); |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 199 | return token; |
| 200 | } |
| 201 | |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 202 | static WindowState createWindow(WindowState parent, int type, String name) { |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 203 | return (parent == null) |
| 204 | ? createWindow(parent, type, sDisplayContent, name) |
| 205 | : createWindow(parent, type, parent.mToken, name); |
| 206 | } |
| 207 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 208 | static WindowState createWindowOnStack(WindowState parent, int stackId, int type, |
| 209 | DisplayContent dc, String name) { |
| 210 | final WindowToken token = createWindowToken(dc, stackId, type); |
| 211 | return createWindow(parent, type, token, name); |
| 212 | } |
| 213 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 214 | WindowState createAppWindow(Task task, int type, String name) { |
| 215 | final AppWindowToken token = new TestAppWindowToken(sDisplayContent); |
| 216 | task.addChild(token, 0); |
| 217 | return createWindow(null, type, token, name); |
| 218 | } |
| 219 | |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 220 | static WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name) { |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 221 | final WindowToken token = createWindowToken(dc, INVALID_STACK_ID, type); |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 222 | return createWindow(parent, type, token, name); |
| 223 | } |
| 224 | |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 225 | static WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name, |
| 226 | boolean ownerCanAddInternalSystemWindow) { |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 227 | final WindowToken token = createWindowToken(dc, INVALID_STACK_ID, type); |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 228 | return createWindow(parent, type, token, name, ownerCanAddInternalSystemWindow); |
| 229 | } |
| 230 | |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 231 | static WindowState createWindow(WindowState parent, int type, WindowToken token, String name) { |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 232 | return createWindow(parent, type, token, name, false /* ownerCanAddInternalSystemWindow */); |
| 233 | } |
| 234 | |
| 235 | static WindowState createWindow(WindowState parent, int type, WindowToken token, String name, |
| 236 | boolean ownerCanAddInternalSystemWindow) { |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 237 | final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type); |
| 238 | attrs.setTitle(name); |
| 239 | |
Wale Ogunwale | daab865 | 2017-02-23 22:11:36 -0800 | [diff] [blame] | 240 | final WindowState w = new WindowState(sWm, sMockSession, new TestIWindow(), token, parent, |
| 241 | OP_NONE, 0, attrs, 0, 0, ownerCanAddInternalSystemWindow); |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 242 | // TODO: Probably better to make this call in the WindowState ctor to avoid errors with |
| 243 | // adding it to the token... |
| 244 | token.addWindow(w); |
Wale Ogunwale | daab865 | 2017-02-23 22:11:36 -0800 | [diff] [blame] | 245 | sWm.mWindowMap.put(w.mClient.asBinder(), w); |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 246 | return w; |
| 247 | } |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 248 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 249 | /** Creates a {@link TaskStack} and adds it to the specified {@link DisplayContent}. */ |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 250 | static TaskStack createTaskStackOnDisplay(DisplayContent dc) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 251 | return createStackControllerOnDisplay(dc).mContainer; |
| 252 | } |
| 253 | |
| 254 | static StackWindowController createStackControllerOnDisplay(DisplayContent dc) { |
| 255 | final int stackId = ++sNextStackId; |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 256 | return createStackControllerOnStackOnDisplay(stackId, dc); |
| 257 | } |
| 258 | |
| 259 | static StackWindowController createStackControllerOnStackOnDisplay(int stackId, |
| 260 | DisplayContent dc) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 261 | return new StackWindowController(stackId, null, dc.getDisplayId(), |
| 262 | true /* onTop */, new Rect(), sWm); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 263 | } |
| 264 | |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 265 | /** Creates a {@link Task} and adds it to the specified {@link TaskStack}. */ |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 266 | static Task createTaskInStack(TaskStack stack, int userId) { |
Wale Ogunwale | 069bbd3 | 2017-02-03 07:58:14 -0800 | [diff] [blame] | 267 | final Task newTask = new Task(sNextTaskId++, stack, userId, sWm, null, EMPTY, 0, false, |
| 268 | false, new TaskDescription(), null); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 269 | stack.addTask(newTask, POSITION_TOP); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 270 | return newTask; |
| 271 | } |
| 272 | |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 273 | /** Creates a {@link DisplayContent} and adds it to the system. */ |
| 274 | DisplayContent createNewDisplay() { |
| 275 | final int displayId = sNextDisplayId++; |
| 276 | final Display display = new Display(DisplayManagerGlobal.getInstance(), displayId, |
| 277 | sDisplayInfo, DEFAULT_DISPLAY_ADJUSTMENTS); |
| 278 | return new DisplayContent(display, sWm, sLayersController, new WallpaperController(sWm)); |
| 279 | } |
| 280 | |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 281 | /* Used so we can gain access to some protected members of the {@link WindowToken} class */ |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 282 | static class TestWindowToken extends WindowToken { |
Robert Carr | dee1b3f | 2017-02-27 11:33:33 -0800 | [diff] [blame^] | 283 | int adj = 0; |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 284 | |
| 285 | TestWindowToken(int type, DisplayContent dc) { |
| 286 | this(type, dc, false /* persistOnEmpty */); |
| 287 | } |
| 288 | |
| 289 | TestWindowToken(int type, DisplayContent dc, boolean persistOnEmpty) { |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 290 | super(sWm, mock(IBinder.class), type, persistOnEmpty, dc, |
| 291 | false /* ownerCanManageAppTokens */); |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | int getWindowsCount() { |
| 295 | return mChildren.size(); |
| 296 | } |
| 297 | |
| 298 | boolean hasWindow(WindowState w) { |
| 299 | return mChildren.contains(w); |
| 300 | } |
Robert Carr | dee1b3f | 2017-02-27 11:33:33 -0800 | [diff] [blame^] | 301 | |
| 302 | @Override |
| 303 | int getAnimLayerAdjustment() { |
| 304 | return adj; |
| 305 | } |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 306 | } |
| 307 | |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 308 | /** Used so we can gain access to some protected members of the {@link AppWindowToken} class. */ |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 309 | static class TestAppWindowToken extends AppWindowToken { |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 310 | |
| 311 | TestAppWindowToken(DisplayContent dc) { |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 312 | super(sWm, null, false, dc, true /* fillsParent */); |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 315 | TestAppWindowToken(WindowManagerService service, IApplicationToken token, |
| 316 | boolean voiceInteraction, DisplayContent dc, long inputDispatchingTimeoutNanos, |
| 317 | boolean fullscreen, boolean showForAllUsers, int targetSdk, int orientation, |
| 318 | int rotationAnimationHint, int configChanges, boolean launchTaskBehind, |
| 319 | boolean alwaysFocusable, AppWindowContainerController controller) { |
| 320 | super(service, token, voiceInteraction, dc, inputDispatchingTimeoutNanos, fullscreen, |
| 321 | showForAllUsers, targetSdk, orientation, rotationAnimationHint, configChanges, |
| 322 | launchTaskBehind, alwaysFocusable, controller); |
| 323 | } |
| 324 | |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 325 | int getWindowsCount() { |
| 326 | return mChildren.size(); |
| 327 | } |
| 328 | |
| 329 | boolean hasWindow(WindowState w) { |
| 330 | return mChildren.contains(w); |
| 331 | } |
| 332 | |
| 333 | WindowState getFirstChild() { |
| 334 | return mChildren.getFirst(); |
| 335 | } |
| 336 | |
| 337 | WindowState getLastChild() { |
| 338 | return mChildren.getLast(); |
| 339 | } |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 340 | |
| 341 | int positionInParent() { |
| 342 | return getParent().mChildren.indexOf(this); |
| 343 | } |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 344 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 345 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 346 | /* Used so we can gain access to some protected members of the {@link Task} class */ |
| 347 | class TestTask extends Task { |
| 348 | |
| 349 | boolean mShouldDeferRemoval = false; |
Andrii Kulian | 7cd7c2d | 2017-01-18 12:14:37 -0800 | [diff] [blame] | 350 | boolean mOnDisplayChangedCalled = false; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 351 | private boolean mUseLocalIsAnimating = false; |
| 352 | private boolean mIsAnimating = false; |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 353 | |
| 354 | TestTask(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds, |
Wale Ogunwale | 069bbd3 | 2017-02-03 07:58:14 -0800 | [diff] [blame] | 355 | Configuration overrideConfig, int resizeMode, boolean supportsPictureInPicture, |
| 356 | boolean homeTask, TaskWindowContainerController controller) { |
| 357 | super(taskId, stack, userId, service, bounds, overrideConfig, resizeMode, |
| 358 | supportsPictureInPicture, homeTask, new TaskDescription(), controller); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | boolean shouldDeferRemoval() { |
| 362 | return mShouldDeferRemoval; |
| 363 | } |
| 364 | |
| 365 | int positionInParent() { |
| 366 | return getParent().mChildren.indexOf(this); |
| 367 | } |
Andrii Kulian | 7cd7c2d | 2017-01-18 12:14:37 -0800 | [diff] [blame] | 368 | |
| 369 | @Override |
| 370 | void onDisplayChanged(DisplayContent dc) { |
| 371 | super.onDisplayChanged(dc); |
| 372 | mOnDisplayChangedCalled = true; |
| 373 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 374 | |
| 375 | @Override |
| 376 | boolean isAnimating() { |
| 377 | return mUseLocalIsAnimating ? mIsAnimating : super.isAnimating(); |
| 378 | } |
| 379 | |
| 380 | void setLocalIsAnimating(boolean isAnimating) { |
| 381 | mUseLocalIsAnimating = true; |
| 382 | mIsAnimating = isAnimating; |
| 383 | } |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 384 | } |
| 385 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 386 | /** |
| 387 | * Used so we can gain access to some protected members of {@link TaskWindowContainerController} |
| 388 | * class. |
| 389 | */ |
| 390 | class TestTaskWindowContainerController extends TaskWindowContainerController { |
| 391 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 392 | TestTaskWindowContainerController() { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 393 | this(createStackControllerOnDisplay(sDisplayContent)); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 394 | } |
| 395 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 396 | TestTaskWindowContainerController(StackWindowController stackController) { |
| 397 | super(sNextTaskId++, new TaskWindowContainerListener() { |
| 398 | @Override |
| 399 | public void onSnapshotChanged(TaskSnapshot snapshot) { |
| 400 | |
| 401 | } |
| 402 | |
| 403 | @Override |
| 404 | public void requestResize(Rect bounds, int resizeMode) { |
| 405 | |
| 406 | } |
| 407 | }, stackController, 0 /* userId */, null /* bounds */, |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 408 | EMPTY /* overrideConfig*/, RESIZE_MODE_UNRESIZEABLE, |
Wale Ogunwale | 069bbd3 | 2017-02-03 07:58:14 -0800 | [diff] [blame] | 409 | false /* supportsPictureInPicture */, false /* homeTask*/, true /* toTop*/, |
| 410 | true /* showForAllUsers */, new TaskDescription(), sWm); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 411 | } |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 412 | |
| 413 | @Override |
| 414 | TestTask createTask(int taskId, TaskStack stack, int userId, Rect bounds, |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 415 | Configuration overrideConfig, int resizeMode, boolean supportsPictureInPicture, |
Wale Ogunwale | 069bbd3 | 2017-02-03 07:58:14 -0800 | [diff] [blame] | 416 | boolean homeTask, TaskDescription taskDescription) { |
| 417 | return new TestTask(taskId, stack, userId, mService, bounds, overrideConfig, resizeMode, |
| 418 | supportsPictureInPicture, homeTask, this); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | |
| 422 | class TestAppWindowContainerController extends AppWindowContainerController { |
| 423 | |
| 424 | final IApplicationToken mToken; |
| 425 | |
| 426 | TestAppWindowContainerController(TestTaskWindowContainerController taskController) { |
| 427 | this(taskController, new TestIApplicationToken()); |
| 428 | } |
| 429 | |
| 430 | TestAppWindowContainerController(TestTaskWindowContainerController taskController, |
| 431 | IApplicationToken token) { |
| 432 | super(taskController, token, null /* listener */, 0 /* index */, |
| 433 | SCREEN_ORIENTATION_UNSPECIFIED, true /* fullscreen */, |
| 434 | true /* showForAllUsers */, 0 /* configChanges */, false /* voiceInteraction */, |
| 435 | false /* launchTaskBehind */, false /* alwaysFocusable */, |
| 436 | 0 /* targetSdkVersion */, 0 /* rotationAnimationHint */, |
| 437 | 0 /* inputDispatchingTimeoutNanos */, sWm); |
| 438 | mToken = token; |
| 439 | } |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 440 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 441 | @Override |
| 442 | AppWindowToken createAppWindow(WindowManagerService service, IApplicationToken token, |
| 443 | boolean voiceInteraction, DisplayContent dc, long inputDispatchingTimeoutNanos, |
| 444 | boolean fullscreen, boolean showForAllUsers, int targetSdk, int orientation, |
| 445 | int rotationAnimationHint, int configChanges, boolean launchTaskBehind, |
| 446 | boolean alwaysFocusable, AppWindowContainerController controller) { |
| 447 | return new TestAppWindowToken(service, token, voiceInteraction, dc, |
| 448 | inputDispatchingTimeoutNanos, fullscreen, showForAllUsers, targetSdk, |
| 449 | orientation, |
| 450 | rotationAnimationHint, configChanges, launchTaskBehind, alwaysFocusable, |
| 451 | controller); |
| 452 | } |
| 453 | |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 454 | AppWindowToken getAppWindowToken() { |
| 455 | return (AppWindowToken) sDisplayContent.getWindowToken(mToken.asBinder()); |
| 456 | } |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | class TestIApplicationToken implements IApplicationToken { |
| 460 | |
| 461 | private final Binder mBinder = new Binder(); |
| 462 | @Override |
| 463 | public IBinder asBinder() { |
| 464 | return mBinder; |
| 465 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 466 | } |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 467 | |
| 468 | /** Used to track resize reports. */ |
| 469 | class TestWindowState extends WindowState { |
| 470 | boolean resizeReported; |
| 471 | |
| 472 | TestWindowState(WindowManager.LayoutParams attrs, WindowToken token) { |
Wale Ogunwale | daab865 | 2017-02-23 22:11:36 -0800 | [diff] [blame] | 473 | super(sWm, sMockSession, new TestIWindow(), token, null, OP_NONE, 0, attrs, 0, 0, |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 474 | false /* ownerCanAddInternalSystemWindow */); |
Wale Ogunwale | daab865 | 2017-02-23 22:11:36 -0800 | [diff] [blame] | 475 | sWm.mWindowMap.put(mClient.asBinder(), this); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | @Override |
| 479 | void reportResized() { |
| 480 | super.reportResized(); |
| 481 | resizeReported = true; |
| 482 | } |
| 483 | |
| 484 | @Override |
| 485 | public boolean isGoneForLayoutLw() { |
| 486 | return false; |
| 487 | } |
| 488 | |
| 489 | @Override |
| 490 | void updateResizingWindowIfNeeded() { |
| 491 | // Used in AppWindowTokenTests#testLandscapeSeascapeRotationRelayout to deceive |
| 492 | // the system that it can actually update the window. |
| 493 | boolean hadSurface = mHasSurface; |
| 494 | mHasSurface = true; |
| 495 | |
| 496 | super.updateResizingWindowIfNeeded(); |
| 497 | |
| 498 | mHasSurface = hadSurface; |
| 499 | } |
| 500 | } |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 501 | } |