Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -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 | 4e4a3ec | 2017-09-27 08:25:03 -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 | 4e4a3ec | 2017-09-27 08:25:03 -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 | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 18 | |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 19 | import static android.app.ActivityManager.PROCESS_STATE_TOP; |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 20 | import static android.app.ActivityManager.START_ABORTED; |
Winson Chung | e789ff6 | 2020-02-24 14:40:23 -0800 | [diff] [blame] | 21 | import static android.app.ActivityManager.START_CANCELED; |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 22 | import static android.app.ActivityManager.START_CLASS_NOT_FOUND; |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 23 | import static android.app.ActivityManager.START_DELIVERED_TO_TOP; |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 24 | import static android.app.ActivityManager.START_FORWARD_AND_REQUEST_CONFLICT; |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 25 | import static android.app.ActivityManager.START_INTENT_NOT_RESOLVED; |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 26 | import static android.app.ActivityManager.START_NOT_VOICE_COMPATIBLE; |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 27 | import static android.app.ActivityManager.START_PERMISSION_DENIED; |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 28 | import static android.app.ActivityManager.START_RETURN_LOCK_TASK_MODE_VIOLATION; |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 29 | import static android.app.ActivityManager.START_SUCCESS; |
| 30 | import static android.app.ActivityManager.START_SWITCHES_CANCELED; |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 31 | import static android.app.ActivityManager.START_TASK_TO_FRONT; |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 32 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 33 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 34 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
| 35 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Louis Chang | 38430df | 2020-01-02 17:14:59 +0800 | [diff] [blame] | 36 | import static android.content.Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT; |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 37 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 38 | import static android.content.Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED; |
Louis Chang | 38430df | 2020-01-02 17:14:59 +0800 | [diff] [blame] | 39 | import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP; |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 40 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TASK; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 41 | |
Tadashi G. Takaoka | a7a6695 | 2018-11-16 15:04:21 +0900 | [diff] [blame] | 42 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.clearInvocations; |
| 43 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer; |
| 44 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; |
| 45 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; |
| 46 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; |
| 47 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.never; |
| 48 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy; |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 49 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; |
Tadashi G. Takaoka | a7a6695 | 2018-11-16 15:04:21 +0900 | [diff] [blame] | 50 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.times; |
| 51 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; |
Diego Vela | 671c007 | 2020-03-25 09:39:26 -0700 | [diff] [blame] | 52 | import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 53 | import static com.android.server.wm.WindowContainer.POSITION_BOTTOM; |
| 54 | import static com.android.server.wm.WindowContainer.POSITION_TOP; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 55 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 56 | import static com.google.common.truth.Truth.assertThat; |
| 57 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 58 | import static org.junit.Assert.assertEquals; |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 59 | import static org.junit.Assert.assertFalse; |
Diego Vela | 671c007 | 2020-03-25 09:39:26 -0700 | [diff] [blame] | 60 | import static org.junit.Assert.assertTrue; |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 61 | import static org.mockito.ArgumentMatchers.any; |
| 62 | import static org.mockito.ArgumentMatchers.anyBoolean; |
| 63 | import static org.mockito.ArgumentMatchers.anyInt; |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 64 | import static org.mockito.ArgumentMatchers.anyString; |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 65 | import static org.mockito.ArgumentMatchers.eq; |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 66 | |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 67 | import android.app.ActivityOptions; |
| 68 | import android.app.IApplicationThread; |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 69 | import android.content.ComponentName; |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 70 | import android.content.Intent; |
| 71 | import android.content.pm.ActivityInfo; |
Bryce Lee | ad5b832 | 2018-03-08 14:28:52 -0800 | [diff] [blame] | 72 | import android.content.pm.ActivityInfo.WindowLayout; |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 73 | import android.content.pm.ApplicationInfo; |
| 74 | import android.content.pm.IPackageManager; |
Philip P. Moltmann | 6c644e6 | 2018-07-18 15:41:24 -0700 | [diff] [blame] | 75 | import android.content.pm.PackageManagerInternal; |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 76 | import android.graphics.Rect; |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 77 | import android.os.IBinder; |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 78 | import android.os.Process; |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 79 | import android.os.RemoteException; |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 80 | import android.platform.test.annotations.Presubmit; |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 81 | import android.service.voice.IVoiceInteractionSession; |
Bryce Lee | ad5b832 | 2018-03-08 14:28:52 -0800 | [diff] [blame] | 82 | import android.view.Gravity; |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 83 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 84 | import androidx.test.filters.SmallTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 85 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 86 | import com.android.server.wm.LaunchParamsController.LaunchParamsModifier; |
Garfield Tan | e3d37b5 | 2019-07-23 12:43:05 -0700 | [diff] [blame] | 87 | import com.android.server.wm.utils.MockTracker; |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 88 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 89 | import org.junit.Before; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 90 | import org.junit.Test; |
Riddle Hsu | 2da2d03 | 2019-08-28 21:08:58 +0800 | [diff] [blame] | 91 | import org.junit.runner.RunWith; |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 92 | |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 93 | /** |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 94 | * Tests for the {@link ActivityStarter} class. |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 95 | * |
| 96 | * Build/Install/Run: |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 97 | * atest WmTests:ActivityStarterTests |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 98 | */ |
| 99 | @SmallTest |
| 100 | @Presubmit |
Riddle Hsu | 2da2d03 | 2019-08-28 21:08:58 +0800 | [diff] [blame] | 101 | @RunWith(WindowTestRunner.class) |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 102 | public class ActivityStarterTests extends ActivityTestsBase { |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 103 | private ActivityStartController mController; |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 104 | private ActivityMetricsLogger mActivityMetricsLogger; |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 105 | private PackageManagerInternal mMockPackageManager; |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 106 | |
| 107 | private static final int PRECONDITION_NO_CALLER_APP = 1; |
| 108 | private static final int PRECONDITION_NO_INTENT_COMPONENT = 1 << 1; |
| 109 | private static final int PRECONDITION_NO_ACTIVITY_INFO = 1 << 2; |
| 110 | private static final int PRECONDITION_SOURCE_PRESENT = 1 << 3; |
| 111 | private static final int PRECONDITION_REQUEST_CODE = 1 << 4; |
| 112 | private static final int PRECONDITION_SOURCE_VOICE_SESSION = 1 << 5; |
| 113 | private static final int PRECONDITION_NO_VOICE_SESSION_SUPPORT = 1 << 6; |
| 114 | private static final int PRECONDITION_DIFFERENT_UID = 1 << 7; |
| 115 | private static final int PRECONDITION_ACTIVITY_SUPPORTS_INTENT_EXCEPTION = 1 << 8; |
| 116 | private static final int PRECONDITION_CANNOT_START_ANY_ACTIVITY = 1 << 9; |
| 117 | private static final int PRECONDITION_DISALLOW_APP_SWITCHING = 1 << 10; |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 118 | |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 119 | private static final int FAKE_CALLING_UID = 666; |
| 120 | private static final int FAKE_REAL_CALLING_UID = 667; |
| 121 | private static final String FAKE_CALLING_PACKAGE = "com.whatever.dude"; |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 122 | private static final int UNIMPORTANT_UID = 12345; |
Michal Karpinski | 0ad4e2f | 2018-11-29 16:22:34 +0000 | [diff] [blame] | 123 | private static final int UNIMPORTANT_UID2 = 12346; |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 124 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 125 | @Before |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 126 | public void setUp() throws Exception { |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 127 | mController = mock(ActivityStartController.class); |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 128 | mActivityMetricsLogger = mock(ActivityMetricsLogger.class); |
| 129 | clearInvocations(mActivityMetricsLogger); |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 133 | public void testStartActivityPreconditions() { |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 134 | verifyStartActivityPreconditions(PRECONDITION_NO_CALLER_APP, START_PERMISSION_DENIED); |
| 135 | verifyStartActivityPreconditions(PRECONDITION_NO_INTENT_COMPONENT, |
| 136 | START_INTENT_NOT_RESOLVED); |
| 137 | verifyStartActivityPreconditions(PRECONDITION_NO_ACTIVITY_INFO, START_CLASS_NOT_FOUND); |
| 138 | verifyStartActivityPreconditions(PRECONDITION_SOURCE_PRESENT | PRECONDITION_REQUEST_CODE, |
| 139 | Intent.FLAG_ACTIVITY_FORWARD_RESULT, START_FORWARD_AND_REQUEST_CONFLICT); |
| 140 | verifyStartActivityPreconditions( |
| 141 | PRECONDITION_SOURCE_PRESENT | PRECONDITION_NO_VOICE_SESSION_SUPPORT |
| 142 | | PRECONDITION_SOURCE_VOICE_SESSION | PRECONDITION_DIFFERENT_UID, |
| 143 | START_NOT_VOICE_COMPATIBLE); |
| 144 | verifyStartActivityPreconditions( |
| 145 | PRECONDITION_SOURCE_PRESENT | PRECONDITION_NO_VOICE_SESSION_SUPPORT |
| 146 | | PRECONDITION_SOURCE_VOICE_SESSION | PRECONDITION_DIFFERENT_UID |
| 147 | | PRECONDITION_ACTIVITY_SUPPORTS_INTENT_EXCEPTION, |
| 148 | START_NOT_VOICE_COMPATIBLE); |
| 149 | verifyStartActivityPreconditions(PRECONDITION_CANNOT_START_ANY_ACTIVITY, START_ABORTED); |
| 150 | verifyStartActivityPreconditions(PRECONDITION_DISALLOW_APP_SWITCHING, |
| 151 | START_SWITCHES_CANCELED); |
| 152 | } |
| 153 | |
| 154 | private static boolean containsConditions(int preconditions, int mask) { |
| 155 | return (preconditions & mask) == mask; |
| 156 | } |
| 157 | |
| 158 | private void verifyStartActivityPreconditions(int preconditions, int expectedResult) { |
| 159 | verifyStartActivityPreconditions(preconditions, 0 /*launchFlags*/, expectedResult); |
| 160 | } |
| 161 | |
Garfield Tan | e3d37b5 | 2019-07-23 12:43:05 -0700 | [diff] [blame] | 162 | private void verifyStartActivityPreconditions(int preconditions, int launchFlags, |
| 163 | int expectedResult) { |
| 164 | // We track mocks created here because this is used in a single test |
| 165 | // (testStartActivityPreconditions) as a specific case, and mocks created inside it won't be |
| 166 | // used for other cases. To avoid extensive memory usage, we clean up all used mocks after |
| 167 | // each case. This is necessary because usually we only clean up mocks after a test |
| 168 | // finishes, but this test creates too many mocks that the intermediate memory usage can be |
| 169 | // ~0.8 GiB and thus very susceptible to OutOfMemoryException. |
| 170 | try (MockTracker tracker = new MockTracker()) { |
| 171 | verifyStartActivityPreconditionsUntracked(preconditions, launchFlags, expectedResult); |
| 172 | } |
| 173 | } |
| 174 | |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 175 | /** |
| 176 | * Excercises how the {@link ActivityStarter} reacts to various preconditions. The caller |
| 177 | * provides a bitmask of all the set conditions (such as {@link #PRECONDITION_NO_CALLER_APP}) |
| 178 | * and the launch flags specified in the intent. The method constructs a call to |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 179 | * {@link ActivityStarter#execute} based on these preconditions and ensures the result matches |
| 180 | * the expected. It is important to note that the method also checks side effects of the start, |
| 181 | * such as ensuring {@link ActivityOptions#abort()} is called in the relevant scenarios. |
Diego Vela | 671c007 | 2020-03-25 09:39:26 -0700 | [diff] [blame] | 182 | * |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 183 | * @param preconditions A bitmask representing the preconditions for the launch |
| 184 | * @param launchFlags The launch flags to be provided by the launch {@link Intent}. |
| 185 | * @param expectedResult The expected result from the launch. |
| 186 | */ |
Garfield Tan | e3d37b5 | 2019-07-23 12:43:05 -0700 | [diff] [blame] | 187 | private void verifyStartActivityPreconditionsUntracked(int preconditions, int launchFlags, |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 188 | int expectedResult) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 189 | final ActivityTaskManagerService service = mService; |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 190 | final IPackageManager packageManager = mock(IPackageManager.class); |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 191 | final ActivityStartController controller = mock(ActivityStartController.class); |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 192 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 193 | final ActivityStarter starter = new ActivityStarter(controller, service, |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 194 | service.mStackSupervisor, mock(ActivityStartInterceptor.class)); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 195 | prepareStarter(launchFlags); |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 196 | final IApplicationThread caller = mock(IApplicationThread.class); |
Darryl L Johnson | 15192d3 | 2020-01-15 15:31:42 -0800 | [diff] [blame] | 197 | final WindowProcessListener listener = mock(WindowProcessListener.class); |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 198 | |
Darryl L Johnson | a098222 | 2020-02-18 18:21:51 -0800 | [diff] [blame] | 199 | final ApplicationInfo ai = new ApplicationInfo(); |
| 200 | ai.packageName = "com.android.test.package"; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 201 | final WindowProcessController wpc = |
| 202 | containsConditions(preconditions, PRECONDITION_NO_CALLER_APP) |
Darryl L Johnson | a098222 | 2020-02-18 18:21:51 -0800 | [diff] [blame] | 203 | ? null : new WindowProcessController(service, ai, null, 0, -1, null, listener); |
Diego Vela | 671c007 | 2020-03-25 09:39:26 -0700 | [diff] [blame] | 204 | doReturn(wpc).when(service).getProcessController(any()); |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 205 | |
| 206 | final Intent intent = new Intent(); |
| 207 | intent.setFlags(launchFlags); |
| 208 | |
| 209 | final ActivityInfo aInfo = containsConditions(preconditions, PRECONDITION_NO_ACTIVITY_INFO) |
| 210 | ? null : new ActivityInfo(); |
| 211 | |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 212 | IVoiceInteractionSession voiceSession = |
| 213 | containsConditions(preconditions, PRECONDITION_SOURCE_VOICE_SESSION) |
| 214 | ? mock(IVoiceInteractionSession.class) : null; |
| 215 | |
| 216 | // Create source token |
| 217 | final ActivityBuilder builder = new ActivityBuilder(service).setTask( |
| 218 | new TaskBuilder(service.mStackSupervisor).setVoiceSession(voiceSession).build()); |
| 219 | |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 220 | if (aInfo != null) { |
| 221 | aInfo.applicationInfo = new ApplicationInfo(); |
Bryce Lee | ad5b832 | 2018-03-08 14:28:52 -0800 | [diff] [blame] | 222 | aInfo.applicationInfo.packageName = |
| 223 | ActivityBuilder.getDefaultComponent().getPackageName(); |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 224 | } |
| 225 | |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 226 | // Offset uid by one from {@link ActivityInfo} to simulate different uids. |
| 227 | if (containsConditions(preconditions, PRECONDITION_DIFFERENT_UID)) { |
| 228 | builder.setUid(aInfo.applicationInfo.uid + 1); |
| 229 | } |
| 230 | |
| 231 | final ActivityRecord source = builder.build(); |
| 232 | |
| 233 | if (!containsConditions(preconditions, PRECONDITION_NO_INTENT_COMPONENT)) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 234 | intent.setComponent(source.mActivityComponent); |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | if (containsConditions(preconditions, PRECONDITION_DISALLOW_APP_SWITCHING)) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 238 | doReturn(false).when(service).checkAppSwitchAllowedLocked( |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 239 | anyInt(), anyInt(), anyInt(), anyInt(), any()); |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 242 | if (containsConditions(preconditions, PRECONDITION_CANNOT_START_ANY_ACTIVITY)) { |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 243 | doReturn(false).when(service.mStackSupervisor).checkStartAnyActivityPermission( |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 244 | any(), any(), any(), anyInt(), anyInt(), anyInt(), any(), any(), |
Winson Chung | c9804e7 | 2018-05-15 11:01:44 -0700 | [diff] [blame] | 245 | anyBoolean(), anyBoolean(), any(), any(), any()); |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | try { |
| 249 | if (containsConditions(preconditions, |
| 250 | PRECONDITION_ACTIVITY_SUPPORTS_INTENT_EXCEPTION)) { |
| 251 | doAnswer((inv) -> { |
| 252 | throw new RemoteException(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 253 | }).when(packageManager).activitySupportsIntent( |
| 254 | eq(source.mActivityComponent), eq(intent), any()); |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 255 | } else { |
| 256 | doReturn(!containsConditions(preconditions, PRECONDITION_NO_VOICE_SESSION_SUPPORT)) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 257 | .when(packageManager).activitySupportsIntent(eq(source.mActivityComponent), |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 258 | eq(intent), any()); |
| 259 | } |
| 260 | } catch (RemoteException e) { |
| 261 | } |
| 262 | |
| 263 | final IBinder resultTo = containsConditions(preconditions, PRECONDITION_SOURCE_PRESENT) |
| 264 | || containsConditions(preconditions, PRECONDITION_SOURCE_VOICE_SESSION) |
| 265 | ? source.appToken : null; |
| 266 | |
| 267 | final int requestCode = containsConditions(preconditions, PRECONDITION_REQUEST_CODE) |
| 268 | ? 1 : 0; |
| 269 | |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 270 | final int result = starter.setCaller(caller) |
| 271 | .setIntent(intent) |
| 272 | .setActivityInfo(aInfo) |
| 273 | .setResultTo(resultTo) |
| 274 | .setRequestCode(requestCode) |
| 275 | .setReason("testLaunchActivityPermissionDenied") |
| 276 | .execute(); |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 277 | |
| 278 | // In some cases the expected result internally is different than the published result. We |
| 279 | // must use ActivityStarter#getExternalResult to translate. |
| 280 | assertEquals(ActivityStarter.getExternalResult(expectedResult), result); |
| 281 | |
| 282 | // Ensure that {@link ActivityOptions} are aborted with unsuccessful result. |
| 283 | if (expectedResult != START_SUCCESS) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 284 | final ActivityStarter optionStarter = new ActivityStarter(mController, mService, |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 285 | mService.mStackSupervisor, mock(ActivityStartInterceptor.class)); |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 286 | final ActivityOptions options = spy(ActivityOptions.makeBasic()); |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 287 | |
| 288 | final int optionResult = optionStarter.setCaller(caller) |
| 289 | .setIntent(intent) |
| 290 | .setActivityInfo(aInfo) |
| 291 | .setResultTo(resultTo) |
| 292 | .setRequestCode(requestCode) |
| 293 | .setReason("testLaunchActivityPermissionDenied") |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 294 | .setActivityOptions(new SafeActivityOptions(options)) |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 295 | .execute(); |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 296 | verify(options, times(1)).abort(); |
| 297 | } |
| 298 | } |
Bryce Lee | b802ea1 | 2017-11-15 21:25:03 -0800 | [diff] [blame] | 299 | |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 300 | private ActivityStarter prepareStarter(@Intent.Flags int launchFlags) { |
| 301 | return prepareStarter(launchFlags, true /* mockGetLaunchStack */); |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Creates a {@link ActivityStarter} with default parameters and necessary mocks. |
| 306 | * |
| 307 | * @param launchFlags The intent flags to launch activity. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 308 | * @param mockGetLaunchStack Whether to mock {@link RootWindowContainer#getLaunchStack} for |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 309 | * always launching to the testing stack. Set to false when allowing |
| 310 | * the activity can be launched to any stack that is decided by real |
| 311 | * implementation. |
| 312 | * @return A {@link ActivityStarter} with default setup. |
| 313 | */ |
| 314 | private ActivityStarter prepareStarter(@Intent.Flags int launchFlags, |
| 315 | boolean mockGetLaunchStack) { |
Bryce Lee | ad5b832 | 2018-03-08 14:28:52 -0800 | [diff] [blame] | 316 | // always allow test to start activity. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 317 | doReturn(true).when(mSupervisor).checkStartAnyActivityPermission( |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 318 | any(), any(), any(), anyInt(), anyInt(), anyInt(), any(), any(), |
Winson Chung | c9804e7 | 2018-05-15 11:01:44 -0700 | [diff] [blame] | 319 | anyBoolean(), anyBoolean(), any(), any(), any()); |
Bryce Lee | ad5b832 | 2018-03-08 14:28:52 -0800 | [diff] [blame] | 320 | |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 321 | if (mockGetLaunchStack) { |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 322 | // Instrument the stack and task used. |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 323 | final ActivityStack stack = mRootWindowContainer.getDefaultTaskDisplayArea() |
| 324 | .createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
| 325 | true /* onTop */); |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 326 | |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 327 | // Direct starter to use spy stack. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 328 | doReturn(stack).when(mRootWindowContainer) |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 329 | .getLaunchStack(any(), any(), any(), anyBoolean()); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 330 | doReturn(stack).when(mRootWindowContainer) |
lumark | f65e02d | 2019-09-14 19:25:21 +0800 | [diff] [blame] | 331 | .getLaunchStack(any(), any(), any(), anyBoolean(), any(), anyInt(), anyInt()); |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 332 | } |
Bryce Lee | ad5b832 | 2018-03-08 14:28:52 -0800 | [diff] [blame] | 333 | |
Philip P. Moltmann | 6c644e6 | 2018-07-18 15:41:24 -0700 | [diff] [blame] | 334 | // Set up mock package manager internal and make sure no unmocked methods are called |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 335 | mMockPackageManager = mock(PackageManagerInternal.class, |
Philip P. Moltmann | 6c644e6 | 2018-07-18 15:41:24 -0700 | [diff] [blame] | 336 | invocation -> { |
| 337 | throw new RuntimeException("Not stubbed"); |
| 338 | }); |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 339 | doReturn(mMockPackageManager).when(mService).getPackageManagerInternalLocked(); |
| 340 | doReturn(false).when(mMockPackageManager).isInstantAppInstallerComponent(any()); |
| 341 | doReturn(null).when(mMockPackageManager).resolveIntent(any(), any(), anyInt(), anyInt(), |
Patrick Baumann | 2fa1c95 | 2020-01-28 09:41:22 -0800 | [diff] [blame] | 342 | anyInt(), anyBoolean(), anyInt()); |
Darryl L Johnson | a098222 | 2020-02-18 18:21:51 -0800 | [diff] [blame] | 343 | doReturn(new ComponentName("", "")).when(mMockPackageManager).getSystemUiServiceComponent(); |
Philip P. Moltmann | 6c644e6 | 2018-07-18 15:41:24 -0700 | [diff] [blame] | 344 | |
| 345 | // Never review permissions |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 346 | doReturn(false).when(mMockPackageManager).isPermissionsReviewRequired(any(), anyInt()); |
| 347 | doNothing().when(mMockPackageManager).grantImplicitAccess( |
Patrick Baumann | 710d720 | 2020-01-09 15:02:14 -0800 | [diff] [blame] | 348 | anyInt(), any(), anyInt(), anyInt(), anyBoolean()); |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 349 | doNothing().when(mMockPackageManager).notifyPackageUse(anyString(), anyInt()); |
Philip P. Moltmann | 6c644e6 | 2018-07-18 15:41:24 -0700 | [diff] [blame] | 350 | |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 351 | final Intent intent = new Intent(); |
| 352 | intent.addFlags(launchFlags); |
| 353 | intent.setComponent(ActivityBuilder.getDefaultComponent()); |
| 354 | |
| 355 | final ActivityInfo info = new ActivityInfo(); |
| 356 | |
| 357 | info.applicationInfo = new ApplicationInfo(); |
| 358 | info.applicationInfo.packageName = ActivityBuilder.getDefaultComponent().getPackageName(); |
| 359 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 360 | return new ActivityStarter(mController, mService, |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 361 | mService.mStackSupervisor, mock(ActivityStartInterceptor.class)) |
| 362 | .setIntent(intent) |
| 363 | .setActivityInfo(info); |
Bryce Lee | ad5b832 | 2018-03-08 14:28:52 -0800 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Ensures that values specified at launch time are passed to {@link LaunchParamsModifier} |
| 368 | * when we are laying out a new task. |
| 369 | */ |
| 370 | @Test |
| 371 | public void testCreateTaskLayout() { |
| 372 | // modifier for validating passed values. |
| 373 | final LaunchParamsModifier modifier = mock(LaunchParamsModifier.class); |
| 374 | mService.mStackSupervisor.getLaunchParamsController().registerModifier(modifier); |
| 375 | |
| 376 | // add custom values to activity info to make unique. |
| 377 | final ActivityInfo info = new ActivityInfo(); |
| 378 | final Rect launchBounds = new Rect(0, 0, 20, 30); |
Bryce Lee | ad5b832 | 2018-03-08 14:28:52 -0800 | [diff] [blame] | 379 | |
| 380 | final WindowLayout windowLayout = |
| 381 | new WindowLayout(10, .5f, 20, 1.0f, Gravity.NO_GRAVITY, 1, 1); |
| 382 | |
| 383 | info.windowLayout = windowLayout; |
| 384 | info.applicationInfo = new ApplicationInfo(); |
| 385 | info.applicationInfo.packageName = ActivityBuilder.getDefaultComponent().getPackageName(); |
| 386 | |
| 387 | // create starter. |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 388 | final ActivityStarter optionStarter = prepareStarter(0 /* launchFlags */); |
Bryce Lee | ad5b832 | 2018-03-08 14:28:52 -0800 | [diff] [blame] | 389 | |
| 390 | final ActivityOptions options = ActivityOptions.makeBasic(); |
| 391 | options.setLaunchBounds(launchBounds); |
| 392 | |
| 393 | // run starter. |
| 394 | optionStarter |
Bryce Lee | ad5b832 | 2018-03-08 14:28:52 -0800 | [diff] [blame] | 395 | .setReason("testCreateTaskLayout") |
| 396 | .setActivityInfo(info) |
| 397 | .setActivityOptions(new SafeActivityOptions(options)) |
| 398 | .execute(); |
| 399 | |
Louis Chang | 6fb1e84 | 2018-12-03 16:07:50 +0800 | [diff] [blame] | 400 | // verify that values are passed to the modifier. Values are passed thrice -- two for |
Garfield Tan | 706dbcb | 2018-10-15 11:33:02 -0700 | [diff] [blame] | 401 | // setting initial state, another when task is created. |
Louis Chang | 6fb1e84 | 2018-12-03 16:07:50 +0800 | [diff] [blame] | 402 | verify(modifier, times(3)).onCalculate(any(), eq(windowLayout), any(), any(), eq(options), |
| 403 | anyInt(), any(), any()); |
Bryce Lee | ad5b832 | 2018-03-08 14:28:52 -0800 | [diff] [blame] | 404 | } |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 405 | |
| 406 | /** |
Louis Chang | 38430df | 2020-01-02 17:14:59 +0800 | [diff] [blame] | 407 | * This test ensures that if the intent is being delivered to a split-screen unfocused task |
| 408 | * while it already on top, reports it as delivering to top. |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 409 | */ |
| 410 | @Test |
| 411 | public void testSplitScreenDeliverToTop() { |
Louis Chang | 38430df | 2020-01-02 17:14:59 +0800 | [diff] [blame] | 412 | final ActivityStarter starter = prepareStarter( |
| 413 | FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | FLAG_ACTIVITY_SINGLE_TOP, false); |
| 414 | final ActivityRecord splitPrimaryFocusActivity = |
| 415 | new ActivityBuilder(mService).setCreateTask(true).build(); |
| 416 | final ActivityRecord splitSecondReusableActivity = |
| 417 | new ActivityBuilder(mService).setCreateTask(true).build(); |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 418 | splitPrimaryFocusActivity.getRootTask() |
Louis Chang | 38430df | 2020-01-02 17:14:59 +0800 | [diff] [blame] | 419 | .setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 420 | splitSecondReusableActivity.getRootTask() |
Louis Chang | 38430df | 2020-01-02 17:14:59 +0800 | [diff] [blame] | 421 | .setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 422 | |
| 423 | // Set focus back to primary. |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 424 | splitPrimaryFocusActivity.getRootTask().moveToFront("testSplitScreenDeliverToTop"); |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 425 | |
Louis Chang | 38430df | 2020-01-02 17:14:59 +0800 | [diff] [blame] | 426 | // Start activity and delivered new intent. |
| 427 | starter.getIntent().setComponent(splitSecondReusableActivity.mActivityComponent); |
Andrii Kulian | 1cfcae8 | 2020-04-10 12:44:38 -0700 | [diff] [blame] | 428 | doReturn(splitSecondReusableActivity).when(mRootWindowContainer).findTask(any(), any()); |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 429 | final int result = starter.setReason("testSplitScreenDeliverToTop").execute(); |
| 430 | |
| 431 | // Ensure result is delivering intent to top. |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 432 | assertEquals(START_DELIVERED_TO_TOP, result); |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | /** |
| 436 | * This test ensures that if the intent is being delivered to a split-screen unfocused task |
| 437 | * reports it is brought to front instead of delivering to top. |
| 438 | */ |
| 439 | @Test |
| 440 | public void testSplitScreenTaskToFront() { |
Louis Chang | 38430df | 2020-01-02 17:14:59 +0800 | [diff] [blame] | 441 | final ActivityStarter starter = prepareStarter( |
| 442 | FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | FLAG_ACTIVITY_SINGLE_TOP, false); |
| 443 | final ActivityRecord splitSecondReusableActivity = |
| 444 | new ActivityBuilder(mService).setCreateTask(true).build(); |
| 445 | final ActivityRecord splitSecondTopActivity = |
| 446 | new ActivityBuilder(mService).setCreateTask(true).build(); |
| 447 | final ActivityRecord splitPrimaryFocusActivity = |
| 448 | new ActivityBuilder(mService).setCreateTask(true).build(); |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 449 | splitPrimaryFocusActivity.getRootTask() |
Louis Chang | 38430df | 2020-01-02 17:14:59 +0800 | [diff] [blame] | 450 | .setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 451 | splitSecondReusableActivity.getRootTask() |
Louis Chang | 38430df | 2020-01-02 17:14:59 +0800 | [diff] [blame] | 452 | .setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 453 | splitSecondTopActivity.getRootTask() |
Louis Chang | 38430df | 2020-01-02 17:14:59 +0800 | [diff] [blame] | 454 | .setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 455 | |
Louis Chang | 38430df | 2020-01-02 17:14:59 +0800 | [diff] [blame] | 456 | // Make it on top of split-screen-secondary. |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 457 | splitSecondTopActivity.getRootTask().moveToFront("testSplitScreenTaskToFront"); |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 458 | |
Louis Chang | 38430df | 2020-01-02 17:14:59 +0800 | [diff] [blame] | 459 | // Let primary stack has focus. |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 460 | splitPrimaryFocusActivity.getRootTask().moveToFront("testSplitScreenTaskToFront"); |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 461 | |
Louis Chang | 38430df | 2020-01-02 17:14:59 +0800 | [diff] [blame] | 462 | // Start activity and delivered new intent. |
| 463 | starter.getIntent().setComponent(splitSecondReusableActivity.mActivityComponent); |
Andrii Kulian | 1cfcae8 | 2020-04-10 12:44:38 -0700 | [diff] [blame] | 464 | doReturn(splitSecondReusableActivity).when(mRootWindowContainer).findTask(any(), any()); |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 465 | final int result = starter.setReason("testSplitScreenMoveToFront").execute(); |
| 466 | |
| 467 | // Ensure result is moving task to front. |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 468 | assertEquals(START_TASK_TO_FRONT, result); |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 469 | } |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 470 | |
| 471 | /** |
| 472 | * Tests activity is cleaned up properly in a task mode violation. |
| 473 | */ |
| 474 | @Test |
| 475 | public void testTaskModeViolation() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 476 | final DisplayContent display = mService.mRootWindowContainer.getDefaultDisplay(); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 477 | display.removeAllTasks(); |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 478 | assertNoTasks(display); |
| 479 | |
| 480 | final ActivityStarter starter = prepareStarter(0); |
| 481 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 482 | final LockTaskController lockTaskController = mService.getLockTaskController(); |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 483 | doReturn(true).when(lockTaskController).isLockTaskModeViolation(any()); |
| 484 | |
| 485 | final int result = starter.setReason("testTaskModeViolation").execute(); |
| 486 | |
| 487 | assertEquals(START_RETURN_LOCK_TASK_MODE_VIOLATION, result); |
| 488 | assertNoTasks(display); |
| 489 | } |
| 490 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 491 | private void assertNoTasks(DisplayContent display) { |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 492 | for (int tdaNdx = display.getTaskDisplayAreaCount() - 1; tdaNdx >= 0; --tdaNdx) { |
| 493 | final TaskDisplayArea taskDisplayArea = display.getTaskDisplayAreaAt(tdaNdx); |
| 494 | for (int sNdx = taskDisplayArea.getStackCount() - 1; sNdx >= 0; --sNdx) { |
| 495 | final ActivityStack stack = taskDisplayArea.getStackAt(sNdx); |
| 496 | assertFalse(stack.hasChild()); |
| 497 | } |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 498 | } |
| 499 | } |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 500 | |
| 501 | /** |
| 502 | * This test ensures that activity starts are not being logged when the logging is disabled. |
| 503 | */ |
| 504 | @Test |
| 505 | public void testActivityStartsLogging_noLoggingWhenDisabled() { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 506 | doReturn(false).when(mService).isActivityStartsLoggingEnabled(); |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 507 | doReturn(mActivityMetricsLogger).when(mService.mStackSupervisor).getActivityMetricsLogger(); |
| 508 | |
| 509 | ActivityStarter starter = prepareStarter(FLAG_ACTIVITY_NEW_TASK); |
| 510 | starter.setReason("testActivityStartsLogging_noLoggingWhenDisabled").execute(); |
| 511 | |
| 512 | // verify logging wasn't done |
Michal Karpinski | 4fd5b84 | 2019-01-28 15:13:32 +0000 | [diff] [blame] | 513 | verify(mActivityMetricsLogger, never()).logAbortedBgActivityStart(any(), any(), anyInt(), |
| 514 | any(), anyInt(), anyBoolean(), anyInt(), anyInt(), anyBoolean(), anyBoolean()); |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | /** |
| 518 | * This test ensures that activity starts are being logged when the logging is enabled. |
| 519 | */ |
| 520 | @Test |
| 521 | public void testActivityStartsLogging_logsWhenEnabled() { |
| 522 | // note: conveniently this package doesn't have any activity visible |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 523 | doReturn(true).when(mService).isActivityStartsLoggingEnabled(); |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 524 | doReturn(mActivityMetricsLogger).when(mService.mStackSupervisor).getActivityMetricsLogger(); |
| 525 | |
| 526 | ActivityStarter starter = prepareStarter(FLAG_ACTIVITY_NEW_TASK) |
| 527 | .setCallingUid(FAKE_CALLING_UID) |
| 528 | .setRealCallingUid(FAKE_REAL_CALLING_UID) |
| 529 | .setCallingPackage(FAKE_CALLING_PACKAGE) |
| 530 | .setOriginatingPendingIntent(null); |
| 531 | |
| 532 | starter.setReason("testActivityStartsLogging_logsWhenEnabled").execute(); |
| 533 | |
| 534 | // verify the above activity start was logged |
Michal Karpinski | 4fd5b84 | 2019-01-28 15:13:32 +0000 | [diff] [blame] | 535 | verify(mActivityMetricsLogger, times(1)).logAbortedBgActivityStart(any(), any(), |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 536 | eq(FAKE_CALLING_UID), eq(FAKE_CALLING_PACKAGE), anyInt(), anyBoolean(), |
Michal Karpinski | 4fd5b84 | 2019-01-28 15:13:32 +0000 | [diff] [blame] | 537 | eq(FAKE_REAL_CALLING_UID), anyInt(), anyBoolean(), eq(false)); |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 538 | } |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 539 | |
| 540 | /** |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 541 | * This test ensures that unsupported usecases aren't aborted when background starts are |
| 542 | * allowed. |
| 543 | */ |
| 544 | @Test |
| 545 | public void testBackgroundActivityStartsAllowed_noStartsAborted() { |
| 546 | doReturn(true).when(mService).isBackgroundActivityStartsEnabled(); |
| 547 | |
Michal Karpinski | 0ad4e2f | 2018-11-29 16:22:34 +0000 | [diff] [blame] | 548 | runAndVerifyBackgroundActivityStartsSubtest("allowed_noStartsAborted", false, |
| 549 | UNIMPORTANT_UID, false, PROCESS_STATE_TOP + 1, |
| 550 | UNIMPORTANT_UID2, false, PROCESS_STATE_TOP + 1, |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 551 | false, false, false, false, false); |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | /** |
| 555 | * This test ensures that unsupported usecases are aborted when background starts are |
| 556 | * disallowed. |
| 557 | */ |
| 558 | @Test |
| 559 | public void testBackgroundActivityStartsDisallowed_unsupportedStartsAborted() { |
| 560 | doReturn(false).when(mService).isBackgroundActivityStartsEnabled(); |
| 561 | |
Michal Karpinski | 0ad4e2f | 2018-11-29 16:22:34 +0000 | [diff] [blame] | 562 | runAndVerifyBackgroundActivityStartsSubtest( |
| 563 | "disallowed_unsupportedUsecase_aborted", true, |
| 564 | UNIMPORTANT_UID, false, PROCESS_STATE_TOP + 1, |
| 565 | UNIMPORTANT_UID2, false, PROCESS_STATE_TOP + 1, |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 566 | false, false, false, false, false); |
Alan Stokes | eea8d3e | 2019-04-10 17:37:25 +0100 | [diff] [blame] | 567 | runAndVerifyBackgroundActivityStartsSubtest( |
| 568 | "disallowed_callingUidProcessStateTop_aborted", true, |
| 569 | UNIMPORTANT_UID, false, PROCESS_STATE_TOP, |
| 570 | UNIMPORTANT_UID2, false, PROCESS_STATE_TOP + 1, |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 571 | false, false, false, false, false); |
Alan Stokes | eea8d3e | 2019-04-10 17:37:25 +0100 | [diff] [blame] | 572 | runAndVerifyBackgroundActivityStartsSubtest( |
| 573 | "disallowed_realCallingUidProcessStateTop_aborted", true, |
| 574 | UNIMPORTANT_UID, false, PROCESS_STATE_TOP + 1, |
| 575 | UNIMPORTANT_UID2, false, PROCESS_STATE_TOP, |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 576 | false, false, false, false, false); |
Alan Stokes | eea8d3e | 2019-04-10 17:37:25 +0100 | [diff] [blame] | 577 | runAndVerifyBackgroundActivityStartsSubtest( |
| 578 | "disallowed_hasForegroundActivities_aborted", true, |
| 579 | UNIMPORTANT_UID, false, PROCESS_STATE_TOP + 1, |
| 580 | UNIMPORTANT_UID2, false, PROCESS_STATE_TOP + 1, |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 581 | true, false, false, false, false); |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | /** |
| 585 | * This test ensures that supported usecases aren't aborted when background starts are |
| 586 | * disallowed. |
Alan Stokes | eea8d3e | 2019-04-10 17:37:25 +0100 | [diff] [blame] | 587 | * The scenarios each have only one condition that makes them supported. |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 588 | */ |
| 589 | @Test |
| 590 | public void testBackgroundActivityStartsDisallowed_supportedStartsNotAborted() { |
| 591 | doReturn(false).when(mService).isBackgroundActivityStartsEnabled(); |
| 592 | |
Michal Karpinski | 0ad4e2f | 2018-11-29 16:22:34 +0000 | [diff] [blame] | 593 | runAndVerifyBackgroundActivityStartsSubtest("disallowed_rootUid_notAborted", false, |
| 594 | Process.ROOT_UID, false, PROCESS_STATE_TOP + 1, |
| 595 | UNIMPORTANT_UID2, false, PROCESS_STATE_TOP + 1, |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 596 | false, false, false, false, false); |
Michal Karpinski | 0ad4e2f | 2018-11-29 16:22:34 +0000 | [diff] [blame] | 597 | runAndVerifyBackgroundActivityStartsSubtest("disallowed_systemUid_notAborted", false, |
| 598 | Process.SYSTEM_UID, false, PROCESS_STATE_TOP + 1, |
| 599 | UNIMPORTANT_UID2, false, PROCESS_STATE_TOP + 1, |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 600 | false, false, false, false, false); |
Michal Karpinski | b416f47 | 2019-01-24 14:34:28 +0000 | [diff] [blame] | 601 | runAndVerifyBackgroundActivityStartsSubtest("disallowed_nfcUid_notAborted", false, |
| 602 | Process.NFC_UID, false, PROCESS_STATE_TOP + 1, |
| 603 | UNIMPORTANT_UID2, false, PROCESS_STATE_TOP + 1, |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 604 | false, false, false, false, false); |
Michal Karpinski | 0ad4e2f | 2018-11-29 16:22:34 +0000 | [diff] [blame] | 605 | runAndVerifyBackgroundActivityStartsSubtest( |
| 606 | "disallowed_callingUidHasVisibleWindow_notAborted", false, |
| 607 | UNIMPORTANT_UID, true, PROCESS_STATE_TOP + 1, |
| 608 | UNIMPORTANT_UID2, false, PROCESS_STATE_TOP + 1, |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 609 | false, false, false, false, false); |
Michal Karpinski | 0ad4e2f | 2018-11-29 16:22:34 +0000 | [diff] [blame] | 610 | runAndVerifyBackgroundActivityStartsSubtest( |
Michal Karpinski | 0ad4e2f | 2018-11-29 16:22:34 +0000 | [diff] [blame] | 611 | "disallowed_realCallingUidHasVisibleWindow_notAborted", false, |
| 612 | UNIMPORTANT_UID, false, PROCESS_STATE_TOP + 1, |
| 613 | UNIMPORTANT_UID2, true, PROCESS_STATE_TOP + 1, |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 614 | false, false, false, false, false); |
Michal Karpinski | 0ad4e2f | 2018-11-29 16:22:34 +0000 | [diff] [blame] | 615 | runAndVerifyBackgroundActivityStartsSubtest( |
Michal Karpinski | 0ad4e2f | 2018-11-29 16:22:34 +0000 | [diff] [blame] | 616 | "disallowed_callerIsRecents_notAborted", false, |
| 617 | UNIMPORTANT_UID, false, PROCESS_STATE_TOP + 1, |
| 618 | UNIMPORTANT_UID2, false, PROCESS_STATE_TOP + 1, |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 619 | false, true, false, false, false); |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 620 | runAndVerifyBackgroundActivityStartsSubtest( |
| 621 | "disallowed_callerIsWhitelisted_notAborted", false, |
| 622 | UNIMPORTANT_UID, false, PROCESS_STATE_TOP + 1, |
| 623 | UNIMPORTANT_UID2, false, PROCESS_STATE_TOP + 1, |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 624 | false, false, true, false, false); |
Michal Karpinski | daef80f | 2019-01-29 16:50:51 +0000 | [diff] [blame] | 625 | runAndVerifyBackgroundActivityStartsSubtest( |
| 626 | "disallowed_callerIsInstrumentingWithBackgroundActivityStartPrivileges_notAborted", |
| 627 | false, |
| 628 | UNIMPORTANT_UID, false, PROCESS_STATE_TOP + 1, |
| 629 | UNIMPORTANT_UID2, false, PROCESS_STATE_TOP + 1, |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 630 | false, false, false, true, false); |
Michal Karpinski | 302dcec | 2019-02-01 11:48:25 +0000 | [diff] [blame] | 631 | runAndVerifyBackgroundActivityStartsSubtest( |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 632 | "disallowed_callingPackageNameIsDeviceOwner_notAborted", false, |
Michal Karpinski | 302dcec | 2019-02-01 11:48:25 +0000 | [diff] [blame] | 633 | UNIMPORTANT_UID, false, PROCESS_STATE_TOP + 1, |
| 634 | UNIMPORTANT_UID2, false, PROCESS_STATE_TOP + 1, |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 635 | false, false, false, false, true); |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | private void runAndVerifyBackgroundActivityStartsSubtest(String name, boolean shouldHaveAborted, |
Michal Karpinski | 0ad4e2f | 2018-11-29 16:22:34 +0000 | [diff] [blame] | 639 | int callingUid, boolean callingUidHasVisibleWindow, int callingUidProcState, |
| 640 | int realCallingUid, boolean realCallingUidHasVisibleWindow, int realCallingUidProcState, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 641 | boolean hasForegroundActivities, boolean callerIsRecents, |
Michal Karpinski | daef80f | 2019-01-29 16:50:51 +0000 | [diff] [blame] | 642 | boolean callerIsTempWhitelisted, |
Michal Karpinski | 302dcec | 2019-02-01 11:48:25 +0000 | [diff] [blame] | 643 | boolean callerIsInstrumentingWithBackgroundActivityStartPrivileges, |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 644 | boolean isCallingUidDeviceOwner) { |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 645 | // window visibility |
Michal Karpinski | a606a29 | 2019-01-12 17:29:52 +0000 | [diff] [blame] | 646 | doReturn(callingUidHasVisibleWindow).when(mService.mWindowManager.mRoot) |
| 647 | .isAnyNonToastWindowVisibleForUid(callingUid); |
| 648 | doReturn(realCallingUidHasVisibleWindow).when(mService.mWindowManager.mRoot) |
| 649 | .isAnyNonToastWindowVisibleForUid(realCallingUid); |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 650 | // process importance |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 651 | doReturn(callingUidProcState).when(mService).getUidState(callingUid); |
| 652 | doReturn(realCallingUidProcState).when(mService).getUidState(realCallingUid); |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 653 | // foreground activities |
| 654 | final IApplicationThread caller = mock(IApplicationThread.class); |
Darryl L Johnson | 15192d3 | 2020-01-15 15:31:42 -0800 | [diff] [blame] | 655 | final WindowProcessListener listener = mock(WindowProcessListener.class); |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 656 | final ApplicationInfo ai = new ApplicationInfo(); |
Michal Karpinski | 0ad4e2f | 2018-11-29 16:22:34 +0000 | [diff] [blame] | 657 | ai.uid = callingUid; |
Darryl L Johnson | a098222 | 2020-02-18 18:21:51 -0800 | [diff] [blame] | 658 | ai.packageName = "com.android.test.package"; |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 659 | final WindowProcessController callerApp = |
Darryl L Johnson | 15192d3 | 2020-01-15 15:31:42 -0800 | [diff] [blame] | 660 | new WindowProcessController(mService, ai, null, callingUid, -1, null, listener); |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 661 | callerApp.setHasForegroundActivities(hasForegroundActivities); |
| 662 | doReturn(callerApp).when(mService).getProcessController(caller); |
Michal Karpinski | 82bb590 | 2018-11-28 15:52:52 +0000 | [diff] [blame] | 663 | // caller is recents |
| 664 | RecentTasks recentTasks = mock(RecentTasks.class); |
| 665 | mService.mStackSupervisor.setRecentTasks(recentTasks); |
Michal Karpinski | 0ad4e2f | 2018-11-29 16:22:34 +0000 | [diff] [blame] | 666 | doReturn(callerIsRecents).when(recentTasks).isCallerRecents(callingUid); |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 667 | // caller is temp whitelisted |
| 668 | callerApp.setAllowBackgroundActivityStarts(callerIsTempWhitelisted); |
Michal Karpinski | daef80f | 2019-01-29 16:50:51 +0000 | [diff] [blame] | 669 | // caller is instrumenting with background activity starts privileges |
Michal Karpinski | 4bc5649 | 2019-01-31 12:07:33 +0000 | [diff] [blame] | 670 | callerApp.setInstrumenting(callerIsInstrumentingWithBackgroundActivityStartPrivileges, |
Michal Karpinski | daef80f | 2019-01-29 16:50:51 +0000 | [diff] [blame] | 671 | callerIsInstrumentingWithBackgroundActivityStartPrivileges); |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 672 | // callingUid is the device owner |
| 673 | doReturn(isCallingUidDeviceOwner).when(mService).isDeviceOwner(callingUid); |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 674 | |
| 675 | final ActivityOptions options = spy(ActivityOptions.makeBasic()); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 676 | ActivityRecord[] outActivity = new ActivityRecord[1]; |
Michal Karpinski | 0ad4e2f | 2018-11-29 16:22:34 +0000 | [diff] [blame] | 677 | ActivityStarter starter = prepareStarter(FLAG_ACTIVITY_NEW_TASK) |
Michal Karpinski | 666631b | 2019-02-26 16:59:11 +0000 | [diff] [blame] | 678 | .setCallingPackage("com.whatever.dude") |
Michal Karpinski | 0ad4e2f | 2018-11-29 16:22:34 +0000 | [diff] [blame] | 679 | .setCaller(caller) |
| 680 | .setCallingUid(callingUid) |
| 681 | .setRealCallingUid(realCallingUid) |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 682 | .setActivityOptions(new SafeActivityOptions(options)) |
| 683 | .setOutActivity(outActivity); |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 684 | |
| 685 | final int result = starter.setReason("testBackgroundActivityStarts_" + name).execute(); |
| 686 | |
| 687 | assertEquals(ActivityStarter.getExternalResult( |
| 688 | shouldHaveAborted ? START_ABORTED : START_SUCCESS), result); |
| 689 | verify(options, times(shouldHaveAborted ? 1 : 0)).abort(); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 690 | |
| 691 | final ActivityRecord startedActivity = outActivity[0]; |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 692 | if (startedActivity != null && startedActivity.getTask() != null) { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 693 | // Remove the activity so it doesn't interfere with with subsequent activity launch |
| 694 | // tests from this method. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 695 | startedActivity.getTask().removeChild(startedActivity); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 696 | } |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | /** |
Riddle Hsu | 273e999 | 2019-04-29 22:40:59 +0800 | [diff] [blame] | 700 | * This test ensures that {@link ActivityStarter#setTargetStackAndMoveToFrontIfNeeded} will |
| 701 | * move the existing task to front if the current focused stack doesn't have running task. |
| 702 | */ |
| 703 | @Test |
| 704 | public void testBringTaskToFrontWhenFocusedStackIsFinising() { |
| 705 | // Put 2 tasks in the same stack (simulate the behavior of home stack). |
| 706 | final ActivityRecord activity = new ActivityBuilder(mService) |
| 707 | .setCreateTask(true).build(); |
| 708 | new ActivityBuilder(mService) |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 709 | .setStack(activity.getRootTask()) |
Riddle Hsu | 273e999 | 2019-04-29 22:40:59 +0800 | [diff] [blame] | 710 | .setCreateTask(true).build(); |
| 711 | |
| 712 | // Create a top finishing activity. |
| 713 | final ActivityRecord finishingTopActivity = new ActivityBuilder(mService) |
| 714 | .setCreateTask(true).build(); |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 715 | finishingTopActivity.getRootTask().moveToFront("finishingTopActivity"); |
Riddle Hsu | 273e999 | 2019-04-29 22:40:59 +0800 | [diff] [blame] | 716 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 717 | assertEquals(finishingTopActivity, mRootWindowContainer.topRunningActivity()); |
Riddle Hsu | 273e999 | 2019-04-29 22:40:59 +0800 | [diff] [blame] | 718 | finishingTopActivity.finishing = true; |
| 719 | |
| 720 | // Launch the bottom task of the target stack. |
| 721 | prepareStarter(FLAG_ACTIVITY_NEW_TASK, false /* mockGetLaunchStack */) |
| 722 | .setReason("testBringTaskToFrontWhenTopStackIsFinising") |
| 723 | .setIntent(activity.intent) |
| 724 | .execute(); |
| 725 | // The hierarchies of the activity should move to front. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 726 | assertEquals(activity, mRootWindowContainer.topRunningActivity()); |
Riddle Hsu | 273e999 | 2019-04-29 22:40:59 +0800 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | /** |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 730 | * This test ensures that when starting an existing single task activity on secondary display |
| 731 | * which is not the top focused display, it should deliver new intent to the activity and not |
| 732 | * create a new stack. |
| 733 | */ |
| 734 | @Test |
| 735 | public void testDeliverIntentToTopActivityOfNonTopDisplay() { |
| 736 | final ActivityStarter starter = prepareStarter(FLAG_ACTIVITY_NEW_TASK, |
| 737 | false /* mockGetLaunchStack */); |
| 738 | |
| 739 | // Create a secondary display at bottom. |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 740 | final TestDisplayContent secondaryDisplay = |
| 741 | new TestDisplayContent.Builder(mService, 1000, 1500) |
Evan Rosky | 4a51dbc0 | 2019-09-11 17:28:07 -0700 | [diff] [blame] | 742 | .setPosition(POSITION_BOTTOM).build(); |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 743 | final TaskDisplayArea secondaryTaskContainer = secondaryDisplay.getDefaultTaskDisplayArea(); |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 744 | final ActivityStack stack = secondaryTaskContainer.createStack( |
| 745 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 746 | |
| 747 | // Create an activity record on the top of secondary display. |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 748 | final ActivityRecord topActivityOnSecondaryDisplay = createSingleTaskActivityOn(stack); |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 749 | |
| 750 | // Put an activity on default display as the top focused activity. |
| 751 | new ActivityBuilder(mService).setCreateTask(true).build(); |
| 752 | |
| 753 | // Start activity with the same intent as {@code topActivityOnSecondaryDisplay} |
| 754 | // on secondary display. |
| 755 | final ActivityOptions options = ActivityOptions.makeBasic() |
| 756 | .setLaunchDisplayId(secondaryDisplay.mDisplayId); |
| 757 | final int result = starter.setReason("testDeliverIntentToTopActivityOfNonTopDisplay") |
| 758 | .setIntent(topActivityOnSecondaryDisplay.intent) |
| 759 | .setActivityOptions(options.toBundle()) |
| 760 | .execute(); |
| 761 | |
| 762 | // Ensure result is delivering intent to top. |
| 763 | assertEquals(START_DELIVERED_TO_TOP, result); |
| 764 | |
| 765 | // Ensure secondary display only creates one stack. |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 766 | verify(secondaryTaskContainer, times(1)).createStack(anyInt(), anyInt(), anyBoolean()); |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | /** |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 770 | * This test ensures that when starting an existing non-top single task activity on secondary |
| 771 | * display which is the top focused display, it should bring the task to front without creating |
| 772 | * unused stack. |
| 773 | */ |
| 774 | @Test |
| 775 | public void testBringTaskToFrontOnSecondaryDisplay() { |
| 776 | final ActivityStarter starter = prepareStarter(FLAG_ACTIVITY_NEW_TASK, |
| 777 | false /* mockGetLaunchStack */); |
| 778 | |
| 779 | // Create a secondary display with an activity. |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 780 | final TestDisplayContent secondaryDisplay = |
| 781 | new TestDisplayContent.Builder(mService, 1000, 1500).build(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 782 | mRootWindowContainer.positionChildAt(POSITION_TOP, secondaryDisplay, |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 783 | false /* includingParents */); |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 784 | final TaskDisplayArea secondaryTaskContainer = secondaryDisplay.getDefaultTaskDisplayArea(); |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 785 | final ActivityRecord singleTaskActivity = createSingleTaskActivityOn( |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 786 | secondaryTaskContainer.createStack(WINDOWING_MODE_FULLSCREEN, |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 787 | ACTIVITY_TYPE_STANDARD, false /* onTop */)); |
| 788 | |
| 789 | // Create another activity on top of the secondary display. |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 790 | final ActivityStack topStack = secondaryTaskContainer.createStack(WINDOWING_MODE_FULLSCREEN, |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 791 | ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 792 | final Task topTask = new TaskBuilder(mSupervisor).setStack(topStack).build(); |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 793 | new ActivityBuilder(mService).setTask(topTask).build(); |
| 794 | |
| 795 | // Start activity with the same intent as {@code singleTaskActivity} on secondary display. |
| 796 | final ActivityOptions options = ActivityOptions.makeBasic() |
| 797 | .setLaunchDisplayId(secondaryDisplay.mDisplayId); |
| 798 | final int result = starter.setReason("testBringTaskToFrontOnSecondaryDisplay") |
| 799 | .setIntent(singleTaskActivity.intent) |
| 800 | .setActivityOptions(options.toBundle()) |
| 801 | .execute(); |
| 802 | |
| 803 | // Ensure result is moving existing task to front. |
| 804 | assertEquals(START_TASK_TO_FRONT, result); |
| 805 | |
| 806 | // Ensure secondary display only creates two stacks. |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 807 | verify(secondaryTaskContainer, times(2)).createStack(anyInt(), anyInt(), anyBoolean()); |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 808 | } |
| 809 | |
Evan Rosky | 8d1c24e | 2020-04-23 09:21:16 -0700 | [diff] [blame] | 810 | @Test |
| 811 | public void testWasVisibleInRestartAttempt() { |
| 812 | final ActivityStarter starter = prepareStarter( |
| 813 | FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | FLAG_ACTIVITY_SINGLE_TOP, false); |
| 814 | final ActivityRecord reusableActivity = |
| 815 | new ActivityBuilder(mService).setCreateTask(true).build(); |
| 816 | final ActivityRecord topActivity = |
| 817 | new ActivityBuilder(mService).setCreateTask(true).build(); |
| 818 | |
| 819 | // Make sure topActivity is on top |
| 820 | topActivity.getRootTask().moveToFront("testWasVisibleInRestartAttempt"); |
| 821 | reusableActivity.setVisible(false); |
| 822 | |
| 823 | final TaskChangeNotificationController taskChangeNotifier = |
| 824 | mService.getTaskChangeNotificationController(); |
| 825 | spyOn(taskChangeNotifier); |
| 826 | |
| 827 | Task task = topActivity.getTask(); |
| 828 | starter.postStartActivityProcessing( |
| 829 | task.getTopNonFinishingActivity(), START_DELIVERED_TO_TOP, task.getStack()); |
| 830 | |
| 831 | verify(taskChangeNotifier).notifyActivityRestartAttempt( |
| 832 | any(), anyBoolean(), anyBoolean(), anyBoolean()); |
| 833 | verify(taskChangeNotifier).notifyActivityRestartAttempt( |
| 834 | any(), anyBoolean(), anyBoolean(), eq(true)); |
| 835 | |
| 836 | Task task2 = reusableActivity.getTask(); |
| 837 | starter.postStartActivityProcessing( |
| 838 | task2.getTopNonFinishingActivity(), START_TASK_TO_FRONT, task.getStack()); |
| 839 | verify(taskChangeNotifier, times(2)).notifyActivityRestartAttempt( |
| 840 | any(), anyBoolean(), anyBoolean(), anyBoolean()); |
| 841 | verify(taskChangeNotifier).notifyActivityRestartAttempt( |
| 842 | any(), anyBoolean(), anyBoolean(), eq(false)); |
| 843 | } |
| 844 | |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 845 | private ActivityRecord createSingleTaskActivityOn(ActivityStack stack) { |
| 846 | final ComponentName componentName = ComponentName.createRelative( |
| 847 | DEFAULT_COMPONENT_PACKAGE_NAME, |
| 848 | DEFAULT_COMPONENT_PACKAGE_NAME + ".SingleTaskActivity"); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 849 | final Task task = new TaskBuilder(mSupervisor) |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 850 | .setComponent(componentName) |
| 851 | .setStack(stack) |
| 852 | .build(); |
| 853 | return new ActivityBuilder(mService) |
| 854 | .setComponent(componentName) |
| 855 | .setLaunchMode(LAUNCH_SINGLE_TASK) |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 856 | .setTask(task) |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 857 | .build(); |
| 858 | } |
| 859 | |
| 860 | /** |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 861 | * This test ensures that a reused top activity in the top focused stack is able to be |
| 862 | * reparented to another display. |
| 863 | */ |
| 864 | @Test |
| 865 | public void testReparentTopFocusedActivityToSecondaryDisplay() { |
| 866 | final ActivityStarter starter = prepareStarter(FLAG_ACTIVITY_NEW_TASK, |
| 867 | false /* mockGetLaunchStack */); |
| 868 | |
| 869 | // Create a secondary display at bottom. |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 870 | final TestDisplayContent secondaryDisplay = addNewDisplayContentAt(POSITION_BOTTOM); |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 871 | final TaskDisplayArea secondaryTaskContainer = secondaryDisplay.getDefaultTaskDisplayArea(); |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 872 | secondaryTaskContainer.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 873 | true /* onTop */); |
| 874 | |
| 875 | // Put an activity on default display as the top focused activity. |
| 876 | final ActivityRecord topActivity = new ActivityBuilder(mService) |
| 877 | .setCreateTask(true) |
| 878 | .setLaunchMode(LAUNCH_SINGLE_TASK) |
| 879 | .build(); |
| 880 | |
| 881 | // Start activity with the same intent as {@code topActivity} on secondary display. |
| 882 | final ActivityOptions options = ActivityOptions.makeBasic() |
| 883 | .setLaunchDisplayId(secondaryDisplay.mDisplayId); |
| 884 | starter.setReason("testReparentTopFocusedActivityToSecondaryDisplay") |
| 885 | .setIntent(topActivity.intent) |
| 886 | .setActivityOptions(options.toBundle()) |
| 887 | .execute(); |
| 888 | |
| 889 | // Ensure the activity is moved to secondary display. |
| 890 | assertEquals(secondaryDisplay, topActivity.getDisplay()); |
| 891 | } |
Winson Chung | e219ae1 | 2019-07-18 13:43:23 -0700 | [diff] [blame] | 892 | |
| 893 | /** |
| 894 | * This test ensures that starting an activity with the freeze-task-list activity option will |
| 895 | * actually freeze the task list |
| 896 | */ |
| 897 | @Test |
| 898 | public void testFreezeTaskListActivityOption() { |
| 899 | RecentTasks recentTasks = mock(RecentTasks.class); |
| 900 | mService.mStackSupervisor.setRecentTasks(recentTasks); |
| 901 | doReturn(true).when(recentTasks).isCallerRecents(anyInt()); |
| 902 | |
| 903 | final ActivityStarter starter = prepareStarter(0 /* flags */); |
| 904 | final ActivityOptions options = ActivityOptions.makeBasic(); |
| 905 | options.setFreezeRecentTasksReordering(); |
| 906 | |
| 907 | starter.setReason("testFreezeTaskListActivityOption") |
| 908 | .setActivityOptions(new SafeActivityOptions(options)) |
| 909 | .execute(); |
| 910 | |
| 911 | verify(recentTasks, times(1)).setFreezeTaskListReordering(); |
| 912 | verify(recentTasks, times(0)).resetFreezeTaskListReorderingOnTimeout(); |
| 913 | } |
| 914 | |
| 915 | /** |
| 916 | * This test ensures that if we froze the task list as a part of starting an activity that fails |
| 917 | * to start, that we also reset the task list. |
| 918 | */ |
| 919 | @Test |
| 920 | public void testFreezeTaskListActivityOptionFailedStart_expectResetFreezeTaskList() { |
| 921 | RecentTasks recentTasks = mock(RecentTasks.class); |
| 922 | mService.mStackSupervisor.setRecentTasks(recentTasks); |
| 923 | doReturn(true).when(recentTasks).isCallerRecents(anyInt()); |
| 924 | |
| 925 | final ActivityStarter starter = prepareStarter(0 /* flags */); |
| 926 | final ActivityOptions options = ActivityOptions.makeBasic(); |
| 927 | options.setFreezeRecentTasksReordering(); |
| 928 | |
| 929 | starter.setReason("testFreezeTaskListActivityOptionFailedStart") |
| 930 | .setActivityOptions(new SafeActivityOptions(options)) |
| 931 | .execute(); |
| 932 | |
| 933 | // Simulate a failed start |
Winson Chung | e789ff6 | 2020-02-24 14:40:23 -0800 | [diff] [blame] | 934 | starter.postStartActivityProcessing(null, START_CANCELED, null); |
Winson Chung | e219ae1 | 2019-07-18 13:43:23 -0700 | [diff] [blame] | 935 | |
| 936 | verify(recentTasks, times(1)).setFreezeTaskListReordering(); |
| 937 | verify(recentTasks, times(1)).resetFreezeTaskListReorderingOnTimeout(); |
| 938 | } |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 939 | |
| 940 | @Test |
| 941 | public void testNoActivityInfo() { |
| 942 | final ActivityStarter starter = prepareStarter(0 /* flags */); |
| 943 | spyOn(starter.mRequest); |
| 944 | |
| 945 | final Intent intent = new Intent(); |
| 946 | intent.setComponent(ActivityBuilder.getDefaultComponent()); |
| 947 | starter.setReason("testNoActivityInfo").setIntent(intent) |
| 948 | .setActivityInfo(null).execute(); |
| 949 | verify(starter.mRequest).resolveActivity(any()); |
| 950 | } |
| 951 | |
| 952 | @Test |
| 953 | public void testResolveEphemeralInstaller() { |
| 954 | final ActivityStarter starter = prepareStarter(0 /* flags */); |
| 955 | final Intent intent = new Intent(); |
| 956 | intent.setComponent(ActivityBuilder.getDefaultComponent()); |
| 957 | |
| 958 | doReturn(true).when(mMockPackageManager).isInstantAppInstallerComponent(any()); |
| 959 | starter.setIntent(intent).mRequest.resolveActivity(mService.mStackSupervisor); |
| 960 | |
| 961 | // Make sure the client intent won't be modified. |
| 962 | assertThat(intent.getComponent()).isNotNull(); |
| 963 | assertThat(starter.getIntent().getComponent()).isNull(); |
| 964 | } |
| 965 | |
| 966 | @Test |
| 967 | public void testNotAllowIntentWithFd() { |
| 968 | final ActivityStarter starter = prepareStarter(0 /* flags */); |
| 969 | final Intent intent = spy(new Intent()); |
| 970 | intent.setComponent(ActivityBuilder.getDefaultComponent()); |
| 971 | doReturn(true).when(intent).hasFileDescriptors(); |
| 972 | |
| 973 | boolean exceptionCaught = false; |
| 974 | try { |
| 975 | starter.setIntent(intent).execute(); |
| 976 | } catch (IllegalArgumentException ex) { |
| 977 | exceptionCaught = true; |
| 978 | } |
| 979 | assertThat(exceptionCaught).isTrue(); |
| 980 | } |
Louis Chang | 07b1300 | 2019-11-27 22:08:37 +0800 | [diff] [blame] | 981 | |
| 982 | @Test |
| 983 | public void testRecycleTaskFromAnotherUser() { |
| 984 | final ActivityStarter starter = prepareStarter(0 /* flags */); |
| 985 | starter.mStartActivity = new ActivityBuilder(mService).build(); |
| 986 | final Task task = new TaskBuilder(mService.mStackSupervisor) |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 987 | .setStack(mService.mRootWindowContainer.getDefaultTaskDisplayArea().createStack( |
Louis Chang | 07b1300 | 2019-11-27 22:08:37 +0800 | [diff] [blame] | 988 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */)) |
| 989 | .setUserId(10) |
| 990 | .build(); |
| 991 | |
| 992 | final int result = starter.recycleTask(task, null, null); |
| 993 | assertThat(result == START_SUCCESS).isTrue(); |
| 994 | assertThat(starter.mAddingToTask).isTrue(); |
| 995 | } |
Louis Chang | 38430df | 2020-01-02 17:14:59 +0800 | [diff] [blame] | 996 | |
| 997 | @Test |
| 998 | public void testTargetStackInSplitScreen() { |
| 999 | final ActivityStarter starter = |
| 1000 | prepareStarter(FLAG_ACTIVITY_LAUNCH_ADJACENT, false /* mockGetLaunchStack */); |
| 1001 | final ActivityRecord top = new ActivityBuilder(mService).setCreateTask(true).build(); |
| 1002 | final ActivityOptions options = ActivityOptions.makeBasic(); |
| 1003 | final ActivityRecord[] outActivity = new ActivityRecord[1]; |
| 1004 | |
| 1005 | // Activity must not land on split-screen stack if currently not in split-screen mode. |
| 1006 | starter.setActivityOptions(options.toBundle()) |
| 1007 | .setReason("testWindowingModeOptionsLaunchAdjacent") |
| 1008 | .setOutActivity(outActivity).execute(); |
| 1009 | assertThat(outActivity[0].inSplitScreenWindowingMode()).isFalse(); |
| 1010 | |
| 1011 | // Move activity to split-screen-primary stack and make sure it has the focus. |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 1012 | TestSplitOrganizer splitOrg = new TestSplitOrganizer(mService, top.getDisplayId()); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 1013 | top.getRootTask().reparent(splitOrg.mPrimary, POSITION_BOTTOM); |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 1014 | top.getRootTask().moveToFront("testWindowingModeOptionsLaunchAdjacent"); |
Louis Chang | 38430df | 2020-01-02 17:14:59 +0800 | [diff] [blame] | 1015 | |
| 1016 | // Activity must landed on split-screen-secondary when launch adjacent. |
| 1017 | starter.setActivityOptions(options.toBundle()) |
| 1018 | .setReason("testWindowingModeOptionsLaunchAdjacent") |
| 1019 | .setOutActivity(outActivity).execute(); |
| 1020 | assertThat(outActivity[0].inSplitScreenSecondaryWindowingMode()).isTrue(); |
| 1021 | } |
Winson Chung | f45dd9f | 2019-10-11 15:07:47 -0700 | [diff] [blame] | 1022 | |
| 1023 | @Test |
| 1024 | public void testActivityStart_expectAddedToRecentTask() { |
| 1025 | RecentTasks recentTasks = mock(RecentTasks.class); |
| 1026 | mService.mStackSupervisor.setRecentTasks(recentTasks); |
| 1027 | doReturn(true).when(recentTasks).isCallerRecents(anyInt()); |
| 1028 | |
| 1029 | final ActivityStarter starter = prepareStarter(0 /* flags */); |
| 1030 | |
| 1031 | starter.setReason("testAddToTaskListOnActivityStart") |
| 1032 | .execute(); |
| 1033 | |
| 1034 | verify(recentTasks, times(1)).add(any()); |
| 1035 | } |
Diego Vela | 671c007 | 2020-03-25 09:39:26 -0700 | [diff] [blame] | 1036 | |
| 1037 | @Test |
| 1038 | public void testStartActivityInner_allSplitScreenPrimaryActivitiesVisible() { |
| 1039 | // Given |
| 1040 | final ActivityStarter starter = prepareStarter(0, false); |
| 1041 | |
| 1042 | starter.setReason("testAllSplitScreenPrimaryActivitiesAreResumed"); |
| 1043 | |
| 1044 | final ActivityRecord targetRecord = new ActivityBuilder(mService).build(); |
| 1045 | targetRecord.setFocusable(false); |
| 1046 | targetRecord.setVisibility(false); |
| 1047 | final ActivityRecord sourceRecord = new ActivityBuilder(mService).build(); |
| 1048 | |
| 1049 | final ActivityStack stack = spy( |
| 1050 | mRootWindowContainer.getDefaultTaskDisplayArea() |
| 1051 | .createStack(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, |
| 1052 | /* onTop */true)); |
| 1053 | |
| 1054 | stack.addChild(targetRecord); |
| 1055 | |
| 1056 | doReturn(stack).when(mRootWindowContainer) |
| 1057 | .getLaunchStack(any(), any(), any(), anyBoolean(), any(), anyInt(), anyInt()); |
| 1058 | |
| 1059 | starter.mStartActivity = new ActivityBuilder(mService).build(); |
| 1060 | |
| 1061 | // When |
| 1062 | starter.startActivityInner( |
| 1063 | /* r */targetRecord, |
| 1064 | /* sourceRecord */ sourceRecord, |
| 1065 | /* voiceSession */null, |
| 1066 | /* voiceInteractor */ null, |
| 1067 | /* startFlags */ 0, |
| 1068 | /* doResume */true, |
| 1069 | /* options */null, |
| 1070 | /* inTask */null, |
| 1071 | /* restrictedBgActivity */false); |
| 1072 | |
| 1073 | // Then |
| 1074 | verify(stack).ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
| 1075 | verify(targetRecord).makeVisibleIfNeeded(null, true); |
| 1076 | assertTrue(targetRecord.mVisibleRequested); |
| 1077 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1078 | } |