blob: a1db3e8d8ded071736d317e7a481884ab6f8a254 [file] [log] [blame]
Bryce Leeaf691c02017-03-20 14:20:22 -07001/*
Wale Ogunwale59507092018-10-29 09:00:30 -07002 * Copyright (C) 2018 The Android Open Source Project
Bryce Leeaf691c02017-03-20 14:20:22 -07003 *
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 Ogunwale59507092018-10-29 09:00:30 -070014 * limitations under the License
Bryce Leeaf691c02017-03-20 14:20:22 -070015 */
16
Wale Ogunwale59507092018-10-29 09:00:30 -070017package com.android.server.wm;
Bryce Leeaf691c02017-03-20 14:20:22 -070018
Wale Ogunwale04a05ac2017-09-17 21:35:02 -070019import static android.view.Display.DEFAULT_DISPLAY;
Bryce Lee0bd8d422018-01-09 09:45:57 -080020
Tadashi G. Takaokaa7a66952018-11-16 15:04:21 +090021import static com.android.dx.mockito.inline.extended.ExtendedMockito.any;
Garfield Tan36a69ad2019-01-16 17:08:23 -080022import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyInt;
Tadashi G. Takaokaa7a66952018-11-16 15:04:21 +090023import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
Garfield Tan0443b372019-01-04 15:00:13 -080024import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
Garfield Tan36a69ad2019-01-16 17:08:23 -080025import static com.android.dx.mockito.inline.extended.ExtendedMockito.eq;
Garfield Tan0443b372019-01-04 15:00:13 -080026import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
Andrii Kulian0c869cc2019-02-06 19:50:32 -080027import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
Garfield Tan0443b372019-01-04 15:00:13 -080028import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
Tadashi G. Takaokaa7a66952018-11-16 15:04:21 +090029import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
Wale Ogunwale59507092018-10-29 09:00:30 -070030import static com.android.server.wm.ActivityStack.ActivityState.INITIALIZING;
31import static com.android.server.wm.ActivityStack.ActivityState.PAUSING;
Andrii Kulian6b321512019-01-23 06:37:00 +000032import static com.android.server.wm.ActivityStack.ActivityState.RESUMED;
Wale Ogunwale59507092018-10-29 09:00:30 -070033import static com.android.server.wm.ActivityStack.ActivityState.STOPPED;
34import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_MOVING;
Andrii Kulian0c869cc2019-02-06 19:50:32 -080035import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_INVISIBLE;
36import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE;
37import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT;
Adrian Roose99bc052017-11-20 17:55:31 +010038
Bryce Lee04ab3462017-04-10 15:06:33 -070039import static org.junit.Assert.assertEquals;
Bryce Lee1533b2b2017-09-14 17:06:41 -070040import static org.junit.Assert.assertFalse;
Yunfan Chen1ee84ea2018-11-13 16:03:37 -080041import static org.junit.Assert.assertNotNull;
Bryce Lee04ab3462017-04-10 15:06:33 -070042import static org.junit.Assert.assertNull;
Bryce Lee1533b2b2017-09-14 17:06:41 -070043import static org.junit.Assert.assertTrue;
chaviw82a0ba82018-03-15 14:26:29 -070044
45import android.app.ActivityOptions;
Garfield Tan36a69ad2019-01-16 17:08:23 -080046import android.app.servertransaction.ActivityConfigurationChangeItem;
Bryce Lee0bd8d422018-01-09 09:45:57 -080047import android.app.servertransaction.ClientTransaction;
48import android.app.servertransaction.PauseActivityItem;
Garfield Tanf6cc5c92019-01-15 13:54:12 -080049import android.content.pm.ActivityInfo;
Garfield Tan0443b372019-01-04 15:00:13 -080050import android.content.res.Configuration;
Andrii Kulian3a1619d2017-07-07 14:38:09 -070051import android.graphics.Rect;
Bryce Leeaf691c02017-03-20 14:20:22 -070052import android.platform.test.annotations.Presubmit;
Garfield Tanf6cc5c92019-01-15 13:54:12 -080053import android.util.MergedConfiguration;
Andrii Kulian04470682018-01-10 15:32:31 -080054import android.util.MutableBoolean;
Bryce Leeaf691c02017-03-20 14:20:22 -070055
Brett Chabota26eda92018-07-23 13:08:30 -070056import androidx.test.filters.MediumTest;
Brett Chabota26eda92018-07-23 13:08:30 -070057
Wale Ogunwale04a05ac2017-09-17 21:35:02 -070058import org.junit.Before;
Bryce Leeaf691c02017-03-20 14:20:22 -070059import org.junit.Test;
Andrii Kulian04470682018-01-10 15:32:31 -080060import org.mockito.invocation.InvocationOnMock;
Bryce Lee0bd8d422018-01-09 09:45:57 -080061
Bryce Leeaf691c02017-03-20 14:20:22 -070062/**
63 * Tests for the {@link ActivityRecord} class.
64 *
65 * Build/Install/Run:
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090066 * atest WmTests:ActivityRecordTests
Bryce Leeaf691c02017-03-20 14:20:22 -070067 */
68@MediumTest
Bryce Lee3115bdf2017-04-05 08:39:40 -070069@Presubmit
Bryce Leeaf691c02017-03-20 14:20:22 -070070public class ActivityRecordTests extends ActivityTestsBase {
Wale Ogunwale7e1f5f52017-10-18 15:19:59 -070071 private TestActivityStack mStack;
Wale Ogunwale04a05ac2017-09-17 21:35:02 -070072 private TaskRecord mTask;
73 private ActivityRecord mActivity;
74
75 @Before
Wale Ogunwale04a05ac2017-09-17 21:35:02 -070076 public void setUp() throws Exception {
Yunfan Chen279f5582018-12-12 15:24:50 -080077 mStack = (TestActivityStack) new StackBuilder(mRootActivityContainer).build();
Louis Changf2835df2018-10-17 15:14:45 +080078 mTask = mStack.getChildAt(0);
79 mActivity = mTask.getTopActivity();
Andrii Kulian6b321512019-01-23 06:37:00 +000080
81 doReturn(false).when(mService).isBooting();
82 doReturn(true).when(mService).isBooted();
Wale Ogunwale04a05ac2017-09-17 21:35:02 -070083 }
84
Bryce Leeaf691c02017-03-20 14:20:22 -070085 @Test
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090086 public void testStackCleanupOnClearingTask() {
Wale Ogunwale04a05ac2017-09-17 21:35:02 -070087 mActivity.setTask(null);
Wale Ogunwale7e1f5f52017-10-18 15:19:59 -070088 assertEquals(mStack.onActivityRemovedFromStackInvocationCount(), 1);
Bryce Leeaf691c02017-03-20 14:20:22 -070089 }
90
91 @Test
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090092 public void testStackCleanupOnActivityRemoval() {
Wale Ogunwale04a05ac2017-09-17 21:35:02 -070093 mTask.removeActivity(mActivity);
Wale Ogunwale7e1f5f52017-10-18 15:19:59 -070094 assertEquals(mStack.onActivityRemovedFromStackInvocationCount(), 1);
Bryce Leeaf691c02017-03-20 14:20:22 -070095 }
96
97 @Test
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090098 public void testStackCleanupOnTaskRemoval() {
Wale Ogunwale04a05ac2017-09-17 21:35:02 -070099 mStack.removeTask(mTask, null /*reason*/, REMOVE_TASK_MODE_MOVING);
Bryce Lee04ab3462017-04-10 15:06:33 -0700100 // Stack should be gone on task removal.
Wale Ogunwaled32da472018-11-16 07:19:28 -0800101 assertNull(mService.mRootActivityContainer.getStack(mStack.mStackId));
Bryce Leeaf691c02017-03-20 14:20:22 -0700102 }
103
104 @Test
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +0900105 public void testNoCleanupMovingActivityInSameStack() {
Bryce Lee18d51592017-10-25 10:22:19 -0700106 final TaskRecord newTask = new TaskBuilder(mService.mStackSupervisor).setStack(mStack)
107 .build();
Wale Ogunwale04a05ac2017-09-17 21:35:02 -0700108 mActivity.reparent(newTask, 0, null /*reason*/);
Wale Ogunwale7e1f5f52017-10-18 15:19:59 -0700109 assertEquals(mStack.onActivityRemovedFromStackInvocationCount(), 0);
Bryce Leeaf691c02017-03-20 14:20:22 -0700110 }
Andrii Kulian3a1619d2017-07-07 14:38:09 -0700111
Andreas Gampecea9e6d2018-02-22 18:06:44 -0800112 @Test
Bryce Lee0bd8d422018-01-09 09:45:57 -0800113 public void testPausingWhenVisibleFromStopped() throws Exception {
Andrii Kulian04470682018-01-10 15:32:31 -0800114 final MutableBoolean pauseFound = new MutableBoolean(false);
115 doAnswer((InvocationOnMock invocationOnMock) -> {
116 final ClientTransaction transaction = invocationOnMock.getArgument(0);
117 if (transaction.getLifecycleStateRequest() instanceof PauseActivityItem) {
118 pauseFound.value = true;
Bryce Lee0bd8d422018-01-09 09:45:57 -0800119 }
Andrii Kulian04470682018-01-10 15:32:31 -0800120 return null;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700121 }).when(mActivity.app.getThread()).scheduleTransaction(any());
Bryce Leed939cf02018-03-12 09:04:44 -0700122
Bryce Lee7ace3952018-02-16 14:34:32 -0800123 mActivity.setState(STOPPED, "testPausingWhenVisibleFromStopped");
Bryce Lee0bd8d422018-01-09 09:45:57 -0800124
Andrii Kulian6b321512019-01-23 06:37:00 +0000125 // The activity is in the focused stack so it should be resumed.
Andrii Kuliana39ae3e2018-05-31 12:43:54 -0700126 mActivity.makeVisibleIfNeeded(null /* starting */, true /* reportToClient */);
Andrii Kulian6b321512019-01-23 06:37:00 +0000127 assertTrue(mActivity.isState(RESUMED));
Bryce Leed939cf02018-03-12 09:04:44 -0700128 assertFalse(pauseFound.value);
Andrii Kulian04470682018-01-10 15:32:31 -0800129
Andrii Kulian6b321512019-01-23 06:37:00 +0000130 // Make the activity non focusable
131 mActivity.setState(STOPPED, "testPausingWhenVisibleFromStopped");
132 doReturn(false).when(mActivity).isFocusable();
Bryce Leed939cf02018-03-12 09:04:44 -0700133
Andrii Kulian6b321512019-01-23 06:37:00 +0000134 // If the activity is not focusable, it should move to paused.
Andrii Kuliana39ae3e2018-05-31 12:43:54 -0700135 mActivity.makeVisibleIfNeeded(null /* starting */, true /* reportToClient */);
Bryce Lee7ace3952018-02-16 14:34:32 -0800136 assertTrue(mActivity.isState(PAUSING));
Andrii Kulian04470682018-01-10 15:32:31 -0800137 assertTrue(pauseFound.value);
Bryce Lee052957b2018-01-16 11:13:30 -0800138
139 // Make sure that the state does not change for current non-stopping states.
Bryce Lee7ace3952018-02-16 14:34:32 -0800140 mActivity.setState(INITIALIZING, "testPausingWhenVisibleFromStopped");
Andrii Kulian6b321512019-01-23 06:37:00 +0000141 doReturn(true).when(mActivity).isFocusable();
Bryce Lee052957b2018-01-16 11:13:30 -0800142
Andrii Kuliana39ae3e2018-05-31 12:43:54 -0700143 mActivity.makeVisibleIfNeeded(null /* starting */, true /* reportToClient */);
Bryce Lee052957b2018-01-16 11:13:30 -0800144
Bryce Lee7ace3952018-02-16 14:34:32 -0800145 assertTrue(mActivity.isState(INITIALIZING));
Bryce Leea0fb8e02018-02-28 14:21:07 -0800146
147 // Make sure the state does not change if we are not the current top activity.
148 mActivity.setState(STOPPED, "testPausingWhenVisibleFromStopped behind");
149
150 // Make sure that the state does not change when we have an activity becoming translucent
151 final ActivityRecord topActivity = new ActivityBuilder(mService).setTask(mTask).build();
152 mStack.mTranslucentActivityWaiting = topActivity;
Andrii Kuliana39ae3e2018-05-31 12:43:54 -0700153 mActivity.makeVisibleIfNeeded(null /* starting */, true /* reportToClient */);
Bryce Leea0fb8e02018-02-28 14:21:07 -0800154
155 assertTrue(mActivity.isState(STOPPED));
Bryce Lee0bd8d422018-01-09 09:45:57 -0800156 }
157
Riddle Hsu0a343c32018-12-21 00:40:48 +0800158 private void ensureActivityConfiguration() {
159 mActivity.ensureActivityConfiguration(0 /* globalChanges */, false /* preserveWindow */);
160 }
161
Bryce Lee1533b2b2017-09-14 17:06:41 -0700162 @Test
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +0900163 public void testCanBeLaunchedOnDisplay() {
Riddle Hsu16567132018-08-16 21:37:47 +0800164 mService.mSupportsMultiWindow = true;
165 final ActivityRecord activity = new ActivityBuilder(mService).build();
Bryce Lee1533b2b2017-09-14 17:06:41 -0700166
Riddle Hsu16567132018-08-16 21:37:47 +0800167 // An activity can be launched on default display.
168 assertTrue(activity.canBeLaunchedOnDisplay(DEFAULT_DISPLAY));
169 // An activity cannot be launched on a non-existent display.
170 assertFalse(activity.canBeLaunchedOnDisplay(DEFAULT_DISPLAY + 1));
Bryce Lee1533b2b2017-09-14 17:06:41 -0700171 }
172
chaviw82a0ba82018-03-15 14:26:29 -0700173 @Test
174 public void testsApplyOptionsLocked() {
175 ActivityOptions activityOptions = ActivityOptions.makeBasic();
176
177 // Set and apply options for ActivityRecord. Pending options should be cleared
178 mActivity.updateOptionsLocked(activityOptions);
179 mActivity.applyOptionsLocked();
180 assertNull(mActivity.pendingOptions);
181
182 // Set options for two ActivityRecords in same Task. Apply one ActivityRecord options.
183 // Pending options should be cleared for both ActivityRecords
184 ActivityRecord activity2 = new ActivityBuilder(mService).setTask(mTask).build();
185 activity2.updateOptionsLocked(activityOptions);
186 mActivity.updateOptionsLocked(activityOptions);
187 mActivity.applyOptionsLocked();
188 assertNull(mActivity.pendingOptions);
189 assertNull(activity2.pendingOptions);
190
191 // Set options for two ActivityRecords in separate Tasks. Apply one ActivityRecord options.
192 // Pending options should be cleared for only ActivityRecord that was applied
193 TaskRecord task2 = new TaskBuilder(mService.mStackSupervisor).setStack(mStack).build();
194 activity2 = new ActivityBuilder(mService).setTask(task2).build();
195 activity2.updateOptionsLocked(activityOptions);
196 mActivity.updateOptionsLocked(activityOptions);
197 mActivity.applyOptionsLocked();
198 assertNull(mActivity.pendingOptions);
199 assertNotNull(activity2.pendingOptions);
200 }
Garfield Tan0443b372019-01-04 15:00:13 -0800201
202 @Test
203 public void testNewOverrideConfigurationIncrementsSeq() {
204 final Configuration newConfig = new Configuration();
205
206 final int prevSeq = mActivity.getMergedOverrideConfiguration().seq;
207 mActivity.onRequestedOverrideConfigurationChanged(newConfig);
208 assertEquals(prevSeq + 1, mActivity.getMergedOverrideConfiguration().seq);
209 }
210
211 @Test
212 public void testNewParentConfigurationIncrementsSeq() {
213 final Configuration newConfig = new Configuration(
214 mTask.getRequestedOverrideConfiguration());
215 newConfig.orientation = newConfig.orientation == Configuration.ORIENTATION_PORTRAIT
216 ? Configuration.ORIENTATION_LANDSCAPE : Configuration.ORIENTATION_PORTRAIT;
217
218 final int prevSeq = mActivity.getMergedOverrideConfiguration().seq;
219 mTask.onRequestedOverrideConfigurationChanged(newConfig);
220 assertEquals(prevSeq + 1, mActivity.getMergedOverrideConfiguration().seq);
221 }
222
223 @Test
224 public void testNotifiesSeqIncrementToAppToken() {
225 final Configuration appWindowTokenRequestedOrientation = mock(Configuration.class);
226 mActivity.mAppWindowToken = mock(AppWindowToken.class);
227 doReturn(appWindowTokenRequestedOrientation).when(mActivity.mAppWindowToken)
228 .getRequestedOverrideConfiguration();
229
230 final Configuration newConfig = new Configuration();
231 newConfig.orientation = Configuration.ORIENTATION_PORTRAIT;
232
233 final int prevSeq = mActivity.getMergedOverrideConfiguration().seq;
234 mActivity.onRequestedOverrideConfigurationChanged(newConfig);
235 assertEquals(prevSeq + 1, appWindowTokenRequestedOrientation.seq);
236 verify(mActivity.mAppWindowToken).onMergedOverrideConfigurationChanged();
237 }
Garfield Tanf6cc5c92019-01-15 13:54:12 -0800238
239 @Test
240 public void testSetsRelaunchReason_NotDragResizing() {
241 mActivity.setState(ActivityStack.ActivityState.RESUMED, "Testing");
242
243 mTask.onRequestedOverrideConfigurationChanged(mTask.getConfiguration());
244 mActivity.setLastReportedConfiguration(new MergedConfiguration(new Configuration(),
245 mActivity.getConfiguration()));
246
247 mActivity.info.configChanges &= ~ActivityInfo.CONFIG_ORIENTATION;
248 final Configuration newConfig = new Configuration(mTask.getConfiguration());
249 newConfig.orientation = newConfig.orientation == Configuration.ORIENTATION_PORTRAIT
250 ? Configuration.ORIENTATION_LANDSCAPE : Configuration.ORIENTATION_PORTRAIT;
251 mTask.onRequestedOverrideConfigurationChanged(newConfig);
252
253 mActivity.mRelaunchReason = ActivityTaskManagerService.RELAUNCH_REASON_NONE;
254
Riddle Hsu0a343c32018-12-21 00:40:48 +0800255 ensureActivityConfiguration();
Garfield Tanf6cc5c92019-01-15 13:54:12 -0800256
257 assertEquals(ActivityTaskManagerService.RELAUNCH_REASON_WINDOWING_MODE_RESIZE,
258 mActivity.mRelaunchReason);
259 }
260
261 @Test
262 public void testSetsRelaunchReason_DragResizing() {
263 mActivity.setState(ActivityStack.ActivityState.RESUMED, "Testing");
264
265 mTask.onRequestedOverrideConfigurationChanged(mTask.getConfiguration());
266 mActivity.setLastReportedConfiguration(new MergedConfiguration(new Configuration(),
267 mActivity.getConfiguration()));
268
269 mActivity.info.configChanges &= ~ActivityInfo.CONFIG_ORIENTATION;
270 final Configuration newConfig = new Configuration(mTask.getConfiguration());
271 newConfig.orientation = newConfig.orientation == Configuration.ORIENTATION_PORTRAIT
272 ? Configuration.ORIENTATION_LANDSCAPE : Configuration.ORIENTATION_PORTRAIT;
273 mTask.onRequestedOverrideConfigurationChanged(newConfig);
274
275 doReturn(true).when(mTask.getTask()).isDragResizing();
276
277 mActivity.mRelaunchReason = ActivityTaskManagerService.RELAUNCH_REASON_NONE;
278
Riddle Hsu0a343c32018-12-21 00:40:48 +0800279 ensureActivityConfiguration();
Garfield Tanf6cc5c92019-01-15 13:54:12 -0800280
281 assertEquals(ActivityTaskManagerService.RELAUNCH_REASON_FREE_RESIZE,
282 mActivity.mRelaunchReason);
283 }
284
285 @Test
286 public void testSetsRelaunchReason_NonResizeConfigChanges() {
287 mActivity.setState(ActivityStack.ActivityState.RESUMED, "Testing");
288
289 mTask.onRequestedOverrideConfigurationChanged(mTask.getConfiguration());
290 mActivity.setLastReportedConfiguration(new MergedConfiguration(new Configuration(),
291 mActivity.getConfiguration()));
292
293 mActivity.info.configChanges &= ~ActivityInfo.CONFIG_FONT_SCALE;
294 final Configuration newConfig = new Configuration(mTask.getConfiguration());
295 newConfig.fontScale = 5;
296 mTask.onRequestedOverrideConfigurationChanged(newConfig);
297
298 mActivity.mRelaunchReason =
299 ActivityTaskManagerService.RELAUNCH_REASON_WINDOWING_MODE_RESIZE;
300
Riddle Hsu0a343c32018-12-21 00:40:48 +0800301 ensureActivityConfiguration();
Garfield Tanf6cc5c92019-01-15 13:54:12 -0800302
303 assertEquals(ActivityTaskManagerService.RELAUNCH_REASON_NONE,
304 mActivity.mRelaunchReason);
305 }
Garfield Tan36a69ad2019-01-16 17:08:23 -0800306
307 @Test
308 public void testSetRequestedOrientationUpdatesConfiguration() throws Exception {
309 mActivity.setState(ActivityStack.ActivityState.RESUMED, "Testing");
310
311 mTask.onRequestedOverrideConfigurationChanged(mTask.getConfiguration());
312 mActivity.setLastReportedConfiguration(new MergedConfiguration(new Configuration(),
313 mActivity.getConfiguration()));
314
315 mActivity.info.configChanges |= ActivityInfo.CONFIG_ORIENTATION;
316 final Configuration newConfig = new Configuration(mActivity.getConfiguration());
317 newConfig.orientation = newConfig.orientation == Configuration.ORIENTATION_PORTRAIT
318 ? Configuration.ORIENTATION_LANDSCAPE
319 : Configuration.ORIENTATION_PORTRAIT;
320
321 // Mimic the behavior that display doesn't handle app's requested orientation.
322 doAnswer(invocation -> {
323 mTask.onConfigurationChanged(newConfig);
324 return null;
325 }).when(mActivity.mAppWindowToken).setOrientation(anyInt(), any(), any());
326
327 final int requestedOrientation;
328 switch (newConfig.orientation) {
329 case Configuration.ORIENTATION_LANDSCAPE:
330 requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
331 break;
332 case Configuration.ORIENTATION_PORTRAIT:
333 requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
334 break;
335 default:
336 throw new IllegalStateException("Orientation in new config should be either"
337 + "landscape or portrait.");
338 }
339 mActivity.setRequestedOrientation(requestedOrientation);
340
341 final ActivityConfigurationChangeItem expected =
342 ActivityConfigurationChangeItem.obtain(newConfig);
343 verify(mService.getLifecycleManager()).scheduleTransaction(eq(mActivity.app.getThread()),
344 eq(mActivity.appToken), eq(expected));
345 }
Andrii Kulianf2195362019-01-31 18:20:11 -0800346
347 @Test
348 public void testShouldMakeActive_deferredResume() {
349 mActivity.setState(ActivityStack.ActivityState.STOPPED, "Testing");
350
351 mSupervisor.beginDeferResume();
352 assertEquals(false, mActivity.shouldMakeActive(null /* activeActivity */));
353
354 mSupervisor.endDeferResume();
355 assertEquals(true, mActivity.shouldMakeActive(null /* activeActivity */));
356 }
Garfield Tan40263302019-02-01 15:27:35 -0800357
358 @Test
Andrii Kulian0c869cc2019-02-06 19:50:32 -0800359 public void testShouldResume_stackVisibility() {
360 mActivity.setState(ActivityStack.ActivityState.STOPPED, "Testing");
361 spyOn(mStack);
362
363 doReturn(STACK_VISIBILITY_VISIBLE).when(mStack).getVisibility(null);
364 assertEquals(true, mActivity.shouldResumeActivity(null /* activeActivity */));
365
366 doReturn(STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT).when(mStack).getVisibility(null);
367 assertEquals(false, mActivity.shouldResumeActivity(null /* activeActivity */));
368
369 doReturn(STACK_VISIBILITY_INVISIBLE).when(mStack).getVisibility(null);
370 assertEquals(false, mActivity.shouldResumeActivity(null /* activeActivity */));
371 }
372
373 @Test
Garfield Tan40263302019-02-01 15:27:35 -0800374 public void testPushConfigurationWhenLaunchTaskBehind() throws Exception {
375 mActivity.setState(ActivityStack.ActivityState.STOPPED, "Testing");
376
377 final TestActivityStack stack = (TestActivityStack) new StackBuilder(mRootActivityContainer)
378 .build();
379 try {
380 stack.setIsTranslucent(false);
381 assertFalse(mStack.shouldBeVisible(null /* starting */));
382
383 mTask.onRequestedOverrideConfigurationChanged(mTask.getConfiguration());
384 mActivity.setLastReportedConfiguration(new MergedConfiguration(new Configuration(),
385 mActivity.getConfiguration()));
386
387 mActivity.mLaunchTaskBehind = true;
388 mActivity.info.configChanges |= ActivityInfo.CONFIG_ORIENTATION;
389 final Configuration newConfig = new Configuration(mActivity.getConfiguration());
390 newConfig.orientation = newConfig.orientation == Configuration.ORIENTATION_PORTRAIT
391 ? Configuration.ORIENTATION_LANDSCAPE
392 : Configuration.ORIENTATION_PORTRAIT;
393
394 mTask.onConfigurationChanged(newConfig);
395
396 mActivity.ensureActivityConfiguration(0 /* globalChanges */,
397 false /* preserveWindow */, true /* ignoreStopState */);
398
399 final ActivityConfigurationChangeItem expected =
400 ActivityConfigurationChangeItem.obtain(newConfig);
401 verify(mService.getLifecycleManager()).scheduleTransaction(
402 eq(mActivity.app.getThread()), eq(mActivity.appToken), eq(expected));
403 } finally {
404 stack.getDisplay().removeChild(stack);
405 }
406 }
Riddle Hsu0a343c32018-12-21 00:40:48 +0800407
408 @Test
409 public void testFixedScreenConfigurationWhenMovingToDisplay() {
410 // Initialize different bounds on a new display.
411 final ActivityDisplay newDisplay = addNewActivityDisplayAt(ActivityDisplay.POSITION_TOP);
412 newDisplay.setBounds(0, 0, 1000, 2000);
413 newDisplay.getConfiguration().densityDpi = 300;
414
415 mTask.getWindowConfiguration().setAppBounds(mStack.getDisplay().getBounds());
416 mTask.getConfiguration().densityDpi = 200;
417 when(mActivity.mAppWindowToken.getOrientationIgnoreVisibility()).thenReturn(
418 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
419 mActivity.info.resizeMode = ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
420 mActivity.info.maxAspectRatio = 1.5f;
421 ensureActivityConfiguration();
422 final Rect originalBounds = new Rect(mActivity.getBounds());
423 final int originalDpi = mActivity.getConfiguration().densityDpi;
424
425 // Move the non-resizable activity to the new display.
426 mStack.reparent(newDisplay, true /* onTop */, false /* displayRemoved */);
427 ensureActivityConfiguration();
428
429 assertEquals(originalBounds, mActivity.getBounds());
430 assertEquals(originalDpi, mActivity.getConfiguration().densityDpi);
431 }
432
433 @Test
434 public void testFixedScreenBoundsWhenDisplaySizeChanged() {
435 when(mActivity.mAppWindowToken.getOrientationIgnoreVisibility()).thenReturn(
436 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
437 mTask.getWindowConfiguration().setAppBounds(mStack.getDisplay().getBounds());
438 mActivity.info.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
439 mActivity.info.resizeMode = ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
440 ensureActivityConfiguration();
441 final Rect originalBounds = new Rect(mActivity.getBounds());
442
443 // Change the size of current display.
444 mStack.getDisplay().setBounds(0, 0, 1000, 2000);
445 ensureActivityConfiguration();
446
447 assertEquals(originalBounds, mActivity.getBounds());
448 }
Bryce Leeaf691c02017-03-20 14:20:22 -0700449}