Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 1 | /* |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 2 | * Copyright (C) 2018 The Android Open Source Project |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [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 |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 15 | */ |
| 16 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 18 | |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 19 | import static android.app.ActivityTaskManager.INVALID_TASK_ID; |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 21 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
| 22 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Bryce Lee | 1a990e5 | 2018-04-23 10:54:11 -0700 | [diff] [blame] | 23 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
| 24 | import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME; |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 25 | import static android.content.pm.ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY; |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 26 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; |
| 27 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; |
| 28 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Riddle Hsu | 88e3c873 | 2019-02-18 19:15:12 +0800 | [diff] [blame] | 29 | import static android.util.DisplayMetrics.DENSITY_DEFAULT; |
Garfield Tan | a3f1903 | 2019-11-19 18:04:50 -0800 | [diff] [blame] | 30 | import static android.view.IWindowManager.FIXED_TO_USER_ROTATION_ENABLED; |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 31 | import static android.view.Surface.ROTATION_0; |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 32 | import static android.view.Surface.ROTATION_90; |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 33 | |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 34 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer; |
| 35 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 36 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.eq; |
| 37 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; |
| 38 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 39 | import static com.android.server.policy.WindowManagerPolicy.USER_ROTATION_FREE; |
Bryce Lee | 1a990e5 | 2018-04-23 10:54:11 -0700 | [diff] [blame] | 40 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 41 | import static com.google.common.truth.Truth.assertThat; |
| 42 | |
Riddle Hsu | 2f9acd2 | 2018-11-06 23:44:43 +0800 | [diff] [blame] | 43 | import static org.hamcrest.Matchers.not; |
| 44 | import static org.hamcrest.Matchers.sameInstance; |
Garfield Tan | 367b35a | 2017-12-13 12:16:21 -0800 | [diff] [blame] | 45 | import static org.junit.Assert.assertEquals; |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 46 | import static org.junit.Assert.assertFalse; |
Evan Rosky | 7021370 | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 47 | import static org.junit.Assert.assertNotEquals; |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 48 | import static org.junit.Assert.assertNotNull; |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 49 | import static org.junit.Assert.assertNull; |
Riddle Hsu | 2f9acd2 | 2018-11-06 23:44:43 +0800 | [diff] [blame] | 50 | import static org.junit.Assert.assertThat; |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 51 | import static org.junit.Assert.assertTrue; |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 52 | import static org.mockito.ArgumentMatchers.any; |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 53 | import static org.mockito.ArgumentMatchers.anyInt; |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 54 | import static org.mockito.Mockito.mock; |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 55 | |
| 56 | import android.app.ActivityManager; |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 57 | import android.app.TaskInfo; |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 58 | import android.content.ComponentName; |
| 59 | import android.content.Intent; |
| 60 | import android.content.pm.ActivityInfo; |
Louis Chang | 96c7b83 | 2018-12-27 09:27:53 +0800 | [diff] [blame] | 61 | import android.content.pm.ApplicationInfo; |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 62 | import android.content.res.Configuration; |
Garfield Tan | 367b35a | 2017-12-13 12:16:21 -0800 | [diff] [blame] | 63 | import android.graphics.Rect; |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 64 | import android.os.IBinder; |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 65 | import android.platform.test.annotations.Presubmit; |
| 66 | import android.service.voice.IVoiceInteractionSession; |
Evan Rosky | 60dba2f | 2019-02-01 10:58:38 -0800 | [diff] [blame] | 67 | import android.util.DisplayMetrics; |
Garfield Tan | 367b35a | 2017-12-13 12:16:21 -0800 | [diff] [blame] | 68 | import android.util.Xml; |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 69 | import android.view.DisplayInfo; |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 70 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 71 | import androidx.test.filters.FlakyTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 72 | import androidx.test.filters.MediumTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 73 | |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 74 | import com.android.internal.app.IVoiceInteractor; |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 75 | import com.android.server.wm.Task.TaskFactory; |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 76 | import com.android.server.wm.utils.WmDisplayCutout; |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 77 | |
| 78 | import org.junit.Before; |
| 79 | import org.junit.Test; |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 80 | import org.junit.runner.RunWith; |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 81 | import org.xmlpull.v1.XmlPullParser; |
| 82 | import org.xmlpull.v1.XmlPullParserException; |
Garfield Tan | 367b35a | 2017-12-13 12:16:21 -0800 | [diff] [blame] | 83 | import org.xmlpull.v1.XmlSerializer; |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 84 | |
Tadashi G. Takaoka | 88df5c3 | 2018-11-21 16:33:57 +0900 | [diff] [blame] | 85 | import java.io.ByteArrayInputStream; |
| 86 | import java.io.ByteArrayOutputStream; |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 87 | import java.io.IOException; |
Tadashi G. Takaoka | 88df5c3 | 2018-11-21 16:33:57 +0900 | [diff] [blame] | 88 | import java.io.InputStreamReader; |
Garfield Tan | 367b35a | 2017-12-13 12:16:21 -0800 | [diff] [blame] | 89 | import java.io.Reader; |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 90 | |
| 91 | /** |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 92 | * Tests for exercising {@link Task}. |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 93 | * |
| 94 | * Build/Install/Run: |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 95 | * atest WmTests:TaskRecordTests |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 96 | */ |
| 97 | @MediumTest |
| 98 | @Presubmit |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 99 | @RunWith(WindowTestRunner.class) |
Garfield Tan | 367b35a | 2017-12-13 12:16:21 -0800 | [diff] [blame] | 100 | public class TaskRecordTests extends ActivityTestsBase { |
| 101 | |
| 102 | private static final String TASK_TAG = "task"; |
| 103 | |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 104 | private Rect mParentBounds; |
| 105 | |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 106 | @Before |
| 107 | public void setUp() throws Exception { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 108 | Task.setTaskFactory(null); |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 109 | mParentBounds = new Rect(10 /*left*/, 30 /*top*/, 80 /*right*/, 60 /*bottom*/); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 110 | removeGlobalMinSizeRestriction(); |
Garfield Tan | 367b35a | 2017-12-13 12:16:21 -0800 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | @Test |
| 114 | public void testRestoreWindowedTask() throws Exception { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 115 | final Task expected = createTask(64); |
Garfield Tan | 367b35a | 2017-12-13 12:16:21 -0800 | [diff] [blame] | 116 | expected.mLastNonFullscreenBounds = new Rect(50, 50, 100, 100); |
| 117 | |
Tadashi G. Takaoka | 88df5c3 | 2018-11-21 16:33:57 +0900 | [diff] [blame] | 118 | final byte[] serializedBytes = serializeToBytes(expected); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 119 | final Task actual = restoreFromBytes(serializedBytes); |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 120 | assertEquals(expected.mTaskId, actual.mTaskId); |
Tadashi G. Takaoka | 88df5c3 | 2018-11-21 16:33:57 +0900 | [diff] [blame] | 121 | assertEquals(expected.mLastNonFullscreenBounds, actual.mLastNonFullscreenBounds); |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | @Test |
| 125 | public void testDefaultTaskFactoryNotNull() throws Exception { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 126 | assertNotNull(Task.getTaskFactory()); |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 127 | } |
| 128 | |
Riddle Hsu | 2f9acd2 | 2018-11-06 23:44:43 +0800 | [diff] [blame] | 129 | /** Ensure we have no chance to modify the original intent. */ |
| 130 | @Test |
| 131 | public void testCopyBaseIntentForTaskInfo() { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 132 | final Task task = createTask(1); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 133 | task.setTaskDescription(new ActivityManager.TaskDescription()); |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 134 | final TaskInfo info = task.getTaskInfo(); |
Riddle Hsu | 2f9acd2 | 2018-11-06 23:44:43 +0800 | [diff] [blame] | 135 | |
| 136 | // The intent of info should be a copy so assert that they are different instances. |
| 137 | assertThat(info.baseIntent, not(sameInstance(task.getBaseIntent()))); |
| 138 | } |
| 139 | |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 140 | @Test |
| 141 | public void testCreateTestRecordUsingCustomizedFactory() throws Exception { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 142 | TestTaskFactory factory = new TestTaskFactory(); |
| 143 | Task.setTaskFactory(factory); |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 144 | |
| 145 | assertFalse(factory.mCreated); |
| 146 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 147 | Task.create(null, 0, null, null, null, null); |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 148 | |
| 149 | assertTrue(factory.mCreated); |
| 150 | } |
| 151 | |
Bryce Lee | 1a990e5 | 2018-04-23 10:54:11 -0700 | [diff] [blame] | 152 | @Test |
| 153 | public void testReturnsToHomeStack() throws Exception { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 154 | final Task task = createTask(1); |
Bryce Lee | 1a990e5 | 2018-04-23 10:54:11 -0700 | [diff] [blame] | 155 | assertFalse(task.returnsToHomeStack()); |
| 156 | task.intent = null; |
| 157 | assertFalse(task.returnsToHomeStack()); |
| 158 | task.intent = new Intent(); |
| 159 | assertFalse(task.returnsToHomeStack()); |
| 160 | task.intent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME); |
| 161 | assertTrue(task.returnsToHomeStack()); |
| 162 | } |
| 163 | |
Evan Rosky | 7021370 | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 164 | /** Ensures that empty bounds cause appBounds to inherit from parent. */ |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 165 | @Test |
| 166 | public void testAppBounds_EmptyBounds() { |
| 167 | final Rect emptyBounds = new Rect(); |
| 168 | testStackBoundsConfiguration(WINDOWING_MODE_FULLSCREEN, mParentBounds, emptyBounds, |
Evan Rosky | 7021370 | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 169 | mParentBounds); |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | /** Ensures that bounds on freeform stacks are not clipped. */ |
| 173 | @Test |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 174 | @FlakyTest(bugId = 137879065) |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 175 | public void testAppBounds_FreeFormBounds() { |
| 176 | final Rect freeFormBounds = new Rect(mParentBounds); |
| 177 | freeFormBounds.offset(10, 10); |
| 178 | testStackBoundsConfiguration(WINDOWING_MODE_FREEFORM, mParentBounds, freeFormBounds, |
| 179 | freeFormBounds); |
| 180 | } |
| 181 | |
| 182 | /** Ensures that fully contained bounds are not clipped. */ |
| 183 | @Test |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 184 | @FlakyTest(bugId = 137879065) |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 185 | public void testAppBounds_ContainedBounds() { |
| 186 | final Rect insetBounds = new Rect(mParentBounds); |
| 187 | insetBounds.inset(5, 5, 5, 5); |
| 188 | testStackBoundsConfiguration( |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 189 | WINDOWING_MODE_FREEFORM, mParentBounds, insetBounds, insetBounds); |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 190 | } |
| 191 | |
Evan Rosky | 60dba2f | 2019-02-01 10:58:38 -0800 | [diff] [blame] | 192 | @Test |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 193 | @FlakyTest(bugId = 137879065) |
Evan Rosky | 60dba2f | 2019-02-01 10:58:38 -0800 | [diff] [blame] | 194 | public void testFitWithinBounds() { |
| 195 | final Rect parentBounds = new Rect(10, 10, 200, 200); |
| 196 | ActivityDisplay display = mService.mRootActivityContainer.getDefaultDisplay(); |
| 197 | ActivityStack stack = display.createStack(WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, |
| 198 | true /* onTop */); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 199 | Task task = new TaskBuilder(mSupervisor).setStack(stack).build(); |
Evan Rosky | 60dba2f | 2019-02-01 10:58:38 -0800 | [diff] [blame] | 200 | final Configuration parentConfig = stack.getConfiguration(); |
| 201 | parentConfig.windowConfiguration.setBounds(parentBounds); |
| 202 | parentConfig.densityDpi = DisplayMetrics.DENSITY_DEFAULT; |
| 203 | |
| 204 | // check top and left |
| 205 | Rect reqBounds = new Rect(-190, -190, 0, 0); |
| 206 | task.setBounds(reqBounds); |
| 207 | // Make sure part of it is exposed |
| 208 | assertTrue(task.getBounds().right > parentBounds.left); |
| 209 | assertTrue(task.getBounds().bottom > parentBounds.top); |
| 210 | // Should still be more-or-less in that corner |
| 211 | assertTrue(task.getBounds().left <= parentBounds.left); |
| 212 | assertTrue(task.getBounds().top <= parentBounds.top); |
| 213 | |
| 214 | assertEquals(reqBounds.width(), task.getBounds().width()); |
| 215 | assertEquals(reqBounds.height(), task.getBounds().height()); |
| 216 | |
| 217 | // check bottom and right |
| 218 | reqBounds = new Rect(210, 210, 400, 400); |
| 219 | task.setBounds(reqBounds); |
| 220 | // Make sure part of it is exposed |
| 221 | assertTrue(task.getBounds().left < parentBounds.right); |
| 222 | assertTrue(task.getBounds().top < parentBounds.bottom); |
| 223 | // Should still be more-or-less in that corner |
| 224 | assertTrue(task.getBounds().right >= parentBounds.right); |
| 225 | assertTrue(task.getBounds().bottom >= parentBounds.bottom); |
| 226 | |
| 227 | assertEquals(reqBounds.width(), task.getBounds().width()); |
| 228 | assertEquals(reqBounds.height(), task.getBounds().height()); |
| 229 | } |
| 230 | |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 231 | /** Tests that the task bounds adjust properly to changes between FULLSCREEN and FREEFORM */ |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 232 | @Test |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 233 | @FlakyTest(bugId = 137879065) |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 234 | public void testBoundsOnModeChangeFreeformToFullscreen() { |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 235 | ActivityDisplay display = mService.mRootActivityContainer.getDefaultDisplay(); |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 236 | ActivityStack stack = new StackBuilder(mRootActivityContainer).setDisplay(display) |
| 237 | .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 238 | Task task = stack.getBottomMostTask(); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 239 | task.getRootActivity().setOrientation(SCREEN_ORIENTATION_UNSPECIFIED); |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 240 | DisplayInfo info = new DisplayInfo(); |
| 241 | display.mDisplay.getDisplayInfo(info); |
| 242 | final Rect fullScreenBounds = new Rect(0, 0, info.logicalWidth, info.logicalHeight); |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 243 | final Rect freeformBounds = new Rect(fullScreenBounds); |
| 244 | freeformBounds.inset((int) (freeformBounds.width() * 0.2), |
| 245 | (int) (freeformBounds.height() * 0.2)); |
| 246 | task.setBounds(freeformBounds); |
| 247 | |
| 248 | assertEquals(freeformBounds, task.getBounds()); |
| 249 | |
| 250 | // FULLSCREEN inherits bounds |
| 251 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 252 | assertEquals(fullScreenBounds, task.getBounds()); |
| 253 | assertEquals(freeformBounds, task.mLastNonFullscreenBounds); |
| 254 | |
| 255 | // FREEFORM restores bounds |
| 256 | stack.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 257 | assertEquals(freeformBounds, task.getBounds()); |
| 258 | } |
| 259 | |
| 260 | /** |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 261 | * Tests that a task with forced orientation has orientation-consistent bounds within the |
| 262 | * parent. |
| 263 | */ |
| 264 | @Test |
| 265 | public void testFullscreenBoundsForcedOrientation() { |
| 266 | final Rect fullScreenBounds = new Rect(0, 0, 1920, 1080); |
| 267 | final Rect fullScreenBoundsPort = new Rect(0, 0, 1080, 1920); |
Evan Rosky | 4a51dbc0 | 2019-09-11 17:28:07 -0700 | [diff] [blame] | 268 | ActivityDisplay display = new TestActivityDisplay.Builder( |
| 269 | mService, fullScreenBounds.width(), fullScreenBounds.height()).build(); |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 270 | assertTrue(mRootActivityContainer.getActivityDisplay(display.mDisplayId) != null); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 271 | // Fix the display orientation to landscape which is the natural rotation (0) for the test |
| 272 | // display. |
| 273 | final DisplayRotation dr = display.mDisplayContent.getDisplayRotation(); |
| 274 | dr.setFixedToUserRotation(FIXED_TO_USER_ROTATION_ENABLED); |
| 275 | dr.setUserRotation(USER_ROTATION_FREE, ROTATION_0); |
| 276 | |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 277 | ActivityStack stack = new StackBuilder(mRootActivityContainer) |
| 278 | .setWindowingMode(WINDOWING_MODE_FULLSCREEN).setDisplay(display).build(); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 279 | Task task = stack.getBottomMostTask(); |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 280 | ActivityRecord root = task.getTopNonFinishingActivity(); |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 281 | |
| 282 | assertEquals(fullScreenBounds, task.getBounds()); |
| 283 | |
| 284 | // Setting app to fixed portrait fits within parent |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 285 | root.setRequestedOrientation(SCREEN_ORIENTATION_PORTRAIT); |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 286 | assertEquals(root, task.getRootActivity()); |
| 287 | assertEquals(SCREEN_ORIENTATION_PORTRAIT, task.getRootActivity().getOrientation()); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 288 | assertThat(task.getBounds().width()).isLessThan(task.getBounds().height()); |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 289 | assertEquals(fullScreenBounds.height(), task.getBounds().height()); |
| 290 | |
Evan Rosky | 130d94f | 2019-01-15 10:18:17 -0800 | [diff] [blame] | 291 | // Top activity gets used |
| 292 | ActivityRecord top = new ActivityBuilder(mService).setTask(task).setStack(stack).build(); |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 293 | assertEquals(top, task.getTopNonFinishingActivity()); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 294 | top.setRequestedOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
| 295 | assertThat(task.getBounds().width()).isGreaterThan(task.getBounds().height()); |
Evan Rosky | 130d94f | 2019-01-15 10:18:17 -0800 | [diff] [blame] | 296 | assertEquals(task.getBounds().width(), fullScreenBounds.width()); |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 297 | |
| 298 | // Setting app to unspecified restores |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 299 | top.setRequestedOrientation(SCREEN_ORIENTATION_UNSPECIFIED); |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 300 | assertEquals(fullScreenBounds, task.getBounds()); |
| 301 | |
| 302 | // Setting app to fixed landscape and changing display |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 303 | top.setRequestedOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
| 304 | // Fix the display orientation to portrait which is 90 degrees for the test display. |
| 305 | dr.setUserRotation(USER_ROTATION_FREE, ROTATION_90); |
| 306 | |
| 307 | assertThat(task.getBounds().width()).isGreaterThan(task.getBounds().height()); |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 308 | assertEquals(fullScreenBoundsPort.width(), task.getBounds().width()); |
| 309 | |
| 310 | // in FREEFORM, no constraint |
| 311 | final Rect freeformBounds = new Rect(display.getBounds()); |
| 312 | freeformBounds.inset((int) (freeformBounds.width() * 0.2), |
| 313 | (int) (freeformBounds.height() * 0.2)); |
| 314 | stack.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 315 | task.setBounds(freeformBounds); |
| 316 | assertEquals(freeformBounds, task.getBounds()); |
| 317 | |
| 318 | // FULLSCREEN letterboxes bounds |
| 319 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 320 | assertThat(task.getBounds().width()).isGreaterThan(task.getBounds().height()); |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 321 | assertEquals(fullScreenBoundsPort.width(), task.getBounds().width()); |
| 322 | |
| 323 | // FREEFORM restores bounds as before |
| 324 | stack.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 325 | assertEquals(freeformBounds, task.getBounds()); |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 326 | } |
| 327 | |
Yunfan Chen | f93c06f | 2019-01-17 07:01:49 +0000 | [diff] [blame] | 328 | @Test |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 329 | public void testIgnoresForcedOrientationWhenParentHandles() { |
| 330 | final Rect fullScreenBounds = new Rect(0, 0, 1920, 1080); |
Evan Rosky | 4a51dbc0 | 2019-09-11 17:28:07 -0700 | [diff] [blame] | 331 | ActivityDisplay display = new TestActivityDisplay.Builder( |
| 332 | mService, fullScreenBounds.width(), fullScreenBounds.height()).build(); |
Yunfan Chen | f93c06f | 2019-01-17 07:01:49 +0000 | [diff] [blame] | 333 | |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 334 | display.getRequestedOverrideConfiguration().orientation = |
| 335 | Configuration.ORIENTATION_LANDSCAPE; |
| 336 | display.onRequestedOverrideConfigurationChanged( |
| 337 | display.getRequestedOverrideConfiguration()); |
| 338 | ActivityStack stack = new StackBuilder(mRootActivityContainer) |
Yunfan Chen | f93c06f | 2019-01-17 07:01:49 +0000 | [diff] [blame] | 339 | .setWindowingMode(WINDOWING_MODE_FULLSCREEN).setDisplay(display).build(); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 340 | Task task = stack.getBottomMostTask(); |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 341 | ActivityRecord root = task.getTopNonFinishingActivity(); |
Yunfan Chen | f93c06f | 2019-01-17 07:01:49 +0000 | [diff] [blame] | 342 | |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 343 | final WindowContainer parentWindowContainer = |
| 344 | new WindowContainer(mSystemServicesTestRule.getWindowManagerService()); |
| 345 | spyOn(parentWindowContainer); |
| 346 | parentWindowContainer.setBounds(fullScreenBounds); |
| 347 | doReturn(parentWindowContainer).when(task).getParent(); |
| 348 | doReturn(true).when(parentWindowContainer).handlesOrientationChangeFromDescendant(); |
Yunfan Chen | f93c06f | 2019-01-17 07:01:49 +0000 | [diff] [blame] | 349 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 350 | // Setting app to fixed portrait fits within parent, but Task shouldn't adjust the |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 351 | // bounds because its parent says it will handle it at a later time. |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 352 | root.setRequestedOrientation(SCREEN_ORIENTATION_PORTRAIT); |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 353 | assertEquals(root, task.getRootActivity()); |
| 354 | assertEquals(SCREEN_ORIENTATION_PORTRAIT, task.getRootActivity().getOrientation()); |
| 355 | assertEquals(fullScreenBounds, task.getBounds()); |
Yunfan Chen | f93c06f | 2019-01-17 07:01:49 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Riddle Hsu | 88e3c873 | 2019-02-18 19:15:12 +0800 | [diff] [blame] | 358 | @Test |
| 359 | public void testComputeConfigResourceOverrides() { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 360 | final Task task = new TaskBuilder(mSupervisor).build(); |
Riddle Hsu | 88e3c873 | 2019-02-18 19:15:12 +0800 | [diff] [blame] | 361 | final Configuration inOutConfig = new Configuration(); |
| 362 | final Configuration parentConfig = new Configuration(); |
| 363 | final int longSide = 1200; |
| 364 | final int shortSide = 600; |
| 365 | parentConfig.densityDpi = 400; |
| 366 | parentConfig.screenHeightDp = 200; // 200 * 400 / 160 = 500px |
| 367 | parentConfig.screenWidthDp = 100; // 100 * 400 / 160 = 250px |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 368 | parentConfig.windowConfiguration.setRotation(ROTATION_0); |
Riddle Hsu | 88e3c873 | 2019-02-18 19:15:12 +0800 | [diff] [blame] | 369 | |
| 370 | // Portrait bounds. |
| 371 | inOutConfig.windowConfiguration.getBounds().set(0, 0, shortSide, longSide); |
| 372 | // By default, the parent bounds should limit the existing input bounds. |
| 373 | task.computeConfigResourceOverrides(inOutConfig, parentConfig); |
| 374 | |
| 375 | assertEquals(parentConfig.screenHeightDp, inOutConfig.screenHeightDp); |
| 376 | assertEquals(parentConfig.screenWidthDp, inOutConfig.screenWidthDp); |
| 377 | assertEquals(Configuration.ORIENTATION_PORTRAIT, inOutConfig.orientation); |
| 378 | |
| 379 | inOutConfig.setToDefaults(); |
| 380 | // Landscape bounds. |
| 381 | inOutConfig.windowConfiguration.getBounds().set(0, 0, longSide, shortSide); |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 382 | |
| 383 | // Setup the display with a top stable inset. The later assertion will ensure the inset is |
| 384 | // excluded from screenHeightDp. |
| 385 | final int statusBarHeight = 100; |
| 386 | final DisplayContent displayContent = mock(DisplayContent.class); |
| 387 | final DisplayPolicy policy = mock(DisplayPolicy.class); |
| 388 | doAnswer(invocationOnMock -> { |
| 389 | final Rect insets = invocationOnMock.<Rect>getArgument(0); |
| 390 | insets.top = statusBarHeight; |
| 391 | return null; |
| 392 | }).when(policy).convertNonDecorInsetsToStableInsets(any(), eq(ROTATION_0)); |
| 393 | doReturn(policy).when(displayContent).getDisplayPolicy(); |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 394 | doReturn(mock(WmDisplayCutout.class)).when(displayContent) |
| 395 | .calculateDisplayCutoutForRotation(anyInt()); |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 396 | |
Riddle Hsu | 88e3c873 | 2019-02-18 19:15:12 +0800 | [diff] [blame] | 397 | // Without limiting to be inside the parent bounds, the out screen size should keep relative |
| 398 | // to the input bounds. |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 399 | final ActivityRecord.CompatDisplayInsets compatIntsets = |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 400 | new ActivityRecord.CompatDisplayInsets(displayContent, new Rect(0, 0, |
| 401 | displayContent.mBaseDisplayWidth, displayContent.mBaseDisplayHeight), |
| 402 | false); |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 403 | task.computeConfigResourceOverrides(inOutConfig, parentConfig, compatIntsets); |
Riddle Hsu | 88e3c873 | 2019-02-18 19:15:12 +0800 | [diff] [blame] | 404 | |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 405 | assertEquals((shortSide - statusBarHeight) * DENSITY_DEFAULT / parentConfig.densityDpi, |
Riddle Hsu | 88e3c873 | 2019-02-18 19:15:12 +0800 | [diff] [blame] | 406 | inOutConfig.screenHeightDp); |
| 407 | assertEquals(longSide * DENSITY_DEFAULT / parentConfig.densityDpi, |
| 408 | inOutConfig.screenWidthDp); |
| 409 | assertEquals(Configuration.ORIENTATION_LANDSCAPE, inOutConfig.orientation); |
| 410 | } |
| 411 | |
Evan Rosky | 7021370 | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 412 | @Test |
| 413 | public void testComputeNestedConfigResourceOverrides() { |
| 414 | final Task task = new TaskBuilder(mSupervisor).build(); |
| 415 | assertTrue(task.getResolvedOverrideBounds().isEmpty()); |
| 416 | int origScreenH = task.getConfiguration().screenHeightDp; |
| 417 | Configuration stackConfig = new Configuration(); |
| 418 | stackConfig.setTo(task.getStack().getRequestedOverrideConfiguration()); |
| 419 | stackConfig.windowConfiguration.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 420 | |
| 421 | // Set bounds on stack (not task) and verify that the task resource configuration changes |
| 422 | // despite it's override bounds being empty. |
| 423 | Rect bounds = new Rect(task.getStack().getBounds()); |
| 424 | bounds.bottom = (int) (bounds.bottom * 0.6f); |
| 425 | stackConfig.windowConfiguration.setBounds(bounds); |
| 426 | task.getStack().onRequestedOverrideConfigurationChanged(stackConfig); |
| 427 | assertNotEquals(origScreenH, task.getConfiguration().screenHeightDp); |
| 428 | } |
| 429 | |
Louis Chang | 96c7b83 | 2018-12-27 09:27:53 +0800 | [diff] [blame] | 430 | /** Ensures that the alias intent won't have target component resolved. */ |
| 431 | @Test |
| 432 | public void testTaskIntentActivityAlias() { |
Louis Chang | 23df1a6 | 2019-01-09 15:10:49 +0800 | [diff] [blame] | 433 | final String aliasClassName = DEFAULT_COMPONENT_PACKAGE_NAME + ".aliasActivity"; |
| 434 | final String targetClassName = DEFAULT_COMPONENT_PACKAGE_NAME + ".targetActivity"; |
| 435 | final ComponentName aliasComponent = |
| 436 | new ComponentName(DEFAULT_COMPONENT_PACKAGE_NAME, aliasClassName); |
| 437 | final ComponentName targetComponent = |
| 438 | new ComponentName(DEFAULT_COMPONENT_PACKAGE_NAME, targetClassName); |
| 439 | |
Louis Chang | 96c7b83 | 2018-12-27 09:27:53 +0800 | [diff] [blame] | 440 | final Intent intent = new Intent(); |
Louis Chang | 23df1a6 | 2019-01-09 15:10:49 +0800 | [diff] [blame] | 441 | intent.setComponent(aliasComponent); |
Louis Chang | 96c7b83 | 2018-12-27 09:27:53 +0800 | [diff] [blame] | 442 | final ActivityInfo info = new ActivityInfo(); |
| 443 | info.applicationInfo = new ApplicationInfo(); |
| 444 | info.packageName = DEFAULT_COMPONENT_PACKAGE_NAME; |
Louis Chang | 23df1a6 | 2019-01-09 15:10:49 +0800 | [diff] [blame] | 445 | info.targetActivity = targetClassName; |
Louis Chang | 96c7b83 | 2018-12-27 09:27:53 +0800 | [diff] [blame] | 446 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 447 | final Task task = Task.create(mService, 1 /* taskId */, info, intent, |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 448 | null /* taskDescription */, null /*stack*/); |
Louis Chang | 23df1a6 | 2019-01-09 15:10:49 +0800 | [diff] [blame] | 449 | assertEquals("The alias activity component should be saved in task intent.", aliasClassName, |
Louis Chang | 96c7b83 | 2018-12-27 09:27:53 +0800 | [diff] [blame] | 450 | task.intent.getComponent().getClassName()); |
Louis Chang | 23df1a6 | 2019-01-09 15:10:49 +0800 | [diff] [blame] | 451 | |
| 452 | ActivityRecord aliasActivity = new ActivityBuilder(mService).setComponent( |
| 453 | aliasComponent).setTargetActivity(targetClassName).build(); |
| 454 | assertEquals("Should be the same intent filter.", true, |
| 455 | task.isSameIntentFilter(aliasActivity)); |
| 456 | |
| 457 | ActivityRecord targetActivity = new ActivityBuilder(mService).setComponent( |
| 458 | targetComponent).build(); |
| 459 | assertEquals("Should be the same intent filter.", true, |
| 460 | task.isSameIntentFilter(targetActivity)); |
| 461 | |
| 462 | ActivityRecord defaultActivity = new ActivityBuilder(mService).build(); |
| 463 | assertEquals("Should not be the same intent filter.", false, |
| 464 | task.isSameIntentFilter(defaultActivity)); |
Louis Chang | 96c7b83 | 2018-12-27 09:27:53 +0800 | [diff] [blame] | 465 | } |
| 466 | |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 467 | /** Test that root activity index is reported correctly for several activities in the task. */ |
| 468 | @Test |
| 469 | public void testFindRootIndex() { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 470 | final Task task = getTestTask(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 471 | // Add an extra activity on top of the root one |
| 472 | new ActivityBuilder(mService).setTask(task).build(); |
| 473 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 474 | assertEquals("The root activity in the task must be reported.", task.getChildAt(0), |
| 475 | task.getRootActivity( |
| 476 | true /*ignoreRelinquishIdentity*/, true /*setToBottomIfNone*/)); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /** |
| 480 | * Test that root activity index is reported correctly for several activities in the task when |
| 481 | * the activities on the bottom are finishing. |
| 482 | */ |
| 483 | @Test |
| 484 | public void testFindRootIndex_finishing() { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 485 | final Task task = getTestTask(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 486 | // Add extra two activities and mark the two on the bottom as finishing. |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 487 | final ActivityRecord activity0 = task.getBottomMostActivity(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 488 | activity0.finishing = true; |
| 489 | final ActivityRecord activity1 = new ActivityBuilder(mService).setTask(task).build(); |
| 490 | activity1.finishing = true; |
| 491 | new ActivityBuilder(mService).setTask(task).build(); |
| 492 | |
| 493 | assertEquals("The first non-finishing activity in the task must be reported.", |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 494 | task.getChildAt(2), task.getRootActivity( |
| 495 | true /*ignoreRelinquishIdentity*/, true /*setToBottomIfNone*/)); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | /** |
| 499 | * Test that root activity index is reported correctly for several activities in the task when |
| 500 | * looking for the 'effective root'. |
| 501 | */ |
| 502 | @Test |
| 503 | public void testFindRootIndex_effectiveRoot() { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 504 | final Task task = getTestTask(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 505 | // Add an extra activity on top of the root one |
| 506 | new ActivityBuilder(mService).setTask(task).build(); |
| 507 | |
| 508 | assertEquals("The root activity in the task must be reported.", |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 509 | task.getChildAt(0), task.getRootActivity( |
| 510 | false /*ignoreRelinquishIdentity*/, true /*setToBottomIfNone*/)); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | /** |
| 514 | * Test that root activity index is reported correctly when looking for the 'effective root' in |
| 515 | * case when bottom activities are relinquishing task identity or finishing. |
| 516 | */ |
| 517 | @Test |
| 518 | public void testFindRootIndex_effectiveRoot_finishingAndRelinquishing() { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 519 | final Task task = getTestTask(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 520 | // Add extra two activities. Mark the one on the bottom with "relinquishTaskIdentity" and |
| 521 | // one above as finishing. |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 522 | final ActivityRecord activity0 = task.getBottomMostActivity(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 523 | activity0.info.flags |= FLAG_RELINQUISH_TASK_IDENTITY; |
| 524 | final ActivityRecord activity1 = new ActivityBuilder(mService).setTask(task).build(); |
| 525 | activity1.finishing = true; |
| 526 | new ActivityBuilder(mService).setTask(task).build(); |
| 527 | |
| 528 | assertEquals("The first non-finishing activity and non-relinquishing task identity " |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 529 | + "must be reported.", task.getChildAt(2), task.getRootActivity( |
| 530 | false /*ignoreRelinquishIdentity*/, true /*setToBottomIfNone*/)); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | /** |
| 534 | * Test that root activity index is reported correctly when looking for the 'effective root' |
| 535 | * for the case when there is only a single activity that also has relinquishTaskIdentity set. |
| 536 | */ |
| 537 | @Test |
| 538 | public void testFindRootIndex_effectiveRoot_relinquishingAndSingleActivity() { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 539 | final Task task = getTestTask(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 540 | // Set relinquishTaskIdentity for the only activity in the task |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 541 | task.getBottomMostActivity().info.flags |= FLAG_RELINQUISH_TASK_IDENTITY; |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 542 | |
| 543 | assertEquals("The root activity in the task must be reported.", |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 544 | task.getChildAt(0), task.getRootActivity( |
| 545 | false /*ignoreRelinquishIdentity*/, true /*setToBottomIfNone*/)); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | /** |
| 549 | * Test that the topmost activity index is reported correctly when looking for the |
| 550 | * 'effective root' for the case when all activities have relinquishTaskIdentity set. |
| 551 | */ |
| 552 | @Test |
| 553 | public void testFindRootIndex_effectiveRoot_relinquishingMultipleActivities() { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 554 | final Task task = getTestTask(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 555 | // Set relinquishTaskIdentity for all activities in the task |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 556 | final ActivityRecord activity0 = task.getBottomMostActivity(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 557 | activity0.info.flags |= FLAG_RELINQUISH_TASK_IDENTITY; |
| 558 | final ActivityRecord activity1 = new ActivityBuilder(mService).setTask(task).build(); |
| 559 | activity1.info.flags |= FLAG_RELINQUISH_TASK_IDENTITY; |
| 560 | |
| 561 | assertEquals("The topmost activity in the task must be reported.", |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 562 | task.getChildAt(task.getChildCount() - 1), task.getRootActivity( |
| 563 | false /*ignoreRelinquishIdentity*/, true /*setToBottomIfNone*/)); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 566 | /** Test that bottom-most activity is reported in {@link Task#getRootActivity()}. */ |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 567 | @Test |
| 568 | public void testGetRootActivity() { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 569 | final Task task = getTestTask(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 570 | // Add an extra activity on top of the root one |
| 571 | new ActivityBuilder(mService).setTask(task).build(); |
| 572 | |
| 573 | assertEquals("The root activity in the task must be reported.", |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 574 | task.getBottomMostActivity(), task.getRootActivity()); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | /** |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 578 | * Test that first non-finishing activity is reported in {@link Task#getRootActivity()}. |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 579 | */ |
| 580 | @Test |
| 581 | public void testGetRootActivity_finishing() { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 582 | final Task task = getTestTask(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 583 | // Add an extra activity on top of the root one |
| 584 | new ActivityBuilder(mService).setTask(task).build(); |
| 585 | // Mark the root as finishing |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 586 | task.getBottomMostActivity().finishing = true; |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 587 | |
| 588 | assertEquals("The first non-finishing activity in the task must be reported.", |
| 589 | task.getChildAt(1), task.getRootActivity()); |
| 590 | } |
| 591 | |
| 592 | /** |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 593 | * Test that relinquishTaskIdentity flag is ignored in {@link Task#getRootActivity()}. |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 594 | */ |
| 595 | @Test |
| 596 | public void testGetRootActivity_relinquishTaskIdentity() { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 597 | final Task task = getTestTask(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 598 | // Mark the bottom-most activity with FLAG_RELINQUISH_TASK_IDENTITY. |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 599 | final ActivityRecord activity0 = task.getBottomMostActivity(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 600 | activity0.info.flags |= FLAG_RELINQUISH_TASK_IDENTITY; |
| 601 | // Add an extra activity on top of the root one. |
| 602 | new ActivityBuilder(mService).setTask(task).build(); |
| 603 | |
| 604 | assertEquals("The root activity in the task must be reported.", |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 605 | task.getBottomMostActivity(), task.getRootActivity()); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | /** |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 609 | * Test that no activity is reported in {@link Task#getRootActivity()} when all activities |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 610 | * in the task are finishing. |
| 611 | */ |
| 612 | @Test |
| 613 | public void testGetRootActivity_allFinishing() { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 614 | final Task task = getTestTask(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 615 | // Mark the bottom-most activity as finishing. |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 616 | final ActivityRecord activity0 = task.getBottomMostActivity(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 617 | activity0.finishing = true; |
| 618 | // Add an extra activity on top of the root one and mark it as finishing |
| 619 | final ActivityRecord activity1 = new ActivityBuilder(mService).setTask(task).build(); |
| 620 | activity1.finishing = true; |
| 621 | |
| 622 | assertNull("No activity must be reported if all are finishing", task.getRootActivity()); |
| 623 | } |
| 624 | |
| 625 | /** |
| 626 | * Test that first non-finishing activity is the root of task. |
| 627 | */ |
| 628 | @Test |
| 629 | public void testIsRootActivity() { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 630 | final Task task = getTestTask(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 631 | // Mark the bottom-most activity as finishing. |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 632 | final ActivityRecord activity0 = task.getBottomMostActivity(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 633 | activity0.finishing = true; |
| 634 | // Add an extra activity on top of the root one. |
| 635 | final ActivityRecord activity1 = new ActivityBuilder(mService).setTask(task).build(); |
| 636 | |
| 637 | assertFalse("Finishing activity must not be the root of task", activity0.isRootOfTask()); |
| 638 | assertTrue("Non-finishing activity must be the root of task", activity1.isRootOfTask()); |
| 639 | } |
| 640 | |
| 641 | /** |
| 642 | * Test that if all activities in the task are finishing, then the one on the bottom is the |
| 643 | * root of task. |
| 644 | */ |
| 645 | @Test |
| 646 | public void testIsRootActivity_allFinishing() { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 647 | final Task task = getTestTask(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 648 | // Mark the bottom-most activity as finishing. |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 649 | final ActivityRecord activity0 = task.getBottomMostActivity(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 650 | activity0.finishing = true; |
| 651 | // Add an extra activity on top of the root one and mark it as finishing |
| 652 | final ActivityRecord activity1 = new ActivityBuilder(mService).setTask(task).build(); |
| 653 | activity1.finishing = true; |
| 654 | |
| 655 | assertTrue("Bottom activity must be the root of task", activity0.isRootOfTask()); |
| 656 | assertFalse("Finishing activity on top must not be the root of task", |
| 657 | activity1.isRootOfTask()); |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * Test {@link ActivityRecord#getTaskForActivityLocked(IBinder, boolean)}. |
| 662 | */ |
| 663 | @Test |
| 664 | public void testGetTaskForActivity() { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 665 | final Task task0 = getTestTask(); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 666 | final ActivityRecord activity0 = task0.getBottomMostActivity(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 667 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 668 | final Task task1 = getTestTask(); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 669 | final ActivityRecord activity1 = task1.getBottomMostActivity(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 670 | |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 671 | assertEquals(task0.mTaskId, |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 672 | ActivityRecord.getTaskForActivityLocked(activity0.appToken, false /* onlyRoot */)); |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 673 | assertEquals(task1.mTaskId, |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 674 | ActivityRecord.getTaskForActivityLocked(activity1.appToken, false /* onlyRoot */)); |
| 675 | } |
| 676 | |
| 677 | /** |
| 678 | * Test {@link ActivityRecord#getTaskForActivityLocked(IBinder, boolean)} with finishing |
| 679 | * activity. |
| 680 | */ |
| 681 | @Test |
| 682 | public void testGetTaskForActivity_onlyRoot_finishing() { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 683 | final Task task = getTestTask(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 684 | // Make the current root activity finishing |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 685 | final ActivityRecord activity0 = task.getBottomMostActivity(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 686 | activity0.finishing = true; |
| 687 | // Add an extra activity on top - this will be the new root |
| 688 | final ActivityRecord activity1 = new ActivityBuilder(mService).setTask(task).build(); |
| 689 | // Add one more on top |
| 690 | final ActivityRecord activity2 = new ActivityBuilder(mService).setTask(task).build(); |
| 691 | |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 692 | assertEquals(task.mTaskId, |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 693 | ActivityRecord.getTaskForActivityLocked(activity0.appToken, true /* onlyRoot */)); |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 694 | assertEquals(task.mTaskId, |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 695 | ActivityRecord.getTaskForActivityLocked(activity1.appToken, true /* onlyRoot */)); |
| 696 | assertEquals("No task must be reported for activity that is above root", INVALID_TASK_ID, |
| 697 | ActivityRecord.getTaskForActivityLocked(activity2.appToken, true /* onlyRoot */)); |
| 698 | } |
| 699 | |
| 700 | /** |
| 701 | * Test {@link ActivityRecord#getTaskForActivityLocked(IBinder, boolean)} with activity that |
| 702 | * relinquishes task identity. |
| 703 | */ |
| 704 | @Test |
| 705 | public void testGetTaskForActivity_onlyRoot_relinquishTaskIdentity() { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 706 | final Task task = getTestTask(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 707 | // Make the current root activity relinquish task identity |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 708 | final ActivityRecord activity0 = task.getBottomMostActivity(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 709 | activity0.info.flags |= FLAG_RELINQUISH_TASK_IDENTITY; |
| 710 | // Add an extra activity on top - this will be the new root |
| 711 | final ActivityRecord activity1 = new ActivityBuilder(mService).setTask(task).build(); |
| 712 | // Add one more on top |
| 713 | final ActivityRecord activity2 = new ActivityBuilder(mService).setTask(task).build(); |
| 714 | |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 715 | assertEquals(task.mTaskId, |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 716 | ActivityRecord.getTaskForActivityLocked(activity0.appToken, true /* onlyRoot */)); |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 717 | assertEquals(task.mTaskId, |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 718 | ActivityRecord.getTaskForActivityLocked(activity1.appToken, true /* onlyRoot */)); |
| 719 | assertEquals("No task must be reported for activity that is above root", INVALID_TASK_ID, |
| 720 | ActivityRecord.getTaskForActivityLocked(activity2.appToken, true /* onlyRoot */)); |
| 721 | } |
| 722 | |
| 723 | /** |
| 724 | * Test {@link ActivityRecord#getTaskForActivityLocked(IBinder, boolean)} allowing non-root |
| 725 | * entries. |
| 726 | */ |
| 727 | @Test |
| 728 | public void testGetTaskForActivity_notOnlyRoot() { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 729 | final Task task = getTestTask(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 730 | // Mark the bottom-most activity as finishing. |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 731 | final ActivityRecord activity0 = task.getBottomMostActivity(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 732 | activity0.finishing = true; |
| 733 | |
| 734 | // Add an extra activity on top of the root one and make it relinquish task identity |
| 735 | final ActivityRecord activity1 = new ActivityBuilder(mService).setTask(task).build(); |
| 736 | activity1.info.flags |= FLAG_RELINQUISH_TASK_IDENTITY; |
| 737 | |
| 738 | // Add one more activity on top |
| 739 | final ActivityRecord activity2 = new ActivityBuilder(mService).setTask(task).build(); |
| 740 | |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 741 | assertEquals(task.mTaskId, |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 742 | ActivityRecord.getTaskForActivityLocked(activity0.appToken, false /* onlyRoot */)); |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 743 | assertEquals(task.mTaskId, |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 744 | ActivityRecord.getTaskForActivityLocked(activity1.appToken, false /* onlyRoot */)); |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 745 | assertEquals(task.mTaskId, |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 746 | ActivityRecord.getTaskForActivityLocked(activity2.appToken, false /* onlyRoot */)); |
| 747 | } |
| 748 | |
| 749 | /** |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 750 | * Test {@link Task#updateEffectiveIntent()}. |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 751 | */ |
| 752 | @Test |
| 753 | public void testUpdateEffectiveIntent() { |
| 754 | // Test simple case with a single activity. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 755 | final Task task = getTestTask(); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 756 | final ActivityRecord activity0 = task.getBottomMostActivity(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 757 | |
| 758 | spyOn(task); |
| 759 | task.updateEffectiveIntent(); |
| 760 | verify(task).setIntent(eq(activity0)); |
| 761 | } |
| 762 | |
| 763 | /** |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 764 | * Test {@link Task#updateEffectiveIntent()} with root activity marked as finishing. This |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 765 | * should make the task use the second activity when updating the intent. |
| 766 | */ |
| 767 | @Test |
| 768 | public void testUpdateEffectiveIntent_rootFinishing() { |
| 769 | // Test simple case with a single activity. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 770 | final Task task = getTestTask(); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 771 | final ActivityRecord activity0 = task.getBottomMostActivity(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 772 | // Mark the bottom-most activity as finishing. |
| 773 | activity0.finishing = true; |
| 774 | // Add an extra activity on top of the root one |
| 775 | final ActivityRecord activity1 = new ActivityBuilder(mService).setTask(task).build(); |
| 776 | |
| 777 | spyOn(task); |
| 778 | task.updateEffectiveIntent(); |
| 779 | verify(task).setIntent(eq(activity1)); |
| 780 | } |
| 781 | |
| 782 | /** |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 783 | * Test {@link Task#updateEffectiveIntent()} when all activities are finishing or |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 784 | * relinquishing task identity. In this case the root activity should still be used when |
| 785 | * updating the intent (legacy behavior). |
| 786 | */ |
| 787 | @Test |
| 788 | public void testUpdateEffectiveIntent_allFinishing() { |
| 789 | // Test simple case with a single activity. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 790 | final Task task = getTestTask(); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 791 | final ActivityRecord activity0 = task.getBottomMostActivity(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 792 | // Mark the bottom-most activity as finishing. |
| 793 | activity0.finishing = true; |
| 794 | // Add an extra activity on top of the root one and make it relinquish task identity |
| 795 | final ActivityRecord activity1 = new ActivityBuilder(mService).setTask(task).build(); |
| 796 | activity1.finishing = true; |
| 797 | |
| 798 | // Task must still update the intent using the root activity (preserving legacy behavior). |
| 799 | spyOn(task); |
| 800 | task.updateEffectiveIntent(); |
| 801 | verify(task).setIntent(eq(activity0)); |
| 802 | } |
| 803 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 804 | private Task getTestTask() { |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 805 | final ActivityStack stack = new StackBuilder(mRootActivityContainer).build(); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 806 | return stack.getBottomMostTask(); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 807 | } |
| 808 | |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 809 | private void testStackBoundsConfiguration(int windowingMode, Rect parentBounds, Rect bounds, |
| 810 | Rect expectedConfigBounds) { |
| 811 | |
| 812 | ActivityDisplay display = mService.mRootActivityContainer.getDefaultDisplay(); |
| 813 | ActivityStack stack = display.createStack(windowingMode, ACTIVITY_TYPE_STANDARD, |
| 814 | true /* onTop */); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 815 | Task task = new TaskBuilder(mSupervisor).setStack(stack).build(); |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 816 | |
| 817 | final Configuration parentConfig = stack.getConfiguration(); |
| 818 | parentConfig.windowConfiguration.setAppBounds(parentBounds); |
| 819 | task.setBounds(bounds); |
| 820 | |
| 821 | task.resolveOverrideConfiguration(parentConfig); |
| 822 | // Assert that both expected and actual are null or are equal to each other |
| 823 | assertEquals(expectedConfigBounds, |
| 824 | task.getResolvedOverrideConfiguration().windowConfiguration.getAppBounds()); |
| 825 | } |
| 826 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 827 | private byte[] serializeToBytes(Task r) throws Exception { |
Tadashi G. Takaoka | 88df5c3 | 2018-11-21 16:33:57 +0900 | [diff] [blame] | 828 | try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { |
Garfield Tan | 367b35a | 2017-12-13 12:16:21 -0800 | [diff] [blame] | 829 | final XmlSerializer serializer = Xml.newSerializer(); |
| 830 | serializer.setOutput(os, "UTF-8"); |
| 831 | serializer.startDocument(null, true); |
| 832 | serializer.startTag(null, TASK_TAG); |
| 833 | r.saveToXml(serializer); |
| 834 | serializer.endTag(null, TASK_TAG); |
| 835 | serializer.endDocument(); |
Garfield Tan | 367b35a | 2017-12-13 12:16:21 -0800 | [diff] [blame] | 836 | |
Tadashi G. Takaoka | 88df5c3 | 2018-11-21 16:33:57 +0900 | [diff] [blame] | 837 | os.flush(); |
| 838 | return os.toByteArray(); |
| 839 | } |
Garfield Tan | 367b35a | 2017-12-13 12:16:21 -0800 | [diff] [blame] | 840 | } |
| 841 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 842 | private Task restoreFromBytes(byte[] in) throws IOException, XmlPullParserException { |
Tadashi G. Takaoka | 88df5c3 | 2018-11-21 16:33:57 +0900 | [diff] [blame] | 843 | try (Reader reader = new InputStreamReader(new ByteArrayInputStream(in))) { |
Garfield Tan | 367b35a | 2017-12-13 12:16:21 -0800 | [diff] [blame] | 844 | final XmlPullParser parser = Xml.newPullParser(); |
| 845 | parser.setInput(reader); |
| 846 | assertEquals(XmlPullParser.START_TAG, parser.next()); |
| 847 | assertEquals(TASK_TAG, parser.getName()); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 848 | return Task.restoreFromXml(parser, mService.mStackSupervisor); |
Garfield Tan | 367b35a | 2017-12-13 12:16:21 -0800 | [diff] [blame] | 849 | } |
| 850 | } |
| 851 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 852 | private Task createTask(int taskId) { |
| 853 | return new Task(mService, taskId, new Intent(), null, null, null, |
Kazuki Takise | c2e17bf | 2018-07-17 17:46:38 +0900 | [diff] [blame] | 854 | ActivityBuilder.getDefaultComponent(), null, false, false, false, 0, 10050, null, |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 855 | 0, false, null, 0, 0, 0, 0, 0, null, 0, false, false, false, 0, |
| 856 | 0, null /*ActivityInfo*/, null /*_voiceSession*/, null /*_voiceInteractor*/, |
| 857 | null /*stack*/); |
Garfield Tan | 367b35a | 2017-12-13 12:16:21 -0800 | [diff] [blame] | 858 | } |
| 859 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 860 | private static class TestTaskFactory extends TaskFactory { |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 861 | private boolean mCreated = false; |
| 862 | |
| 863 | @Override |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 864 | Task create(ActivityTaskManagerService service, int taskId, ActivityInfo info, |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 865 | Intent intent, IVoiceInteractionSession voiceSession, |
| 866 | IVoiceInteractor voiceInteractor, ActivityStack stack) { |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 867 | mCreated = true; |
| 868 | return null; |
| 869 | } |
| 870 | |
| 871 | @Override |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 872 | Task create(ActivityTaskManagerService service, int taskId, ActivityInfo info, |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 873 | Intent intent, ActivityManager.TaskDescription taskDescription, |
| 874 | ActivityStack stack) { |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 875 | mCreated = true; |
| 876 | return null; |
| 877 | } |
| 878 | |
| 879 | @Override |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 880 | Task create(ActivityTaskManagerService service, int taskId, Intent intent, |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 881 | Intent affinityIntent, String affinity, String rootAffinity, |
| 882 | ComponentName realActivity, |
| 883 | ComponentName origActivity, boolean rootWasReset, boolean autoRemoveRecents, |
| 884 | boolean askedCompatMode, int userId, int effectiveUid, String lastDescription, |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 885 | long lastTimeMoved, |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 886 | boolean neverRelinquishIdentity, |
| 887 | ActivityManager.TaskDescription lastTaskDescription, |
| 888 | int taskAffiliation, int prevTaskId, int nextTaskId, int taskAffiliationColor, |
| 889 | int callingUid, String callingPackage, int resizeMode, |
| 890 | boolean supportsPictureInPicture, |
| 891 | boolean realActivitySuspended, boolean userSetupComplete, int minWidth, |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 892 | int minHeight, ActivityStack stack) { |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 893 | mCreated = true; |
| 894 | return null; |
| 895 | } |
| 896 | |
| 897 | @Override |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 898 | Task restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor) |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 899 | throws IOException, XmlPullParserException { |
| 900 | mCreated = true; |
| 901 | return null; |
| 902 | } |
| 903 | } |
| 904 | } |