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