blob: a9d930f5c893e99ad32de1066517ad5f1dd6656d [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
David Stevens46939562017-03-24 13:04:00 -070019import static android.view.View.VISIBLE;
20
Jorim Jaggi829b9cd2017-01-23 16:20:53 +010021import android.app.ActivityManager.TaskDescription;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080022import android.content.res.Configuration;
23import android.graphics.Rect;
Andrii Kulian367ff7f2017-01-25 19:45:34 -080024import android.hardware.display.DisplayManagerGlobal;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080025import android.os.Binder;
Andrii Kulian367ff7f2017-01-25 19:45:34 -080026import android.view.Display;
27import android.view.DisplayInfo;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080028import android.view.IApplicationToken;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080029import org.junit.Assert;
Wale Ogunwale17f175c2017-02-07 16:54:10 -080030import org.junit.After;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080031import org.junit.Before;
Jorim Jaggi9bafc712017-01-19 17:28:30 +010032import org.mockito.MockitoAnnotations;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080033
Wale Ogunwale1666e312016-12-16 11:27:18 -080034import android.app.ActivityManager.TaskSnapshot;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080035import android.content.Context;
36import android.os.IBinder;
37import android.support.test.InstrumentationRegistry;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080038import android.view.IWindow;
39import android.view.WindowManager;
40
41import static android.app.ActivityManager.StackId.FIRST_DYNAMIC_STACK_ID;
Winson Chung83471632016-12-13 11:02:12 -080042import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080043import static android.app.AppOpsManager.OP_NONE;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080044import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080045import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080046import static android.content.res.Configuration.EMPTY;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +010047import static android.content.res.Configuration.ORIENTATION_UNDEFINED;
Andrii Kulian367ff7f2017-01-25 19:45:34 -080048import static android.view.DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080049import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
Wale Ogunwale34247952017-02-19 11:57:53 -080050import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080051import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080052import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
53import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
54import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
55import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
56import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
57import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
58import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
59import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
60import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080061import static com.android.server.wm.WindowContainer.POSITION_TOP;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080062import static org.mockito.Mockito.mock;
63
Jorim Jaggi9bafc712017-01-19 17:28:30 +010064import com.android.server.AttributeCache;
Wale Ogunwale17f175c2017-02-07 16:54:10 -080065
66import java.util.HashSet;
Wale Ogunwale34247952017-02-19 11:57:53 -080067import java.util.LinkedList;
Jorim Jaggi9bafc712017-01-19 17:28:30 +010068
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080069/**
70 * Common base class for window manager unit test classes.
71 */
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080072class WindowTestsBase {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080073 static WindowManagerService sWm = null;
Jorim Jaggi9bafc712017-01-19 17:28:30 +010074 static TestWindowManagerPolicy sPolicy = null;
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -080075 private final static IWindow sIWindow = new TestIWindow();
Jorim Jaggi9bafc712017-01-19 17:28:30 +010076 private final static Session sMockSession = mock(Session.class);
Bryce Lee310de9e2017-03-15 10:18:21 -070077 // The default display is removed in {@link #setUp} and then we iterate over all displays to
78 // make sure we don't collide with any existing display. If we run into no other display, the
Bryce Lee6272c7f2017-03-17 17:22:35 -070079 // added display should be treated as default. This cannot be the default display
80 private static int sNextDisplayId = Display.DEFAULT_DISPLAY + 1;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080081 static int sNextStackId = FIRST_DYNAMIC_STACK_ID;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080082 private static int sNextTaskId = 0;
83
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080084 private static boolean sOneTimeSetupDone = false;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080085 static DisplayContent sDisplayContent;
Andrii Kulian367ff7f2017-01-25 19:45:34 -080086 static DisplayInfo sDisplayInfo = new DisplayInfo();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080087 static WindowLayersController sLayersController;
88 static WindowState sWallpaperWindow;
89 static WindowState sImeWindow;
90 static WindowState sImeDialogWindow;
91 static WindowState sStatusBarWindow;
92 static WindowState sDockedDividerWindow;
93 static WindowState sNavBarWindow;
94 static WindowState sAppWindow;
95 static WindowState sChildAppWindowAbove;
96 static WindowState sChildAppWindowBelow;
Wale Ogunwale17f175c2017-02-07 16:54:10 -080097 static HashSet<WindowState> sCommonWindows;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080098
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080099 @Before
100 public void setUp() throws Exception {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800101 if (sOneTimeSetupDone) {
102 return;
103 }
104 sOneTimeSetupDone = true;
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100105 MockitoAnnotations.initMocks(this);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800106 final Context context = InstrumentationRegistry.getTargetContext();
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100107 AttributeCache.init(context);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800108 sWm = TestWindowManagerPolicy.getWindowManagerService(context);
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100109 sPolicy = (TestWindowManagerPolicy) sWm.mPolicy;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800110 sLayersController = new WindowLayersController(sWm);
Bryce Lee6272c7f2017-03-17 17:22:35 -0700111
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800112 // Make sure that display ids don't overlap, so there won't be several displays with same
113 // ids among RootWindowContainer children.
114 for (DisplayContent dc : sWm.mRoot.mChildren) {
115 if (dc.getDisplayId() >= sNextDisplayId) {
116 sNextDisplayId = dc.getDisplayId() + 1;
117 }
Bryce Lee6272c7f2017-03-17 17:22:35 -0700118
119 // The default display must be preserved as some tests require it to function
120 // (such as policy rotation).
121 if (dc.getDisplayId() != Display.DEFAULT_DISPLAY) {
122 // It is safe to remove these displays as new displays will always be created with
123 // new ids.
124 dc.removeImmediately();
125 }
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800126 }
Bryce Lee6272c7f2017-03-17 17:22:35 -0700127
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800128 context.getDisplay().getDisplayInfo(sDisplayInfo);
129 sDisplayContent = createNewDisplay();
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100130 sWm.mDisplayEnabled = true;
131 sWm.mDisplayReady = true;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800132
133 // Set-up some common windows.
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800134 sCommonWindows = new HashSet();
135 sWallpaperWindow = createCommonWindow(null, TYPE_WALLPAPER, "wallpaperWindow");
136 sImeWindow = createCommonWindow(null, TYPE_INPUT_METHOD, "sImeWindow");
Wale Ogunwale34247952017-02-19 11:57:53 -0800137 sWm.mInputMethodWindow = sImeWindow;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800138 sImeDialogWindow = createCommonWindow(null, TYPE_INPUT_METHOD_DIALOG, "sImeDialogWindow");
139 sStatusBarWindow = createCommonWindow(null, TYPE_STATUS_BAR, "sStatusBarWindow");
140 sNavBarWindow = createCommonWindow(null, TYPE_NAVIGATION_BAR, "sNavBarWindow");
141 sDockedDividerWindow = createCommonWindow(null, TYPE_DOCK_DIVIDER, "sDockedDividerWindow");
142 sAppWindow = createCommonWindow(null, TYPE_BASE_APPLICATION, "sAppWindow");
143 sChildAppWindowAbove = createCommonWindow(sAppWindow, TYPE_APPLICATION_ATTACHED_DIALOG,
144 "sChildAppWindowAbove");
145 sChildAppWindowBelow = createCommonWindow(sAppWindow, TYPE_APPLICATION_MEDIA_OVERLAY,
146 "sChildAppWindowBelow");
147 }
148
149 @After
150 public void tearDown() throws Exception {
Wale Ogunwale34247952017-02-19 11:57:53 -0800151 final LinkedList<WindowState> nonCommonWindows = new LinkedList();
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800152 sWm.mRoot.forAllWindows(w -> {
153 if (!sCommonWindows.contains(w)) {
Wale Ogunwale34247952017-02-19 11:57:53 -0800154 nonCommonWindows.addLast(w);
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800155 }
156 }, true /* traverseTopToBottom */);
Wale Ogunwale34247952017-02-19 11:57:53 -0800157
158 while (!nonCommonWindows.isEmpty()) {
159 nonCommonWindows.pollLast().removeImmediately();
160 }
161
162 sWm.mInputMethodTarget = null;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800163 }
164
165 private static WindowState createCommonWindow(WindowState parent, int type, String name) {
166 final WindowState win = createWindow(parent, type, name);
167 sCommonWindows.add(win);
Wale Ogunwale34247952017-02-19 11:57:53 -0800168 // Prevent common windows from been IMe targets
169 win.mAttrs.flags |= FLAG_NOT_FOCUSABLE;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800170 return win;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800171 }
172
173 /** Asserts that the first entry is greater than the second entry. */
174 void assertGreaterThan(int first, int second) throws Exception {
175 Assert.assertTrue("Excepted " + first + " to be greater than " + second, first > second);
176 }
177
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100178 /**
179 * Waits until the main handler for WM has processed all messages.
180 */
181 void waitUntilHandlerIdle() {
182 sWm.mH.runWithScissors(() -> { }, 0);
183 }
184
Winson Chung83471632016-12-13 11:02:12 -0800185 private static WindowToken createWindowToken(DisplayContent dc, int stackId, int type) {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800186 if (type < FIRST_APPLICATION_WINDOW || type > LAST_APPLICATION_WINDOW) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800187 return new TestWindowToken(type, dc);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800188 }
189
Winson Chung83471632016-12-13 11:02:12 -0800190 final TaskStack stack = stackId == INVALID_STACK_ID
191 ? createTaskStackOnDisplay(dc)
192 : createStackControllerOnStackOnDisplay(stackId, dc).mContainer;
Andrii Kuliand2765632016-12-12 22:26:34 -0800193 final Task task = createTaskInStack(stack, 0 /* userId */);
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800194 final TestAppWindowToken token = new TestAppWindowToken(dc);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800195 task.addChild(token, 0);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800196 return token;
197 }
198
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100199 static WindowState createWindow(WindowState parent, int type, String name) {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800200 return (parent == null)
201 ? createWindow(parent, type, sDisplayContent, name)
202 : createWindow(parent, type, parent.mToken, name);
203 }
204
Winson Chung83471632016-12-13 11:02:12 -0800205 static WindowState createWindowOnStack(WindowState parent, int stackId, int type,
206 DisplayContent dc, String name) {
207 final WindowToken token = createWindowToken(dc, stackId, type);
208 return createWindow(parent, type, token, name);
209 }
210
Jorim Jaggi02886a82016-12-06 09:10:06 -0800211 WindowState createAppWindow(Task task, int type, String name) {
212 final AppWindowToken token = new TestAppWindowToken(sDisplayContent);
213 task.addChild(token, 0);
214 return createWindow(null, type, token, name);
215 }
216
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100217 static WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name) {
Winson Chung83471632016-12-13 11:02:12 -0800218 final WindowToken token = createWindowToken(dc, INVALID_STACK_ID, type);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800219 return createWindow(parent, type, token, name);
220 }
221
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800222 static WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name,
223 boolean ownerCanAddInternalSystemWindow) {
Winson Chung83471632016-12-13 11:02:12 -0800224 final WindowToken token = createWindowToken(dc, INVALID_STACK_ID, type);
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800225 return createWindow(parent, type, token, name, ownerCanAddInternalSystemWindow);
226 }
227
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100228 static WindowState createWindow(WindowState parent, int type, WindowToken token, String name) {
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800229 return createWindow(parent, type, token, name, false /* ownerCanAddInternalSystemWindow */);
230 }
231
232 static WindowState createWindow(WindowState parent, int type, WindowToken token, String name,
233 boolean ownerCanAddInternalSystemWindow) {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800234 final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type);
235 attrs.setTitle(name);
236
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -0800237 final WindowState w = new WindowState(sWm, sMockSession, sIWindow, token, parent, OP_NONE,
David Stevens46939562017-03-24 13:04:00 -0700238 0, attrs, VISIBLE, 0, ownerCanAddInternalSystemWindow);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800239 // TODO: Probably better to make this call in the WindowState ctor to avoid errors with
240 // adding it to the token...
241 token.addWindow(w);
242 return w;
243 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800244
Andrii Kuliand2765632016-12-12 22:26:34 -0800245 /** Creates a {@link TaskStack} and adds it to the specified {@link DisplayContent}. */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100246 static TaskStack createTaskStackOnDisplay(DisplayContent dc) {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800247 return createStackControllerOnDisplay(dc).mContainer;
248 }
249
250 static StackWindowController createStackControllerOnDisplay(DisplayContent dc) {
251 final int stackId = ++sNextStackId;
Winson Chung83471632016-12-13 11:02:12 -0800252 return createStackControllerOnStackOnDisplay(stackId, dc);
253 }
254
255 static StackWindowController createStackControllerOnStackOnDisplay(int stackId,
256 DisplayContent dc) {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800257 return new StackWindowController(stackId, null, dc.getDisplayId(),
258 true /* onTop */, new Rect(), sWm);
Andrii Kuliand2765632016-12-12 22:26:34 -0800259 }
260
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800261 /** Creates a {@link Task} and adds it to the specified {@link TaskStack}. */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100262 static Task createTaskInStack(TaskStack stack, int userId) {
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800263 final Task newTask = new Task(sNextTaskId++, stack, userId, sWm, null, EMPTY, 0, false,
264 false, new TaskDescription(), null);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800265 stack.addTask(newTask, POSITION_TOP);
Andrii Kuliand2765632016-12-12 22:26:34 -0800266 return newTask;
267 }
268
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800269 /** Creates a {@link DisplayContent} and adds it to the system. */
270 DisplayContent createNewDisplay() {
271 final int displayId = sNextDisplayId++;
272 final Display display = new Display(DisplayManagerGlobal.getInstance(), displayId,
273 sDisplayInfo, DEFAULT_DISPLAY_ADJUSTMENTS);
274 return new DisplayContent(display, sWm, sLayersController, new WallpaperController(sWm));
275 }
276
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800277 /* Used so we can gain access to some protected members of the {@link WindowToken} class */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100278 static class TestWindowToken extends WindowToken {
Robert Carrdee1b3f2017-02-27 11:33:33 -0800279 int adj = 0;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800280
281 TestWindowToken(int type, DisplayContent dc) {
282 this(type, dc, false /* persistOnEmpty */);
283 }
284
285 TestWindowToken(int type, DisplayContent dc, boolean persistOnEmpty) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800286 super(sWm, mock(IBinder.class), type, persistOnEmpty, dc,
287 false /* ownerCanManageAppTokens */);
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800288 }
289
290 int getWindowsCount() {
291 return mChildren.size();
292 }
293
294 boolean hasWindow(WindowState w) {
295 return mChildren.contains(w);
296 }
Robert Carrdee1b3f2017-02-27 11:33:33 -0800297
298 @Override
299 int getAnimLayerAdjustment() {
300 return adj;
301 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800302 }
303
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800304 /** Used so we can gain access to some protected members of the {@link AppWindowToken} class. */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100305 static class TestAppWindowToken extends AppWindowToken {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800306
307 TestAppWindowToken(DisplayContent dc) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700308 super(sWm, null, false, dc, true /* fillsParent */, null /* overrideConfig */,
309 null /* bounds */);
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800310 }
311
Winson Chung30480042017-01-26 10:55:34 -0800312 TestAppWindowToken(WindowManagerService service, IApplicationToken token,
313 boolean voiceInteraction, DisplayContent dc, long inputDispatchingTimeoutNanos,
314 boolean fullscreen, boolean showForAllUsers, int targetSdk, int orientation,
315 int rotationAnimationHint, int configChanges, boolean launchTaskBehind,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700316 boolean alwaysFocusable, AppWindowContainerController controller,
317 Configuration overrideConfig, Rect bounds) {
Winson Chung30480042017-01-26 10:55:34 -0800318 super(service, token, voiceInteraction, dc, inputDispatchingTimeoutNanos, fullscreen,
319 showForAllUsers, targetSdk, orientation, rotationAnimationHint, configChanges,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700320 launchTaskBehind, alwaysFocusable, controller, overrideConfig, bounds);
Winson Chung30480042017-01-26 10:55:34 -0800321 }
322
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800323 int getWindowsCount() {
324 return mChildren.size();
325 }
326
327 boolean hasWindow(WindowState w) {
328 return mChildren.contains(w);
329 }
330
331 WindowState getFirstChild() {
332 return mChildren.getFirst();
333 }
334
335 WindowState getLastChild() {
336 return mChildren.getLast();
337 }
Winson Chung30480042017-01-26 10:55:34 -0800338
339 int positionInParent() {
340 return getParent().mChildren.indexOf(this);
341 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800342 }
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800343
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800344 /* Used so we can gain access to some protected members of the {@link Task} class */
345 class TestTask extends Task {
346
347 boolean mShouldDeferRemoval = false;
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -0800348 boolean mOnDisplayChangedCalled = false;
Wale Ogunwale1666e312016-12-16 11:27:18 -0800349 private boolean mUseLocalIsAnimating = false;
350 private boolean mIsAnimating = false;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800351
352 TestTask(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800353 Configuration overrideConfig, int resizeMode, boolean supportsPictureInPicture,
354 boolean homeTask, TaskWindowContainerController controller) {
355 super(taskId, stack, userId, service, bounds, overrideConfig, resizeMode,
356 supportsPictureInPicture, homeTask, new TaskDescription(), controller);
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800357 }
358
359 boolean shouldDeferRemoval() {
360 return mShouldDeferRemoval;
361 }
362
363 int positionInParent() {
364 return getParent().mChildren.indexOf(this);
365 }
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -0800366
367 @Override
368 void onDisplayChanged(DisplayContent dc) {
369 super.onDisplayChanged(dc);
370 mOnDisplayChangedCalled = true;
371 }
Wale Ogunwale1666e312016-12-16 11:27:18 -0800372
373 @Override
374 boolean isAnimating() {
375 return mUseLocalIsAnimating ? mIsAnimating : super.isAnimating();
376 }
377
378 void setLocalIsAnimating(boolean isAnimating) {
379 mUseLocalIsAnimating = true;
380 mIsAnimating = isAnimating;
381 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800382 }
383
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800384 /**
385 * Used so we can gain access to some protected members of {@link TaskWindowContainerController}
386 * class.
387 */
388 class TestTaskWindowContainerController extends TaskWindowContainerController {
389
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800390 TestTaskWindowContainerController() {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800391 this(createStackControllerOnDisplay(sDisplayContent));
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800392 }
393
Wale Ogunwale1666e312016-12-16 11:27:18 -0800394 TestTaskWindowContainerController(StackWindowController stackController) {
395 super(sNextTaskId++, new TaskWindowContainerListener() {
396 @Override
397 public void onSnapshotChanged(TaskSnapshot snapshot) {
398
399 }
400
401 @Override
402 public void requestResize(Rect bounds, int resizeMode) {
403
404 }
405 }, stackController, 0 /* userId */, null /* bounds */,
Winson Chungd3395382016-12-13 11:49:09 -0800406 EMPTY /* overrideConfig*/, RESIZE_MODE_UNRESIZEABLE,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800407 false /* supportsPictureInPicture */, false /* homeTask*/, true /* toTop*/,
408 true /* showForAllUsers */, new TaskDescription(), sWm);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800409 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800410
411 @Override
412 TestTask createTask(int taskId, TaskStack stack, int userId, Rect bounds,
Winson Chungd3395382016-12-13 11:49:09 -0800413 Configuration overrideConfig, int resizeMode, boolean supportsPictureInPicture,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800414 boolean homeTask, TaskDescription taskDescription) {
415 return new TestTask(taskId, stack, userId, mService, bounds, overrideConfig, resizeMode,
416 supportsPictureInPicture, homeTask, this);
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800417 }
418 }
419
420 class TestAppWindowContainerController extends AppWindowContainerController {
421
422 final IApplicationToken mToken;
423
424 TestAppWindowContainerController(TestTaskWindowContainerController taskController) {
425 this(taskController, new TestIApplicationToken());
426 }
427
428 TestAppWindowContainerController(TestTaskWindowContainerController taskController,
429 IApplicationToken token) {
430 super(taskController, token, null /* listener */, 0 /* index */,
431 SCREEN_ORIENTATION_UNSPECIFIED, true /* fullscreen */,
432 true /* showForAllUsers */, 0 /* configChanges */, false /* voiceInteraction */,
433 false /* launchTaskBehind */, false /* alwaysFocusable */,
434 0 /* targetSdkVersion */, 0 /* rotationAnimationHint */,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700435 0 /* inputDispatchingTimeoutNanos */, sWm, null /* overrideConfig */,
436 null /* bounds */);
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800437 mToken = token;
438 }
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100439
Winson Chung30480042017-01-26 10:55:34 -0800440 @Override
441 AppWindowToken createAppWindow(WindowManagerService service, IApplicationToken token,
442 boolean voiceInteraction, DisplayContent dc, long inputDispatchingTimeoutNanos,
443 boolean fullscreen, boolean showForAllUsers, int targetSdk, int orientation,
444 int rotationAnimationHint, int configChanges, boolean launchTaskBehind,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700445 boolean alwaysFocusable, AppWindowContainerController controller,
446 Configuration overrideConfig, Rect bounds) {
Winson Chung30480042017-01-26 10:55:34 -0800447 return new TestAppWindowToken(service, token, voiceInteraction, dc,
448 inputDispatchingTimeoutNanos, fullscreen, showForAllUsers, targetSdk,
449 orientation,
450 rotationAnimationHint, configChanges, launchTaskBehind, alwaysFocusable,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700451 controller, overrideConfig, bounds);
Winson Chung30480042017-01-26 10:55:34 -0800452 }
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 Ogunwale8e44f6c2017-03-09 15:25:10 -0800473 super(sWm, sMockSession, sIWindow, token, null, OP_NONE, 0, attrs, 0, 0,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800474 false /* ownerCanAddInternalSystemWindow */);
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800475 }
476
477 @Override
478 void reportResized() {
479 super.reportResized();
480 resizeReported = true;
481 }
482
483 @Override
484 public boolean isGoneForLayoutLw() {
485 return false;
486 }
487
488 @Override
489 void updateResizingWindowIfNeeded() {
490 // Used in AppWindowTokenTests#testLandscapeSeascapeRotationRelayout to deceive
491 // the system that it can actually update the window.
492 boolean hadSurface = mHasSurface;
493 mHasSurface = true;
494
495 super.updateResizingWindowIfNeeded();
496
497 mHasSurface = hadSurface;
498 }
499 }
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800500}