Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1 | /* |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 2 | * Copyright (C) 2018 The Android Open Source Project |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 14 | * limitations under the License |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 18 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 19 | import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION; |
| 20 | import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT; |
| 21 | import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; |
| 22 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; |
| 23 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
| 24 | import static android.content.res.Configuration.ORIENTATION_PORTRAIT; |
Louis Chang | 6a9be16 | 2019-07-15 10:41:32 +0800 | [diff] [blame] | 25 | import static android.os.Process.NOBODY_UID; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 26 | import static android.view.Display.DEFAULT_DISPLAY; |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 27 | import static android.view.Surface.ROTATION_0; |
| 28 | import static android.view.Surface.ROTATION_90; |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 29 | import static android.view.WindowManager.TRANSIT_TASK_CLOSE; |
Bryce Lee | 0bd8d42 | 2018-01-09 09:45:57 -0800 | [diff] [blame] | 30 | |
Tadashi G. Takaoka | a7a6695 | 2018-11-16 15:04:21 +0900 | [diff] [blame] | 31 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.any; |
Garfield Tan | 36a69ad | 2019-01-16 17:08:23 -0800 | [diff] [blame] | 32 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyInt; |
Andrii Kulian | 149d9ad3 | 2019-08-23 15:04:17 -0700 | [diff] [blame] | 33 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.atLeast; |
Tadashi G. Takaoka | a7a6695 | 2018-11-16 15:04:21 +0900 | [diff] [blame] | 34 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 35 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 36 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; |
Garfield Tan | 36a69ad | 2019-01-16 17:08:23 -0800 | [diff] [blame] | 37 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.eq; |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 38 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 39 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset; |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 40 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 41 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.times; |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 42 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; |
Tadashi G. Takaoka | a7a6695 | 2018-11-16 15:04:21 +0900 | [diff] [blame] | 43 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.when; |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 44 | import static com.android.server.wm.ActivityRecord.FINISH_RESULT_CANCELLED; |
| 45 | import static com.android.server.wm.ActivityRecord.FINISH_RESULT_REMOVED; |
| 46 | import static com.android.server.wm.ActivityRecord.FINISH_RESULT_REQUESTED; |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 47 | import static com.android.server.wm.ActivityStack.ActivityState.DESTROYED; |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 48 | import static com.android.server.wm.ActivityStack.ActivityState.DESTROYING; |
| 49 | import static com.android.server.wm.ActivityStack.ActivityState.FINISHING; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 50 | import static com.android.server.wm.ActivityStack.ActivityState.INITIALIZING; |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 51 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSED; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 52 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSING; |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 53 | import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; |
Louis Chang | eadb22f | 2019-06-19 12:09:23 +0800 | [diff] [blame] | 54 | import static com.android.server.wm.ActivityStack.ActivityState.STARTED; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 55 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPED; |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 56 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPING; |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 57 | import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_DESTROYING; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 58 | import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_MOVING; |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 59 | import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_INVISIBLE; |
| 60 | import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE; |
| 61 | import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 62 | |
Louis Chang | 6a9be16 | 2019-07-15 10:41:32 +0800 | [diff] [blame] | 63 | import static com.google.common.truth.Truth.assertThat; |
| 64 | |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 65 | import static org.junit.Assert.assertEquals; |
Bryce Lee | 1533b2b | 2017-09-14 17:06:41 -0700 | [diff] [blame] | 66 | import static org.junit.Assert.assertFalse; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 67 | import static org.junit.Assert.assertNotEquals; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 68 | import static org.junit.Assert.assertNotNull; |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 69 | import static org.junit.Assert.assertNull; |
Bryce Lee | 1533b2b | 2017-09-14 17:06:41 -0700 | [diff] [blame] | 70 | import static org.junit.Assert.assertTrue; |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 71 | import static org.mockito.ArgumentMatchers.anyString; |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 72 | import static org.mockito.Mockito.never; |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 73 | |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 74 | import android.app.ActivityManager; |
| 75 | import android.app.ActivityManagerInternal; |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 76 | import android.app.ActivityOptions; |
Garfield Tan | 36a69ad | 2019-01-16 17:08:23 -0800 | [diff] [blame] | 77 | import android.app.servertransaction.ActivityConfigurationChangeItem; |
Bryce Lee | 0bd8d42 | 2018-01-09 09:45:57 -0800 | [diff] [blame] | 78 | import android.app.servertransaction.ClientTransaction; |
| 79 | import android.app.servertransaction.PauseActivityItem; |
Louis Chang | 6a9be16 | 2019-07-15 10:41:32 +0800 | [diff] [blame] | 80 | import android.content.ComponentName; |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 81 | import android.content.pm.ActivityInfo; |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 82 | import android.content.res.Configuration; |
Louis Chang | 6a9be16 | 2019-07-15 10:41:32 +0800 | [diff] [blame] | 83 | import android.content.res.Resources; |
Andrii Kulian | 3a1619d | 2017-07-07 14:38:09 -0700 | [diff] [blame] | 84 | import android.graphics.Rect; |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 85 | import android.os.Bundle; |
| 86 | import android.os.PersistableBundle; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 87 | import android.platform.test.annotations.Presubmit; |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 88 | import android.util.MergedConfiguration; |
Andrii Kulian | 0447068 | 2018-01-10 15:32:31 -0800 | [diff] [blame] | 89 | import android.util.MutableBoolean; |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 90 | import android.view.DisplayInfo; |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 91 | import android.view.IRemoteAnimationFinishedCallback; |
| 92 | import android.view.IRemoteAnimationRunner.Stub; |
| 93 | import android.view.RemoteAnimationAdapter; |
| 94 | import android.view.RemoteAnimationTarget; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 95 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 96 | import androidx.test.filters.MediumTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 97 | |
Louis Chang | 6a9be16 | 2019-07-15 10:41:32 +0800 | [diff] [blame] | 98 | import com.android.internal.R; |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 99 | import com.android.server.wm.ActivityStack.ActivityState; |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 100 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 101 | import org.junit.Before; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 102 | import org.junit.Test; |
Riddle Hsu | 2da2d03 | 2019-08-28 21:08:58 +0800 | [diff] [blame] | 103 | import org.junit.runner.RunWith; |
Andrii Kulian | 0447068 | 2018-01-10 15:32:31 -0800 | [diff] [blame] | 104 | import org.mockito.invocation.InvocationOnMock; |
Bryce Lee | 0bd8d42 | 2018-01-09 09:45:57 -0800 | [diff] [blame] | 105 | |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 106 | import java.util.concurrent.TimeUnit; |
| 107 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 108 | /** |
| 109 | * Tests for the {@link ActivityRecord} class. |
| 110 | * |
| 111 | * Build/Install/Run: |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 112 | * atest WmTests:ActivityRecordTests |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 113 | */ |
| 114 | @MediumTest |
Bryce Lee | 3115bdf | 2017-04-05 08:39:40 -0700 | [diff] [blame] | 115 | @Presubmit |
Riddle Hsu | 2da2d03 | 2019-08-28 21:08:58 +0800 | [diff] [blame] | 116 | @RunWith(WindowTestRunner.class) |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 117 | public class ActivityRecordTests extends ActivityTestsBase { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 118 | private ActivityStack mStack; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 119 | private TaskRecord mTask; |
| 120 | private ActivityRecord mActivity; |
| 121 | |
| 122 | @Before |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 123 | public void setUp() throws Exception { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 124 | mStack = new StackBuilder(mRootActivityContainer).build(); |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 125 | mTask = mStack.getChildAt(0); |
| 126 | mActivity = mTask.getTopActivity(); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 127 | |
| 128 | doReturn(false).when(mService).isBooting(); |
| 129 | doReturn(true).when(mService).isBooted(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 132 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 133 | public void testStackCleanupOnClearingTask() { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 134 | mActivity.setTask(null); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 135 | verify(mStack, times(1)).onActivityRemovedFromStack(any()); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 139 | public void testStackCleanupOnActivityRemoval() { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 140 | mTask.removeActivity(mActivity); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 141 | verify(mStack, times(1)).onActivityRemovedFromStack(any()); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 145 | public void testStackCleanupOnTaskRemoval() { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 146 | mStack.removeTask(mTask, null /*reason*/, REMOVE_TASK_MODE_MOVING); |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 147 | // Stack should be gone on task removal. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 148 | assertNull(mService.mRootActivityContainer.getStack(mStack.mStackId)); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 152 | public void testNoCleanupMovingActivityInSameStack() { |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 153 | final TaskRecord newTask = new TaskBuilder(mService.mStackSupervisor).setStack(mStack) |
| 154 | .build(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 155 | mActivity.reparent(newTask, 0, null /*reason*/); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 156 | verify(mStack, times(0)).onActivityRemovedFromStack(any()); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 157 | } |
Andrii Kulian | 3a1619d | 2017-07-07 14:38:09 -0700 | [diff] [blame] | 158 | |
Andreas Gampe | cea9e6d | 2018-02-22 18:06:44 -0800 | [diff] [blame] | 159 | @Test |
Bryce Lee | 0bd8d42 | 2018-01-09 09:45:57 -0800 | [diff] [blame] | 160 | public void testPausingWhenVisibleFromStopped() throws Exception { |
Andrii Kulian | 0447068 | 2018-01-10 15:32:31 -0800 | [diff] [blame] | 161 | final MutableBoolean pauseFound = new MutableBoolean(false); |
| 162 | doAnswer((InvocationOnMock invocationOnMock) -> { |
| 163 | final ClientTransaction transaction = invocationOnMock.getArgument(0); |
| 164 | if (transaction.getLifecycleStateRequest() instanceof PauseActivityItem) { |
| 165 | pauseFound.value = true; |
Bryce Lee | 0bd8d42 | 2018-01-09 09:45:57 -0800 | [diff] [blame] | 166 | } |
Andrii Kulian | 0447068 | 2018-01-10 15:32:31 -0800 | [diff] [blame] | 167 | return null; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 168 | }).when(mActivity.app.getThread()).scheduleTransaction(any()); |
Bryce Lee | d939cf0 | 2018-03-12 09:04:44 -0700 | [diff] [blame] | 169 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 170 | mActivity.setState(STOPPED, "testPausingWhenVisibleFromStopped"); |
Bryce Lee | 0bd8d42 | 2018-01-09 09:45:57 -0800 | [diff] [blame] | 171 | |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 172 | // The activity is in the focused stack so it should be resumed. |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 173 | mActivity.makeVisibleIfNeeded(null /* starting */, true /* reportToClient */); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 174 | assertTrue(mActivity.isState(RESUMED)); |
Bryce Lee | d939cf0 | 2018-03-12 09:04:44 -0700 | [diff] [blame] | 175 | assertFalse(pauseFound.value); |
Andrii Kulian | 0447068 | 2018-01-10 15:32:31 -0800 | [diff] [blame] | 176 | |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 177 | // Make the activity non focusable |
| 178 | mActivity.setState(STOPPED, "testPausingWhenVisibleFromStopped"); |
| 179 | doReturn(false).when(mActivity).isFocusable(); |
Bryce Lee | d939cf0 | 2018-03-12 09:04:44 -0700 | [diff] [blame] | 180 | |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 181 | // If the activity is not focusable, it should move to paused. |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 182 | mActivity.makeVisibleIfNeeded(null /* starting */, true /* reportToClient */); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 183 | assertTrue(mActivity.isState(PAUSING)); |
Andrii Kulian | 0447068 | 2018-01-10 15:32:31 -0800 | [diff] [blame] | 184 | assertTrue(pauseFound.value); |
Bryce Lee | 052957b | 2018-01-16 11:13:30 -0800 | [diff] [blame] | 185 | |
| 186 | // Make sure that the state does not change for current non-stopping states. |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 187 | mActivity.setState(INITIALIZING, "testPausingWhenVisibleFromStopped"); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 188 | doReturn(true).when(mActivity).isFocusable(); |
Bryce Lee | 052957b | 2018-01-16 11:13:30 -0800 | [diff] [blame] | 189 | |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 190 | mActivity.makeVisibleIfNeeded(null /* starting */, true /* reportToClient */); |
Bryce Lee | 052957b | 2018-01-16 11:13:30 -0800 | [diff] [blame] | 191 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 192 | assertTrue(mActivity.isState(INITIALIZING)); |
Bryce Lee | a0fb8e0 | 2018-02-28 14:21:07 -0800 | [diff] [blame] | 193 | |
| 194 | // Make sure the state does not change if we are not the current top activity. |
| 195 | mActivity.setState(STOPPED, "testPausingWhenVisibleFromStopped behind"); |
| 196 | |
Bryce Lee | a0fb8e0 | 2018-02-28 14:21:07 -0800 | [diff] [blame] | 197 | final ActivityRecord topActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 198 | mStack.mTranslucentActivityWaiting = topActivity; |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 199 | mActivity.makeVisibleIfNeeded(null /* starting */, true /* reportToClient */); |
Louis Chang | eadb22f | 2019-06-19 12:09:23 +0800 | [diff] [blame] | 200 | assertTrue(mActivity.isState(STARTED)); |
| 201 | |
| 202 | mStack.mTranslucentActivityWaiting = null; |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 203 | topActivity.setOccludesParent(false); |
Louis Chang | eadb22f | 2019-06-19 12:09:23 +0800 | [diff] [blame] | 204 | mActivity.setState(STOPPED, "testPausingWhenVisibleFromStopped behind non-opaque"); |
| 205 | mActivity.makeVisibleIfNeeded(null /* starting */, true /* reportToClient */); |
| 206 | assertTrue(mActivity.isState(STARTED)); |
Bryce Lee | 0bd8d42 | 2018-01-09 09:45:57 -0800 | [diff] [blame] | 207 | } |
| 208 | |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 209 | private void ensureActivityConfiguration() { |
| 210 | mActivity.ensureActivityConfiguration(0 /* globalChanges */, false /* preserveWindow */); |
| 211 | } |
| 212 | |
Bryce Lee | 1533b2b | 2017-09-14 17:06:41 -0700 | [diff] [blame] | 213 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 214 | public void testCanBeLaunchedOnDisplay() { |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 215 | mService.mSupportsMultiWindow = true; |
| 216 | final ActivityRecord activity = new ActivityBuilder(mService).build(); |
Bryce Lee | 1533b2b | 2017-09-14 17:06:41 -0700 | [diff] [blame] | 217 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 218 | // An activity can be launched on default display. |
| 219 | assertTrue(activity.canBeLaunchedOnDisplay(DEFAULT_DISPLAY)); |
| 220 | // An activity cannot be launched on a non-existent display. |
| 221 | assertFalse(activity.canBeLaunchedOnDisplay(DEFAULT_DISPLAY + 1)); |
Bryce Lee | 1533b2b | 2017-09-14 17:06:41 -0700 | [diff] [blame] | 222 | } |
| 223 | |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 224 | @Test |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 225 | public void testRestartProcessIfVisible() { |
| 226 | doNothing().when(mSupervisor).scheduleRestartTimeout(mActivity); |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 227 | mActivity.visible = true; |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 228 | mActivity.setSavedState(null /* savedState */); |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 229 | mActivity.setState(ActivityStack.ActivityState.RESUMED, "testRestart"); |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 230 | prepareFixedAspectRatioUnresizableActivity(); |
| 231 | |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 232 | final Rect originalOverrideBounds = new Rect(mActivity.getBounds()); |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 233 | setupDisplayAndParentSize(600, 1200); |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 234 | // The visible activity should recompute configuration according to the last parent bounds. |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 235 | mService.restartActivityProcessIfVisible(mActivity.appToken); |
| 236 | |
| 237 | assertEquals(ActivityStack.ActivityState.RESTARTING_PROCESS, mActivity.getState()); |
| 238 | assertNotEquals(originalOverrideBounds, mActivity.getBounds()); |
| 239 | } |
| 240 | |
| 241 | @Test |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 242 | public void testsApplyOptionsLocked() { |
| 243 | ActivityOptions activityOptions = ActivityOptions.makeBasic(); |
| 244 | |
| 245 | // Set and apply options for ActivityRecord. Pending options should be cleared |
| 246 | mActivity.updateOptionsLocked(activityOptions); |
| 247 | mActivity.applyOptionsLocked(); |
| 248 | assertNull(mActivity.pendingOptions); |
| 249 | |
| 250 | // Set options for two ActivityRecords in same Task. Apply one ActivityRecord options. |
| 251 | // Pending options should be cleared for both ActivityRecords |
| 252 | ActivityRecord activity2 = new ActivityBuilder(mService).setTask(mTask).build(); |
| 253 | activity2.updateOptionsLocked(activityOptions); |
| 254 | mActivity.updateOptionsLocked(activityOptions); |
| 255 | mActivity.applyOptionsLocked(); |
| 256 | assertNull(mActivity.pendingOptions); |
| 257 | assertNull(activity2.pendingOptions); |
| 258 | |
| 259 | // Set options for two ActivityRecords in separate Tasks. Apply one ActivityRecord options. |
| 260 | // Pending options should be cleared for only ActivityRecord that was applied |
| 261 | TaskRecord task2 = new TaskBuilder(mService.mStackSupervisor).setStack(mStack).build(); |
| 262 | activity2 = new ActivityBuilder(mService).setTask(task2).build(); |
| 263 | activity2.updateOptionsLocked(activityOptions); |
| 264 | mActivity.updateOptionsLocked(activityOptions); |
| 265 | mActivity.applyOptionsLocked(); |
| 266 | assertNull(mActivity.pendingOptions); |
| 267 | assertNotNull(activity2.pendingOptions); |
| 268 | } |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 269 | |
| 270 | @Test |
| 271 | public void testNewOverrideConfigurationIncrementsSeq() { |
| 272 | final Configuration newConfig = new Configuration(); |
| 273 | |
| 274 | final int prevSeq = mActivity.getMergedOverrideConfiguration().seq; |
| 275 | mActivity.onRequestedOverrideConfigurationChanged(newConfig); |
| 276 | assertEquals(prevSeq + 1, mActivity.getMergedOverrideConfiguration().seq); |
| 277 | } |
| 278 | |
| 279 | @Test |
| 280 | public void testNewParentConfigurationIncrementsSeq() { |
| 281 | final Configuration newConfig = new Configuration( |
| 282 | mTask.getRequestedOverrideConfiguration()); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 283 | newConfig.orientation = newConfig.orientation == ORIENTATION_PORTRAIT |
| 284 | ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT; |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 285 | |
| 286 | final int prevSeq = mActivity.getMergedOverrideConfiguration().seq; |
| 287 | mTask.onRequestedOverrideConfigurationChanged(newConfig); |
| 288 | assertEquals(prevSeq + 1, mActivity.getMergedOverrideConfiguration().seq); |
| 289 | } |
| 290 | |
| 291 | @Test |
| 292 | public void testNotifiesSeqIncrementToAppToken() { |
| 293 | final Configuration appWindowTokenRequestedOrientation = mock(Configuration.class); |
| 294 | mActivity.mAppWindowToken = mock(AppWindowToken.class); |
| 295 | doReturn(appWindowTokenRequestedOrientation).when(mActivity.mAppWindowToken) |
| 296 | .getRequestedOverrideConfiguration(); |
| 297 | |
| 298 | final Configuration newConfig = new Configuration(); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 299 | newConfig.orientation = ORIENTATION_PORTRAIT; |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 300 | |
| 301 | final int prevSeq = mActivity.getMergedOverrideConfiguration().seq; |
| 302 | mActivity.onRequestedOverrideConfigurationChanged(newConfig); |
| 303 | assertEquals(prevSeq + 1, appWindowTokenRequestedOrientation.seq); |
| 304 | verify(mActivity.mAppWindowToken).onMergedOverrideConfigurationChanged(); |
| 305 | } |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 306 | |
| 307 | @Test |
| 308 | public void testSetsRelaunchReason_NotDragResizing() { |
| 309 | mActivity.setState(ActivityStack.ActivityState.RESUMED, "Testing"); |
| 310 | |
| 311 | mTask.onRequestedOverrideConfigurationChanged(mTask.getConfiguration()); |
| 312 | mActivity.setLastReportedConfiguration(new MergedConfiguration(new Configuration(), |
| 313 | mActivity.getConfiguration())); |
| 314 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 315 | mActivity.info.configChanges &= ~CONFIG_ORIENTATION; |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 316 | final Configuration newConfig = new Configuration(mTask.getConfiguration()); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 317 | newConfig.orientation = newConfig.orientation == ORIENTATION_PORTRAIT |
| 318 | ? ORIENTATION_LANDSCAPE |
| 319 | : ORIENTATION_PORTRAIT; |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 320 | mTask.onRequestedOverrideConfigurationChanged(newConfig); |
| 321 | |
| 322 | mActivity.mRelaunchReason = ActivityTaskManagerService.RELAUNCH_REASON_NONE; |
| 323 | |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 324 | ensureActivityConfiguration(); |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 325 | |
| 326 | assertEquals(ActivityTaskManagerService.RELAUNCH_REASON_WINDOWING_MODE_RESIZE, |
| 327 | mActivity.mRelaunchReason); |
| 328 | } |
| 329 | |
| 330 | @Test |
| 331 | public void testSetsRelaunchReason_DragResizing() { |
| 332 | mActivity.setState(ActivityStack.ActivityState.RESUMED, "Testing"); |
| 333 | |
| 334 | mTask.onRequestedOverrideConfigurationChanged(mTask.getConfiguration()); |
| 335 | mActivity.setLastReportedConfiguration(new MergedConfiguration(new Configuration(), |
| 336 | mActivity.getConfiguration())); |
| 337 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 338 | mActivity.info.configChanges &= ~CONFIG_ORIENTATION; |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 339 | final Configuration newConfig = new Configuration(mTask.getConfiguration()); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 340 | newConfig.orientation = newConfig.orientation == ORIENTATION_PORTRAIT |
| 341 | ? ORIENTATION_LANDSCAPE |
| 342 | : ORIENTATION_PORTRAIT; |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 343 | mTask.onRequestedOverrideConfigurationChanged(newConfig); |
| 344 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 345 | doReturn(true).when(mTask.mTask).isDragResizing(); |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 346 | |
| 347 | mActivity.mRelaunchReason = ActivityTaskManagerService.RELAUNCH_REASON_NONE; |
| 348 | |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 349 | ensureActivityConfiguration(); |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 350 | |
| 351 | assertEquals(ActivityTaskManagerService.RELAUNCH_REASON_FREE_RESIZE, |
| 352 | mActivity.mRelaunchReason); |
| 353 | } |
| 354 | |
| 355 | @Test |
| 356 | public void testSetsRelaunchReason_NonResizeConfigChanges() { |
| 357 | mActivity.setState(ActivityStack.ActivityState.RESUMED, "Testing"); |
| 358 | |
| 359 | mTask.onRequestedOverrideConfigurationChanged(mTask.getConfiguration()); |
| 360 | mActivity.setLastReportedConfiguration(new MergedConfiguration(new Configuration(), |
| 361 | mActivity.getConfiguration())); |
| 362 | |
| 363 | mActivity.info.configChanges &= ~ActivityInfo.CONFIG_FONT_SCALE; |
| 364 | final Configuration newConfig = new Configuration(mTask.getConfiguration()); |
| 365 | newConfig.fontScale = 5; |
| 366 | mTask.onRequestedOverrideConfigurationChanged(newConfig); |
| 367 | |
| 368 | mActivity.mRelaunchReason = |
| 369 | ActivityTaskManagerService.RELAUNCH_REASON_WINDOWING_MODE_RESIZE; |
| 370 | |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 371 | ensureActivityConfiguration(); |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 372 | |
| 373 | assertEquals(ActivityTaskManagerService.RELAUNCH_REASON_NONE, |
| 374 | mActivity.mRelaunchReason); |
| 375 | } |
Garfield Tan | 36a69ad | 2019-01-16 17:08:23 -0800 | [diff] [blame] | 376 | |
| 377 | @Test |
| 378 | public void testSetRequestedOrientationUpdatesConfiguration() throws Exception { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 379 | mActivity = new ActivityBuilder(mService) |
| 380 | .setTask(mTask) |
| 381 | .setConfigChanges(CONFIG_ORIENTATION | CONFIG_SCREEN_LAYOUT) |
| 382 | .build(); |
Garfield Tan | 36a69ad | 2019-01-16 17:08:23 -0800 | [diff] [blame] | 383 | mActivity.setState(ActivityStack.ActivityState.RESUMED, "Testing"); |
| 384 | |
Garfield Tan | 36a69ad | 2019-01-16 17:08:23 -0800 | [diff] [blame] | 385 | mActivity.setLastReportedConfiguration(new MergedConfiguration(new Configuration(), |
| 386 | mActivity.getConfiguration())); |
| 387 | |
Garfield Tan | 36a69ad | 2019-01-16 17:08:23 -0800 | [diff] [blame] | 388 | final Configuration newConfig = new Configuration(mActivity.getConfiguration()); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 389 | final int shortSide = Math.min(newConfig.screenWidthDp, newConfig.screenHeightDp); |
| 390 | final int longSide = Math.max(newConfig.screenWidthDp, newConfig.screenHeightDp); |
| 391 | if (newConfig.orientation == ORIENTATION_PORTRAIT) { |
| 392 | newConfig.orientation = ORIENTATION_LANDSCAPE; |
| 393 | newConfig.screenWidthDp = longSide; |
| 394 | newConfig.screenHeightDp = shortSide; |
| 395 | } else { |
| 396 | newConfig.orientation = ORIENTATION_PORTRAIT; |
| 397 | newConfig.screenWidthDp = shortSide; |
| 398 | newConfig.screenHeightDp = longSide; |
| 399 | } |
Garfield Tan | 36a69ad | 2019-01-16 17:08:23 -0800 | [diff] [blame] | 400 | |
| 401 | // Mimic the behavior that display doesn't handle app's requested orientation. |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 402 | final DisplayContent dc = mTask.mTask.getDisplayContent(); |
| 403 | doReturn(false).when(dc).onDescendantOrientationChanged(any(), any()); |
| 404 | doReturn(false).when(dc).handlesOrientationChangeFromDescendant(); |
Garfield Tan | 36a69ad | 2019-01-16 17:08:23 -0800 | [diff] [blame] | 405 | |
| 406 | final int requestedOrientation; |
| 407 | switch (newConfig.orientation) { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 408 | case ORIENTATION_LANDSCAPE: |
| 409 | requestedOrientation = SCREEN_ORIENTATION_LANDSCAPE; |
Garfield Tan | 36a69ad | 2019-01-16 17:08:23 -0800 | [diff] [blame] | 410 | break; |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 411 | case ORIENTATION_PORTRAIT: |
Garfield Tan | 36a69ad | 2019-01-16 17:08:23 -0800 | [diff] [blame] | 412 | requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; |
| 413 | break; |
| 414 | default: |
| 415 | throw new IllegalStateException("Orientation in new config should be either" |
| 416 | + "landscape or portrait."); |
| 417 | } |
| 418 | mActivity.setRequestedOrientation(requestedOrientation); |
| 419 | |
| 420 | final ActivityConfigurationChangeItem expected = |
| 421 | ActivityConfigurationChangeItem.obtain(newConfig); |
| 422 | verify(mService.getLifecycleManager()).scheduleTransaction(eq(mActivity.app.getThread()), |
| 423 | eq(mActivity.appToken), eq(expected)); |
| 424 | } |
Andrii Kulian | f219536 | 2019-01-31 18:20:11 -0800 | [diff] [blame] | 425 | |
| 426 | @Test |
| 427 | public void testShouldMakeActive_deferredResume() { |
| 428 | mActivity.setState(ActivityStack.ActivityState.STOPPED, "Testing"); |
| 429 | |
| 430 | mSupervisor.beginDeferResume(); |
| 431 | assertEquals(false, mActivity.shouldMakeActive(null /* activeActivity */)); |
| 432 | |
| 433 | mSupervisor.endDeferResume(); |
| 434 | assertEquals(true, mActivity.shouldMakeActive(null /* activeActivity */)); |
| 435 | } |
Garfield Tan | 4026330 | 2019-02-01 15:27:35 -0800 | [diff] [blame] | 436 | |
| 437 | @Test |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 438 | public void testShouldResume_stackVisibility() { |
| 439 | mActivity.setState(ActivityStack.ActivityState.STOPPED, "Testing"); |
| 440 | spyOn(mStack); |
| 441 | |
| 442 | doReturn(STACK_VISIBILITY_VISIBLE).when(mStack).getVisibility(null); |
| 443 | assertEquals(true, mActivity.shouldResumeActivity(null /* activeActivity */)); |
| 444 | |
| 445 | doReturn(STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT).when(mStack).getVisibility(null); |
| 446 | assertEquals(false, mActivity.shouldResumeActivity(null /* activeActivity */)); |
| 447 | |
| 448 | doReturn(STACK_VISIBILITY_INVISIBLE).when(mStack).getVisibility(null); |
| 449 | assertEquals(false, mActivity.shouldResumeActivity(null /* activeActivity */)); |
| 450 | } |
| 451 | |
| 452 | @Test |
Garfield Tan | 4026330 | 2019-02-01 15:27:35 -0800 | [diff] [blame] | 453 | public void testPushConfigurationWhenLaunchTaskBehind() throws Exception { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 454 | mActivity = new ActivityBuilder(mService) |
| 455 | .setTask(mTask) |
| 456 | .setLaunchTaskBehind(true) |
| 457 | .setConfigChanges(CONFIG_ORIENTATION) |
| 458 | .build(); |
Garfield Tan | 4026330 | 2019-02-01 15:27:35 -0800 | [diff] [blame] | 459 | mActivity.setState(ActivityStack.ActivityState.STOPPED, "Testing"); |
| 460 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 461 | final ActivityStack stack = new StackBuilder(mRootActivityContainer).build(); |
Garfield Tan | 4026330 | 2019-02-01 15:27:35 -0800 | [diff] [blame] | 462 | try { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 463 | doReturn(false).when(stack).isStackTranslucent(any()); |
Garfield Tan | 4026330 | 2019-02-01 15:27:35 -0800 | [diff] [blame] | 464 | assertFalse(mStack.shouldBeVisible(null /* starting */)); |
| 465 | |
Garfield Tan | 4026330 | 2019-02-01 15:27:35 -0800 | [diff] [blame] | 466 | mActivity.setLastReportedConfiguration(new MergedConfiguration(new Configuration(), |
| 467 | mActivity.getConfiguration())); |
| 468 | |
Garfield Tan | 4026330 | 2019-02-01 15:27:35 -0800 | [diff] [blame] | 469 | final Configuration newConfig = new Configuration(mActivity.getConfiguration()); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 470 | final int shortSide = Math.min(newConfig.screenWidthDp, newConfig.screenHeightDp); |
| 471 | final int longSide = Math.max(newConfig.screenWidthDp, newConfig.screenHeightDp); |
| 472 | if (newConfig.orientation == ORIENTATION_PORTRAIT) { |
| 473 | newConfig.orientation = ORIENTATION_LANDSCAPE; |
| 474 | newConfig.screenWidthDp = longSide; |
| 475 | newConfig.screenHeightDp = shortSide; |
| 476 | } else { |
| 477 | newConfig.orientation = ORIENTATION_PORTRAIT; |
| 478 | newConfig.screenWidthDp = shortSide; |
| 479 | newConfig.screenHeightDp = longSide; |
| 480 | } |
Garfield Tan | 4026330 | 2019-02-01 15:27:35 -0800 | [diff] [blame] | 481 | |
| 482 | mTask.onConfigurationChanged(newConfig); |
| 483 | |
| 484 | mActivity.ensureActivityConfiguration(0 /* globalChanges */, |
| 485 | false /* preserveWindow */, true /* ignoreStopState */); |
| 486 | |
| 487 | final ActivityConfigurationChangeItem expected = |
| 488 | ActivityConfigurationChangeItem.obtain(newConfig); |
| 489 | verify(mService.getLifecycleManager()).scheduleTransaction( |
| 490 | eq(mActivity.app.getThread()), eq(mActivity.appToken), eq(expected)); |
| 491 | } finally { |
| 492 | stack.getDisplay().removeChild(stack); |
| 493 | } |
| 494 | } |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 495 | |
| 496 | @Test |
Louis Chang | 3d119a9 | 2019-04-22 10:45:37 +0800 | [diff] [blame] | 497 | public void testShouldPauseWhenMakeClientVisible() { |
| 498 | ActivityRecord topActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 499 | topActivity.setOccludesParent(false); |
Louis Chang | 3d119a9 | 2019-04-22 10:45:37 +0800 | [diff] [blame] | 500 | mActivity.setState(ActivityStack.ActivityState.STOPPED, "Testing"); |
| 501 | mActivity.makeClientVisible(); |
Louis Chang | eadb22f | 2019-06-19 12:09:23 +0800 | [diff] [blame] | 502 | assertEquals(STARTED, mActivity.getState()); |
Louis Chang | 3d119a9 | 2019-04-22 10:45:37 +0800 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | @Test |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 506 | public void testSizeCompatMode_FixedAspectRatioBoundsWithDecor() { |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 507 | setupDisplayContentForCompatDisplayInsets(); |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 508 | final int decorHeight = 200; // e.g. The device has cutout. |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 509 | final DisplayPolicy policy = setupDisplayAndParentSize(600, 800).getDisplayPolicy(); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 510 | spyOn(policy); |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 511 | doAnswer(invocationOnMock -> { |
| 512 | final int rotation = invocationOnMock.<Integer>getArgument(0); |
| 513 | final Rect insets = invocationOnMock.<Rect>getArgument(4); |
| 514 | if (rotation == ROTATION_0) { |
| 515 | insets.top = decorHeight; |
| 516 | } else if (rotation == ROTATION_90) { |
| 517 | insets.left = decorHeight; |
| 518 | } |
| 519 | return null; |
| 520 | }).when(policy).getNonDecorInsetsLw(anyInt() /* rotation */, anyInt() /* width */, |
| 521 | anyInt() /* height */, any() /* displayCutout */, any() /* outInsets */); |
| 522 | |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 523 | doReturn(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) |
| 524 | .when(mActivity.mAppWindowToken).getOrientationIgnoreVisibility(); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 525 | mActivity.info.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
Riddle Hsu | 9ad178510 | 2019-03-26 00:26:54 +0800 | [diff] [blame] | 526 | mActivity.info.minAspectRatio = mActivity.info.maxAspectRatio = 1; |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 527 | ensureActivityConfiguration(); |
Riddle Hsu | 9ad178510 | 2019-03-26 00:26:54 +0800 | [diff] [blame] | 528 | // The parent configuration doesn't change since the first resolved configuration, so the |
| 529 | // activity shouldn't be in the size compatibility mode. |
| 530 | assertFalse(mActivity.inSizeCompatMode()); |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 531 | |
| 532 | final Rect appBounds = mActivity.getWindowConfiguration().getAppBounds(); |
| 533 | // Ensure the app bounds keep the declared aspect ratio. |
| 534 | assertEquals(appBounds.width(), appBounds.height()); |
| 535 | // The decor height should be a part of the effective bounds. |
| 536 | assertEquals(mActivity.getBounds().height(), appBounds.height() + decorHeight); |
| 537 | |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 538 | mTask.getConfiguration().windowConfiguration.setRotation(ROTATION_90); |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 539 | mActivity.onConfigurationChanged(mTask.getConfiguration()); |
| 540 | // After changing orientation, the aspect ratio should be the same. |
| 541 | assertEquals(appBounds.width(), appBounds.height()); |
| 542 | // The decor height will be included in width. |
| 543 | assertEquals(mActivity.getBounds().width(), appBounds.width() + decorHeight); |
| 544 | } |
| 545 | |
| 546 | @Test |
Riddle Hsu | 2560c3b | 2019-02-23 23:45:58 +0800 | [diff] [blame] | 547 | public void testSizeCompatMode_FixedScreenConfigurationWhenMovingToDisplay() { |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 548 | // Initialize different bounds on a new display. |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 549 | final Rect newDisplayBounds = new Rect(0, 0, 1000, 2000); |
| 550 | DisplayInfo info = new DisplayInfo(); |
| 551 | mService.mContext.getDisplay().getDisplayInfo(info); |
| 552 | info.logicalWidth = newDisplayBounds.width(); |
| 553 | info.logicalHeight = newDisplayBounds.height(); |
| 554 | info.logicalDensityDpi = 300; |
| 555 | |
| 556 | final ActivityDisplay newDisplay = |
| 557 | addNewActivityDisplayAt(info, ActivityDisplay.POSITION_TOP); |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 558 | |
Evan Rosky | 5572953 | 2019-08-09 20:01:00 -0700 | [diff] [blame] | 559 | final Configuration c = |
| 560 | new Configuration(mStack.getDisplay().getRequestedOverrideConfiguration()); |
| 561 | c.densityDpi = 200; |
| 562 | mStack.getDisplay().onRequestedOverrideConfigurationChanged(c); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 563 | mActivity = new ActivityBuilder(mService) |
| 564 | .setTask(mTask) |
| 565 | .setResizeMode(RESIZE_MODE_UNRESIZEABLE) |
| 566 | .setMaxAspectRatio(1.5f) |
| 567 | .build(); |
Evan Rosky | 5572953 | 2019-08-09 20:01:00 -0700 | [diff] [blame] | 568 | mActivity.visible = true; |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 569 | |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 570 | final Rect originalBounds = new Rect(mActivity.getBounds()); |
| 571 | final int originalDpi = mActivity.getConfiguration().densityDpi; |
| 572 | |
| 573 | // Move the non-resizable activity to the new display. |
| 574 | mStack.reparent(newDisplay, true /* onTop */, false /* displayRemoved */); |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 575 | |
| 576 | assertEquals(originalBounds, mActivity.getBounds()); |
| 577 | assertEquals(originalDpi, mActivity.getConfiguration().densityDpi); |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 578 | assertTrue(mActivity.inSizeCompatMode()); |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | @Test |
Riddle Hsu | 2560c3b | 2019-02-23 23:45:58 +0800 | [diff] [blame] | 582 | public void testSizeCompatMode_FixedScreenBoundsWhenDisplaySizeChanged() { |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 583 | setupDisplayContentForCompatDisplayInsets(); |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 584 | when(mActivity.mAppWindowToken.getOrientationIgnoreVisibility()).thenReturn( |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 585 | ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 586 | mTask.getWindowConfiguration().setAppBounds(mStack.getDisplay().getBounds()); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 587 | mTask.getConfiguration().orientation = ORIENTATION_PORTRAIT; |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 588 | mActivity.info.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 589 | mActivity.info.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 590 | ensureActivityConfiguration(); |
| 591 | final Rect originalBounds = new Rect(mActivity.getBounds()); |
| 592 | |
| 593 | // Change the size of current display. |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 594 | setupDisplayAndParentSize(1000, 2000); |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 595 | ensureActivityConfiguration(); |
| 596 | |
| 597 | assertEquals(originalBounds, mActivity.getBounds()); |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 598 | assertTrue(mActivity.inSizeCompatMode()); |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 599 | } |
Riddle Hsu | 2560c3b | 2019-02-23 23:45:58 +0800 | [diff] [blame] | 600 | |
| 601 | @Test |
| 602 | public void testSizeCompatMode_FixedScreenLayoutSizeBits() { |
| 603 | final int fixedScreenLayout = Configuration.SCREENLAYOUT_LONG_NO |
| 604 | | Configuration.SCREENLAYOUT_SIZE_NORMAL; |
Evan Rosky | 5572953 | 2019-08-09 20:01:00 -0700 | [diff] [blame] | 605 | mTask.getRequestedOverrideConfiguration().screenLayout = fixedScreenLayout |
Riddle Hsu | 2560c3b | 2019-02-23 23:45:58 +0800 | [diff] [blame] | 606 | | Configuration.SCREENLAYOUT_LAYOUTDIR_LTR; |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 607 | prepareFixedAspectRatioUnresizableActivity(); |
Riddle Hsu | 2560c3b | 2019-02-23 23:45:58 +0800 | [diff] [blame] | 608 | |
| 609 | // The initial configuration should inherit from parent. |
| 610 | assertEquals(mTask.getConfiguration().screenLayout, |
| 611 | mActivity.getConfiguration().screenLayout); |
| 612 | |
| 613 | mTask.getConfiguration().screenLayout = Configuration.SCREENLAYOUT_LAYOUTDIR_RTL |
| 614 | | Configuration.SCREENLAYOUT_LONG_YES | Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 615 | mActivity.onConfigurationChanged(mTask.getConfiguration()); |
| 616 | |
| 617 | // The size and aspect ratio bits don't change, but the layout direction should be updated. |
| 618 | assertEquals(fixedScreenLayout | Configuration.SCREENLAYOUT_LAYOUTDIR_RTL, |
| 619 | mActivity.getConfiguration().screenLayout); |
| 620 | } |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 621 | |
| 622 | @Test |
| 623 | public void testSizeCompatMode_ResetNonVisibleActivity() { |
| 624 | final ActivityDisplay display = mStack.getDisplay(); |
| 625 | spyOn(display); |
| 626 | |
| 627 | prepareFixedAspectRatioUnresizableActivity(); |
| 628 | mActivity.setState(STOPPED, "testSizeCompatMode"); |
| 629 | mActivity.visible = false; |
| 630 | mActivity.app.setReportedProcState(ActivityManager.PROCESS_STATE_CACHED_ACTIVITY); |
| 631 | // Make the parent bounds to be different so the activity is in size compatibility mode. |
| 632 | mTask.getWindowConfiguration().setAppBounds(new Rect(0, 0, 600, 1200)); |
| 633 | |
| 634 | // Simulate the display changes orientation. |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 635 | doReturn(ActivityInfo.CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 636 | | ActivityInfo.CONFIG_WINDOW_CONFIGURATION) |
| 637 | .when(display).getLastOverrideConfigurationChanges(); |
| 638 | mActivity.onConfigurationChanged(mTask.getConfiguration()); |
| 639 | // The override configuration should not change so it is still in size compatibility mode. |
| 640 | assertTrue(mActivity.inSizeCompatMode()); |
| 641 | |
| 642 | // Simulate the display changes density. |
| 643 | doReturn(ActivityInfo.CONFIG_DENSITY).when(display).getLastOverrideConfigurationChanges(); |
| 644 | mService.mAmInternal = mock(ActivityManagerInternal.class); |
| 645 | mActivity.onConfigurationChanged(mTask.getConfiguration()); |
| 646 | // The override configuration should be reset and the activity's process will be killed. |
| 647 | assertFalse(mActivity.inSizeCompatMode()); |
| 648 | verify(mActivity).restartProcessIfVisible(); |
Riddle Hsu | 2da2d03 | 2019-08-28 21:08:58 +0800 | [diff] [blame] | 649 | mLockRule.runWithScissors(mService.mH, () -> { }, TimeUnit.SECONDS.toMillis(3)); |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 650 | verify(mService.mAmInternal).killProcess( |
| 651 | eq(mActivity.app.mName), eq(mActivity.app.mUid), anyString()); |
| 652 | } |
| 653 | |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 654 | @Test |
| 655 | public void testTakeOptions() { |
| 656 | ActivityOptions opts = ActivityOptions.makeRemoteAnimation( |
| 657 | new RemoteAnimationAdapter(new Stub() { |
| 658 | |
| 659 | @Override |
| 660 | public void onAnimationStart(RemoteAnimationTarget[] apps, |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame^] | 661 | RemoteAnimationTarget[] wallpapers, |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 662 | IRemoteAnimationFinishedCallback finishedCallback) { |
| 663 | |
| 664 | } |
| 665 | |
| 666 | @Override |
| 667 | public void onAnimationCancelled() { |
| 668 | |
| 669 | } |
| 670 | }, 0, 0)); |
| 671 | mActivity.updateOptionsLocked(opts); |
| 672 | assertNotNull(mActivity.takeOptionsLocked(true /* fromClient */)); |
| 673 | assertNotNull(mActivity.pendingOptions); |
| 674 | |
| 675 | mActivity.updateOptionsLocked(ActivityOptions.makeBasic()); |
| 676 | assertNotNull(mActivity.takeOptionsLocked(false /* fromClient */)); |
| 677 | assertNull(mActivity.pendingOptions); |
| 678 | } |
| 679 | |
Louis Chang | 6a9be16 | 2019-07-15 10:41:32 +0800 | [diff] [blame] | 680 | @Test |
| 681 | public void testCanLaunchHomeActivityFromChooser() { |
| 682 | ComponentName chooserComponent = ComponentName.unflattenFromString( |
| 683 | Resources.getSystem().getString(R.string.config_chooserActivity)); |
| 684 | ActivityRecord chooserActivity = new ActivityBuilder(mService).setComponent( |
| 685 | chooserComponent).build(); |
| 686 | assertThat(mActivity.canLaunchHomeActivity(NOBODY_UID, chooserActivity)).isTrue(); |
| 687 | } |
| 688 | |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 689 | /** |
| 690 | * Verify that an {@link ActivityRecord} reports that it has saved state after creation, and |
| 691 | * that it is cleared after activity is resumed. |
| 692 | */ |
| 693 | @Test |
| 694 | public void testHasSavedState() { |
| 695 | assertTrue(mActivity.hasSavedState()); |
| 696 | |
| 697 | ActivityRecord.activityResumedLocked(mActivity.appToken); |
| 698 | assertFalse(mActivity.hasSavedState()); |
| 699 | assertNull(mActivity.getSavedState()); |
| 700 | } |
| 701 | |
| 702 | /** Verify the behavior of {@link ActivityRecord#setSavedState(Bundle)}. */ |
| 703 | @Test |
| 704 | public void testUpdateSavedState() { |
| 705 | mActivity.setSavedState(null /* savedState */); |
| 706 | assertFalse(mActivity.hasSavedState()); |
| 707 | assertNull(mActivity.getSavedState()); |
| 708 | |
| 709 | final Bundle savedState = new Bundle(); |
| 710 | savedState.putString("test", "string"); |
| 711 | mActivity.setSavedState(savedState); |
| 712 | assertTrue(mActivity.hasSavedState()); |
| 713 | assertEquals(savedState, mActivity.getSavedState()); |
| 714 | } |
| 715 | |
| 716 | /** Verify the correct updates of saved state when activity client reports stop. */ |
| 717 | @Test |
| 718 | public void testUpdateSavedState_activityStopped() { |
| 719 | final Bundle savedState = new Bundle(); |
| 720 | savedState.putString("test", "string"); |
| 721 | final PersistableBundle persistentSavedState = new PersistableBundle(); |
| 722 | persistentSavedState.putString("persist", "string"); |
| 723 | |
| 724 | // Set state to STOPPING, or ActivityRecord#activityStoppedLocked() call will be ignored. |
| 725 | mActivity.setState(STOPPING, "test"); |
| 726 | mActivity.activityStoppedLocked(savedState, persistentSavedState, "desc"); |
| 727 | assertTrue(mActivity.hasSavedState()); |
| 728 | assertEquals(savedState, mActivity.getSavedState()); |
| 729 | assertEquals(persistentSavedState, mActivity.getPersistentSavedState()); |
| 730 | |
| 731 | // Sending 'null' for saved state can only happen due to timeout, so previously stored saved |
| 732 | // states should not be overridden. |
| 733 | mActivity.setState(STOPPING, "test"); |
| 734 | mActivity.activityStoppedLocked(null /* savedState */, null /* persistentSavedState */, |
| 735 | "desc"); |
| 736 | assertTrue(mActivity.hasSavedState()); |
| 737 | assertEquals(savedState, mActivity.getSavedState()); |
| 738 | assertEquals(persistentSavedState, mActivity.getPersistentSavedState()); |
| 739 | } |
| 740 | |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 741 | /** |
| 742 | * Verify that activity finish request is not performed if activity is finishing or is in |
| 743 | * incorrect state. |
| 744 | */ |
| 745 | @Test |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 746 | public void testFinishActivityIfPossible_cancelled() { |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 747 | // Mark activity as finishing |
| 748 | mActivity.finishing = true; |
| 749 | assertEquals("Duplicate finish request must be ignored", FINISH_RESULT_CANCELLED, |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 750 | mActivity.finishIfPossible("test", false /* oomAdj */)); |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 751 | assertTrue(mActivity.finishing); |
| 752 | assertTrue(mActivity.isInStackLocked()); |
| 753 | |
| 754 | // Remove activity from task |
| 755 | mActivity.finishing = false; |
| 756 | mActivity.setTask(null); |
| 757 | assertEquals("Activity outside of task/stack cannot be finished", FINISH_RESULT_CANCELLED, |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 758 | mActivity.finishIfPossible("test", false /* oomAdj */)); |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 759 | assertFalse(mActivity.finishing); |
| 760 | } |
| 761 | |
| 762 | /** |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 763 | * Verify that activity finish request is placed, but not executed immediately if activity is |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 764 | * not ready yet. |
| 765 | */ |
| 766 | @Test |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 767 | public void testFinishActivityIfPossible_requested() { |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 768 | mActivity.finishing = false; |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 769 | assertEquals("Currently resumed activity must be prepared removal", FINISH_RESULT_REQUESTED, |
| 770 | mActivity.finishIfPossible("test", false /* oomAdj */)); |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 771 | assertTrue(mActivity.finishing); |
| 772 | assertTrue(mActivity.isInStackLocked()); |
| 773 | |
| 774 | // First request to finish activity must schedule a "destroy" request to the client. |
| 775 | // Activity must be removed from history after the client reports back or after timeout. |
| 776 | mActivity.finishing = false; |
| 777 | mActivity.setState(STOPPED, "test"); |
| 778 | assertEquals("Activity outside of task/stack cannot be finished", FINISH_RESULT_REQUESTED, |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 779 | mActivity.finishIfPossible("test", false /* oomAdj */)); |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 780 | assertTrue(mActivity.finishing); |
| 781 | assertTrue(mActivity.isInStackLocked()); |
| 782 | } |
| 783 | |
| 784 | /** |
| 785 | * Verify that activity finish request removes activity immediately if it's ready. |
| 786 | */ |
| 787 | @Test |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 788 | public void testFinishActivityIfPossible_removed() { |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 789 | // Prepare the activity record to be ready for immediate removal. It should be invisible and |
| 790 | // have no process. Otherwise, request to finish it will send a message to client first. |
| 791 | mActivity.setState(STOPPED, "test"); |
| 792 | mActivity.visible = false; |
| 793 | mActivity.nowVisible = false; |
| 794 | // Set process to 'null' to allow immediate removal, but don't call mActivity.setProcess() - |
| 795 | // this will cause NPE when updating task's process. |
| 796 | mActivity.app = null; |
| 797 | assertEquals("Activity outside of task/stack cannot be finished", FINISH_RESULT_REMOVED, |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 798 | mActivity.finishIfPossible("test", false /* oomAdj */)); |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 799 | assertTrue(mActivity.finishing); |
| 800 | assertFalse(mActivity.isInStackLocked()); |
| 801 | } |
| 802 | |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 803 | /** |
Riddle Hsu | 1e7ba58 | 2019-08-26 19:18:34 +0800 | [diff] [blame] | 804 | * Verify that when finishing the top focused activity on top display, the stack order will be |
| 805 | * changed by adjusting focus. |
| 806 | */ |
| 807 | @Test |
| 808 | public void testFinishActivityIfPossible_adjustStackOrder() { |
| 809 | // Prepare the stacks with order (top to bottom): mStack, stack1, stack2. |
| 810 | final ActivityStack stack1 = new StackBuilder(mRootActivityContainer).build(); |
| 811 | mStack.moveToFront("test"); |
| 812 | // The stack2 is needed here for moving back to simulate the |
| 813 | // {@link ActivityDisplay#mPreferredTopFocusableStack} is cleared, so |
| 814 | // {@link ActivityDisplay#getFocusedStack} will rely on the order of focusable-and-visible |
| 815 | // stacks. Then when mActivity is finishing, its stack will be invisible (no running |
| 816 | // activities in the stack) that is the key condition to verify. |
| 817 | final ActivityStack stack2 = new StackBuilder(mRootActivityContainer).build(); |
| 818 | stack2.moveToBack("test", stack2.getChildAt(0)); |
| 819 | |
| 820 | assertTrue(mStack.isTopStackOnDisplay()); |
| 821 | |
| 822 | mActivity.setState(RESUMED, "test"); |
| 823 | mActivity.finishIfPossible(0 /* resultCode */, null /* resultData */, "test", |
Louis Chang | 7b03ad9 | 2019-08-21 12:32:33 +0800 | [diff] [blame] | 824 | false /* oomAdj */); |
Riddle Hsu | 1e7ba58 | 2019-08-26 19:18:34 +0800 | [diff] [blame] | 825 | |
| 826 | assertTrue(stack1.isTopStackOnDisplay()); |
| 827 | } |
| 828 | |
| 829 | /** |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 830 | * Verify that resumed activity is paused due to finish request. |
| 831 | */ |
| 832 | @Test |
| 833 | public void testFinishActivityIfPossible_resumedStartsPausing() { |
| 834 | mActivity.finishing = false; |
| 835 | mActivity.setState(RESUMED, "test"); |
| 836 | assertEquals("Currently resumed activity must be paused before removal", |
| 837 | FINISH_RESULT_REQUESTED, mActivity.finishIfPossible("test", false /* oomAdj */)); |
| 838 | assertEquals(PAUSING, mActivity.getState()); |
| 839 | verify(mActivity).setVisibility(eq(false)); |
| 840 | verify(mActivity.getDisplay().mDisplayContent) |
| 841 | .prepareAppTransition(eq(TRANSIT_TASK_CLOSE), eq(false) /* alwaysKeepCurrent */); |
| 842 | } |
| 843 | |
| 844 | /** |
| 845 | * Verify that finish request will be completed immediately for non-resumed activity. |
| 846 | */ |
| 847 | @Test |
| 848 | public void testFinishActivityIfPossible_nonResumedFinishCompletesImmediately() { |
| 849 | final ActivityState[] states = {INITIALIZING, STARTED, PAUSED, STOPPING, STOPPED}; |
| 850 | for (ActivityState state : states) { |
| 851 | mActivity.finishing = false; |
| 852 | mActivity.setState(state, "test"); |
| 853 | reset(mActivity); |
| 854 | assertEquals("Finish must be requested", FINISH_RESULT_REQUESTED, |
| 855 | mActivity.finishIfPossible("test", false /* oomAdj */)); |
| 856 | verify(mActivity).completeFinishing(anyString()); |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | /** |
| 861 | * Verify that finishing will not be completed in PAUSING state. |
| 862 | */ |
| 863 | @Test |
| 864 | public void testFinishActivityIfPossible_pausing() { |
| 865 | mActivity.finishing = false; |
| 866 | mActivity.setState(PAUSING, "test"); |
| 867 | assertEquals("Finish must be requested", FINISH_RESULT_REQUESTED, |
| 868 | mActivity.finishIfPossible("test", false /* oomAdj */)); |
| 869 | verify(mActivity, never()).completeFinishing(anyString()); |
| 870 | } |
| 871 | |
| 872 | /** |
| 873 | * Verify that finish request for resumed activity will prepare an app transition but not |
| 874 | * execute it immediately. |
| 875 | */ |
| 876 | @Test |
| 877 | public void testFinishActivityIfPossible_visibleResumedPreparesAppTransition() { |
| 878 | mActivity.finishing = false; |
| 879 | mActivity.visible = true; |
| 880 | mActivity.setState(RESUMED, "test"); |
| 881 | mActivity.finishIfPossible("test", false /* oomAdj */); |
| 882 | |
| 883 | verify(mActivity).setVisibility(eq(false)); |
| 884 | verify(mActivity.getDisplay().mDisplayContent) |
| 885 | .prepareAppTransition(eq(TRANSIT_TASK_CLOSE), eq(false) /* alwaysKeepCurrent */); |
| 886 | verify(mActivity.getDisplay().mDisplayContent, never()).executeAppTransition(); |
| 887 | } |
| 888 | |
| 889 | /** |
| 890 | * Verify that finish request for paused activity will prepare and execute an app transition. |
| 891 | */ |
| 892 | @Test |
| 893 | public void testFinishActivityIfPossible_visibleNotResumedExecutesAppTransition() { |
| 894 | mActivity.finishing = false; |
| 895 | mActivity.visible = true; |
| 896 | mActivity.setState(PAUSED, "test"); |
| 897 | mActivity.finishIfPossible("test", false /* oomAdj */); |
| 898 | |
Andrii Kulian | 149d9ad3 | 2019-08-23 15:04:17 -0700 | [diff] [blame] | 899 | verify(mActivity, atLeast(1)).setVisibility(eq(false)); |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 900 | verify(mActivity.getDisplay().mDisplayContent) |
| 901 | .prepareAppTransition(eq(TRANSIT_TASK_CLOSE), eq(false) /* alwaysKeepCurrent */); |
| 902 | verify(mActivity.getDisplay().mDisplayContent).executeAppTransition(); |
| 903 | } |
| 904 | |
| 905 | /** |
| 906 | * Verify that finish request for non-visible activity will not prepare any transitions. |
| 907 | */ |
| 908 | @Test |
| 909 | public void testFinishActivityIfPossible_nonVisibleNoAppTransition() { |
| 910 | // Put an activity on top of test activity to make it invisible and prevent us from |
| 911 | // accidentally resuming the topmost one again. |
| 912 | new ActivityBuilder(mService).build(); |
| 913 | mActivity.visible = false; |
| 914 | mActivity.setState(STOPPED, "test"); |
| 915 | |
| 916 | mActivity.finishIfPossible("test", false /* oomAdj */); |
| 917 | |
| 918 | verify(mActivity.getDisplay().mDisplayContent, never()) |
| 919 | .prepareAppTransition(eq(TRANSIT_TASK_CLOSE), eq(false) /* alwaysKeepCurrent */); |
| 920 | } |
| 921 | |
| 922 | /** |
| 923 | * Verify that complete finish request for non-finishing activity is invalid. |
| 924 | */ |
| 925 | @Test(expected = IllegalArgumentException.class) |
| 926 | public void testCompleteFinishing_failNotFinishing() { |
| 927 | mActivity.finishing = false; |
| 928 | mActivity.completeFinishing("test"); |
| 929 | } |
| 930 | |
| 931 | /** |
| 932 | * Verify that complete finish request for resumed activity is invalid. |
| 933 | */ |
| 934 | @Test(expected = IllegalArgumentException.class) |
| 935 | public void testCompleteFinishing_failResumed() { |
| 936 | mActivity.setState(RESUMED, "test"); |
| 937 | mActivity.completeFinishing("test"); |
| 938 | } |
| 939 | |
| 940 | /** |
| 941 | * Verify that finish request for pausing activity must be a no-op - activity will finish |
| 942 | * once it completes pausing. |
| 943 | */ |
| 944 | @Test |
| 945 | public void testCompleteFinishing_pausing() { |
| 946 | mActivity.setState(PAUSING, "test"); |
| 947 | mActivity.finishing = true; |
| 948 | |
| 949 | assertEquals("Activity must not be removed immediately - waiting for paused", |
| 950 | mActivity, mActivity.completeFinishing("test")); |
| 951 | assertEquals(PAUSING, mActivity.getState()); |
| 952 | verify(mActivity, never()).destroyIfPossible(anyString()); |
| 953 | } |
| 954 | |
| 955 | /** |
| 956 | * Verify that complete finish request for visible activity must be delayed before the next one |
| 957 | * becomes visible. |
| 958 | */ |
| 959 | @Test |
| 960 | public void testCompleteFinishing_waitForNextVisible() { |
| 961 | final ActivityRecord topActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 962 | topActivity.visible = true; |
| 963 | topActivity.nowVisible = true; |
| 964 | topActivity.finishing = true; |
| 965 | topActivity.setState(PAUSED, "true"); |
| 966 | // Mark the bottom activity as not visible, so that we will wait for it before removing |
| 967 | // the top one. |
| 968 | mActivity.visible = false; |
| 969 | mActivity.nowVisible = false; |
| 970 | mActivity.setState(STOPPED, "test"); |
| 971 | |
| 972 | assertEquals("Activity must not be removed immediately - waiting for next visible", |
| 973 | topActivity, topActivity.completeFinishing("test")); |
| 974 | assertEquals("Activity must be stopped to make next one visible", STOPPING, |
| 975 | topActivity.getState()); |
| 976 | assertTrue("Activity must be stopped to make next one visible", |
| 977 | topActivity.mStackSupervisor.mStoppingActivities.contains(topActivity)); |
| 978 | verify(topActivity, never()).destroyIfPossible(anyString()); |
| 979 | } |
| 980 | |
| 981 | /** |
| 982 | * Verify that complete finish request for invisible activity must not be delayed. |
| 983 | */ |
| 984 | @Test |
| 985 | public void testCompleteFinishing_noWaitForNextVisible_alreadyInvisible() { |
| 986 | final ActivityRecord topActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 987 | topActivity.visible = false; |
| 988 | topActivity.nowVisible = false; |
| 989 | topActivity.finishing = true; |
| 990 | topActivity.setState(PAUSED, "true"); |
| 991 | // Mark the bottom activity as not visible, so that we would wait for it before removing |
| 992 | // the top one. |
| 993 | mActivity.visible = false; |
| 994 | mActivity.nowVisible = false; |
| 995 | mActivity.setState(STOPPED, "test"); |
| 996 | |
| 997 | topActivity.completeFinishing("test"); |
| 998 | |
| 999 | verify(topActivity).destroyIfPossible(anyString()); |
| 1000 | } |
| 1001 | |
| 1002 | /** |
| 1003 | * Verify that paused finishing activity will be added to finishing list and wait for next one |
| 1004 | * to idle. |
| 1005 | */ |
| 1006 | @Test |
| 1007 | public void testCompleteFinishing_waitForIdle() { |
| 1008 | final ActivityRecord topActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 1009 | topActivity.visible = true; |
| 1010 | topActivity.nowVisible = true; |
| 1011 | topActivity.finishing = true; |
| 1012 | topActivity.setState(PAUSED, "true"); |
| 1013 | // Mark the bottom activity as already visible, so that there is no need to wait for it. |
| 1014 | mActivity.visible = true; |
| 1015 | mActivity.nowVisible = true; |
| 1016 | mActivity.setState(RESUMED, "test"); |
| 1017 | |
| 1018 | topActivity.completeFinishing("test"); |
| 1019 | |
| 1020 | verify(topActivity).addToFinishingAndWaitForIdle(); |
| 1021 | } |
| 1022 | |
| 1023 | /** |
| 1024 | * Verify that complete finish request for visible activity must not be delayed if the next one |
| 1025 | * is already visible and it's not the focused stack. |
| 1026 | */ |
| 1027 | @Test |
| 1028 | public void testCompleteFinishing_noWaitForNextVisible_stopped() { |
| 1029 | final ActivityRecord topActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 1030 | topActivity.visible = false; |
| 1031 | topActivity.nowVisible = false; |
| 1032 | topActivity.finishing = true; |
| 1033 | topActivity.setState(STOPPED, "true"); |
| 1034 | // Mark the bottom activity as already visible, so that there is no need to wait for it. |
| 1035 | mActivity.visible = true; |
| 1036 | mActivity.nowVisible = true; |
| 1037 | mActivity.setState(RESUMED, "test"); |
| 1038 | |
| 1039 | topActivity.completeFinishing("test"); |
| 1040 | |
| 1041 | verify(topActivity).destroyIfPossible(anyString()); |
| 1042 | } |
| 1043 | |
| 1044 | /** |
| 1045 | * Verify that complete finish request for visible activity must not be delayed if the next one |
| 1046 | * is already visible and it's not the focused stack. |
| 1047 | */ |
| 1048 | @Test |
| 1049 | public void testCompleteFinishing_noWaitForNextVisible_nonFocusedStack() { |
| 1050 | final ActivityRecord topActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 1051 | topActivity.visible = true; |
| 1052 | topActivity.nowVisible = true; |
| 1053 | topActivity.finishing = true; |
| 1054 | topActivity.setState(PAUSED, "true"); |
| 1055 | // Mark the bottom activity as already visible, so that there is no need to wait for it. |
| 1056 | mActivity.visible = true; |
| 1057 | mActivity.nowVisible = true; |
| 1058 | mActivity.setState(RESUMED, "test"); |
| 1059 | |
| 1060 | // Add another stack to become focused and make the activity there visible. This way it |
| 1061 | // simulates finishing in non-focused stack in split-screen. |
| 1062 | final ActivityStack stack = new StackBuilder(mRootActivityContainer).build(); |
| 1063 | stack.getChildAt(0).getChildAt(0).nowVisible = true; |
lumark | 50b8154 | 2019-09-01 23:11:49 +0800 | [diff] [blame] | 1064 | stack.getChildAt(0).getChildAt(0).visible = true; |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 1065 | |
| 1066 | topActivity.completeFinishing("test"); |
| 1067 | |
| 1068 | verify(topActivity).destroyIfPossible(anyString()); |
| 1069 | } |
| 1070 | |
| 1071 | /** |
| 1072 | * Verify destroy activity request completes successfully. |
| 1073 | */ |
| 1074 | @Test |
| 1075 | public void testDestroyIfPossible() { |
| 1076 | doReturn(false).when(mRootActivityContainer).resumeFocusedStacksTopActivities(); |
| 1077 | spyOn(mStack); |
| 1078 | mActivity.destroyIfPossible("test"); |
| 1079 | |
| 1080 | assertEquals(DESTROYING, mActivity.getState()); |
| 1081 | assertTrue(mActivity.finishing); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1082 | verify(mActivity).destroyImmediately(eq(true) /* removeFromApp */, anyString()); |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | /** |
| 1086 | * Verify that complete finish request for visible activity must not destroy it immediately if |
| 1087 | * it is the last running activity on a display with a home stack. We must wait for home |
| 1088 | * activity to come up to avoid a black flash in this case. |
| 1089 | */ |
| 1090 | @Test |
| 1091 | public void testDestroyIfPossible_lastActivityAboveEmptyHomeStack() { |
| 1092 | // Empty the home stack. |
| 1093 | final ActivityStack homeStack = mActivity.getDisplay().getHomeStack(); |
| 1094 | for (TaskRecord t : homeStack.getAllTasks()) { |
| 1095 | homeStack.removeTask(t, "test", REMOVE_TASK_MODE_DESTROYING); |
| 1096 | } |
| 1097 | mActivity.finishing = true; |
| 1098 | doReturn(false).when(mRootActivityContainer).resumeFocusedStacksTopActivities(); |
| 1099 | spyOn(mStack); |
| 1100 | |
| 1101 | // Try to destroy the last activity above the home stack. |
| 1102 | mActivity.destroyIfPossible("test"); |
| 1103 | |
| 1104 | // Verify that the activity was not actually destroyed, but waits for next one to come up |
| 1105 | // instead. |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1106 | verify(mActivity, never()).destroyImmediately(eq(true) /* removeFromApp */, anyString()); |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 1107 | assertEquals(FINISHING, mActivity.getState()); |
| 1108 | assertTrue(mActivity.mStackSupervisor.mFinishingActivities.contains(mActivity)); |
| 1109 | } |
| 1110 | |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1111 | /** |
| 1112 | * Test that the activity will be moved to destroying state and the message to destroy will be |
| 1113 | * sent to the client. |
| 1114 | */ |
| 1115 | @Test |
| 1116 | public void testDestroyImmediately_hadApp_finishing() { |
| 1117 | mActivity.finishing = true; |
| 1118 | mActivity.destroyImmediately(false /* removeFromApp */, "test"); |
| 1119 | |
| 1120 | assertEquals(DESTROYING, mActivity.getState()); |
| 1121 | } |
| 1122 | |
| 1123 | /** |
| 1124 | * Test that the activity will be moved to destroyed state immediately if it was not marked as |
| 1125 | * finishing before {@link ActivityRecord#destroyImmediately(boolean, String)}. |
| 1126 | */ |
| 1127 | @Test |
| 1128 | public void testDestroyImmediately_hadApp_notFinishing() { |
| 1129 | mActivity.finishing = false; |
| 1130 | mActivity.destroyImmediately(false /* removeFromApp */, "test"); |
| 1131 | |
| 1132 | assertEquals(DESTROYED, mActivity.getState()); |
| 1133 | } |
| 1134 | |
| 1135 | /** |
| 1136 | * Test that an activity with no process attached and that is marked as finishing will be |
| 1137 | * removed from task when {@link ActivityRecord#destroyImmediately(boolean, String)} is called. |
| 1138 | */ |
| 1139 | @Test |
| 1140 | public void testDestroyImmediately_noApp_finishing() { |
| 1141 | mActivity.app = null; |
| 1142 | mActivity.finishing = true; |
| 1143 | final TaskRecord task = mActivity.getTaskRecord(); |
| 1144 | |
| 1145 | mActivity.destroyImmediately(false /* removeFromApp */, "test"); |
| 1146 | |
| 1147 | assertEquals(DESTROYED, mActivity.getState()); |
| 1148 | assertNull(mActivity.getTaskRecord()); |
| 1149 | assertEquals(0, task.getChildCount()); |
| 1150 | } |
| 1151 | |
| 1152 | /** |
| 1153 | * Test that an activity with no process attached and that is not marked as finishing will be |
| 1154 | * marked as DESTROYED but not removed from task. |
| 1155 | */ |
| 1156 | @Test |
| 1157 | public void testDestroyImmediately_noApp_notFinishing() { |
| 1158 | mActivity.app = null; |
| 1159 | mActivity.finishing = false; |
| 1160 | final TaskRecord task = mActivity.getTaskRecord(); |
| 1161 | |
| 1162 | mActivity.destroyImmediately(false /* removeFromApp */, "test"); |
| 1163 | |
| 1164 | assertEquals(DESTROYED, mActivity.getState()); |
| 1165 | assertEquals(task, mActivity.getTaskRecord()); |
| 1166 | assertEquals(1, task.getChildCount()); |
| 1167 | } |
| 1168 | |
| 1169 | /** |
| 1170 | * Test that an activity will not be destroyed if it is marked as non-destroyable. |
| 1171 | */ |
| 1172 | @Test |
| 1173 | public void testSafelyDestroy_nonDestroyable() { |
| 1174 | doReturn(false).when(mActivity).isDestroyable(); |
| 1175 | |
| 1176 | mActivity.safelyDestroy("test"); |
| 1177 | |
| 1178 | verify(mActivity, never()).destroyImmediately(eq(true) /* removeFromApp */, anyString()); |
| 1179 | } |
| 1180 | |
| 1181 | /** |
| 1182 | * Test that an activity will not be destroyed if it is marked as non-destroyable. |
| 1183 | */ |
| 1184 | @Test |
| 1185 | public void testSafelyDestroy_destroyable() { |
| 1186 | doReturn(true).when(mActivity).isDestroyable(); |
| 1187 | |
| 1188 | mActivity.safelyDestroy("test"); |
| 1189 | |
| 1190 | verify(mActivity).destroyImmediately(eq(true) /* removeFromApp */, anyString()); |
| 1191 | } |
| 1192 | |
| 1193 | @Test |
| 1194 | public void testRemoveFromHistory() { |
| 1195 | final ActivityStack stack = mActivity.getActivityStack(); |
| 1196 | final TaskRecord task = mActivity.getTaskRecord(); |
| 1197 | |
| 1198 | mActivity.removeFromHistory("test"); |
| 1199 | |
| 1200 | assertEquals(DESTROYED, mActivity.getState()); |
| 1201 | assertNull(mActivity.app); |
| 1202 | assertNull(mActivity.getTaskRecord()); |
| 1203 | assertEquals(0, task.getChildCount()); |
| 1204 | assertNull(task.getStack()); |
| 1205 | assertEquals(0, stack.getChildCount()); |
| 1206 | } |
| 1207 | |
| 1208 | /** |
| 1209 | * Test that it's not allowed to call {@link ActivityRecord#destroyed(String)} if activity is |
| 1210 | * not in destroying or destroyed state. |
| 1211 | */ |
| 1212 | @Test(expected = IllegalStateException.class) |
| 1213 | public void testDestroyed_notDestroying() { |
| 1214 | mActivity.setState(STOPPED, "test"); |
| 1215 | mActivity.destroyed("test"); |
| 1216 | } |
| 1217 | |
| 1218 | /** |
| 1219 | * Test that {@link ActivityRecord#destroyed(String)} can be called if an activity is destroying |
| 1220 | */ |
| 1221 | @Test |
| 1222 | public void testDestroyed_destroying() { |
| 1223 | mActivity.setState(DESTROYING, "test"); |
| 1224 | mActivity.destroyed("test"); |
| 1225 | |
| 1226 | verify(mActivity).removeFromHistory(anyString()); |
| 1227 | } |
| 1228 | |
| 1229 | /** |
| 1230 | * Test that {@link ActivityRecord#destroyed(String)} can be called if an activity is destroyed. |
| 1231 | */ |
| 1232 | @Test |
| 1233 | public void testDestroyed_destroyed() { |
| 1234 | mActivity.setState(DESTROYED, "test"); |
| 1235 | mActivity.destroyed("test"); |
| 1236 | |
| 1237 | verify(mActivity).removeFromHistory(anyString()); |
| 1238 | } |
| 1239 | |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 1240 | /** Setup {@link #mActivity} as a size-compat-mode-able activity without fixed orientation. */ |
| 1241 | private void prepareFixedAspectRatioUnresizableActivity() { |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 1242 | setupDisplayContentForCompatDisplayInsets(); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 1243 | mActivity.info.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 1244 | mActivity.info.maxAspectRatio = 1.5f; |
Evan Rosky | 5572953 | 2019-08-09 20:01:00 -0700 | [diff] [blame] | 1245 | mActivity.visible = true; |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 1246 | ensureActivityConfiguration(); |
| 1247 | } |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 1248 | |
| 1249 | private void setupDisplayContentForCompatDisplayInsets() { |
| 1250 | final Rect displayBounds = mStack.getDisplay().getBounds(); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 1251 | setupDisplayAndParentSize(displayBounds.width(), displayBounds.height()); |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | private DisplayContent setupDisplayAndParentSize(int width, int height) { |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 1255 | final DisplayContent displayContent = mStack.getDisplay().mDisplayContent; |
| 1256 | displayContent.mBaseDisplayWidth = width; |
| 1257 | displayContent.mBaseDisplayHeight = height; |
Evan Rosky | 5572953 | 2019-08-09 20:01:00 -0700 | [diff] [blame] | 1258 | final Configuration c = |
| 1259 | new Configuration(mStack.getDisplay().getRequestedOverrideConfiguration()); |
| 1260 | c.windowConfiguration.setBounds(new Rect(0, 0, width, height)); |
| 1261 | c.windowConfiguration.setAppBounds(0, 0, width, height); |
| 1262 | c.windowConfiguration.setRotation(ROTATION_0); |
| 1263 | mStack.getDisplay().onRequestedOverrideConfigurationChanged(c); |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 1264 | return displayContent; |
| 1265 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1266 | } |