Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1 | /* |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 2 | * Copyright (C) 2018 The Android Open Source Project |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 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 |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 14 | * limitations under the License |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 18 | |
Andrii Kulian | 6a6c4f1 | 2018-07-16 21:23:33 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 21 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 22 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 23 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 24 | import static android.view.Display.DEFAULT_DISPLAY; |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 25 | import static android.view.DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS; |
Andrii Kulian | 6a6c4f1 | 2018-07-16 21:23:33 -0700 | [diff] [blame] | 26 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 27 | import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; |
| 28 | |
Tadashi G. Takaoka | a7a6695 | 2018-11-16 15:04:21 +0900 | [diff] [blame] | 29 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.any; |
| 30 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean; |
| 31 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyInt; |
| 32 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyString; |
| 33 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer; |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 34 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doCallRealMethod; |
Tadashi G. Takaoka | a7a6695 | 2018-11-16 15:04:21 +0900 | [diff] [blame] | 35 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; |
| 36 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; |
| 37 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 38 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset; |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 39 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 40 | import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_DESTROYING; |
| 41 | import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; |
Andrii Kulian | 6a6c4f1 | 2018-07-16 21:23:33 -0700 | [diff] [blame] | 42 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 43 | import android.app.ActivityManagerInternal; |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 44 | import android.app.ActivityOptions; |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 45 | import android.app.AppOpsManager; |
Bryce Lee | 0bd8d42 | 2018-01-09 09:45:57 -0800 | [diff] [blame] | 46 | import android.app.IApplicationThread; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 47 | import android.content.ComponentName; |
| 48 | import android.content.Context; |
| 49 | import android.content.Intent; |
| 50 | import android.content.pm.ActivityInfo; |
| 51 | import android.content.pm.ApplicationInfo; |
Bryce Lee | ba8f442 | 2017-11-20 12:35:57 -0800 | [diff] [blame] | 52 | import android.content.pm.IPackageManager; |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 53 | import android.content.pm.PackageManagerInternal; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 54 | import android.content.res.Configuration; |
| 55 | import android.graphics.Rect; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 56 | import android.hardware.display.DisplayManager; |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 57 | import android.hardware.display.DisplayManagerGlobal; |
Riddle Hsu | 1abb56b | 2018-10-18 11:51:17 +0800 | [diff] [blame] | 58 | import android.os.Handler; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 59 | import android.os.Looper; |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 60 | import android.os.PowerManager; |
Riddle Hsu | 1abb56b | 2018-10-18 11:51:17 +0800 | [diff] [blame] | 61 | import android.os.Process; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 62 | import android.os.UserHandle; |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 63 | import android.service.voice.IVoiceInteractionSession; |
Adrian Roos | 3150dbf | 2018-03-28 18:06:52 +0200 | [diff] [blame] | 64 | import android.testing.DexmakerShareClassLoaderRule; |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 65 | import android.view.Display; |
| 66 | import android.view.DisplayInfo; |
Adrian Roos | 3150dbf | 2018-03-28 18:06:52 +0200 | [diff] [blame] | 67 | |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 68 | import com.android.internal.app.IVoiceInteractor; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 69 | import com.android.server.AttributeCache; |
Riddle Hsu | 1abb56b | 2018-10-18 11:51:17 +0800 | [diff] [blame] | 70 | import com.android.server.ServiceThread; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 71 | import com.android.server.am.ActivityManagerService; |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 72 | import com.android.server.am.PendingIntentController; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 73 | import com.android.server.appop.AppOpsService; |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 74 | import com.android.server.firewall.IntentFirewall; |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 75 | import com.android.server.policy.PermissionPolicyInternal; |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 76 | import com.android.server.uri.UriGrantsManagerInternal; |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 77 | import com.android.server.wm.TaskRecord.TaskRecordFactory; |
Garfield Tan | 26835f0 | 2019-02-07 14:38:38 -0800 | [diff] [blame] | 78 | import com.android.server.wm.utils.MockTracker; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 79 | |
Bryce Lee | 3115bdf | 2017-04-05 08:39:40 -0700 | [diff] [blame] | 80 | import org.junit.After; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 81 | import org.junit.Before; |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 82 | import org.junit.BeforeClass; |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 83 | import org.junit.Rule; |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 84 | import org.mockito.invocation.InvocationOnMock; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 85 | |
Riddle Hsu | 1abb56b | 2018-10-18 11:51:17 +0800 | [diff] [blame] | 86 | import java.io.File; |
Andrii Kulian | 6a6c4f1 | 2018-07-16 21:23:33 -0700 | [diff] [blame] | 87 | import java.util.List; |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 88 | import java.util.function.Consumer; |
Andrii Kulian | 6a6c4f1 | 2018-07-16 21:23:33 -0700 | [diff] [blame] | 89 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 90 | /** |
| 91 | * A base class to handle common operations in activity related unit tests. |
| 92 | */ |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 93 | class ActivityTestsBase { |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 94 | private static int sNextDisplayId = DEFAULT_DISPLAY + 1; |
| 95 | |
Adrian Roos | 3150dbf | 2018-03-28 18:06:52 +0200 | [diff] [blame] | 96 | @Rule |
| 97 | public final DexmakerShareClassLoaderRule mDexmakerShareClassLoaderRule = |
| 98 | new DexmakerShareClassLoaderRule(); |
| 99 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 100 | final Context mContext = getInstrumentation().getTargetContext(); |
Riddle Hsu | 1abb56b | 2018-10-18 11:51:17 +0800 | [diff] [blame] | 101 | final TestInjector mTestInjector = new TestInjector(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 102 | |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 103 | ActivityTaskManagerService mService; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 104 | RootActivityContainer mRootActivityContainer; |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 105 | ActivityStackSupervisor mSupervisor; |
| 106 | |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 107 | private MockTracker mMockTracker; |
| 108 | |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 109 | // Default package name |
| 110 | static final String DEFAULT_COMPONENT_PACKAGE_NAME = "com.foo"; |
| 111 | |
| 112 | // Default base activity name |
| 113 | private static final String DEFAULT_COMPONENT_CLASS_NAME = ".BarActivity"; |
| 114 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 115 | @BeforeClass |
| 116 | public static void setUpOnceBase() { |
| 117 | AttributeCache.init(getInstrumentation().getTargetContext()); |
| 118 | } |
| 119 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 120 | @Before |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 121 | public void setUpBase() { |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 122 | mMockTracker = new MockTracker(); |
| 123 | |
Riddle Hsu | 1abb56b | 2018-10-18 11:51:17 +0800 | [diff] [blame] | 124 | mTestInjector.setUp(); |
Wale Ogunwale | 976ca47 | 2019-01-17 09:55:38 -0800 | [diff] [blame] | 125 | |
| 126 | mService = new TestActivityTaskManagerService(mContext); |
| 127 | mSupervisor = mService.mStackSupervisor; |
| 128 | mRootActivityContainer = mService.mRootActivityContainer; |
Bryce Lee | 3115bdf | 2017-04-05 08:39:40 -0700 | [diff] [blame] | 129 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 130 | |
Bryce Lee | 3115bdf | 2017-04-05 08:39:40 -0700 | [diff] [blame] | 131 | @After |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 132 | public void tearDownBase() { |
Riddle Hsu | 1abb56b | 2018-10-18 11:51:17 +0800 | [diff] [blame] | 133 | mTestInjector.tearDown(); |
Tadashi G. Takaoka | 5a108b8 | 2018-12-13 17:09:12 +0900 | [diff] [blame] | 134 | if (mService != null) { |
| 135 | mService.setWindowManager(null); |
| 136 | mService = null; |
| 137 | } |
Riddle Hsu | 43233b7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 138 | if (sMockWindowManagerService != null) { |
| 139 | reset(sMockWindowManagerService); |
| 140 | } |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 141 | |
| 142 | mMockTracker.close(); |
| 143 | mMockTracker = null; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 146 | /** Creates a {@link TestActivityDisplay}. */ |
| 147 | TestActivityDisplay createNewActivityDisplay() { |
| 148 | return TestActivityDisplay.create(mSupervisor, sNextDisplayId++); |
| 149 | } |
| 150 | |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 151 | TestActivityDisplay createNewActivityDisplay(DisplayInfo info) { |
| 152 | return TestActivityDisplay.create(mSupervisor, sNextDisplayId++, info); |
| 153 | } |
| 154 | |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 155 | /** Creates and adds a {@link TestActivityDisplay} to supervisor at the given position. */ |
| 156 | TestActivityDisplay addNewActivityDisplayAt(int position) { |
| 157 | final TestActivityDisplay display = createNewActivityDisplay(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 158 | mRootActivityContainer.addChild(display, position); |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 159 | return display; |
| 160 | } |
| 161 | |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 162 | /** Creates and adds a {@link TestActivityDisplay} to supervisor at the given position. */ |
| 163 | TestActivityDisplay addNewActivityDisplayAt(DisplayInfo info, int position) { |
| 164 | final TestActivityDisplay display = createNewActivityDisplay(info); |
| 165 | mRootActivityContainer.addChild(display, position); |
| 166 | return display; |
| 167 | } |
| 168 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 169 | /** |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 170 | * Delegates task creation to {@link #TaskBuilder} to avoid the dependency of window hierarchy |
| 171 | * when starting activity in unit tests. |
| 172 | */ |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 173 | void mockTaskRecordFactory(Consumer<TaskBuilder> taskBuilderSetup) { |
| 174 | final TaskBuilder taskBuilder = new TaskBuilder(mSupervisor).setCreateStack(false); |
| 175 | if (taskBuilderSetup != null) { |
| 176 | taskBuilderSetup.accept(taskBuilder); |
| 177 | } |
| 178 | final TaskRecord task = taskBuilder.build(); |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 179 | final TaskRecordFactory factory = mock(TaskRecordFactory.class); |
| 180 | TaskRecord.setTaskRecordFactory(factory); |
| 181 | doReturn(task).when(factory).create(any() /* service */, anyInt() /* taskId */, |
| 182 | any() /* info */, any() /* intent */, any() /* voiceSession */, |
| 183 | any() /* voiceInteractor */); |
| 184 | } |
| 185 | |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 186 | void mockTaskRecordFactory() { |
| 187 | mockTaskRecordFactory(null /* taskBuilderSetup */); |
| 188 | } |
| 189 | |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 190 | /** |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 191 | * Builder for creating new activities. |
| 192 | */ |
| 193 | protected static class ActivityBuilder { |
| 194 | // An id appended to the end of the component name to make it unique |
| 195 | private static int sCurrentActivityId = 0; |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 196 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 197 | private final ActivityTaskManagerService mService; |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 198 | |
| 199 | private ComponentName mComponent; |
Louis Chang | 23df1a6 | 2019-01-09 15:10:49 +0800 | [diff] [blame] | 200 | private String mTargetActivity; |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 201 | private TaskRecord mTaskRecord; |
| 202 | private int mUid; |
| 203 | private boolean mCreateTask; |
| 204 | private ActivityStack mStack; |
Bryce Lee | c961e0a | 2018-04-13 17:58:02 -0700 | [diff] [blame] | 205 | private int mActivityFlags; |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 206 | private int mLaunchMode; |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 207 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 208 | ActivityBuilder(ActivityTaskManagerService service) { |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 209 | mService = service; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 212 | ActivityBuilder setComponent(ComponentName component) { |
| 213 | mComponent = component; |
| 214 | return this; |
| 215 | } |
| 216 | |
Louis Chang | 23df1a6 | 2019-01-09 15:10:49 +0800 | [diff] [blame] | 217 | ActivityBuilder setTargetActivity(String targetActivity) { |
| 218 | mTargetActivity = targetActivity; |
| 219 | return this; |
| 220 | } |
| 221 | |
Bryce Lee | ad5b832 | 2018-03-08 14:28:52 -0800 | [diff] [blame] | 222 | static ComponentName getDefaultComponent() { |
| 223 | return ComponentName.createRelative(DEFAULT_COMPONENT_PACKAGE_NAME, |
| 224 | DEFAULT_COMPONENT_PACKAGE_NAME); |
| 225 | } |
| 226 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 227 | ActivityBuilder setTask(TaskRecord task) { |
| 228 | mTaskRecord = task; |
| 229 | return this; |
| 230 | } |
| 231 | |
Bryce Lee | c961e0a | 2018-04-13 17:58:02 -0700 | [diff] [blame] | 232 | ActivityBuilder setActivityFlags(int flags) { |
| 233 | mActivityFlags = flags; |
| 234 | return this; |
| 235 | } |
| 236 | |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 237 | ActivityBuilder setLaunchMode(int launchMode) { |
| 238 | mLaunchMode = launchMode; |
| 239 | return this; |
| 240 | } |
| 241 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 242 | ActivityBuilder setStack(ActivityStack stack) { |
| 243 | mStack = stack; |
| 244 | return this; |
| 245 | } |
| 246 | |
| 247 | ActivityBuilder setCreateTask(boolean createTask) { |
| 248 | mCreateTask = createTask; |
| 249 | return this; |
| 250 | } |
| 251 | |
| 252 | ActivityBuilder setUid(int uid) { |
| 253 | mUid = uid; |
| 254 | return this; |
| 255 | } |
| 256 | |
| 257 | ActivityRecord build() { |
| 258 | if (mComponent == null) { |
| 259 | final int id = sCurrentActivityId++; |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 260 | mComponent = ComponentName.createRelative(DEFAULT_COMPONENT_PACKAGE_NAME, |
| 261 | DEFAULT_COMPONENT_CLASS_NAME + id); |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | if (mCreateTask) { |
| 265 | mTaskRecord = new TaskBuilder(mService.mStackSupervisor) |
| 266 | .setComponent(mComponent) |
| 267 | .setStack(mStack).build(); |
| 268 | } |
| 269 | |
| 270 | Intent intent = new Intent(); |
| 271 | intent.setComponent(mComponent); |
| 272 | final ActivityInfo aInfo = new ActivityInfo(); |
| 273 | aInfo.applicationInfo = new ApplicationInfo(); |
| 274 | aInfo.applicationInfo.packageName = mComponent.getPackageName(); |
| 275 | aInfo.applicationInfo.uid = mUid; |
Louis Chang | 23df1a6 | 2019-01-09 15:10:49 +0800 | [diff] [blame] | 276 | aInfo.packageName = mComponent.getPackageName(); |
| 277 | if (mTargetActivity != null) { |
| 278 | aInfo.targetActivity = mTargetActivity; |
| 279 | } |
Bryce Lee | c961e0a | 2018-04-13 17:58:02 -0700 | [diff] [blame] | 280 | aInfo.flags |= mActivityFlags; |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 281 | aInfo.launchMode = mLaunchMode; |
Bryce Lee | c961e0a | 2018-04-13 17:58:02 -0700 | [diff] [blame] | 282 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 283 | final ActivityRecord activity = new ActivityRecord(mService, null /* caller */, |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 284 | 0 /* launchedFromPid */, 0, null, intent, null, |
| 285 | aInfo /*aInfo*/, new Configuration(), null /* resultTo */, null /* resultWho */, |
| 286 | 0 /* reqCode */, false /*componentSpecified*/, false /* rootVoiceInteraction */, |
| 287 | mService.mStackSupervisor, null /* options */, null /* sourceRecord */); |
Yunfan Chen | d4ef301 | 2018-11-28 21:14:32 -0800 | [diff] [blame] | 288 | spyOn(activity); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 289 | activity.mAppWindowToken = mock(AppWindowToken.class); |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 290 | doCallRealMethod().when(activity.mAppWindowToken).getOrientationIgnoreVisibility(); |
| 291 | doCallRealMethod().when(activity.mAppWindowToken) |
| 292 | .setOrientation(anyInt(), any(), any()); |
| 293 | doCallRealMethod().when(activity.mAppWindowToken).setOrientation(anyInt()); |
Yunfan Chen | d4ef301 | 2018-11-28 21:14:32 -0800 | [diff] [blame] | 294 | doNothing().when(activity).removeWindowContainer(); |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 295 | doReturn(mock(Configuration.class)).when(activity.mAppWindowToken) |
| 296 | .getRequestedOverrideConfiguration(); |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 297 | |
| 298 | if (mTaskRecord != null) { |
| 299 | mTaskRecord.addActivityToTop(activity); |
| 300 | } |
| 301 | |
Andrii Kulian | beadacc | 2019-05-20 12:18:01 +0000 | [diff] [blame] | 302 | final WindowProcessController wpc = new WindowProcessController(mService, |
| 303 | mService.mContext.getApplicationInfo(), "name", 12345, |
| 304 | UserHandle.getUserId(12345), mock(Object.class), |
| 305 | mock(WindowProcessListener.class)); |
| 306 | wpc.setThread(mock(IApplicationThread.class)); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 307 | activity.setProcess(wpc); |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 308 | return activity; |
| 309 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 312 | /** |
| 313 | * Builder for creating new tasks. |
| 314 | */ |
| 315 | protected static class TaskBuilder { |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 316 | // Default package name |
| 317 | static final String DEFAULT_PACKAGE = "com.bar"; |
| 318 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 319 | private final ActivityStackSupervisor mSupervisor; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 320 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 321 | private ComponentName mComponent; |
| 322 | private String mPackage; |
| 323 | private int mFlags = 0; |
Kazuki Takise | c2e17bf | 2018-07-17 17:46:38 +0900 | [diff] [blame] | 324 | // Task id 0 is reserved in ARC for the home app. |
| 325 | private int mTaskId = 1; |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 326 | private int mUserId = 0; |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 327 | private IVoiceInteractionSession mVoiceSession; |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 328 | private boolean mCreateStack = true; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 329 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 330 | private ActivityStack mStack; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 331 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 332 | TaskBuilder(ActivityStackSupervisor supervisor) { |
| 333 | mSupervisor = supervisor; |
| 334 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 335 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 336 | TaskBuilder setComponent(ComponentName component) { |
| 337 | mComponent = component; |
| 338 | return this; |
| 339 | } |
| 340 | |
| 341 | TaskBuilder setPackage(String packageName) { |
| 342 | mPackage = packageName; |
| 343 | return this; |
| 344 | } |
| 345 | |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 346 | /** |
| 347 | * Set to {@code true} by default, set to {@code false} to prevent the task from |
| 348 | * automatically creating a parent stack. |
| 349 | */ |
| 350 | TaskBuilder setCreateStack(boolean createStack) { |
| 351 | mCreateStack = createStack; |
| 352 | return this; |
| 353 | } |
| 354 | |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 355 | TaskBuilder setVoiceSession(IVoiceInteractionSession session) { |
| 356 | mVoiceSession = session; |
| 357 | return this; |
| 358 | } |
| 359 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 360 | TaskBuilder setFlags(int flags) { |
| 361 | mFlags = flags; |
| 362 | return this; |
| 363 | } |
| 364 | |
| 365 | TaskBuilder setTaskId(int taskId) { |
| 366 | mTaskId = taskId; |
| 367 | return this; |
| 368 | } |
| 369 | |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 370 | TaskBuilder setUserId(int userId) { |
| 371 | mUserId = userId; |
| 372 | return this; |
| 373 | } |
| 374 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 375 | TaskBuilder setStack(ActivityStack stack) { |
| 376 | mStack = stack; |
| 377 | return this; |
| 378 | } |
| 379 | |
| 380 | TaskRecord build() { |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 381 | if (mStack == null && mCreateStack) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 382 | mStack = mSupervisor.mRootActivityContainer.getDefaultDisplay().createStack( |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 383 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 384 | } |
| 385 | |
| 386 | final ActivityInfo aInfo = new ActivityInfo(); |
| 387 | aInfo.applicationInfo = new ApplicationInfo(); |
| 388 | aInfo.applicationInfo.packageName = mPackage; |
| 389 | |
| 390 | Intent intent = new Intent(); |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 391 | if (mComponent == null) { |
| 392 | mComponent = ComponentName.createRelative(DEFAULT_COMPONENT_PACKAGE_NAME, |
| 393 | DEFAULT_COMPONENT_CLASS_NAME); |
| 394 | } |
| 395 | |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 396 | intent.setComponent(mComponent); |
| 397 | intent.setFlags(mFlags); |
| 398 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 399 | final TestTaskRecord task = new TestTaskRecord(mSupervisor.mService, mTaskId, aInfo, |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 400 | intent /*intent*/, mVoiceSession, null /*_voiceInteractor*/); |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 401 | task.userId = mUserId; |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 402 | |
| 403 | if (mStack != null) { |
Andrii Kulian | 6a6c4f1 | 2018-07-16 21:23:33 -0700 | [diff] [blame] | 404 | mStack.moveToFront("test"); |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 405 | mStack.addTask(task, true, "creating test task"); |
| 406 | task.setStack(mStack); |
Yunfan Chen | 0e7aff9 | 2018-12-05 16:35:32 -0800 | [diff] [blame] | 407 | task.setTask(); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 408 | mStack.getTaskStack().addChild(task.mTask, 0); |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 411 | task.touchActiveTime(); |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 412 | |
| 413 | return task; |
| 414 | } |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 415 | |
| 416 | private static class TestTaskRecord extends TaskRecord { |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 417 | TestTaskRecord(ActivityTaskManagerService service, int taskId, ActivityInfo info, |
| 418 | Intent intent, IVoiceInteractionSession voiceSession, |
| 419 | IVoiceInteractor voiceInteractor) { |
| 420 | super(service, taskId, info, intent, voiceSession, voiceInteractor); |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | @Override |
Yunfan Chen | 0e7aff9 | 2018-12-05 16:35:32 -0800 | [diff] [blame] | 424 | void createTask(boolean onTop, boolean showForAllUsers) { |
| 425 | setTask(); |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 428 | void setTask() { |
| 429 | Task mockTask = mock(Task.class); |
| 430 | mockTask.mTaskRecord = this; |
| 431 | doCallRealMethod().when(mockTask).onDescendantOrientationChanged(any(), any()); |
Yunfan Chen | 0e7aff9 | 2018-12-05 16:35:32 -0800 | [diff] [blame] | 432 | setTask(mock(Task.class)); |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 433 | } |
| 434 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 437 | protected class TestActivityTaskManagerService extends ActivityTaskManagerService { |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 438 | private PackageManagerInternal mPmInternal; |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 439 | private PermissionPolicyInternal mPermissionPolicyInternal; |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 440 | |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 441 | // ActivityStackSupervisor may be created more than once while setting up AMS and ATMS. |
| 442 | // We keep the reference in order to prevent creating it twice. |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 443 | ActivityStackSupervisor mTestStackSupervisor; |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 444 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 445 | ActivityDisplay mDefaultDisplay; |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 446 | AppOpsService mAppOpsService; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 447 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 448 | TestActivityTaskManagerService(Context context) { |
| 449 | super(context); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 450 | spyOn(this); |
| 451 | |
| 452 | mUgmInternal = mock(UriGrantsManagerInternal.class); |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 453 | mAppOpsService = mock(AppOpsService.class); |
| 454 | |
| 455 | // Make sure permission checks aren't overridden. |
| 456 | doReturn(AppOpsManager.MODE_DEFAULT) |
| 457 | .when(mAppOpsService).noteOperation(anyInt(), anyInt(), anyString()); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 458 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 459 | mSupportsMultiWindow = true; |
| 460 | mSupportsMultiDisplay = true; |
| 461 | mSupportsSplitScreenMultiWindow = true; |
| 462 | mSupportsFreeformWindowManagement = true; |
| 463 | mSupportsPictureInPicture = true; |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 464 | |
| 465 | final TestActivityManagerService am = |
| 466 | new TestActivityManagerService(mTestInjector, this); |
| 467 | |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 468 | spyOn(getLifecycleManager()); |
| 469 | spyOn(getLockTaskController()); |
| 470 | doReturn(mock(IPackageManager.class)).when(this).getPackageManager(); |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 471 | // allow background activity starts by default |
| 472 | doReturn(true).when(this).isBackgroundActivityStartsEnabled(); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 473 | doNothing().when(this).updateCpuStats(); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 474 | } |
| 475 | |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 476 | void setup(IntentFirewall intentFirewall, PendingIntentController intentController, |
| 477 | ActivityManagerInternal amInternal, WindowManagerService wm, Looper looper) { |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 478 | mAmInternal = amInternal; |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 479 | initialize(intentFirewall, intentController, looper); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 480 | initRootActivityContainerMocks(wm); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 481 | setWindowManager(wm); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 482 | createDefaultDisplay(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 485 | void initRootActivityContainerMocks(WindowManagerService wm) { |
| 486 | spyOn(mRootActivityContainer); |
Wale Ogunwale | 31acb3f | 2018-11-20 15:23:55 -0800 | [diff] [blame] | 487 | mRootActivityContainer.setWindowContainer(mock(RootWindowContainer.class)); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 488 | mRootActivityContainer.mWindowManager = wm; |
| 489 | mRootActivityContainer.mDisplayManager = |
| 490 | (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE); |
| 491 | doNothing().when(mRootActivityContainer).setWindowManager(any()); |
| 492 | // Invoked during {@link ActivityStack} creation. |
| 493 | doNothing().when(mRootActivityContainer).updateUIDsPresentOnDisplay(); |
| 494 | // Always keep things awake. |
| 495 | doReturn(true).when(mRootActivityContainer).hasAwakeDisplay(); |
| 496 | // Called when moving activity to pinned stack. |
| 497 | doNothing().when(mRootActivityContainer).ensureActivitiesVisible(any(), anyInt(), |
| 498 | anyBoolean()); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 499 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 500 | |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 501 | void createDefaultDisplay() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 502 | // Create a default display and put a home stack on it so that we'll always have |
| 503 | // something focusable. |
| 504 | mDefaultDisplay = TestActivityDisplay.create(mStackSupervisor, DEFAULT_DISPLAY); |
| 505 | spyOn(mDefaultDisplay); |
| 506 | mRootActivityContainer.addChild(mDefaultDisplay, ActivityDisplay.POSITION_TOP); |
| 507 | mDefaultDisplay.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, ON_TOP); |
| 508 | final TaskRecord task = new TaskBuilder(mStackSupervisor) |
| 509 | .setStack(mDefaultDisplay.getHomeStack()).build(); |
| 510 | new ActivityBuilder(this).setTask(task).build(); |
| 511 | |
| 512 | doReturn(mDefaultDisplay).when(mRootActivityContainer).getDefaultDisplay(); |
| 513 | } |
| 514 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 515 | @Override |
| 516 | int handleIncomingUser(int callingPid, int callingUid, int userId, String name) { |
| 517 | return userId; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 518 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 519 | |
| 520 | @Override |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 521 | AppOpsService getAppOpsService() { |
| 522 | return mAppOpsService; |
| 523 | } |
| 524 | |
| 525 | @Override |
Riddle Hsu | aaef731 | 2019-01-24 19:00:58 +0800 | [diff] [blame] | 526 | void updateCpuStats() { |
| 527 | } |
| 528 | |
| 529 | @Override |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 530 | void updateBatteryStats(ActivityRecord component, boolean resumed) { |
| 531 | } |
| 532 | |
| 533 | @Override |
| 534 | void updateActivityUsageStats(ActivityRecord activity, int event) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | @Override |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 538 | protected ActivityStackSupervisor createStackSupervisor() { |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 539 | if (mTestStackSupervisor == null) { |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 540 | mTestStackSupervisor = new TestActivityStackSupervisor(this, mH.getLooper()); |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 541 | } |
| 542 | return mTestStackSupervisor; |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 545 | @Override |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 546 | PackageManagerInternal getPackageManagerInternalLocked() { |
| 547 | if (mPmInternal == null) { |
| 548 | mPmInternal = mock(PackageManagerInternal.class); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 549 | doReturn(false) |
| 550 | .when(mPmInternal) |
| 551 | .isPermissionsReviewRequired(anyString(), anyInt()); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 552 | } |
| 553 | return mPmInternal; |
| 554 | } |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 555 | |
| 556 | @Override |
| 557 | PermissionPolicyInternal getPermissionPolicyInternal() { |
| 558 | if (mPermissionPolicyInternal == null) { |
| 559 | mPermissionPolicyInternal = mock(PermissionPolicyInternal.class); |
| 560 | doReturn(true).when(mPermissionPolicyInternal).checkStartActivity(any(), anyInt(), |
| 561 | any()); |
| 562 | } |
| 563 | return mPermissionPolicyInternal; |
| 564 | } |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Riddle Hsu | 1abb56b | 2018-10-18 11:51:17 +0800 | [diff] [blame] | 567 | private static class TestInjector extends ActivityManagerService.Injector { |
| 568 | private ServiceThread mHandlerThread; |
| 569 | |
| 570 | @Override |
| 571 | public Context getContext() { |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 572 | return getInstrumentation().getTargetContext(); |
Riddle Hsu | 1abb56b | 2018-10-18 11:51:17 +0800 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | @Override |
| 576 | public AppOpsService getAppOpsService(File file, Handler handler) { |
| 577 | return null; |
| 578 | } |
| 579 | |
| 580 | @Override |
| 581 | public Handler getUiHandler(ActivityManagerService service) { |
| 582 | return mHandlerThread.getThreadHandler(); |
| 583 | } |
| 584 | |
| 585 | @Override |
| 586 | public boolean isNetworkRestrictedForUid(int uid) { |
| 587 | return false; |
| 588 | } |
| 589 | |
| 590 | void setUp() { |
| 591 | mHandlerThread = new ServiceThread("ActivityTestsThread", |
| 592 | Process.THREAD_PRIORITY_DEFAULT, true /* allowIo */); |
| 593 | mHandlerThread.start(); |
| 594 | } |
| 595 | |
| 596 | void tearDown() { |
Riddle Hsu | e2e5ee1 | 2019-06-11 23:44:39 +0800 | [diff] [blame] | 597 | // Make sure there are no running messages and then quit the thread so the next test |
| 598 | // won't be affected. |
| 599 | mHandlerThread.getThreadHandler().runWithScissors(mHandlerThread::quit, |
| 600 | 0 /* timeout */); |
Riddle Hsu | 1abb56b | 2018-10-18 11:51:17 +0800 | [diff] [blame] | 601 | } |
| 602 | } |
| 603 | |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 604 | // TODO: Replace this with a mock object since we are no longer in AMS package. |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 605 | /** |
| 606 | * An {@link ActivityManagerService} subclass which provides a test |
| 607 | * {@link ActivityStackSupervisor}. |
| 608 | */ |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 609 | class TestActivityManagerService extends ActivityManagerService { |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 610 | |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 611 | TestActivityManagerService(TestInjector testInjector, TestActivityTaskManagerService atm) { |
Riddle Hsu | 1abb56b | 2018-10-18 11:51:17 +0800 | [diff] [blame] | 612 | super(testInjector, testInjector.mHandlerThread); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 613 | spyOn(this); |
Bryce Lee | 29a649d | 2017-08-18 13:52:31 -0700 | [diff] [blame] | 614 | |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 615 | mWindowManager = prepareMockWindowManager(); |
| 616 | mUgmInternal = mock(UriGrantsManagerInternal.class); |
| 617 | |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 618 | atm.setup(mIntentFirewall, mPendingIntentController, new LocalService(), mWindowManager, |
| 619 | testInjector.mHandlerThread.getLooper()); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 620 | |
| 621 | mActivityTaskManager = atm; |
| 622 | mAtmInternal = atm.mInternal; |
| 623 | |
| 624 | doReturn(mock(IPackageManager.class)).when(this).getPackageManager(); |
| 625 | PackageManagerInternal mockPackageManager = mock(PackageManagerInternal.class); |
| 626 | doReturn(mockPackageManager).when(this).getPackageManagerInternalLocked(); |
| 627 | doReturn(null).when(mockPackageManager).getDefaultHomeActivity(anyInt()); |
| 628 | doNothing().when(this).grantEphemeralAccessLocked(anyInt(), any(), anyInt(), anyInt()); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 629 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | /** |
| 633 | * An {@link ActivityStackSupervisor} which stubs out certain methods that depend on |
| 634 | * setup not available in the test environment. Also specifies an injector for |
| 635 | */ |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 636 | protected class TestActivityStackSupervisor extends ActivityStackSupervisor { |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 637 | private KeyguardController mKeyguardController; |
Bryce Lee | 943ebe7 | 2017-05-04 10:19:07 -0700 | [diff] [blame] | 638 | |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 639 | TestActivityStackSupervisor(ActivityTaskManagerService service, Looper looper) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 640 | super(service, looper); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 641 | spyOn(this); |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 642 | mWindowManager = prepareMockWindowManager(); |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 643 | mKeyguardController = mock(KeyguardController.class); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 644 | |
Riddle Hsu | e2e5ee1 | 2019-06-11 23:44:39 +0800 | [diff] [blame] | 645 | // Do not schedule idle that may touch methods outside the scope of the test. |
| 646 | doNothing().when(this).scheduleIdleLocked(); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 647 | doNothing().when(this).scheduleIdleTimeoutLocked(any()); |
| 648 | // unit test version does not handle launch wake lock |
| 649 | doNothing().when(this).acquireLaunchWakelock(); |
| 650 | doReturn(mKeyguardController).when(this).getKeyguardController(); |
| 651 | |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 652 | mLaunchingActivityWakeLock = mock(PowerManager.WakeLock.class); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 653 | |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 654 | initialize(); |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | @Override |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 658 | public KeyguardController getKeyguardController() { |
| 659 | return mKeyguardController; |
| 660 | } |
| 661 | |
| 662 | @Override |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 663 | void setWindowManager(WindowManagerService wm) { |
| 664 | mWindowManager = wm; |
| 665 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 668 | protected static class TestActivityDisplay extends ActivityDisplay { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 669 | private final ActivityStackSupervisor mSupervisor; |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 670 | |
| 671 | static TestActivityDisplay create(ActivityStackSupervisor supervisor, int displayId) { |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 672 | return create(supervisor, displayId, new DisplayInfo()); |
| 673 | } |
| 674 | |
| 675 | static TestActivityDisplay create(ActivityStackSupervisor supervisor, int displayId, |
| 676 | DisplayInfo info) { |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 677 | if (displayId == DEFAULT_DISPLAY) { |
| 678 | return new TestActivityDisplay(supervisor, |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 679 | supervisor.mRootActivityContainer.mDisplayManager.getDisplay(displayId)); |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 680 | } |
| 681 | final Display display = new Display(DisplayManagerGlobal.getInstance(), displayId, |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 682 | info, DEFAULT_DISPLAY_ADJUSTMENTS); |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 683 | return new TestActivityDisplay(supervisor, display); |
| 684 | } |
| 685 | |
| 686 | TestActivityDisplay(ActivityStackSupervisor supervisor, Display display) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 687 | super(supervisor.mService.mRootActivityContainer, display); |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 688 | // Normally this comes from display-properties as exposed by WM. Without that, just |
| 689 | // hard-code to FULLSCREEN for tests. |
| 690 | setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 691 | mSupervisor = supervisor; |
Andrii Kulian | b1cdb10 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 694 | @SuppressWarnings("TypeParameterUnusedInFormals") |
Andrii Kulian | b1cdb10 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 695 | @Override |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 696 | ActivityStack createStackUnchecked(int windowingMode, int activityType, |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 697 | int stackId, boolean onTop) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 698 | return new StackBuilder(mSupervisor.mRootActivityContainer).setDisplay(this) |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 699 | .setWindowingMode(windowingMode).setActivityType(activityType) |
| 700 | .setStackId(stackId).setOnTop(onTop).setCreateActivity(false).build(); |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 701 | } |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 702 | |
| 703 | @Override |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 704 | protected DisplayContent createDisplayContent() { |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 705 | final DisplayContent displayContent = mock(DisplayContent.class); |
| 706 | DockedStackDividerController divider = mock(DockedStackDividerController.class); |
| 707 | doReturn(divider).when(displayContent).getDockedDividerController(); |
| 708 | return displayContent; |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 709 | } |
Andrii Kulian | 6a6c4f1 | 2018-07-16 21:23:33 -0700 | [diff] [blame] | 710 | |
| 711 | void removeAllTasks() { |
| 712 | for (int i = 0; i < getChildCount(); i++) { |
| 713 | final ActivityStack stack = getChildAt(i); |
| 714 | for (TaskRecord task : (List<TaskRecord>) stack.getAllTasks()) { |
| 715 | stack.removeTask(task, "removeAllTasks", REMOVE_TASK_MODE_DESTROYING); |
| 716 | } |
| 717 | } |
| 718 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Tadashi G. Takaoka | 5a108b8 | 2018-12-13 17:09:12 +0900 | [diff] [blame] | 721 | private static WindowManagerService sMockWindowManagerService; |
| 722 | |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 723 | private static WindowManagerService prepareMockWindowManager() { |
Garfield Tan | 26835f0 | 2019-02-07 14:38:38 -0800 | [diff] [blame] | 724 | if (sMockWindowManagerService == null) { |
| 725 | sMockWindowManagerService = mock(WindowManagerService.class); |
Tadashi G. Takaoka | 5a108b8 | 2018-12-13 17:09:12 +0900 | [diff] [blame] | 726 | } |
| 727 | |
Garfield Tan | 26835f0 | 2019-02-07 14:38:38 -0800 | [diff] [blame] | 728 | sMockWindowManagerService.mRoot = mock(RootWindowContainer.class); |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 729 | |
| 730 | doAnswer((InvocationOnMock invocationOnMock) -> { |
| 731 | final Runnable runnable = invocationOnMock.<Runnable>getArgument(0); |
| 732 | if (runnable != null) { |
| 733 | runnable.run(); |
| 734 | } |
| 735 | return null; |
Garfield Tan | 26835f0 | 2019-02-07 14:38:38 -0800 | [diff] [blame] | 736 | }).when(sMockWindowManagerService).inSurfaceTransaction(any()); |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 737 | |
Garfield Tan | 26835f0 | 2019-02-07 14:38:38 -0800 | [diff] [blame] | 738 | return sMockWindowManagerService; |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 739 | } |
| 740 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 741 | /** |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 742 | * Overridden {@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] | 743 | * method is called. Note that its functionality depends on the implementations of the |
| 744 | * construction arguments. |
| 745 | */ |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 746 | protected static class TestActivityStack |
| 747 | extends ActivityStack { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 748 | private int mOnActivityRemovedFromStackCount = 0; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 749 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 750 | static final int IS_TRANSLUCENT_UNSET = 0; |
| 751 | static final int IS_TRANSLUCENT_FALSE = 1; |
| 752 | static final int IS_TRANSLUCENT_TRUE = 2; |
| 753 | private int mIsTranslucent = IS_TRANSLUCENT_UNSET; |
| 754 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 755 | static final int SUPPORTS_SPLIT_SCREEN_UNSET = 0; |
| 756 | static final int SUPPORTS_SPLIT_SCREEN_FALSE = 1; |
| 757 | static final int SUPPORTS_SPLIT_SCREEN_TRUE = 2; |
| 758 | private int mSupportsSplitScreen = SUPPORTS_SPLIT_SCREEN_UNSET; |
| 759 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 760 | TestActivityStack(ActivityDisplay display, int stackId, ActivityStackSupervisor supervisor, |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 761 | int windowingMode, int activityType, boolean onTop, boolean createActivity) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 762 | super(display, stackId, supervisor, windowingMode, activityType, onTop); |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 763 | if (createActivity) { |
| 764 | new ActivityBuilder(mService).setCreateTask(true).setStack(this).build(); |
| 765 | if (onTop) { |
| 766 | // We move the task to front again in order to regain focus after activity |
| 767 | // added to the stack. Or {@link ActivityDisplay#mPreferredTopFocusableStack} |
| 768 | // could be other stacks (e.g. home stack). |
| 769 | moveToFront("createActivityStack"); |
| 770 | } else { |
| 771 | moveToBack("createActivityStack", null); |
| 772 | } |
| 773 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | @Override |
| 777 | void onActivityRemovedFromStack(ActivityRecord r) { |
| 778 | mOnActivityRemovedFromStackCount++; |
| 779 | super.onActivityRemovedFromStack(r); |
| 780 | } |
| 781 | |
| 782 | // Returns the number of times {@link #onActivityRemovedFromStack} has been called |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 783 | int onActivityRemovedFromStackInvocationCount() { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 784 | return mOnActivityRemovedFromStackCount; |
| 785 | } |
| 786 | |
| 787 | @Override |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 788 | protected void createTaskStack(int displayId, boolean onTop, Rect outBounds) { |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 789 | mTaskStack = mock(TaskStack.class); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 790 | |
| 791 | // Primary pinned stacks require a non-empty out bounds to be set or else all tasks |
| 792 | // will be moved to the full screen stack. |
| 793 | if (getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 794 | outBounds.set(0, 0, 100, 100); |
| 795 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | @Override |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 799 | TaskStack getTaskStack() { |
| 800 | return mTaskStack; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 801 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 802 | |
| 803 | void setIsTranslucent(boolean isTranslucent) { |
| 804 | mIsTranslucent = isTranslucent ? IS_TRANSLUCENT_TRUE : IS_TRANSLUCENT_FALSE; |
| 805 | } |
| 806 | |
| 807 | @Override |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 808 | boolean isStackTranslucent(ActivityRecord starting) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 809 | switch (mIsTranslucent) { |
| 810 | case IS_TRANSLUCENT_TRUE: |
| 811 | return true; |
| 812 | case IS_TRANSLUCENT_FALSE: |
| 813 | return false; |
| 814 | case IS_TRANSLUCENT_UNSET: |
| 815 | default: |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 816 | return super.isStackTranslucent(starting); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 817 | } |
| 818 | } |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 819 | |
| 820 | void setSupportsSplitScreen(boolean supportsSplitScreen) { |
| 821 | mSupportsSplitScreen = supportsSplitScreen |
| 822 | ? SUPPORTS_SPLIT_SCREEN_TRUE : SUPPORTS_SPLIT_SCREEN_FALSE; |
| 823 | } |
| 824 | |
| 825 | @Override |
| 826 | public boolean supportsSplitScreenWindowingMode() { |
| 827 | switch (mSupportsSplitScreen) { |
| 828 | case SUPPORTS_SPLIT_SCREEN_TRUE: |
| 829 | return true; |
| 830 | case SUPPORTS_SPLIT_SCREEN_FALSE: |
| 831 | return false; |
| 832 | case SUPPORTS_SPLIT_SCREEN_UNSET: |
| 833 | default: |
| 834 | return super.supportsSplitScreenWindowingMode(); |
| 835 | } |
| 836 | } |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 837 | |
| 838 | @Override |
| 839 | void startActivityLocked(ActivityRecord r, ActivityRecord focusedTopActivity, |
| 840 | boolean newTask, boolean keepCurTransition, |
| 841 | ActivityOptions options) { |
| 842 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 843 | } |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 844 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 845 | static class StackBuilder { |
| 846 | private final RootActivityContainer mRootActivityContainer; |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 847 | private ActivityDisplay mDisplay; |
| 848 | private int mStackId = -1; |
| 849 | private int mWindowingMode = WINDOWING_MODE_FULLSCREEN; |
| 850 | private int mActivityType = ACTIVITY_TYPE_STANDARD; |
| 851 | private boolean mOnTop = true; |
| 852 | private boolean mCreateActivity = true; |
| 853 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 854 | StackBuilder(RootActivityContainer root) { |
| 855 | mRootActivityContainer = root; |
| 856 | mDisplay = mRootActivityContainer.getDefaultDisplay(); |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | StackBuilder setWindowingMode(int windowingMode) { |
| 860 | mWindowingMode = windowingMode; |
| 861 | return this; |
| 862 | } |
| 863 | |
| 864 | StackBuilder setActivityType(int activityType) { |
| 865 | mActivityType = activityType; |
| 866 | return this; |
| 867 | } |
| 868 | |
| 869 | StackBuilder setStackId(int stackId) { |
| 870 | mStackId = stackId; |
| 871 | return this; |
| 872 | } |
| 873 | |
| 874 | StackBuilder setDisplay(ActivityDisplay display) { |
| 875 | mDisplay = display; |
| 876 | return this; |
| 877 | } |
| 878 | |
| 879 | StackBuilder setOnTop(boolean onTop) { |
| 880 | mOnTop = onTop; |
| 881 | return this; |
| 882 | } |
| 883 | |
| 884 | StackBuilder setCreateActivity(boolean createActivity) { |
| 885 | mCreateActivity = createActivity; |
| 886 | return this; |
| 887 | } |
| 888 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 889 | @SuppressWarnings("TypeParameterUnusedInFormals") |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 890 | ActivityStack build() { |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 891 | final int stackId = mStackId >= 0 ? mStackId : mDisplay.getNextStackId(); |
| 892 | if (mWindowingMode == WINDOWING_MODE_PINNED) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 893 | return new ActivityStack(mDisplay, stackId, mRootActivityContainer.mStackSupervisor, |
| 894 | mWindowingMode, ACTIVITY_TYPE_STANDARD, mOnTop) { |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 895 | @Override |
| 896 | Rect getDefaultPictureInPictureBounds(float aspectRatio) { |
| 897 | return new Rect(50, 50, 100, 100); |
| 898 | } |
| 899 | |
| 900 | @Override |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 901 | void createTaskStack(int displayId, boolean onTop, Rect outBounds) { |
| 902 | mTaskStack = mock(TaskStack.class); |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 903 | } |
| 904 | }; |
| 905 | } else { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 906 | return new TestActivityStack(mDisplay, stackId, |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 907 | mRootActivityContainer.mStackSupervisor, mWindowingMode, |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 908 | mActivityType, mOnTop, mCreateActivity); |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 913 | } |