blob: 6e09167f7cba5751a87c434a11a47dd5217bf5dd [file] [log] [blame]
Jorim Jaggife762342016-10-13 14:33:27 +02001/*
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. Takaokab6e148c2018-11-03 02:59:06 -070014 * limitations under the License.
Jorim Jaggife762342016-10-13 14:33:27 +020015 */
16
17package com.android.server.wm;
18
lumark588a3e82018-07-20 18:53:54 +080019import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
20import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
21import static android.view.WindowManager.TRANSIT_ACTIVITY_CLOSE;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010022import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN;
Jorim Jaggi9c52ebb2018-06-01 14:45:24 +020023import static android.view.WindowManager.TRANSIT_CRASHING_ACTIVITY_CLOSE;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010024import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY;
25import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
Jorim Jaggib142f572019-03-01 16:08:54 +010026import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
Tadashi G. Takaokad7aa79a2019-02-08 17:42:37 +090027import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean;
Tadashi G. Takaokabf0d57b2018-11-19 16:09:58 +090028import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
Tadashi G. Takaokad7aa79a2019-02-08 17:42:37 +090029import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
Jorim Jaggife762342016-10-13 14:33:27 +020030import static org.junit.Assert.assertEquals;
Tadashi G. Takaokad7aa79a2019-02-08 17:42:37 +090031import static org.junit.Assert.assertFalse;
Jorim Jaggib142f572019-03-01 16:08:54 +010032import static org.junit.Assert.assertNull;
Tadashi G. Takaokad7aa79a2019-02-08 17:42:37 +090033import static org.junit.Assert.assertTrue;
Jorim Jaggife762342016-10-13 14:33:27 +020034
lumark588a3e82018-07-20 18:53:54 +080035import android.graphics.Rect;
Jorim Jaggife762342016-10-13 14:33:27 +020036import android.platform.test.annotations.Presubmit;
lumark588a3e82018-07-20 18:53:54 +080037import android.view.Display;
Brett Chabota26eda92018-07-23 13:08:30 -070038
Jorim Jaggife762342016-10-13 14:33:27 +020039import org.junit.Before;
40import org.junit.Test;
Jorim Jaggife762342016-10-13 14:33:27 +020041
Jorim Jaggib142f572019-03-01 16:08:54 +010042import androidx.test.filters.SmallTest;
43
Jorim Jaggife762342016-10-13 14:33:27 +020044/**
45 * Test class for {@link AppTransition}.
46 *
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070047 * Build/Install/Run:
Jorim Jaggib142f572019-03-01 16:08:54 +010048 * atest WmTests:AppTransitionTests
Jorim Jaggife762342016-10-13 14:33:27 +020049 */
50@SmallTest
51@Presubmit
lumark588a3e82018-07-20 18:53:54 +080052public class AppTransitionTests extends WindowTestsBase {
Jorim Jaggife762342016-10-13 14:33:27 +020053
lumark588a3e82018-07-20 18:53:54 +080054 private DisplayContent mDc;
Jorim Jaggife762342016-10-13 14:33:27 +020055
56 @Before
57 public void setUp() throws Exception {
Yunfan Chen787b244d2019-02-22 12:34:39 +090058 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. Takaokab6e148c2018-11-03 02:59:06 -070063 mDc = mWm.getDefaultDisplayContentLocked();
Jorim Jaggife762342016-10-13 14:33:27 +020064 }
65
66 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070067 public void testKeyguardOverride() {
68 mWm.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false /* alwaysKeepCurrent */);
69 mWm.prepareAppTransition(TRANSIT_KEYGUARD_GOING_AWAY, false /* alwaysKeepCurrent */);
lumark588a3e82018-07-20 18:53:54 +080070 assertEquals(TRANSIT_KEYGUARD_GOING_AWAY, mDc.mAppTransition.getAppTransition());
Jorim Jaggife762342016-10-13 14:33:27 +020071 }
72
73 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070074 public void testKeyguardKeep() {
75 mWm.prepareAppTransition(TRANSIT_KEYGUARD_GOING_AWAY, false /* alwaysKeepCurrent */);
76 mWm.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false /* alwaysKeepCurrent */);
lumark588a3e82018-07-20 18:53:54 +080077 assertEquals(TRANSIT_KEYGUARD_GOING_AWAY, mDc.mAppTransition.getAppTransition());
Jorim Jaggi9c52ebb2018-06-01 14:45:24 +020078 }
79
80 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070081 public void testForceOverride() {
82 mWm.prepareAppTransition(TRANSIT_KEYGUARD_UNOCCLUDE, false /* alwaysKeepCurrent */);
Wale Ogunwale3a256e62018-12-06 14:41:18 -080083 mDc.prepareAppTransition(TRANSIT_ACTIVITY_OPEN,
lumark588a3e82018-07-20 18:53:54 +080084 false /* alwaysKeepCurrent */, 0 /* flags */, true /* forceOverride */);
85 assertEquals(TRANSIT_ACTIVITY_OPEN, mDc.mAppTransition.getAppTransition());
Jorim Jaggife762342016-10-13 14:33:27 +020086 }
Jorim Jaggi9c52ebb2018-06-01 14:45:24 +020087
88 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070089 public void testCrashing() {
90 mWm.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false /* alwaysKeepCurrent */);
91 mWm.prepareAppTransition(TRANSIT_CRASHING_ACTIVITY_CLOSE, false /* alwaysKeepCurrent */);
lumark588a3e82018-07-20 18:53:54 +080092 assertEquals(TRANSIT_CRASHING_ACTIVITY_CLOSE, mDc.mAppTransition.getAppTransition());
Jorim Jaggi9c52ebb2018-06-01 14:45:24 +020093 }
94
95 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070096 public void testKeepKeyguard_withCrashing() {
97 mWm.prepareAppTransition(TRANSIT_KEYGUARD_GOING_AWAY, false /* alwaysKeepCurrent */);
98 mWm.prepareAppTransition(TRANSIT_CRASHING_ACTIVITY_CLOSE, false /* alwaysKeepCurrent */);
lumark588a3e82018-07-20 18:53:54 +080099 assertEquals(TRANSIT_KEYGUARD_GOING_AWAY, mDc.mAppTransition.getAppTransition());
100 }
101
102 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700103 public void testAppTransitionStateForMultiDisplay() {
lumark588a3e82018-07-20 18:53:54 +0800104 // Create 2 displays & presume both display the state is ON for ready to display & animate.
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800105 final DisplayContent dc1 = createNewDisplay(Display.STATE_ON);
106 final DisplayContent dc2 = createNewDisplay(Display.STATE_ON);
lumark588a3e82018-07-20 18:53:54 +0800107
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
lumark588a3e82018-07-20 18:53:54 +0800114 token1.allDrawn = true;
115 token1.startingDisplayed = true;
116 token1.startingMoved = true;
lumark588a3e82018-07-20 18:53:54 +0800117
118 // Simulate activity resume / finish flows to prepare app transition & set visibility,
119 // make sure transition is set as expected for each display.
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800120 dc1.prepareAppTransition(TRANSIT_ACTIVITY_OPEN,
lumark588a3e82018-07-20 18:53:54 +0800121 false /* alwaysKeepCurrent */, 0 /* flags */, false /* forceOverride */);
122 assertEquals(TRANSIT_ACTIVITY_OPEN, dc1.mAppTransition.getAppTransition());
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800123 dc2.prepareAppTransition(TRANSIT_ACTIVITY_CLOSE,
lumark588a3e82018-07-20 18:53:54 +0800124 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 Chen1ee84ea2018-11-13 16:03:37 -0800128 token1.setVisibility(true, false);
129 token2.setVisibility(false, false);
lumark588a3e82018-07-20 18:53:54 +0800130
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. Takaokab6e148c2018-11-03 02:59:06 -0700139 public void testCleanAppTransitionWhenTaskStackReparent() {
lumark588a3e82018-07-20 18:53:54 +0800140 // Create 2 displays & presume both display the state is ON for ready to display & animate.
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800141 final DisplayContent dc1 = createNewDisplay(Display.STATE_ON);
142 final DisplayContent dc2 = createNewDisplay(Display.STATE_ON);
lumark588a3e82018-07-20 18:53:54 +0800143
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 Ogunwale3a256e62018-12-06 14:41:18 -0800154 dc1.prepareAppTransition(TRANSIT_ACTIVITY_OPEN,
lumark588a3e82018-07-20 18:53:54 +0800155 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 Chen279f5582018-12-12 15:24:50 -0800163 stack1.reparent(dc2.getDisplayId(), new Rect(), true);
lumark588a3e82018-07-20 18:53:54 +0800164
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 Jaggib142f572019-03-01 16:08:54 +0100170 @Test
171 public void testLoadAnimationSafely() {
172 DisplayContent dc = createNewDisplay(Display.STATE_ON);
173 assertNull(dc.mAppTransition.loadAnimationSafely(
174 getInstrumentation().getTargetContext(), -1));
175 }
176
Jorim Jaggife762342016-10-13 14:33:27 +0200177}