blob: 83926654884be51037beea52366ddc43973c19a8 [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;
Andrii Kulian367ff7f2017-01-25 19:45:34 -080045import static android.view.DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080046import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
Wale Ogunwale34247952017-02-19 11:57:53 -080047import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080048import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080049import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
50import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
51import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
52import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
53import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
54import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
55import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
56import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
57import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080058import static com.android.server.wm.WindowContainer.POSITION_TOP;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080059import static org.mockito.Mockito.mock;
60
Jorim Jaggi9bafc712017-01-19 17:28:30 +010061import com.android.server.AttributeCache;
Wale Ogunwale17f175c2017-02-07 16:54:10 -080062
63import java.util.HashSet;
Wale Ogunwale34247952017-02-19 11:57:53 -080064import java.util.LinkedList;
Jorim Jaggi9bafc712017-01-19 17:28:30 +010065
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080066/**
67 * Common base class for window manager unit test classes.
68 */
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080069class WindowTestsBase {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080070 static WindowManagerService sWm = null;
Jorim Jaggi9bafc712017-01-19 17:28:30 +010071 static TestWindowManagerPolicy sPolicy = null;
Jorim Jaggi9bafc712017-01-19 17:28:30 +010072 private final static Session sMockSession = mock(Session.class);
Andrii Kulian367ff7f2017-01-25 19:45:34 -080073 private static int sNextDisplayId = Display.DEFAULT_DISPLAY + 1;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080074 static int sNextStackId = FIRST_DYNAMIC_STACK_ID;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080075 private static int sNextTaskId = 0;
76
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080077 private static boolean sOneTimeSetupDone = false;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080078 static DisplayContent sDisplayContent;
Andrii Kulian367ff7f2017-01-25 19:45:34 -080079 static DisplayInfo sDisplayInfo = new DisplayInfo();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080080 static WindowLayersController sLayersController;
81 static WindowState sWallpaperWindow;
82 static WindowState sImeWindow;
83 static WindowState sImeDialogWindow;
84 static WindowState sStatusBarWindow;
85 static WindowState sDockedDividerWindow;
86 static WindowState sNavBarWindow;
87 static WindowState sAppWindow;
88 static WindowState sChildAppWindowAbove;
89 static WindowState sChildAppWindowBelow;
Wale Ogunwale17f175c2017-02-07 16:54:10 -080090 static HashSet<WindowState> sCommonWindows;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080091
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080092 @Before
93 public void setUp() throws Exception {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080094 if (sOneTimeSetupDone) {
95 return;
96 }
97 sOneTimeSetupDone = true;
Jorim Jaggi9bafc712017-01-19 17:28:30 +010098 MockitoAnnotations.initMocks(this);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080099 final Context context = InstrumentationRegistry.getTargetContext();
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100100 AttributeCache.init(context);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800101 sWm = TestWindowManagerPolicy.getWindowManagerService(context);
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100102 sPolicy = (TestWindowManagerPolicy) sWm.mPolicy;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800103 sLayersController = new WindowLayersController(sWm);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800104 sDisplayContent = sWm.mRoot.getDisplayContent(context.getDisplay().getDisplayId());
105 if (sDisplayContent != null) {
106 sDisplayContent.removeImmediately();
107 }
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800108 // Make sure that display ids don't overlap, so there won't be several displays with same
109 // ids among RootWindowContainer children.
110 for (DisplayContent dc : sWm.mRoot.mChildren) {
111 if (dc.getDisplayId() >= sNextDisplayId) {
112 sNextDisplayId = dc.getDisplayId() + 1;
113 }
114 }
115 context.getDisplay().getDisplayInfo(sDisplayInfo);
116 sDisplayContent = createNewDisplay();
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100117 sWm.mDisplayEnabled = true;
118 sWm.mDisplayReady = true;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800119
120 // Set-up some common windows.
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800121 sCommonWindows = new HashSet();
122 sWallpaperWindow = createCommonWindow(null, TYPE_WALLPAPER, "wallpaperWindow");
123 sImeWindow = createCommonWindow(null, TYPE_INPUT_METHOD, "sImeWindow");
Wale Ogunwale34247952017-02-19 11:57:53 -0800124 sWm.mInputMethodWindow = sImeWindow;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800125 sImeDialogWindow = createCommonWindow(null, TYPE_INPUT_METHOD_DIALOG, "sImeDialogWindow");
126 sStatusBarWindow = createCommonWindow(null, TYPE_STATUS_BAR, "sStatusBarWindow");
127 sNavBarWindow = createCommonWindow(null, TYPE_NAVIGATION_BAR, "sNavBarWindow");
128 sDockedDividerWindow = createCommonWindow(null, TYPE_DOCK_DIVIDER, "sDockedDividerWindow");
129 sAppWindow = createCommonWindow(null, TYPE_BASE_APPLICATION, "sAppWindow");
130 sChildAppWindowAbove = createCommonWindow(sAppWindow, TYPE_APPLICATION_ATTACHED_DIALOG,
131 "sChildAppWindowAbove");
132 sChildAppWindowBelow = createCommonWindow(sAppWindow, TYPE_APPLICATION_MEDIA_OVERLAY,
133 "sChildAppWindowBelow");
134 }
135
136 @After
137 public void tearDown() throws Exception {
Wale Ogunwale34247952017-02-19 11:57:53 -0800138 final LinkedList<WindowState> nonCommonWindows = new LinkedList();
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800139 sWm.mRoot.forAllWindows(w -> {
140 if (!sCommonWindows.contains(w)) {
Wale Ogunwale34247952017-02-19 11:57:53 -0800141 nonCommonWindows.addLast(w);
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800142 }
143 }, true /* traverseTopToBottom */);
Wale Ogunwale34247952017-02-19 11:57:53 -0800144
145 while (!nonCommonWindows.isEmpty()) {
146 nonCommonWindows.pollLast().removeImmediately();
147 }
148
149 sWm.mInputMethodTarget = null;
Wale Ogunwaledaab8652017-02-23 22:11:36 -0800150 sWm.mInputMethodTargetCandidate = null;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800151 }
152
153 private static WindowState createCommonWindow(WindowState parent, int type, String name) {
154 final WindowState win = createWindow(parent, type, name);
155 sCommonWindows.add(win);
Wale Ogunwale34247952017-02-19 11:57:53 -0800156 // Prevent common windows from been IMe targets
157 win.mAttrs.flags |= FLAG_NOT_FOCUSABLE;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800158 return win;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800159 }
160
Winson Chung83471632016-12-13 11:02:12 -0800161 /**
162 * Creates a window for a task on a the given {@param stackId}.
163 */
164 private WindowState createStackWindow(int stackId, String name) {
165 final StackWindowController stackController = createStackControllerOnStackOnDisplay(stackId,
166 sDisplayContent);
167 final TestTaskWindowContainerController taskController =
168 new TestTaskWindowContainerController(stackController);
169 TestAppWindowToken appWinToken = new TestAppWindowToken(sDisplayContent);
170 appWinToken.mTask = taskController.mContainer;
171 final WindowState win = createWindow(null, TYPE_BASE_APPLICATION, name);
172 win.mAppToken = appWinToken;
173 return win;
174 }
175
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800176 /** Asserts that the first entry is greater than the second entry. */
177 void assertGreaterThan(int first, int second) throws Exception {
178 Assert.assertTrue("Excepted " + first + " to be greater than " + second, first > second);
179 }
180
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100181 /**
182 * Waits until the main handler for WM has processed all messages.
183 */
184 void waitUntilHandlerIdle() {
185 sWm.mH.runWithScissors(() -> { }, 0);
186 }
187
Winson Chung83471632016-12-13 11:02:12 -0800188 private static WindowToken createWindowToken(DisplayContent dc, int stackId, int type) {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800189 if (type < FIRST_APPLICATION_WINDOW || type > LAST_APPLICATION_WINDOW) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800190 return new TestWindowToken(type, dc);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800191 }
192
Winson Chung83471632016-12-13 11:02:12 -0800193 final TaskStack stack = stackId == INVALID_STACK_ID
194 ? createTaskStackOnDisplay(dc)
195 : createStackControllerOnStackOnDisplay(stackId, dc).mContainer;
Andrii Kuliand2765632016-12-12 22:26:34 -0800196 final Task task = createTaskInStack(stack, 0 /* userId */);
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800197 final TestAppWindowToken token = new TestAppWindowToken(dc);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800198 task.addChild(token, 0);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800199 return token;
200 }
201
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100202 static WindowState createWindow(WindowState parent, int type, String name) {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800203 return (parent == null)
204 ? createWindow(parent, type, sDisplayContent, name)
205 : createWindow(parent, type, parent.mToken, name);
206 }
207
Winson Chung83471632016-12-13 11:02:12 -0800208 static WindowState createWindowOnStack(WindowState parent, int stackId, int type,
209 DisplayContent dc, String name) {
210 final WindowToken token = createWindowToken(dc, stackId, type);
211 return createWindow(parent, type, token, name);
212 }
213
Jorim Jaggi02886a82016-12-06 09:10:06 -0800214 WindowState createAppWindow(Task task, int type, String name) {
215 final AppWindowToken token = new TestAppWindowToken(sDisplayContent);
216 task.addChild(token, 0);
217 return createWindow(null, type, token, name);
218 }
219
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100220 static WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name) {
Winson Chung83471632016-12-13 11:02:12 -0800221 final WindowToken token = createWindowToken(dc, INVALID_STACK_ID, type);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800222 return createWindow(parent, type, token, name);
223 }
224
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800225 static WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name,
226 boolean ownerCanAddInternalSystemWindow) {
Winson Chung83471632016-12-13 11:02:12 -0800227 final WindowToken token = createWindowToken(dc, INVALID_STACK_ID, type);
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800228 return createWindow(parent, type, token, name, ownerCanAddInternalSystemWindow);
229 }
230
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100231 static WindowState createWindow(WindowState parent, int type, WindowToken token, String name) {
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800232 return createWindow(parent, type, token, name, false /* ownerCanAddInternalSystemWindow */);
233 }
234
235 static WindowState createWindow(WindowState parent, int type, WindowToken token, String name,
236 boolean ownerCanAddInternalSystemWindow) {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800237 final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type);
238 attrs.setTitle(name);
239
Wale Ogunwaledaab8652017-02-23 22:11:36 -0800240 final WindowState w = new WindowState(sWm, sMockSession, new TestIWindow(), token, parent,
241 OP_NONE, 0, attrs, 0, 0, ownerCanAddInternalSystemWindow);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800242 // TODO: Probably better to make this call in the WindowState ctor to avoid errors with
243 // adding it to the token...
244 token.addWindow(w);
Wale Ogunwaledaab8652017-02-23 22:11:36 -0800245 sWm.mWindowMap.put(w.mClient.asBinder(), w);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800246 return w;
247 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800248
Andrii Kuliand2765632016-12-12 22:26:34 -0800249 /** Creates a {@link TaskStack} and adds it to the specified {@link DisplayContent}. */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100250 static TaskStack createTaskStackOnDisplay(DisplayContent dc) {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800251 return createStackControllerOnDisplay(dc).mContainer;
252 }
253
254 static StackWindowController createStackControllerOnDisplay(DisplayContent dc) {
255 final int stackId = ++sNextStackId;
Winson Chung83471632016-12-13 11:02:12 -0800256 return createStackControllerOnStackOnDisplay(stackId, dc);
257 }
258
259 static StackWindowController createStackControllerOnStackOnDisplay(int stackId,
260 DisplayContent dc) {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800261 return new StackWindowController(stackId, null, dc.getDisplayId(),
262 true /* onTop */, new Rect(), sWm);
Andrii Kuliand2765632016-12-12 22:26:34 -0800263 }
264
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800265 /** Creates a {@link Task} and adds it to the specified {@link TaskStack}. */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100266 static Task createTaskInStack(TaskStack stack, int userId) {
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800267 final Task newTask = new Task(sNextTaskId++, stack, userId, sWm, null, EMPTY, 0, false,
268 false, new TaskDescription(), null);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800269 stack.addTask(newTask, POSITION_TOP);
Andrii Kuliand2765632016-12-12 22:26:34 -0800270 return newTask;
271 }
272
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800273 /** Creates a {@link DisplayContent} and adds it to the system. */
274 DisplayContent createNewDisplay() {
275 final int displayId = sNextDisplayId++;
276 final Display display = new Display(DisplayManagerGlobal.getInstance(), displayId,
277 sDisplayInfo, DEFAULT_DISPLAY_ADJUSTMENTS);
278 return new DisplayContent(display, sWm, sLayersController, new WallpaperController(sWm));
279 }
280
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800281 /* Used so we can gain access to some protected members of the {@link WindowToken} class */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100282 static class TestWindowToken extends WindowToken {
Robert Carrdee1b3f2017-02-27 11:33:33 -0800283 int adj = 0;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800284
285 TestWindowToken(int type, DisplayContent dc) {
286 this(type, dc, false /* persistOnEmpty */);
287 }
288
289 TestWindowToken(int type, DisplayContent dc, boolean persistOnEmpty) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800290 super(sWm, mock(IBinder.class), type, persistOnEmpty, dc,
291 false /* ownerCanManageAppTokens */);
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800292 }
293
294 int getWindowsCount() {
295 return mChildren.size();
296 }
297
298 boolean hasWindow(WindowState w) {
299 return mChildren.contains(w);
300 }
Robert Carrdee1b3f2017-02-27 11:33:33 -0800301
302 @Override
303 int getAnimLayerAdjustment() {
304 return adj;
305 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800306 }
307
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800308 /** Used so we can gain access to some protected members of the {@link AppWindowToken} class. */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100309 static class TestAppWindowToken extends AppWindowToken {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800310
311 TestAppWindowToken(DisplayContent dc) {
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800312 super(sWm, null, false, dc, true /* fillsParent */);
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800313 }
314
Winson Chung30480042017-01-26 10:55:34 -0800315 TestAppWindowToken(WindowManagerService service, IApplicationToken token,
316 boolean voiceInteraction, DisplayContent dc, long inputDispatchingTimeoutNanos,
317 boolean fullscreen, boolean showForAllUsers, int targetSdk, int orientation,
318 int rotationAnimationHint, int configChanges, boolean launchTaskBehind,
319 boolean alwaysFocusable, AppWindowContainerController controller) {
320 super(service, token, voiceInteraction, dc, inputDispatchingTimeoutNanos, fullscreen,
321 showForAllUsers, targetSdk, orientation, rotationAnimationHint, configChanges,
322 launchTaskBehind, alwaysFocusable, controller);
323 }
324
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800325 int getWindowsCount() {
326 return mChildren.size();
327 }
328
329 boolean hasWindow(WindowState w) {
330 return mChildren.contains(w);
331 }
332
333 WindowState getFirstChild() {
334 return mChildren.getFirst();
335 }
336
337 WindowState getLastChild() {
338 return mChildren.getLast();
339 }
Winson Chung30480042017-01-26 10:55:34 -0800340
341 int positionInParent() {
342 return getParent().mChildren.indexOf(this);
343 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800344 }
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800345
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800346 /* Used so we can gain access to some protected members of the {@link Task} class */
347 class TestTask extends Task {
348
349 boolean mShouldDeferRemoval = false;
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -0800350 boolean mOnDisplayChangedCalled = false;
Wale Ogunwale1666e312016-12-16 11:27:18 -0800351 private boolean mUseLocalIsAnimating = false;
352 private boolean mIsAnimating = false;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800353
354 TestTask(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800355 Configuration overrideConfig, int resizeMode, boolean supportsPictureInPicture,
356 boolean homeTask, TaskWindowContainerController controller) {
357 super(taskId, stack, userId, service, bounds, overrideConfig, resizeMode,
358 supportsPictureInPicture, homeTask, new TaskDescription(), controller);
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800359 }
360
361 boolean shouldDeferRemoval() {
362 return mShouldDeferRemoval;
363 }
364
365 int positionInParent() {
366 return getParent().mChildren.indexOf(this);
367 }
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -0800368
369 @Override
370 void onDisplayChanged(DisplayContent dc) {
371 super.onDisplayChanged(dc);
372 mOnDisplayChangedCalled = true;
373 }
Wale Ogunwale1666e312016-12-16 11:27:18 -0800374
375 @Override
376 boolean isAnimating() {
377 return mUseLocalIsAnimating ? mIsAnimating : super.isAnimating();
378 }
379
380 void setLocalIsAnimating(boolean isAnimating) {
381 mUseLocalIsAnimating = true;
382 mIsAnimating = isAnimating;
383 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800384 }
385
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800386 /**
387 * Used so we can gain access to some protected members of {@link TaskWindowContainerController}
388 * class.
389 */
390 class TestTaskWindowContainerController extends TaskWindowContainerController {
391
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800392 TestTaskWindowContainerController() {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800393 this(createStackControllerOnDisplay(sDisplayContent));
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800394 }
395
Wale Ogunwale1666e312016-12-16 11:27:18 -0800396 TestTaskWindowContainerController(StackWindowController stackController) {
397 super(sNextTaskId++, new TaskWindowContainerListener() {
398 @Override
399 public void onSnapshotChanged(TaskSnapshot snapshot) {
400
401 }
402
403 @Override
404 public void requestResize(Rect bounds, int resizeMode) {
405
406 }
407 }, stackController, 0 /* userId */, null /* bounds */,
Winson Chungd3395382016-12-13 11:49:09 -0800408 EMPTY /* overrideConfig*/, RESIZE_MODE_UNRESIZEABLE,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800409 false /* supportsPictureInPicture */, false /* homeTask*/, true /* toTop*/,
410 true /* showForAllUsers */, new TaskDescription(), sWm);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800411 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800412
413 @Override
414 TestTask createTask(int taskId, TaskStack stack, int userId, Rect bounds,
Winson Chungd3395382016-12-13 11:49:09 -0800415 Configuration overrideConfig, int resizeMode, boolean supportsPictureInPicture,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800416 boolean homeTask, TaskDescription taskDescription) {
417 return new TestTask(taskId, stack, userId, mService, bounds, overrideConfig, resizeMode,
418 supportsPictureInPicture, homeTask, this);
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800419 }
420 }
421
422 class TestAppWindowContainerController extends AppWindowContainerController {
423
424 final IApplicationToken mToken;
425
426 TestAppWindowContainerController(TestTaskWindowContainerController taskController) {
427 this(taskController, new TestIApplicationToken());
428 }
429
430 TestAppWindowContainerController(TestTaskWindowContainerController taskController,
431 IApplicationToken token) {
432 super(taskController, token, null /* listener */, 0 /* index */,
433 SCREEN_ORIENTATION_UNSPECIFIED, true /* fullscreen */,
434 true /* showForAllUsers */, 0 /* configChanges */, false /* voiceInteraction */,
435 false /* launchTaskBehind */, false /* alwaysFocusable */,
436 0 /* targetSdkVersion */, 0 /* rotationAnimationHint */,
437 0 /* inputDispatchingTimeoutNanos */, sWm);
438 mToken = token;
439 }
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100440
Winson Chung30480042017-01-26 10:55:34 -0800441 @Override
442 AppWindowToken createAppWindow(WindowManagerService service, IApplicationToken token,
443 boolean voiceInteraction, DisplayContent dc, long inputDispatchingTimeoutNanos,
444 boolean fullscreen, boolean showForAllUsers, int targetSdk, int orientation,
445 int rotationAnimationHint, int configChanges, boolean launchTaskBehind,
446 boolean alwaysFocusable, AppWindowContainerController controller) {
447 return new TestAppWindowToken(service, token, voiceInteraction, dc,
448 inputDispatchingTimeoutNanos, fullscreen, showForAllUsers, targetSdk,
449 orientation,
450 rotationAnimationHint, configChanges, launchTaskBehind, alwaysFocusable,
451 controller);
452 }
453
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100454 AppWindowToken getAppWindowToken() {
455 return (AppWindowToken) sDisplayContent.getWindowToken(mToken.asBinder());
456 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800457 }
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 Ogunwalee1fe7fa22016-12-15 18:27:00 -0800466 }
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800467
468 /** Used to track resize reports. */
469 class TestWindowState extends WindowState {
470 boolean resizeReported;
471
472 TestWindowState(WindowManager.LayoutParams attrs, WindowToken token) {
Wale Ogunwaledaab8652017-02-23 22:11:36 -0800473 super(sWm, sMockSession, new TestIWindow(), token, null, OP_NONE, 0, attrs, 0, 0,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800474 false /* ownerCanAddInternalSystemWindow */);
Wale Ogunwaledaab8652017-02-23 22:11:36 -0800475 sWm.mWindowMap.put(mClient.asBinder(), this);
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800476 }
477
478 @Override
479 void reportResized() {
480 super.reportResized();
481 resizeReported = true;
482 }
483
484 @Override
485 public boolean isGoneForLayoutLw() {
486 return false;
487 }
488
489 @Override
490 void updateResizingWindowIfNeeded() {
491 // Used in AppWindowTokenTests#testLandscapeSeascapeRotationRelayout to deceive
492 // the system that it can actually update the window.
493 boolean hadSurface = mHasSurface;
494 mHasSurface = true;
495
496 super.updateResizingWindowIfNeeded();
497
498 mHasSurface = hadSurface;
499 }
500 }
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800501}