Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 14 | * limitations under the License. |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
| 21 | import static android.view.WindowManager.TRANSIT_ACTIVITY_CLOSE; |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 22 | import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN; |
Jorim Jaggi | 9c52ebb | 2018-06-01 14:45:24 +0200 | [diff] [blame] | 23 | import static android.view.WindowManager.TRANSIT_CRASHING_ACTIVITY_CLOSE; |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 24 | import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY; |
| 25 | import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 26 | |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 27 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 28 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 29 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 30 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 31 | import static org.junit.Assert.assertEquals; |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 32 | import static org.junit.Assert.assertFalse; |
| 33 | import static org.junit.Assert.assertTrue; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 34 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 35 | import android.graphics.Rect; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 36 | import android.platform.test.annotations.Presubmit; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 37 | import android.view.Display; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 38 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 39 | import androidx.test.filters.SmallTest; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 40 | |
| 41 | import org.junit.Before; |
| 42 | import org.junit.Test; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Test class for {@link AppTransition}. |
| 46 | * |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 47 | * Build/Install/Run: |
| 48 | * atest FrameworksServicesTests:AppTransitionTests |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 49 | */ |
| 50 | @SmallTest |
| 51 | @Presubmit |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 52 | public class AppTransitionTests extends WindowTestsBase { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 53 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 54 | private DisplayContent mDc; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 55 | |
| 56 | @Before |
| 57 | public void setUp() throws Exception { |
Yunfan Chen | 787b244d | 2019-02-22 12:34:39 +0900 | [diff] [blame] | 58 | synchronized (mWm.mGlobalLock) { |
| 59 | // Hold the lock to protect the stubbing from being accessed by other threads. |
| 60 | spyOn(mWm.mRoot); |
| 61 | doNothing().when(mWm.mRoot).performSurfacePlacement(anyBoolean()); |
| 62 | } |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 63 | mDc = mWm.getDefaultDisplayContentLocked(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 67 | public void testKeyguardOverride() { |
| 68 | mWm.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false /* alwaysKeepCurrent */); |
| 69 | mWm.prepareAppTransition(TRANSIT_KEYGUARD_GOING_AWAY, false /* alwaysKeepCurrent */); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 70 | assertEquals(TRANSIT_KEYGUARD_GOING_AWAY, mDc.mAppTransition.getAppTransition()); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 74 | public void testKeyguardKeep() { |
| 75 | mWm.prepareAppTransition(TRANSIT_KEYGUARD_GOING_AWAY, false /* alwaysKeepCurrent */); |
| 76 | mWm.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false /* alwaysKeepCurrent */); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 77 | assertEquals(TRANSIT_KEYGUARD_GOING_AWAY, mDc.mAppTransition.getAppTransition()); |
Jorim Jaggi | 9c52ebb | 2018-06-01 14:45:24 +0200 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 81 | public void testForceOverride() { |
| 82 | mWm.prepareAppTransition(TRANSIT_KEYGUARD_UNOCCLUDE, false /* alwaysKeepCurrent */); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 83 | mDc.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 84 | false /* alwaysKeepCurrent */, 0 /* flags */, true /* forceOverride */); |
| 85 | assertEquals(TRANSIT_ACTIVITY_OPEN, mDc.mAppTransition.getAppTransition()); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 86 | } |
Jorim Jaggi | 9c52ebb | 2018-06-01 14:45:24 +0200 | [diff] [blame] | 87 | |
| 88 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 89 | public void testCrashing() { |
| 90 | mWm.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false /* alwaysKeepCurrent */); |
| 91 | mWm.prepareAppTransition(TRANSIT_CRASHING_ACTIVITY_CLOSE, false /* alwaysKeepCurrent */); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 92 | assertEquals(TRANSIT_CRASHING_ACTIVITY_CLOSE, mDc.mAppTransition.getAppTransition()); |
Jorim Jaggi | 9c52ebb | 2018-06-01 14:45:24 +0200 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 96 | public void testKeepKeyguard_withCrashing() { |
| 97 | mWm.prepareAppTransition(TRANSIT_KEYGUARD_GOING_AWAY, false /* alwaysKeepCurrent */); |
| 98 | mWm.prepareAppTransition(TRANSIT_CRASHING_ACTIVITY_CLOSE, false /* alwaysKeepCurrent */); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 99 | assertEquals(TRANSIT_KEYGUARD_GOING_AWAY, mDc.mAppTransition.getAppTransition()); |
| 100 | } |
| 101 | |
| 102 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 103 | public void testAppTransitionStateForMultiDisplay() { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 104 | // Create 2 displays & presume both display the state is ON for ready to display & animate. |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 105 | final DisplayContent dc1 = createNewDisplay(Display.STATE_ON); |
| 106 | final DisplayContent dc2 = createNewDisplay(Display.STATE_ON); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 107 | |
| 108 | // Create 2 app window tokens to represent 2 activity window. |
| 109 | final WindowTestUtils.TestAppWindowToken token1 = createTestAppWindowToken(dc1, |
| 110 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); |
| 111 | final WindowTestUtils.TestAppWindowToken token2 = createTestAppWindowToken(dc2, |
| 112 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); |
| 113 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 114 | token1.allDrawn = true; |
| 115 | token1.startingDisplayed = true; |
| 116 | token1.startingMoved = true; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 117 | |
| 118 | // Simulate activity resume / finish flows to prepare app transition & set visibility, |
| 119 | // make sure transition is set as expected for each display. |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 120 | dc1.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 121 | false /* alwaysKeepCurrent */, 0 /* flags */, false /* forceOverride */); |
| 122 | assertEquals(TRANSIT_ACTIVITY_OPEN, dc1.mAppTransition.getAppTransition()); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 123 | dc2.prepareAppTransition(TRANSIT_ACTIVITY_CLOSE, |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 124 | false /* alwaysKeepCurrent */, 0 /* flags */, false /* forceOverride */); |
| 125 | assertEquals(TRANSIT_ACTIVITY_CLOSE, dc2.mAppTransition.getAppTransition()); |
| 126 | // One activity window is visible for resuming & the other activity window is invisible |
| 127 | // for finishing in different display. |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 128 | token1.setVisibility(true, false); |
| 129 | token2.setVisibility(false, false); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 130 | |
| 131 | // Make sure each display is in animating stage. |
| 132 | assertTrue(dc1.mOpeningApps.size() > 0); |
| 133 | assertTrue(dc2.mClosingApps.size() > 0); |
| 134 | assertTrue(dc1.isAppAnimating()); |
| 135 | assertTrue(dc2.isAppAnimating()); |
| 136 | } |
| 137 | |
| 138 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 139 | public void testCleanAppTransitionWhenTaskStackReparent() { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 140 | // Create 2 displays & presume both display the state is ON for ready to display & animate. |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 141 | final DisplayContent dc1 = createNewDisplay(Display.STATE_ON); |
| 142 | final DisplayContent dc2 = createNewDisplay(Display.STATE_ON); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 143 | |
| 144 | final TaskStack stack1 = createTaskStackOnDisplay(dc1); |
| 145 | final Task task1 = createTaskInStack(stack1, 0 /* userId */); |
| 146 | final WindowTestUtils.TestAppWindowToken token1 = |
| 147 | WindowTestUtils.createTestAppWindowToken(dc1); |
| 148 | task1.addChild(token1, 0); |
| 149 | |
| 150 | // Simulate same app is during opening / closing transition set stage. |
| 151 | dc1.mClosingApps.add(token1); |
| 152 | assertTrue(dc1.mClosingApps.size() > 0); |
| 153 | |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 154 | dc1.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 155 | false /* alwaysKeepCurrent */, 0 /* flags */, false /* forceOverride */); |
| 156 | assertEquals(TRANSIT_ACTIVITY_OPEN, dc1.mAppTransition.getAppTransition()); |
| 157 | assertTrue(dc1.mAppTransition.isTransitionSet()); |
| 158 | |
| 159 | dc1.mOpeningApps.add(token1); |
| 160 | assertTrue(dc1.mOpeningApps.size() > 0); |
| 161 | |
| 162 | // Move stack to another display. |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 163 | stack1.reparent(dc2.getDisplayId(), new Rect(), true); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 164 | |
| 165 | // Verify if token are cleared from both pending transition list in former display. |
| 166 | assertFalse(dc1.mOpeningApps.contains(token1)); |
| 167 | assertFalse(dc1.mOpeningApps.contains(token1)); |
| 168 | } |
| 169 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 170 | } |