Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.am; |
| 18 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 21 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 22 | import static android.view.Display.DEFAULT_DISPLAY; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 23 | import static org.mockito.Mockito.mock; |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 24 | import static org.mockito.Mockito.doReturn; |
| 25 | import static org.mockito.Mockito.any; |
| 26 | import static org.mockito.Mockito.doAnswer; |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 27 | import static org.mockito.Mockito.spy; |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 28 | |
| 29 | import org.mockito.invocation.InvocationOnMock; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 30 | |
| 31 | import android.content.ComponentName; |
| 32 | import android.content.Context; |
| 33 | import android.content.Intent; |
| 34 | import android.content.pm.ActivityInfo; |
| 35 | import android.content.pm.ApplicationInfo; |
| 36 | import android.content.res.Configuration; |
| 37 | import android.graphics.Rect; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 38 | import android.hardware.display.DisplayManager; |
Bryce Lee | 3115bdf | 2017-04-05 08:39:40 -0700 | [diff] [blame] | 39 | import android.os.HandlerThread; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 40 | import android.os.Looper; |
| 41 | import android.support.test.InstrumentationRegistry; |
| 42 | import com.android.server.AttributeCache; |
| 43 | import com.android.server.wm.AppWindowContainerController; |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 44 | import com.android.server.wm.PinnedStackWindowController; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 45 | import com.android.server.wm.StackWindowController; |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 46 | import com.android.server.wm.TaskWindowContainerController; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 47 | import com.android.server.wm.WindowManagerService; |
| 48 | import com.android.server.wm.WindowTestUtils; |
Bryce Lee | 3115bdf | 2017-04-05 08:39:40 -0700 | [diff] [blame] | 49 | import org.junit.After; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 50 | import org.junit.Before; |
| 51 | import org.mockito.MockitoAnnotations; |
| 52 | |
| 53 | /** |
| 54 | * A base class to handle common operations in activity related unit tests. |
| 55 | */ |
| 56 | public class ActivityTestsBase { |
Bryce Lee | 939a9a3 | 2017-10-23 10:01:21 -0700 | [diff] [blame] | 57 | private static boolean sOneTimeSetupDone = false; |
| 58 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 59 | private final Context mContext = InstrumentationRegistry.getContext(); |
Bryce Lee | 3115bdf | 2017-04-05 08:39:40 -0700 | [diff] [blame] | 60 | private HandlerThread mHandlerThread; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 61 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 62 | @Before |
| 63 | public void setUp() throws Exception { |
Bryce Lee | 939a9a3 | 2017-10-23 10:01:21 -0700 | [diff] [blame] | 64 | if (!sOneTimeSetupDone) { |
| 65 | sOneTimeSetupDone = true; |
| 66 | |
| 67 | // Allows to mock package local classes and methods |
| 68 | System.setProperty("dexmaker.share_classloader", "true"); |
| 69 | MockitoAnnotations.initMocks(this); |
| 70 | } |
Bryce Lee | 3115bdf | 2017-04-05 08:39:40 -0700 | [diff] [blame] | 71 | mHandlerThread = new HandlerThread("ActivityTestsBaseThread"); |
| 72 | mHandlerThread.start(); |
| 73 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 74 | |
Bryce Lee | 3115bdf | 2017-04-05 08:39:40 -0700 | [diff] [blame] | 75 | @After |
| 76 | public void tearDown() { |
| 77 | mHandlerThread.quitSafely(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | protected ActivityManagerService createActivityManagerService() { |
Winson Chung | 3f0e59a | 2017-10-25 10:19:05 -0700 | [diff] [blame] | 81 | return setupActivityManagerService(new TestActivityManagerService(mContext)); |
| 82 | } |
| 83 | |
| 84 | protected ActivityManagerService setupActivityManagerService(ActivityManagerService service) { |
| 85 | service = spy(service); |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 86 | service.mWindowManager = prepareMockWindowManager(); |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 87 | return service; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 90 | /** |
| 91 | * Builder for creating new activities. |
| 92 | */ |
| 93 | protected static class ActivityBuilder { |
| 94 | // An id appended to the end of the component name to make it unique |
| 95 | private static int sCurrentActivityId = 0; |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 96 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 97 | // Default package name |
| 98 | private static final String DEFAULT_PACKAGE = "com.foo"; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 99 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 100 | // Default base activity name |
| 101 | private static final String DEFAULT_BASE_ACTIVITY_NAME = ".BarActivity"; |
| 102 | |
| 103 | private final ActivityManagerService mService; |
| 104 | |
| 105 | private ComponentName mComponent; |
| 106 | private TaskRecord mTaskRecord; |
| 107 | private int mUid; |
| 108 | private boolean mCreateTask; |
| 109 | private ActivityStack mStack; |
| 110 | |
| 111 | ActivityBuilder(ActivityManagerService service) { |
| 112 | mService = service; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 115 | ActivityBuilder setComponent(ComponentName component) { |
| 116 | mComponent = component; |
| 117 | return this; |
| 118 | } |
| 119 | |
| 120 | ActivityBuilder setTask(TaskRecord task) { |
| 121 | mTaskRecord = task; |
| 122 | return this; |
| 123 | } |
| 124 | |
| 125 | ActivityBuilder setStack(ActivityStack stack) { |
| 126 | mStack = stack; |
| 127 | return this; |
| 128 | } |
| 129 | |
| 130 | ActivityBuilder setCreateTask(boolean createTask) { |
| 131 | mCreateTask = createTask; |
| 132 | return this; |
| 133 | } |
| 134 | |
| 135 | ActivityBuilder setUid(int uid) { |
| 136 | mUid = uid; |
| 137 | return this; |
| 138 | } |
| 139 | |
| 140 | ActivityRecord build() { |
| 141 | if (mComponent == null) { |
| 142 | final int id = sCurrentActivityId++; |
| 143 | mComponent = ComponentName.createRelative(DEFAULT_PACKAGE, |
| 144 | DEFAULT_BASE_ACTIVITY_NAME + id); |
| 145 | } |
| 146 | |
| 147 | if (mCreateTask) { |
| 148 | mTaskRecord = new TaskBuilder(mService.mStackSupervisor) |
| 149 | .setComponent(mComponent) |
| 150 | .setStack(mStack).build(); |
| 151 | } |
| 152 | |
| 153 | Intent intent = new Intent(); |
| 154 | intent.setComponent(mComponent); |
| 155 | final ActivityInfo aInfo = new ActivityInfo(); |
| 156 | aInfo.applicationInfo = new ApplicationInfo(); |
| 157 | aInfo.applicationInfo.packageName = mComponent.getPackageName(); |
| 158 | aInfo.applicationInfo.uid = mUid; |
| 159 | AttributeCache.init(mService.mContext); |
| 160 | final ActivityRecord activity = new ActivityRecord(mService, null /* caller */, |
| 161 | 0 /* launchedFromPid */, 0, null, intent, null, |
| 162 | aInfo /*aInfo*/, new Configuration(), null /* resultTo */, null /* resultWho */, |
| 163 | 0 /* reqCode */, false /*componentSpecified*/, false /* rootVoiceInteraction */, |
| 164 | mService.mStackSupervisor, null /* options */, null /* sourceRecord */); |
| 165 | activity.mWindowContainerController = mock(AppWindowContainerController.class); |
| 166 | |
| 167 | if (mTaskRecord != null) { |
| 168 | mTaskRecord.addActivityToTop(activity); |
| 169 | } |
| 170 | |
| 171 | return activity; |
| 172 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 175 | /** |
| 176 | * Builder for creating new tasks. |
| 177 | */ |
| 178 | protected static class TaskBuilder { |
| 179 | private final ActivityStackSupervisor mSupervisor; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 180 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 181 | private ComponentName mComponent; |
| 182 | private String mPackage; |
| 183 | private int mFlags = 0; |
| 184 | private int mTaskId = 0; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 185 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 186 | private ActivityStack mStack; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 187 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 188 | TaskBuilder(ActivityStackSupervisor supervisor) { |
| 189 | mSupervisor = supervisor; |
| 190 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 191 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 192 | TaskBuilder setComponent(ComponentName component) { |
| 193 | mComponent = component; |
| 194 | return this; |
| 195 | } |
| 196 | |
| 197 | TaskBuilder setPackage(String packageName) { |
| 198 | mPackage = packageName; |
| 199 | return this; |
| 200 | } |
| 201 | |
| 202 | TaskBuilder setFlags(int flags) { |
| 203 | mFlags = flags; |
| 204 | return this; |
| 205 | } |
| 206 | |
| 207 | TaskBuilder setTaskId(int taskId) { |
| 208 | mTaskId = taskId; |
| 209 | return this; |
| 210 | } |
| 211 | |
| 212 | TaskBuilder setStack(ActivityStack stack) { |
| 213 | mStack = stack; |
| 214 | return this; |
| 215 | } |
| 216 | |
| 217 | TaskRecord build() { |
| 218 | if (mStack == null) { |
| 219 | mStack = mSupervisor.getDefaultDisplay().createStack( |
| 220 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 221 | } |
| 222 | |
| 223 | final ActivityInfo aInfo = new ActivityInfo(); |
| 224 | aInfo.applicationInfo = new ApplicationInfo(); |
| 225 | aInfo.applicationInfo.packageName = mPackage; |
| 226 | |
| 227 | Intent intent = new Intent(); |
| 228 | intent.setComponent(mComponent); |
| 229 | intent.setFlags(mFlags); |
| 230 | |
| 231 | final TaskRecord task = new TaskRecord(mSupervisor.mService, mTaskId, aInfo, |
| 232 | intent /*intent*/, null /*_taskDescription*/); |
| 233 | mSupervisor.setFocusStackUnchecked("test", mStack); |
| 234 | mStack.addTask(task, true, "creating test task"); |
| 235 | task.setStack(mStack); |
| 236 | task.setWindowContainerController(mock(TaskWindowContainerController.class)); |
| 237 | |
| 238 | return task; |
| 239 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | /** |
| 243 | * An {@link ActivityManagerService} subclass which provides a test |
| 244 | * {@link ActivityStackSupervisor}. |
| 245 | */ |
| 246 | protected static class TestActivityManagerService extends ActivityManagerService { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 247 | TestActivityManagerService(Context context) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 248 | super(context); |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 249 | mSupportsMultiWindow = true; |
| 250 | mSupportsMultiDisplay = true; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 251 | mSupportsSplitScreenMultiWindow = true; |
| 252 | mSupportsFreeformWindowManagement = true; |
| 253 | mSupportsPictureInPicture = true; |
Bryce Lee | 6a0754a | 2017-10-10 17:53:50 -0700 | [diff] [blame] | 254 | mWindowManager = WindowTestUtils.getMockWindowManagerService(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | @Override |
| 258 | protected ActivityStackSupervisor createStackSupervisor() { |
Bryce Lee | 3115bdf | 2017-04-05 08:39:40 -0700 | [diff] [blame] | 259 | return new TestActivityStackSupervisor(this, mHandlerThread.getLooper()); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 260 | } |
Bryce Lee | 29a649d | 2017-08-18 13:52:31 -0700 | [diff] [blame] | 261 | |
| 262 | @Override |
| 263 | void updateUsageStats(ActivityRecord component, boolean resumed) { |
| 264 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /** |
| 268 | * An {@link ActivityStackSupervisor} which stubs out certain methods that depend on |
| 269 | * setup not available in the test environment. Also specifies an injector for |
| 270 | */ |
| 271 | protected static class TestActivityStackSupervisor extends ActivityStackSupervisor { |
Bryce Lee | 943ebe7 | 2017-05-04 10:19:07 -0700 | [diff] [blame] | 272 | private final ActivityDisplay mDisplay; |
Bryce Lee | 1533b2b | 2017-09-14 17:06:41 -0700 | [diff] [blame] | 273 | private boolean mLastResizeable; |
Bryce Lee | 943ebe7 | 2017-05-04 10:19:07 -0700 | [diff] [blame] | 274 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 275 | public TestActivityStackSupervisor(ActivityManagerService service, Looper looper) { |
| 276 | super(service, looper); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 277 | mDisplayManager = |
| 278 | (DisplayManager) mService.mContext.getSystemService(Context.DISPLAY_SERVICE); |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 279 | mWindowManager = prepareMockWindowManager(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 280 | mDisplay = new TestActivityDisplay(this, DEFAULT_DISPLAY); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 281 | attachDisplay(mDisplay); |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 284 | @Override |
| 285 | ActivityDisplay getDefaultDisplay() { |
| 286 | return mDisplay; |
| 287 | } |
| 288 | |
Bryce Lee | 1533b2b | 2017-09-14 17:06:41 -0700 | [diff] [blame] | 289 | // TODO: Use Mockito spy instead. Currently not possible due to TestActivityStackSupervisor |
| 290 | // access to ActivityDisplay |
| 291 | @Override |
| 292 | boolean canPlaceEntityOnDisplay(int displayId, boolean resizeable, int callingPid, |
| 293 | int callingUid, ActivityInfo activityInfo) { |
| 294 | mLastResizeable = resizeable; |
| 295 | return super.canPlaceEntityOnDisplay(displayId, resizeable, callingPid, callingUid, |
| 296 | activityInfo); |
| 297 | } |
| 298 | |
| 299 | // TODO: remove and use Mockito verify once {@link #canPlaceEntityOnDisplay} override is |
| 300 | // removed. |
| 301 | public boolean getLastResizeableFromCanPlaceEntityOnDisplay() { |
| 302 | return mLastResizeable; |
| 303 | } |
| 304 | |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 305 | // No home stack is set. |
| 306 | @Override |
| 307 | void moveHomeStackToFront(String reason) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 310 | @Override |
| 311 | boolean moveHomeStackTaskToTop(String reason) { |
| 312 | return true; |
| 313 | } |
| 314 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 315 | // Invoked during {@link ActivityStack} creation. |
| 316 | @Override |
| 317 | void updateUIDsPresentOnDisplay() { |
| 318 | } |
| 319 | |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 320 | // Just return the current front task. |
| 321 | @Override |
| 322 | ActivityStack getNextFocusableStackLocked(ActivityStack currentFocus) { |
| 323 | return mFocusedStack; |
| 324 | } |
| 325 | |
| 326 | // Called when moving activity to pinned stack. |
| 327 | @Override |
| 328 | void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 329 | boolean preserveWindows) { |
| 330 | } |
| 331 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 332 | // Always keep things awake |
| 333 | @Override |
| 334 | boolean hasAwakeDisplay() { |
| 335 | return true; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | private static class TestActivityDisplay extends ActivityDisplay { |
| 340 | |
| 341 | private final ActivityStackSupervisor mSupervisor; |
| 342 | TestActivityDisplay(ActivityStackSupervisor supervisor, int displayId) { |
| 343 | super(supervisor, displayId); |
| 344 | mSupervisor = supervisor; |
Andrii Kulian | b1cdb10 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | @Override |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 348 | <T extends ActivityStack> T createStackUnchecked(int windowingMode, int activityType, |
| 349 | int stackId, boolean onTop) { |
| 350 | if (windowingMode == WINDOWING_MODE_PINNED) { |
| 351 | return (T) new PinnedActivityStack(this, stackId, mSupervisor, onTop) { |
Andrii Kulian | b1cdb10 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 352 | @Override |
| 353 | Rect getDefaultPictureInPictureBounds(float aspectRatio) { |
| 354 | return new Rect(50, 50, 100, 100); |
| 355 | } |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 356 | |
| 357 | @Override |
| 358 | PinnedStackWindowController createStackWindowController(int displayId, |
| 359 | boolean onTop, Rect outBounds) { |
| 360 | return mock(PinnedStackWindowController.class); |
| 361 | } |
Andrii Kulian | b1cdb10 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 362 | }; |
| 363 | } else { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 364 | return (T) new TestActivityStack( |
| 365 | this, stackId, mSupervisor, windowingMode, activityType, onTop); |
Andrii Kulian | b1cdb10 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 366 | } |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 367 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 370 | private static WindowManagerService prepareMockWindowManager() { |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 371 | final WindowManagerService service = WindowTestUtils.getMockWindowManagerService(); |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 372 | |
| 373 | doAnswer((InvocationOnMock invocationOnMock) -> { |
| 374 | final Runnable runnable = invocationOnMock.<Runnable>getArgument(0); |
| 375 | if (runnable != null) { |
| 376 | runnable.run(); |
| 377 | } |
| 378 | return null; |
| 379 | }).when(service).inSurfaceTransaction(any()); |
| 380 | |
| 381 | return service; |
| 382 | } |
| 383 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 384 | /** |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 385 | * Overrided of {@link ActivityStack} that tracks test metrics, such as the number of times a |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 386 | * method is called. Note that its functionality depends on the implementations of the |
| 387 | * construction arguments. |
| 388 | */ |
| 389 | protected static class TestActivityStack<T extends StackWindowController> |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 390 | extends ActivityStack<T> { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 391 | private int mOnActivityRemovedFromStackCount = 0; |
| 392 | private T mContainerController; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 393 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 394 | static final int IS_TRANSLUCENT_UNSET = 0; |
| 395 | static final int IS_TRANSLUCENT_FALSE = 1; |
| 396 | static final int IS_TRANSLUCENT_TRUE = 2; |
| 397 | private int mIsTranslucent = IS_TRANSLUCENT_UNSET; |
| 398 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame^] | 399 | static final int SUPPORTS_SPLIT_SCREEN_UNSET = 0; |
| 400 | static final int SUPPORTS_SPLIT_SCREEN_FALSE = 1; |
| 401 | static final int SUPPORTS_SPLIT_SCREEN_TRUE = 2; |
| 402 | private int mSupportsSplitScreen = SUPPORTS_SPLIT_SCREEN_UNSET; |
| 403 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 404 | TestActivityStack(ActivityDisplay display, int stackId, ActivityStackSupervisor supervisor, |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 405 | int windowingMode, int activityType, boolean onTop) { |
| 406 | super(display, stackId, supervisor, windowingMode, activityType, onTop); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | @Override |
| 410 | void onActivityRemovedFromStack(ActivityRecord r) { |
| 411 | mOnActivityRemovedFromStackCount++; |
| 412 | super.onActivityRemovedFromStack(r); |
| 413 | } |
| 414 | |
| 415 | // Returns the number of times {@link #onActivityRemovedFromStack} has been called |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 416 | int onActivityRemovedFromStackInvocationCount() { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 417 | return mOnActivityRemovedFromStackCount; |
| 418 | } |
| 419 | |
| 420 | @Override |
Wale Ogunwale | 034a8ec | 2017-09-02 17:14:40 -0700 | [diff] [blame] | 421 | protected T createStackWindowController(int displayId, boolean onTop, Rect outBounds) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 422 | mContainerController = (T) WindowTestUtils.createMockStackWindowContainerController(); |
| 423 | return mContainerController; |
| 424 | } |
| 425 | |
| 426 | @Override |
| 427 | T getWindowContainerController() { |
| 428 | return mContainerController; |
| 429 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 430 | |
| 431 | void setIsTranslucent(boolean isTranslucent) { |
| 432 | mIsTranslucent = isTranslucent ? IS_TRANSLUCENT_TRUE : IS_TRANSLUCENT_FALSE; |
| 433 | } |
| 434 | |
| 435 | @Override |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 436 | boolean isStackTranslucent(ActivityRecord starting) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 437 | switch (mIsTranslucent) { |
| 438 | case IS_TRANSLUCENT_TRUE: |
| 439 | return true; |
| 440 | case IS_TRANSLUCENT_FALSE: |
| 441 | return false; |
| 442 | case IS_TRANSLUCENT_UNSET: |
| 443 | default: |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 444 | return super.isStackTranslucent(starting); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 445 | } |
| 446 | } |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame^] | 447 | |
| 448 | void setSupportsSplitScreen(boolean supportsSplitScreen) { |
| 449 | mSupportsSplitScreen = supportsSplitScreen |
| 450 | ? SUPPORTS_SPLIT_SCREEN_TRUE : SUPPORTS_SPLIT_SCREEN_FALSE; |
| 451 | } |
| 452 | |
| 453 | @Override |
| 454 | public boolean supportsSplitScreenWindowingMode() { |
| 455 | switch (mSupportsSplitScreen) { |
| 456 | case SUPPORTS_SPLIT_SCREEN_TRUE: |
| 457 | return true; |
| 458 | case SUPPORTS_SPLIT_SCREEN_FALSE: |
| 459 | return false; |
| 460 | case SUPPORTS_SPLIT_SCREEN_UNSET: |
| 461 | default: |
| 462 | return super.supportsSplitScreenWindowingMode(); |
| 463 | } |
| 464 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 465 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 466 | } |