blob: 5c3368bd25acc6f4e8e2d34a3fcbe4626f9eb97a [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
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070014 * limitations under the License.
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080015 */
16
17package com.android.server.wm;
18
Brett Chabota26eda92018-07-23 13:08:30 -070019import static android.app.AppOpsManager.OP_NONE;
Wale Ogunwale68278562017-09-23 17:13:55 -070020import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
21import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
Wale Ogunwale11cc5162017-04-25 20:29:13 -070022import static android.view.Display.DEFAULT_DISPLAY;
Andrii Kulian367ff7f2017-01-25 19:45:34 -080023import static android.view.DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS;
Brett Chabota26eda92018-07-23 13:08:30 -070024import static android.view.View.VISIBLE;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080025import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
Wale Ogunwale34247952017-02-19 11:57:53 -080026import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080027import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080028import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
29import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
30import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
31import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
32import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
33import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
34import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
35import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
36import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Brett Chabota26eda92018-07-23 13:08:30 -070037
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070038import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
39
Tadashi G. Takaokabf0d57b2018-11-19 16:09:58 +090040import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080041
Brett Chabota26eda92018-07-23 13:08:30 -070042import android.content.Context;
43import android.content.res.Configuration;
44import android.graphics.Rect;
45import android.hardware.display.DisplayManagerGlobal;
46import android.testing.DexmakerShareClassLoaderRule;
47import android.util.Log;
48import android.view.Display;
49import android.view.DisplayInfo;
50import android.view.IWindow;
51import android.view.WindowManager;
52
Jorim Jaggi9bafc712017-01-19 17:28:30 +010053import com.android.server.AttributeCache;
Wale Ogunwale17f175c2017-02-07 16:54:10 -080054
Brett Chabota26eda92018-07-23 13:08:30 -070055import org.junit.After;
Brett Chabota26eda92018-07-23 13:08:30 -070056import org.junit.Before;
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070057import org.junit.BeforeClass;
Brett Chabota26eda92018-07-23 13:08:30 -070058import org.junit.Rule;
59
Wale Ogunwale17f175c2017-02-07 16:54:10 -080060import java.util.HashSet;
Wale Ogunwale34247952017-02-19 11:57:53 -080061import java.util.LinkedList;
Jorim Jaggi9bafc712017-01-19 17:28:30 +010062
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080063/**
64 * Common base class for window manager unit test classes.
chaviw97d28202018-02-27 16:23:53 -080065 *
66 * Make sure any requests to WM hold the WM lock if needed b/73966377
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080067 */
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080068class WindowTestsBase {
chaviw578b6fe2018-03-06 16:24:17 -080069 private static final String TAG = WindowTestsBase.class.getSimpleName();
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070070
71 WindowManagerService mWm;
Adrian Roos3150dbf2018-03-28 18:06:52 +020072 private final IWindow mIWindow = new TestIWindow();
73 private Session mMockSession;
Bryce Lee310de9e2017-03-15 10:18:21 -070074 // The default display is removed in {@link #setUp} and then we iterate over all displays to
75 // 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 -070076 // added display should be treated as default. This cannot be the default display
Wale Ogunwale11cc5162017-04-25 20:29:13 -070077 private static int sNextDisplayId = DEFAULT_DISPLAY + 1;
Wale Ogunwale44f036f2017-09-29 05:09:09 -070078 static int sNextStackId = 1000;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080079
Riddle Hsuf53da812018-08-15 22:00:27 +080080 /** Non-default display. */
Wale Ogunwale11cc5162017-04-25 20:29:13 -070081 DisplayContent mDisplayContent;
82 DisplayInfo mDisplayInfo = new DisplayInfo();
Wale Ogunwale11cc5162017-04-25 20:29:13 -070083 WindowState mWallpaperWindow;
84 WindowState mImeWindow;
85 WindowState mImeDialogWindow;
86 WindowState mStatusBarWindow;
87 WindowState mDockedDividerWindow;
88 WindowState mNavBarWindow;
89 WindowState mAppWindow;
90 WindowState mChildAppWindowAbove;
91 WindowState mChildAppWindowBelow;
92 HashSet<WindowState> mCommonWindows;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080093
Adrian Roos3150dbf2018-03-28 18:06:52 +020094 @Rule
95 public final DexmakerShareClassLoaderRule mDexmakerShareClassLoaderRule =
96 new DexmakerShareClassLoaderRule();
97
98 @Rule
99 public final WindowManagerServiceRule mWmRule = new WindowManagerServiceRule();
100
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700101 static WindowState.PowerManagerWrapper sPowerManagerWrapper; // TODO(roosa): make non-static.
102
103 @BeforeClass
104 public static void setUpOnceBase() {
105 AttributeCache.init(getInstrumentation().getTargetContext());
106 sPowerManagerWrapper = mock(WindowState.PowerManagerWrapper.class);
107 }
chaviw40234662018-02-07 09:37:16 -0800108
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800109 @Before
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700110 public void setUpBase() {
chaviw578b6fe2018-03-06 16:24:17 -0800111 // If @Before throws an exception, the error isn't logged. This will make sure any failures
112 // in the set up are clear. This can be removed when b/37850063 is fixed.
113 try {
Adrian Roos3150dbf2018-03-28 18:06:52 +0200114 mMockSession = mock(Session.class);
chaviw578b6fe2018-03-06 16:24:17 -0800115
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700116 final Context context = getInstrumentation().getTargetContext();
chaviw578b6fe2018-03-06 16:24:17 -0800117
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700118 mWm = mWmRule.getWindowManagerService();
chaviw578b6fe2018-03-06 16:24:17 -0800119 beforeCreateDisplay();
120
chaviw578b6fe2018-03-06 16:24:17 -0800121 context.getDisplay().getDisplayInfo(mDisplayInfo);
122 mDisplayContent = createNewDisplay();
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700123 mWm.mDisplayEnabled = true;
124 mWm.mDisplayReady = true;
chaviw578b6fe2018-03-06 16:24:17 -0800125
126 // Set-up some common windows.
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700127 mCommonWindows = new HashSet<>();
128 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800129 mWallpaperWindow = createCommonWindow(null, TYPE_WALLPAPER, "wallpaperWindow");
130 mImeWindow = createCommonWindow(null, TYPE_INPUT_METHOD, "mImeWindow");
lumark90120a82018-08-15 00:33:03 +0800131 mDisplayContent.mInputMethodWindow = mImeWindow;
chaviw97d28202018-02-27 16:23:53 -0800132 mImeDialogWindow = createCommonWindow(null, TYPE_INPUT_METHOD_DIALOG,
133 "mImeDialogWindow");
134 mStatusBarWindow = createCommonWindow(null, TYPE_STATUS_BAR, "mStatusBarWindow");
135 mNavBarWindow = createCommonWindow(null, TYPE_NAVIGATION_BAR, "mNavBarWindow");
136 mDockedDividerWindow = createCommonWindow(null, TYPE_DOCK_DIVIDER,
137 "mDockedDividerWindow");
138 mAppWindow = createCommonWindow(null, TYPE_BASE_APPLICATION, "mAppWindow");
139 mChildAppWindowAbove = createCommonWindow(mAppWindow,
140 TYPE_APPLICATION_ATTACHED_DIALOG,
141 "mChildAppWindowAbove");
142 mChildAppWindowBelow = createCommonWindow(mAppWindow,
143 TYPE_APPLICATION_MEDIA_OVERLAY,
144 "mChildAppWindowBelow");
145 }
chaviw578b6fe2018-03-06 16:24:17 -0800146 // Adding a display will cause freezing the display. Make sure to wait until it's
147 // unfrozen to not run into race conditions with the tests.
148 waitUntilHandlersIdle();
149 } catch (Exception e) {
150 Log.e(TAG, "Failed to set up test", e);
151 throw e;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800152 }
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800153 }
154
Robert Carrb1579c82017-09-05 14:54:47 -0700155 void beforeCreateDisplay() {
156 // Called before display is created.
157 }
158
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800159 @After
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700160 public void tearDownBase() {
chaviw578b6fe2018-03-06 16:24:17 -0800161 // If @After throws an exception, the error isn't logged. This will make sure any failures
162 // in the tear down are clear. This can be removed when b/37850063 is fixed.
163 try {
Riddle Hsua4d6fa22018-08-11 00:50:39 +0800164 // Test may schedule to perform surface placement or other messages. Wait until a
165 // stable state to clean up for consistency.
166 waitUntilHandlersIdle();
167
168 final LinkedList<WindowState> nonCommonWindows = new LinkedList<>();
Wale Ogunwale027f4752017-05-12 10:37:16 -0700169
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700170 synchronized (mWm.mGlobalLock) {
171 mWm.mRoot.forAllWindows(w -> {
chaviw578b6fe2018-03-06 16:24:17 -0800172 if (!mCommonWindows.contains(w)) {
173 nonCommonWindows.addLast(w);
174 }
175 }, true /* traverseTopToBottom */);
176
177 while (!nonCommonWindows.isEmpty()) {
178 nonCommonWindows.pollLast().removeImmediately();
Wale Ogunwale027f4752017-05-12 10:37:16 -0700179 }
Wale Ogunwale027f4752017-05-12 10:37:16 -0700180
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700181 for (int i = mWm.mRoot.mChildren.size() - 1; i >= 0; --i) {
182 final DisplayContent displayContent = mWm.mRoot.mChildren.get(i);
Riddle Hsua4d6fa22018-08-11 00:50:39 +0800183 if (!displayContent.isDefaultDisplay) {
184 displayContent.removeImmediately();
185 }
186 }
lumark588a3e82018-07-20 18:53:54 +0800187 // Remove app transition & window freeze timeout callbacks to prevent unnecessary
188 // actions after test.
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700189 mWm.getDefaultDisplayContentLocked().mAppTransition
lumark588a3e82018-07-20 18:53:54 +0800190 .removeAppTransitionTimeoutCallbacks();
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700191 mWm.mH.removeMessages(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT);
lumarkff0ab692018-11-05 20:32:30 +0800192 mDisplayContent.mInputMethodTarget = null;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800193 }
Wale Ogunwale34247952017-02-19 11:57:53 -0800194
chaviw578b6fe2018-03-06 16:24:17 -0800195 // Wait until everything is really cleaned up.
196 waitUntilHandlersIdle();
197 } catch (Exception e) {
198 Log.e(TAG, "Failed to tear down test", e);
199 throw e;
Wale Ogunwale34247952017-02-19 11:57:53 -0800200 }
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800201 }
202
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700203 private WindowState createCommonWindow(WindowState parent, int type, String name) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700204 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800205 final WindowState win = createWindow(parent, type, name);
206 mCommonWindows.add(win);
207 // Prevent common windows from been IMe targets
208 win.mAttrs.flags |= FLAG_NOT_FOCUSABLE;
209 return win;
210 }
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800211 }
212
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100213 /**
214 * Waits until the main handler for WM has processed all messages.
215 */
Jorim Jaggied7993b2017-03-28 18:50:01 +0100216 void waitUntilHandlersIdle() {
Adrian Roos3150dbf2018-03-28 18:06:52 +0200217 mWmRule.waitUntilWindowManagerHandlersIdle();
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100218 }
219
Wale Ogunwale68278562017-09-23 17:13:55 -0700220 private WindowToken createWindowToken(
221 DisplayContent dc, int windowingMode, int activityType, int type) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700222 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800223 if (type < FIRST_APPLICATION_WINDOW || type > LAST_APPLICATION_WINDOW) {
224 return WindowTestUtils.createTestWindowToken(type, dc);
225 }
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800226
chaviw97d28202018-02-27 16:23:53 -0800227 return createAppWindowToken(dc, windowingMode, activityType);
228 }
chaviwb28de1f2018-03-02 10:42:36 -0800229 }
230
231 AppWindowToken createAppWindowToken(DisplayContent dc, int windowingMode, int activityType) {
Vishnu Naira2977262018-07-26 13:31:26 -0700232 return createTestAppWindowToken(dc, windowingMode, activityType);
233 }
234
235 WindowTestUtils.TestAppWindowToken createTestAppWindowToken(DisplayContent dc, int
236 windowingMode, int activityType) {
chaviwb28de1f2018-03-02 10:42:36 -0800237 final TaskStack stack = createStackControllerOnStackOnDisplay(windowingMode, activityType,
238 dc).mContainer;
Andrii Kuliand2765632016-12-12 22:26:34 -0800239 final Task task = createTaskInStack(stack, 0 /* userId */);
chaviwb28de1f2018-03-02 10:42:36 -0800240 final WindowTestUtils.TestAppWindowToken appWindowToken =
chaviw97d28202018-02-27 16:23:53 -0800241 WindowTestUtils.createTestAppWindowToken(dc);
chaviwb28de1f2018-03-02 10:42:36 -0800242 task.addChild(appWindowToken, 0);
243 return appWindowToken;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800244 }
245
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700246 WindowState createWindow(WindowState parent, int type, String name) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700247 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800248 return (parent == null)
249 ? createWindow(parent, type, mDisplayContent, name)
250 : createWindow(parent, type, parent.mToken, name);
251 }
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800252 }
253
Wale Ogunwale68278562017-09-23 17:13:55 -0700254 WindowState createWindowOnStack(WindowState parent, int windowingMode, int activityType,
255 int type, DisplayContent dc, String name) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700256 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800257 final WindowToken token = createWindowToken(dc, windowingMode, activityType, type);
258 return createWindow(parent, type, token, name);
259 }
Winson Chung83471632016-12-13 11:02:12 -0800260 }
261
Jorim Jaggi02886a82016-12-06 09:10:06 -0800262 WindowState createAppWindow(Task task, int type, String name) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700263 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800264 final AppWindowToken token = WindowTestUtils.createTestAppWindowToken(mDisplayContent);
265 task.addChild(token, 0);
266 return createWindow(null, type, token, name);
267 }
Jorim Jaggi02886a82016-12-06 09:10:06 -0800268 }
269
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700270 WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700271 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800272 final WindowToken token = createWindowToken(
273 dc, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, type);
274 return createWindow(parent, type, token, name);
275 }
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800276 }
277
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700278 WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name,
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800279 boolean ownerCanAddInternalSystemWindow) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700280 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800281 final WindowToken token = createWindowToken(
282 dc, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, type);
283 return createWindow(parent, type, token, name, 0 /* ownerId */,
284 ownerCanAddInternalSystemWindow);
285 }
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800286 }
287
Adrian Roos3150dbf2018-03-28 18:06:52 +0200288 WindowState createWindow(WindowState parent, int type, WindowToken token, String name) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700289 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800290 return createWindow(parent, type, token, name, 0 /* ownerId */,
291 false /* ownerCanAddInternalSystemWindow */);
292 }
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800293 }
294
Adrian Roos3150dbf2018-03-28 18:06:52 +0200295 WindowState createWindow(WindowState parent, int type, WindowToken token, String name,
Daichi Hironoda0748d2017-12-13 12:48:59 +0900296 int ownerId, boolean ownerCanAddInternalSystemWindow) {
Adrian Roos3150dbf2018-03-28 18:06:52 +0200297 return createWindow(parent, type, token, name, ownerId, ownerCanAddInternalSystemWindow,
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700298 mWm, mMockSession, mIWindow);
Adrian Roos3150dbf2018-03-28 18:06:52 +0200299 }
300
301 static WindowState createWindow(WindowState parent, int type, WindowToken token,
302 String name, int ownerId, boolean ownerCanAddInternalSystemWindow,
303 WindowManagerService service, Session session, IWindow iWindow) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700304 synchronized (service.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800305 final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type);
306 attrs.setTitle(name);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800307
Adrian Roos3150dbf2018-03-28 18:06:52 +0200308 final WindowState w = new WindowState(service, session, iWindow, token, parent,
chaviw97d28202018-02-27 16:23:53 -0800309 OP_NONE,
310 0, attrs, VISIBLE, ownerId, ownerCanAddInternalSystemWindow,
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700311 sPowerManagerWrapper);
chaviw97d28202018-02-27 16:23:53 -0800312 // TODO: Probably better to make this call in the WindowState ctor to avoid errors with
313 // adding it to the token...
314 token.addWindow(w);
315 return w;
316 }
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800317 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800318
Andrii Kuliand2765632016-12-12 22:26:34 -0800319 /** Creates a {@link TaskStack} and adds it to the specified {@link DisplayContent}. */
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700320 TaskStack createTaskStackOnDisplay(DisplayContent dc) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700321 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800322 return createStackControllerOnDisplay(dc).mContainer;
323 }
Wale Ogunwale1666e312016-12-16 11:27:18 -0800324 }
325
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700326 StackWindowController createStackControllerOnDisplay(DisplayContent dc) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700327 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800328 return createStackControllerOnStackOnDisplay(
329 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, dc);
330 }
Winson Chung83471632016-12-13 11:02:12 -0800331 }
332
Wale Ogunwale68278562017-09-23 17:13:55 -0700333 StackWindowController createStackControllerOnStackOnDisplay(
334 int windowingMode, int activityType, DisplayContent dc) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700335 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800336 final Configuration overrideConfig = new Configuration();
337 overrideConfig.windowConfiguration.setWindowingMode(windowingMode);
338 overrideConfig.windowConfiguration.setActivityType(activityType);
339 final int stackId = ++sNextStackId;
340 final StackWindowController controller = new StackWindowController(stackId, null,
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700341 dc.getDisplayId(), true /* onTop */, new Rect(), mWm);
Evan Roskydfe3da72018-10-26 17:21:06 -0700342 controller.onRequestedOverrideConfigurationChanged(overrideConfig);
chaviw97d28202018-02-27 16:23:53 -0800343 return controller;
344 }
Andrii Kuliand2765632016-12-12 22:26:34 -0800345 }
346
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800347 /** Creates a {@link Task} and adds it to the specified {@link TaskStack}. */
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700348 Task createTaskInStack(TaskStack stack, int userId) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700349 return WindowTestUtils.createTaskInStack(mWm, stack, userId);
Andrii Kuliand2765632016-12-12 22:26:34 -0800350 }
351
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800352 /** Creates a {@link DisplayContent} and adds it to the system. */
353 DisplayContent createNewDisplay() {
Chilun8753ad32018-10-09 15:56:45 +0800354 return createNewDisplay(mDisplayInfo);
355 }
356
357 /** Creates a {@link DisplayContent} and adds it to the system. */
358 DisplayContent createNewDisplay(DisplayInfo displayInfo) {
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800359 final int displayId = sNextDisplayId++;
360 final Display display = new Display(DisplayManagerGlobal.getInstance(), displayId,
Chilun8753ad32018-10-09 15:56:45 +0800361 displayInfo, DEFAULT_DISPLAY_ADJUSTMENTS);
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700362 synchronized (mWm.mGlobalLock) {
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800363 return new DisplayContent(display, mWm, mock(ActivityDisplay.class));
chaviw97d28202018-02-27 16:23:53 -0800364 }
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800365 }
366
lumark588a3e82018-07-20 18:53:54 +0800367 /**
368 * Creates a {@link DisplayContent} with given display state and adds it to the system.
369 *
lumark588a3e82018-07-20 18:53:54 +0800370 * @param displayState For initializing the state of the display. See
371 * {@link Display#getState()}.
372 */
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800373 DisplayContent createNewDisplay(int displayState) {
lumark588a3e82018-07-20 18:53:54 +0800374 // Leverage main display info & initialize it with display state for given displayId.
375 DisplayInfo displayInfo = new DisplayInfo();
376 displayInfo.copyFrom(mDisplayInfo);
377 displayInfo.state = displayState;
378 final int displayId = sNextDisplayId++;
379 final Display display = new Display(DisplayManagerGlobal.getInstance(), displayId,
380 displayInfo, DEFAULT_DISPLAY_ADJUSTMENTS);
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700381 synchronized (mWm.mGlobalLock) {
lumark588a3e82018-07-20 18:53:54 +0800382 // Display creation is driven by DisplayWindowController via ActivityStackSupervisor.
383 // We skip those steps here.
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800384 final ActivityDisplay mockAd = mock(ActivityDisplay.class);
385 return mWm.mRoot.createDisplayContent(display, mockAd);
lumark588a3e82018-07-20 18:53:54 +0800386 }
387 }
388
Bryce Leeaf691c02017-03-20 14:20:22 -0700389 /** Creates a {@link com.android.server.wm.WindowTestUtils.TestWindowState} */
390 WindowTestUtils.TestWindowState createWindowState(WindowManager.LayoutParams attrs,
391 WindowToken token) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700392 synchronized (mWm.mGlobalLock) {
393 return new WindowTestUtils.TestWindowState(mWm, mMockSession, mIWindow, attrs, token);
chaviw97d28202018-02-27 16:23:53 -0800394 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800395 }
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800396}