1 /* 2 * Copyright (C) 2014 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 com.android.systemui.keyguard; 18 19 import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT; 20 21 import static com.android.internal.telephony.IccCardConstants.State.ABSENT; 22 import static com.android.internal.telephony.IccCardConstants.State.PIN_REQUIRED; 23 import static com.android.internal.telephony.IccCardConstants.State.PUK_REQUIRED; 24 import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST; 25 import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW; 26 import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT; 27 import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT; 28 29 import android.app.ActivityManager; 30 import android.app.ActivityTaskManager; 31 import android.app.AlarmManager; 32 import android.app.PendingIntent; 33 import android.app.StatusBarManager; 34 import android.app.trust.TrustManager; 35 import android.content.BroadcastReceiver; 36 import android.content.ContentResolver; 37 import android.content.Context; 38 import android.content.Intent; 39 import android.content.IntentFilter; 40 import android.content.pm.UserInfo; 41 import android.hardware.biometrics.BiometricSourceType; 42 import android.media.AudioAttributes; 43 import android.media.AudioManager; 44 import android.media.SoundPool; 45 import android.os.Bundle; 46 import android.os.DeadObjectException; 47 import android.os.Handler; 48 import android.os.Looper; 49 import android.os.Message; 50 import android.os.PowerManager; 51 import android.os.RemoteException; 52 import android.os.SystemClock; 53 import android.os.SystemProperties; 54 import android.os.Trace; 55 import android.os.UserHandle; 56 import android.os.UserManager; 57 import android.provider.Settings; 58 import android.telephony.SubscriptionManager; 59 import android.telephony.TelephonyManager; 60 import android.util.EventLog; 61 import android.util.Log; 62 import android.util.Slog; 63 import android.util.SparseArray; 64 import android.view.View; 65 import android.view.ViewGroup; 66 import android.view.WindowManagerPolicyConstants; 67 import android.view.animation.Animation; 68 import android.view.animation.AnimationUtils; 69 70 import com.android.internal.policy.IKeyguardDismissCallback; 71 import com.android.internal.policy.IKeyguardDrawnCallback; 72 import com.android.internal.policy.IKeyguardExitCallback; 73 import com.android.internal.policy.IKeyguardStateCallback; 74 import com.android.internal.telephony.IccCardConstants; 75 import com.android.internal.util.LatencyTracker; 76 import com.android.internal.widget.LockPatternUtils; 77 import com.android.keyguard.KeyguardConstants; 78 import com.android.keyguard.KeyguardDisplayManager; 79 import com.android.keyguard.KeyguardSecurityView; 80 import com.android.keyguard.KeyguardUpdateMonitor; 81 import com.android.keyguard.KeyguardUpdateMonitorCallback; 82 import com.android.keyguard.ViewMediatorCallback; 83 import com.android.systemui.Dependency; 84 import com.android.systemui.R; 85 import com.android.systemui.SystemUI; 86 import com.android.systemui.SystemUIFactory; 87 import com.android.systemui.UiOffloadThread; 88 import com.android.systemui.plugins.FalsingManager; 89 import com.android.systemui.statusbar.phone.BiometricUnlockController; 90 import com.android.systemui.statusbar.phone.KeyguardBypassController; 91 import com.android.systemui.statusbar.phone.NotificationPanelView; 92 import com.android.systemui.statusbar.phone.StatusBar; 93 import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; 94 import com.android.systemui.statusbar.phone.StatusBarWindowController; 95 import com.android.systemui.util.InjectionInflationController; 96 97 import java.io.FileDescriptor; 98 import java.io.PrintWriter; 99 import java.util.ArrayList; 100 101 /** 102 * Mediates requests related to the keyguard. This includes queries about the 103 * state of the keyguard, power management events that effect whether the keyguard 104 * should be shown or reset, callbacks to the phone window manager to notify 105 * it of when the keyguard is showing, and events from the keyguard view itself 106 * stating that the keyguard was succesfully unlocked. 107 * 108 * Note that the keyguard view is shown when the screen is off (as appropriate) 109 * so that once the screen comes on, it will be ready immediately. 110 * 111 * Example queries about the keyguard: 112 * - is {movement, key} one that should wake the keygaurd? 113 * - is the keyguard showing? 114 * - are input events restricted due to the state of the keyguard? 115 * 116 * Callbacks to the phone window manager: 117 * - the keyguard is showing 118 * 119 * Example external events that translate to keyguard view changes: 120 * - screen turned off -> reset the keyguard, and show it so it will be ready 121 * next time the screen turns on 122 * - keyboard is slid open -> if the keyguard is not secure, hide it 123 * 124 * Events from the keyguard view: 125 * - user succesfully unlocked keyguard -> hide keyguard view, and no longer 126 * restrict input events. 127 * 128 * Note: in addition to normal power managment events that effect the state of 129 * whether the keyguard should be showing, external apps and services may request 130 * that the keyguard be disabled via {@link #setKeyguardEnabled(boolean)}. When 131 * false, this will override all other conditions for turning on the keyguard. 132 * 133 * Threading and synchronization: 134 * This class is created by the initialization routine of the {@link WindowManagerPolicyConstants}, 135 * and runs on its thread. The keyguard UI is created from that thread in the 136 * constructor of this class. The apis may be called from other threads, including the 137 * {@link com.android.server.input.InputManagerService}'s and {@link android.view.WindowManager}'s. 138 * Therefore, methods on this class are synchronized, and any action that is pointed 139 * directly to the keyguard UI is posted to a {@link android.os.Handler} to ensure it is taken on the UI 140 * thread of the keyguard. 141 */ 142 public class KeyguardViewMediator extends SystemUI { 143 private static final int KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT = 30000; 144 private static final long KEYGUARD_DONE_PENDING_TIMEOUT_MS = 3000; 145 146 private static final boolean DEBUG = KeyguardConstants.DEBUG; 147 private static final boolean DEBUG_SIM_STATES = KeyguardConstants.DEBUG_SIM_STATES; 148 149 private final static String TAG = "KeyguardViewMediator"; 150 151 private static final String DELAYED_KEYGUARD_ACTION = 152 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD"; 153 private static final String DELAYED_LOCK_PROFILE_ACTION = 154 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_LOCK"; 155 156 private static final String SYSTEMUI_PERMISSION = "com.android.systemui.permission.SELF"; 157 158 // used for handler messages 159 private static final int SHOW = 1; 160 private static final int HIDE = 2; 161 private static final int RESET = 3; 162 private static final int VERIFY_UNLOCK = 4; 163 private static final int NOTIFY_FINISHED_GOING_TO_SLEEP = 5; 164 private static final int NOTIFY_SCREEN_TURNING_ON = 6; 165 private static final int KEYGUARD_DONE = 7; 166 private static final int KEYGUARD_DONE_DRAWING = 8; 167 private static final int SET_OCCLUDED = 9; 168 private static final int KEYGUARD_TIMEOUT = 10; 169 private static final int DISMISS = 11; 170 private static final int START_KEYGUARD_EXIT_ANIM = 12; 171 private static final int KEYGUARD_DONE_PENDING_TIMEOUT = 13; 172 private static final int NOTIFY_STARTED_WAKING_UP = 14; 173 private static final int NOTIFY_SCREEN_TURNED_ON = 15; 174 private static final int NOTIFY_SCREEN_TURNED_OFF = 16; 175 private static final int NOTIFY_STARTED_GOING_TO_SLEEP = 17; 176 private static final int SYSTEM_READY = 18; 177 178 /** 179 * The default amount of time we stay awake (used for all key input) 180 */ 181 public static final int AWAKE_INTERVAL_BOUNCER_MS = 10000; 182 183 /** 184 * How long to wait after the screen turns off due to timeout before 185 * turning on the keyguard (i.e, the user has this much time to turn 186 * the screen back on without having to face the keyguard). 187 */ 188 private static final int KEYGUARD_LOCK_AFTER_DELAY_DEFAULT = 5000; 189 190 /** 191 * How long we'll wait for the {@link ViewMediatorCallback#keyguardDoneDrawing()} 192 * callback before unblocking a call to {@link #setKeyguardEnabled(boolean)} 193 * that is reenabling the keyguard. 194 */ 195 private static final int KEYGUARD_DONE_DRAWING_TIMEOUT_MS = 2000; 196 197 /** 198 * Boolean option for doKeyguardLocked/doKeyguardTimeout which, when set to true, forces the 199 * keyguard to show even if it is disabled for the current user. 200 */ 201 public static final String OPTION_FORCE_SHOW = "force_show"; 202 203 /** The stream type that the lock sounds are tied to. */ 204 private int mUiSoundsStreamType; 205 206 private AlarmManager mAlarmManager; 207 private AudioManager mAudioManager; 208 private StatusBarManager mStatusBarManager; 209 private final StatusBarWindowController mStatusBarWindowController = 210 Dependency.get(StatusBarWindowController.class); 211 private final UiOffloadThread mUiOffloadThread = Dependency.get(UiOffloadThread.class); 212 213 private boolean mSystemReady; 214 private boolean mBootCompleted; 215 private boolean mBootSendUserPresent; 216 private boolean mShuttingDown; 217 private boolean mDozing; 218 219 /** High level access to the power manager for WakeLocks */ 220 private PowerManager mPM; 221 222 /** TrustManager for letting it know when we change visibility */ 223 private TrustManager mTrustManager; 224 225 /** 226 * Used to keep the device awake while to ensure the keyguard finishes opening before 227 * we sleep. 228 */ 229 private PowerManager.WakeLock mShowKeyguardWakeLock; 230 231 private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; 232 233 // these are protected by synchronized (this) 234 235 /** 236 * External apps (like the phone app) can tell us to disable the keygaurd. 237 */ 238 private boolean mExternallyEnabled = true; 239 240 /** 241 * Remember if an external call to {@link #setKeyguardEnabled} with value 242 * false caused us to hide the keyguard, so that we need to reshow it once 243 * the keygaurd is reenabled with another call with value true. 244 */ 245 private boolean mNeedToReshowWhenReenabled = false; 246 247 // cached value of whether we are showing (need to know this to quickly 248 // answer whether the input should be restricted) 249 private boolean mShowing; 250 251 // AOD is enabled and status bar is in AOD state. 252 private boolean mAodShowing; 253 254 /** Cached value of #isInputRestricted */ 255 private boolean mInputRestricted; 256 257 // true if the keyguard is hidden by another window 258 private boolean mOccluded = false; 259 260 /** 261 * Helps remember whether the screen has turned on since the last time 262 * it turned off due to timeout. see {@link #onScreenTurnedOff(int)} 263 */ 264 private int mDelayedShowingSequence; 265 266 /** 267 * Simiar to {@link #mDelayedProfileShowingSequence}, but it is for profile case. 268 */ 269 private int mDelayedProfileShowingSequence; 270 271 /** 272 * If the user has disabled the keyguard, then requests to exit, this is 273 * how we'll ultimately let them know whether it was successful. We use this 274 * var being non-null as an indicator that there is an in progress request. 275 */ 276 private IKeyguardExitCallback mExitSecureCallback; 277 private final DismissCallbackRegistry mDismissCallbackRegistry = new DismissCallbackRegistry(); 278 279 // the properties of the keyguard 280 281 private KeyguardUpdateMonitor mUpdateMonitor; 282 283 /** 284 * Last SIM state reported by the telephony system. 285 * Index is the slotId - in case of multiple SIM cards. 286 */ 287 private final SparseArray<IccCardConstants.State> mLastSimStates = new SparseArray<>(); 288 289 private boolean mDeviceInteractive; 290 private boolean mGoingToSleep; 291 292 // last known state of the cellular connection 293 private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE; 294 295 /** 296 * Whether a hide is pending an we are just waiting for #startKeyguardExitAnimation to be 297 * called. 298 * */ 299 private boolean mHiding; 300 301 /** 302 * we send this intent when the keyguard is dismissed. 303 */ 304 private static final Intent USER_PRESENT_INTENT = new Intent(Intent.ACTION_USER_PRESENT) 305 .addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING 306 | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT 307 | Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS); 308 309 /** 310 * {@link #setKeyguardEnabled} waits on this condition when it reenables 311 * the keyguard. 312 */ 313 private boolean mWaitingUntilKeyguardVisible = false; 314 private LockPatternUtils mLockPatternUtils; 315 private boolean mKeyguardDonePending = false; 316 private boolean mHideAnimationRun = false; 317 private boolean mHideAnimationRunning = false; 318 319 private SoundPool mLockSounds; 320 private int mLockSoundId; 321 private int mUnlockSoundId; 322 private int mTrustedSoundId; 323 private int mLockSoundStreamId; 324 325 /** 326 * The animation used for hiding keyguard. This is used to fetch the animation timings if 327 * WindowManager is not providing us with them. 328 */ 329 private Animation mHideAnimation; 330 331 /** 332 * The volume applied to the lock/unlock sounds. 333 */ 334 private float mLockSoundVolume; 335 336 /** 337 * For managing external displays 338 */ 339 private KeyguardDisplayManager mKeyguardDisplayManager; 340 341 private final ArrayList<IKeyguardStateCallback> mKeyguardStateCallbacks = new ArrayList<>(); 342 343 /** 344 * When starting going to sleep, we figured out that we need to reset Keyguard state and this 345 * should be committed when finished going to sleep. 346 */ 347 private boolean mPendingReset; 348 349 /** 350 * When starting going to sleep, we figured out that we need to lock Keyguard and this should be 351 * committed when finished going to sleep. 352 */ 353 private boolean mPendingLock; 354 355 /** 356 * Controller for showing individual "work challenge" lock screen windows inside managed profile 357 * tasks when the current user has been unlocked but the profile is still locked. 358 */ 359 private WorkLockActivityController mWorkLockController; 360 361 /** 362 * @see #setPulsing(boolean) 363 */ 364 private boolean mPulsing; 365 366 private boolean mLockLater; 367 368 private boolean mWakeAndUnlocking; 369 private IKeyguardDrawnCallback mDrawnCallback; 370 private CharSequence mCustomMessage; 371 372 KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() { 373 374 @Override 375 public void onUserSwitching(int userId) { 376 // Note that the mLockPatternUtils user has already been updated from setCurrentUser. 377 // We need to force a reset of the views, since lockNow (called by 378 // ActivityManagerService) will not reconstruct the keyguard if it is already showing. 379 synchronized (KeyguardViewMediator.this) { 380 resetKeyguardDonePendingLocked(); 381 if (mLockPatternUtils.isLockScreenDisabled(userId)) { 382 // If we switching to a user that has keyguard disabled, dismiss keyguard. 383 dismiss(null /* callback */, null /* message */); 384 } else { 385 resetStateLocked(); 386 } 387 adjustStatusBarLocked(); 388 } 389 } 390 391 @Override 392 public void onUserSwitchComplete(int userId) { 393 if (userId != UserHandle.USER_SYSTEM) { 394 UserInfo info = UserManager.get(mContext).getUserInfo(userId); 395 // Don't try to dismiss if the user has Pin/Patter/Password set 396 if (info == null || mLockPatternUtils.isSecure(userId)) { 397 return; 398 } else if (info.isGuest() || info.isDemo()) { 399 // If we just switched to a guest, try to dismiss keyguard. 400 dismiss(null /* callback */, null /* message */); 401 } 402 } 403 } 404 405 @Override 406 public void onUserInfoChanged(int userId) { 407 } 408 409 @Override 410 public void onClockVisibilityChanged() { 411 adjustStatusBarLocked(); 412 } 413 414 @Override 415 public void onDeviceProvisioned() { 416 sendUserPresentBroadcast(); 417 synchronized (KeyguardViewMediator.this) { 418 // If system user is provisioned, we might want to lock now to avoid showing launcher 419 if (mustNotUnlockCurrentUser()) { 420 doKeyguardLocked(null); 421 } 422 } 423 } 424 425 @Override 426 public void onSimStateChanged(int subId, int slotId, IccCardConstants.State simState) { 427 428 if (DEBUG_SIM_STATES) { 429 Log.d(TAG, "onSimStateChanged(subId=" + subId + ", slotId=" + slotId 430 + ",state=" + simState + ")"); 431 } 432 433 int size = mKeyguardStateCallbacks.size(); 434 boolean simPinSecure = mUpdateMonitor.isSimPinSecure(); 435 for (int i = size - 1; i >= 0; i--) { 436 try { 437 mKeyguardStateCallbacks.get(i).onSimSecureStateChanged(simPinSecure); 438 } catch (RemoteException e) { 439 Slog.w(TAG, "Failed to call onSimSecureStateChanged", e); 440 if (e instanceof DeadObjectException) { 441 mKeyguardStateCallbacks.remove(i); 442 } 443 } 444 } 445 446 boolean simWasLocked; 447 synchronized (KeyguardViewMediator.this) { 448 IccCardConstants.State lastState = mLastSimStates.get(slotId); 449 simWasLocked = (lastState == PIN_REQUIRED || lastState == PUK_REQUIRED); 450 mLastSimStates.append(slotId, simState); 451 } 452 453 switch (simState) { 454 case NOT_READY: 455 case ABSENT: 456 // only force lock screen in case of missing sim if user hasn't 457 // gone through setup wizard 458 synchronized (KeyguardViewMediator.this) { 459 if (shouldWaitForProvisioning()) { 460 if (!mShowing) { 461 if (DEBUG_SIM_STATES) Log.d(TAG, "ICC_ABSENT isn't showing," 462 + " we need to show the keyguard since the " 463 + "device isn't provisioned yet."); 464 doKeyguardLocked(null); 465 } else { 466 resetStateLocked(); 467 } 468 } 469 if (simState == ABSENT) { 470 // MVNO SIMs can become transiently NOT_READY when switching networks, 471 // so we should only lock when they are ABSENT. 472 if (simWasLocked) { 473 if (DEBUG_SIM_STATES) Log.d(TAG, "SIM moved to ABSENT when the " 474 + "previous state was locked. Reset the state."); 475 resetStateLocked(); 476 } 477 } 478 } 479 break; 480 case PIN_REQUIRED: 481 case PUK_REQUIRED: 482 synchronized (KeyguardViewMediator.this) { 483 if (!mShowing) { 484 if (DEBUG_SIM_STATES) Log.d(TAG, 485 "INTENT_VALUE_ICC_LOCKED and keygaurd isn't " 486 + "showing; need to show keyguard so user can enter sim pin"); 487 doKeyguardLocked(null); 488 } else { 489 resetStateLocked(); 490 } 491 } 492 break; 493 case PERM_DISABLED: 494 synchronized (KeyguardViewMediator.this) { 495 if (!mShowing) { 496 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED and " 497 + "keygaurd isn't showing."); 498 doKeyguardLocked(null); 499 } else { 500 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED, resetStateLocked to" 501 + "show permanently disabled message in lockscreen."); 502 resetStateLocked(); 503 } 504 } 505 break; 506 case READY: 507 synchronized (KeyguardViewMediator.this) { 508 if (DEBUG_SIM_STATES) Log.d(TAG, "READY, reset state? " + mShowing); 509 if (mShowing && simWasLocked) { 510 if (DEBUG_SIM_STATES) Log.d(TAG, "SIM moved to READY when the " 511 + "previous state was locked. Reset the state."); 512 resetStateLocked(); 513 } 514 } 515 break; 516 default: 517 if (DEBUG_SIM_STATES) Log.v(TAG, "Unspecific state: " + simState); 518 break; 519 } 520 } 521 522 @Override 523 public void onBiometricAuthFailed(BiometricSourceType biometricSourceType) { 524 final int currentUser = KeyguardUpdateMonitor.getCurrentUser(); 525 if (mLockPatternUtils.isSecure(currentUser)) { 526 mLockPatternUtils.getDevicePolicyManager().reportFailedBiometricAttempt( 527 currentUser); 528 } 529 } 530 531 @Override 532 public void onBiometricAuthenticated(int userId, BiometricSourceType biometricSourceType) { 533 if (mLockPatternUtils.isSecure(userId)) { 534 mLockPatternUtils.getDevicePolicyManager().reportSuccessfulBiometricAttempt( 535 userId); 536 } 537 } 538 539 @Override 540 public void onTrustChanged(int userId) { 541 if (userId == KeyguardUpdateMonitor.getCurrentUser()) { 542 synchronized (KeyguardViewMediator.this) { 543 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(userId)); 544 } 545 } 546 } 547 548 @Override 549 public void onHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) { 550 synchronized (KeyguardViewMediator.this) { 551 notifyHasLockscreenWallpaperChanged(hasLockscreenWallpaper); 552 } 553 } 554 }; 555 556 ViewMediatorCallback mViewMediatorCallback = new ViewMediatorCallback() { 557 558 @Override 559 public void userActivity() { 560 KeyguardViewMediator.this.userActivity(); 561 } 562 563 @Override 564 public void keyguardDone(boolean strongAuth, int targetUserId) { 565 if (targetUserId != ActivityManager.getCurrentUser()) { 566 return; 567 } 568 569 tryKeyguardDone(); 570 } 571 572 @Override 573 public void keyguardDoneDrawing() { 574 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDoneDrawing"); 575 mHandler.sendEmptyMessage(KEYGUARD_DONE_DRAWING); 576 Trace.endSection(); 577 } 578 579 @Override 580 public void setNeedsInput(boolean needsInput) { 581 mStatusBarKeyguardViewManager.setNeedsInput(needsInput); 582 } 583 584 @Override 585 public void keyguardDonePending(boolean strongAuth, int targetUserId) { 586 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDonePending"); 587 if (targetUserId != ActivityManager.getCurrentUser()) { 588 Trace.endSection(); 589 return; 590 } 591 592 mKeyguardDonePending = true; 593 mHideAnimationRun = true; 594 mHideAnimationRunning = true; 595 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable); 596 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_PENDING_TIMEOUT, 597 KEYGUARD_DONE_PENDING_TIMEOUT_MS); 598 Trace.endSection(); 599 } 600 601 @Override 602 public void keyguardGone() { 603 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardGone"); 604 mKeyguardDisplayManager.hide(); 605 Trace.endSection(); 606 } 607 608 @Override 609 public void readyForKeyguardDone() { 610 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#readyForKeyguardDone"); 611 if (mKeyguardDonePending) { 612 mKeyguardDonePending = false; 613 tryKeyguardDone(); 614 } 615 Trace.endSection(); 616 } 617 618 @Override 619 public void resetKeyguard() { 620 resetStateLocked(); 621 } 622 623 @Override 624 public void onCancelClicked() { 625 mStatusBarKeyguardViewManager.onCancelClicked(); 626 } 627 628 @Override 629 public void onBouncerVisiblityChanged(boolean shown) { 630 synchronized (KeyguardViewMediator.this) { 631 adjustStatusBarLocked(shown); 632 } 633 } 634 635 @Override 636 public void playTrustedSound() { 637 KeyguardViewMediator.this.playTrustedSound(); 638 } 639 640 @Override 641 public boolean isScreenOn() { 642 return mDeviceInteractive; 643 } 644 645 @Override 646 public int getBouncerPromptReason() { 647 int currentUser = ActivityManager.getCurrentUser(); 648 boolean trust = mTrustManager.isTrustUsuallyManaged(currentUser); 649 boolean biometrics = mUpdateMonitor.isUnlockingWithBiometricsPossible(currentUser); 650 boolean any = trust || biometrics; 651 KeyguardUpdateMonitor.StrongAuthTracker strongAuthTracker = 652 mUpdateMonitor.getStrongAuthTracker(); 653 int strongAuth = strongAuthTracker.getStrongAuthForUser(currentUser); 654 655 if (any && !strongAuthTracker.hasUserAuthenticatedSinceBoot()) { 656 return KeyguardSecurityView.PROMPT_REASON_RESTART; 657 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_TIMEOUT) != 0) { 658 return KeyguardSecurityView.PROMPT_REASON_TIMEOUT; 659 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW) != 0) { 660 return KeyguardSecurityView.PROMPT_REASON_DEVICE_ADMIN; 661 } else if (trust && (strongAuth & SOME_AUTH_REQUIRED_AFTER_USER_REQUEST) != 0) { 662 return KeyguardSecurityView.PROMPT_REASON_USER_REQUEST; 663 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_LOCKOUT) != 0) { 664 return KeyguardSecurityView.PROMPT_REASON_AFTER_LOCKOUT; 665 } 666 return KeyguardSecurityView.PROMPT_REASON_NONE; 667 } 668 669 @Override 670 public CharSequence consumeCustomMessage() { 671 final CharSequence message = mCustomMessage; 672 mCustomMessage = null; 673 return message; 674 } 675 }; 676 userActivity()677 public void userActivity() { 678 mPM.userActivity(SystemClock.uptimeMillis(), false); 679 } 680 mustNotUnlockCurrentUser()681 boolean mustNotUnlockCurrentUser() { 682 return UserManager.isSplitSystemUser() 683 && KeyguardUpdateMonitor.getCurrentUser() == UserHandle.USER_SYSTEM; 684 } 685 setupLocked()686 private void setupLocked() { 687 mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); 688 mTrustManager = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE); 689 690 mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard"); 691 mShowKeyguardWakeLock.setReferenceCounted(false); 692 693 IntentFilter filter = new IntentFilter(); 694 filter.addAction(Intent.ACTION_SHUTDOWN); 695 mContext.registerReceiver(mBroadcastReceiver, filter); 696 697 final IntentFilter delayedActionFilter = new IntentFilter(); 698 delayedActionFilter.addAction(DELAYED_KEYGUARD_ACTION); 699 delayedActionFilter.addAction(DELAYED_LOCK_PROFILE_ACTION); 700 mContext.registerReceiver(mDelayedLockBroadcastReceiver, delayedActionFilter, 701 SYSTEMUI_PERMISSION, null /* scheduler */); 702 703 InjectionInflationController injectionInflationController = 704 new InjectionInflationController(SystemUIFactory.getInstance().getRootComponent()); 705 mKeyguardDisplayManager = new KeyguardDisplayManager(mContext, 706 injectionInflationController); 707 708 mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); 709 710 mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext); 711 712 mLockPatternUtils = new LockPatternUtils(mContext); 713 KeyguardUpdateMonitor.setCurrentUser(ActivityManager.getCurrentUser()); 714 715 // Assume keyguard is showing (unless it's disabled) until we know for sure, unless Keyguard 716 // is disabled. 717 if (mContext.getResources().getBoolean(R.bool.config_enableKeyguardService)) { 718 setShowingLocked(!shouldWaitForProvisioning() 719 && !mLockPatternUtils.isLockScreenDisabled( 720 KeyguardUpdateMonitor.getCurrentUser()), true /* forceCallbacks */); 721 } else { 722 // The system's keyguard is disabled or missing. 723 setShowingLocked(false /* showing */, true /* forceCallbacks */); 724 } 725 726 mStatusBarKeyguardViewManager = 727 SystemUIFactory.getInstance().createStatusBarKeyguardViewManager(mContext, 728 mViewMediatorCallback, mLockPatternUtils); 729 final ContentResolver cr = mContext.getContentResolver(); 730 731 mDeviceInteractive = mPM.isInteractive(); 732 733 mLockSounds = new SoundPool.Builder() 734 .setMaxStreams(1) 735 .setAudioAttributes( 736 new AudioAttributes.Builder() 737 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) 738 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) 739 .build()) 740 .build(); 741 String soundPath = Settings.Global.getString(cr, Settings.Global.LOCK_SOUND); 742 if (soundPath != null) { 743 mLockSoundId = mLockSounds.load(soundPath, 1); 744 } 745 if (soundPath == null || mLockSoundId == 0) { 746 Log.w(TAG, "failed to load lock sound from " + soundPath); 747 } 748 soundPath = Settings.Global.getString(cr, Settings.Global.UNLOCK_SOUND); 749 if (soundPath != null) { 750 mUnlockSoundId = mLockSounds.load(soundPath, 1); 751 } 752 if (soundPath == null || mUnlockSoundId == 0) { 753 Log.w(TAG, "failed to load unlock sound from " + soundPath); 754 } 755 soundPath = Settings.Global.getString(cr, Settings.Global.TRUSTED_SOUND); 756 if (soundPath != null) { 757 mTrustedSoundId = mLockSounds.load(soundPath, 1); 758 } 759 if (soundPath == null || mTrustedSoundId == 0) { 760 Log.w(TAG, "failed to load trusted sound from " + soundPath); 761 } 762 763 int lockSoundDefaultAttenuation = mContext.getResources().getInteger( 764 com.android.internal.R.integer.config_lockSoundVolumeDb); 765 mLockSoundVolume = (float)Math.pow(10, (float)lockSoundDefaultAttenuation/20); 766 767 mHideAnimation = AnimationUtils.loadAnimation(mContext, 768 com.android.internal.R.anim.lock_screen_behind_enter); 769 770 mWorkLockController = new WorkLockActivityController(mContext); 771 } 772 773 @Override start()774 public void start() { 775 synchronized (this) { 776 setupLocked(); 777 } 778 putComponent(KeyguardViewMediator.class, this); 779 } 780 781 /** 782 * Let us know that the system is ready after startup. 783 */ onSystemReady()784 public void onSystemReady() { 785 mHandler.obtainMessage(SYSTEM_READY).sendToTarget(); 786 } 787 handleSystemReady()788 private void handleSystemReady() { 789 synchronized (this) { 790 if (DEBUG) Log.d(TAG, "onSystemReady"); 791 mSystemReady = true; 792 doKeyguardLocked(null); 793 mUpdateMonitor.registerCallback(mUpdateCallback); 794 } 795 // Most services aren't available until the system reaches the ready state, so we 796 // send it here when the device first boots. 797 maybeSendUserPresentBroadcast(); 798 } 799 800 /** 801 * Called to let us know the screen was turned off. 802 * @param why either {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_USER} or 803 * {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_TIMEOUT}. 804 */ onStartedGoingToSleep(int why)805 public void onStartedGoingToSleep(int why) { 806 if (DEBUG) Log.d(TAG, "onStartedGoingToSleep(" + why + ")"); 807 synchronized (this) { 808 mDeviceInteractive = false; 809 mGoingToSleep = true; 810 811 // Lock immediately based on setting if secure (user has a pin/pattern/password). 812 // This also "locks" the device when not secure to provide easy access to the 813 // camera while preventing unwanted input. 814 int currentUser = KeyguardUpdateMonitor.getCurrentUser(); 815 final boolean lockImmediately = 816 mLockPatternUtils.getPowerButtonInstantlyLocks(currentUser) 817 || !mLockPatternUtils.isSecure(currentUser); 818 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser()); 819 mLockLater = false; 820 if (mExitSecureCallback != null) { 821 if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled"); 822 try { 823 mExitSecureCallback.onKeyguardExitResult(false); 824 } catch (RemoteException e) { 825 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); 826 } 827 mExitSecureCallback = null; 828 if (!mExternallyEnabled) { 829 hideLocked(); 830 } 831 } else if (mShowing) { 832 mPendingReset = true; 833 } else if ((why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_TIMEOUT && timeout > 0) 834 || (why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_USER && !lockImmediately)) { 835 doKeyguardLaterLocked(timeout); 836 mLockLater = true; 837 } else if (!mLockPatternUtils.isLockScreenDisabled(currentUser)) { 838 mPendingLock = true; 839 } 840 841 if (mPendingLock) { 842 playSounds(true); 843 } 844 } 845 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedGoingToSleep(why); 846 notifyStartedGoingToSleep(); 847 } 848 onFinishedGoingToSleep(int why, boolean cameraGestureTriggered)849 public void onFinishedGoingToSleep(int why, boolean cameraGestureTriggered) { 850 if (DEBUG) Log.d(TAG, "onFinishedGoingToSleep(" + why + ")"); 851 synchronized (this) { 852 mDeviceInteractive = false; 853 mGoingToSleep = false; 854 mWakeAndUnlocking = false; 855 856 resetKeyguardDonePendingLocked(); 857 mHideAnimationRun = false; 858 859 notifyFinishedGoingToSleep(); 860 861 if (cameraGestureTriggered) { 862 Log.i(TAG, "Camera gesture was triggered, preventing Keyguard locking."); 863 864 // Just to make sure, make sure the device is awake. 865 mContext.getSystemService(PowerManager.class).wakeUp(SystemClock.uptimeMillis(), 866 PowerManager.WAKE_REASON_CAMERA_LAUNCH, 867 "com.android.systemui:CAMERA_GESTURE_PREVENT_LOCK"); 868 mPendingLock = false; 869 mPendingReset = false; 870 } 871 872 if (mPendingReset) { 873 resetStateLocked(); 874 mPendingReset = false; 875 } 876 877 if (mPendingLock) { 878 doKeyguardLocked(null); 879 mPendingLock = false; 880 } 881 882 // We do not have timeout and power button instant lock setting for profile lock. 883 // So we use the personal setting if there is any. But if there is no device 884 // we need to make sure we lock it immediately when the screen is off. 885 if (!mLockLater && !cameraGestureTriggered) { 886 doKeyguardForChildProfilesLocked(); 887 } 888 889 } 890 KeyguardUpdateMonitor.getInstance(mContext).dispatchFinishedGoingToSleep(why); 891 } 892 getLockTimeout(int userId)893 private long getLockTimeout(int userId) { 894 // if the screen turned off because of timeout or the user hit the power button 895 // and we don't need to lock immediately, set an alarm 896 // to enable it a little bit later (i.e, give the user a chance 897 // to turn the screen back on within a certain window without 898 // having to unlock the screen) 899 final ContentResolver cr = mContext.getContentResolver(); 900 901 // From SecuritySettings 902 final long lockAfterTimeout = Settings.Secure.getInt(cr, 903 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, 904 KEYGUARD_LOCK_AFTER_DELAY_DEFAULT); 905 906 // From DevicePolicyAdmin 907 final long policyTimeout = mLockPatternUtils.getDevicePolicyManager() 908 .getMaximumTimeToLock(null, userId); 909 910 long timeout; 911 912 if (policyTimeout <= 0) { 913 timeout = lockAfterTimeout; 914 } else { 915 // From DisplaySettings 916 long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT, 917 KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT); 918 919 // policy in effect. Make sure we don't go beyond policy limit. 920 displayTimeout = Math.max(displayTimeout, 0); // ignore negative values 921 timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout); 922 timeout = Math.max(timeout, 0); 923 } 924 return timeout; 925 } 926 doKeyguardLaterLocked()927 private void doKeyguardLaterLocked() { 928 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser()); 929 if (timeout == 0) { 930 doKeyguardLocked(null); 931 } else { 932 doKeyguardLaterLocked(timeout); 933 } 934 } 935 doKeyguardLaterLocked(long timeout)936 private void doKeyguardLaterLocked(long timeout) { 937 // Lock in the future 938 long when = SystemClock.elapsedRealtime() + timeout; 939 Intent intent = new Intent(DELAYED_KEYGUARD_ACTION); 940 intent.putExtra("seq", mDelayedShowingSequence); 941 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); 942 PendingIntent sender = PendingIntent.getBroadcast(mContext, 943 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); 944 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender); 945 if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = " 946 + mDelayedShowingSequence); 947 doKeyguardLaterForChildProfilesLocked(); 948 } 949 doKeyguardLaterForChildProfilesLocked()950 private void doKeyguardLaterForChildProfilesLocked() { 951 UserManager um = UserManager.get(mContext); 952 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) { 953 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) { 954 long userTimeout = getLockTimeout(profileId); 955 if (userTimeout == 0) { 956 doKeyguardForChildProfilesLocked(); 957 } else { 958 long userWhen = SystemClock.elapsedRealtime() + userTimeout; 959 Intent lockIntent = new Intent(DELAYED_LOCK_PROFILE_ACTION); 960 lockIntent.putExtra("seq", mDelayedProfileShowingSequence); 961 lockIntent.putExtra(Intent.EXTRA_USER_ID, profileId); 962 lockIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); 963 PendingIntent lockSender = PendingIntent.getBroadcast( 964 mContext, 0, lockIntent, PendingIntent.FLAG_CANCEL_CURRENT); 965 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, 966 userWhen, lockSender); 967 } 968 } 969 } 970 } 971 doKeyguardForChildProfilesLocked()972 private void doKeyguardForChildProfilesLocked() { 973 UserManager um = UserManager.get(mContext); 974 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) { 975 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) { 976 lockProfile(profileId); 977 } 978 } 979 } 980 cancelDoKeyguardLaterLocked()981 private void cancelDoKeyguardLaterLocked() { 982 mDelayedShowingSequence++; 983 } 984 cancelDoKeyguardForChildProfilesLocked()985 private void cancelDoKeyguardForChildProfilesLocked() { 986 mDelayedProfileShowingSequence++; 987 } 988 989 /** 990 * Let's us know when the device is waking up. 991 */ onStartedWakingUp()992 public void onStartedWakingUp() { 993 Trace.beginSection("KeyguardViewMediator#onStartedWakingUp"); 994 995 // TODO: Rename all screen off/on references to interactive/sleeping 996 synchronized (this) { 997 mDeviceInteractive = true; 998 cancelDoKeyguardLaterLocked(); 999 cancelDoKeyguardForChildProfilesLocked(); 1000 if (DEBUG) Log.d(TAG, "onStartedWakingUp, seq = " + mDelayedShowingSequence); 1001 notifyStartedWakingUp(); 1002 } 1003 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedWakingUp(); 1004 maybeSendUserPresentBroadcast(); 1005 Trace.endSection(); 1006 } 1007 onScreenTurningOn(IKeyguardDrawnCallback callback)1008 public void onScreenTurningOn(IKeyguardDrawnCallback callback) { 1009 Trace.beginSection("KeyguardViewMediator#onScreenTurningOn"); 1010 notifyScreenOn(callback); 1011 Trace.endSection(); 1012 } 1013 onScreenTurnedOn()1014 public void onScreenTurnedOn() { 1015 Trace.beginSection("KeyguardViewMediator#onScreenTurnedOn"); 1016 notifyScreenTurnedOn(); 1017 mUpdateMonitor.dispatchScreenTurnedOn(); 1018 Trace.endSection(); 1019 } 1020 onScreenTurnedOff()1021 public void onScreenTurnedOff() { 1022 notifyScreenTurnedOff(); 1023 mUpdateMonitor.dispatchScreenTurnedOff(); 1024 } 1025 maybeSendUserPresentBroadcast()1026 private void maybeSendUserPresentBroadcast() { 1027 if (mSystemReady && mLockPatternUtils.isLockScreenDisabled( 1028 KeyguardUpdateMonitor.getCurrentUser())) { 1029 // Lock screen is disabled because the user has set the preference to "None". 1030 // In this case, send out ACTION_USER_PRESENT here instead of in 1031 // handleKeyguardDone() 1032 sendUserPresentBroadcast(); 1033 } else if (mSystemReady && shouldWaitForProvisioning()) { 1034 // Skipping the lockscreen because we're not yet provisioned, but we still need to 1035 // notify the StrongAuthTracker that it's now safe to run trust agents, in case the 1036 // user sets a credential later. 1037 getLockPatternUtils().userPresent(KeyguardUpdateMonitor.getCurrentUser()); 1038 } 1039 } 1040 1041 /** 1042 * A dream started. We should lock after the usual screen-off lock timeout but only 1043 * if there is a secure lock pattern. 1044 */ onDreamingStarted()1045 public void onDreamingStarted() { 1046 KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStarted(); 1047 synchronized (this) { 1048 if (mDeviceInteractive 1049 && mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())) { 1050 doKeyguardLaterLocked(); 1051 } 1052 } 1053 } 1054 1055 /** 1056 * A dream stopped. 1057 */ onDreamingStopped()1058 public void onDreamingStopped() { 1059 KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStopped(); 1060 synchronized (this) { 1061 if (mDeviceInteractive) { 1062 cancelDoKeyguardLaterLocked(); 1063 } 1064 } 1065 } 1066 1067 /** 1068 * Same semantics as {@link WindowManagerPolicyConstants#enableKeyguard}; provide 1069 * a way for external stuff to override normal keyguard behavior. For instance 1070 * the phone app disables the keyguard when it receives incoming calls. 1071 */ setKeyguardEnabled(boolean enabled)1072 public void setKeyguardEnabled(boolean enabled) { 1073 synchronized (this) { 1074 if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")"); 1075 1076 mExternallyEnabled = enabled; 1077 1078 if (!enabled && mShowing) { 1079 if (mExitSecureCallback != null) { 1080 if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring"); 1081 // we're in the process of handling a request to verify the user 1082 // can get past the keyguard. ignore extraneous requests to disable / reenable 1083 return; 1084 } 1085 1086 // hiding keyguard that is showing, remember to reshow later 1087 if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, " 1088 + "disabling status bar expansion"); 1089 mNeedToReshowWhenReenabled = true; 1090 updateInputRestrictedLocked(); 1091 hideLocked(); 1092 } else if (enabled && mNeedToReshowWhenReenabled) { 1093 // reenabled after previously hidden, reshow 1094 if (DEBUG) Log.d(TAG, "previously hidden, reshowing, reenabling " 1095 + "status bar expansion"); 1096 mNeedToReshowWhenReenabled = false; 1097 updateInputRestrictedLocked(); 1098 1099 if (mExitSecureCallback != null) { 1100 if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting"); 1101 try { 1102 mExitSecureCallback.onKeyguardExitResult(false); 1103 } catch (RemoteException e) { 1104 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); 1105 } 1106 mExitSecureCallback = null; 1107 resetStateLocked(); 1108 } else { 1109 showLocked(null); 1110 1111 // block until we know the keygaurd is done drawing (and post a message 1112 // to unblock us after a timeout so we don't risk blocking too long 1113 // and causing an ANR). 1114 mWaitingUntilKeyguardVisible = true; 1115 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING, KEYGUARD_DONE_DRAWING_TIMEOUT_MS); 1116 if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false"); 1117 while (mWaitingUntilKeyguardVisible) { 1118 try { 1119 wait(); 1120 } catch (InterruptedException e) { 1121 Thread.currentThread().interrupt(); 1122 } 1123 } 1124 if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible"); 1125 } 1126 } 1127 } 1128 } 1129 1130 /** 1131 * @see android.app.KeyguardManager#exitKeyguardSecurely 1132 */ verifyUnlock(IKeyguardExitCallback callback)1133 public void verifyUnlock(IKeyguardExitCallback callback) { 1134 Trace.beginSection("KeyguardViewMediator#verifyUnlock"); 1135 synchronized (this) { 1136 if (DEBUG) Log.d(TAG, "verifyUnlock"); 1137 if (shouldWaitForProvisioning()) { 1138 // don't allow this api when the device isn't provisioned 1139 if (DEBUG) Log.d(TAG, "ignoring because device isn't provisioned"); 1140 try { 1141 callback.onKeyguardExitResult(false); 1142 } catch (RemoteException e) { 1143 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); 1144 } 1145 } else if (mExternallyEnabled) { 1146 // this only applies when the user has externally disabled the 1147 // keyguard. this is unexpected and means the user is not 1148 // using the api properly. 1149 Log.w(TAG, "verifyUnlock called when not externally disabled"); 1150 try { 1151 callback.onKeyguardExitResult(false); 1152 } catch (RemoteException e) { 1153 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); 1154 } 1155 } else if (mExitSecureCallback != null) { 1156 // already in progress with someone else 1157 try { 1158 callback.onKeyguardExitResult(false); 1159 } catch (RemoteException e) { 1160 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); 1161 } 1162 } else if (!isSecure()) { 1163 1164 // Keyguard is not secure, no need to do anything, and we don't need to reshow 1165 // the Keyguard after the client releases the Keyguard lock. 1166 mExternallyEnabled = true; 1167 mNeedToReshowWhenReenabled = false; 1168 updateInputRestricted(); 1169 try { 1170 callback.onKeyguardExitResult(true); 1171 } catch (RemoteException e) { 1172 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); 1173 } 1174 } else { 1175 1176 // Since we prevent apps from hiding the Keyguard if we are secure, this should be 1177 // a no-op as well. 1178 try { 1179 callback.onKeyguardExitResult(false); 1180 } catch (RemoteException e) { 1181 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); 1182 } 1183 } 1184 } 1185 Trace.endSection(); 1186 } 1187 1188 /** 1189 * Is the keyguard currently showing and not being force hidden? 1190 */ isShowingAndNotOccluded()1191 public boolean isShowingAndNotOccluded() { 1192 return mShowing && !mOccluded; 1193 } 1194 1195 /** 1196 * Notify us when the keyguard is occluded by another window 1197 */ setOccluded(boolean isOccluded, boolean animate)1198 public void setOccluded(boolean isOccluded, boolean animate) { 1199 Trace.beginSection("KeyguardViewMediator#setOccluded"); 1200 if (DEBUG) Log.d(TAG, "setOccluded " + isOccluded); 1201 mHandler.removeMessages(SET_OCCLUDED); 1202 Message msg = mHandler.obtainMessage(SET_OCCLUDED, isOccluded ? 1 : 0, animate ? 1 : 0); 1203 mHandler.sendMessage(msg); 1204 Trace.endSection(); 1205 } 1206 isHiding()1207 public boolean isHiding() { 1208 return mHiding; 1209 } 1210 1211 /** 1212 * Handles SET_OCCLUDED message sent by setOccluded() 1213 */ handleSetOccluded(boolean isOccluded, boolean animate)1214 private void handleSetOccluded(boolean isOccluded, boolean animate) { 1215 Trace.beginSection("KeyguardViewMediator#handleSetOccluded"); 1216 synchronized (KeyguardViewMediator.this) { 1217 if (mHiding && isOccluded) { 1218 // We're in the process of going away but WindowManager wants to show a 1219 // SHOW_WHEN_LOCKED activity instead. 1220 startKeyguardExitAnimation(0, 0); 1221 } 1222 1223 if (mOccluded != isOccluded) { 1224 mOccluded = isOccluded; 1225 mUpdateMonitor.setKeyguardOccluded(isOccluded); 1226 mStatusBarKeyguardViewManager.setOccluded(isOccluded, animate 1227 && mDeviceInteractive); 1228 adjustStatusBarLocked(); 1229 } 1230 } 1231 Trace.endSection(); 1232 } 1233 1234 /** 1235 * Used by PhoneWindowManager to enable the keyguard due to a user activity timeout. 1236 * This must be safe to call from any thread and with any window manager locks held. 1237 */ doKeyguardTimeout(Bundle options)1238 public void doKeyguardTimeout(Bundle options) { 1239 mHandler.removeMessages(KEYGUARD_TIMEOUT); 1240 Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT, options); 1241 mHandler.sendMessage(msg); 1242 } 1243 1244 /** 1245 * Given the state of the keyguard, is the input restricted? 1246 * Input is restricted when the keyguard is showing, or when the keyguard 1247 * was suppressed by an app that disabled the keyguard or we haven't been provisioned yet. 1248 */ isInputRestricted()1249 public boolean isInputRestricted() { 1250 return mShowing || mNeedToReshowWhenReenabled; 1251 } 1252 updateInputRestricted()1253 private void updateInputRestricted() { 1254 synchronized (this) { 1255 updateInputRestrictedLocked(); 1256 } 1257 } 1258 updateInputRestrictedLocked()1259 private void updateInputRestrictedLocked() { 1260 boolean inputRestricted = isInputRestricted(); 1261 if (mInputRestricted != inputRestricted) { 1262 mInputRestricted = inputRestricted; 1263 int size = mKeyguardStateCallbacks.size(); 1264 for (int i = size - 1; i >= 0; i--) { 1265 final IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i); 1266 try { 1267 callback.onInputRestrictedStateChanged(inputRestricted); 1268 } catch (RemoteException e) { 1269 Slog.w(TAG, "Failed to call onDeviceProvisioned", e); 1270 if (e instanceof DeadObjectException) { 1271 mKeyguardStateCallbacks.remove(callback); 1272 } 1273 } 1274 } 1275 } 1276 } 1277 1278 /** 1279 * Enable the keyguard if the settings are appropriate. 1280 */ doKeyguardLocked(Bundle options)1281 private void doKeyguardLocked(Bundle options) { 1282 if (KeyguardUpdateMonitor.CORE_APPS_ONLY) { 1283 // Don't show keyguard during half-booted cryptkeeper stage. 1284 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because booting to cryptkeeper"); 1285 return; 1286 } 1287 1288 // if another app is disabling us, don't show 1289 if (!mExternallyEnabled) { 1290 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled"); 1291 1292 mNeedToReshowWhenReenabled = true; 1293 return; 1294 } 1295 1296 // if the keyguard is already showing, don't bother 1297 if (mStatusBarKeyguardViewManager.isShowing()) { 1298 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing"); 1299 resetStateLocked(); 1300 return; 1301 } 1302 1303 // In split system user mode, we never unlock system user. 1304 if (!mustNotUnlockCurrentUser() 1305 || !mUpdateMonitor.isDeviceProvisioned()) { 1306 1307 // if the setup wizard hasn't run yet, don't show 1308 final boolean requireSim = !SystemProperties.getBoolean("keyguard.no_require_sim", false); 1309 final boolean absent = SubscriptionManager.isValidSubscriptionId( 1310 mUpdateMonitor.getNextSubIdForState(ABSENT)); 1311 final boolean disabled = SubscriptionManager.isValidSubscriptionId( 1312 mUpdateMonitor.getNextSubIdForState(IccCardConstants.State.PERM_DISABLED)); 1313 final boolean lockedOrMissing = mUpdateMonitor.isSimPinSecure() 1314 || ((absent || disabled) && requireSim); 1315 1316 if (!lockedOrMissing && shouldWaitForProvisioning()) { 1317 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned" 1318 + " and the sim is not locked or missing"); 1319 return; 1320 } 1321 1322 boolean forceShow = options != null && options.getBoolean(OPTION_FORCE_SHOW, false); 1323 if (mLockPatternUtils.isLockScreenDisabled(KeyguardUpdateMonitor.getCurrentUser()) 1324 && !lockedOrMissing && !forceShow) { 1325 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off"); 1326 return; 1327 } 1328 1329 if (mLockPatternUtils.checkVoldPassword(KeyguardUpdateMonitor.getCurrentUser())) { 1330 if (DEBUG) Log.d(TAG, "Not showing lock screen since just decrypted"); 1331 // Without this, settings is not enabled until the lock screen first appears 1332 setShowingLocked(false); 1333 hideLocked(); 1334 return; 1335 } 1336 } 1337 1338 if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen"); 1339 showLocked(options); 1340 } 1341 lockProfile(int userId)1342 private void lockProfile(int userId) { 1343 mTrustManager.setDeviceLockedForUser(userId, true); 1344 } 1345 shouldWaitForProvisioning()1346 private boolean shouldWaitForProvisioning() { 1347 return !mUpdateMonitor.isDeviceProvisioned() && !isSecure(); 1348 } 1349 1350 /** 1351 * Dismiss the keyguard through the security layers. 1352 * @param callback Callback to be informed about the result 1353 * @param message Message that should be displayed on the bouncer. 1354 */ handleDismiss(IKeyguardDismissCallback callback, CharSequence message)1355 private void handleDismiss(IKeyguardDismissCallback callback, CharSequence message) { 1356 if (mShowing) { 1357 if (callback != null) { 1358 mDismissCallbackRegistry.addCallback(callback); 1359 } 1360 mCustomMessage = message; 1361 mStatusBarKeyguardViewManager.dismissAndCollapse(); 1362 } else if (callback != null) { 1363 new DismissCallbackWrapper(callback).notifyDismissError(); 1364 } 1365 } 1366 dismiss(IKeyguardDismissCallback callback, CharSequence message)1367 public void dismiss(IKeyguardDismissCallback callback, CharSequence message) { 1368 mHandler.obtainMessage(DISMISS, new DismissMessage(callback, message)).sendToTarget(); 1369 } 1370 1371 /** 1372 * Send message to keyguard telling it to reset its state. 1373 * @see #handleReset 1374 */ resetStateLocked()1375 private void resetStateLocked() { 1376 if (DEBUG) Log.e(TAG, "resetStateLocked"); 1377 Message msg = mHandler.obtainMessage(RESET); 1378 mHandler.sendMessage(msg); 1379 } 1380 1381 /** 1382 * Send message to keyguard telling it to verify unlock 1383 * @see #handleVerifyUnlock() 1384 */ verifyUnlockLocked()1385 private void verifyUnlockLocked() { 1386 if (DEBUG) Log.d(TAG, "verifyUnlockLocked"); 1387 mHandler.sendEmptyMessage(VERIFY_UNLOCK); 1388 } 1389 notifyStartedGoingToSleep()1390 private void notifyStartedGoingToSleep() { 1391 if (DEBUG) Log.d(TAG, "notifyStartedGoingToSleep"); 1392 mHandler.sendEmptyMessage(NOTIFY_STARTED_GOING_TO_SLEEP); 1393 } 1394 notifyFinishedGoingToSleep()1395 private void notifyFinishedGoingToSleep() { 1396 if (DEBUG) Log.d(TAG, "notifyFinishedGoingToSleep"); 1397 mHandler.sendEmptyMessage(NOTIFY_FINISHED_GOING_TO_SLEEP); 1398 } 1399 notifyStartedWakingUp()1400 private void notifyStartedWakingUp() { 1401 if (DEBUG) Log.d(TAG, "notifyStartedWakingUp"); 1402 mHandler.sendEmptyMessage(NOTIFY_STARTED_WAKING_UP); 1403 } 1404 notifyScreenOn(IKeyguardDrawnCallback callback)1405 private void notifyScreenOn(IKeyguardDrawnCallback callback) { 1406 if (DEBUG) Log.d(TAG, "notifyScreenOn"); 1407 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNING_ON, callback); 1408 mHandler.sendMessage(msg); 1409 } 1410 notifyScreenTurnedOn()1411 private void notifyScreenTurnedOn() { 1412 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOn"); 1413 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_ON); 1414 mHandler.sendMessage(msg); 1415 } 1416 notifyScreenTurnedOff()1417 private void notifyScreenTurnedOff() { 1418 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOff"); 1419 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_OFF); 1420 mHandler.sendMessage(msg); 1421 } 1422 1423 /** 1424 * Send message to keyguard telling it to show itself 1425 * @see #handleShow 1426 */ showLocked(Bundle options)1427 private void showLocked(Bundle options) { 1428 Trace.beginSection("KeyguardViewMediator#showLocked aqcuiring mShowKeyguardWakeLock"); 1429 if (DEBUG) Log.d(TAG, "showLocked"); 1430 // ensure we stay awake until we are finished displaying the keyguard 1431 mShowKeyguardWakeLock.acquire(); 1432 Message msg = mHandler.obtainMessage(SHOW, options); 1433 mHandler.sendMessage(msg); 1434 Trace.endSection(); 1435 } 1436 1437 /** 1438 * Send message to keyguard telling it to hide itself 1439 * @see #handleHide() 1440 */ hideLocked()1441 private void hideLocked() { 1442 Trace.beginSection("KeyguardViewMediator#hideLocked"); 1443 if (DEBUG) Log.d(TAG, "hideLocked"); 1444 Message msg = mHandler.obtainMessage(HIDE); 1445 mHandler.sendMessage(msg); 1446 Trace.endSection(); 1447 } 1448 isSecure()1449 public boolean isSecure() { 1450 return isSecure(KeyguardUpdateMonitor.getCurrentUser()); 1451 } 1452 isSecure(int userId)1453 public boolean isSecure(int userId) { 1454 return mLockPatternUtils.isSecure(userId) 1455 || KeyguardUpdateMonitor.getInstance(mContext).isSimPinSecure(); 1456 } 1457 setSwitchingUser(boolean switching)1458 public void setSwitchingUser(boolean switching) { 1459 KeyguardUpdateMonitor.getInstance(mContext).setSwitchingUser(switching); 1460 } 1461 1462 /** 1463 * Update the newUserId. Call while holding WindowManagerService lock. 1464 * NOTE: Should only be called by KeyguardViewMediator in response to the user id changing. 1465 * 1466 * @param newUserId The id of the incoming user. 1467 */ setCurrentUser(int newUserId)1468 public void setCurrentUser(int newUserId) { 1469 KeyguardUpdateMonitor.setCurrentUser(newUserId); 1470 synchronized (this) { 1471 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(newUserId)); 1472 } 1473 } 1474 1475 /** 1476 * This broadcast receiver should be registered with the SystemUI permission. 1477 */ 1478 private final BroadcastReceiver mDelayedLockBroadcastReceiver = new BroadcastReceiver() { 1479 @Override 1480 public void onReceive(Context context, Intent intent) { 1481 if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) { 1482 final int sequence = intent.getIntExtra("seq", 0); 1483 if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = " 1484 + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence); 1485 synchronized (KeyguardViewMediator.this) { 1486 if (mDelayedShowingSequence == sequence) { 1487 doKeyguardLocked(null); 1488 } 1489 } 1490 } else if (DELAYED_LOCK_PROFILE_ACTION.equals(intent.getAction())) { 1491 final int sequence = intent.getIntExtra("seq", 0); 1492 int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, 0); 1493 if (userId != 0) { 1494 synchronized (KeyguardViewMediator.this) { 1495 if (mDelayedProfileShowingSequence == sequence) { 1496 lockProfile(userId); 1497 } 1498 } 1499 } 1500 } 1501 } 1502 }; 1503 1504 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { 1505 @Override 1506 public void onReceive(Context context, Intent intent) { 1507 if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) { 1508 synchronized (KeyguardViewMediator.this){ 1509 mShuttingDown = true; 1510 } 1511 } 1512 } 1513 }; 1514 keyguardDone()1515 public void keyguardDone() { 1516 Trace.beginSection("KeyguardViewMediator#keyguardDone"); 1517 if (DEBUG) Log.d(TAG, "keyguardDone()"); 1518 userActivity(); 1519 EventLog.writeEvent(70000, 2); 1520 Message msg = mHandler.obtainMessage(KEYGUARD_DONE); 1521 mHandler.sendMessage(msg); 1522 Trace.endSection(); 1523 } 1524 1525 /** 1526 * This handler will be associated with the policy thread, which will also 1527 * be the UI thread of the keyguard. Since the apis of the policy, and therefore 1528 * this class, can be called by other threads, any action that directly 1529 * interacts with the keyguard ui should be posted to this handler, rather 1530 * than called directly. 1531 */ 1532 private Handler mHandler = new Handler(Looper.myLooper(), null, true /*async*/) { 1533 @Override 1534 public void handleMessage(Message msg) { 1535 switch (msg.what) { 1536 case SHOW: 1537 handleShow((Bundle) msg.obj); 1538 break; 1539 case HIDE: 1540 handleHide(); 1541 break; 1542 case RESET: 1543 handleReset(); 1544 break; 1545 case VERIFY_UNLOCK: 1546 Trace.beginSection("KeyguardViewMediator#handleMessage VERIFY_UNLOCK"); 1547 handleVerifyUnlock(); 1548 Trace.endSection(); 1549 break; 1550 case NOTIFY_STARTED_GOING_TO_SLEEP: 1551 handleNotifyStartedGoingToSleep(); 1552 break; 1553 case NOTIFY_FINISHED_GOING_TO_SLEEP: 1554 handleNotifyFinishedGoingToSleep(); 1555 break; 1556 case NOTIFY_SCREEN_TURNING_ON: 1557 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNING_ON"); 1558 handleNotifyScreenTurningOn((IKeyguardDrawnCallback) msg.obj); 1559 Trace.endSection(); 1560 break; 1561 case NOTIFY_SCREEN_TURNED_ON: 1562 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNED_ON"); 1563 handleNotifyScreenTurnedOn(); 1564 Trace.endSection(); 1565 break; 1566 case NOTIFY_SCREEN_TURNED_OFF: 1567 handleNotifyScreenTurnedOff(); 1568 break; 1569 case NOTIFY_STARTED_WAKING_UP: 1570 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_STARTED_WAKING_UP"); 1571 handleNotifyStartedWakingUp(); 1572 Trace.endSection(); 1573 break; 1574 case KEYGUARD_DONE: 1575 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE"); 1576 handleKeyguardDone(); 1577 Trace.endSection(); 1578 break; 1579 case KEYGUARD_DONE_DRAWING: 1580 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_DRAWING"); 1581 handleKeyguardDoneDrawing(); 1582 Trace.endSection(); 1583 break; 1584 case SET_OCCLUDED: 1585 Trace.beginSection("KeyguardViewMediator#handleMessage SET_OCCLUDED"); 1586 handleSetOccluded(msg.arg1 != 0, msg.arg2 != 0); 1587 Trace.endSection(); 1588 break; 1589 case KEYGUARD_TIMEOUT: 1590 synchronized (KeyguardViewMediator.this) { 1591 doKeyguardLocked((Bundle) msg.obj); 1592 } 1593 break; 1594 case DISMISS: 1595 final DismissMessage message = (DismissMessage) msg.obj; 1596 handleDismiss(message.getCallback(), message.getMessage()); 1597 break; 1598 case START_KEYGUARD_EXIT_ANIM: 1599 Trace.beginSection("KeyguardViewMediator#handleMessage START_KEYGUARD_EXIT_ANIM"); 1600 StartKeyguardExitAnimParams params = (StartKeyguardExitAnimParams) msg.obj; 1601 handleStartKeyguardExitAnimation(params.startTime, params.fadeoutDuration); 1602 Dependency.get(FalsingManager.class).onSucccessfulUnlock(); 1603 Trace.endSection(); 1604 break; 1605 case KEYGUARD_DONE_PENDING_TIMEOUT: 1606 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_PENDING_TIMEOUT"); 1607 Log.w(TAG, "Timeout while waiting for activity drawn!"); 1608 Trace.endSection(); 1609 break; 1610 case SYSTEM_READY: 1611 handleSystemReady(); 1612 break; 1613 } 1614 } 1615 }; 1616 tryKeyguardDone()1617 private void tryKeyguardDone() { 1618 if (!mKeyguardDonePending && mHideAnimationRun && !mHideAnimationRunning) { 1619 handleKeyguardDone(); 1620 } else if (!mHideAnimationRun) { 1621 mHideAnimationRun = true; 1622 mHideAnimationRunning = true; 1623 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable); 1624 } 1625 } 1626 1627 /** 1628 * @see #keyguardDone 1629 * @see #KEYGUARD_DONE 1630 */ handleKeyguardDone()1631 private void handleKeyguardDone() { 1632 Trace.beginSection("KeyguardViewMediator#handleKeyguardDone"); 1633 final int currentUser = KeyguardUpdateMonitor.getCurrentUser(); 1634 mUiOffloadThread.submit(() -> { 1635 if (mLockPatternUtils.isSecure(currentUser)) { 1636 mLockPatternUtils.getDevicePolicyManager().reportKeyguardDismissed(currentUser); 1637 } 1638 }); 1639 if (DEBUG) Log.d(TAG, "handleKeyguardDone"); 1640 synchronized (this) { 1641 resetKeyguardDonePendingLocked(); 1642 } 1643 1644 mUpdateMonitor.clearBiometricRecognized(); 1645 1646 if (mGoingToSleep) { 1647 Log.i(TAG, "Device is going to sleep, aborting keyguardDone"); 1648 return; 1649 } 1650 if (mExitSecureCallback != null) { 1651 try { 1652 mExitSecureCallback.onKeyguardExitResult(true /* authenciated */); 1653 } catch (RemoteException e) { 1654 Slog.w(TAG, "Failed to call onKeyguardExitResult()", e); 1655 } 1656 1657 mExitSecureCallback = null; 1658 1659 // after succesfully exiting securely, no need to reshow 1660 // the keyguard when they've released the lock 1661 mExternallyEnabled = true; 1662 mNeedToReshowWhenReenabled = false; 1663 updateInputRestricted(); 1664 } 1665 1666 handleHide(); 1667 Trace.endSection(); 1668 } 1669 sendUserPresentBroadcast()1670 private void sendUserPresentBroadcast() { 1671 synchronized (this) { 1672 if (mBootCompleted) { 1673 int currentUserId = KeyguardUpdateMonitor.getCurrentUser(); 1674 final UserHandle currentUser = new UserHandle(currentUserId); 1675 final UserManager um = (UserManager) mContext.getSystemService( 1676 Context.USER_SERVICE); 1677 mUiOffloadThread.submit(() -> { 1678 for (int profileId : um.getProfileIdsWithDisabled(currentUser.getIdentifier())) { 1679 mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, UserHandle.of(profileId)); 1680 } 1681 getLockPatternUtils().userPresent(currentUserId); 1682 }); 1683 } else { 1684 mBootSendUserPresent = true; 1685 } 1686 } 1687 } 1688 1689 /** 1690 * @see #keyguardDone 1691 * @see #KEYGUARD_DONE_DRAWING 1692 */ handleKeyguardDoneDrawing()1693 private void handleKeyguardDoneDrawing() { 1694 Trace.beginSection("KeyguardViewMediator#handleKeyguardDoneDrawing"); 1695 synchronized(this) { 1696 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing"); 1697 if (mWaitingUntilKeyguardVisible) { 1698 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing: notifying mWaitingUntilKeyguardVisible"); 1699 mWaitingUntilKeyguardVisible = false; 1700 notifyAll(); 1701 1702 // there will usually be two of these sent, one as a timeout, and one 1703 // as a result of the callback, so remove any remaining messages from 1704 // the queue 1705 mHandler.removeMessages(KEYGUARD_DONE_DRAWING); 1706 } 1707 } 1708 Trace.endSection(); 1709 } 1710 playSounds(boolean locked)1711 private void playSounds(boolean locked) { 1712 playSound(locked ? mLockSoundId : mUnlockSoundId); 1713 } 1714 playSound(int soundId)1715 private void playSound(int soundId) { 1716 if (soundId == 0) return; 1717 final ContentResolver cr = mContext.getContentResolver(); 1718 if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) { 1719 1720 mLockSounds.stop(mLockSoundStreamId); 1721 // Init mAudioManager 1722 if (mAudioManager == null) { 1723 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); 1724 if (mAudioManager == null) return; 1725 mUiSoundsStreamType = mAudioManager.getUiSoundsStreamType(); 1726 } 1727 1728 mUiOffloadThread.submit(() -> { 1729 // If the stream is muted, don't play the sound 1730 if (mAudioManager.isStreamMute(mUiSoundsStreamType)) return; 1731 1732 int id = mLockSounds.play(soundId, 1733 mLockSoundVolume, mLockSoundVolume, 1/*priortiy*/, 0/*loop*/, 1.0f/*rate*/); 1734 synchronized (this) { 1735 mLockSoundStreamId = id; 1736 } 1737 }); 1738 1739 } 1740 } 1741 playTrustedSound()1742 private void playTrustedSound() { 1743 playSound(mTrustedSoundId); 1744 } 1745 updateActivityLockScreenState(boolean showing, boolean aodShowing)1746 private void updateActivityLockScreenState(boolean showing, boolean aodShowing) { 1747 mUiOffloadThread.submit(() -> { 1748 if (DEBUG) { 1749 Log.d(TAG, "updateActivityLockScreenState(" + showing + ", " + aodShowing + ")"); 1750 } 1751 try { 1752 ActivityTaskManager.getService().setLockScreenShown(showing, aodShowing); 1753 } catch (RemoteException e) { 1754 } 1755 }); 1756 } 1757 1758 /** 1759 * Handle message sent by {@link #showLocked}. 1760 * @see #SHOW 1761 */ handleShow(Bundle options)1762 private void handleShow(Bundle options) { 1763 Trace.beginSection("KeyguardViewMediator#handleShow"); 1764 final int currentUser = KeyguardUpdateMonitor.getCurrentUser(); 1765 if (mLockPatternUtils.isSecure(currentUser)) { 1766 mLockPatternUtils.getDevicePolicyManager().reportKeyguardSecured(currentUser); 1767 } 1768 synchronized (KeyguardViewMediator.this) { 1769 if (!mSystemReady) { 1770 if (DEBUG) Log.d(TAG, "ignoring handleShow because system is not ready."); 1771 return; 1772 } else { 1773 if (DEBUG) Log.d(TAG, "handleShow"); 1774 } 1775 1776 mHiding = false; 1777 mWakeAndUnlocking = false; 1778 setShowingLocked(true); 1779 mStatusBarKeyguardViewManager.show(options); 1780 resetKeyguardDonePendingLocked(); 1781 mHideAnimationRun = false; 1782 adjustStatusBarLocked(); 1783 userActivity(); 1784 mUpdateMonitor.setKeyguardGoingAway(false /* away */); 1785 mStatusBarWindowController.setKeyguardGoingAway(false /* goingAway */); 1786 mShowKeyguardWakeLock.release(); 1787 } 1788 mKeyguardDisplayManager.show(); 1789 Trace.endSection(); 1790 } 1791 1792 private final Runnable mKeyguardGoingAwayRunnable = new Runnable() { 1793 @Override 1794 public void run() { 1795 Trace.beginSection("KeyguardViewMediator.mKeyGuardGoingAwayRunnable"); 1796 if (DEBUG) Log.d(TAG, "keyguardGoingAway"); 1797 mStatusBarKeyguardViewManager.keyguardGoingAway(); 1798 1799 int flags = 0; 1800 if (mStatusBarKeyguardViewManager.shouldDisableWindowAnimationsForUnlock() 1801 || (mWakeAndUnlocking && !mPulsing)) { 1802 flags |= WindowManagerPolicyConstants 1803 .KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS; 1804 } 1805 if (mStatusBarKeyguardViewManager.isGoingToNotificationShade() 1806 || (mWakeAndUnlocking && mPulsing)) { 1807 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE; 1808 } 1809 if (mStatusBarKeyguardViewManager.isUnlockWithWallpaper()) { 1810 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER; 1811 } 1812 if (mStatusBarKeyguardViewManager.shouldSubtleWindowAnimationsForUnlock()) { 1813 flags |= WindowManagerPolicyConstants 1814 .KEYGUARD_GOING_AWAY_FLAG_SUBTLE_WINDOW_ANIMATIONS; 1815 } 1816 1817 mUpdateMonitor.setKeyguardGoingAway(true /* goingAway */); 1818 mStatusBarWindowController.setKeyguardGoingAway(true /* goingAway */); 1819 1820 // Don't actually hide the Keyguard at the moment, wait for window 1821 // manager until it tells us it's safe to do so with 1822 // startKeyguardExitAnimation. 1823 // Posting to mUiOffloadThread to ensure that calls to ActivityTaskManager will be in 1824 // order. 1825 final int keyguardFlag = flags; 1826 mUiOffloadThread.submit(() -> { 1827 try { 1828 ActivityTaskManager.getService().keyguardGoingAway(keyguardFlag); 1829 } catch (RemoteException e) { 1830 Log.e(TAG, "Error while calling WindowManager", e); 1831 } 1832 }); 1833 Trace.endSection(); 1834 } 1835 }; 1836 1837 private final Runnable mHideAnimationFinishedRunnable = () -> { 1838 mHideAnimationRunning = false; 1839 tryKeyguardDone(); 1840 }; 1841 1842 /** 1843 * Handle message sent by {@link #hideLocked()} 1844 * @see #HIDE 1845 */ handleHide()1846 private void handleHide() { 1847 Trace.beginSection("KeyguardViewMediator#handleHide"); 1848 1849 // It's possible that the device was unlocked in a dream state. It's time to wake up. 1850 if (mAodShowing) { 1851 PowerManager pm = mContext.getSystemService(PowerManager.class); 1852 pm.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE, 1853 "com.android.systemui:BOUNCER_DOZING"); 1854 } 1855 1856 synchronized (KeyguardViewMediator.this) { 1857 if (DEBUG) Log.d(TAG, "handleHide"); 1858 1859 if (mustNotUnlockCurrentUser()) { 1860 // In split system user mode, we never unlock system user. The end user has to 1861 // switch to another user. 1862 // TODO: We should stop it early by disabling the swipe up flow. Right now swipe up 1863 // still completes and makes the screen blank. 1864 if (DEBUG) Log.d(TAG, "Split system user, quit unlocking."); 1865 return; 1866 } 1867 mHiding = true; 1868 1869 if (mShowing && !mOccluded) { 1870 mKeyguardGoingAwayRunnable.run(); 1871 } else { 1872 handleStartKeyguardExitAnimation( 1873 SystemClock.uptimeMillis() + mHideAnimation.getStartOffset(), 1874 mHideAnimation.getDuration()); 1875 } 1876 } 1877 Trace.endSection(); 1878 } 1879 handleStartKeyguardExitAnimation(long startTime, long fadeoutDuration)1880 private void handleStartKeyguardExitAnimation(long startTime, long fadeoutDuration) { 1881 Trace.beginSection("KeyguardViewMediator#handleStartKeyguardExitAnimation"); 1882 if (DEBUG) Log.d(TAG, "handleStartKeyguardExitAnimation startTime=" + startTime 1883 + " fadeoutDuration=" + fadeoutDuration); 1884 synchronized (KeyguardViewMediator.this) { 1885 1886 if (!mHiding) { 1887 // Tell ActivityManager that we canceled the keyguardExitAnimation. 1888 setShowingLocked(mShowing, true /* force */); 1889 return; 1890 } 1891 mHiding = false; 1892 1893 if (mWakeAndUnlocking && mDrawnCallback != null) { 1894 1895 // Hack level over 9000: To speed up wake-and-unlock sequence, force it to report 1896 // the next draw from here so we don't have to wait for window manager to signal 1897 // this to our ViewRootImpl. 1898 mStatusBarKeyguardViewManager.getViewRootImpl().setReportNextDraw(); 1899 notifyDrawn(mDrawnCallback); 1900 mDrawnCallback = null; 1901 } 1902 1903 // only play "unlock" noises if not on a call (since the incall UI 1904 // disables the keyguard) 1905 if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState)) { 1906 playSounds(false); 1907 } 1908 1909 setShowingLocked(false); 1910 mWakeAndUnlocking = false; 1911 mDismissCallbackRegistry.notifyDismissSucceeded(); 1912 mStatusBarKeyguardViewManager.hide(startTime, fadeoutDuration); 1913 resetKeyguardDonePendingLocked(); 1914 mHideAnimationRun = false; 1915 adjustStatusBarLocked(); 1916 sendUserPresentBroadcast(); 1917 } 1918 Trace.endSection(); 1919 } 1920 adjustStatusBarLocked()1921 private void adjustStatusBarLocked() { 1922 adjustStatusBarLocked(false /* forceHideHomeRecentsButtons */); 1923 } 1924 adjustStatusBarLocked(boolean forceHideHomeRecentsButtons)1925 private void adjustStatusBarLocked(boolean forceHideHomeRecentsButtons) { 1926 if (mStatusBarManager == null) { 1927 mStatusBarManager = (StatusBarManager) 1928 mContext.getSystemService(Context.STATUS_BAR_SERVICE); 1929 } 1930 1931 if (mStatusBarManager == null) { 1932 Log.w(TAG, "Could not get status bar manager"); 1933 } else { 1934 // Disable aspects of the system/status/navigation bars that must not be re-enabled by 1935 // windows that appear on top, ever 1936 int flags = StatusBarManager.DISABLE_NONE; 1937 if (forceHideHomeRecentsButtons || isShowingAndNotOccluded()) { 1938 flags |= StatusBarManager.DISABLE_HOME | StatusBarManager.DISABLE_RECENT; 1939 } 1940 1941 if (DEBUG) { 1942 Log.d(TAG, "adjustStatusBarLocked: mShowing=" + mShowing + " mOccluded=" + mOccluded 1943 + " isSecure=" + isSecure() + " force=" + forceHideHomeRecentsButtons 1944 + " --> flags=0x" + Integer.toHexString(flags)); 1945 } 1946 1947 mStatusBarManager.disable(flags); 1948 } 1949 } 1950 1951 /** 1952 * Handle message sent by {@link #resetStateLocked} 1953 * @see #RESET 1954 */ handleReset()1955 private void handleReset() { 1956 synchronized (KeyguardViewMediator.this) { 1957 if (DEBUG) Log.d(TAG, "handleReset"); 1958 mStatusBarKeyguardViewManager.reset(true /* hideBouncerWhenShowing */); 1959 } 1960 } 1961 1962 /** 1963 * Handle message sent by {@link #verifyUnlock} 1964 * @see #VERIFY_UNLOCK 1965 */ handleVerifyUnlock()1966 private void handleVerifyUnlock() { 1967 Trace.beginSection("KeyguardViewMediator#handleVerifyUnlock"); 1968 synchronized (KeyguardViewMediator.this) { 1969 if (DEBUG) Log.d(TAG, "handleVerifyUnlock"); 1970 setShowingLocked(true); 1971 mStatusBarKeyguardViewManager.dismissAndCollapse(); 1972 } 1973 Trace.endSection(); 1974 } 1975 handleNotifyStartedGoingToSleep()1976 private void handleNotifyStartedGoingToSleep() { 1977 synchronized (KeyguardViewMediator.this) { 1978 if (DEBUG) Log.d(TAG, "handleNotifyStartedGoingToSleep"); 1979 mStatusBarKeyguardViewManager.onStartedGoingToSleep(); 1980 } 1981 } 1982 1983 /** 1984 * Handle message sent by {@link #notifyFinishedGoingToSleep()} 1985 * @see #NOTIFY_FINISHED_GOING_TO_SLEEP 1986 */ handleNotifyFinishedGoingToSleep()1987 private void handleNotifyFinishedGoingToSleep() { 1988 synchronized (KeyguardViewMediator.this) { 1989 if (DEBUG) Log.d(TAG, "handleNotifyFinishedGoingToSleep"); 1990 mStatusBarKeyguardViewManager.onFinishedGoingToSleep(); 1991 } 1992 } 1993 handleNotifyStartedWakingUp()1994 private void handleNotifyStartedWakingUp() { 1995 Trace.beginSection("KeyguardViewMediator#handleMotifyStartedWakingUp"); 1996 synchronized (KeyguardViewMediator.this) { 1997 if (DEBUG) Log.d(TAG, "handleNotifyWakingUp"); 1998 mStatusBarKeyguardViewManager.onStartedWakingUp(); 1999 } 2000 Trace.endSection(); 2001 } 2002 handleNotifyScreenTurningOn(IKeyguardDrawnCallback callback)2003 private void handleNotifyScreenTurningOn(IKeyguardDrawnCallback callback) { 2004 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurningOn"); 2005 synchronized (KeyguardViewMediator.this) { 2006 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurningOn"); 2007 mStatusBarKeyguardViewManager.onScreenTurningOn(); 2008 if (callback != null) { 2009 if (mWakeAndUnlocking) { 2010 mDrawnCallback = callback; 2011 } else { 2012 notifyDrawn(callback); 2013 } 2014 } 2015 } 2016 Trace.endSection(); 2017 } 2018 handleNotifyScreenTurnedOn()2019 private void handleNotifyScreenTurnedOn() { 2020 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurnedOn"); 2021 if (LatencyTracker.isEnabled(mContext)) { 2022 LatencyTracker.getInstance(mContext).onActionEnd(LatencyTracker.ACTION_TURN_ON_SCREEN); 2023 } 2024 synchronized (this) { 2025 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOn"); 2026 mStatusBarKeyguardViewManager.onScreenTurnedOn(); 2027 } 2028 Trace.endSection(); 2029 } 2030 handleNotifyScreenTurnedOff()2031 private void handleNotifyScreenTurnedOff() { 2032 synchronized (this) { 2033 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOff"); 2034 mDrawnCallback = null; 2035 } 2036 } 2037 notifyDrawn(final IKeyguardDrawnCallback callback)2038 private void notifyDrawn(final IKeyguardDrawnCallback callback) { 2039 Trace.beginSection("KeyguardViewMediator#notifyDrawn"); 2040 try { 2041 callback.onDrawn(); 2042 } catch (RemoteException e) { 2043 Slog.w(TAG, "Exception calling onDrawn():", e); 2044 } 2045 Trace.endSection(); 2046 } 2047 resetKeyguardDonePendingLocked()2048 private void resetKeyguardDonePendingLocked() { 2049 mKeyguardDonePending = false; 2050 mHandler.removeMessages(KEYGUARD_DONE_PENDING_TIMEOUT); 2051 } 2052 2053 @Override onBootCompleted()2054 public void onBootCompleted() { 2055 mUpdateMonitor.dispatchBootCompleted(); 2056 synchronized (this) { 2057 mBootCompleted = true; 2058 if (mBootSendUserPresent) { 2059 sendUserPresentBroadcast(); 2060 } 2061 } 2062 } 2063 onWakeAndUnlocking()2064 public void onWakeAndUnlocking() { 2065 Trace.beginSection("KeyguardViewMediator#onWakeAndUnlocking"); 2066 mWakeAndUnlocking = true; 2067 keyguardDone(); 2068 Trace.endSection(); 2069 } 2070 registerStatusBar(StatusBar statusBar, ViewGroup container, NotificationPanelView panelView, BiometricUnlockController biometricUnlockController, ViewGroup lockIconContainer, View notificationContainer, KeyguardBypassController bypassController, FalsingManager falsingManager)2071 public StatusBarKeyguardViewManager registerStatusBar(StatusBar statusBar, 2072 ViewGroup container, NotificationPanelView panelView, 2073 BiometricUnlockController biometricUnlockController, ViewGroup lockIconContainer, 2074 View notificationContainer, KeyguardBypassController bypassController, 2075 FalsingManager falsingManager) { 2076 mStatusBarKeyguardViewManager.registerStatusBar(statusBar, container, panelView, 2077 biometricUnlockController, mDismissCallbackRegistry, lockIconContainer, 2078 notificationContainer, bypassController, falsingManager); 2079 return mStatusBarKeyguardViewManager; 2080 } 2081 startKeyguardExitAnimation(long startTime, long fadeoutDuration)2082 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { 2083 Trace.beginSection("KeyguardViewMediator#startKeyguardExitAnimation"); 2084 Message msg = mHandler.obtainMessage(START_KEYGUARD_EXIT_ANIM, 2085 new StartKeyguardExitAnimParams(startTime, fadeoutDuration)); 2086 mHandler.sendMessage(msg); 2087 Trace.endSection(); 2088 } 2089 onShortPowerPressedGoHome()2090 public void onShortPowerPressedGoHome() { 2091 // do nothing 2092 } 2093 getViewMediatorCallback()2094 public ViewMediatorCallback getViewMediatorCallback() { 2095 return mViewMediatorCallback; 2096 } 2097 getLockPatternUtils()2098 public LockPatternUtils getLockPatternUtils() { 2099 return mLockPatternUtils; 2100 } 2101 2102 @Override dump(FileDescriptor fd, PrintWriter pw, String[] args)2103 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 2104 pw.print(" mSystemReady: "); pw.println(mSystemReady); 2105 pw.print(" mBootCompleted: "); pw.println(mBootCompleted); 2106 pw.print(" mBootSendUserPresent: "); pw.println(mBootSendUserPresent); 2107 pw.print(" mExternallyEnabled: "); pw.println(mExternallyEnabled); 2108 pw.print(" mShuttingDown: "); pw.println(mShuttingDown); 2109 pw.print(" mNeedToReshowWhenReenabled: "); pw.println(mNeedToReshowWhenReenabled); 2110 pw.print(" mShowing: "); pw.println(mShowing); 2111 pw.print(" mInputRestricted: "); pw.println(mInputRestricted); 2112 pw.print(" mOccluded: "); pw.println(mOccluded); 2113 pw.print(" mDelayedShowingSequence: "); pw.println(mDelayedShowingSequence); 2114 pw.print(" mExitSecureCallback: "); pw.println(mExitSecureCallback); 2115 pw.print(" mDeviceInteractive: "); pw.println(mDeviceInteractive); 2116 pw.print(" mGoingToSleep: "); pw.println(mGoingToSleep); 2117 pw.print(" mHiding: "); pw.println(mHiding); 2118 pw.print(" mDozing: "); pw.println(mDozing); 2119 pw.print(" mAodShowing: "); pw.println(mAodShowing); 2120 pw.print(" mWaitingUntilKeyguardVisible: "); pw.println(mWaitingUntilKeyguardVisible); 2121 pw.print(" mKeyguardDonePending: "); pw.println(mKeyguardDonePending); 2122 pw.print(" mHideAnimationRun: "); pw.println(mHideAnimationRun); 2123 pw.print(" mPendingReset: "); pw.println(mPendingReset); 2124 pw.print(" mPendingLock: "); pw.println(mPendingLock); 2125 pw.print(" mWakeAndUnlocking: "); pw.println(mWakeAndUnlocking); 2126 pw.print(" mDrawnCallback: "); pw.println(mDrawnCallback); 2127 } 2128 2129 /** 2130 * @param dozing true when AOD - or ambient mode - is showing. 2131 */ setDozing(boolean dozing)2132 public void setDozing(boolean dozing) { 2133 if (dozing == mDozing) { 2134 return; 2135 } 2136 mDozing = dozing; 2137 setShowingLocked(mShowing); 2138 } 2139 2140 /** 2141 * @param pulsing true when device temporarily wakes up to display an incoming notification. 2142 */ setPulsing(boolean pulsing)2143 public void setPulsing(boolean pulsing) { 2144 mPulsing = pulsing; 2145 } 2146 2147 private static class StartKeyguardExitAnimParams { 2148 2149 long startTime; 2150 long fadeoutDuration; 2151 StartKeyguardExitAnimParams(long startTime, long fadeoutDuration)2152 private StartKeyguardExitAnimParams(long startTime, long fadeoutDuration) { 2153 this.startTime = startTime; 2154 this.fadeoutDuration = fadeoutDuration; 2155 } 2156 } 2157 setShowingLocked(boolean showing)2158 private void setShowingLocked(boolean showing) { 2159 setShowingLocked(showing, false /* forceCallbacks */); 2160 } 2161 setShowingLocked(boolean showing, boolean forceCallbacks)2162 private void setShowingLocked(boolean showing, boolean forceCallbacks) { 2163 final boolean aodShowing = mDozing && !mWakeAndUnlocking; 2164 final boolean notifyDefaultDisplayCallbacks = showing != mShowing 2165 || aodShowing != mAodShowing || forceCallbacks; 2166 mShowing = showing; 2167 mAodShowing = aodShowing; 2168 if (notifyDefaultDisplayCallbacks) { 2169 notifyDefaultDisplayCallbacks(showing); 2170 updateActivityLockScreenState(showing, aodShowing); 2171 } 2172 } 2173 notifyDefaultDisplayCallbacks(boolean showing)2174 private void notifyDefaultDisplayCallbacks(boolean showing) { 2175 int size = mKeyguardStateCallbacks.size(); 2176 for (int i = size - 1; i >= 0; i--) { 2177 IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i); 2178 try { 2179 callback.onShowingStateChanged(showing); 2180 } catch (RemoteException e) { 2181 Slog.w(TAG, "Failed to call onShowingStateChanged", e); 2182 if (e instanceof DeadObjectException) { 2183 mKeyguardStateCallbacks.remove(callback); 2184 } 2185 } 2186 } 2187 updateInputRestrictedLocked(); 2188 mUiOffloadThread.submit(() -> { 2189 mTrustManager.reportKeyguardShowingChanged(); 2190 }); 2191 } 2192 notifyTrustedChangedLocked(boolean trusted)2193 private void notifyTrustedChangedLocked(boolean trusted) { 2194 int size = mKeyguardStateCallbacks.size(); 2195 for (int i = size - 1; i >= 0; i--) { 2196 try { 2197 mKeyguardStateCallbacks.get(i).onTrustedChanged(trusted); 2198 } catch (RemoteException e) { 2199 Slog.w(TAG, "Failed to call notifyTrustedChangedLocked", e); 2200 if (e instanceof DeadObjectException) { 2201 mKeyguardStateCallbacks.remove(i); 2202 } 2203 } 2204 } 2205 } 2206 notifyHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper)2207 private void notifyHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) { 2208 int size = mKeyguardStateCallbacks.size(); 2209 for (int i = size - 1; i >= 0; i--) { 2210 try { 2211 mKeyguardStateCallbacks.get(i).onHasLockscreenWallpaperChanged( 2212 hasLockscreenWallpaper); 2213 } catch (RemoteException e) { 2214 Slog.w(TAG, "Failed to call onHasLockscreenWallpaperChanged", e); 2215 if (e instanceof DeadObjectException) { 2216 mKeyguardStateCallbacks.remove(i); 2217 } 2218 } 2219 } 2220 } 2221 addStateMonitorCallback(IKeyguardStateCallback callback)2222 public void addStateMonitorCallback(IKeyguardStateCallback callback) { 2223 synchronized (this) { 2224 mKeyguardStateCallbacks.add(callback); 2225 try { 2226 callback.onSimSecureStateChanged(mUpdateMonitor.isSimPinSecure()); 2227 callback.onShowingStateChanged(mShowing); 2228 callback.onInputRestrictedStateChanged(mInputRestricted); 2229 callback.onTrustedChanged(mUpdateMonitor.getUserHasTrust( 2230 KeyguardUpdateMonitor.getCurrentUser())); 2231 callback.onHasLockscreenWallpaperChanged(mUpdateMonitor.hasLockscreenWallpaper()); 2232 } catch (RemoteException e) { 2233 Slog.w(TAG, "Failed to call to IKeyguardStateCallback", e); 2234 } 2235 } 2236 } 2237 2238 private static class DismissMessage { 2239 private final CharSequence mMessage; 2240 private final IKeyguardDismissCallback mCallback; 2241 DismissMessage(IKeyguardDismissCallback callback, CharSequence message)2242 DismissMessage(IKeyguardDismissCallback callback, CharSequence message) { 2243 mCallback = callback; 2244 mMessage = message; 2245 } 2246 getCallback()2247 public IKeyguardDismissCallback getCallback() { 2248 return mCallback; 2249 } 2250 getMessage()2251 public CharSequence getMessage() { 2252 return mMessage; 2253 } 2254 } 2255 } 2256