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.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; 20 import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; 21 import static android.server.wm.ShellCommandHelper.executeShellCommand; 22 import static android.server.wm.WindowManagerState.TRANSIT_ACTIVITY_CLOSE; 23 import static android.server.wm.WindowManagerState.TRANSIT_ACTIVITY_OPEN; 24 import static android.server.wm.WindowManagerState.TRANSIT_TASK_CLOSE; 25 import static android.server.wm.WindowManagerState.TRANSIT_TASK_OPEN; 26 import static android.server.wm.WindowManagerState.TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE; 27 import static android.server.wm.WindowManagerState.TRANSIT_WALLPAPER_CLOSE; 28 import static android.server.wm.WindowManagerState.TRANSIT_WALLPAPER_INTRA_CLOSE; 29 import static android.server.wm.WindowManagerState.TRANSIT_WALLPAPER_INTRA_OPEN; 30 import static android.server.wm.WindowManagerState.TRANSIT_WALLPAPER_OPEN; 31 import static android.server.wm.app.Components.BOTTOM_ACTIVITY; 32 import static android.server.wm.app.Components.BOTTOM_NON_RESIZABLE_ACTIVITY; 33 import static android.server.wm.app.Components.BottomActivity.EXTRA_BOTTOM_WALLPAPER; 34 import static android.server.wm.app.Components.BottomActivity.EXTRA_STOP_DELAY; 35 import static android.server.wm.app.Components.TOP_ACTIVITY; 36 import static android.server.wm.app.Components.TOP_NON_RESIZABLE_ACTIVITY; 37 import static android.server.wm.app.Components.TOP_NON_RESIZABLE_WALLPAPER_ACTIVITY; 38 import static android.server.wm.app.Components.TOP_WALLPAPER_ACTIVITY; 39 import static android.server.wm.app.Components.TRANSLUCENT_TOP_ACTIVITY; 40 import static android.server.wm.app.Components.TRANSLUCENT_TOP_NON_RESIZABLE_ACTIVITY; 41 import static android.server.wm.app.Components.TRANSLUCENT_TOP_WALLPAPER_ACTIVITY; 42 import static android.server.wm.app.Components.TopActivity.EXTRA_FINISH_DELAY; 43 44 import static org.junit.Assert.assertEquals; 45 import static org.junit.Assume.assumeFalse; 46 import static org.junit.Assume.assumeTrue; 47 48 import android.content.ComponentName; 49 import android.content.pm.PackageManager; 50 import android.platform.test.annotations.Presubmit; 51 52 import org.junit.Before; 53 import org.junit.Test; 54 55 /** 56 * This test tests the transition type selection logic in ActivityManager/WindowManager. 57 * BottomActivity is started first, then TopActivity, and we check the transition type that the 58 * system selects when TopActivity enters or exits under various setups. 59 * 60 * Note that we only require the correct transition type to be reported (eg. TRANSIT_ACTIVITY_OPEN, 61 * TRANSIT_TASK_CLOSE, TRANSIT_WALLPAPER_OPEN, etc.). The exact animation is unspecified and can be 62 * overridden. 63 * 64 * <p>Build/Install/Run: 65 * atest CtsWindowManagerDeviceTestCases:TransitionSelectionTests 66 */ 67 @Presubmit 68 public class TransitionSelectionTests extends ActivityManagerTestBase { 69 70 @Before setup()71 public void setup() { 72 assumeFalse(ENABLE_SHELL_TRANSITIONS); 73 } 74 75 // Test activity open/close under normal timing 76 @Test testOpenActivity_NeitherWallpaper()77 public void testOpenActivity_NeitherWallpaper() { 78 testOpenActivity(false /*bottomWallpaper*/, false /*topWallpaper*/, 79 false /*slowStop*/, TRANSIT_ACTIVITY_OPEN); 80 } 81 82 @Test testCloseActivity_NeitherWallpaper()83 public void testCloseActivity_NeitherWallpaper() { 84 testCloseActivity(false /*bottomWallpaper*/, false /*topWallpaper*/, 85 false /*slowStop*/, TRANSIT_ACTIVITY_CLOSE); 86 } 87 88 @Test testOpenActivity_BottomWallpaper()89 public void testOpenActivity_BottomWallpaper() { 90 testOpenActivity(true /*bottomWallpaper*/, false /*topWallpaper*/, 91 false /*slowStop*/, TRANSIT_WALLPAPER_CLOSE); 92 } 93 94 @Test testCloseActivity_BottomWallpaper()95 public void testCloseActivity_BottomWallpaper() { 96 testCloseActivity(true /*bottomWallpaper*/, false /*topWallpaper*/, 97 false /*slowStop*/, TRANSIT_WALLPAPER_OPEN); 98 } 99 100 @Test testOpenActivity_BothWallpaper()101 public void testOpenActivity_BothWallpaper() { 102 testOpenActivity(true /*bottomWallpaper*/, true /*topWallpaper*/, 103 false /*slowStop*/, TRANSIT_WALLPAPER_INTRA_OPEN); 104 } 105 106 @Test testCloseActivity_BothWallpaper()107 public void testCloseActivity_BothWallpaper() { 108 testCloseActivity(true /*bottomWallpaper*/, true /*topWallpaper*/, 109 false /*slowStop*/, TRANSIT_WALLPAPER_INTRA_CLOSE); 110 } 111 112 //------------------------------------------------------------------------// 113 114 // Test task open/close under normal timing 115 @Test testOpenTask_NeitherWallpaper()116 public void testOpenTask_NeitherWallpaper() { 117 assumeFalse(isAutomotive() && hasSplitscreenMultitaskingFeature()); 118 testOpenTask(false /*bottomWallpaper*/, false /*topWallpaper*/, true /* topResizable */, 119 false /*slowStop*/, TRANSIT_TASK_OPEN, WINDOWING_MODE_FULLSCREEN); 120 } 121 122 @Test testOpenFreeformTask_NeitherWallpaper()123 public void testOpenFreeformTask_NeitherWallpaper() { 124 assumeTrue(supportsFreeform()); 125 testOpenTask(false /*bottomWallpaper*/, false /*topWallpaper*/, true /* topResizable */, 126 false /*slowStop*/, TRANSIT_TASK_OPEN, WINDOWING_MODE_FREEFORM); 127 } 128 129 @Test testCloseTask_NeitherWallpaper()130 public void testCloseTask_NeitherWallpaper() { 131 assumeFalse(isAutomotive() && hasSplitscreenMultitaskingFeature()); 132 testCloseTask(false /*bottomWallpaper*/, false /*topWallpaper*/, true /* topResizable */, 133 false /*slowStop*/, TRANSIT_TASK_CLOSE, WINDOWING_MODE_FULLSCREEN); 134 } 135 136 @Test testOpenTask_BottomWallpaper_TopNonResizable()137 public void testOpenTask_BottomWallpaper_TopNonResizable() { 138 testOpenTask(true /*bottomWallpaper*/, false /*topWallpaper*/, false /* topResizable */, 139 false /*slowStop*/, TRANSIT_WALLPAPER_CLOSE, WINDOWING_MODE_FULLSCREEN); 140 } 141 142 @Test testOpenFreeformTask_BottomWallpaper_TopResizable()143 public void testOpenFreeformTask_BottomWallpaper_TopResizable() { 144 assumeTrue(supportsFreeform()); 145 testOpenTask(true /*bottomWallpaper*/, false /*topWallpaper*/, true /* topResizable */, 146 false /*slowStop*/, TRANSIT_TASK_OPEN, WINDOWING_MODE_FREEFORM); 147 } 148 149 @Test testCloseTask_BottomWallpaper_TopNonResizable()150 public void testCloseTask_BottomWallpaper_TopNonResizable() { 151 testCloseTask(true /*bottomWallpaper*/, false /*topWallpaper*/, false /* topResizable */, 152 false /*slowStop*/, TRANSIT_WALLPAPER_OPEN, WINDOWING_MODE_FULLSCREEN); 153 } 154 155 @Test testCloseFreeformTask_BottomWallpaper_TopResizable()156 public void testCloseFreeformTask_BottomWallpaper_TopResizable() { 157 assumeTrue(supportsFreeform()); 158 testCloseTask(true /*bottomWallpaper*/, false /*topWallpaper*/, true /* topResizable */, 159 false /*slowStop*/, TRANSIT_TASK_CLOSE, WINDOWING_MODE_FREEFORM); 160 } 161 162 @Test testOpenTask_BothWallpaper()163 public void testOpenTask_BothWallpaper() { 164 testOpenTask(true /*bottomWallpaper*/, true /*topWallpaper*/, false /* topResizable */, 165 false /*slowStop*/, TRANSIT_WALLPAPER_INTRA_OPEN, WINDOWING_MODE_FULLSCREEN); 166 } 167 168 @Test testCloseTask_BothWallpaper()169 public void testCloseTask_BothWallpaper() { 170 testCloseTask(true /*bottomWallpaper*/, true /*topWallpaper*/, false /* topResizable */, 171 false /*slowStop*/, TRANSIT_WALLPAPER_INTRA_CLOSE, WINDOWING_MODE_FULLSCREEN); 172 } 173 174 //------------------------------------------------------------------------// 175 176 // Test activity close -- bottom activity slow in stopping 177 // These simulate the case where the bottom activity is resumed 178 // before AM receives its activitiyStopped 179 @Test testCloseActivity_NeitherWallpaper_SlowStop()180 public void testCloseActivity_NeitherWallpaper_SlowStop() { 181 testCloseActivity(false /*bottomWallpaper*/, false /*topWallpaper*/, 182 true /*slowStop*/, TRANSIT_ACTIVITY_CLOSE); 183 } 184 185 @Test testCloseActivity_BottomWallpaper_SlowStop()186 public void testCloseActivity_BottomWallpaper_SlowStop() { 187 testCloseActivity(true /*bottomWallpaper*/, false /*topWallpaper*/, 188 true /*slowStop*/, TRANSIT_WALLPAPER_OPEN); 189 } 190 191 @Test testCloseActivity_BothWallpaper_SlowStop()192 public void testCloseActivity_BothWallpaper_SlowStop() { 193 testCloseActivity(true /*bottomWallpaper*/, true /*topWallpaper*/, 194 true /*slowStop*/, TRANSIT_WALLPAPER_INTRA_CLOSE); 195 } 196 197 //------------------------------------------------------------------------// 198 199 // Test task close -- bottom task top activity slow in stopping 200 // These simulate the case where the bottom activity is resumed 201 // before AM receives its activitiyStopped 202 @Test testCloseTask_NeitherWallpaper_SlowStop()203 public void testCloseTask_NeitherWallpaper_SlowStop() { 204 assumeFalse(isAutomotive() && hasSplitscreenMultitaskingFeature()); 205 testCloseTask(false /*bottomWallpaper*/, false /*topWallpaper*/, true /* topResizable */, 206 true /*slowStop*/, TRANSIT_TASK_CLOSE, WINDOWING_MODE_FULLSCREEN); 207 } 208 209 @Test testCloseTask_BottomWallpaper_TopNonResizable_SlowStop()210 public void testCloseTask_BottomWallpaper_TopNonResizable_SlowStop() { 211 assumeFalse(isAutomotive() && hasSplitscreenMultitaskingFeature()); 212 testCloseTask(true /*bottomWallpaper*/, false /*topWallpaper*/, false /* topResizable */, 213 true /*slowStop*/, TRANSIT_WALLPAPER_OPEN, WINDOWING_MODE_FULLSCREEN); 214 } 215 216 @Test testCloseFreeformTask_BottomWallpaper_TopResizable_SlowStop()217 public void testCloseFreeformTask_BottomWallpaper_TopResizable_SlowStop() { 218 assumeTrue(supportsFreeform()); 219 testCloseTask(true /*bottomWallpaper*/, false /*topWallpaper*/, true /* topResizable */, 220 true /*slowStop*/, TRANSIT_TASK_CLOSE, WINDOWING_MODE_FREEFORM); 221 } 222 223 @Test testCloseTask_BothWallpaper_SlowStop()224 public void testCloseTask_BothWallpaper_SlowStop() { 225 testCloseTask(true /*bottomWallpaper*/, true /*topWallpaper*/, false /* topResizable */, 226 true /*slowStop*/, TRANSIT_WALLPAPER_INTRA_CLOSE, WINDOWING_MODE_FULLSCREEN); 227 } 228 229 //------------------------------------------------------------------------// 230 231 /// Test closing of translucent activity/task 232 @Test testCloseActivity_NeitherWallpaper_Translucent()233 public void testCloseActivity_NeitherWallpaper_Translucent() { 234 testCloseActivityTranslucent(false /*bottomWallpaper*/, false /*topWallpaper*/, 235 TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE); 236 } 237 238 @Test testCloseActivity_BottomWallpaper_Translucent()239 public void testCloseActivity_BottomWallpaper_Translucent() { 240 testCloseActivityTranslucent(true /*bottomWallpaper*/, false /*topWallpaper*/, 241 TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE); 242 } 243 244 @Test testCloseActivity_BothWallpaper_Translucent()245 public void testCloseActivity_BothWallpaper_Translucent() { 246 testCloseActivityTranslucent(true /*bottomWallpaper*/, true /*topWallpaper*/, 247 TRANSIT_WALLPAPER_INTRA_CLOSE); 248 } 249 250 @Test testCloseTask_NeitherWallpaper_Translucent()251 public void testCloseTask_NeitherWallpaper_Translucent() { 252 testCloseTaskTranslucent(false /*bottomWallpaper*/, false /*topWallpaper*/, 253 TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE); 254 } 255 256 @Test testCloseTask_BottomWallpaper_Translucent()257 public void testCloseTask_BottomWallpaper_Translucent() { 258 testCloseTaskTranslucent(true /*bottomWallpaper*/, false /*topWallpaper*/, 259 TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE); 260 } 261 262 @Test testCloseTask_BothWallpaper_Translucent()263 public void testCloseTask_BothWallpaper_Translucent() { 264 testCloseTaskTranslucent(true /*bottomWallpaper*/, true /*topWallpaper*/, 265 TRANSIT_WALLPAPER_INTRA_CLOSE); 266 } 267 268 //------------------------------------------------------------------------// 269 testOpenActivity(boolean bottomWallpaper, boolean topWallpaper, boolean slowStop, String expectedTransit)270 private void testOpenActivity(boolean bottomWallpaper, 271 boolean topWallpaper, boolean slowStop, String expectedTransit) { 272 testTransitionSelection(true /*testOpen*/, false /*testNewTask*/, 273 bottomWallpaper, topWallpaper, false /*topTranslucent*/, true /* topResizable */, 274 slowStop, expectedTransit, WINDOWING_MODE_FULLSCREEN); 275 } 276 testCloseActivity(boolean bottomWallpaper, boolean topWallpaper, boolean slowStop, String expectedTransit)277 private void testCloseActivity(boolean bottomWallpaper, 278 boolean topWallpaper, boolean slowStop, String expectedTransit) { 279 testTransitionSelection(false /*testOpen*/, false /*testNewTask*/, 280 bottomWallpaper, topWallpaper, false /*topTranslucent*/, true /* topResizable */, 281 slowStop, expectedTransit, WINDOWING_MODE_FULLSCREEN); 282 } 283 testOpenTask(boolean bottomWallpaper, boolean topWallpaper, boolean topResizable, boolean slowStop, String expectedTransit, int windowingMode)284 private void testOpenTask(boolean bottomWallpaper, boolean topWallpaper, boolean topResizable, 285 boolean slowStop, String expectedTransit, int windowingMode) { 286 testTransitionSelection(true /*testOpen*/, true /*testNewTask*/, 287 bottomWallpaper, topWallpaper, false /*topTranslucent*/, topResizable, slowStop, 288 expectedTransit, windowingMode); 289 } 290 testCloseTask(boolean bottomWallpaper, boolean topWallpaper, boolean topResizable, boolean slowStop, String expectedTransit, int windowingMode)291 private void testCloseTask(boolean bottomWallpaper, boolean topWallpaper, boolean topResizable, 292 boolean slowStop, String expectedTransit, int windowingMode) { 293 testTransitionSelection(false /*testOpen*/, true /*testNewTask*/, 294 bottomWallpaper, topWallpaper, false /*topTranslucent*/, 295 topResizable /* topResizable */, slowStop, expectedTransit, windowingMode); 296 } 297 testCloseActivityTranslucent(boolean bottomWallpaper, boolean topWallpaper, String expectedTransit)298 private void testCloseActivityTranslucent(boolean bottomWallpaper, 299 boolean topWallpaper, String expectedTransit) { 300 testTransitionSelection(false /*testOpen*/, false /*testNewTask*/, 301 bottomWallpaper, topWallpaper, true /*topTranslucent*/, true /* topResizable */, 302 false /*slowStop*/, expectedTransit, WINDOWING_MODE_FULLSCREEN); 303 } 304 testCloseTaskTranslucent(boolean bottomWallpaper, boolean topWallpaper, String expectedTransit)305 private void testCloseTaskTranslucent(boolean bottomWallpaper, 306 boolean topWallpaper, String expectedTransit) { 307 testTransitionSelection(false /*testOpen*/, true /*testNewTask*/, 308 bottomWallpaper, topWallpaper, true /*topTranslucent*/, true /* topResizable */, 309 false /*slowStop*/, expectedTransit, WINDOWING_MODE_FULLSCREEN); 310 } 311 312 //------------------------------------------------------------------------// 313 testTransitionSelection( boolean testOpen, boolean testNewTask, boolean bottomWallpaper, boolean topWallpaper, boolean topTranslucent, boolean topResizable, boolean testSlowStop, String expectedTransit, int windowingMode)314 private void testTransitionSelection( 315 boolean testOpen, boolean testNewTask, 316 boolean bottomWallpaper, boolean topWallpaper, boolean topTranslucent, 317 boolean topResizable, boolean testSlowStop, String expectedTransit, int windowingMode) { 318 final ComponentName bottomComponent = bottomWallpaper 319 ? BOTTOM_NON_RESIZABLE_ACTIVITY : BOTTOM_ACTIVITY; 320 String bottomStartCmd = getAmStartCmd(bottomComponent); 321 if (bottomWallpaper) { 322 bottomStartCmd += " --ez " + EXTRA_BOTTOM_WALLPAPER + " true"; 323 } 324 if (testSlowStop) { 325 bottomStartCmd += " --ei " + EXTRA_STOP_DELAY + " 3000"; 326 } 327 executeShellCommand(bottomStartCmd + " --windowingMode " + windowingMode); 328 329 mWmState.computeState(bottomComponent); 330 331 final ComponentName topActivity; 332 if (topTranslucent && !topResizable) { 333 topActivity = TRANSLUCENT_TOP_NON_RESIZABLE_ACTIVITY; 334 } else if (topTranslucent && topWallpaper) { 335 topActivity = TRANSLUCENT_TOP_WALLPAPER_ACTIVITY; 336 } else if (topTranslucent) { 337 topActivity = TRANSLUCENT_TOP_ACTIVITY; 338 } else if (!topResizable && topWallpaper) { 339 topActivity = TOP_NON_RESIZABLE_WALLPAPER_ACTIVITY; 340 } else if (!topResizable) { 341 topActivity = TOP_NON_RESIZABLE_ACTIVITY; 342 } else if (topWallpaper) { 343 topActivity = TOP_WALLPAPER_ACTIVITY; 344 } else { 345 topActivity = TOP_ACTIVITY; 346 } 347 String topStartCmd = getAmStartCmd(topActivity); 348 if (testNewTask) { 349 topStartCmd += " -f 0x18000000"; 350 } 351 if (!testOpen) { 352 topStartCmd += " --ei " + EXTRA_FINISH_DELAY + " 1000"; 353 } 354 topStartCmd += " --windowingMode " + windowingMode; 355 // Launch top task in the same display area as the bottom task. CTS tests using multiple 356 // tasks assume they will be started in the same task display area. 357 int bottomComponentDisplayAreaFeatureId = 358 mWmState.getTaskDisplayAreaFeatureId(bottomComponent); 359 topStartCmd += " --task-display-area-feature-id " + bottomComponentDisplayAreaFeatureId; 360 executeShellCommand(topStartCmd); 361 362 Condition.waitFor("Retrieving correct transition", () -> { 363 if (testOpen) { 364 mWmState.computeState(topActivity); 365 } else { 366 mWmState.computeState(bottomComponent); 367 } 368 return expectedTransit.equals( 369 mWmState.getDefaultDisplayLastTransition()); 370 }); 371 assertEquals("Picked wrong transition", expectedTransit, 372 mWmState.getDefaultDisplayLastTransition()); 373 } 374 375 /** 376 * Checks whether the device is automotive 377 */ isAutomotive()378 private boolean isAutomotive() { 379 PackageManager pm = mContext.getPackageManager(); 380 return pm.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE); 381 } 382 383 /** 384 * Checks whether the device has automotive splitscreen multitasking feature enabled 385 */ hasSplitscreenMultitaskingFeature()386 private boolean hasSplitscreenMultitaskingFeature() { 387 PackageManager pm = mContext.getPackageManager(); 388 return pm.hasSystemFeature(/* PackageManager.FEATURE_CAR_SPLITSCREEN_MULTITASKING */ 389 "android.software.car.splitscreen_multitasking"); 390 } 391 } 392