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