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