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 | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 19 | import static android.view.Display.DEFAULT_DISPLAY; |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame^] | 20 | import static android.view.Surface.ROTATION_0; |
| 21 | import static android.view.Surface.ROTATION_90; |
Bryce Lee | 0bd8d42 | 2018-01-09 09:45:57 -0800 | [diff] [blame] | 22 | |
Tadashi G. Takaoka | a7a6695 | 2018-11-16 15:04:21 +0900 | [diff] [blame] | 23 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.any; |
Garfield Tan | 36a69ad | 2019-01-16 17:08:23 -0800 | [diff] [blame] | 24 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyInt; |
Tadashi G. Takaoka | a7a6695 | 2018-11-16 15:04:21 +0900 | [diff] [blame] | 25 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 26 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 27 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; |
Garfield Tan | 36a69ad | 2019-01-16 17:08:23 -0800 | [diff] [blame] | 28 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.eq; |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 29 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 30 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 31 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; |
Tadashi G. Takaoka | a7a6695 | 2018-11-16 15:04:21 +0900 | [diff] [blame] | 32 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.when; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 33 | import static com.android.server.wm.ActivityStack.ActivityState.INITIALIZING; |
| 34 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSING; |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 35 | import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 36 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPED; |
| 37 | import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_MOVING; |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 38 | import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_INVISIBLE; |
| 39 | import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE; |
| 40 | import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 41 | |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 42 | import static org.junit.Assert.assertEquals; |
Bryce Lee | 1533b2b | 2017-09-14 17:06:41 -0700 | [diff] [blame] | 43 | import static org.junit.Assert.assertFalse; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 44 | import static org.junit.Assert.assertNotEquals; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 45 | import static org.junit.Assert.assertNotNull; |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 46 | import static org.junit.Assert.assertNull; |
Bryce Lee | 1533b2b | 2017-09-14 17:06:41 -0700 | [diff] [blame] | 47 | import static org.junit.Assert.assertTrue; |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 48 | import static org.mockito.ArgumentMatchers.anyString; |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 49 | |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 50 | import android.app.ActivityManager; |
| 51 | import android.app.ActivityManagerInternal; |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 52 | import android.app.ActivityOptions; |
Garfield Tan | 36a69ad | 2019-01-16 17:08:23 -0800 | [diff] [blame] | 53 | import android.app.servertransaction.ActivityConfigurationChangeItem; |
Bryce Lee | 0bd8d42 | 2018-01-09 09:45:57 -0800 | [diff] [blame] | 54 | import android.app.servertransaction.ClientTransaction; |
| 55 | import android.app.servertransaction.PauseActivityItem; |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 56 | import android.content.pm.ActivityInfo; |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 57 | import android.content.res.Configuration; |
Andrii Kulian | 3a1619d | 2017-07-07 14:38:09 -0700 | [diff] [blame] | 58 | import android.graphics.Rect; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 59 | import android.platform.test.annotations.Presubmit; |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 60 | import android.util.MergedConfiguration; |
Andrii Kulian | 0447068 | 2018-01-10 15:32:31 -0800 | [diff] [blame] | 61 | import android.util.MutableBoolean; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 62 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 63 | import androidx.test.filters.MediumTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 64 | |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame^] | 65 | import com.android.server.wm.utils.WmDisplayCutout; |
| 66 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 67 | import org.junit.Before; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 68 | import org.junit.Test; |
Andrii Kulian | 0447068 | 2018-01-10 15:32:31 -0800 | [diff] [blame] | 69 | import org.mockito.invocation.InvocationOnMock; |
Bryce Lee | 0bd8d42 | 2018-01-09 09:45:57 -0800 | [diff] [blame] | 70 | |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 71 | import java.util.concurrent.TimeUnit; |
| 72 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 73 | /** |
| 74 | * Tests for the {@link ActivityRecord} class. |
| 75 | * |
| 76 | * Build/Install/Run: |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 77 | * atest WmTests:ActivityRecordTests |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 78 | */ |
| 79 | @MediumTest |
Bryce Lee | 3115bdf | 2017-04-05 08:39:40 -0700 | [diff] [blame] | 80 | @Presubmit |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 81 | public class ActivityRecordTests extends ActivityTestsBase { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 82 | private TestActivityStack mStack; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 83 | private TaskRecord mTask; |
| 84 | private ActivityRecord mActivity; |
| 85 | |
| 86 | @Before |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 87 | public void setUp() throws Exception { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 88 | mStack = (TestActivityStack) new StackBuilder(mRootActivityContainer).build(); |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 89 | mTask = mStack.getChildAt(0); |
| 90 | mActivity = mTask.getTopActivity(); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 91 | |
| 92 | doReturn(false).when(mService).isBooting(); |
| 93 | doReturn(true).when(mService).isBooted(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 96 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 97 | public void testStackCleanupOnClearingTask() { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 98 | mActivity.setTask(null); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 99 | assertEquals(mStack.onActivityRemovedFromStackInvocationCount(), 1); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 103 | public void testStackCleanupOnActivityRemoval() { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 104 | mTask.removeActivity(mActivity); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 105 | assertEquals(mStack.onActivityRemovedFromStackInvocationCount(), 1); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 109 | public void testStackCleanupOnTaskRemoval() { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 110 | mStack.removeTask(mTask, null /*reason*/, REMOVE_TASK_MODE_MOVING); |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 111 | // Stack should be gone on task removal. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 112 | assertNull(mService.mRootActivityContainer.getStack(mStack.mStackId)); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 116 | public void testNoCleanupMovingActivityInSameStack() { |
Bryce Lee | 18d5159 | 2017-10-25 10:22:19 -0700 | [diff] [blame] | 117 | final TaskRecord newTask = new TaskBuilder(mService.mStackSupervisor).setStack(mStack) |
| 118 | .build(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 119 | mActivity.reparent(newTask, 0, null /*reason*/); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 120 | assertEquals(mStack.onActivityRemovedFromStackInvocationCount(), 0); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 121 | } |
Andrii Kulian | 3a1619d | 2017-07-07 14:38:09 -0700 | [diff] [blame] | 122 | |
Andreas Gampe | cea9e6d | 2018-02-22 18:06:44 -0800 | [diff] [blame] | 123 | @Test |
Bryce Lee | 0bd8d42 | 2018-01-09 09:45:57 -0800 | [diff] [blame] | 124 | public void testPausingWhenVisibleFromStopped() throws Exception { |
Andrii Kulian | 0447068 | 2018-01-10 15:32:31 -0800 | [diff] [blame] | 125 | final MutableBoolean pauseFound = new MutableBoolean(false); |
| 126 | doAnswer((InvocationOnMock invocationOnMock) -> { |
| 127 | final ClientTransaction transaction = invocationOnMock.getArgument(0); |
| 128 | if (transaction.getLifecycleStateRequest() instanceof PauseActivityItem) { |
| 129 | pauseFound.value = true; |
Bryce Lee | 0bd8d42 | 2018-01-09 09:45:57 -0800 | [diff] [blame] | 130 | } |
Andrii Kulian | 0447068 | 2018-01-10 15:32:31 -0800 | [diff] [blame] | 131 | return null; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 132 | }).when(mActivity.app.getThread()).scheduleTransaction(any()); |
Bryce Lee | d939cf0 | 2018-03-12 09:04:44 -0700 | [diff] [blame] | 133 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 134 | mActivity.setState(STOPPED, "testPausingWhenVisibleFromStopped"); |
Bryce Lee | 0bd8d42 | 2018-01-09 09:45:57 -0800 | [diff] [blame] | 135 | |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 136 | // The activity is in the focused stack so it should be resumed. |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 137 | mActivity.makeVisibleIfNeeded(null /* starting */, true /* reportToClient */); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 138 | assertTrue(mActivity.isState(RESUMED)); |
Bryce Lee | d939cf0 | 2018-03-12 09:04:44 -0700 | [diff] [blame] | 139 | assertFalse(pauseFound.value); |
Andrii Kulian | 0447068 | 2018-01-10 15:32:31 -0800 | [diff] [blame] | 140 | |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 141 | // Make the activity non focusable |
| 142 | mActivity.setState(STOPPED, "testPausingWhenVisibleFromStopped"); |
| 143 | doReturn(false).when(mActivity).isFocusable(); |
Bryce Lee | d939cf0 | 2018-03-12 09:04:44 -0700 | [diff] [blame] | 144 | |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 145 | // If the activity is not focusable, it should move to paused. |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 146 | mActivity.makeVisibleIfNeeded(null /* starting */, true /* reportToClient */); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 147 | assertTrue(mActivity.isState(PAUSING)); |
Andrii Kulian | 0447068 | 2018-01-10 15:32:31 -0800 | [diff] [blame] | 148 | assertTrue(pauseFound.value); |
Bryce Lee | 052957b | 2018-01-16 11:13:30 -0800 | [diff] [blame] | 149 | |
| 150 | // 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] | 151 | mActivity.setState(INITIALIZING, "testPausingWhenVisibleFromStopped"); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 152 | doReturn(true).when(mActivity).isFocusable(); |
Bryce Lee | 052957b | 2018-01-16 11:13:30 -0800 | [diff] [blame] | 153 | |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 154 | mActivity.makeVisibleIfNeeded(null /* starting */, true /* reportToClient */); |
Bryce Lee | 052957b | 2018-01-16 11:13:30 -0800 | [diff] [blame] | 155 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 156 | assertTrue(mActivity.isState(INITIALIZING)); |
Bryce Lee | a0fb8e0 | 2018-02-28 14:21:07 -0800 | [diff] [blame] | 157 | |
| 158 | // Make sure the state does not change if we are not the current top activity. |
| 159 | mActivity.setState(STOPPED, "testPausingWhenVisibleFromStopped behind"); |
| 160 | |
| 161 | // Make sure that the state does not change when we have an activity becoming translucent |
| 162 | final ActivityRecord topActivity = new ActivityBuilder(mService).setTask(mTask).build(); |
| 163 | mStack.mTranslucentActivityWaiting = topActivity; |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 164 | mActivity.makeVisibleIfNeeded(null /* starting */, true /* reportToClient */); |
Bryce Lee | a0fb8e0 | 2018-02-28 14:21:07 -0800 | [diff] [blame] | 165 | |
| 166 | assertTrue(mActivity.isState(STOPPED)); |
Bryce Lee | 0bd8d42 | 2018-01-09 09:45:57 -0800 | [diff] [blame] | 167 | } |
| 168 | |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 169 | private void ensureActivityConfiguration() { |
| 170 | mActivity.ensureActivityConfiguration(0 /* globalChanges */, false /* preserveWindow */); |
| 171 | } |
| 172 | |
Bryce Lee | 1533b2b | 2017-09-14 17:06:41 -0700 | [diff] [blame] | 173 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 174 | public void testCanBeLaunchedOnDisplay() { |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 175 | mService.mSupportsMultiWindow = true; |
| 176 | final ActivityRecord activity = new ActivityBuilder(mService).build(); |
Bryce Lee | 1533b2b | 2017-09-14 17:06:41 -0700 | [diff] [blame] | 177 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 178 | // An activity can be launched on default display. |
| 179 | assertTrue(activity.canBeLaunchedOnDisplay(DEFAULT_DISPLAY)); |
| 180 | // An activity cannot be launched on a non-existent display. |
| 181 | assertFalse(activity.canBeLaunchedOnDisplay(DEFAULT_DISPLAY + 1)); |
Bryce Lee | 1533b2b | 2017-09-14 17:06:41 -0700 | [diff] [blame] | 182 | } |
| 183 | |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 184 | @Test |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 185 | public void testRestartProcessIfVisible() { |
| 186 | doNothing().when(mSupervisor).scheduleRestartTimeout(mActivity); |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 187 | mActivity.visible = true; |
| 188 | mActivity.haveState = false; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 189 | mActivity.setState(ActivityStack.ActivityState.RESUMED, "testRestart"); |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 190 | prepareFixedAspectRatioUnresizableActivity(); |
| 191 | |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 192 | final Rect originalOverrideBounds = new Rect(mActivity.getBounds()); |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame^] | 193 | setupDisplayAndParentSize(600, 1200); |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 194 | // The visible activity should recompute configuration according to the last parent bounds. |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 195 | mService.restartActivityProcessIfVisible(mActivity.appToken); |
| 196 | |
| 197 | assertEquals(ActivityStack.ActivityState.RESTARTING_PROCESS, mActivity.getState()); |
| 198 | assertNotEquals(originalOverrideBounds, mActivity.getBounds()); |
| 199 | } |
| 200 | |
| 201 | @Test |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 202 | public void testsApplyOptionsLocked() { |
| 203 | ActivityOptions activityOptions = ActivityOptions.makeBasic(); |
| 204 | |
| 205 | // Set and apply options for ActivityRecord. Pending options should be cleared |
| 206 | mActivity.updateOptionsLocked(activityOptions); |
| 207 | mActivity.applyOptionsLocked(); |
| 208 | assertNull(mActivity.pendingOptions); |
| 209 | |
| 210 | // Set options for two ActivityRecords in same Task. Apply one ActivityRecord options. |
| 211 | // Pending options should be cleared for both ActivityRecords |
| 212 | ActivityRecord activity2 = new ActivityBuilder(mService).setTask(mTask).build(); |
| 213 | activity2.updateOptionsLocked(activityOptions); |
| 214 | mActivity.updateOptionsLocked(activityOptions); |
| 215 | mActivity.applyOptionsLocked(); |
| 216 | assertNull(mActivity.pendingOptions); |
| 217 | assertNull(activity2.pendingOptions); |
| 218 | |
| 219 | // Set options for two ActivityRecords in separate Tasks. Apply one ActivityRecord options. |
| 220 | // Pending options should be cleared for only ActivityRecord that was applied |
| 221 | TaskRecord task2 = new TaskBuilder(mService.mStackSupervisor).setStack(mStack).build(); |
| 222 | activity2 = new ActivityBuilder(mService).setTask(task2).build(); |
| 223 | activity2.updateOptionsLocked(activityOptions); |
| 224 | mActivity.updateOptionsLocked(activityOptions); |
| 225 | mActivity.applyOptionsLocked(); |
| 226 | assertNull(mActivity.pendingOptions); |
| 227 | assertNotNull(activity2.pendingOptions); |
| 228 | } |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 229 | |
| 230 | @Test |
| 231 | public void testNewOverrideConfigurationIncrementsSeq() { |
| 232 | final Configuration newConfig = new Configuration(); |
| 233 | |
| 234 | final int prevSeq = mActivity.getMergedOverrideConfiguration().seq; |
| 235 | mActivity.onRequestedOverrideConfigurationChanged(newConfig); |
| 236 | assertEquals(prevSeq + 1, mActivity.getMergedOverrideConfiguration().seq); |
| 237 | } |
| 238 | |
| 239 | @Test |
| 240 | public void testNewParentConfigurationIncrementsSeq() { |
| 241 | final Configuration newConfig = new Configuration( |
| 242 | mTask.getRequestedOverrideConfiguration()); |
| 243 | newConfig.orientation = newConfig.orientation == Configuration.ORIENTATION_PORTRAIT |
| 244 | ? Configuration.ORIENTATION_LANDSCAPE : Configuration.ORIENTATION_PORTRAIT; |
| 245 | |
| 246 | final int prevSeq = mActivity.getMergedOverrideConfiguration().seq; |
| 247 | mTask.onRequestedOverrideConfigurationChanged(newConfig); |
| 248 | assertEquals(prevSeq + 1, mActivity.getMergedOverrideConfiguration().seq); |
| 249 | } |
| 250 | |
| 251 | @Test |
| 252 | public void testNotifiesSeqIncrementToAppToken() { |
| 253 | final Configuration appWindowTokenRequestedOrientation = mock(Configuration.class); |
| 254 | mActivity.mAppWindowToken = mock(AppWindowToken.class); |
| 255 | doReturn(appWindowTokenRequestedOrientation).when(mActivity.mAppWindowToken) |
| 256 | .getRequestedOverrideConfiguration(); |
| 257 | |
| 258 | final Configuration newConfig = new Configuration(); |
| 259 | newConfig.orientation = Configuration.ORIENTATION_PORTRAIT; |
| 260 | |
| 261 | final int prevSeq = mActivity.getMergedOverrideConfiguration().seq; |
| 262 | mActivity.onRequestedOverrideConfigurationChanged(newConfig); |
| 263 | assertEquals(prevSeq + 1, appWindowTokenRequestedOrientation.seq); |
| 264 | verify(mActivity.mAppWindowToken).onMergedOverrideConfigurationChanged(); |
| 265 | } |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 266 | |
| 267 | @Test |
| 268 | public void testSetsRelaunchReason_NotDragResizing() { |
| 269 | mActivity.setState(ActivityStack.ActivityState.RESUMED, "Testing"); |
| 270 | |
| 271 | mTask.onRequestedOverrideConfigurationChanged(mTask.getConfiguration()); |
| 272 | mActivity.setLastReportedConfiguration(new MergedConfiguration(new Configuration(), |
| 273 | mActivity.getConfiguration())); |
| 274 | |
| 275 | mActivity.info.configChanges &= ~ActivityInfo.CONFIG_ORIENTATION; |
| 276 | final Configuration newConfig = new Configuration(mTask.getConfiguration()); |
| 277 | newConfig.orientation = newConfig.orientation == Configuration.ORIENTATION_PORTRAIT |
| 278 | ? Configuration.ORIENTATION_LANDSCAPE : Configuration.ORIENTATION_PORTRAIT; |
| 279 | mTask.onRequestedOverrideConfigurationChanged(newConfig); |
| 280 | |
| 281 | mActivity.mRelaunchReason = ActivityTaskManagerService.RELAUNCH_REASON_NONE; |
| 282 | |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 283 | ensureActivityConfiguration(); |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 284 | |
| 285 | assertEquals(ActivityTaskManagerService.RELAUNCH_REASON_WINDOWING_MODE_RESIZE, |
| 286 | mActivity.mRelaunchReason); |
| 287 | } |
| 288 | |
| 289 | @Test |
| 290 | public void testSetsRelaunchReason_DragResizing() { |
| 291 | mActivity.setState(ActivityStack.ActivityState.RESUMED, "Testing"); |
| 292 | |
| 293 | mTask.onRequestedOverrideConfigurationChanged(mTask.getConfiguration()); |
| 294 | mActivity.setLastReportedConfiguration(new MergedConfiguration(new Configuration(), |
| 295 | mActivity.getConfiguration())); |
| 296 | |
| 297 | mActivity.info.configChanges &= ~ActivityInfo.CONFIG_ORIENTATION; |
| 298 | final Configuration newConfig = new Configuration(mTask.getConfiguration()); |
| 299 | newConfig.orientation = newConfig.orientation == Configuration.ORIENTATION_PORTRAIT |
| 300 | ? Configuration.ORIENTATION_LANDSCAPE : Configuration.ORIENTATION_PORTRAIT; |
| 301 | mTask.onRequestedOverrideConfigurationChanged(newConfig); |
| 302 | |
| 303 | doReturn(true).when(mTask.getTask()).isDragResizing(); |
| 304 | |
| 305 | mActivity.mRelaunchReason = ActivityTaskManagerService.RELAUNCH_REASON_NONE; |
| 306 | |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 307 | ensureActivityConfiguration(); |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 308 | |
| 309 | assertEquals(ActivityTaskManagerService.RELAUNCH_REASON_FREE_RESIZE, |
| 310 | mActivity.mRelaunchReason); |
| 311 | } |
| 312 | |
| 313 | @Test |
| 314 | public void testSetsRelaunchReason_NonResizeConfigChanges() { |
| 315 | mActivity.setState(ActivityStack.ActivityState.RESUMED, "Testing"); |
| 316 | |
| 317 | mTask.onRequestedOverrideConfigurationChanged(mTask.getConfiguration()); |
| 318 | mActivity.setLastReportedConfiguration(new MergedConfiguration(new Configuration(), |
| 319 | mActivity.getConfiguration())); |
| 320 | |
| 321 | mActivity.info.configChanges &= ~ActivityInfo.CONFIG_FONT_SCALE; |
| 322 | final Configuration newConfig = new Configuration(mTask.getConfiguration()); |
| 323 | newConfig.fontScale = 5; |
| 324 | mTask.onRequestedOverrideConfigurationChanged(newConfig); |
| 325 | |
| 326 | mActivity.mRelaunchReason = |
| 327 | ActivityTaskManagerService.RELAUNCH_REASON_WINDOWING_MODE_RESIZE; |
| 328 | |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 329 | ensureActivityConfiguration(); |
Garfield Tan | f6cc5c9 | 2019-01-15 13:54:12 -0800 | [diff] [blame] | 330 | |
| 331 | assertEquals(ActivityTaskManagerService.RELAUNCH_REASON_NONE, |
| 332 | mActivity.mRelaunchReason); |
| 333 | } |
Garfield Tan | 36a69ad | 2019-01-16 17:08:23 -0800 | [diff] [blame] | 334 | |
| 335 | @Test |
| 336 | public void testSetRequestedOrientationUpdatesConfiguration() throws Exception { |
| 337 | mActivity.setState(ActivityStack.ActivityState.RESUMED, "Testing"); |
| 338 | |
| 339 | mTask.onRequestedOverrideConfigurationChanged(mTask.getConfiguration()); |
| 340 | mActivity.setLastReportedConfiguration(new MergedConfiguration(new Configuration(), |
| 341 | mActivity.getConfiguration())); |
| 342 | |
| 343 | mActivity.info.configChanges |= ActivityInfo.CONFIG_ORIENTATION; |
| 344 | final Configuration newConfig = new Configuration(mActivity.getConfiguration()); |
| 345 | newConfig.orientation = newConfig.orientation == Configuration.ORIENTATION_PORTRAIT |
| 346 | ? Configuration.ORIENTATION_LANDSCAPE |
| 347 | : Configuration.ORIENTATION_PORTRAIT; |
| 348 | |
| 349 | // Mimic the behavior that display doesn't handle app's requested orientation. |
| 350 | doAnswer(invocation -> { |
| 351 | mTask.onConfigurationChanged(newConfig); |
| 352 | return null; |
| 353 | }).when(mActivity.mAppWindowToken).setOrientation(anyInt(), any(), any()); |
| 354 | |
| 355 | final int requestedOrientation; |
| 356 | switch (newConfig.orientation) { |
| 357 | case Configuration.ORIENTATION_LANDSCAPE: |
| 358 | requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; |
| 359 | break; |
| 360 | case Configuration.ORIENTATION_PORTRAIT: |
| 361 | requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; |
| 362 | break; |
| 363 | default: |
| 364 | throw new IllegalStateException("Orientation in new config should be either" |
| 365 | + "landscape or portrait."); |
| 366 | } |
| 367 | mActivity.setRequestedOrientation(requestedOrientation); |
| 368 | |
| 369 | final ActivityConfigurationChangeItem expected = |
| 370 | ActivityConfigurationChangeItem.obtain(newConfig); |
| 371 | verify(mService.getLifecycleManager()).scheduleTransaction(eq(mActivity.app.getThread()), |
| 372 | eq(mActivity.appToken), eq(expected)); |
| 373 | } |
Andrii Kulian | f219536 | 2019-01-31 18:20:11 -0800 | [diff] [blame] | 374 | |
| 375 | @Test |
| 376 | public void testShouldMakeActive_deferredResume() { |
| 377 | mActivity.setState(ActivityStack.ActivityState.STOPPED, "Testing"); |
| 378 | |
| 379 | mSupervisor.beginDeferResume(); |
| 380 | assertEquals(false, mActivity.shouldMakeActive(null /* activeActivity */)); |
| 381 | |
| 382 | mSupervisor.endDeferResume(); |
| 383 | assertEquals(true, mActivity.shouldMakeActive(null /* activeActivity */)); |
| 384 | } |
Garfield Tan | 4026330 | 2019-02-01 15:27:35 -0800 | [diff] [blame] | 385 | |
| 386 | @Test |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 387 | public void testShouldResume_stackVisibility() { |
| 388 | mActivity.setState(ActivityStack.ActivityState.STOPPED, "Testing"); |
| 389 | spyOn(mStack); |
| 390 | |
| 391 | doReturn(STACK_VISIBILITY_VISIBLE).when(mStack).getVisibility(null); |
| 392 | assertEquals(true, mActivity.shouldResumeActivity(null /* activeActivity */)); |
| 393 | |
| 394 | doReturn(STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT).when(mStack).getVisibility(null); |
| 395 | assertEquals(false, mActivity.shouldResumeActivity(null /* activeActivity */)); |
| 396 | |
| 397 | doReturn(STACK_VISIBILITY_INVISIBLE).when(mStack).getVisibility(null); |
| 398 | assertEquals(false, mActivity.shouldResumeActivity(null /* activeActivity */)); |
| 399 | } |
| 400 | |
| 401 | @Test |
Garfield Tan | 4026330 | 2019-02-01 15:27:35 -0800 | [diff] [blame] | 402 | public void testPushConfigurationWhenLaunchTaskBehind() throws Exception { |
| 403 | mActivity.setState(ActivityStack.ActivityState.STOPPED, "Testing"); |
| 404 | |
| 405 | final TestActivityStack stack = (TestActivityStack) new StackBuilder(mRootActivityContainer) |
| 406 | .build(); |
| 407 | try { |
| 408 | stack.setIsTranslucent(false); |
| 409 | assertFalse(mStack.shouldBeVisible(null /* starting */)); |
| 410 | |
| 411 | mTask.onRequestedOverrideConfigurationChanged(mTask.getConfiguration()); |
| 412 | mActivity.setLastReportedConfiguration(new MergedConfiguration(new Configuration(), |
| 413 | mActivity.getConfiguration())); |
| 414 | |
| 415 | mActivity.mLaunchTaskBehind = true; |
| 416 | mActivity.info.configChanges |= ActivityInfo.CONFIG_ORIENTATION; |
| 417 | final Configuration newConfig = new Configuration(mActivity.getConfiguration()); |
| 418 | newConfig.orientation = newConfig.orientation == Configuration.ORIENTATION_PORTRAIT |
| 419 | ? Configuration.ORIENTATION_LANDSCAPE |
| 420 | : Configuration.ORIENTATION_PORTRAIT; |
| 421 | |
| 422 | mTask.onConfigurationChanged(newConfig); |
| 423 | |
| 424 | mActivity.ensureActivityConfiguration(0 /* globalChanges */, |
| 425 | false /* preserveWindow */, true /* ignoreStopState */); |
| 426 | |
| 427 | final ActivityConfigurationChangeItem expected = |
| 428 | ActivityConfigurationChangeItem.obtain(newConfig); |
| 429 | verify(mService.getLifecycleManager()).scheduleTransaction( |
| 430 | eq(mActivity.app.getThread()), eq(mActivity.appToken), eq(expected)); |
| 431 | } finally { |
| 432 | stack.getDisplay().removeChild(stack); |
| 433 | } |
| 434 | } |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 435 | |
| 436 | @Test |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 437 | public void testSizeCompatMode_FixedAspectRatioBoundsWithDecor() { |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame^] | 438 | setupDisplayContentForCompatDisplayInsets(); |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 439 | final int decorHeight = 200; // e.g. The device has cutout. |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame^] | 440 | final DisplayPolicy policy = setupDisplayAndParentSize(600, 800).getDisplayPolicy(); |
| 441 | doAnswer(invocationOnMock -> { |
| 442 | final int rotation = invocationOnMock.<Integer>getArgument(0); |
| 443 | final Rect insets = invocationOnMock.<Rect>getArgument(4); |
| 444 | if (rotation == ROTATION_0) { |
| 445 | insets.top = decorHeight; |
| 446 | } else if (rotation == ROTATION_90) { |
| 447 | insets.left = decorHeight; |
| 448 | } |
| 449 | return null; |
| 450 | }).when(policy).getNonDecorInsetsLw(anyInt() /* rotation */, anyInt() /* width */, |
| 451 | anyInt() /* height */, any() /* displayCutout */, any() /* outInsets */); |
| 452 | |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 453 | doReturn(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) |
| 454 | .when(mActivity.mAppWindowToken).getOrientationIgnoreVisibility(); |
| 455 | mActivity.info.resizeMode = ActivityInfo.RESIZE_MODE_UNRESIZEABLE; |
Riddle Hsu | 9ad178510 | 2019-03-26 00:26:54 +0800 | [diff] [blame] | 456 | mActivity.info.minAspectRatio = mActivity.info.maxAspectRatio = 1; |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 457 | ensureActivityConfiguration(); |
Riddle Hsu | 9ad178510 | 2019-03-26 00:26:54 +0800 | [diff] [blame] | 458 | // The parent configuration doesn't change since the first resolved configuration, so the |
| 459 | // activity shouldn't be in the size compatibility mode. |
| 460 | assertFalse(mActivity.inSizeCompatMode()); |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 461 | |
| 462 | final Rect appBounds = mActivity.getWindowConfiguration().getAppBounds(); |
| 463 | // Ensure the app bounds keep the declared aspect ratio. |
| 464 | assertEquals(appBounds.width(), appBounds.height()); |
| 465 | // The decor height should be a part of the effective bounds. |
| 466 | assertEquals(mActivity.getBounds().height(), appBounds.height() + decorHeight); |
| 467 | |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame^] | 468 | mTask.getConfiguration().windowConfiguration.setRotation(ROTATION_90); |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 469 | mActivity.onConfigurationChanged(mTask.getConfiguration()); |
| 470 | // After changing orientation, the aspect ratio should be the same. |
| 471 | assertEquals(appBounds.width(), appBounds.height()); |
| 472 | // The decor height will be included in width. |
| 473 | assertEquals(mActivity.getBounds().width(), appBounds.width() + decorHeight); |
| 474 | } |
| 475 | |
| 476 | @Test |
Riddle Hsu | 2560c3b | 2019-02-23 23:45:58 +0800 | [diff] [blame] | 477 | public void testSizeCompatMode_FixedScreenConfigurationWhenMovingToDisplay() { |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 478 | // Initialize different bounds on a new display. |
| 479 | final ActivityDisplay newDisplay = addNewActivityDisplayAt(ActivityDisplay.POSITION_TOP); |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 480 | newDisplay.getWindowConfiguration().setAppBounds(new Rect(0, 0, 1000, 2000)); |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 481 | newDisplay.getConfiguration().densityDpi = 300; |
| 482 | |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 483 | mTask.getConfiguration().densityDpi = 200; |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 484 | prepareFixedAspectRatioUnresizableActivity(); |
| 485 | |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 486 | final Rect originalBounds = new Rect(mActivity.getBounds()); |
| 487 | final int originalDpi = mActivity.getConfiguration().densityDpi; |
| 488 | |
| 489 | // Move the non-resizable activity to the new display. |
| 490 | mStack.reparent(newDisplay, true /* onTop */, false /* displayRemoved */); |
| 491 | ensureActivityConfiguration(); |
| 492 | |
| 493 | assertEquals(originalBounds, mActivity.getBounds()); |
| 494 | assertEquals(originalDpi, mActivity.getConfiguration().densityDpi); |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 495 | assertTrue(mActivity.inSizeCompatMode()); |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | @Test |
Riddle Hsu | 2560c3b | 2019-02-23 23:45:58 +0800 | [diff] [blame] | 499 | public void testSizeCompatMode_FixedScreenBoundsWhenDisplaySizeChanged() { |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame^] | 500 | setupDisplayContentForCompatDisplayInsets(); |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 501 | when(mActivity.mAppWindowToken.getOrientationIgnoreVisibility()).thenReturn( |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 502 | ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 503 | mTask.getWindowConfiguration().setAppBounds(mStack.getDisplay().getBounds()); |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 504 | mTask.getConfiguration().orientation = Configuration.ORIENTATION_PORTRAIT; |
| 505 | mActivity.info.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 506 | mActivity.info.resizeMode = ActivityInfo.RESIZE_MODE_UNRESIZEABLE; |
| 507 | ensureActivityConfiguration(); |
| 508 | final Rect originalBounds = new Rect(mActivity.getBounds()); |
| 509 | |
| 510 | // Change the size of current display. |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame^] | 511 | setupDisplayAndParentSize(1000, 2000); |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 512 | ensureActivityConfiguration(); |
| 513 | |
| 514 | assertEquals(originalBounds, mActivity.getBounds()); |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 515 | assertTrue(mActivity.inSizeCompatMode()); |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 516 | } |
Riddle Hsu | 2560c3b | 2019-02-23 23:45:58 +0800 | [diff] [blame] | 517 | |
| 518 | @Test |
| 519 | public void testSizeCompatMode_FixedScreenLayoutSizeBits() { |
| 520 | final int fixedScreenLayout = Configuration.SCREENLAYOUT_LONG_NO |
| 521 | | Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| 522 | mTask.getConfiguration().screenLayout = fixedScreenLayout |
| 523 | | Configuration.SCREENLAYOUT_LAYOUTDIR_LTR; |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 524 | prepareFixedAspectRatioUnresizableActivity(); |
Riddle Hsu | 2560c3b | 2019-02-23 23:45:58 +0800 | [diff] [blame] | 525 | |
| 526 | // The initial configuration should inherit from parent. |
| 527 | assertEquals(mTask.getConfiguration().screenLayout, |
| 528 | mActivity.getConfiguration().screenLayout); |
| 529 | |
| 530 | mTask.getConfiguration().screenLayout = Configuration.SCREENLAYOUT_LAYOUTDIR_RTL |
| 531 | | Configuration.SCREENLAYOUT_LONG_YES | Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 532 | mActivity.onConfigurationChanged(mTask.getConfiguration()); |
| 533 | |
| 534 | // The size and aspect ratio bits don't change, but the layout direction should be updated. |
| 535 | assertEquals(fixedScreenLayout | Configuration.SCREENLAYOUT_LAYOUTDIR_RTL, |
| 536 | mActivity.getConfiguration().screenLayout); |
| 537 | } |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 538 | |
| 539 | @Test |
| 540 | public void testSizeCompatMode_ResetNonVisibleActivity() { |
| 541 | final ActivityDisplay display = mStack.getDisplay(); |
| 542 | spyOn(display); |
| 543 | |
| 544 | prepareFixedAspectRatioUnresizableActivity(); |
| 545 | mActivity.setState(STOPPED, "testSizeCompatMode"); |
| 546 | mActivity.visible = false; |
| 547 | mActivity.app.setReportedProcState(ActivityManager.PROCESS_STATE_CACHED_ACTIVITY); |
| 548 | // Make the parent bounds to be different so the activity is in size compatibility mode. |
| 549 | mTask.getWindowConfiguration().setAppBounds(new Rect(0, 0, 600, 1200)); |
| 550 | |
| 551 | // Simulate the display changes orientation. |
| 552 | doReturn(ActivityInfo.CONFIG_SCREEN_SIZE | ActivityInfo.CONFIG_ORIENTATION |
| 553 | | ActivityInfo.CONFIG_WINDOW_CONFIGURATION) |
| 554 | .when(display).getLastOverrideConfigurationChanges(); |
| 555 | mActivity.onConfigurationChanged(mTask.getConfiguration()); |
| 556 | // The override configuration should not change so it is still in size compatibility mode. |
| 557 | assertTrue(mActivity.inSizeCompatMode()); |
| 558 | |
| 559 | // Simulate the display changes density. |
| 560 | doReturn(ActivityInfo.CONFIG_DENSITY).when(display).getLastOverrideConfigurationChanges(); |
| 561 | mService.mAmInternal = mock(ActivityManagerInternal.class); |
| 562 | mActivity.onConfigurationChanged(mTask.getConfiguration()); |
| 563 | // The override configuration should be reset and the activity's process will be killed. |
| 564 | assertFalse(mActivity.inSizeCompatMode()); |
| 565 | verify(mActivity).restartProcessIfVisible(); |
| 566 | mService.mH.runWithScissors(() -> { }, TimeUnit.SECONDS.toMillis(3)); |
| 567 | verify(mService.mAmInternal).killProcess( |
| 568 | eq(mActivity.app.mName), eq(mActivity.app.mUid), anyString()); |
| 569 | } |
| 570 | |
| 571 | /** Setup {@link #mActivity} as a size-compat-mode-able activity without fixed orientation. */ |
| 572 | private void prepareFixedAspectRatioUnresizableActivity() { |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame^] | 573 | setupDisplayContentForCompatDisplayInsets(); |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 574 | when(mActivity.mAppWindowToken.getOrientationIgnoreVisibility()).thenReturn( |
| 575 | ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 576 | mActivity.info.resizeMode = ActivityInfo.RESIZE_MODE_UNRESIZEABLE; |
| 577 | mActivity.info.maxAspectRatio = 1.5f; |
| 578 | ensureActivityConfiguration(); |
| 579 | } |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame^] | 580 | |
| 581 | private void setupDisplayContentForCompatDisplayInsets() { |
| 582 | final Rect displayBounds = mStack.getDisplay().getBounds(); |
| 583 | final DisplayContent displayContent = setupDisplayAndParentSize( |
| 584 | displayBounds.width(), displayBounds.height()); |
| 585 | doReturn(mock(DisplayPolicy.class)).when(displayContent).getDisplayPolicy(); |
| 586 | doReturn(mock(WmDisplayCutout.class)).when(displayContent) |
| 587 | .calculateDisplayCutoutForRotation(anyInt()); |
| 588 | } |
| 589 | |
| 590 | private DisplayContent setupDisplayAndParentSize(int width, int height) { |
| 591 | // The DisplayContent is already a mocked object. |
| 592 | final DisplayContent displayContent = mStack.getDisplay().mDisplayContent; |
| 593 | displayContent.mBaseDisplayWidth = width; |
| 594 | displayContent.mBaseDisplayHeight = height; |
| 595 | mTask.getWindowConfiguration().setAppBounds(0, 0, width, height); |
| 596 | mTask.getWindowConfiguration().setRotation(ROTATION_0); |
| 597 | return displayContent; |
| 598 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 599 | } |