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