blob: 0da9dc40bb4d7e6f46bcc267a748ca67fbca1669 [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;
lumark51bc29e2019-05-04 12:22:15 +080022import static android.os.Process.SYSTEM_UID;
Brett Chabota26eda92018-07-23 13:08:30 -070023import static android.view.View.VISIBLE;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080024import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
Wale Ogunwale34247952017-02-19 11:57:53 -080025import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080026import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080027import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
28import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
29import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
30import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
31import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
32import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
33import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
34import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
35import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Brett Chabota26eda92018-07-23 13:08:30 -070036
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070037import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
38
Wale Ogunwale8a1860a2019-06-05 08:57:19 -070039import static com.android.server.wm.ActivityDisplay.POSITION_TOP;
Vishnu Naire6e2b0f2019-02-21 10:41:00 -080040
41import static org.mockito.Mockito.mock;
42
Brett Chabota26eda92018-07-23 13:08:30 -070043import android.content.Context;
Brett Chabota26eda92018-07-23 13:08:30 -070044import android.util.Log;
45import android.view.Display;
46import android.view.DisplayInfo;
47import android.view.IWindow;
Vishnu Naire6e2b0f2019-02-21 10:41:00 -080048import android.view.SurfaceControl.Transaction;
Brett Chabota26eda92018-07-23 13:08:30 -070049import android.view.WindowManager;
50
Jorim Jaggi9bafc712017-01-19 17:28:30 +010051import com.android.server.AttributeCache;
Wale Ogunwale17f175c2017-02-07 16:54:10 -080052
Brett Chabota26eda92018-07-23 13:08:30 -070053import org.junit.After;
Brett Chabota26eda92018-07-23 13:08:30 -070054import org.junit.Before;
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070055import org.junit.BeforeClass;
Brett Chabota26eda92018-07-23 13:08:30 -070056
Wale Ogunwale17f175c2017-02-07 16:54:10 -080057import java.util.HashSet;
Wale Ogunwale34247952017-02-19 11:57:53 -080058import java.util.LinkedList;
Jorim Jaggi9bafc712017-01-19 17:28:30 +010059
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080060/**
61 * Common base class for window manager unit test classes.
chaviw97d28202018-02-27 16:23:53 -080062 *
63 * Make sure any requests to WM hold the WM lock if needed b/73966377
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080064 */
Riddle Hsu73f53572019-09-23 23:13:01 +080065class WindowTestsBase extends SystemServiceTestsBase {
chaviw578b6fe2018-03-06 16:24:17 -080066 private static final String TAG = WindowTestsBase.class.getSimpleName();
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070067
68 WindowManagerService mWm;
Adrian Roos3150dbf2018-03-28 18:06:52 +020069 private final IWindow mIWindow = new TestIWindow();
70 private Session mMockSession;
Wale Ogunwale44f036f2017-09-29 05:09:09 -070071 static int sNextStackId = 1000;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080072
Riddle Hsuf53da812018-08-15 22:00:27 +080073 /** Non-default display. */
Wale Ogunwale11cc5162017-04-25 20:29:13 -070074 DisplayContent mDisplayContent;
75 DisplayInfo mDisplayInfo = new DisplayInfo();
Wale Ogunwale11cc5162017-04-25 20:29:13 -070076 WindowState mWallpaperWindow;
77 WindowState mImeWindow;
78 WindowState mImeDialogWindow;
79 WindowState mStatusBarWindow;
80 WindowState mDockedDividerWindow;
81 WindowState mNavBarWindow;
82 WindowState mAppWindow;
83 WindowState mChildAppWindowAbove;
84 WindowState mChildAppWindowBelow;
85 HashSet<WindowState> mCommonWindows;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080086
Riddle Hsu3a4bb612019-01-31 00:02:22 +080087 /**
Vishnu Naire6e2b0f2019-02-21 10:41:00 -080088 * Spied {@link Transaction} class than can be used to verify calls.
Riddle Hsu3a4bb612019-01-31 00:02:22 +080089 */
Vishnu Naire6e2b0f2019-02-21 10:41:00 -080090 Transaction mTransaction;
Riddle Hsu3a4bb612019-01-31 00:02:22 +080091
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070092 @BeforeClass
93 public static void setUpOnceBase() {
94 AttributeCache.init(getInstrumentation().getTargetContext());
Tadashi G. Takaoka5a108b82018-12-13 17:09:12 +090095 }
96
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080097 @Before
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070098 public void setUpBase() {
chaviw578b6fe2018-03-06 16:24:17 -080099 // If @Before throws an exception, the error isn't logged. This will make sure any failures
100 // in the set up are clear. This can be removed when b/37850063 is fixed.
101 try {
Adrian Roos3150dbf2018-03-28 18:06:52 +0200102 mMockSession = mock(Session.class);
chaviw578b6fe2018-03-06 16:24:17 -0800103
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700104 final Context context = getInstrumentation().getTargetContext();
chaviw578b6fe2018-03-06 16:24:17 -0800105
Tadashi G. Takaokad7aa79a2019-02-08 17:42:37 +0900106 mWm = mSystemServicesTestRule.getWindowManagerService();
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700107 mTransaction = mSystemServicesTestRule.mTransaction;
Vishnu Naire6e2b0f2019-02-21 10:41:00 -0800108
chaviw578b6fe2018-03-06 16:24:17 -0800109 beforeCreateDisplay();
110
chaviw578b6fe2018-03-06 16:24:17 -0800111 context.getDisplay().getDisplayInfo(mDisplayInfo);
112 mDisplayContent = createNewDisplay();
chaviw578b6fe2018-03-06 16:24:17 -0800113
114 // Set-up some common windows.
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700115 mCommonWindows = new HashSet<>();
116 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800117 mWallpaperWindow = createCommonWindow(null, TYPE_WALLPAPER, "wallpaperWindow");
118 mImeWindow = createCommonWindow(null, TYPE_INPUT_METHOD, "mImeWindow");
lumark90120a82018-08-15 00:33:03 +0800119 mDisplayContent.mInputMethodWindow = mImeWindow;
chaviw97d28202018-02-27 16:23:53 -0800120 mImeDialogWindow = createCommonWindow(null, TYPE_INPUT_METHOD_DIALOG,
121 "mImeDialogWindow");
122 mStatusBarWindow = createCommonWindow(null, TYPE_STATUS_BAR, "mStatusBarWindow");
123 mNavBarWindow = createCommonWindow(null, TYPE_NAVIGATION_BAR, "mNavBarWindow");
124 mDockedDividerWindow = createCommonWindow(null, TYPE_DOCK_DIVIDER,
125 "mDockedDividerWindow");
126 mAppWindow = createCommonWindow(null, TYPE_BASE_APPLICATION, "mAppWindow");
127 mChildAppWindowAbove = createCommonWindow(mAppWindow,
128 TYPE_APPLICATION_ATTACHED_DIALOG,
129 "mChildAppWindowAbove");
130 mChildAppWindowBelow = createCommonWindow(mAppWindow,
131 TYPE_APPLICATION_MEDIA_OVERLAY,
132 "mChildAppWindowBelow");
133 }
chaviw578b6fe2018-03-06 16:24:17 -0800134 // Adding a display will cause freezing the display. Make sure to wait until it's
135 // unfrozen to not run into race conditions with the tests.
136 waitUntilHandlersIdle();
137 } catch (Exception e) {
138 Log.e(TAG, "Failed to set up test", e);
139 throw e;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800140 }
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800141 }
142
Robert Carrb1579c82017-09-05 14:54:47 -0700143 void beforeCreateDisplay() {
144 // Called before display is created.
145 }
146
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800147 @After
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700148 public void tearDownBase() {
chaviw578b6fe2018-03-06 16:24:17 -0800149 // If @After throws an exception, the error isn't logged. This will make sure any failures
150 // in the tear down are clear. This can be removed when b/37850063 is fixed.
151 try {
Riddle Hsua4d6fa22018-08-11 00:50:39 +0800152 // Test may schedule to perform surface placement or other messages. Wait until a
153 // stable state to clean up for consistency.
154 waitUntilHandlersIdle();
155
156 final LinkedList<WindowState> nonCommonWindows = new LinkedList<>();
Wale Ogunwale027f4752017-05-12 10:37:16 -0700157
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700158 synchronized (mWm.mGlobalLock) {
159 mWm.mRoot.forAllWindows(w -> {
chaviw578b6fe2018-03-06 16:24:17 -0800160 if (!mCommonWindows.contains(w)) {
161 nonCommonWindows.addLast(w);
162 }
163 }, true /* traverseTopToBottom */);
164
165 while (!nonCommonWindows.isEmpty()) {
166 nonCommonWindows.pollLast().removeImmediately();
Wale Ogunwale027f4752017-05-12 10:37:16 -0700167 }
Wale Ogunwale027f4752017-05-12 10:37:16 -0700168
lumark588a3e82018-07-20 18:53:54 +0800169 // Remove app transition & window freeze timeout callbacks to prevent unnecessary
170 // actions after test.
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700171 mWm.getDefaultDisplayContentLocked().mAppTransition
lumark588a3e82018-07-20 18:53:54 +0800172 .removeAppTransitionTimeoutCallbacks();
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700173 mWm.mH.removeMessages(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT);
lumarkff0ab692018-11-05 20:32:30 +0800174 mDisplayContent.mInputMethodTarget = null;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800175 }
Wale Ogunwale34247952017-02-19 11:57:53 -0800176
Tadashi G. Takaokaa5f7c2c2019-01-09 12:17:14 +0900177 // Cleaned up everything in Handler.
Tadashi G. Takaokad7aa79a2019-02-08 17:42:37 +0900178 mSystemServicesTestRule.cleanupWindowManagerHandlers();
chaviw578b6fe2018-03-06 16:24:17 -0800179 } catch (Exception e) {
180 Log.e(TAG, "Failed to tear down test", e);
181 throw e;
Wale Ogunwale34247952017-02-19 11:57:53 -0800182 }
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800183 }
184
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700185 private WindowState createCommonWindow(WindowState parent, int type, String name) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700186 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800187 final WindowState win = createWindow(parent, type, name);
188 mCommonWindows.add(win);
189 // Prevent common windows from been IMe targets
190 win.mAttrs.flags |= FLAG_NOT_FOCUSABLE;
191 return win;
192 }
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800193 }
194
Wale Ogunwale68278562017-09-23 17:13:55 -0700195 private WindowToken createWindowToken(
196 DisplayContent dc, int windowingMode, int activityType, int type) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700197 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800198 if (type < FIRST_APPLICATION_WINDOW || type > LAST_APPLICATION_WINDOW) {
199 return WindowTestUtils.createTestWindowToken(type, dc);
200 }
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800201
Garfield Tane8d84ab2019-10-11 09:49:40 -0700202 return createActivityRecord(dc, windowingMode, activityType);
chaviw97d28202018-02-27 16:23:53 -0800203 }
chaviwb28de1f2018-03-02 10:42:36 -0800204 }
205
Garfield Tane8d84ab2019-10-11 09:49:40 -0700206 ActivityRecord createActivityRecord(DisplayContent dc, int windowingMode, int activityType) {
207 return createTestActivityRecord(dc, windowingMode, activityType);
Vishnu Naira2977262018-07-26 13:31:26 -0700208 }
209
Garfield Tane8d84ab2019-10-11 09:49:40 -0700210 ActivityRecord createTestActivityRecord(DisplayContent dc, int
Vishnu Naira2977262018-07-26 13:31:26 -0700211 windowingMode, int activityType) {
Wale Ogunwalebebd8cd2019-10-28 15:53:31 -0700212 final ActivityStack stack = createTaskStackOnDisplay(windowingMode, activityType, dc);
213 return WindowTestUtils.createTestActivityRecord(stack);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800214 }
215
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700216 WindowState createWindow(WindowState parent, int type, String name) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700217 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800218 return (parent == null)
219 ? createWindow(parent, type, mDisplayContent, name)
220 : createWindow(parent, type, parent.mToken, name);
221 }
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800222 }
223
Michal Karpinskia606a292019-01-12 17:29:52 +0000224 WindowState createWindow(WindowState parent, int type, String name, int ownerId) {
225 synchronized (mWm.mGlobalLock) {
226 return (parent == null)
227 ? createWindow(parent, type, mDisplayContent, name, ownerId)
228 : createWindow(parent, type, parent.mToken, name, ownerId);
229 }
230 }
231
Wale Ogunwale68278562017-09-23 17:13:55 -0700232 WindowState createWindowOnStack(WindowState parent, int windowingMode, int activityType,
233 int type, DisplayContent dc, String name) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700234 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800235 final WindowToken token = createWindowToken(dc, windowingMode, activityType, type);
236 return createWindow(parent, type, token, name);
237 }
Winson Chung83471632016-12-13 11:02:12 -0800238 }
239
Jorim Jaggi02886a82016-12-06 09:10:06 -0800240 WindowState createAppWindow(Task task, int type, String name) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700241 synchronized (mWm.mGlobalLock) {
Garfield Tane8d84ab2019-10-11 09:49:40 -0700242 final ActivityRecord activity =
243 WindowTestUtils.createTestActivityRecord(mDisplayContent);
244 task.addChild(activity, 0);
245 return createWindow(null, type, activity, name);
chaviw97d28202018-02-27 16:23:53 -0800246 }
Jorim Jaggi02886a82016-12-06 09:10:06 -0800247 }
248
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700249 WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700250 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800251 final WindowToken token = createWindowToken(
252 dc, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, type);
Michal Karpinskia606a292019-01-12 17:29:52 +0000253 return createWindow(parent, type, token, name, 0 /* ownerId */);
254 }
255 }
256
257 WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name,
258 int ownerId) {
259 synchronized (mWm.mGlobalLock) {
260 final WindowToken token = createWindowToken(
261 dc, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, type);
262 return createWindow(parent, type, token, name, ownerId);
chaviw97d28202018-02-27 16:23:53 -0800263 }
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800264 }
265
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700266 WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name,
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800267 boolean ownerCanAddInternalSystemWindow) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700268 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800269 final WindowToken token = createWindowToken(
270 dc, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, type);
271 return createWindow(parent, type, token, name, 0 /* ownerId */,
272 ownerCanAddInternalSystemWindow);
273 }
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800274 }
275
Adrian Roos3150dbf2018-03-28 18:06:52 +0200276 WindowState createWindow(WindowState parent, int type, WindowToken token, String name) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700277 synchronized (mWm.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800278 return createWindow(parent, type, token, name, 0 /* ownerId */,
279 false /* ownerCanAddInternalSystemWindow */);
280 }
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800281 }
282
Adrian Roos3150dbf2018-03-28 18:06:52 +0200283 WindowState createWindow(WindowState parent, int type, WindowToken token, String name,
Michal Karpinskia606a292019-01-12 17:29:52 +0000284 int ownerId) {
285 synchronized (mWm.mGlobalLock) {
286 return createWindow(parent, type, token, name, ownerId,
287 false /* ownerCanAddInternalSystemWindow */);
288 }
289 }
290
291 WindowState createWindow(WindowState parent, int type, WindowToken token, String name,
Daichi Hironoda0748d2017-12-13 12:48:59 +0900292 int ownerId, boolean ownerCanAddInternalSystemWindow) {
Adrian Roos3150dbf2018-03-28 18:06:52 +0200293 return createWindow(parent, type, token, name, ownerId, ownerCanAddInternalSystemWindow,
Garfield Tane3d37b52019-07-23 12:43:05 -0700294 mWm, mMockSession, mIWindow, mSystemServicesTestRule.getPowerManagerWrapper());
Adrian Roos3150dbf2018-03-28 18:06:52 +0200295 }
296
297 static WindowState createWindow(WindowState parent, int type, WindowToken token,
298 String name, int ownerId, boolean ownerCanAddInternalSystemWindow,
Garfield Tane3d37b52019-07-23 12:43:05 -0700299 WindowManagerService service, Session session, IWindow iWindow,
300 WindowState.PowerManagerWrapper powerManagerWrapper) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700301 synchronized (service.mGlobalLock) {
chaviw97d28202018-02-27 16:23:53 -0800302 final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type);
303 attrs.setTitle(name);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800304
Adrian Roos3150dbf2018-03-28 18:06:52 +0200305 final WindowState w = new WindowState(service, session, iWindow, token, parent,
chaviw97d28202018-02-27 16:23:53 -0800306 OP_NONE,
307 0, attrs, VISIBLE, ownerId, ownerCanAddInternalSystemWindow,
Garfield Tane3d37b52019-07-23 12:43:05 -0700308 powerManagerWrapper);
chaviw97d28202018-02-27 16:23:53 -0800309 // TODO: Probably better to make this call in the WindowState ctor to avoid errors with
310 // adding it to the token...
311 token.addWindow(w);
312 return w;
313 }
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800314 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800315
Louis Changdc077272019-11-12 16:52:56 +0800316 /** Creates a {@link ActivityStack} and adds it to the specified {@link DisplayContent}. */
Wale Ogunwalebebd8cd2019-10-28 15:53:31 -0700317 ActivityStack createTaskStackOnDisplay(DisplayContent dc) {
318 return createTaskStackOnDisplay(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, dc);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800319 }
320
Wale Ogunwalebebd8cd2019-10-28 15:53:31 -0700321 ActivityStack createTaskStackOnDisplay(int windowingMode, int activityType, DisplayContent dc) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700322 synchronized (mWm.mGlobalLock) {
Wale Ogunwalebebd8cd2019-10-28 15:53:31 -0700323 return new ActivityTestsBase.StackBuilder(
Wale Ogunwalea733c792019-10-16 21:31:15 -0700324 dc.mWmService.mAtmService.mRootActivityContainer)
325 .setDisplay(dc.mActivityDisplay)
326 .setWindowingMode(windowingMode)
327 .setActivityType(activityType)
328 .setCreateActivity(false)
329 .build();
chaviw97d28202018-02-27 16:23:53 -0800330 }
Andrii Kuliand2765632016-12-12 22:26:34 -0800331 }
332
Wale Ogunwalebebd8cd2019-10-28 15:53:31 -0700333 /** Creates a {@link Task} and adds it to the specified {@link ActivityStack}. */
334 Task createTaskInStack(ActivityStack stack, int userId) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700335 return WindowTestUtils.createTaskInStack(mWm, stack, userId);
Andrii Kuliand2765632016-12-12 22:26:34 -0800336 }
337
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800338 /** Creates a {@link DisplayContent} and adds it to the system. */
339 DisplayContent createNewDisplay() {
Chilun8753ad32018-10-09 15:56:45 +0800340 return createNewDisplay(mDisplayInfo);
341 }
342
343 /** Creates a {@link DisplayContent} and adds it to the system. */
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700344 DisplayContent createNewDisplay(DisplayInfo info) {
345 final ActivityDisplay display =
346 TestActivityDisplay.create(mWm.mAtmService.mStackSupervisor, info);
347 mWm.mAtmService.mRootActivityContainer.addChild(display, POSITION_TOP);
348 return display.mDisplayContent;
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800349 }
350
lumark588a3e82018-07-20 18:53:54 +0800351 /**
352 * Creates a {@link DisplayContent} with given display state and adds it to the system.
353 *
lumark588a3e82018-07-20 18:53:54 +0800354 * @param displayState For initializing the state of the display. See
355 * {@link Display#getState()}.
356 */
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800357 DisplayContent createNewDisplay(int displayState) {
lumark588a3e82018-07-20 18:53:54 +0800358 // Leverage main display info & initialize it with display state for given displayId.
359 DisplayInfo displayInfo = new DisplayInfo();
360 displayInfo.copyFrom(mDisplayInfo);
361 displayInfo.state = displayState;
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700362 return createNewDisplay(displayInfo);
lumark588a3e82018-07-20 18:53:54 +0800363 }
364
Bryce Leeaf691c02017-03-20 14:20:22 -0700365 /** Creates a {@link com.android.server.wm.WindowTestUtils.TestWindowState} */
366 WindowTestUtils.TestWindowState createWindowState(WindowManager.LayoutParams attrs,
367 WindowToken token) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700368 synchronized (mWm.mGlobalLock) {
369 return new WindowTestUtils.TestWindowState(mWm, mMockSession, mIWindow, attrs, token);
chaviw97d28202018-02-27 16:23:53 -0800370 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800371 }
lumark51bc29e2019-05-04 12:22:15 +0800372
373 /** Creates a {@link DisplayContent} as parts of simulate display info for test. */
374 DisplayContent createMockSimulatedDisplay() {
375 DisplayInfo displayInfo = new DisplayInfo();
376 displayInfo.copyFrom(mDisplayInfo);
377 displayInfo.type = Display.TYPE_VIRTUAL;
378 displayInfo.ownerUid = SYSTEM_UID;
379 return createNewDisplay(displayInfo);
380 }
Wale Ogunwalea733c792019-10-16 21:31:15 -0700381
382 /** Sets the default minimum task size to 1 so that tests can use small task sizes */
Wale Ogunwale2322bed2019-10-10 17:24:19 +0200383 void removeGlobalMinSizeRestriction() {
Wale Ogunwalea733c792019-10-16 21:31:15 -0700384 mWm.mAtmService.mRootActivityContainer.mDefaultMinSizeOfResizeableTaskDp = 1;
385 }
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800386}