blob: 163268191df18814fb16de758593494955a945e7 [file] [log] [blame]
Bryce Leeaf691c02017-03-20 14:20:22 -07001/*
Wale Ogunwale59507092018-10-29 09:00:30 -07002 * Copyright (C) 2018 The Android Open Source Project
Bryce Leeaf691c02017-03-20 14:20:22 -07003 *
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
Wale Ogunwale59507092018-10-29 09:00:30 -070014 * limitations under the License
Bryce Leeaf691c02017-03-20 14:20:22 -070015 */
16
Wale Ogunwale59507092018-10-29 09:00:30 -070017package com.android.server.wm;
Bryce Leeaf691c02017-03-20 14:20:22 -070018
Bryce Lee18d51592017-10-25 10:22:19 -070019import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
20import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
Wale Ogunwale04a05ac2017-09-17 21:35:02 -070021import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
Evan Rosky72f084d2019-09-11 17:05:16 -070022import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
Wale Ogunwale8a1860a2019-06-05 08:57:19 -070023import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
24import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Andrii Kulian6a6c4f12018-07-16 21:23:33 -070025
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090026import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
27
Tadashi G. Takaokaa7a66952018-11-16 15:04:21 +090028import static com.android.dx.mockito.inline.extended.ExtendedMockito.any;
29import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean;
Tadashi G. Takaokaa7a66952018-11-16 15:04:21 +090030import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
Wale Ogunwaleda8b8272018-11-29 19:37:37 -080031import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
Tadashi G. Takaokaa7a66952018-11-16 15:04:21 +090032import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
Wale Ogunwaleb73f3962018-11-20 07:58:22 -080033import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
Andrii Kulian6a6c4f12018-07-16 21:23:33 -070034
Bryce Lee2b8e0372018-04-05 17:01:37 -070035import android.app.ActivityOptions;
Bryce Lee0bd8d422018-01-09 09:45:57 -080036import android.app.IApplicationThread;
Bryce Leeaf691c02017-03-20 14:20:22 -070037import android.content.ComponentName;
38import android.content.Context;
39import android.content.Intent;
40import android.content.pm.ActivityInfo;
41import android.content.pm.ApplicationInfo;
42import android.content.res.Configuration;
Wale Ogunwaleda8b8272018-11-29 19:37:37 -080043import android.os.Build;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -070044import android.os.UserHandle;
Bryce Lee93e7f792017-10-25 15:54:55 -070045import android.service.voice.IVoiceInteractionSession;
Riddle Hsub70b36d2018-09-11 21:20:02 +080046import android.view.DisplayInfo;
Adrian Roos3150dbf2018-03-28 18:06:52 +020047
Bryce Leeaf691c02017-03-20 14:20:22 -070048import com.android.server.AttributeCache;
Brett Chabota26eda92018-07-23 13:08:30 -070049
Bryce Leeaf691c02017-03-20 14:20:22 -070050import org.junit.Before;
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090051import org.junit.BeforeClass;
Andrii Kulian6a6c4f12018-07-16 21:23:33 -070052
Bryce Leeaf691c02017-03-20 14:20:22 -070053/**
54 * A base class to handle common operations in activity related unit tests.
55 */
Riddle Hsu73f53572019-09-23 23:13:01 +080056class ActivityTestsBase extends SystemServiceTestsBase {
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090057 final Context mContext = getInstrumentation().getTargetContext();
Bryce Leeaf691c02017-03-20 14:20:22 -070058
Riddle Hsub70b36d2018-09-11 21:20:02 +080059 ActivityTaskManagerService mService;
Wale Ogunwaled32da472018-11-16 07:19:28 -080060 RootActivityContainer mRootActivityContainer;
Riddle Hsub70b36d2018-09-11 21:20:02 +080061 ActivityStackSupervisor mSupervisor;
62
Bryce Leefbd263b42018-03-07 10:33:55 -080063 // Default package name
64 static final String DEFAULT_COMPONENT_PACKAGE_NAME = "com.foo";
65
66 // Default base activity name
67 private static final String DEFAULT_COMPONENT_CLASS_NAME = ".BarActivity";
68
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090069 @BeforeClass
70 public static void setUpOnceBase() {
71 AttributeCache.init(getInstrumentation().getTargetContext());
72 }
73
Bryce Leeaf691c02017-03-20 14:20:22 -070074 @Before
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090075 public void setUpBase() {
Wale Ogunwale8a1860a2019-06-05 08:57:19 -070076 mService = mSystemServicesTestRule.getActivityTaskManagerService();
Wale Ogunwale976ca472019-01-17 09:55:38 -080077 mSupervisor = mService.mStackSupervisor;
78 mRootActivityContainer = mService.mRootActivityContainer;
Bryce Lee3115bdf2017-04-05 08:39:40 -070079 }
Bryce Leeaf691c02017-03-20 14:20:22 -070080
Riddle Hsub70b36d2018-09-11 21:20:02 +080081 /** Creates a {@link TestActivityDisplay}. */
82 TestActivityDisplay createNewActivityDisplay() {
Wale Ogunwale8a1860a2019-06-05 08:57:19 -070083 return TestActivityDisplay.create(mSupervisor);
Riddle Hsub70b36d2018-09-11 21:20:02 +080084 }
85
Garfield Tan891146c2018-10-09 12:14:00 -070086 TestActivityDisplay createNewActivityDisplay(DisplayInfo info) {
Wale Ogunwale8a1860a2019-06-05 08:57:19 -070087 return TestActivityDisplay.create(mSupervisor, info);
Garfield Tan891146c2018-10-09 12:14:00 -070088 }
89
Riddle Hsub70b36d2018-09-11 21:20:02 +080090 /** Creates and adds a {@link TestActivityDisplay} to supervisor at the given position. */
91 TestActivityDisplay addNewActivityDisplayAt(int position) {
92 final TestActivityDisplay display = createNewActivityDisplay();
Wale Ogunwaled32da472018-11-16 07:19:28 -080093 mRootActivityContainer.addChild(display, position);
Riddle Hsub70b36d2018-09-11 21:20:02 +080094 return display;
95 }
96
Evan Rosky730f6e82018-12-03 17:40:11 -080097 /** Creates and adds a {@link TestActivityDisplay} to supervisor at the given position. */
98 TestActivityDisplay addNewActivityDisplayAt(DisplayInfo info, int position) {
99 final TestActivityDisplay display = createNewActivityDisplay(info);
100 mRootActivityContainer.addChild(display, position);
101 return display;
102 }
103
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700104 /** Sets the default minimum task size to 1 so that tests can use small task sizes */
105 public void removeGlobalMinSizeRestriction() {
106 mService.mRootActivityContainer.mDefaultMinSizeOfResizeableTaskDp = 1;
Riddle Hsu609a8e22019-06-27 16:46:29 -0600107 }
108
Riddle Hsuff9e8282019-04-24 23:55:11 +0800109 /**
Bryce Lee18d51592017-10-25 10:22:19 -0700110 * Builder for creating new activities.
111 */
112 protected static class ActivityBuilder {
113 // An id appended to the end of the component name to make it unique
114 private static int sCurrentActivityId = 0;
Bryce Lee9f6affd2017-09-01 09:18:35 -0700115
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700116 private final ActivityTaskManagerService mService;
Bryce Lee18d51592017-10-25 10:22:19 -0700117
118 private ComponentName mComponent;
Louis Chang23df1a62019-01-09 15:10:49 +0800119 private String mTargetActivity;
Louis Changcdec0802019-11-11 11:45:07 +0800120 private Task mTask;
Riddle Hsu1063b512019-10-22 21:12:23 +0800121 private String mProcessName = "name";
122 private int mUid = 12345;
Bryce Lee18d51592017-10-25 10:22:19 -0700123 private boolean mCreateTask;
124 private ActivityStack mStack;
Bryce Leec961e0a2018-04-13 17:58:02 -0700125 private int mActivityFlags;
Riddle Hsub70b36d2018-09-11 21:20:02 +0800126 private int mLaunchMode;
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700127 private int mResizeMode = RESIZE_MODE_RESIZEABLE;
128 private float mMaxAspectRatio;
129 private int mScreenOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
130 private boolean mLaunchTaskBehind;
131 private int mConfigChanges;
lumarkf65e02d2019-09-14 19:25:21 +0800132 private int mLaunchedFromPid;
133 private int mLaunchedFromUid;
Bryce Lee18d51592017-10-25 10:22:19 -0700134
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700135 ActivityBuilder(ActivityTaskManagerService service) {
Bryce Lee18d51592017-10-25 10:22:19 -0700136 mService = service;
Bryce Leeaf691c02017-03-20 14:20:22 -0700137 }
138
Bryce Lee18d51592017-10-25 10:22:19 -0700139 ActivityBuilder setComponent(ComponentName component) {
140 mComponent = component;
141 return this;
142 }
143
Louis Chang23df1a62019-01-09 15:10:49 +0800144 ActivityBuilder setTargetActivity(String targetActivity) {
145 mTargetActivity = targetActivity;
146 return this;
147 }
148
Bryce Leead5b8322018-03-08 14:28:52 -0800149 static ComponentName getDefaultComponent() {
150 return ComponentName.createRelative(DEFAULT_COMPONENT_PACKAGE_NAME,
151 DEFAULT_COMPONENT_PACKAGE_NAME);
152 }
153
Louis Changcdec0802019-11-11 11:45:07 +0800154 ActivityBuilder setTask(Task task) {
155 mTask = task;
Bryce Lee18d51592017-10-25 10:22:19 -0700156 return this;
157 }
158
Bryce Leec961e0a2018-04-13 17:58:02 -0700159 ActivityBuilder setActivityFlags(int flags) {
160 mActivityFlags = flags;
161 return this;
162 }
163
Riddle Hsub70b36d2018-09-11 21:20:02 +0800164 ActivityBuilder setLaunchMode(int launchMode) {
165 mLaunchMode = launchMode;
166 return this;
167 }
168
Bryce Lee18d51592017-10-25 10:22:19 -0700169 ActivityBuilder setStack(ActivityStack stack) {
170 mStack = stack;
171 return this;
172 }
173
174 ActivityBuilder setCreateTask(boolean createTask) {
175 mCreateTask = createTask;
176 return this;
177 }
178
Riddle Hsu1063b512019-10-22 21:12:23 +0800179 ActivityBuilder setProcessName(String name) {
180 mProcessName = name;
181 return this;
182 }
183
Bryce Lee18d51592017-10-25 10:22:19 -0700184 ActivityBuilder setUid(int uid) {
185 mUid = uid;
186 return this;
187 }
188
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700189 ActivityBuilder setResizeMode(int resizeMode) {
190 mResizeMode = resizeMode;
191 return this;
192 }
193
194 ActivityBuilder setMaxAspectRatio(float maxAspectRatio) {
195 mMaxAspectRatio = maxAspectRatio;
196 return this;
197 }
198
199 ActivityBuilder setScreenOrientation(int screenOrientation) {
200 mScreenOrientation = screenOrientation;
201 return this;
202 }
203
204 ActivityBuilder setLaunchTaskBehind(boolean launchTaskBehind) {
205 mLaunchTaskBehind = launchTaskBehind;
206 return this;
207 }
208
209 ActivityBuilder setConfigChanges(int configChanges) {
210 mConfigChanges = configChanges;
211 return this;
212 }
213
lumarkf65e02d2019-09-14 19:25:21 +0800214 ActivityBuilder setLaunchedFromPid(int pid) {
215 mLaunchedFromPid = pid;
216 return this;
217 }
218
219 ActivityBuilder setLaunchedFromUid(int uid) {
220 mLaunchedFromUid = uid;
221 return this;
222 }
223
Bryce Lee18d51592017-10-25 10:22:19 -0700224 ActivityRecord build() {
225 if (mComponent == null) {
226 final int id = sCurrentActivityId++;
Bryce Leefbd263b42018-03-07 10:33:55 -0800227 mComponent = ComponentName.createRelative(DEFAULT_COMPONENT_PACKAGE_NAME,
228 DEFAULT_COMPONENT_CLASS_NAME + id);
Bryce Lee18d51592017-10-25 10:22:19 -0700229 }
230
231 if (mCreateTask) {
Louis Changcdec0802019-11-11 11:45:07 +0800232 mTask = new TaskBuilder(mService.mStackSupervisor)
Bryce Lee18d51592017-10-25 10:22:19 -0700233 .setComponent(mComponent)
234 .setStack(mStack).build();
235 }
236
237 Intent intent = new Intent();
238 intent.setComponent(mComponent);
239 final ActivityInfo aInfo = new ActivityInfo();
240 aInfo.applicationInfo = new ApplicationInfo();
Wale Ogunwale3198da42019-10-10 14:45:03 +0200241 aInfo.applicationInfo.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;
Bryce Lee18d51592017-10-25 10:22:19 -0700242 aInfo.applicationInfo.packageName = mComponent.getPackageName();
243 aInfo.applicationInfo.uid = mUid;
Riddle Hsu1063b512019-10-22 21:12:23 +0800244 aInfo.processName = mProcessName;
Louis Chang23df1a62019-01-09 15:10:49 +0800245 aInfo.packageName = mComponent.getPackageName();
246 if (mTargetActivity != null) {
247 aInfo.targetActivity = mTargetActivity;
248 }
Bryce Leec961e0a2018-04-13 17:58:02 -0700249 aInfo.flags |= mActivityFlags;
Riddle Hsub70b36d2018-09-11 21:20:02 +0800250 aInfo.launchMode = mLaunchMode;
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700251 aInfo.resizeMode = mResizeMode;
252 aInfo.maxAspectRatio = mMaxAspectRatio;
253 aInfo.screenOrientation = mScreenOrientation;
254 aInfo.configChanges |= mConfigChanges;
255
256 ActivityOptions options = null;
257 if (mLaunchTaskBehind) {
258 options = ActivityOptions.makeTaskLaunchBehind();
259 }
Bryce Leec961e0a2018-04-13 17:58:02 -0700260
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700261 final ActivityRecord activity = new ActivityRecord(mService, null /* caller */,
lumarkf65e02d2019-09-14 19:25:21 +0800262 mLaunchedFromPid /* launchedFromPid */, mLaunchedFromUid /* launchedFromUid */,
263 null, intent, null, aInfo /*aInfo*/, new Configuration(), null /* resultTo */,
264 null /* resultWho */, 0 /* reqCode */, false /*componentSpecified*/,
265 false /* rootVoiceInteraction */, mService.mStackSupervisor, options,
266 null /* sourceRecord */);
Yunfan Chend4ef3012018-11-28 21:14:32 -0800267 spyOn(activity);
Louis Changcdec0802019-11-11 11:45:07 +0800268 if (mTask != null) {
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700269 // fullscreen value is normally read from resources in ctor, so for testing we need
270 // to set it somewhere else since we can't mock resources.
Wale Ogunwaleda8b8272018-11-29 19:37:37 -0800271 doReturn(true).when(activity).occludesParent();
Louis Changcdec0802019-11-11 11:45:07 +0800272 mTask.addChild(activity);
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700273 // Make visible by default...
Issei Suzukif2f6c912019-11-08 11:24:18 +0100274 activity.setVisible(true);
Bryce Lee18d51592017-10-25 10:22:19 -0700275 }
276
Andrii Kulianbeadacc2019-05-20 12:18:01 +0000277 final WindowProcessController wpc = new WindowProcessController(mService,
Riddle Hsu1063b512019-10-22 21:12:23 +0800278 mService.mContext.getApplicationInfo(), mProcessName, mUid,
Andrii Kulianbeadacc2019-05-20 12:18:01 +0000279 UserHandle.getUserId(12345), mock(Object.class),
280 mock(WindowProcessListener.class));
281 wpc.setThread(mock(IApplicationThread.class));
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700282 activity.setProcess(wpc);
Wale Ogunwaleda8b8272018-11-29 19:37:37 -0800283 doReturn(wpc).when(mService).getProcessController(
284 activity.processName, activity.info.applicationInfo.uid);
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700285
286 // Resume top activities to make sure all other signals in the system are connected.
287 mService.mRootActivityContainer.resumeFocusedStacksTopActivities();
Bryce Lee18d51592017-10-25 10:22:19 -0700288 return activity;
289 }
Bryce Leeaf691c02017-03-20 14:20:22 -0700290 }
291
Bryce Lee18d51592017-10-25 10:22:19 -0700292 /**
293 * Builder for creating new tasks.
294 */
295 protected static class TaskBuilder {
296 private final ActivityStackSupervisor mSupervisor;
Winson Chung1dbc8112017-09-28 18:05:31 -0700297
Bryce Lee18d51592017-10-25 10:22:19 -0700298 private ComponentName mComponent;
299 private String mPackage;
300 private int mFlags = 0;
Kazuki Takisec2e17bf2018-07-17 17:46:38 +0900301 // Task id 0 is reserved in ARC for the home app.
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700302 private int mTaskId = SystemServicesTestRule.sNextTaskId++;
Winson Chung0ec2a352017-10-26 11:38:30 -0700303 private int mUserId = 0;
Bryce Lee93e7f792017-10-25 15:54:55 -0700304 private IVoiceInteractionSession mVoiceSession;
Bryce Lee2b8e0372018-04-05 17:01:37 -0700305 private boolean mCreateStack = true;
Bryce Leeaf691c02017-03-20 14:20:22 -0700306
Bryce Lee18d51592017-10-25 10:22:19 -0700307 private ActivityStack mStack;
Bryce Leeaf691c02017-03-20 14:20:22 -0700308
Bryce Lee18d51592017-10-25 10:22:19 -0700309 TaskBuilder(ActivityStackSupervisor supervisor) {
310 mSupervisor = supervisor;
311 }
Bryce Leeaf691c02017-03-20 14:20:22 -0700312
Bryce Lee18d51592017-10-25 10:22:19 -0700313 TaskBuilder setComponent(ComponentName component) {
314 mComponent = component;
315 return this;
316 }
317
318 TaskBuilder setPackage(String packageName) {
319 mPackage = packageName;
320 return this;
321 }
322
Bryce Lee2b8e0372018-04-05 17:01:37 -0700323 /**
324 * Set to {@code true} by default, set to {@code false} to prevent the task from
325 * automatically creating a parent stack.
326 */
327 TaskBuilder setCreateStack(boolean createStack) {
328 mCreateStack = createStack;
329 return this;
330 }
331
Bryce Lee93e7f792017-10-25 15:54:55 -0700332 TaskBuilder setVoiceSession(IVoiceInteractionSession session) {
333 mVoiceSession = session;
334 return this;
335 }
336
Bryce Lee18d51592017-10-25 10:22:19 -0700337 TaskBuilder setFlags(int flags) {
338 mFlags = flags;
339 return this;
340 }
341
342 TaskBuilder setTaskId(int taskId) {
343 mTaskId = taskId;
344 return this;
345 }
346
Winson Chung0ec2a352017-10-26 11:38:30 -0700347 TaskBuilder setUserId(int userId) {
348 mUserId = userId;
349 return this;
350 }
351
Bryce Lee18d51592017-10-25 10:22:19 -0700352 TaskBuilder setStack(ActivityStack stack) {
353 mStack = stack;
354 return this;
355 }
356
Louis Changcdec0802019-11-11 11:45:07 +0800357 Task build() {
Bryce Lee2b8e0372018-04-05 17:01:37 -0700358 if (mStack == null && mCreateStack) {
Wale Ogunwaled32da472018-11-16 07:19:28 -0800359 mStack = mSupervisor.mRootActivityContainer.getDefaultDisplay().createStack(
Bryce Lee18d51592017-10-25 10:22:19 -0700360 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */);
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700361 spyOn(mStack);
Bryce Lee18d51592017-10-25 10:22:19 -0700362 }
363
364 final ActivityInfo aInfo = new ActivityInfo();
365 aInfo.applicationInfo = new ApplicationInfo();
366 aInfo.applicationInfo.packageName = mPackage;
367
368 Intent intent = new Intent();
Bryce Leefbd263b42018-03-07 10:33:55 -0800369 if (mComponent == null) {
370 mComponent = ComponentName.createRelative(DEFAULT_COMPONENT_PACKAGE_NAME,
371 DEFAULT_COMPONENT_CLASS_NAME);
372 }
373
Bryce Lee18d51592017-10-25 10:22:19 -0700374 intent.setComponent(mComponent);
375 intent.setFlags(mFlags);
376
Louis Changcdec0802019-11-11 11:45:07 +0800377 final Task task = new Task(mSupervisor.mService, mTaskId, aInfo,
Wale Ogunwale4e79a1c2019-10-05 20:52:40 -0700378 intent /*intent*/, mVoiceSession, null /*_voiceInteractor*/,
Wale Ogunwale2322bed2019-10-10 17:24:19 +0200379 null /*taskDescription*/, mStack);
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700380 spyOn(task);
Wale Ogunwale4e79a1c2019-10-05 20:52:40 -0700381 task.mUserId = mUserId;
Bryce Lee2b8e0372018-04-05 17:01:37 -0700382
383 if (mStack != null) {
Andrii Kulian6a6c4f12018-07-16 21:23:33 -0700384 mStack.moveToFront("test");
Wale Ogunwale2322bed2019-10-10 17:24:19 +0200385 mStack.addChild(task, true, true);
Bryce Lee2b8e0372018-04-05 17:01:37 -0700386 }
387
Bryce Lee18d51592017-10-25 10:22:19 -0700388 return task;
389 }
Bryce Leeaf691c02017-03-20 14:20:22 -0700390 }
Louis Changf2835df2018-10-17 15:14:45 +0800391
Wale Ogunwaled32da472018-11-16 07:19:28 -0800392 static class StackBuilder {
393 private final RootActivityContainer mRootActivityContainer;
Louis Changf2835df2018-10-17 15:14:45 +0800394 private ActivityDisplay mDisplay;
395 private int mStackId = -1;
Evan Rosky72f084d2019-09-11 17:05:16 -0700396 private int mWindowingMode = WINDOWING_MODE_UNDEFINED;
Louis Changf2835df2018-10-17 15:14:45 +0800397 private int mActivityType = ACTIVITY_TYPE_STANDARD;
398 private boolean mOnTop = true;
399 private boolean mCreateActivity = true;
400
Wale Ogunwaled32da472018-11-16 07:19:28 -0800401 StackBuilder(RootActivityContainer root) {
402 mRootActivityContainer = root;
403 mDisplay = mRootActivityContainer.getDefaultDisplay();
Louis Changf2835df2018-10-17 15:14:45 +0800404 }
405
406 StackBuilder setWindowingMode(int windowingMode) {
407 mWindowingMode = windowingMode;
408 return this;
409 }
410
411 StackBuilder setActivityType(int activityType) {
412 mActivityType = activityType;
413 return this;
414 }
415
416 StackBuilder setStackId(int stackId) {
417 mStackId = stackId;
418 return this;
419 }
420
421 StackBuilder setDisplay(ActivityDisplay display) {
422 mDisplay = display;
423 return this;
424 }
425
426 StackBuilder setOnTop(boolean onTop) {
427 mOnTop = onTop;
428 return this;
429 }
430
431 StackBuilder setCreateActivity(boolean createActivity) {
432 mCreateActivity = createActivity;
433 return this;
434 }
435
Yunfan Chen279f5582018-12-12 15:24:50 -0800436 ActivityStack build() {
Louis Changf2835df2018-10-17 15:14:45 +0800437 final int stackId = mStackId >= 0 ? mStackId : mDisplay.getNextStackId();
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700438 final ActivityStack stack;
439 final ActivityStackSupervisor supervisor = mRootActivityContainer.mStackSupervisor;
Louis Changf2835df2018-10-17 15:14:45 +0800440 if (mWindowingMode == WINDOWING_MODE_PINNED) {
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700441 stack = new ActivityStack(mDisplay, stackId, supervisor,
Hongwei Wang43a752b2019-09-17 20:20:30 +0000442 mWindowingMode, ACTIVITY_TYPE_STANDARD, mOnTop);
Louis Changf2835df2018-10-17 15:14:45 +0800443 } else {
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700444 stack = new ActivityStack(mDisplay, stackId, supervisor,
445 mWindowingMode, mActivityType, mOnTop);
446
447 if (mCreateActivity) {
448 new ActivityBuilder(supervisor.mService)
449 .setCreateTask(true)
450 .setStack(stack)
451 .build();
452 if (mOnTop) {
453 // We move the task to front again in order to regain focus after activity
454 // added to the stack.
455 // Or {@link ActivityDisplay#mPreferredTopFocusableStack} could be other
456 // stacks (e.g. home stack).
457 stack.moveToFront("createActivityStack");
458 } else {
459 stack.moveToBack("createActivityStack", null);
460 }
461 }
Louis Changf2835df2018-10-17 15:14:45 +0800462 }
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700463
464 spyOn(stack);
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700465 doNothing().when(stack).startActivityLocked(
466 any(), any(), anyBoolean(), anyBoolean(), any());
467
468 return stack;
Louis Changf2835df2018-10-17 15:14:45 +0800469 }
470
471 }
Bryce Leeaf691c02017-03-20 14:20:22 -0700472}