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.keyguard; 18 19 import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW; 20 import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; 21 import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; 22 import static android.server.wm.ComponentNameUtils.getWindowName; 23 import static android.server.wm.app.Components.BROADCAST_RECEIVER_ACTIVITY; 24 import static android.server.wm.app.Components.DISMISS_KEYGUARD_ACTIVITY; 25 import static android.server.wm.app.Components.DISMISS_KEYGUARD_METHOD_ACTIVITY; 26 import static android.server.wm.app.Components.INHERIT_SHOW_WHEN_LOCKED_ADD_ACTIVITY; 27 import static android.server.wm.app.Components.INHERIT_SHOW_WHEN_LOCKED_ATTR_ACTIVITY; 28 import static android.server.wm.app.Components.INHERIT_SHOW_WHEN_LOCKED_REMOVE_ACTIVITY; 29 import static android.server.wm.app.Components.KEYGUARD_LOCK_ACTIVITY; 30 import static android.server.wm.app.Components.LAUNCHING_ACTIVITY; 31 import static android.server.wm.app.Components.NO_INHERIT_SHOW_WHEN_LOCKED_ATTR_ACTIVITY; 32 import static android.server.wm.app.Components.SHOW_WHEN_LOCKED_ACTIVITY; 33 import static android.server.wm.app.Components.SHOW_WHEN_LOCKED_ATTR_ACTIVITY; 34 import static android.server.wm.app.Components.SHOW_WHEN_LOCKED_ATTR_ROTATION_ACTIVITY; 35 import static android.server.wm.app.Components.SHOW_WHEN_LOCKED_DIALOG_ACTIVITY; 36 import static android.server.wm.app.Components.SHOW_WHEN_LOCKED_NO_PREVIEW_ACTIVITY; 37 import static android.server.wm.app.Components.SHOW_WHEN_LOCKED_TRANSLUCENT_ACTIVITY; 38 import static android.server.wm.app.Components.SHOW_WHEN_LOCKED_WITH_DIALOG_ACTIVITY; 39 import static android.server.wm.app.Components.TEST_ACTIVITY; 40 import static android.server.wm.app.Components.TURN_SCREEN_ON_ACTIVITY; 41 import static android.server.wm.app.Components.TURN_SCREEN_ON_ATTR_DISMISS_KEYGUARD_ACTIVITY; 42 import static android.server.wm.app.Components.TURN_SCREEN_ON_DISMISS_KEYGUARD_ACTIVITY; 43 import static android.view.Display.DEFAULT_DISPLAY; 44 import static android.view.Surface.ROTATION_90; 45 import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; 46 47 import static org.junit.Assert.assertFalse; 48 import static org.junit.Assert.assertTrue; 49 import static org.junit.Assume.assumeTrue; 50 import static org.mockito.ArgumentMatchers.anyBoolean; 51 import static org.mockito.Mockito.never; 52 import static org.mockito.Mockito.spy; 53 import static org.mockito.Mockito.times; 54 import static org.mockito.Mockito.verify; 55 56 import android.Manifest; 57 import android.app.KeyguardManager.KeyguardLockedStateListener; 58 import android.app.WallpaperManager; 59 import android.content.ComponentName; 60 import android.content.res.Configuration; 61 import android.platform.test.annotations.Presubmit; 62 import android.server.wm.CommandSession; 63 import android.server.wm.CommandSession.ActivitySession; 64 import android.server.wm.CommandSession.ActivitySessionClient; 65 import android.server.wm.KeyguardTestBase; 66 import android.server.wm.LockScreenSession; 67 import android.server.wm.RotationSession; 68 import android.server.wm.UiDeviceUtils; 69 import android.server.wm.WindowManagerState; 70 import android.server.wm.app.Components; 71 72 import org.junit.Before; 73 import org.junit.Ignore; 74 import org.junit.Test; 75 76 /** 77 * Build/Install/Run: 78 * atest CtsWindowManagerDeviceKeyguard:KeyguardTests 79 */ 80 @Presubmit 81 @android.server.wm.annotation.Group2 82 public class KeyguardTests extends KeyguardTestBase { 83 isLockscreenLiveWpEnabled()84 boolean isLockscreenLiveWpEnabled() { 85 WallpaperManager mWallpaperManager = mContext.getSystemService(WallpaperManager.class); 86 return mWallpaperManager != null && mWallpaperManager.isLockscreenLiveWallpaperEnabled(); 87 } 88 89 @Before 90 @Override setUp()91 public void setUp() throws Exception { 92 super.setUp(); 93 assumeTrue(supportsInsecureLock()); 94 assertFalse(isUiModeLockedToVrHeadset()); 95 } 96 97 @Test testKeyguardHidesActivity()98 public void testKeyguardHidesActivity() { 99 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 100 launchActivity(TEST_ACTIVITY); 101 waitAndAssertResumedActivity(TEST_ACTIVITY); 102 lockScreenSession.gotoKeyguard(); 103 mWmState.computeState(); 104 mWmState.assertKeyguardShowingAndNotOccluded(); 105 assertTrue(mKeyguardManager.isKeyguardLocked()); 106 waitAndAssertStoppedActivity(TEST_ACTIVITY); 107 108 mObjectTracker.close(lockScreenSession); 109 assertFalse(mKeyguardManager.isKeyguardLocked()); 110 } 111 112 @Test testShowWhenLockedActivity()113 public void testShowWhenLockedActivity() { 114 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 115 launchActivity(SHOW_WHEN_LOCKED_ACTIVITY); 116 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ACTIVITY); 117 lockScreenSession.gotoKeyguard(SHOW_WHEN_LOCKED_ACTIVITY); 118 mWmState.computeState(); 119 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ACTIVITY); 120 mWmState.assertKeyguardShowingAndOccluded(); 121 } 122 123 /** 124 * Tests whether dismissing keyguard and them immediately starting a showWhenLocked activity 125 * over the top, ends in the right state of keyguard not showing and not occluded. 126 */ 127 @Test testLaunchShowWhenLockedActivity_whileDismissingKeyguard_unlocksAndShows()128 public void testLaunchShowWhenLockedActivity_whileDismissingKeyguard_unlocksAndShows() { 129 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 130 131 lockScreenSession.gotoKeyguard(); 132 launchActivityWithDismissKeyguardIfInsecure(SHOW_WHEN_LOCKED_ACTIVITY); 133 134 mWmState.waitForAppTransitionIdleOnDisplay(DEFAULT_DISPLAY); 135 mWmState.computeState(); 136 mWmState.assertKeyguardGone(); 137 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ACTIVITY); 138 139 UiDeviceUtils.pressBackButton(); 140 mWmState.waitForAppTransitionIdleOnDisplay(DEFAULT_DISPLAY); 141 mWmState.computeState(); 142 mWmState.assertKeyguardGone(); 143 mWmState.assertNotResumedActivity("Exited to home screen", SHOW_WHEN_LOCKED_ACTIVITY); 144 } 145 146 /** 147 * Tests whether dialogs from SHOW_WHEN_LOCKED activities are also visible if Keyguard is 148 * showing. 149 */ 150 @Test testShowWhenLockedActivity_withDialog()151 public void testShowWhenLockedActivity_withDialog() { 152 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 153 launchActivity(SHOW_WHEN_LOCKED_WITH_DIALOG_ACTIVITY); 154 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_WITH_DIALOG_ACTIVITY); 155 lockScreenSession.gotoKeyguard(SHOW_WHEN_LOCKED_WITH_DIALOG_ACTIVITY); 156 mWmState.waitFor((wmState) -> wmState.allWindowSurfacesShown( 157 getWindowName(SHOW_WHEN_LOCKED_WITH_DIALOG_ACTIVITY)), 158 "Wait for all windows visible for " + SHOW_WHEN_LOCKED_WITH_DIALOG_ACTIVITY); 159 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_WITH_DIALOG_ACTIVITY); 160 assertTrue(mWmState.allWindowSurfacesShown( 161 getWindowName(SHOW_WHEN_LOCKED_WITH_DIALOG_ACTIVITY))); 162 mWmState.assertKeyguardShowingAndOccluded(); 163 } 164 165 /** 166 * Tests whether multiple SHOW_WHEN_LOCKED activities are shown if the topmost is translucent. 167 */ 168 @Test testMultipleShowWhenLockedActivities()169 public void testMultipleShowWhenLockedActivities() { 170 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 171 172 // Launch opaque activity 173 launchActivity(SHOW_WHEN_LOCKED_ACTIVITY); 174 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ACTIVITY); 175 176 // Launch translucent activity 177 launchActivity(SHOW_WHEN_LOCKED_TRANSLUCENT_ACTIVITY); 178 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_TRANSLUCENT_ACTIVITY); 179 180 // Both should be showing 181 mWmState.assertVisibility(SHOW_WHEN_LOCKED_ACTIVITY, true); 182 mWmState.assertVisibility(SHOW_WHEN_LOCKED_TRANSLUCENT_ACTIVITY, true); 183 184 // Go to Keyguard by turning the screen off and on 185 lockScreenSession.gotoKeyguard( 186 SHOW_WHEN_LOCKED_ACTIVITY, SHOW_WHEN_LOCKED_TRANSLUCENT_ACTIVITY); 187 188 // The activities should both remain visible, and keyguard should be occluded 189 mWmState.computeState(); 190 mWmState.assertVisibility(SHOW_WHEN_LOCKED_ACTIVITY, true); 191 mWmState.assertVisibility(SHOW_WHEN_LOCKED_TRANSLUCENT_ACTIVITY, true); 192 mWmState.assertKeyguardShowingAndOccluded(); 193 } 194 195 /** 196 * Tests whether keyguard stays occluded when going back through more than one SHOW_WHEN_LOCKED 197 * activity in the stack. 198 */ 199 @Test testMultipleShowWhenLockedActivities_remainOccludedDuringTransition()200 public void testMultipleShowWhenLockedActivities_remainOccludedDuringTransition() { 201 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 202 203 lockScreenSession.gotoKeyguard( 204 SHOW_WHEN_LOCKED_ACTIVITY, SHOW_WHEN_LOCKED_TRANSLUCENT_ACTIVITY); 205 206 // Launch three activities in a task over keyguard 207 launchActivity(SHOW_WHEN_LOCKED_ACTIVITY); 208 launchActivity(SHOW_WHEN_LOCKED_TRANSLUCENT_ACTIVITY); 209 launchActivity(SHOW_WHEN_LOCKED_DIALOG_ACTIVITY); 210 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_DIALOG_ACTIVITY); 211 212 // All should be showing, and keyguard should be occluded 213 mWmState.computeState(); 214 mWmState.assertVisibility(SHOW_WHEN_LOCKED_ACTIVITY, true); 215 mWmState.assertVisibility(SHOW_WHEN_LOCKED_TRANSLUCENT_ACTIVITY, true); 216 mWmState.assertVisibility(SHOW_WHEN_LOCKED_DIALOG_ACTIVITY, true); 217 mWmState.assertKeyguardShowingAndOccluded(); 218 219 // Go back to the translucent activity 220 mWmState.assertFocusedActivity("Dialog activity focused", SHOW_WHEN_LOCKED_DIALOG_ACTIVITY); 221 UiDeviceUtils.pressBackButton(); 222 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_TRANSLUCENT_ACTIVITY); 223 mWmState.computeState(); 224 mWmState.assertKeyguardShowingAndOccluded(); 225 226 // Go back again to opaque activity 227 UiDeviceUtils.pressBackButton(); 228 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ACTIVITY); 229 mWmState.computeState(); 230 mWmState.assertKeyguardShowingAndOccluded(); 231 232 // Go back to the keyguard 233 UiDeviceUtils.pressBackButton(); 234 mWmState.computeState(); 235 mWmState.assertKeyguardShowingAndNotOccluded(); 236 } 237 238 /** 239 * Tests that when top SHOW_WHEN_LOCKED activity is finishing and the next one is also 240 * SHOW_WHEN_LOCKED, it should be able to resume next SHOW_WHEN_LOCKED activity. 241 */ 242 @Test testFinishMultipleShowWhenLockedActivities()243 public void testFinishMultipleShowWhenLockedActivities() { 244 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 245 final ActivitySessionClient activitySession = createManagedActivityClientSession(); 246 247 launchActivity(SHOW_WHEN_LOCKED_ACTIVITY); 248 final ActivitySession showWhenLockedActivitySession = 249 activitySession.startActivity(getLaunchActivityBuilder() 250 .setUseInstrumentation() 251 .setNewTask(true) 252 .setMultipleTask(true) 253 .setTargetActivity(SHOW_WHEN_LOCKED_ATTR_ROTATION_ACTIVITY)); 254 255 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ATTR_ROTATION_ACTIVITY); 256 mWmState.assertFocusedActivity("Launching Activity must be focused", 257 SHOW_WHEN_LOCKED_ATTR_ROTATION_ACTIVITY); 258 lockScreenSession.gotoKeyguard(SHOW_WHEN_LOCKED_ATTR_ROTATION_ACTIVITY); 259 260 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ATTR_ROTATION_ACTIVITY); 261 mWmState.assertFocusedActivity("Top activity stay un-change", 262 SHOW_WHEN_LOCKED_ATTR_ROTATION_ACTIVITY); 263 mWmState.assertKeyguardShowingAndOccluded(); 264 265 showWhenLockedActivitySession.finish(); 266 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ACTIVITY); 267 mWmState.assertFocusedActivity("ShowWhenLocked activity must occludes keyguard", 268 SHOW_WHEN_LOCKED_ACTIVITY); 269 mWmState.assertKeyguardShowingAndOccluded(); 270 } 271 272 /** 273 * If we have a translucent SHOW_WHEN_LOCKED_ACTIVITY, the wallpaper should also be showing. 274 */ 275 @Test testTranslucentShowWhenLockedActivity()276 public void testTranslucentShowWhenLockedActivity() { 277 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 278 launchActivity(SHOW_WHEN_LOCKED_TRANSLUCENT_ACTIVITY); 279 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_TRANSLUCENT_ACTIVITY); 280 lockScreenSession.gotoKeyguard(SHOW_WHEN_LOCKED_TRANSLUCENT_ACTIVITY); 281 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_TRANSLUCENT_ACTIVITY); 282 if (isLockscreenLiveWpEnabled()) { 283 // When the flag is not enabled, the behavior of this test is not well-defined. 284 // This check would pass with a shared wallpaper, but not with a separate lock screen 285 // wallpaper. 286 mWmState.waitAndAssertWindowShown(TYPE_WALLPAPER, true); 287 } 288 mWmState.assertKeyguardShowingAndOccluded(); 289 } 290 291 /** 292 * If we have a translucent SHOW_WHEN_LOCKED activity, the activity behind should not be shown. 293 */ 294 @Test testTranslucentDoesntRevealBehind()295 public void testTranslucentDoesntRevealBehind() { 296 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 297 launchActivity(TEST_ACTIVITY); 298 launchActivity(SHOW_WHEN_LOCKED_TRANSLUCENT_ACTIVITY); 299 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_TRANSLUCENT_ACTIVITY); 300 mWmState.assertVisibility(TEST_ACTIVITY, true); 301 mWmState.assertVisibility(SHOW_WHEN_LOCKED_TRANSLUCENT_ACTIVITY, true); 302 lockScreenSession.gotoKeyguard(SHOW_WHEN_LOCKED_TRANSLUCENT_ACTIVITY); 303 mWmState.computeState(); 304 waitAndAssertStoppedActivity(TEST_ACTIVITY); 305 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_TRANSLUCENT_ACTIVITY); 306 mWmState.assertKeyguardShowingAndOccluded(); 307 } 308 309 @Test testDialogShowWhenLockedActivity()310 public void testDialogShowWhenLockedActivity() { 311 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 312 launchActivity(SHOW_WHEN_LOCKED_DIALOG_ACTIVITY); 313 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_DIALOG_ACTIVITY); 314 lockScreenSession.gotoKeyguard(SHOW_WHEN_LOCKED_DIALOG_ACTIVITY); 315 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_DIALOG_ACTIVITY); 316 if (isLockscreenLiveWpEnabled()) { 317 // When the flag is not enabled, the behavior of this test is not well-defined. 318 // This check would pass with a shared wallpaper, but not with a separate lock screen 319 // wallpaper. 320 mWmState.waitAndAssertWindowShown(TYPE_WALLPAPER, true); 321 } 322 mWmState.assertKeyguardShowingAndOccluded(); 323 } 324 325 /** 326 * Test that showWhenLocked activity is fullscreen when shown over keyguard 327 */ 328 @Test 329 @Presubmit 330 // TODO (b/169271554): Temporarily switch activity to fullscreen when needing to showWhenLocked 331 @Ignore testShowWhenLockedActivityWhileSplit()332 public void testShowWhenLockedActivityWhileSplit() { 333 assumeTrue(supportsSplitScreenMultiWindow()); 334 335 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 336 launchActivitiesInSplitScreen( 337 getLaunchActivityBuilder().setTargetActivity(LAUNCHING_ACTIVITY), 338 getLaunchActivityBuilder().setTargetActivity(SHOW_WHEN_LOCKED_ACTIVITY) 339 .setRandomData(true) 340 .setMultipleTask(false)); 341 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ACTIVITY); 342 lockScreenSession.gotoKeyguard(SHOW_WHEN_LOCKED_ACTIVITY); 343 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ACTIVITY); 344 mWmState.assertKeyguardShowingAndOccluded(); 345 WindowManagerState.Activity activity = mWmState.getActivity(SHOW_WHEN_LOCKED_ACTIVITY); 346 assertFalse(activity.getWindowingMode() == WINDOWING_MODE_MULTI_WINDOW); 347 } 348 349 /** 350 * Tests whether an activity that has called setInheritShowWhenLocked(true) above a 351 * SHOW_WHEN_LOCKED activity is visible if Keyguard is locked. 352 */ 353 @Test testInheritShowWhenLockedAdd()354 public void testInheritShowWhenLockedAdd() { 355 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 356 launchActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 357 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 358 359 launchActivity(INHERIT_SHOW_WHEN_LOCKED_ADD_ACTIVITY); 360 waitAndAssertStoppedActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 361 waitAndAssertResumedActivity(INHERIT_SHOW_WHEN_LOCKED_ADD_ACTIVITY); 362 363 lockScreenSession.gotoKeyguard(); 364 mWmState.computeState(); 365 mWmState.assertKeyguardShowingAndOccluded(); 366 waitAndAssertStoppedActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 367 waitAndAssertResumedActivity(INHERIT_SHOW_WHEN_LOCKED_ADD_ACTIVITY); 368 } 369 370 /** 371 * Tests whether an activity that has the manifest attribute inheritShowWhenLocked but then 372 * calls setInheritShowWhenLocked(false) above a SHOW_WHEN_LOCKED activity is invisible if 373 * Keyguard is locked. 374 */ 375 @Test testInheritShowWhenLockedRemove()376 public void testInheritShowWhenLockedRemove() { 377 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 378 launchActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 379 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 380 381 launchActivity(INHERIT_SHOW_WHEN_LOCKED_REMOVE_ACTIVITY); 382 waitAndAssertStoppedActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 383 waitAndAssertResumedActivity(INHERIT_SHOW_WHEN_LOCKED_REMOVE_ACTIVITY); 384 385 lockScreenSession.gotoKeyguard(); 386 mWmState.computeState(); 387 mWmState.assertKeyguardShowingAndNotOccluded(); 388 assertTrue(mKeyguardManager.isKeyguardLocked()); 389 waitAndAssertStoppedActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 390 waitAndAssertStoppedActivity(INHERIT_SHOW_WHEN_LOCKED_REMOVE_ACTIVITY); 391 } 392 393 /** 394 * Tests whether an activity that has the manifest attribute inheritShowWhenLocked above a 395 * SHOW_WHEN_LOCKED activity is visible if Keyguard is locked. 396 * */ 397 @Test testInheritShowWhenLockedAttr()398 public void testInheritShowWhenLockedAttr() { 399 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 400 launchActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 401 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 402 403 launchActivity(INHERIT_SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 404 waitAndAssertStoppedActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 405 waitAndAssertResumedActivity(INHERIT_SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 406 407 lockScreenSession.gotoKeyguard(); 408 mWmState.computeState(); 409 mWmState.assertKeyguardShowingAndOccluded(); 410 waitAndAssertStoppedActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 411 waitAndAssertResumedActivity(INHERIT_SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 412 } 413 414 /** 415 * Tests whether an activity that doesn't have the manifest attribute inheritShowWhenLocked 416 * above a SHOW_WHEN_LOCKED activity is invisible if Keyguard is locked. 417 * */ 418 @Test testNoInheritShowWhenLocked()419 public void testNoInheritShowWhenLocked() { 420 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 421 launchActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 422 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 423 424 launchActivity(NO_INHERIT_SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 425 waitAndAssertStoppedActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 426 waitAndAssertResumedActivity(NO_INHERIT_SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 427 428 lockScreenSession.gotoKeyguard(); 429 mWmState.computeState(); 430 mWmState.assertKeyguardShowingAndNotOccluded(); 431 assertTrue(mKeyguardManager.isKeyguardLocked()); 432 waitAndAssertStoppedActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 433 waitAndAssertStoppedActivity(NO_INHERIT_SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 434 } 435 436 @Test testNoTransientConfigurationWhenShowWhenLockedRequestsOrientation()437 public void testNoTransientConfigurationWhenShowWhenLockedRequestsOrientation() { 438 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 439 final ActivitySessionClient activitySession = createManagedActivityClientSession(); 440 441 final ActivitySession showWhenLockedActivitySession = 442 activitySession.startActivity(getLaunchActivityBuilder() 443 .setUseInstrumentation() 444 .setTargetActivity(SHOW_WHEN_LOCKED_ATTR_ROTATION_ACTIVITY)); 445 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ATTR_ROTATION_ACTIVITY); 446 447 lockScreenSession.gotoKeyguard(SHOW_WHEN_LOCKED_ATTR_ROTATION_ACTIVITY); 448 449 separateTestJournal(); 450 451 final int displayId = mWmState 452 .getDisplayByActivity(SHOW_WHEN_LOCKED_ATTR_ROTATION_ACTIVITY); 453 WindowManagerState.DisplayContent display = mWmState 454 .getDisplay(displayId); 455 final int origDisplayOrientation = display.getFullConfiguration().orientation; 456 final int orientation = origDisplayOrientation == Configuration.ORIENTATION_LANDSCAPE 457 ? SCREEN_ORIENTATION_PORTRAIT 458 : SCREEN_ORIENTATION_LANDSCAPE; 459 showWhenLockedActivitySession.requestOrientation(orientation); 460 461 mWmState.waitForActivityOrientation(SHOW_WHEN_LOCKED_ATTR_ROTATION_ACTIVITY, 462 orientation == SCREEN_ORIENTATION_LANDSCAPE 463 ? Configuration.ORIENTATION_LANDSCAPE 464 : Configuration.ORIENTATION_PORTRAIT); 465 466 display = mWmState.getDisplay(displayId); 467 468 // If the window is a non-fullscreen window (e.g. a freeform window) or the display is 469 // squared, there won't be activity lifecycle. 470 if (display.getFullConfiguration().orientation != origDisplayOrientation) { 471 assertActivityLifecycle(SHOW_WHEN_LOCKED_ATTR_ROTATION_ACTIVITY, 472 false /* relaunched */); 473 } 474 } 475 476 /** 477 * Test that when a normal activity finished and an existing FLAG_DISMISS_KEYGUARD activity 478 * becomes the top activity, it should be resumed. 479 */ 480 @Test testResumeDismissKeyguardActivityFromBackground()481 public void testResumeDismissKeyguardActivityFromBackground() { 482 testResumeOccludingActivityFromBackground(DISMISS_KEYGUARD_ACTIVITY); 483 } 484 485 /** 486 * Test that when a normal activity finished and an existing SHOW_WHEN_LOCKED activity becomes 487 * the top activity, it should be resumed. 488 */ 489 @Test testResumeShowWhenLockedActivityFromBackground()490 public void testResumeShowWhenLockedActivityFromBackground() { 491 testResumeOccludingActivityFromBackground(SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 492 } 493 testResumeOccludingActivityFromBackground(ComponentName occludingActivity)494 private void testResumeOccludingActivityFromBackground(ComponentName occludingActivity) { 495 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 496 lockScreenSession.gotoKeyguard(); 497 mWmState.assertKeyguardShowingAndNotOccluded(); 498 499 // Launch an activity which is able to occlude keyguard. 500 getLaunchActivityBuilder().setUseInstrumentation() 501 .setTargetActivity(occludingActivity).execute(); 502 503 // Launch an activity without SHOW_WHEN_LOCKED and finish it. 504 final int tdaFeatureId = mWmState.getTaskDisplayAreaFeatureId(occludingActivity); 505 final ActivitySession nonShowWhenLockedActivitySession = 506 createManagedActivityClientSession().startActivity(getLaunchActivityBuilder() 507 .setUseInstrumentation() 508 // Don't wait for activity visible because keyguard will show. 509 .setWaitForLaunched(false) 510 .setLaunchTaskDisplayAreaFeatureId(tdaFeatureId) 511 .setTargetActivity(TEST_ACTIVITY)); 512 mWmState.waitForAllStoppedActivities(); 513 mWmState.waitForKeyguardShowingAndNotOccluded(); 514 // The activity should be launched in same TDA to ensure that 515 // keyguard is showing and not occluded. 516 assumeTrue("Should launch in same TDA", 517 mWmState.getTaskDisplayArea(occludingActivity) 518 == mWmState.getTaskDisplayArea(TEST_ACTIVITY)); 519 mWmState.assertKeyguardShowingAndNotOccluded(); 520 521 nonShowWhenLockedActivitySession.finish(); 522 mWmState.waitForKeyguardShowingAndOccluded(); 523 524 // The occluding activity should be resumed because it becomes the top activity. 525 waitAndAssertResumedActivity(occludingActivity); 526 assertTrue(occludingActivity + " must be resumed.", 527 mWmState.hasActivityState(occludingActivity, 528 WindowManagerState.STATE_RESUMED)); 529 } 530 531 @Test testTurnScreenOnActivityOnAod()532 public void testTurnScreenOnActivityOnAod() { 533 final AodSession aodSession = createManagedAodSession(); 534 assumeTrue(aodSession.isAodAvailable()); 535 aodSession.setAodEnabled(true); 536 537 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 538 lockScreenSession.sleepDevice(); 539 assertTrue(mWmState.getKeyguardControllerState().isKeyguardShowing()); 540 541 final CommandSession.ActivitySessionClient activityClient = 542 createManagedActivityClientSession(); 543 activityClient.startActivity( 544 getLaunchActivityBuilder().setUseInstrumentation().setIntentExtra(extra -> { 545 extra.putBoolean(Components.TurnScreenOnActivity.EXTRA_SHOW_WHEN_LOCKED, 546 false); 547 }).setTargetActivity(TURN_SCREEN_ON_ACTIVITY)); 548 549 mWmState.waitForAllStoppedActivities(); 550 // An activity without set showWhenLocked or dismissKeyguard cannot wakeup device and/or 551 // unlock insecure keyguard even if it has setTurnScreenOn, so the device should stay 552 // invisible and the display stay in dozing. 553 waitAndAssertStoppedActivity(TURN_SCREEN_ON_ACTIVITY); 554 assertTrue(mWmState.getKeyguardControllerState().isKeyguardShowing()); 555 assertFalse(isDisplayOn(DEFAULT_DISPLAY)); 556 } 557 558 @Test testShowWhenLockedActivityBeforeAod()559 public void testShowWhenLockedActivityBeforeAod() { 560 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 561 final AodSession aodSession = createManagedAodSession(); 562 assumeTrue(aodSession.isAodAvailable()); 563 aodSession.setAodEnabled(true); 564 565 // Unlocked; ShowWhenLockedActivity should be visible 566 launchActivity(SHOW_WHEN_LOCKED_ACTIVITY); 567 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ACTIVITY); 568 569 // In AOD; ShowWhenLockedActivity should NOT be visible 570 lockScreenSession.sleepDevice(); 571 mWmState.waitForKeyguardShowingAndOccluded(); 572 waitAndAssertStoppedActivity(SHOW_WHEN_LOCKED_ACTIVITY); 573 574 // Awake; ShowWhenLockedActivity should be visible again 575 lockScreenSession.wakeUpDevice(); 576 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ACTIVITY); 577 mWmState.assertKeyguardShowingAndOccluded(); 578 } 579 580 @Test testShowWhenLockedActivityDuringAod()581 public void testShowWhenLockedActivityDuringAod() { 582 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 583 final AodSession aodSession = createManagedAodSession(); 584 assumeTrue(aodSession.isAodAvailable()); 585 aodSession.setAodEnabled(true); 586 587 // In AOD and locked 588 lockScreenSession.sleepDevice(); 589 mWmState.waitForKeyguardShowingAndOccluded(); 590 591 // Launch ShowWhenLockedActivity invisibly under AOD 592 launchActivity(SHOW_WHEN_LOCKED_ACTIVITY); 593 waitAndAssertStoppedActivity(SHOW_WHEN_LOCKED_ACTIVITY); 594 595 // Wake up; we should see ShowWhenLockedActivity instead of KeyGuard 596 lockScreenSession.wakeUpDevice(); 597 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ACTIVITY); 598 mWmState.assertKeyguardShowingAndOccluded(); 599 } 600 601 /** 602 * Tests whether a FLAG_DISMISS_KEYGUARD activity occludes Keyguard. 603 */ 604 @Test testDismissKeyguardActivity()605 public void testDismissKeyguardActivity() { 606 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 607 lockScreenSession.gotoKeyguard(); 608 mWmState.computeState(); 609 assertTrue(mWmState.getKeyguardControllerState().isKeyguardShowing()); 610 launchActivity(DISMISS_KEYGUARD_ACTIVITY); 611 mWmState.waitForKeyguardShowingAndOccluded(); 612 waitAndAssertResumedActivity(DISMISS_KEYGUARD_ACTIVITY); 613 mWmState.assertKeyguardShowingAndOccluded(); 614 } 615 616 @Test testDismissKeyguardActivity_method()617 public void testDismissKeyguardActivity_method() { 618 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 619 separateTestJournal(); 620 lockScreenSession.gotoKeyguard(); 621 mWmState.computeState(); 622 assertTrue(mWmState.getKeyguardControllerState().isKeyguardShowing()); 623 launchActivity(DISMISS_KEYGUARD_METHOD_ACTIVITY); 624 mWmState.waitForKeyguardGone(); 625 waitAndAssertResumedActivity(DISMISS_KEYGUARD_METHOD_ACTIVITY); 626 assertFalse(mWmState.getKeyguardControllerState().isKeyguardShowing()); 627 assertOnDismissSucceeded(DISMISS_KEYGUARD_METHOD_ACTIVITY); 628 } 629 630 @Test testDismissKeyguardActivity_method_notTop()631 public void testDismissKeyguardActivity_method_notTop() { 632 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 633 separateTestJournal(); 634 lockScreenSession.gotoKeyguard(); 635 mWmState.computeState(); 636 assertTrue(mWmState.getKeyguardControllerState().isKeyguardShowing()); 637 launchActivity(BROADCAST_RECEIVER_ACTIVITY); 638 launchActivity(TEST_ACTIVITY); 639 mBroadcastActionTrigger.dismissKeyguardByMethod(); 640 assertOnDismissError(BROADCAST_RECEIVER_ACTIVITY); 641 } 642 643 @Test testDismissKeyguardActivity_method_turnScreenOn()644 public void testDismissKeyguardActivity_method_turnScreenOn() { 645 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 646 separateTestJournal(); 647 lockScreenSession.sleepDevice(); 648 mWmState.computeState(); 649 assertTrue(mWmState.getKeyguardControllerState().isKeyguardShowing()); 650 launchActivity(TURN_SCREEN_ON_DISMISS_KEYGUARD_ACTIVITY); 651 mWmState.waitForKeyguardGone(); 652 waitAndAssertResumedActivity(TURN_SCREEN_ON_DISMISS_KEYGUARD_ACTIVITY); 653 assertFalse(mWmState.getKeyguardControllerState().isKeyguardShowing()); 654 assertOnDismissSucceeded(TURN_SCREEN_ON_DISMISS_KEYGUARD_ACTIVITY); 655 assertTrue(isDisplayOn(DEFAULT_DISPLAY)); 656 } 657 658 @Test testDismissKeyguard_fromShowWhenLocked_notAllowed()659 public void testDismissKeyguard_fromShowWhenLocked_notAllowed() { 660 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 661 lockScreenSession.gotoKeyguard(); 662 mWmState.assertKeyguardShowingAndNotOccluded(); 663 launchActivity(SHOW_WHEN_LOCKED_ACTIVITY); 664 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ACTIVITY); 665 mWmState.assertKeyguardShowingAndOccluded(); 666 mBroadcastActionTrigger.dismissKeyguardByFlag(); 667 mWmState.assertKeyguardShowingAndOccluded(); 668 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ACTIVITY); 669 } 670 671 @Test testDismissKeyguard_fromActivityOption_onlyOnce()672 public void testDismissKeyguard_fromActivityOption_onlyOnce() { 673 // TODO(b/228431314): Move this test from CTS to flicker test. 674 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 675 676 lockScreenSession.gotoKeyguard(); 677 launchActivityWithDismissKeyguardIfInsecure(SHOW_WHEN_LOCKED_NO_PREVIEW_ACTIVITY); 678 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_NO_PREVIEW_ACTIVITY); 679 680 lockScreenSession.gotoKeyguard(); 681 assertFalse(mWmState.getKeyguardControllerState().isKeyguardGoingAway()); 682 } 683 684 @Test testKeyguardLock()685 public void testKeyguardLock() { 686 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 687 lockScreenSession.gotoKeyguard(); 688 mWmState.assertKeyguardShowingAndNotOccluded(); 689 launchActivity(KEYGUARD_LOCK_ACTIVITY); 690 waitAndAssertResumedActivity(KEYGUARD_LOCK_ACTIVITY); 691 mBroadcastActionTrigger.finishBroadcastReceiverActivity(); 692 // The {@link KEYGUARD_LOCK_ACTIVITY} has gone because of the 'finish' broadcast. 693 mWmState.waitAndAssertActivityRemoved(KEYGUARD_LOCK_ACTIVITY); 694 mWmState.waitForKeyguardShowingAndNotOccluded(); 695 mWmState.assertKeyguardShowingAndNotOccluded(); 696 } 697 698 699 /** 700 * Turn on keyguard, and launch an activity on top of the keyguard. 701 * Next, change the orientation of the device to rotate the activity. 702 * The activity should still remain above keyguard at this point. 703 * Send the 'finish' broadcast to dismiss the activity. 704 * Ensure that the activity is gone, and the keyguard is visible. 705 */ 706 @Test testUnoccludedRotationChange()707 public void testUnoccludedRotationChange() { 708 // Go home now to make sure Home is behind Keyguard. 709 launchHomeActivity(); 710 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 711 final RotationSession rotationSession = createManagedRotationSession(); 712 lockScreenSession.gotoKeyguard(); 713 mWmState.assertKeyguardShowingAndNotOccluded(); 714 715 launchActivity(SHOW_WHEN_LOCKED_ACTIVITY); 716 waitAndAssertResumedActivity(SHOW_WHEN_LOCKED_ACTIVITY); 717 718 rotationSession.set(ROTATION_90); 719 mBroadcastActionTrigger.finishBroadcastReceiverActivity(); 720 mWmState.waitForKeyguardShowingAndNotOccluded(); 721 mWmState.waitForDisplayUnfrozen(); 722 mWmState.waitForAppTransitionIdleOnDisplay(DEFAULT_DISPLAY); 723 mWmState.assertValidity(); 724 mWmState.waitAndAssertVisibilityGone(mWmState.getHomeActivityName()); 725 mWmState.assertKeyguardShowingAndNotOccluded(); 726 // The {@link SHOW_WHEN_LOCKED_ACTIVITY} has gone because of the 'finish' broadcast. 727 mWmState.waitAndAssertActivityRemoved(SHOW_WHEN_LOCKED_ACTIVITY); 728 } 729 730 @Test testDismissKeyguardAttrActivity_method_turnScreenOn()731 public void testDismissKeyguardAttrActivity_method_turnScreenOn() { 732 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 733 lockScreenSession.sleepDevice(); 734 735 separateTestJournal(); 736 mWmState.computeState(); 737 assertTrue(mWmState.getKeyguardControllerState().isKeyguardShowing()); 738 launchActivity(TURN_SCREEN_ON_ATTR_DISMISS_KEYGUARD_ACTIVITY); 739 mWmState.waitForKeyguardGone(); 740 waitAndAssertResumedActivity(TURN_SCREEN_ON_ATTR_DISMISS_KEYGUARD_ACTIVITY); 741 assertFalse(mWmState.getKeyguardControllerState().isKeyguardShowing()); 742 assertTrue(isDisplayOn(DEFAULT_DISPLAY)); 743 } 744 745 @Test testScreenOffWhileOccludedStopsActivityNoAod()746 public void testScreenOffWhileOccludedStopsActivityNoAod() { 747 final AodSession aodSession = createManagedAodSession(); 748 aodSession.setAodEnabled(false); 749 testScreenOffWhileOccludedStopsActivity(false /* assertAod */); 750 } 751 752 @Test testScreenOffWhileOccludedStopsActivityAod()753 public void testScreenOffWhileOccludedStopsActivityAod() { 754 final AodSession aodSession = createManagedAodSession(); 755 assumeTrue(aodSession.isAodAvailable()); 756 aodSession.setAodEnabled(true); 757 testScreenOffWhileOccludedStopsActivity(true /* assertAod */); 758 } 759 760 /** 761 * @param assertAod {@code true} to check AOD status, {@code false} otherwise. Note that when 762 * AOD is disabled for the default display, AOD status shouldn't be checked. 763 */ testScreenOffWhileOccludedStopsActivity(boolean assertAod)764 private void testScreenOffWhileOccludedStopsActivity(boolean assertAod) { 765 try (LockScreenSession lockScreenSession = 766 new LockScreenSession(mInstrumentation, mWmState)) { 767 separateTestJournal(); 768 lockScreenSession.gotoKeyguard(); 769 mWmState.assertKeyguardShowingAndNotOccluded(); 770 launchActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 771 waitAndAssertTopResumedActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY, DEFAULT_DISPLAY, 772 "Activity with showWhenLocked attribute should be resumed."); 773 mWmState.assertKeyguardShowingAndOccluded(); 774 if (assertAod) { 775 mWmState.assertAodNotShowing(); 776 } 777 lockScreenSession.sleepDevice(); 778 if (assertAod) { 779 mWmState.assertAodShowing(); 780 } 781 mWmState.waitForAllStoppedActivities(); 782 assertSingleLaunchAndStop(SHOW_WHEN_LOCKED_ATTR_ACTIVITY); 783 } 784 } 785 786 @Test testScreenOffCausesSingleStopNoAod()787 public void testScreenOffCausesSingleStopNoAod() { 788 final AodSession aodSession = createManagedAodSession(); 789 aodSession.setAodEnabled(false); 790 testScreenOffCausesSingleStop(); 791 } 792 793 @Test testScreenOffCausesSingleStopAod()794 public void testScreenOffCausesSingleStopAod() { 795 final AodSession aodSession = createManagedAodSession(); 796 assumeTrue(aodSession.isAodAvailable()); 797 aodSession.setAodEnabled(true); 798 testScreenOffCausesSingleStop(); 799 } 800 testScreenOffCausesSingleStop()801 private void testScreenOffCausesSingleStop() { 802 try (LockScreenSession lockScreenSession = 803 new LockScreenSession(mInstrumentation, mWmState)) { 804 separateTestJournal(); 805 launchActivity(TEST_ACTIVITY); 806 waitAndAssertResumedActivity(TEST_ACTIVITY); 807 lockScreenSession.sleepDevice(); 808 mWmState.waitForAllStoppedActivities(); 809 assertSingleLaunchAndStop(TEST_ACTIVITY); 810 } 811 812 } 813 814 @Test testAddKeyguardLockedStateListener_hideToShow_callbackInvoked()815 public void testAddKeyguardLockedStateListener_hideToShow_callbackInvoked() { 816 mInstrumentation.getUiAutomation().adoptShellPermissionIdentity( 817 Manifest.permission.SUBSCRIBE_TO_KEYGUARD_LOCKED_STATE); 818 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 819 final KeyguardLockedStateListener listener = getTestKeyguardLockedStateListener(); 820 mKeyguardManager.addKeyguardLockedStateListener(mContext.getMainExecutor(), listener); 821 822 lockScreenSession.gotoKeyguard(); 823 lockScreenSession.gotoKeyguard(); // state not changed 824 825 verify(listener, times(1)).onKeyguardLockedStateChanged(true); 826 verify(listener, never()).onKeyguardLockedStateChanged(false); 827 828 mKeyguardManager.removeKeyguardLockedStateListener(listener); 829 mInstrumentation.getUiAutomation().dropShellPermissionIdentity(); 830 } 831 832 @Test testAddKeyguardLockedStateListener_showToHide_callbackInvoked()833 public void testAddKeyguardLockedStateListener_showToHide_callbackInvoked() { 834 mInstrumentation.getUiAutomation().adoptShellPermissionIdentity( 835 Manifest.permission.SUBSCRIBE_TO_KEYGUARD_LOCKED_STATE); 836 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 837 final KeyguardLockedStateListener listener = getTestKeyguardLockedStateListener(); 838 mKeyguardManager.addKeyguardLockedStateListener(mContext.getMainExecutor(), listener); 839 840 lockScreenSession.gotoKeyguard(); 841 lockScreenSession.unlockDevice(); 842 lockScreenSession.unlockDevice(); // state not changed 843 844 verify(listener, times(1)).onKeyguardLockedStateChanged(true); 845 verify(listener, times(1)).onKeyguardLockedStateChanged(false); 846 847 mKeyguardManager.removeKeyguardLockedStateListener(listener); 848 mInstrumentation.getUiAutomation().dropShellPermissionIdentity(); 849 } 850 851 @Test testAddRemoveKeyguardLockedStateListener_callbackNotInvoked()852 public void testAddRemoveKeyguardLockedStateListener_callbackNotInvoked() { 853 mInstrumentation.getUiAutomation().adoptShellPermissionIdentity( 854 Manifest.permission.SUBSCRIBE_TO_KEYGUARD_LOCKED_STATE); 855 final LockScreenSession lockScreenSession = createManagedLockScreenSession(); 856 final KeyguardLockedStateListener listener = getTestKeyguardLockedStateListener(); 857 mKeyguardManager.addKeyguardLockedStateListener(mContext.getMainExecutor(), listener); 858 mKeyguardManager.removeKeyguardLockedStateListener(listener); 859 860 lockScreenSession.gotoKeyguard(); 861 lockScreenSession.unlockDevice(); 862 lockScreenSession.gotoKeyguard(); 863 864 verify(listener, never()).onKeyguardLockedStateChanged(anyBoolean()); 865 866 mInstrumentation.getUiAutomation().dropShellPermissionIdentity(); 867 } 868 getTestKeyguardLockedStateListener()869 public KeyguardLockedStateListener getTestKeyguardLockedStateListener() { 870 return spy(new TestKeyguardLockedStateListener()); 871 } 872 873 public static class TestKeyguardLockedStateListener implements KeyguardLockedStateListener { 874 @Override onKeyguardLockedStateChanged(boolean isKeyguardLocked)875 public void onKeyguardLockedStateChanged(boolean isKeyguardLocked) { 876 } 877 } 878 } 879