Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 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 |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.am; |
| 18 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
| 21 | import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_DESTROYING; |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 22 | import static org.junit.Assert.assertEquals; |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 23 | import static org.junit.Assert.assertFalse; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 24 | import static org.junit.Assert.assertNotNull; |
| 25 | import static org.junit.Assert.assertNull; |
| 26 | |
| 27 | import android.content.ComponentName; |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 28 | import android.content.pm.ActivityInfo; |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 29 | import android.os.UserHandle; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 30 | import android.platform.test.annotations.Presubmit; |
| 31 | import android.support.test.filters.SmallTest; |
| 32 | import android.support.test.runner.AndroidJUnit4; |
| 33 | |
| 34 | import org.junit.runner.RunWith; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 35 | import org.junit.Before; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 36 | import org.junit.Test; |
| 37 | |
| 38 | /** |
| 39 | * Tests for the {@link ActivityStack} class. |
| 40 | * |
| 41 | * Build/Install/Run: |
| 42 | * bit FrameworksServicesTests:com.android.server.am.ActivityStackTests |
| 43 | */ |
| 44 | @SmallTest |
| 45 | @Presubmit |
| 46 | @RunWith(AndroidJUnit4.class) |
| 47 | public class ActivityStackTests extends ActivityTestsBase { |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 48 | private static final int TEST_STACK_ID = 100; |
| 49 | private static final ComponentName testActivityComponent = |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 50 | ComponentName.unflattenFromString("com.foo/.BarActivity"); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 51 | private static final ComponentName testOverlayComponent = |
| 52 | ComponentName.unflattenFromString("com.foo/.OverlayActivity"); |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 53 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 54 | private ActivityManagerService mService; |
| 55 | private ActivityStackSupervisor mSupervisor; |
| 56 | private ActivityStack mStack; |
| 57 | private TaskRecord mTask; |
| 58 | |
| 59 | @Before |
| 60 | @Override |
| 61 | public void setUp() throws Exception { |
| 62 | super.setUp(); |
| 63 | |
| 64 | mService = createActivityManagerService(); |
| 65 | mSupervisor = mService.mStackSupervisor; |
| 66 | mStack = mService.mStackSupervisor.getDefaultDisplay().createStack( |
| 67 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 68 | mTask = createTask(mSupervisor, testActivityComponent, mStack); |
| 69 | } |
| 70 | |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 71 | @Test |
| 72 | public void testEmptyTaskCleanupOnRemove() throws Exception { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 73 | assertNotNull(mTask.getWindowContainerController()); |
| 74 | mStack.removeTask(mTask, "testEmptyTaskCleanupOnRemove", REMOVE_TASK_MODE_DESTROYING); |
| 75 | assertNull(mTask.getWindowContainerController()); |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 76 | } |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 77 | |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 78 | @Test |
| 79 | public void testOccupiedTaskCleanupOnRemove() throws Exception { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 80 | final ActivityRecord r = createActivity(mService, testActivityComponent, mTask); |
| 81 | assertNotNull(mTask.getWindowContainerController()); |
| 82 | mStack.removeTask(mTask, "testOccupiedTaskCleanupOnRemove", REMOVE_TASK_MODE_DESTROYING); |
| 83 | assertNotNull(mTask.getWindowContainerController()); |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 84 | } |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 85 | |
| 86 | @Test |
| 87 | public void testNoPauseDuringResumeTopActivity() throws Exception { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 88 | final ActivityRecord r = createActivity(mService, testActivityComponent, mTask); |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 89 | |
| 90 | // Simulate the a resumed activity set during |
| 91 | // {@link ActivityStack#resumeTopActivityUncheckedLocked}. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 92 | mSupervisor.inResumeTopActivity = true; |
| 93 | mStack.mResumedActivity = r; |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 94 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 95 | final boolean waiting = mStack.goToSleepIfPossible(false); |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 96 | |
| 97 | // Ensure we report not being ready for sleep. |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 98 | assertFalse(waiting); |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 99 | |
| 100 | // Make sure the resumed activity is untouched. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 101 | assertEquals(mStack.mResumedActivity, r); |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 102 | } |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 103 | |
| 104 | @Test |
| 105 | public void testStopActivityWhenActivityDestroyed() throws Exception { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 106 | final ActivityRecord r = createActivity(mService, testActivityComponent, mTask); |
| 107 | r.info.flags |= ActivityInfo.FLAG_NO_HISTORY; |
| 108 | mSupervisor.setFocusStackUnchecked("testStopActivityWithDestroy", mStack); |
| 109 | mStack.stopActivityLocked(r); |
| 110 | // Mostly testing to make sure there is a crash in the call part, so if we get here we are |
| 111 | // good-to-go! |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 112 | } |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 113 | |
| 114 | @Test |
| 115 | public void testFindTaskWithOverlay() throws Exception { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 116 | final ActivityRecord r = createActivity(mService, testActivityComponent, mTask, 0); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 117 | // Overlay must be for a different user to prevent recognizing a matching top activity |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 118 | final ActivityRecord taskOverlay = createActivity(mService, testOverlayComponent, mTask, |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 119 | UserHandle.PER_USER_RANGE * 2); |
| 120 | taskOverlay.mTaskOverlay = true; |
| 121 | |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 122 | final ActivityStackSupervisor.FindTaskResult result = |
| 123 | new ActivityStackSupervisor.FindTaskResult(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 124 | mStack.findTaskLocked(r, result); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 125 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 126 | assertEquals(mTask.getTopActivity(false /* includeOverlays */), r); |
| 127 | assertEquals(mTask.getTopActivity(true /* includeOverlays */), taskOverlay); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 128 | assertNotNull(result.r); |
| 129 | } |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 130 | } |