blob: 4a193454f818abcc0daaf28dffe22e80eb463b75 [file] [log] [blame]
Bryce Leeaf691c02017-03-20 14:20:22 -07001/*
2 * Copyright (C) 2017 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.am;
18
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;
Bryce Leef3c6a472017-11-14 14:53:06 -080022import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
Wale Ogunwale9dcf9462017-09-19 15:13:01 -070023import static android.view.Display.DEFAULT_DISPLAY;
Bryce Leeaf691c02017-03-20 14:20:22 -070024import static org.mockito.Mockito.mock;
Bryce Lee2a3cc462017-10-27 10:57:35 -070025import static org.mockito.Mockito.doNothing;
Bryce Lee04ab3462017-04-10 15:06:33 -070026import static org.mockito.Mockito.doReturn;
27import static org.mockito.Mockito.any;
Bryce Lee2a3cc462017-10-27 10:57:35 -070028import static org.mockito.Mockito.anyBoolean;
29import static org.mockito.Mockito.anyInt;
Bryce Lee04ab3462017-04-10 15:06:33 -070030import static org.mockito.Mockito.doAnswer;
Bryce Lee4e4a3ec2017-09-27 08:25:03 -070031import static org.mockito.Mockito.spy;
Bryce Lee04ab3462017-04-10 15:06:33 -070032
Winson Chung59a47ded2018-01-25 17:46:06 +000033import com.android.server.wm.DisplayWindowController;
Bryce Lee04ab3462017-04-10 15:06:33 -070034import org.mockito.invocation.InvocationOnMock;
Bryce Leeaf691c02017-03-20 14:20:22 -070035
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;
Bryce Leeba8f4422017-11-20 12:35:57 -080042import android.content.pm.IPackageManager;
Bryce Leeaf691c02017-03-20 14:20:22 -070043import android.content.res.Configuration;
44import android.graphics.Rect;
Wale Ogunwale9dcf9462017-09-19 15:13:01 -070045import android.hardware.display.DisplayManager;
Bryce Lee3115bdf2017-04-05 08:39:40 -070046import android.os.HandlerThread;
Bryce Leeaf691c02017-03-20 14:20:22 -070047import android.os.Looper;
Bryce Lee93e7f792017-10-25 15:54:55 -070048import android.service.voice.IVoiceInteractionSession;
Bryce Leeaf691c02017-03-20 14:20:22 -070049import android.support.test.InstrumentationRegistry;
50import com.android.server.AttributeCache;
51import com.android.server.wm.AppWindowContainerController;
Bryce Lee4e4a3ec2017-09-27 08:25:03 -070052import com.android.server.wm.PinnedStackWindowController;
Bryce Leeaf691c02017-03-20 14:20:22 -070053import com.android.server.wm.StackWindowController;
Bryce Lee04ab3462017-04-10 15:06:33 -070054import com.android.server.wm.TaskWindowContainerController;
Bryce Leeaf691c02017-03-20 14:20:22 -070055import com.android.server.wm.WindowManagerService;
56import com.android.server.wm.WindowTestUtils;
Bryce Lee3115bdf2017-04-05 08:39:40 -070057import org.junit.After;
Bryce Leeaf691c02017-03-20 14:20:22 -070058import org.junit.Before;
59import org.mockito.MockitoAnnotations;
60
61/**
62 * A base class to handle common operations in activity related unit tests.
63 */
64public class ActivityTestsBase {
Bryce Lee939a9a32017-10-23 10:01:21 -070065 private static boolean sOneTimeSetupDone = false;
66
Bryce Leeaf691c02017-03-20 14:20:22 -070067 private final Context mContext = InstrumentationRegistry.getContext();
Bryce Lee3115bdf2017-04-05 08:39:40 -070068 private HandlerThread mHandlerThread;
Bryce Leeaf691c02017-03-20 14:20:22 -070069
Bryce Leefbd263b42018-03-07 10:33:55 -080070 // Default package name
71 static final String DEFAULT_COMPONENT_PACKAGE_NAME = "com.foo";
72
73 // Default base activity name
74 private static final String DEFAULT_COMPONENT_CLASS_NAME = ".BarActivity";
75
Bryce Leeaf691c02017-03-20 14:20:22 -070076 @Before
77 public void setUp() throws Exception {
Bryce Lee939a9a32017-10-23 10:01:21 -070078 if (!sOneTimeSetupDone) {
79 sOneTimeSetupDone = true;
80
81 // Allows to mock package local classes and methods
82 System.setProperty("dexmaker.share_classloader", "true");
83 MockitoAnnotations.initMocks(this);
84 }
Bryce Lee3115bdf2017-04-05 08:39:40 -070085 mHandlerThread = new HandlerThread("ActivityTestsBaseThread");
86 mHandlerThread.start();
87 }
Bryce Leeaf691c02017-03-20 14:20:22 -070088
Bryce Lee3115bdf2017-04-05 08:39:40 -070089 @After
90 public void tearDown() {
91 mHandlerThread.quitSafely();
Bryce Leeaf691c02017-03-20 14:20:22 -070092 }
93
94 protected ActivityManagerService createActivityManagerService() {
Bryce Lee93e7f792017-10-25 15:54:55 -070095 final ActivityManagerService service =
96 setupActivityManagerService(new TestActivityManagerService(mContext));
97 AttributeCache.init(mContext);
98 return service;
Winson Chung3f0e59a2017-10-25 10:19:05 -070099 }
100
101 protected ActivityManagerService setupActivityManagerService(ActivityManagerService service) {
102 service = spy(service);
Bryce Leeba8f4422017-11-20 12:35:57 -0800103 doReturn(mock(IPackageManager.class)).when(service).getPackageManager();
Bryce Lee4e4a3ec2017-09-27 08:25:03 -0700104 service.mWindowManager = prepareMockWindowManager();
Bryce Lee840c5662017-04-13 10:02:51 -0700105 return service;
Bryce Leeaf691c02017-03-20 14:20:22 -0700106 }
107
Bryce Lee18d51592017-10-25 10:22:19 -0700108 /**
109 * Builder for creating new activities.
110 */
111 protected static class ActivityBuilder {
112 // An id appended to the end of the component name to make it unique
113 private static int sCurrentActivityId = 0;
Bryce Lee9f6affd2017-09-01 09:18:35 -0700114
Bryce Leeaf691c02017-03-20 14:20:22 -0700115
Bryce Lee18d51592017-10-25 10:22:19 -0700116
117 private final ActivityManagerService mService;
118
119 private ComponentName mComponent;
120 private TaskRecord mTaskRecord;
121 private int mUid;
122 private boolean mCreateTask;
123 private ActivityStack mStack;
124
125 ActivityBuilder(ActivityManagerService service) {
126 mService = service;
Bryce Leeaf691c02017-03-20 14:20:22 -0700127 }
128
Bryce Lee18d51592017-10-25 10:22:19 -0700129 ActivityBuilder setComponent(ComponentName component) {
130 mComponent = component;
131 return this;
132 }
133
134 ActivityBuilder setTask(TaskRecord task) {
135 mTaskRecord = task;
136 return this;
137 }
138
139 ActivityBuilder setStack(ActivityStack stack) {
140 mStack = stack;
141 return this;
142 }
143
144 ActivityBuilder setCreateTask(boolean createTask) {
145 mCreateTask = createTask;
146 return this;
147 }
148
149 ActivityBuilder setUid(int uid) {
150 mUid = uid;
151 return this;
152 }
153
Bryce Leefbd263b42018-03-07 10:33:55 -0800154 String getDefaultComponentPackageName() {
155 return DEFAULT_COMPONENT_PACKAGE_NAME;
156 }
157
Bryce Lee18d51592017-10-25 10:22:19 -0700158 ActivityRecord build() {
159 if (mComponent == null) {
160 final int id = sCurrentActivityId++;
Bryce Leefbd263b42018-03-07 10:33:55 -0800161 mComponent = ComponentName.createRelative(DEFAULT_COMPONENT_PACKAGE_NAME,
162 DEFAULT_COMPONENT_CLASS_NAME + id);
Bryce Lee18d51592017-10-25 10:22:19 -0700163 }
164
165 if (mCreateTask) {
166 mTaskRecord = new TaskBuilder(mService.mStackSupervisor)
167 .setComponent(mComponent)
168 .setStack(mStack).build();
169 }
170
171 Intent intent = new Intent();
172 intent.setComponent(mComponent);
173 final ActivityInfo aInfo = new ActivityInfo();
174 aInfo.applicationInfo = new ApplicationInfo();
175 aInfo.applicationInfo.packageName = mComponent.getPackageName();
176 aInfo.applicationInfo.uid = mUid;
Bryce Lee18d51592017-10-25 10:22:19 -0700177 final ActivityRecord activity = new ActivityRecord(mService, null /* caller */,
178 0 /* launchedFromPid */, 0, null, intent, null,
179 aInfo /*aInfo*/, new Configuration(), null /* resultTo */, null /* resultWho */,
180 0 /* reqCode */, false /*componentSpecified*/, false /* rootVoiceInteraction */,
181 mService.mStackSupervisor, null /* options */, null /* sourceRecord */);
182 activity.mWindowContainerController = mock(AppWindowContainerController.class);
183
184 if (mTaskRecord != null) {
185 mTaskRecord.addActivityToTop(activity);
186 }
187
Bryce Lee0bd8d422018-01-09 09:45:57 -0800188 activity.setProcess(new ProcessRecord(null, mService.mContext.getApplicationInfo(),
189 "name", 12345));
190 activity.app.thread = mock(IApplicationThread.class);
191
Bryce Lee18d51592017-10-25 10:22:19 -0700192 return activity;
193 }
Bryce Leeaf691c02017-03-20 14:20:22 -0700194 }
195
Bryce Lee18d51592017-10-25 10:22:19 -0700196 /**
197 * Builder for creating new tasks.
198 */
199 protected static class TaskBuilder {
Bryce Leefbd263b42018-03-07 10:33:55 -0800200 // Default package name
201 static final String DEFAULT_PACKAGE = "com.bar";
202
Bryce Lee18d51592017-10-25 10:22:19 -0700203 private final ActivityStackSupervisor mSupervisor;
Winson Chung1dbc8112017-09-28 18:05:31 -0700204
Bryce Lee18d51592017-10-25 10:22:19 -0700205 private ComponentName mComponent;
206 private String mPackage;
207 private int mFlags = 0;
208 private int mTaskId = 0;
Winson Chung0ec2a352017-10-26 11:38:30 -0700209 private int mUserId = 0;
Bryce Lee93e7f792017-10-25 15:54:55 -0700210 private IVoiceInteractionSession mVoiceSession;
Bryce Leeaf691c02017-03-20 14:20:22 -0700211
Bryce Lee18d51592017-10-25 10:22:19 -0700212 private ActivityStack mStack;
Bryce Leeaf691c02017-03-20 14:20:22 -0700213
Bryce Lee18d51592017-10-25 10:22:19 -0700214 TaskBuilder(ActivityStackSupervisor supervisor) {
215 mSupervisor = supervisor;
216 }
Bryce Leeaf691c02017-03-20 14:20:22 -0700217
Bryce Lee18d51592017-10-25 10:22:19 -0700218 TaskBuilder setComponent(ComponentName component) {
219 mComponent = component;
220 return this;
221 }
222
223 TaskBuilder setPackage(String packageName) {
224 mPackage = packageName;
225 return this;
226 }
227
Bryce Lee93e7f792017-10-25 15:54:55 -0700228 TaskBuilder setVoiceSession(IVoiceInteractionSession session) {
229 mVoiceSession = session;
230 return this;
231 }
232
Bryce Lee18d51592017-10-25 10:22:19 -0700233 TaskBuilder setFlags(int flags) {
234 mFlags = flags;
235 return this;
236 }
237
238 TaskBuilder setTaskId(int taskId) {
239 mTaskId = taskId;
240 return this;
241 }
242
Winson Chung0ec2a352017-10-26 11:38:30 -0700243 TaskBuilder setUserId(int userId) {
244 mUserId = userId;
245 return this;
246 }
247
Bryce Lee18d51592017-10-25 10:22:19 -0700248 TaskBuilder setStack(ActivityStack stack) {
249 mStack = stack;
250 return this;
251 }
252
253 TaskRecord build() {
254 if (mStack == null) {
255 mStack = mSupervisor.getDefaultDisplay().createStack(
256 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */);
257 }
258
259 final ActivityInfo aInfo = new ActivityInfo();
260 aInfo.applicationInfo = new ApplicationInfo();
261 aInfo.applicationInfo.packageName = mPackage;
262
263 Intent intent = new Intent();
Bryce Leefbd263b42018-03-07 10:33:55 -0800264 if (mComponent == null) {
265 mComponent = ComponentName.createRelative(DEFAULT_COMPONENT_PACKAGE_NAME,
266 DEFAULT_COMPONENT_CLASS_NAME);
267 }
268
Bryce Lee18d51592017-10-25 10:22:19 -0700269 intent.setComponent(mComponent);
270 intent.setFlags(mFlags);
271
272 final TaskRecord task = new TaskRecord(mSupervisor.mService, mTaskId, aInfo,
Bryce Lee93e7f792017-10-25 15:54:55 -0700273 intent /*intent*/, mVoiceSession, null /*_voiceInteractor*/);
Winson Chung0ec2a352017-10-26 11:38:30 -0700274 task.userId = mUserId;
Bryce Lee18d51592017-10-25 10:22:19 -0700275 mSupervisor.setFocusStackUnchecked("test", mStack);
276 mStack.addTask(task, true, "creating test task");
277 task.setStack(mStack);
278 task.setWindowContainerController(mock(TaskWindowContainerController.class));
Winson Chung0ec2a352017-10-26 11:38:30 -0700279 task.touchActiveTime();
Bryce Lee18d51592017-10-25 10:22:19 -0700280
281 return task;
282 }
Bryce Leeaf691c02017-03-20 14:20:22 -0700283 }
284
285 /**
286 * An {@link ActivityManagerService} subclass which provides a test
287 * {@link ActivityStackSupervisor}.
288 */
289 protected static class TestActivityManagerService extends ActivityManagerService {
Bryce Leeb0f993f2018-03-02 15:38:01 -0800290 private ClientLifecycleManager mLifecycleManager;
291
Wale Ogunwale04a05ac2017-09-17 21:35:02 -0700292 TestActivityManagerService(Context context) {
Bryce Leeaf691c02017-03-20 14:20:22 -0700293 super(context);
Bryce Lee04ab3462017-04-10 15:06:33 -0700294 mSupportsMultiWindow = true;
295 mSupportsMultiDisplay = true;
Wale Ogunwale04a05ac2017-09-17 21:35:02 -0700296 mSupportsSplitScreenMultiWindow = true;
297 mSupportsFreeformWindowManagement = true;
298 mSupportsPictureInPicture = true;
Bryce Lee6a0754a2017-10-10 17:53:50 -0700299 mWindowManager = WindowTestUtils.getMockWindowManagerService();
Bryce Leeaf691c02017-03-20 14:20:22 -0700300 }
301
302 @Override
Bryce Leeb0f993f2018-03-02 15:38:01 -0800303 public ClientLifecycleManager getLifecycleManager() {
304 if (mLifecycleManager == null) {
305 return super.getLifecycleManager();
306 }
307 return mLifecycleManager;
308 }
309
310 void setLifecycleManager(ClientLifecycleManager manager) {
311 mLifecycleManager = manager;
312 }
313
314 @Override
Bryce Lee2a3cc462017-10-27 10:57:35 -0700315 final protected ActivityStackSupervisor createStackSupervisor() {
316 final ActivityStackSupervisor supervisor = spy(createTestSupervisor());
317
318 // No home stack is set.
319 doNothing().when(supervisor).moveHomeStackToFront(any());
320 doReturn(true).when(supervisor).moveHomeStackTaskToTop(any());
321 // Invoked during {@link ActivityStack} creation.
322 doNothing().when(supervisor).updateUIDsPresentOnDisplay();
323 // Always keep things awake.
324 doReturn(true).when(supervisor).hasAwakeDisplay();
325 // Called when moving activity to pinned stack.
326 doNothing().when(supervisor).ensureActivitiesVisibleLocked(any(), anyInt(), anyBoolean());
327 // Do not schedule idle timeouts
328 doNothing().when(supervisor).scheduleIdleTimeoutLocked(any());
Bryce Leefbd263b42018-03-07 10:33:55 -0800329 // unit test version does not handle launch wake lock
330 doNothing().when(supervisor).acquireLaunchWakelock();
Bryce Lee2a3cc462017-10-27 10:57:35 -0700331
332 supervisor.initialize();
333
334 return supervisor;
335 }
336
337 protected ActivityStackSupervisor createTestSupervisor() {
Bryce Lee3115bdf2017-04-05 08:39:40 -0700338 return new TestActivityStackSupervisor(this, mHandlerThread.getLooper());
Bryce Leeaf691c02017-03-20 14:20:22 -0700339 }
Bryce Lee29a649d2017-08-18 13:52:31 -0700340
341 @Override
342 void updateUsageStats(ActivityRecord component, boolean resumed) {
343 }
Bryce Leeaf691c02017-03-20 14:20:22 -0700344 }
345
346 /**
347 * An {@link ActivityStackSupervisor} which stubs out certain methods that depend on
348 * setup not available in the test environment. Also specifies an injector for
349 */
350 protected static class TestActivityStackSupervisor extends ActivityStackSupervisor {
Bryce Lee2a3cc462017-10-27 10:57:35 -0700351 private ActivityDisplay mDisplay;
Bryce Lee943ebe72017-05-04 10:19:07 -0700352
Bryce Leeaf691c02017-03-20 14:20:22 -0700353 public TestActivityStackSupervisor(ActivityManagerService service, Looper looper) {
354 super(service, looper);
Wale Ogunwale9dcf9462017-09-19 15:13:01 -0700355 mDisplayManager =
356 (DisplayManager) mService.mContext.getSystemService(Context.DISPLAY_SERVICE);
Bryce Lee04ab3462017-04-10 15:06:33 -0700357 mWindowManager = prepareMockWindowManager();
Bryce Lee2a3cc462017-10-27 10:57:35 -0700358 }
359
360 @Override
361 public void initialize() {
362 super.initialize();
Wale Ogunwale04a05ac2017-09-17 21:35:02 -0700363 mDisplay = new TestActivityDisplay(this, DEFAULT_DISPLAY);
Wale Ogunwale9dcf9462017-09-19 15:13:01 -0700364 attachDisplay(mDisplay);
Bryce Lee04ab3462017-04-10 15:06:33 -0700365 }
366
Wale Ogunwale04a05ac2017-09-17 21:35:02 -0700367 @Override
368 ActivityDisplay getDefaultDisplay() {
369 return mDisplay;
370 }
371
Bryce Lee2a3cc462017-10-27 10:57:35 -0700372 // Just return the current front task. This is called internally so we cannot use spy to mock this out.
Bryce Lee04ab3462017-04-10 15:06:33 -0700373 @Override
Wale Ogunwalee1f68ce2018-03-09 08:58:54 -0800374 ActivityStack getNextFocusableStackLocked(ActivityStack currentFocus,
375 boolean ignoreCurrent) {
Bryce Lee04ab3462017-04-10 15:06:33 -0700376 return mFocusedStack;
377 }
Wale Ogunwale04a05ac2017-09-17 21:35:02 -0700378 }
379
Winson Chung59a47ded2018-01-25 17:46:06 +0000380 protected static class TestActivityDisplay extends ActivityDisplay {
Wale Ogunwale04a05ac2017-09-17 21:35:02 -0700381
382 private final ActivityStackSupervisor mSupervisor;
383 TestActivityDisplay(ActivityStackSupervisor supervisor, int displayId) {
384 super(supervisor, displayId);
385 mSupervisor = supervisor;
Andrii Kulianb1cdb102017-07-13 15:33:06 -0700386 }
387
388 @Override
Wale Ogunwale04a05ac2017-09-17 21:35:02 -0700389 <T extends ActivityStack> T createStackUnchecked(int windowingMode, int activityType,
390 int stackId, boolean onTop) {
391 if (windowingMode == WINDOWING_MODE_PINNED) {
392 return (T) new PinnedActivityStack(this, stackId, mSupervisor, onTop) {
Andrii Kulianb1cdb102017-07-13 15:33:06 -0700393 @Override
394 Rect getDefaultPictureInPictureBounds(float aspectRatio) {
395 return new Rect(50, 50, 100, 100);
396 }
Bryce Lee4e4a3ec2017-09-27 08:25:03 -0700397
398 @Override
399 PinnedStackWindowController createStackWindowController(int displayId,
400 boolean onTop, Rect outBounds) {
401 return mock(PinnedStackWindowController.class);
402 }
Andrii Kulianb1cdb102017-07-13 15:33:06 -0700403 };
404 } else {
Wale Ogunwale04a05ac2017-09-17 21:35:02 -0700405 return (T) new TestActivityStack(
406 this, stackId, mSupervisor, windowingMode, activityType, onTop);
Andrii Kulianb1cdb102017-07-13 15:33:06 -0700407 }
Bryce Lee04ab3462017-04-10 15:06:33 -0700408 }
Winson Chung59a47ded2018-01-25 17:46:06 +0000409
410 @Override
411 protected DisplayWindowController createWindowContainerController() {
412 return mock(DisplayWindowController.class);
413 }
Bryce Leeaf691c02017-03-20 14:20:22 -0700414 }
415
Bryce Lee04ab3462017-04-10 15:06:33 -0700416 private static WindowManagerService prepareMockWindowManager() {
Bryce Lee4e4a3ec2017-09-27 08:25:03 -0700417 final WindowManagerService service = WindowTestUtils.getMockWindowManagerService();
Bryce Lee04ab3462017-04-10 15:06:33 -0700418
419 doAnswer((InvocationOnMock invocationOnMock) -> {
420 final Runnable runnable = invocationOnMock.<Runnable>getArgument(0);
421 if (runnable != null) {
422 runnable.run();
423 }
424 return null;
425 }).when(service).inSurfaceTransaction(any());
426
427 return service;
428 }
429
Bryce Leeaf691c02017-03-20 14:20:22 -0700430 /**
Bryce Lee4e4a3ec2017-09-27 08:25:03 -0700431 * Overrided of {@link ActivityStack} that tracks test metrics, such as the number of times a
Bryce Leeaf691c02017-03-20 14:20:22 -0700432 * method is called. Note that its functionality depends on the implementations of the
433 * construction arguments.
434 */
435 protected static class TestActivityStack<T extends StackWindowController>
Wale Ogunwale7e1f5f52017-10-18 15:19:59 -0700436 extends ActivityStack<T> {
Bryce Leeaf691c02017-03-20 14:20:22 -0700437 private int mOnActivityRemovedFromStackCount = 0;
438 private T mContainerController;
Wale Ogunwale04a05ac2017-09-17 21:35:02 -0700439
Wale Ogunwale7e1f5f52017-10-18 15:19:59 -0700440 static final int IS_TRANSLUCENT_UNSET = 0;
441 static final int IS_TRANSLUCENT_FALSE = 1;
442 static final int IS_TRANSLUCENT_TRUE = 2;
443 private int mIsTranslucent = IS_TRANSLUCENT_UNSET;
444
Wale Ogunwale30e441d2017-11-09 08:28:45 -0800445 static final int SUPPORTS_SPLIT_SCREEN_UNSET = 0;
446 static final int SUPPORTS_SPLIT_SCREEN_FALSE = 1;
447 static final int SUPPORTS_SPLIT_SCREEN_TRUE = 2;
448 private int mSupportsSplitScreen = SUPPORTS_SPLIT_SCREEN_UNSET;
449
Wale Ogunwale9dcf9462017-09-19 15:13:01 -0700450 TestActivityStack(ActivityDisplay display, int stackId, ActivityStackSupervisor supervisor,
Wale Ogunwale04a05ac2017-09-17 21:35:02 -0700451 int windowingMode, int activityType, boolean onTop) {
452 super(display, stackId, supervisor, windowingMode, activityType, onTop);
Bryce Leeaf691c02017-03-20 14:20:22 -0700453 }
454
455 @Override
456 void onActivityRemovedFromStack(ActivityRecord r) {
457 mOnActivityRemovedFromStackCount++;
458 super.onActivityRemovedFromStack(r);
459 }
460
461 // Returns the number of times {@link #onActivityRemovedFromStack} has been called
Wale Ogunwale7e1f5f52017-10-18 15:19:59 -0700462 int onActivityRemovedFromStackInvocationCount() {
Bryce Leeaf691c02017-03-20 14:20:22 -0700463 return mOnActivityRemovedFromStackCount;
464 }
465
466 @Override
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700467 protected T createStackWindowController(int displayId, boolean onTop, Rect outBounds) {
Bryce Leeaf691c02017-03-20 14:20:22 -0700468 mContainerController = (T) WindowTestUtils.createMockStackWindowContainerController();
Bryce Leef3c6a472017-11-14 14:53:06 -0800469
470 // Primary pinned stacks require a non-empty out bounds to be set or else all tasks
471 // will be moved to the full screen stack.
472 if (getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
473 outBounds.set(0, 0, 100, 100);
474 }
Bryce Leeaf691c02017-03-20 14:20:22 -0700475 return mContainerController;
476 }
477
478 @Override
479 T getWindowContainerController() {
480 return mContainerController;
481 }
Wale Ogunwale7e1f5f52017-10-18 15:19:59 -0700482
483 void setIsTranslucent(boolean isTranslucent) {
484 mIsTranslucent = isTranslucent ? IS_TRANSLUCENT_TRUE : IS_TRANSLUCENT_FALSE;
485 }
486
487 @Override
Wale Ogunwale66e16852017-10-19 13:35:52 -0700488 boolean isStackTranslucent(ActivityRecord starting) {
Wale Ogunwale7e1f5f52017-10-18 15:19:59 -0700489 switch (mIsTranslucent) {
490 case IS_TRANSLUCENT_TRUE:
491 return true;
492 case IS_TRANSLUCENT_FALSE:
493 return false;
494 case IS_TRANSLUCENT_UNSET:
495 default:
Wale Ogunwale66e16852017-10-19 13:35:52 -0700496 return super.isStackTranslucent(starting);
Wale Ogunwale7e1f5f52017-10-18 15:19:59 -0700497 }
498 }
Wale Ogunwale30e441d2017-11-09 08:28:45 -0800499
500 void setSupportsSplitScreen(boolean supportsSplitScreen) {
501 mSupportsSplitScreen = supportsSplitScreen
502 ? SUPPORTS_SPLIT_SCREEN_TRUE : SUPPORTS_SPLIT_SCREEN_FALSE;
503 }
504
505 @Override
506 public boolean supportsSplitScreenWindowingMode() {
507 switch (mSupportsSplitScreen) {
508 case SUPPORTS_SPLIT_SCREEN_TRUE:
509 return true;
510 case SUPPORTS_SPLIT_SCREEN_FALSE:
511 return false;
512 case SUPPORTS_SPLIT_SCREEN_UNSET:
513 default:
514 return super.supportsSplitScreenWindowingMode();
515 }
516 }
Bryce Leeaf691c02017-03-20 14:20:22 -0700517 }
Bryce Leeaf691c02017-03-20 14:20:22 -0700518}