blob: 48799d23c06e68ead16d2afdd1264a19e782f75f [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
Bryce Lee6272c7f2017-03-17 17:22:35 -070077 // added display should be treated as default. This cannot be the default display
78 private static int sNextDisplayId = Display.DEFAULT_DISPLAY + 1;
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);
Bryce Lee6272c7f2017-03-17 17:22:35 -0700109
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800110 // Make sure that display ids don't overlap, so there won't be several displays with same
111 // ids among RootWindowContainer children.
112 for (DisplayContent dc : sWm.mRoot.mChildren) {
113 if (dc.getDisplayId() >= sNextDisplayId) {
114 sNextDisplayId = dc.getDisplayId() + 1;
115 }
Bryce Lee6272c7f2017-03-17 17:22:35 -0700116
117 // The default display must be preserved as some tests require it to function
118 // (such as policy rotation).
119 if (dc.getDisplayId() != Display.DEFAULT_DISPLAY) {
120 // It is safe to remove these displays as new displays will always be created with
121 // new ids.
122 dc.removeImmediately();
123 }
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800124 }
Bryce Lee6272c7f2017-03-17 17:22:35 -0700125
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800126 context.getDisplay().getDisplayInfo(sDisplayInfo);
127 sDisplayContent = createNewDisplay();
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100128 sWm.mDisplayEnabled = true;
129 sWm.mDisplayReady = true;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800130
131 // Set-up some common windows.
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800132 sCommonWindows = new HashSet();
133 sWallpaperWindow = createCommonWindow(null, TYPE_WALLPAPER, "wallpaperWindow");
134 sImeWindow = createCommonWindow(null, TYPE_INPUT_METHOD, "sImeWindow");
Wale Ogunwale34247952017-02-19 11:57:53 -0800135 sWm.mInputMethodWindow = sImeWindow;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800136 sImeDialogWindow = createCommonWindow(null, TYPE_INPUT_METHOD_DIALOG, "sImeDialogWindow");
137 sStatusBarWindow = createCommonWindow(null, TYPE_STATUS_BAR, "sStatusBarWindow");
138 sNavBarWindow = createCommonWindow(null, TYPE_NAVIGATION_BAR, "sNavBarWindow");
139 sDockedDividerWindow = createCommonWindow(null, TYPE_DOCK_DIVIDER, "sDockedDividerWindow");
140 sAppWindow = createCommonWindow(null, TYPE_BASE_APPLICATION, "sAppWindow");
141 sChildAppWindowAbove = createCommonWindow(sAppWindow, TYPE_APPLICATION_ATTACHED_DIALOG,
142 "sChildAppWindowAbove");
143 sChildAppWindowBelow = createCommonWindow(sAppWindow, TYPE_APPLICATION_MEDIA_OVERLAY,
144 "sChildAppWindowBelow");
145 }
146
147 @After
148 public void tearDown() throws Exception {
Wale Ogunwale34247952017-02-19 11:57:53 -0800149 final LinkedList<WindowState> nonCommonWindows = new LinkedList();
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800150 sWm.mRoot.forAllWindows(w -> {
151 if (!sCommonWindows.contains(w)) {
Wale Ogunwale34247952017-02-19 11:57:53 -0800152 nonCommonWindows.addLast(w);
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800153 }
154 }, true /* traverseTopToBottom */);
Wale Ogunwale34247952017-02-19 11:57:53 -0800155
156 while (!nonCommonWindows.isEmpty()) {
157 nonCommonWindows.pollLast().removeImmediately();
158 }
159
160 sWm.mInputMethodTarget = null;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800161 }
162
163 private static WindowState createCommonWindow(WindowState parent, int type, String name) {
164 final WindowState win = createWindow(parent, type, name);
165 sCommonWindows.add(win);
Wale Ogunwale34247952017-02-19 11:57:53 -0800166 // Prevent common windows from been IMe targets
167 win.mAttrs.flags |= FLAG_NOT_FOCUSABLE;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800168 return win;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800169 }
170
171 /** Asserts that the first entry is greater than the second entry. */
172 void assertGreaterThan(int first, int second) throws Exception {
173 Assert.assertTrue("Excepted " + first + " to be greater than " + second, first > second);
174 }
175
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100176 /**
177 * Waits until the main handler for WM has processed all messages.
178 */
179 void waitUntilHandlerIdle() {
180 sWm.mH.runWithScissors(() -> { }, 0);
181 }
182
Winson Chung83471632016-12-13 11:02:12 -0800183 private static WindowToken createWindowToken(DisplayContent dc, int stackId, int type) {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800184 if (type < FIRST_APPLICATION_WINDOW || type > LAST_APPLICATION_WINDOW) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800185 return new TestWindowToken(type, dc);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800186 }
187
Winson Chung83471632016-12-13 11:02:12 -0800188 final TaskStack stack = stackId == INVALID_STACK_ID
189 ? createTaskStackOnDisplay(dc)
190 : createStackControllerOnStackOnDisplay(stackId, dc).mContainer;
Andrii Kuliand2765632016-12-12 22:26:34 -0800191 final Task task = createTaskInStack(stack, 0 /* userId */);
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800192 final TestAppWindowToken token = new TestAppWindowToken(dc);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800193 task.addChild(token, 0);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800194 return token;
195 }
196
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100197 static WindowState createWindow(WindowState parent, int type, String name) {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800198 return (parent == null)
199 ? createWindow(parent, type, sDisplayContent, name)
200 : createWindow(parent, type, parent.mToken, name);
201 }
202
Winson Chung83471632016-12-13 11:02:12 -0800203 static WindowState createWindowOnStack(WindowState parent, int stackId, int type,
204 DisplayContent dc, String name) {
205 final WindowToken token = createWindowToken(dc, stackId, type);
206 return createWindow(parent, type, token, name);
207 }
208
Jorim Jaggi02886a82016-12-06 09:10:06 -0800209 WindowState createAppWindow(Task task, int type, String name) {
210 final AppWindowToken token = new TestAppWindowToken(sDisplayContent);
211 task.addChild(token, 0);
212 return createWindow(null, type, token, name);
213 }
214
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100215 static WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name) {
Winson Chung83471632016-12-13 11:02:12 -0800216 final WindowToken token = createWindowToken(dc, INVALID_STACK_ID, type);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800217 return createWindow(parent, type, token, name);
218 }
219
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800220 static WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name,
221 boolean ownerCanAddInternalSystemWindow) {
Winson Chung83471632016-12-13 11:02:12 -0800222 final WindowToken token = createWindowToken(dc, INVALID_STACK_ID, type);
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800223 return createWindow(parent, type, token, name, ownerCanAddInternalSystemWindow);
224 }
225
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100226 static WindowState createWindow(WindowState parent, int type, WindowToken token, String name) {
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800227 return createWindow(parent, type, token, name, false /* ownerCanAddInternalSystemWindow */);
228 }
229
230 static WindowState createWindow(WindowState parent, int type, WindowToken token, String name,
231 boolean ownerCanAddInternalSystemWindow) {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800232 final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type);
233 attrs.setTitle(name);
234
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -0800235 final WindowState w = new WindowState(sWm, sMockSession, sIWindow, token, parent, OP_NONE,
236 0, attrs, 0, 0, ownerCanAddInternalSystemWindow);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800237 // TODO: Probably better to make this call in the WindowState ctor to avoid errors with
238 // adding it to the token...
239 token.addWindow(w);
240 return w;
241 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800242
Andrii Kuliand2765632016-12-12 22:26:34 -0800243 /** Creates a {@link TaskStack} and adds it to the specified {@link DisplayContent}. */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100244 static TaskStack createTaskStackOnDisplay(DisplayContent dc) {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800245 return createStackControllerOnDisplay(dc).mContainer;
246 }
247
248 static StackWindowController createStackControllerOnDisplay(DisplayContent dc) {
249 final int stackId = ++sNextStackId;
Winson Chung83471632016-12-13 11:02:12 -0800250 return createStackControllerOnStackOnDisplay(stackId, dc);
251 }
252
253 static StackWindowController createStackControllerOnStackOnDisplay(int stackId,
254 DisplayContent dc) {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800255 return new StackWindowController(stackId, null, dc.getDisplayId(),
256 true /* onTop */, new Rect(), sWm);
Andrii Kuliand2765632016-12-12 22:26:34 -0800257 }
258
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800259 /** Creates a {@link Task} and adds it to the specified {@link TaskStack}. */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100260 static Task createTaskInStack(TaskStack stack, int userId) {
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800261 final Task newTask = new Task(sNextTaskId++, stack, userId, sWm, null, EMPTY, 0, false,
262 false, new TaskDescription(), null);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800263 stack.addTask(newTask, POSITION_TOP);
Andrii Kuliand2765632016-12-12 22:26:34 -0800264 return newTask;
265 }
266
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800267 /** Creates a {@link DisplayContent} and adds it to the system. */
268 DisplayContent createNewDisplay() {
269 final int displayId = sNextDisplayId++;
270 final Display display = new Display(DisplayManagerGlobal.getInstance(), displayId,
271 sDisplayInfo, DEFAULT_DISPLAY_ADJUSTMENTS);
272 return new DisplayContent(display, sWm, sLayersController, new WallpaperController(sWm));
273 }
274
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800275 /* Used so we can gain access to some protected members of the {@link WindowToken} class */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100276 static class TestWindowToken extends WindowToken {
Robert Carrdee1b3f2017-02-27 11:33:33 -0800277 int adj = 0;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800278
279 TestWindowToken(int type, DisplayContent dc) {
280 this(type, dc, false /* persistOnEmpty */);
281 }
282
283 TestWindowToken(int type, DisplayContent dc, boolean persistOnEmpty) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800284 super(sWm, mock(IBinder.class), type, persistOnEmpty, dc,
285 false /* ownerCanManageAppTokens */);
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800286 }
287
288 int getWindowsCount() {
289 return mChildren.size();
290 }
291
292 boolean hasWindow(WindowState w) {
293 return mChildren.contains(w);
294 }
Robert Carrdee1b3f2017-02-27 11:33:33 -0800295
296 @Override
297 int getAnimLayerAdjustment() {
298 return adj;
299 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800300 }
301
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800302 /** Used so we can gain access to some protected members of the {@link AppWindowToken} class. */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100303 static class TestAppWindowToken extends AppWindowToken {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800304
305 TestAppWindowToken(DisplayContent dc) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700306 super(sWm, null, false, dc, true /* fillsParent */, null /* overrideConfig */,
307 null /* bounds */);
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800308 }
309
Winson Chung30480042017-01-26 10:55:34 -0800310 TestAppWindowToken(WindowManagerService service, IApplicationToken token,
311 boolean voiceInteraction, DisplayContent dc, long inputDispatchingTimeoutNanos,
312 boolean fullscreen, boolean showForAllUsers, int targetSdk, int orientation,
313 int rotationAnimationHint, int configChanges, boolean launchTaskBehind,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700314 boolean alwaysFocusable, AppWindowContainerController controller,
315 Configuration overrideConfig, Rect bounds) {
Winson Chung30480042017-01-26 10:55:34 -0800316 super(service, token, voiceInteraction, dc, inputDispatchingTimeoutNanos, fullscreen,
317 showForAllUsers, targetSdk, orientation, rotationAnimationHint, configChanges,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700318 launchTaskBehind, alwaysFocusable, controller, overrideConfig, bounds);
Winson Chung30480042017-01-26 10:55:34 -0800319 }
320
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800321 int getWindowsCount() {
322 return mChildren.size();
323 }
324
325 boolean hasWindow(WindowState w) {
326 return mChildren.contains(w);
327 }
328
329 WindowState getFirstChild() {
330 return mChildren.getFirst();
331 }
332
333 WindowState getLastChild() {
334 return mChildren.getLast();
335 }
Winson Chung30480042017-01-26 10:55:34 -0800336
337 int positionInParent() {
338 return getParent().mChildren.indexOf(this);
339 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800340 }
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800341
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800342 /* Used so we can gain access to some protected members of the {@link Task} class */
343 class TestTask extends Task {
344
345 boolean mShouldDeferRemoval = false;
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -0800346 boolean mOnDisplayChangedCalled = false;
Wale Ogunwale1666e312016-12-16 11:27:18 -0800347 private boolean mUseLocalIsAnimating = false;
348 private boolean mIsAnimating = false;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800349
350 TestTask(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800351 Configuration overrideConfig, int resizeMode, boolean supportsPictureInPicture,
352 boolean homeTask, TaskWindowContainerController controller) {
353 super(taskId, stack, userId, service, bounds, overrideConfig, resizeMode,
354 supportsPictureInPicture, homeTask, new TaskDescription(), controller);
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800355 }
356
357 boolean shouldDeferRemoval() {
358 return mShouldDeferRemoval;
359 }
360
361 int positionInParent() {
362 return getParent().mChildren.indexOf(this);
363 }
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -0800364
365 @Override
366 void onDisplayChanged(DisplayContent dc) {
367 super.onDisplayChanged(dc);
368 mOnDisplayChangedCalled = true;
369 }
Wale Ogunwale1666e312016-12-16 11:27:18 -0800370
371 @Override
372 boolean isAnimating() {
373 return mUseLocalIsAnimating ? mIsAnimating : super.isAnimating();
374 }
375
376 void setLocalIsAnimating(boolean isAnimating) {
377 mUseLocalIsAnimating = true;
378 mIsAnimating = isAnimating;
379 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800380 }
381
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800382 /**
383 * Used so we can gain access to some protected members of {@link TaskWindowContainerController}
384 * class.
385 */
386 class TestTaskWindowContainerController extends TaskWindowContainerController {
387
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800388 TestTaskWindowContainerController() {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800389 this(createStackControllerOnDisplay(sDisplayContent));
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800390 }
391
Wale Ogunwale1666e312016-12-16 11:27:18 -0800392 TestTaskWindowContainerController(StackWindowController stackController) {
393 super(sNextTaskId++, new TaskWindowContainerListener() {
394 @Override
395 public void onSnapshotChanged(TaskSnapshot snapshot) {
396
397 }
398
399 @Override
400 public void requestResize(Rect bounds, int resizeMode) {
401
402 }
403 }, stackController, 0 /* userId */, null /* bounds */,
Winson Chungd3395382016-12-13 11:49:09 -0800404 EMPTY /* overrideConfig*/, RESIZE_MODE_UNRESIZEABLE,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800405 false /* supportsPictureInPicture */, false /* homeTask*/, true /* toTop*/,
406 true /* showForAllUsers */, new TaskDescription(), sWm);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800407 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800408
409 @Override
410 TestTask createTask(int taskId, TaskStack stack, int userId, Rect bounds,
Winson Chungd3395382016-12-13 11:49:09 -0800411 Configuration overrideConfig, int resizeMode, boolean supportsPictureInPicture,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800412 boolean homeTask, TaskDescription taskDescription) {
413 return new TestTask(taskId, stack, userId, mService, bounds, overrideConfig, resizeMode,
414 supportsPictureInPicture, homeTask, this);
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800415 }
416 }
417
418 class TestAppWindowContainerController extends AppWindowContainerController {
419
420 final IApplicationToken mToken;
421
422 TestAppWindowContainerController(TestTaskWindowContainerController taskController) {
423 this(taskController, new TestIApplicationToken());
424 }
425
426 TestAppWindowContainerController(TestTaskWindowContainerController taskController,
427 IApplicationToken token) {
428 super(taskController, token, null /* listener */, 0 /* index */,
429 SCREEN_ORIENTATION_UNSPECIFIED, true /* fullscreen */,
430 true /* showForAllUsers */, 0 /* configChanges */, false /* voiceInteraction */,
431 false /* launchTaskBehind */, false /* alwaysFocusable */,
432 0 /* targetSdkVersion */, 0 /* rotationAnimationHint */,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700433 0 /* inputDispatchingTimeoutNanos */, sWm, null /* overrideConfig */,
434 null /* bounds */);
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800435 mToken = token;
436 }
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100437
Winson Chung30480042017-01-26 10:55:34 -0800438 @Override
439 AppWindowToken createAppWindow(WindowManagerService service, IApplicationToken token,
440 boolean voiceInteraction, DisplayContent dc, long inputDispatchingTimeoutNanos,
441 boolean fullscreen, boolean showForAllUsers, int targetSdk, int orientation,
442 int rotationAnimationHint, int configChanges, boolean launchTaskBehind,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700443 boolean alwaysFocusable, AppWindowContainerController controller,
444 Configuration overrideConfig, Rect bounds) {
Winson Chung30480042017-01-26 10:55:34 -0800445 return new TestAppWindowToken(service, token, voiceInteraction, dc,
446 inputDispatchingTimeoutNanos, fullscreen, showForAllUsers, targetSdk,
447 orientation,
448 rotationAnimationHint, configChanges, launchTaskBehind, alwaysFocusable,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700449 controller, overrideConfig, bounds);
Winson Chung30480042017-01-26 10:55:34 -0800450 }
451
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100452 AppWindowToken getAppWindowToken() {
453 return (AppWindowToken) sDisplayContent.getWindowToken(mToken.asBinder());
454 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800455 }
456
457 class TestIApplicationToken implements IApplicationToken {
458
459 private final Binder mBinder = new Binder();
460 @Override
461 public IBinder asBinder() {
462 return mBinder;
463 }
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800464 }
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800465
466 /** Used to track resize reports. */
467 class TestWindowState extends WindowState {
468 boolean resizeReported;
469
470 TestWindowState(WindowManager.LayoutParams attrs, WindowToken token) {
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -0800471 super(sWm, sMockSession, sIWindow, token, null, OP_NONE, 0, attrs, 0, 0,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800472 false /* ownerCanAddInternalSystemWindow */);
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800473 }
474
475 @Override
476 void reportResized() {
477 super.reportResized();
478 resizeReported = true;
479 }
480
481 @Override
482 public boolean isGoneForLayoutLw() {
483 return false;
484 }
485
486 @Override
487 void updateResizingWindowIfNeeded() {
488 // Used in AppWindowTokenTests#testLandscapeSeascapeRotationRelayout to deceive
489 // the system that it can actually update the window.
490 boolean hadSurface = mHasSurface;
491 mHasSurface = true;
492
493 super.updateResizingWindowIfNeeded();
494
495 mHasSurface = hadSurface;
496 }
497 }
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800498}