blob: 96481dd83b55e2f71a79ea9bb11cd8c5ceafc1ef [file] [log] [blame]
Wale Ogunwale44fbdf52016-11-16 10:18:45 -08001/*
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
17package com.android.server.wm;
18
Jorim Jaggi829b9cd2017-01-23 16:20:53 +010019import android.app.ActivityManager.TaskDescription;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080020import android.content.res.Configuration;
21import android.graphics.Rect;
Andrii Kulian367ff7f2017-01-25 19:45:34 -080022import android.hardware.display.DisplayManagerGlobal;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080023import android.os.Binder;
Andrii Kulian367ff7f2017-01-25 19:45:34 -080024import android.view.Display;
25import android.view.DisplayInfo;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080026import android.view.IApplicationToken;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080027import org.junit.Assert;
Wale Ogunwale17f175c2017-02-07 16:54:10 -080028import org.junit.After;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080029import org.junit.Before;
Jorim Jaggi9bafc712017-01-19 17:28:30 +010030import org.mockito.MockitoAnnotations;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080031
Wale Ogunwale1666e312016-12-16 11:27:18 -080032import android.app.ActivityManager.TaskSnapshot;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080033import android.content.Context;
34import android.os.IBinder;
35import android.support.test.InstrumentationRegistry;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080036import android.view.IWindow;
37import android.view.WindowManager;
38
39import static android.app.ActivityManager.StackId.FIRST_DYNAMIC_STACK_ID;
Winson Chung83471632016-12-13 11:02:12 -080040import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080041import static android.app.AppOpsManager.OP_NONE;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080042import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080043import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080044import static android.content.res.Configuration.EMPTY;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +010045import static android.content.res.Configuration.ORIENTATION_UNDEFINED;
Andrii Kulian367ff7f2017-01-25 19:45:34 -080046import static android.view.DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080047import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
Wale Ogunwale34247952017-02-19 11:57:53 -080048import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080049import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080050import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
51import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
52import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
53import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
54import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
55import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
56import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
57import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
58import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080059import static com.android.server.wm.WindowContainer.POSITION_TOP;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080060import static org.mockito.Mockito.mock;
61
Jorim Jaggi9bafc712017-01-19 17:28:30 +010062import com.android.server.AttributeCache;
Wale Ogunwale17f175c2017-02-07 16:54:10 -080063
64import java.util.HashSet;
Wale Ogunwale34247952017-02-19 11:57:53 -080065import java.util.LinkedList;
Jorim Jaggi9bafc712017-01-19 17:28:30 +010066
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080067/**
68 * Common base class for window manager unit test classes.
69 */
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080070class WindowTestsBase {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080071 static WindowManagerService sWm = null;
Jorim Jaggi9bafc712017-01-19 17:28:30 +010072 static TestWindowManagerPolicy sPolicy = null;
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -080073 private final static IWindow sIWindow = new TestIWindow();
Jorim Jaggi9bafc712017-01-19 17:28:30 +010074 private final static Session sMockSession = mock(Session.class);
Bryce Lee310de9e2017-03-15 10:18:21 -070075 // 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 Ogunwalec5cc3012017-01-13 13:26:16 -080079 static int sNextStackId = FIRST_DYNAMIC_STACK_ID;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080080 private static int sNextTaskId = 0;
81
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080082 private static boolean sOneTimeSetupDone = false;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080083 static DisplayContent sDisplayContent;
Andrii Kulian367ff7f2017-01-25 19:45:34 -080084 static DisplayInfo sDisplayInfo = new DisplayInfo();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080085 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 Ogunwale17f175c2017-02-07 16:54:10 -080095 static HashSet<WindowState> sCommonWindows;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080096
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080097 @Before
98 public void setUp() throws Exception {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080099 if (sOneTimeSetupDone) {
100 return;
101 }
102 sOneTimeSetupDone = true;
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100103 MockitoAnnotations.initMocks(this);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800104 final Context context = InstrumentationRegistry.getTargetContext();
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100105 AttributeCache.init(context);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800106 sWm = TestWindowManagerPolicy.getWindowManagerService(context);
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100107 sPolicy = (TestWindowManagerPolicy) sWm.mPolicy;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800108 sLayersController = new WindowLayersController(sWm);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800109 sDisplayContent = sWm.mRoot.getDisplayContent(context.getDisplay().getDisplayId());
110 if (sDisplayContent != null) {
111 sDisplayContent.removeImmediately();
112 }
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800113 // 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 Jaggi9bafc712017-01-19 17:28:30 +0100122 sWm.mDisplayEnabled = true;
123 sWm.mDisplayReady = true;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800124
125 // Set-up some common windows.
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800126 sCommonWindows = new HashSet();
127 sWallpaperWindow = createCommonWindow(null, TYPE_WALLPAPER, "wallpaperWindow");
128 sImeWindow = createCommonWindow(null, TYPE_INPUT_METHOD, "sImeWindow");
Wale Ogunwale34247952017-02-19 11:57:53 -0800129 sWm.mInputMethodWindow = sImeWindow;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800130 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 Ogunwale34247952017-02-19 11:57:53 -0800143 final LinkedList<WindowState> nonCommonWindows = new LinkedList();
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800144 sWm.mRoot.forAllWindows(w -> {
145 if (!sCommonWindows.contains(w)) {
Wale Ogunwale34247952017-02-19 11:57:53 -0800146 nonCommonWindows.addLast(w);
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800147 }
148 }, true /* traverseTopToBottom */);
Wale Ogunwale34247952017-02-19 11:57:53 -0800149
150 while (!nonCommonWindows.isEmpty()) {
151 nonCommonWindows.pollLast().removeImmediately();
152 }
153
154 sWm.mInputMethodTarget = null;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800155 }
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 Ogunwale34247952017-02-19 11:57:53 -0800160 // Prevent common windows from been IMe targets
161 win.mAttrs.flags |= FLAG_NOT_FOCUSABLE;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800162 return win;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800163 }
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 Jaggi9bafc712017-01-19 17:28:30 +0100170 /**
171 * Waits until the main handler for WM has processed all messages.
172 */
173 void waitUntilHandlerIdle() {
174 sWm.mH.runWithScissors(() -> { }, 0);
175 }
176
Winson Chung83471632016-12-13 11:02:12 -0800177 private static WindowToken createWindowToken(DisplayContent dc, int stackId, int type) {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800178 if (type < FIRST_APPLICATION_WINDOW || type > LAST_APPLICATION_WINDOW) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800179 return new TestWindowToken(type, dc);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800180 }
181
Winson Chung83471632016-12-13 11:02:12 -0800182 final TaskStack stack = stackId == INVALID_STACK_ID
183 ? createTaskStackOnDisplay(dc)
184 : createStackControllerOnStackOnDisplay(stackId, dc).mContainer;
Andrii Kuliand2765632016-12-12 22:26:34 -0800185 final Task task = createTaskInStack(stack, 0 /* userId */);
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800186 final TestAppWindowToken token = new TestAppWindowToken(dc);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800187 task.addChild(token, 0);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800188 return token;
189 }
190
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100191 static WindowState createWindow(WindowState parent, int type, String name) {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800192 return (parent == null)
193 ? createWindow(parent, type, sDisplayContent, name)
194 : createWindow(parent, type, parent.mToken, name);
195 }
196
Winson Chung83471632016-12-13 11:02:12 -0800197 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 Jaggi02886a82016-12-06 09:10:06 -0800203 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 Jaggi9bafc712017-01-19 17:28:30 +0100209 static WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name) {
Winson Chung83471632016-12-13 11:02:12 -0800210 final WindowToken token = createWindowToken(dc, INVALID_STACK_ID, type);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800211 return createWindow(parent, type, token, name);
212 }
213
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800214 static WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name,
215 boolean ownerCanAddInternalSystemWindow) {
Winson Chung83471632016-12-13 11:02:12 -0800216 final WindowToken token = createWindowToken(dc, INVALID_STACK_ID, type);
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800217 return createWindow(parent, type, token, name, ownerCanAddInternalSystemWindow);
218 }
219
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100220 static WindowState createWindow(WindowState parent, int type, WindowToken token, String name) {
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800221 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 Ogunwale44fbdf52016-11-16 10:18:45 -0800226 final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type);
227 attrs.setTitle(name);
228
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -0800229 final WindowState w = new WindowState(sWm, sMockSession, sIWindow, token, parent, OP_NONE,
230 0, attrs, 0, 0, ownerCanAddInternalSystemWindow);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800231 // 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 Ogunwale3d0bfd92016-12-05 11:38:02 -0800236
Andrii Kuliand2765632016-12-12 22:26:34 -0800237 /** Creates a {@link TaskStack} and adds it to the specified {@link DisplayContent}. */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100238 static TaskStack createTaskStackOnDisplay(DisplayContent dc) {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800239 return createStackControllerOnDisplay(dc).mContainer;
240 }
241
242 static StackWindowController createStackControllerOnDisplay(DisplayContent dc) {
243 final int stackId = ++sNextStackId;
Winson Chung83471632016-12-13 11:02:12 -0800244 return createStackControllerOnStackOnDisplay(stackId, dc);
245 }
246
247 static StackWindowController createStackControllerOnStackOnDisplay(int stackId,
248 DisplayContent dc) {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800249 return new StackWindowController(stackId, null, dc.getDisplayId(),
250 true /* onTop */, new Rect(), sWm);
Andrii Kuliand2765632016-12-12 22:26:34 -0800251 }
252
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800253 /** Creates a {@link Task} and adds it to the specified {@link TaskStack}. */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100254 static Task createTaskInStack(TaskStack stack, int userId) {
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800255 final Task newTask = new Task(sNextTaskId++, stack, userId, sWm, null, EMPTY, 0, false,
256 false, new TaskDescription(), null);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800257 stack.addTask(newTask, POSITION_TOP);
Andrii Kuliand2765632016-12-12 22:26:34 -0800258 return newTask;
259 }
260
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800261 /** 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 Ogunwale3d0bfd92016-12-05 11:38:02 -0800269 /* Used so we can gain access to some protected members of the {@link WindowToken} class */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100270 static class TestWindowToken extends WindowToken {
Robert Carrdee1b3f2017-02-27 11:33:33 -0800271 int adj = 0;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800272
273 TestWindowToken(int type, DisplayContent dc) {
274 this(type, dc, false /* persistOnEmpty */);
275 }
276
277 TestWindowToken(int type, DisplayContent dc, boolean persistOnEmpty) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800278 super(sWm, mock(IBinder.class), type, persistOnEmpty, dc,
279 false /* ownerCanManageAppTokens */);
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800280 }
281
282 int getWindowsCount() {
283 return mChildren.size();
284 }
285
286 boolean hasWindow(WindowState w) {
287 return mChildren.contains(w);
288 }
Robert Carrdee1b3f2017-02-27 11:33:33 -0800289
290 @Override
291 int getAnimLayerAdjustment() {
292 return adj;
293 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800294 }
295
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800296 /** Used so we can gain access to some protected members of the {@link AppWindowToken} class. */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100297 static class TestAppWindowToken extends AppWindowToken {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800298
299 TestAppWindowToken(DisplayContent dc) {
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800300 super(sWm, null, false, dc, true /* fillsParent */);
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800301 }
302
Winson Chung30480042017-01-26 10:55:34 -0800303 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 Ogunwale3d0bfd92016-12-05 11:38:02 -0800313 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 Chung30480042017-01-26 10:55:34 -0800328
329 int positionInParent() {
330 return getParent().mChildren.indexOf(this);
331 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800332 }
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800333
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800334 /* 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 Kulian7cd7c2d2017-01-18 12:14:37 -0800338 boolean mOnDisplayChangedCalled = false;
Wale Ogunwale1666e312016-12-16 11:27:18 -0800339 private boolean mUseLocalIsAnimating = false;
340 private boolean mIsAnimating = false;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800341
342 TestTask(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800343 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 Ogunwalec5cc3012017-01-13 13:26:16 -0800347 }
348
349 boolean shouldDeferRemoval() {
350 return mShouldDeferRemoval;
351 }
352
353 int positionInParent() {
354 return getParent().mChildren.indexOf(this);
355 }
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -0800356
357 @Override
358 void onDisplayChanged(DisplayContent dc) {
359 super.onDisplayChanged(dc);
360 mOnDisplayChangedCalled = true;
361 }
Wale Ogunwale1666e312016-12-16 11:27:18 -0800362
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 Ogunwalec5cc3012017-01-13 13:26:16 -0800372 }
373
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800374 /**
375 * Used so we can gain access to some protected members of {@link TaskWindowContainerController}
376 * class.
377 */
378 class TestTaskWindowContainerController extends TaskWindowContainerController {
379
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800380 TestTaskWindowContainerController() {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800381 this(createStackControllerOnDisplay(sDisplayContent));
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800382 }
383
Wale Ogunwale1666e312016-12-16 11:27:18 -0800384 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 Chungd3395382016-12-13 11:49:09 -0800396 EMPTY /* overrideConfig*/, RESIZE_MODE_UNRESIZEABLE,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800397 false /* supportsPictureInPicture */, false /* homeTask*/, true /* toTop*/,
398 true /* showForAllUsers */, new TaskDescription(), sWm);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800399 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800400
401 @Override
402 TestTask createTask(int taskId, TaskStack stack, int userId, Rect bounds,
Winson Chungd3395382016-12-13 11:49:09 -0800403 Configuration overrideConfig, int resizeMode, boolean supportsPictureInPicture,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800404 boolean homeTask, TaskDescription taskDescription) {
405 return new TestTask(taskId, stack, userId, mService, bounds, overrideConfig, resizeMode,
406 supportsPictureInPicture, homeTask, this);
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800407 }
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 Jaggi9bafc712017-01-19 17:28:30 +0100428
Winson Chung30480042017-01-26 10:55:34 -0800429 @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 Jaggi9bafc712017-01-19 17:28:30 +0100442 AppWindowToken getAppWindowToken() {
443 return (AppWindowToken) sDisplayContent.getWindowToken(mToken.asBinder());
444 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800445 }
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 Ogunwalee1fe7fa22016-12-15 18:27:00 -0800454 }
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800455
456 /** Used to track resize reports. */
457 class TestWindowState extends WindowState {
458 boolean resizeReported;
459
460 TestWindowState(WindowManager.LayoutParams attrs, WindowToken token) {
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -0800461 super(sWm, sMockSession, sIWindow, token, null, OP_NONE, 0, attrs, 0, 0,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800462 false /* ownerCanAddInternalSystemWindow */);
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800463 }
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 Ogunwale44fbdf52016-11-16 10:18:45 -0800488}