• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
14  * limitations under the License.
15  */
16 
17 package android.server.wm;
18 
19 import static android.server.wm.WindowManagerState.TRANSIT_ACTIVITY_CLOSE;
20 import static android.server.wm.WindowManagerState.TRANSIT_ACTIVITY_OPEN;
21 import static android.server.wm.WindowManagerState.TRANSIT_TASK_CLOSE;
22 import static android.server.wm.WindowManagerState.TRANSIT_TASK_OPEN;
23 import static android.server.wm.WindowManagerState.TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE;
24 import static android.server.wm.WindowManagerState.TRANSIT_WALLPAPER_CLOSE;
25 import static android.server.wm.WindowManagerState.TRANSIT_WALLPAPER_INTRA_CLOSE;
26 import static android.server.wm.WindowManagerState.TRANSIT_WALLPAPER_INTRA_OPEN;
27 import static android.server.wm.WindowManagerState.TRANSIT_WALLPAPER_OPEN;
28 import static android.server.wm.app.Components.BOTTOM_ACTIVITY;
29 import static android.server.wm.app.Components.BOTTOM_NON_RESIZABLE_ACTIVITY;
30 import static android.server.wm.app.Components.BottomActivity.EXTRA_BOTTOM_WALLPAPER;
31 import static android.server.wm.app.Components.BottomActivity.EXTRA_STOP_DELAY;
32 import static android.server.wm.app.Components.TOP_ACTIVITY;
33 import static android.server.wm.app.Components.TOP_NON_RESIZABLE_ACTIVITY;
34 import static android.server.wm.app.Components.TOP_NON_RESIZABLE_WALLPAPER_ACTIVITY;
35 import static android.server.wm.app.Components.TOP_WALLPAPER_ACTIVITY;
36 import static android.server.wm.app.Components.TRANSLUCENT_TOP_ACTIVITY;
37 import static android.server.wm.app.Components.TRANSLUCENT_TOP_NON_RESIZABLE_ACTIVITY;
38 import static android.server.wm.app.Components.TRANSLUCENT_TOP_WALLPAPER_ACTIVITY;
39 import static android.server.wm.app.Components.TopActivity.EXTRA_FINISH_DELAY;
40 
41 import static org.junit.Assert.assertEquals;
42 
43 import android.content.ComponentName;
44 import android.platform.test.annotations.Presubmit;
45 
46 import org.junit.Test;
47 
48 /**
49  * This test tests the transition type selection logic in ActivityManager/WindowManager.
50  * BottomActivity is started first, then TopActivity, and we check the transition type that the
51  * system selects when TopActivity enters or exits under various setups.
52  *
53  * Note that we only require the correct transition type to be reported (eg. TRANSIT_ACTIVITY_OPEN,
54  * TRANSIT_TASK_CLOSE, TRANSIT_WALLPAPER_OPEN, etc.). The exact animation is unspecified and can be
55  * overridden.
56  *
57  * <p>Build/Install/Run:
58  *     atest CtsWindowManagerDeviceTestCases:TransitionSelectionTests
59  */
60 @Presubmit
61 public class TransitionSelectionTests extends ActivityManagerTestBase {
62 
63     // Test activity open/close under normal timing
64     @Test
testOpenActivity_NeitherWallpaper()65     public void testOpenActivity_NeitherWallpaper() {
66         testOpenActivity(false /*bottomWallpaper*/, false /*topWallpaper*/,
67                 false /*slowStop*/, TRANSIT_ACTIVITY_OPEN);
68     }
69 
70     @Test
testCloseActivity_NeitherWallpaper()71     public void testCloseActivity_NeitherWallpaper() {
72         testCloseActivity(false /*bottomWallpaper*/, false /*topWallpaper*/,
73                 false /*slowStop*/, TRANSIT_ACTIVITY_CLOSE);
74     }
75 
76     @Test
testOpenActivity_BottomWallpaper()77     public void testOpenActivity_BottomWallpaper() {
78         testOpenActivity(true /*bottomWallpaper*/, false /*topWallpaper*/,
79                 false /*slowStop*/, TRANSIT_WALLPAPER_CLOSE);
80     }
81 
82     @Test
testCloseActivity_BottomWallpaper()83     public void testCloseActivity_BottomWallpaper() {
84         testCloseActivity(true /*bottomWallpaper*/, false /*topWallpaper*/,
85                 false /*slowStop*/, TRANSIT_WALLPAPER_OPEN);
86     }
87 
88     @Test
testOpenActivity_BothWallpaper()89     public void testOpenActivity_BothWallpaper() {
90         testOpenActivity(true /*bottomWallpaper*/, true /*topWallpaper*/,
91                 false /*slowStop*/, TRANSIT_WALLPAPER_INTRA_OPEN);
92     }
93 
94     @Test
testCloseActivity_BothWallpaper()95     public void testCloseActivity_BothWallpaper() {
96         testCloseActivity(true /*bottomWallpaper*/, true /*topWallpaper*/,
97                 false /*slowStop*/, TRANSIT_WALLPAPER_INTRA_CLOSE);
98     }
99 
100     //------------------------------------------------------------------------//
101 
102     // Test task open/close under normal timing
103     @Test
testOpenTask_NeitherWallpaper()104     public void testOpenTask_NeitherWallpaper() {
105         testOpenTask(false /*bottomWallpaper*/, false /*topWallpaper*/,
106             true /* topResizable */, false /*slowStop*/, TRANSIT_TASK_OPEN);
107     }
108 
109     @Test
testCloseTask_NeitherWallpaper()110     public void testCloseTask_NeitherWallpaper() {
111         testCloseTask(false /*bottomWallpaper*/, false /*topWallpaper*/,
112             true /* topResizable */, false /*slowStop*/, TRANSIT_TASK_CLOSE);
113     }
114 
115     @Test
testOpenTask_BottomWallpaper_TopNonResizable()116     public void testOpenTask_BottomWallpaper_TopNonResizable() {
117         testOpenTask(true /*bottomWallpaper*/, false /*topWallpaper*/,
118             false /* topResizable */, false /*slowStop*/, TRANSIT_WALLPAPER_CLOSE);
119     }
120 
121     @Test
testCloseTask_BottomWallpaper_TopNonResizable()122     public void testCloseTask_BottomWallpaper_TopNonResizable() {
123         testCloseTask(true /*bottomWallpaper*/, false /*topWallpaper*/,
124             false /* topResizable */, false /*slowStop*/, TRANSIT_WALLPAPER_OPEN);
125     }
126 
127     @Test
testOpenTask_BothWallpaper()128     public void testOpenTask_BothWallpaper() {
129         testOpenTask(true /*bottomWallpaper*/, true /*topWallpaper*/,
130             false /* topResizable */, false /*slowStop*/, TRANSIT_WALLPAPER_INTRA_OPEN);
131     }
132 
133     @Test
testCloseTask_BothWallpaper()134     public void testCloseTask_BothWallpaper() {
135         testCloseTask(true /*bottomWallpaper*/, true /*topWallpaper*/,
136             false /* topResizable */, false /*slowStop*/, TRANSIT_WALLPAPER_INTRA_CLOSE);
137     }
138 
139     //------------------------------------------------------------------------//
140 
141     // Test activity close -- bottom activity slow in stopping
142     // These simulate the case where the bottom activity is resumed
143     // before AM receives its activitiyStopped
144     @Test
testCloseActivity_NeitherWallpaper_SlowStop()145     public void testCloseActivity_NeitherWallpaper_SlowStop() {
146         testCloseActivity(false /*bottomWallpaper*/, false /*topWallpaper*/,
147                 true /*slowStop*/, TRANSIT_ACTIVITY_CLOSE);
148     }
149 
150     @Test
testCloseActivity_BottomWallpaper_SlowStop()151     public void testCloseActivity_BottomWallpaper_SlowStop() {
152         testCloseActivity(true /*bottomWallpaper*/, false /*topWallpaper*/,
153                 true /*slowStop*/, TRANSIT_WALLPAPER_OPEN);
154     }
155 
156     @Test
testCloseActivity_BothWallpaper_SlowStop()157     public void testCloseActivity_BothWallpaper_SlowStop() {
158         testCloseActivity(true /*bottomWallpaper*/, true /*topWallpaper*/,
159                 true /*slowStop*/, TRANSIT_WALLPAPER_INTRA_CLOSE);
160     }
161 
162     //------------------------------------------------------------------------//
163 
164     // Test task close -- bottom task top activity slow in stopping
165     // These simulate the case where the bottom activity is resumed
166     // before AM receives its activitiyStopped
167     @Test
testCloseTask_NeitherWallpaper_SlowStop()168     public void testCloseTask_NeitherWallpaper_SlowStop() {
169         testCloseTask(false /*bottomWallpaper*/, false /*topWallpaper*/,
170             true /* topResizable */, true /*slowStop*/, TRANSIT_TASK_CLOSE);
171     }
172 
173     @Test
testCloseTask_BottomWallpaper_TopNonResizable_SlowStop()174     public void testCloseTask_BottomWallpaper_TopNonResizable_SlowStop() {
175         testCloseTask(true /*bottomWallpaper*/, false /*topWallpaper*/,
176             false /* topResizable */, true /*slowStop*/, TRANSIT_WALLPAPER_OPEN);
177     }
178 
179     @Test
testCloseTask_BothWallpaper_SlowStop()180     public void testCloseTask_BothWallpaper_SlowStop() {
181         testCloseTask(true /*bottomWallpaper*/, true /*topWallpaper*/,
182             false /* topResizable */, true /*slowStop*/, TRANSIT_WALLPAPER_INTRA_CLOSE);
183     }
184 
185     //------------------------------------------------------------------------//
186 
187     /// Test closing of translucent activity/task
188     @Test
testCloseActivity_NeitherWallpaper_Translucent()189     public void testCloseActivity_NeitherWallpaper_Translucent() {
190         testCloseActivityTranslucent(false /*bottomWallpaper*/, false /*topWallpaper*/,
191                 TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE);
192     }
193 
194     @Test
testCloseActivity_BottomWallpaper_Translucent()195     public void testCloseActivity_BottomWallpaper_Translucent() {
196         testCloseActivityTranslucent(true /*bottomWallpaper*/, false /*topWallpaper*/,
197                 TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE);
198     }
199 
200     @Test
testCloseActivity_BothWallpaper_Translucent()201     public void testCloseActivity_BothWallpaper_Translucent() {
202         testCloseActivityTranslucent(true /*bottomWallpaper*/, true /*topWallpaper*/,
203                 TRANSIT_WALLPAPER_INTRA_CLOSE);
204     }
205 
206     @Test
testCloseTask_NeitherWallpaper_Translucent()207     public void testCloseTask_NeitherWallpaper_Translucent() {
208         testCloseTaskTranslucent(false /*bottomWallpaper*/, false /*topWallpaper*/,
209                 TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE);
210     }
211 
212     @Test
testCloseTask_BottomWallpaper_Translucent()213     public void testCloseTask_BottomWallpaper_Translucent() {
214         testCloseTaskTranslucent(true /*bottomWallpaper*/, false /*topWallpaper*/,
215                 TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE);
216     }
217 
218     @Test
testCloseTask_BothWallpaper_Translucent()219     public void testCloseTask_BothWallpaper_Translucent() {
220         testCloseTaskTranslucent(true /*bottomWallpaper*/, true /*topWallpaper*/,
221                 TRANSIT_WALLPAPER_INTRA_CLOSE);
222     }
223 
224     //------------------------------------------------------------------------//
225 
testOpenActivity(boolean bottomWallpaper, boolean topWallpaper, boolean slowStop, String expectedTransit)226     private void testOpenActivity(boolean bottomWallpaper,
227             boolean topWallpaper, boolean slowStop, String expectedTransit) {
228         testTransitionSelection(true /*testOpen*/, false /*testNewTask*/,
229             bottomWallpaper, topWallpaper, false /*topTranslucent*/, true /* topResizable */,
230             slowStop, expectedTransit);
231     }
232 
testCloseActivity(boolean bottomWallpaper, boolean topWallpaper, boolean slowStop, String expectedTransit)233     private void testCloseActivity(boolean bottomWallpaper,
234             boolean topWallpaper, boolean slowStop, String expectedTransit) {
235         testTransitionSelection(false /*testOpen*/, false /*testNewTask*/,
236             bottomWallpaper, topWallpaper, false /*topTranslucent*/, true /* topResizable */,
237             slowStop, expectedTransit);
238     }
239 
testOpenTask(boolean bottomWallpaper, boolean topWallpaper, boolean topResizable, boolean slowStop, String expectedTransit)240     private void testOpenTask(boolean bottomWallpaper,
241         boolean topWallpaper, boolean topResizable, boolean slowStop, String expectedTransit) {
242         testTransitionSelection(true /*testOpen*/, true /*testNewTask*/,
243             bottomWallpaper, topWallpaper, false /*topTranslucent*/, topResizable, slowStop,
244             expectedTransit);
245     }
246 
testCloseTask(boolean bottomWallpaper, boolean topWallpaper, boolean topResizable, boolean slowStop, String expectedTransit)247     private void testCloseTask(boolean bottomWallpaper,
248         boolean topWallpaper, boolean topResizable, boolean slowStop, String expectedTransit) {
249         testTransitionSelection(false /*testOpen*/, true /*testNewTask*/,
250             bottomWallpaper, topWallpaper, false /*topTranslucent*/,
251             topResizable /* topResizable */, slowStop, expectedTransit);
252     }
253 
testCloseActivityTranslucent(boolean bottomWallpaper, boolean topWallpaper, String expectedTransit)254     private void testCloseActivityTranslucent(boolean bottomWallpaper,
255             boolean topWallpaper, String expectedTransit) {
256         testTransitionSelection(false /*testOpen*/, false /*testNewTask*/,
257             bottomWallpaper, topWallpaper, true /*topTranslucent*/, true /* topResizable */,
258             false /*slowStop*/, expectedTransit);
259     }
260 
testCloseTaskTranslucent(boolean bottomWallpaper, boolean topWallpaper, String expectedTransit)261     private void testCloseTaskTranslucent(boolean bottomWallpaper,
262             boolean topWallpaper, String expectedTransit) {
263         testTransitionSelection(false /*testOpen*/, true /*testNewTask*/,
264             bottomWallpaper, topWallpaper, true /*topTranslucent*/, true /* topResizable */,
265             false /*slowStop*/, expectedTransit);
266     }
267 
268     //------------------------------------------------------------------------//
269 
testTransitionSelection( boolean testOpen, boolean testNewTask, boolean bottomWallpaper, boolean topWallpaper, boolean topTranslucent, boolean topResizable, boolean testSlowStop, String expectedTransit)270     private void testTransitionSelection(
271         boolean testOpen, boolean testNewTask,
272         boolean bottomWallpaper, boolean topWallpaper, boolean topTranslucent,
273         boolean topResizable, boolean testSlowStop, String expectedTransit) {
274         final ComponentName bottomComponent = bottomWallpaper
275             ? BOTTOM_NON_RESIZABLE_ACTIVITY : BOTTOM_ACTIVITY;
276         String bottomStartCmd = getAmStartCmd(bottomComponent);
277         if (bottomWallpaper) {
278             bottomStartCmd += " --ez " + EXTRA_BOTTOM_WALLPAPER + " true";
279         }
280         if (testSlowStop) {
281             bottomStartCmd += " --ei " + EXTRA_STOP_DELAY + " 3000";
282         }
283         executeShellCommand(bottomStartCmd);
284 
285         mWmState.computeState(bottomComponent);
286 
287         final ComponentName topActivity;
288         if (topTranslucent && !topResizable) {
289             topActivity = TRANSLUCENT_TOP_NON_RESIZABLE_ACTIVITY;
290         } else if (topTranslucent && topWallpaper) {
291             topActivity = TRANSLUCENT_TOP_WALLPAPER_ACTIVITY;
292         } else if (topTranslucent) {
293             topActivity = TRANSLUCENT_TOP_ACTIVITY;
294         } else if (!topResizable && topWallpaper) {
295             topActivity = TOP_NON_RESIZABLE_WALLPAPER_ACTIVITY;
296         } else if (!topResizable) {
297             topActivity = TOP_NON_RESIZABLE_ACTIVITY;
298         } else if (topWallpaper) {
299             topActivity = TOP_WALLPAPER_ACTIVITY;
300         } else {
301             topActivity = TOP_ACTIVITY;
302         }
303         String topStartCmd = getAmStartCmd(topActivity);
304         if (testNewTask) {
305             topStartCmd += " -f 0x18000000";
306         }
307         if (!testOpen) {
308             topStartCmd += " --ei " + EXTRA_FINISH_DELAY + " 1000";
309         }
310         executeShellCommand(topStartCmd);
311 
312         Condition.waitFor("Retrieving correct transition", () -> {
313             if (testOpen) {
314                 mWmState.computeState(topActivity);
315             } else {
316                 mWmState.computeState(bottomComponent);
317             }
318             return expectedTransit.equals(
319                     mWmState.getDefaultDisplayLastTransition());
320         });
321         assertEquals("Picked wrong transition", expectedTransit,
322                 mWmState.getDefaultDisplayLastTransition());
323     }
324 }
325