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