1 /* 2 * Copyright (C) 2007 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.internal.policy.impl; 18 19 import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT; 20 21 import com.android.internal.telephony.IccCard; 22 import com.android.internal.widget.LockPatternUtils; 23 24 import android.app.ActivityManagerNative; 25 import android.app.AlarmManager; 26 import android.app.PendingIntent; 27 import android.app.StatusBarManager; 28 import android.content.BroadcastReceiver; 29 import android.content.ContentResolver; 30 import android.content.Context; 31 import android.content.Intent; 32 import android.content.IntentFilter; 33 import android.media.AudioManager; 34 import android.media.SoundPool; 35 import android.os.Handler; 36 import android.os.LocalPowerManager; 37 import android.os.Message; 38 import android.os.PowerManager; 39 import android.os.RemoteException; 40 import android.os.SystemClock; 41 import android.os.SystemProperties; 42 import android.provider.Settings; 43 import android.telephony.TelephonyManager; 44 import android.util.EventLog; 45 import android.util.Log; 46 import android.view.KeyEvent; 47 import android.view.WindowManagerImpl; 48 import android.view.WindowManagerPolicy; 49 50 51 /** 52 * Mediates requests related to the keyguard. This includes queries about the 53 * state of the keyguard, power management events that effect whether the keyguard 54 * should be shown or reset, callbacks to the phone window manager to notify 55 * it of when the keyguard is showing, and events from the keyguard view itself 56 * stating that the keyguard was succesfully unlocked. 57 * 58 * Note that the keyguard view is shown when the screen is off (as appropriate) 59 * so that once the screen comes on, it will be ready immediately. 60 * 61 * Example queries about the keyguard: 62 * - is {movement, key} one that should wake the keygaurd? 63 * - is the keyguard showing? 64 * - are input events restricted due to the state of the keyguard? 65 * 66 * Callbacks to the phone window manager: 67 * - the keyguard is showing 68 * 69 * Example external events that translate to keyguard view changes: 70 * - screen turned off -> reset the keyguard, and show it so it will be ready 71 * next time the screen turns on 72 * - keyboard is slid open -> if the keyguard is not secure, hide it 73 * 74 * Events from the keyguard view: 75 * - user succesfully unlocked keyguard -> hide keyguard view, and no longer 76 * restrict input events. 77 * 78 * Note: in addition to normal power managment events that effect the state of 79 * whether the keyguard should be showing, external apps and services may request 80 * that the keyguard be disabled via {@link #setKeyguardEnabled(boolean)}. When 81 * false, this will override all other conditions for turning on the keyguard. 82 * 83 * Threading and synchronization: 84 * This class is created by the initialization routine of the {@link WindowManagerPolicy}, 85 * and runs on its thread. The keyguard UI is created from that thread in the 86 * constructor of this class. The apis may be called from other threads, including the 87 * {@link com.android.server.wm.InputManager}'s and {@link android.view.WindowManager}'s. 88 * Therefore, methods on this class are synchronized, and any action that is pointed 89 * directly to the keyguard UI is posted to a {@link Handler} to ensure it is taken on the UI 90 * thread of the keyguard. 91 */ 92 public class KeyguardViewMediator implements KeyguardViewCallback, 93 KeyguardUpdateMonitor.InfoCallback, KeyguardUpdateMonitor.SimStateCallback { 94 private static final int KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT = 30000; 95 private final static boolean DEBUG = false; 96 private final static boolean DBG_WAKE = false; 97 98 private final static String TAG = "KeyguardViewMediator"; 99 100 private static final String DELAYED_KEYGUARD_ACTION = 101 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD"; 102 103 // used for handler messages 104 private static final int TIMEOUT = 1; 105 private static final int SHOW = 2; 106 private static final int HIDE = 3; 107 private static final int RESET = 4; 108 private static final int VERIFY_UNLOCK = 5; 109 private static final int NOTIFY_SCREEN_OFF = 6; 110 private static final int NOTIFY_SCREEN_ON = 7; 111 private static final int WAKE_WHEN_READY = 8; 112 private static final int KEYGUARD_DONE = 9; 113 private static final int KEYGUARD_DONE_DRAWING = 10; 114 private static final int KEYGUARD_DONE_AUTHENTICATING = 11; 115 private static final int SET_HIDDEN = 12; 116 private static final int KEYGUARD_TIMEOUT = 13; 117 118 /** 119 * The default amount of time we stay awake (used for all key input) 120 */ 121 protected static final int AWAKE_INTERVAL_DEFAULT_MS = 10000; 122 123 124 /** 125 * The default amount of time we stay awake (used for all key input) when 126 * the keyboard is open 127 */ 128 protected static final int AWAKE_INTERVAL_DEFAULT_KEYBOARD_OPEN_MS = 10000; 129 130 /** 131 * How long to wait after the screen turns off due to timeout before 132 * turning on the keyguard (i.e, the user has this much time to turn 133 * the screen back on without having to face the keyguard). 134 */ 135 private static final int KEYGUARD_LOCK_AFTER_DELAY_DEFAULT = 5000; 136 137 /** 138 * How long we'll wait for the {@link KeyguardViewCallback#keyguardDoneDrawing()} 139 * callback before unblocking a call to {@link #setKeyguardEnabled(boolean)} 140 * that is reenabling the keyguard. 141 */ 142 private static final int KEYGUARD_DONE_DRAWING_TIMEOUT_MS = 2000; 143 144 /** 145 * Allow the user to expand the status bar when the keyguard is engaged 146 * (without a pattern or password). 147 */ 148 private static final boolean ENABLE_INSECURE_STATUS_BAR_EXPAND = true; 149 150 /** The stream type that the lock sounds are tied to. */ 151 private static final int MASTER_STREAM_TYPE = AudioManager.STREAM_RING; 152 /** Minimum volume for lock sounds, as a ratio of max MASTER_STREAM_TYPE */ 153 final float MIN_LOCK_VOLUME = 0.05f; 154 /** Maximum volume for lock sounds, as a ratio of max MASTER_STREAM_TYPE */ 155 final float MAX_LOCK_VOLUME = 0.4f; 156 157 private Context mContext; 158 private AlarmManager mAlarmManager; 159 private AudioManager mAudioManager; 160 private StatusBarManager mStatusBarManager; 161 private boolean mShowLockIcon; 162 private boolean mShowingLockIcon; 163 164 private boolean mSystemReady; 165 166 // Whether the next call to playSounds() should be skipped. Defaults to 167 // true because the first lock (on boot) should be silent. 168 private boolean mSuppressNextLockSound = true; 169 170 171 /** Low level access to the power manager for enableUserActivity. Having this 172 * requires that we run in the system process. */ 173 LocalPowerManager mRealPowerManager; 174 175 /** High level access to the power manager for WakeLocks */ 176 private PowerManager mPM; 177 178 /** 179 * Used to keep the device awake while the keyguard is showing, i.e for 180 * calls to {@link #pokeWakelock()} 181 */ 182 private PowerManager.WakeLock mWakeLock; 183 184 /** 185 * Used to keep the device awake while to ensure the keyguard finishes opening before 186 * we sleep. 187 */ 188 private PowerManager.WakeLock mShowKeyguardWakeLock; 189 190 /** 191 * Does not turn on screen, held while a call to {@link KeyguardViewManager#wakeWhenReadyTq(int)} 192 * is called to make sure the device doesn't sleep before it has a chance to poke 193 * the wake lock. 194 * @see #wakeWhenReadyLocked(int) 195 */ 196 private PowerManager.WakeLock mWakeAndHandOff; 197 198 private KeyguardViewManager mKeyguardViewManager; 199 200 // these are protected by synchronized (this) 201 202 /** 203 * External apps (like the phone app) can tell us to disable the keygaurd. 204 */ 205 private boolean mExternallyEnabled = true; 206 207 /** 208 * Remember if an external call to {@link #setKeyguardEnabled} with value 209 * false caused us to hide the keyguard, so that we need to reshow it once 210 * the keygaurd is reenabled with another call with value true. 211 */ 212 private boolean mNeedToReshowWhenReenabled = false; 213 214 // cached value of whether we are showing (need to know this to quickly 215 // answer whether the input should be restricted) 216 private boolean mShowing = false; 217 218 // true if the keyguard is hidden by another window 219 private boolean mHidden = false; 220 221 /** 222 * Helps remember whether the screen has turned on since the last time 223 * it turned off due to timeout. see {@link #onScreenTurnedOff(int)} 224 */ 225 private int mDelayedShowingSequence; 226 227 private int mWakelockSequence; 228 229 private PhoneWindowManager mCallback; 230 231 /** 232 * If the user has disabled the keyguard, then requests to exit, this is 233 * how we'll ultimately let them know whether it was successful. We use this 234 * var being non-null as an indicator that there is an in progress request. 235 */ 236 private WindowManagerPolicy.OnKeyguardExitResult mExitSecureCallback; 237 238 // the properties of the keyguard 239 private KeyguardViewProperties mKeyguardViewProperties; 240 241 private KeyguardUpdateMonitor mUpdateMonitor; 242 243 private boolean mKeyboardOpen = false; 244 245 private boolean mScreenOn = false; 246 247 // last known state of the cellular connection 248 private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE; 249 250 /** 251 * we send this intent when the keyguard is dismissed. 252 */ 253 private Intent mUserPresentIntent; 254 255 /** 256 * {@link #setKeyguardEnabled} waits on this condition when it reenables 257 * the keyguard. 258 */ 259 private boolean mWaitingUntilKeyguardVisible = false; 260 private LockPatternUtils mLockPatternUtils; 261 262 private SoundPool mLockSounds; 263 private int mLockSoundId; 264 private int mUnlockSoundId; 265 private int mLockSoundStreamId; 266 private int mMasterStreamMaxVolume; 267 KeyguardViewMediator(Context context, PhoneWindowManager callback, LocalPowerManager powerManager)268 public KeyguardViewMediator(Context context, PhoneWindowManager callback, 269 LocalPowerManager powerManager) { 270 mContext = context; 271 272 mRealPowerManager = powerManager; 273 mPM = (PowerManager) context.getSystemService(Context.POWER_SERVICE); 274 mWakeLock = mPM.newWakeLock( 275 PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, 276 "keyguard"); 277 mWakeLock.setReferenceCounted(false); 278 mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard"); 279 mShowKeyguardWakeLock.setReferenceCounted(false); 280 281 mWakeAndHandOff = mPM.newWakeLock( 282 PowerManager.PARTIAL_WAKE_LOCK, 283 "keyguardWakeAndHandOff"); 284 mWakeAndHandOff.setReferenceCounted(false); 285 286 IntentFilter filter = new IntentFilter(); 287 filter.addAction(DELAYED_KEYGUARD_ACTION); 288 filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); 289 context.registerReceiver(mBroadCastReceiver, filter); 290 mAlarmManager = (AlarmManager) context 291 .getSystemService(Context.ALARM_SERVICE); 292 mCallback = callback; 293 294 mUpdateMonitor = new KeyguardUpdateMonitor(context); 295 296 mUpdateMonitor.registerInfoCallback(this); 297 mUpdateMonitor.registerSimStateCallback(this); 298 299 mLockPatternUtils = new LockPatternUtils(mContext); 300 mKeyguardViewProperties 301 = new LockPatternKeyguardViewProperties(mLockPatternUtils, mUpdateMonitor); 302 303 mKeyguardViewManager = new KeyguardViewManager( 304 context, WindowManagerImpl.getDefault(), this, 305 mKeyguardViewProperties, mUpdateMonitor); 306 307 mUserPresentIntent = new Intent(Intent.ACTION_USER_PRESENT); 308 mUserPresentIntent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING 309 | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); 310 311 final ContentResolver cr = mContext.getContentResolver(); 312 mShowLockIcon = (Settings.System.getInt(cr, "show_status_bar_lock", 0) == 1); 313 314 mLockSounds = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0); 315 String soundPath = Settings.System.getString(cr, Settings.System.LOCK_SOUND); 316 if (soundPath != null) { 317 mLockSoundId = mLockSounds.load(soundPath, 1); 318 } 319 if (soundPath == null || mLockSoundId == 0) { 320 if (DEBUG) Log.d(TAG, "failed to load sound from " + soundPath); 321 } 322 soundPath = Settings.System.getString(cr, Settings.System.UNLOCK_SOUND); 323 if (soundPath != null) { 324 mUnlockSoundId = mLockSounds.load(soundPath, 1); 325 } 326 if (soundPath == null || mUnlockSoundId == 0) { 327 if (DEBUG) Log.d(TAG, "failed to load sound from " + soundPath); 328 } 329 } 330 331 /** 332 * Let us know that the system is ready after startup. 333 */ onSystemReady()334 public void onSystemReady() { 335 synchronized (this) { 336 if (DEBUG) Log.d(TAG, "onSystemReady"); 337 mSystemReady = true; 338 doKeyguardLocked(); 339 } 340 } 341 342 /** 343 * Called to let us know the screen was turned off. 344 * @param why either {@link WindowManagerPolicy#OFF_BECAUSE_OF_USER}, 345 * {@link WindowManagerPolicy#OFF_BECAUSE_OF_TIMEOUT} or 346 * {@link WindowManagerPolicy#OFF_BECAUSE_OF_PROX_SENSOR}. 347 */ onScreenTurnedOff(int why)348 public void onScreenTurnedOff(int why) { 349 synchronized (this) { 350 mScreenOn = false; 351 if (DEBUG) Log.d(TAG, "onScreenTurnedOff(" + why + ")"); 352 353 if (mExitSecureCallback != null) { 354 if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled"); 355 mExitSecureCallback.onKeyguardExitResult(false); 356 mExitSecureCallback = null; 357 if (!mExternallyEnabled) { 358 hideLocked(); 359 } 360 } else if (mShowing) { 361 notifyScreenOffLocked(); 362 resetStateLocked(); 363 } else if (why == WindowManagerPolicy.OFF_BECAUSE_OF_TIMEOUT) { 364 // if the screen turned off because of timeout, set an alarm 365 // to enable it a little bit later (i.e, give the user a chance 366 // to turn the screen back on within a certain window without 367 // having to unlock the screen) 368 final ContentResolver cr = mContext.getContentResolver(); 369 370 // From DisplaySettings 371 long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT, 372 KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT); 373 374 // From SecuritySettings 375 final long lockAfterTimeout = Settings.Secure.getInt(cr, 376 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, 377 KEYGUARD_LOCK_AFTER_DELAY_DEFAULT); 378 379 // From DevicePolicyAdmin 380 final long policyTimeout = mLockPatternUtils.getDevicePolicyManager() 381 .getMaximumTimeToLock(null); 382 383 long timeout; 384 if (policyTimeout > 0) { 385 // policy in effect. Make sure we don't go beyond policy limit. 386 displayTimeout = Math.max(displayTimeout, 0); // ignore negative values 387 timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout); 388 } else { 389 timeout = lockAfterTimeout; 390 } 391 392 if (timeout <= 0) { 393 // Lock now 394 mSuppressNextLockSound = true; 395 doKeyguardLocked(); 396 } else { 397 // Lock in the future 398 long when = SystemClock.elapsedRealtime() + timeout; 399 Intent intent = new Intent(DELAYED_KEYGUARD_ACTION); 400 intent.putExtra("seq", mDelayedShowingSequence); 401 PendingIntent sender = PendingIntent.getBroadcast(mContext, 402 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); 403 mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, 404 sender); 405 if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = " 406 + mDelayedShowingSequence); 407 } 408 } else if (why == WindowManagerPolicy.OFF_BECAUSE_OF_PROX_SENSOR) { 409 // Do not enable the keyguard if the prox sensor forced the screen off. 410 } else { 411 doKeyguardLocked(); 412 } 413 } 414 } 415 416 /** 417 * Let's us know the screen was turned on. 418 */ onScreenTurnedOn(KeyguardViewManager.ShowListener showListener)419 public void onScreenTurnedOn(KeyguardViewManager.ShowListener showListener) { 420 synchronized (this) { 421 mScreenOn = true; 422 mDelayedShowingSequence++; 423 if (DEBUG) Log.d(TAG, "onScreenTurnedOn, seq = " + mDelayedShowingSequence); 424 notifyScreenOnLocked(showListener); 425 } 426 } 427 428 /** 429 * Same semantics as {@link WindowManagerPolicy#enableKeyguard}; provide 430 * a way for external stuff to override normal keyguard behavior. For instance 431 * the phone app disables the keyguard when it receives incoming calls. 432 */ setKeyguardEnabled(boolean enabled)433 public void setKeyguardEnabled(boolean enabled) { 434 synchronized (this) { 435 if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")"); 436 437 438 mExternallyEnabled = enabled; 439 440 if (!enabled && mShowing) { 441 if (mExitSecureCallback != null) { 442 if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring"); 443 // we're in the process of handling a request to verify the user 444 // can get past the keyguard. ignore extraneous requests to disable / reenable 445 return; 446 } 447 448 // hiding keyguard that is showing, remember to reshow later 449 if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, " 450 + "disabling status bar expansion"); 451 mNeedToReshowWhenReenabled = true; 452 hideLocked(); 453 } else if (enabled && mNeedToReshowWhenReenabled) { 454 // reenabled after previously hidden, reshow 455 if (DEBUG) Log.d(TAG, "previously hidden, reshowing, reenabling " 456 + "status bar expansion"); 457 mNeedToReshowWhenReenabled = false; 458 459 if (mExitSecureCallback != null) { 460 if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting"); 461 mExitSecureCallback.onKeyguardExitResult(false); 462 mExitSecureCallback = null; 463 resetStateLocked(); 464 } else { 465 showLocked(); 466 467 // block until we know the keygaurd is done drawing (and post a message 468 // to unblock us after a timeout so we don't risk blocking too long 469 // and causing an ANR). 470 mWaitingUntilKeyguardVisible = true; 471 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING, KEYGUARD_DONE_DRAWING_TIMEOUT_MS); 472 if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false"); 473 while (mWaitingUntilKeyguardVisible) { 474 try { 475 wait(); 476 } catch (InterruptedException e) { 477 Thread.currentThread().interrupt(); 478 } 479 } 480 if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible"); 481 } 482 } 483 } 484 } 485 486 /** 487 * @see android.app.KeyguardManager#exitKeyguardSecurely 488 */ verifyUnlock(WindowManagerPolicy.OnKeyguardExitResult callback)489 public void verifyUnlock(WindowManagerPolicy.OnKeyguardExitResult callback) { 490 synchronized (this) { 491 if (DEBUG) Log.d(TAG, "verifyUnlock"); 492 if (!mUpdateMonitor.isDeviceProvisioned()) { 493 // don't allow this api when the device isn't provisioned 494 if (DEBUG) Log.d(TAG, "ignoring because device isn't provisioned"); 495 callback.onKeyguardExitResult(false); 496 } else if (mExternallyEnabled) { 497 // this only applies when the user has externally disabled the 498 // keyguard. this is unexpected and means the user is not 499 // using the api properly. 500 Log.w(TAG, "verifyUnlock called when not externally disabled"); 501 callback.onKeyguardExitResult(false); 502 } else if (mExitSecureCallback != null) { 503 // already in progress with someone else 504 callback.onKeyguardExitResult(false); 505 } else { 506 mExitSecureCallback = callback; 507 verifyUnlockLocked(); 508 } 509 } 510 } 511 512 /** 513 * Is the keyguard currently showing? 514 */ isShowing()515 public boolean isShowing() { 516 return mShowing; 517 } 518 519 /** 520 * Is the keyguard currently showing and not being force hidden? 521 */ isShowingAndNotHidden()522 public boolean isShowingAndNotHidden() { 523 return mShowing && !mHidden; 524 } 525 526 /** 527 * Notify us when the keyguard is hidden by another window 528 */ setHidden(boolean isHidden)529 public void setHidden(boolean isHidden) { 530 if (DEBUG) Log.d(TAG, "setHidden " + isHidden); 531 mHandler.removeMessages(SET_HIDDEN); 532 Message msg = mHandler.obtainMessage(SET_HIDDEN, (isHidden ? 1 : 0), 0); 533 mHandler.sendMessage(msg); 534 } 535 536 /** 537 * Handles SET_HIDDEN message sent by setHidden() 538 */ handleSetHidden(boolean isHidden)539 private void handleSetHidden(boolean isHidden) { 540 synchronized (KeyguardViewMediator.this) { 541 if (mHidden != isHidden) { 542 mHidden = isHidden; 543 adjustUserActivityLocked(); 544 adjustStatusBarLocked(); 545 } 546 } 547 } 548 549 /** 550 * Used by PhoneWindowManager to enable the keyguard due to a user activity timeout. 551 * This must be safe to call from any thread and with any window manager locks held. 552 */ doKeyguardTimeout()553 public void doKeyguardTimeout() { 554 mHandler.removeMessages(KEYGUARD_TIMEOUT); 555 Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT); 556 mHandler.sendMessage(msg); 557 } 558 559 /** 560 * Given the state of the keyguard, is the input restricted? 561 * Input is restricted when the keyguard is showing, or when the keyguard 562 * was suppressed by an app that disabled the keyguard or we haven't been provisioned yet. 563 */ isInputRestricted()564 public boolean isInputRestricted() { 565 return mShowing || mNeedToReshowWhenReenabled || !mUpdateMonitor.isDeviceProvisioned(); 566 } 567 568 /** 569 * Returns true if the change is resulting in the keyguard beign dismissed, 570 * meaning the screen can turn on immediately. Otherwise returns false. 571 */ doLidChangeTq(boolean isLidOpen)572 public boolean doLidChangeTq(boolean isLidOpen) { 573 mKeyboardOpen = isLidOpen; 574 575 if (mUpdateMonitor.isKeyguardBypassEnabled() && mKeyboardOpen 576 && !mKeyguardViewProperties.isSecure() && mKeyguardViewManager.isShowing()) { 577 if (DEBUG) Log.d(TAG, "bypassing keyguard on sliding open of keyboard with non-secure keyguard"); 578 mHandler.sendEmptyMessage(KEYGUARD_DONE_AUTHENTICATING); 579 return true; 580 } 581 return false; 582 } 583 584 /** 585 * Enable the keyguard if the settings are appropriate. Return true if all 586 * work that will happen is done; returns false if the caller can wait for 587 * the keyguard to be shown. 588 */ doKeyguardLocked()589 private void doKeyguardLocked() { 590 // if another app is disabling us, don't show 591 if (!mExternallyEnabled) { 592 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled"); 593 594 // note: we *should* set mNeedToReshowWhenReenabled=true here, but that makes 595 // for an occasional ugly flicker in this situation: 596 // 1) receive a call with the screen on (no keyguard) or make a call 597 // 2) screen times out 598 // 3) user hits key to turn screen back on 599 // instead, we reenable the keyguard when we know the screen is off and the call 600 // ends (see the broadcast receiver below) 601 // TODO: clean this up when we have better support at the window manager level 602 // for apps that wish to be on top of the keyguard 603 return; 604 } 605 606 // if the keyguard is already showing, don't bother 607 if (mKeyguardViewManager.isShowing()) { 608 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing"); 609 return; 610 } 611 612 // if the setup wizard hasn't run yet, don't show 613 final boolean requireSim = !SystemProperties.getBoolean("keyguard.no_require_sim", 614 false); 615 final boolean provisioned = mUpdateMonitor.isDeviceProvisioned(); 616 final IccCard.State state = mUpdateMonitor.getSimState(); 617 final boolean lockedOrMissing = state.isPinLocked() 618 || ((state == IccCard.State.ABSENT 619 || state == IccCard.State.PERM_DISABLED) 620 && requireSim); 621 622 if (!lockedOrMissing && !provisioned) { 623 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned" 624 + " and the sim is not locked or missing"); 625 return; 626 } 627 628 if (mLockPatternUtils.isLockScreenDisabled() && !lockedOrMissing) { 629 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off"); 630 return; 631 } 632 633 if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen"); 634 showLocked(); 635 } 636 637 /** 638 * Send message to keyguard telling it to reset its state. 639 * @see #handleReset() 640 */ resetStateLocked()641 private void resetStateLocked() { 642 if (DEBUG) Log.d(TAG, "resetStateLocked"); 643 Message msg = mHandler.obtainMessage(RESET); 644 mHandler.sendMessage(msg); 645 } 646 647 /** 648 * Send message to keyguard telling it to verify unlock 649 * @see #handleVerifyUnlock() 650 */ verifyUnlockLocked()651 private void verifyUnlockLocked() { 652 if (DEBUG) Log.d(TAG, "verifyUnlockLocked"); 653 mHandler.sendEmptyMessage(VERIFY_UNLOCK); 654 } 655 656 657 /** 658 * Send a message to keyguard telling it the screen just turned on. 659 * @see #onScreenTurnedOff(int) 660 * @see #handleNotifyScreenOff 661 */ notifyScreenOffLocked()662 private void notifyScreenOffLocked() { 663 if (DEBUG) Log.d(TAG, "notifyScreenOffLocked"); 664 mHandler.sendEmptyMessage(NOTIFY_SCREEN_OFF); 665 } 666 667 /** 668 * Send a message to keyguard telling it the screen just turned on. 669 * @see #onScreenTurnedOn() 670 * @see #handleNotifyScreenOn 671 */ notifyScreenOnLocked(KeyguardViewManager.ShowListener showListener)672 private void notifyScreenOnLocked(KeyguardViewManager.ShowListener showListener) { 673 if (DEBUG) Log.d(TAG, "notifyScreenOnLocked"); 674 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_ON, showListener); 675 mHandler.sendMessage(msg); 676 } 677 678 /** 679 * Send message to keyguard telling it about a wake key so it can adjust 680 * its state accordingly and then poke the wake lock when it is ready. 681 * @param keyCode The wake key. 682 * @see #handleWakeWhenReady 683 * @see #onWakeKeyWhenKeyguardShowingTq(int) 684 */ wakeWhenReadyLocked(int keyCode)685 private void wakeWhenReadyLocked(int keyCode) { 686 if (DBG_WAKE) Log.d(TAG, "wakeWhenReadyLocked(" + keyCode + ")"); 687 688 /** 689 * acquire the handoff lock that will keep the cpu running. this will 690 * be released once the keyguard has set itself up and poked the other wakelock 691 * in {@link #handleWakeWhenReady(int)} 692 */ 693 mWakeAndHandOff.acquire(); 694 695 Message msg = mHandler.obtainMessage(WAKE_WHEN_READY, keyCode, 0); 696 mHandler.sendMessage(msg); 697 } 698 699 /** 700 * Send message to keyguard telling it to show itself 701 * @see #handleShow() 702 */ showLocked()703 private void showLocked() { 704 if (DEBUG) Log.d(TAG, "showLocked"); 705 // ensure we stay awake until we are finished displaying the keyguard 706 mShowKeyguardWakeLock.acquire(); 707 Message msg = mHandler.obtainMessage(SHOW); 708 mHandler.sendMessage(msg); 709 } 710 711 /** 712 * Send message to keyguard telling it to hide itself 713 * @see #handleHide() 714 */ hideLocked()715 private void hideLocked() { 716 if (DEBUG) Log.d(TAG, "hideLocked"); 717 Message msg = mHandler.obtainMessage(HIDE); 718 mHandler.sendMessage(msg); 719 } 720 721 /** {@inheritDoc} */ onSimStateChanged(IccCard.State simState)722 public void onSimStateChanged(IccCard.State simState) { 723 if (DEBUG) Log.d(TAG, "onSimStateChanged: " + simState); 724 725 switch (simState) { 726 case ABSENT: 727 // only force lock screen in case of missing sim if user hasn't 728 // gone through setup wizard 729 synchronized (this) { 730 if (!mUpdateMonitor.isDeviceProvisioned()) { 731 if (!isShowing()) { 732 if (DEBUG) Log.d(TAG, "ICC_ABSENT isn't showing," 733 + " we need to show the keyguard since the " 734 + "device isn't provisioned yet."); 735 doKeyguardLocked(); 736 } else { 737 resetStateLocked(); 738 } 739 } 740 } 741 break; 742 case PIN_REQUIRED: 743 case PUK_REQUIRED: 744 synchronized (this) { 745 if (!isShowing()) { 746 if (DEBUG) Log.d(TAG, "INTENT_VALUE_ICC_LOCKED and keygaurd isn't showing, we need " 747 + "to show the keyguard so the user can enter their sim pin"); 748 doKeyguardLocked(); 749 } else { 750 resetStateLocked(); 751 } 752 } 753 break; 754 case PERM_DISABLED: 755 synchronized (this) { 756 if (!isShowing()) { 757 if (DEBUG) Log.d(TAG, "PERM_DISABLED and " 758 + "keygaurd isn't showing."); 759 doKeyguardLocked(); 760 } else { 761 if (DEBUG) Log.d(TAG, "PERM_DISABLED, resetStateLocked to" 762 + "show permanently disabled message in lockscreen."); 763 resetStateLocked(); 764 } 765 } 766 break; 767 case READY: 768 synchronized (this) { 769 if (isShowing()) { 770 resetStateLocked(); 771 } 772 } 773 break; 774 } 775 } 776 isSecure()777 public boolean isSecure() { 778 return mKeyguardViewProperties.isSecure(); 779 } 780 781 private BroadcastReceiver mBroadCastReceiver = new BroadcastReceiver() { 782 @Override 783 public void onReceive(Context context, Intent intent) { 784 final String action = intent.getAction(); 785 if (action.equals(DELAYED_KEYGUARD_ACTION)) { 786 787 int sequence = intent.getIntExtra("seq", 0); 788 789 if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = " 790 + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence); 791 792 synchronized (KeyguardViewMediator.this) { 793 if (mDelayedShowingSequence == sequence) { 794 // Don't play lockscreen SFX if the screen went off due to 795 // timeout. 796 mSuppressNextLockSound = true; 797 798 doKeyguardLocked(); 799 } 800 } 801 } else if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(action)) { 802 mPhoneState = intent.getStringExtra(TelephonyManager.EXTRA_STATE); 803 804 synchronized (KeyguardViewMediator.this) { 805 if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState) // call ending 806 && !mScreenOn // screen off 807 && mExternallyEnabled) { // not disabled by any app 808 809 // note: this is a way to gracefully reenable the keyguard when the call 810 // ends and the screen is off without always reenabling the keyguard 811 // each time the screen turns off while in call (and having an occasional ugly 812 // flicker while turning back on the screen and disabling the keyguard again). 813 if (DEBUG) Log.d(TAG, "screen is off and call ended, let's make sure the " 814 + "keyguard is showing"); 815 doKeyguardLocked(); 816 } 817 } 818 } 819 } 820 }; 821 822 823 /** 824 * When a key is received when the screen is off and the keyguard is showing, 825 * we need to decide whether to actually turn on the screen, and if so, tell 826 * the keyguard to prepare itself and poke the wake lock when it is ready. 827 * 828 * The 'Tq' suffix is per the documentation in {@link WindowManagerPolicy}. 829 * Be sure not to take any action that takes a long time; any significant 830 * action should be posted to a handler. 831 * 832 * @param keyCode The keycode of the key that woke the device 833 * @return Whether we poked the wake lock (and turned the screen on) 834 */ onWakeKeyWhenKeyguardShowingTq(int keyCode)835 public boolean onWakeKeyWhenKeyguardShowingTq(int keyCode) { 836 if (DEBUG) Log.d(TAG, "onWakeKeyWhenKeyguardShowing(" + keyCode + ")"); 837 838 if (isWakeKeyWhenKeyguardShowing(keyCode)) { 839 // give the keyguard view manager a chance to adjust the state of the 840 // keyguard based on the key that woke the device before poking 841 // the wake lock 842 wakeWhenReadyLocked(keyCode); 843 return true; 844 } else { 845 return false; 846 } 847 } 848 isWakeKeyWhenKeyguardShowing(int keyCode)849 private boolean isWakeKeyWhenKeyguardShowing(int keyCode) { 850 switch (keyCode) { 851 case KeyEvent.KEYCODE_VOLUME_UP: 852 case KeyEvent.KEYCODE_VOLUME_DOWN: 853 case KeyEvent.KEYCODE_VOLUME_MUTE: 854 case KeyEvent.KEYCODE_MUTE: 855 case KeyEvent.KEYCODE_HEADSETHOOK: 856 case KeyEvent.KEYCODE_MEDIA_PLAY: 857 case KeyEvent.KEYCODE_MEDIA_PAUSE: 858 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: 859 case KeyEvent.KEYCODE_MEDIA_STOP: 860 case KeyEvent.KEYCODE_MEDIA_NEXT: 861 case KeyEvent.KEYCODE_MEDIA_PREVIOUS: 862 case KeyEvent.KEYCODE_MEDIA_REWIND: 863 case KeyEvent.KEYCODE_MEDIA_RECORD: 864 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: 865 case KeyEvent.KEYCODE_CAMERA: 866 return false; 867 } 868 return true; 869 } 870 871 /** 872 * When a wake motion such as an external mouse movement is received when the screen 873 * is off and the keyguard is showing, we need to decide whether to actually turn 874 * on the screen, and if so, tell the keyguard to prepare itself and poke the wake 875 * lock when it is ready. 876 * 877 * The 'Tq' suffix is per the documentation in {@link WindowManagerPolicy}. 878 * Be sure not to take any action that takes a long time; any significant 879 * action should be posted to a handler. 880 * 881 * @return Whether we poked the wake lock (and turned the screen on) 882 */ onWakeMotionWhenKeyguardShowingTq()883 public boolean onWakeMotionWhenKeyguardShowingTq() { 884 if (DEBUG) Log.d(TAG, "onWakeMotionWhenKeyguardShowing()"); 885 886 // give the keyguard view manager a chance to adjust the state of the 887 // keyguard based on the key that woke the device before poking 888 // the wake lock 889 wakeWhenReadyLocked(KeyEvent.KEYCODE_UNKNOWN); 890 return true; 891 } 892 893 /** 894 * Callbacks from {@link KeyguardViewManager}. 895 */ 896 897 /** {@inheritDoc} */ pokeWakelock()898 public void pokeWakelock() { 899 pokeWakelock(mKeyboardOpen ? 900 AWAKE_INTERVAL_DEFAULT_KEYBOARD_OPEN_MS : AWAKE_INTERVAL_DEFAULT_MS); 901 } 902 903 /** {@inheritDoc} */ pokeWakelock(int holdMs)904 public void pokeWakelock(int holdMs) { 905 synchronized (this) { 906 if (DBG_WAKE) Log.d(TAG, "pokeWakelock(" + holdMs + ")"); 907 mWakeLock.acquire(); 908 mHandler.removeMessages(TIMEOUT); 909 mWakelockSequence++; 910 Message msg = mHandler.obtainMessage(TIMEOUT, mWakelockSequence, 0); 911 mHandler.sendMessageDelayed(msg, holdMs); 912 } 913 } 914 915 /** 916 * {@inheritDoc} 917 * 918 * @see #handleKeyguardDone 919 */ keyguardDone(boolean authenticated)920 public void keyguardDone(boolean authenticated) { 921 keyguardDone(authenticated, true); 922 } 923 keyguardDone(boolean authenticated, boolean wakeup)924 public void keyguardDone(boolean authenticated, boolean wakeup) { 925 synchronized (this) { 926 EventLog.writeEvent(70000, 2); 927 if (DEBUG) Log.d(TAG, "keyguardDone(" + authenticated + ")"); 928 Message msg = mHandler.obtainMessage(KEYGUARD_DONE); 929 msg.arg1 = wakeup ? 1 : 0; 930 mHandler.sendMessage(msg); 931 932 if (authenticated) { 933 mUpdateMonitor.clearFailedAttempts(); 934 } 935 936 if (mExitSecureCallback != null) { 937 mExitSecureCallback.onKeyguardExitResult(authenticated); 938 mExitSecureCallback = null; 939 940 if (authenticated) { 941 // after succesfully exiting securely, no need to reshow 942 // the keyguard when they've released the lock 943 mExternallyEnabled = true; 944 mNeedToReshowWhenReenabled = false; 945 } 946 } 947 } 948 } 949 950 /** 951 * {@inheritDoc} 952 * 953 * @see #handleKeyguardDoneDrawing 954 */ keyguardDoneDrawing()955 public void keyguardDoneDrawing() { 956 mHandler.sendEmptyMessage(KEYGUARD_DONE_DRAWING); 957 } 958 959 /** 960 * This handler will be associated with the policy thread, which will also 961 * be the UI thread of the keyguard. Since the apis of the policy, and therefore 962 * this class, can be called by other threads, any action that directly 963 * interacts with the keyguard ui should be posted to this handler, rather 964 * than called directly. 965 */ 966 private Handler mHandler = new Handler() { 967 @Override 968 public void handleMessage(Message msg) { 969 switch (msg.what) { 970 case TIMEOUT: 971 handleTimeout(msg.arg1); 972 return ; 973 case SHOW: 974 handleShow(); 975 return ; 976 case HIDE: 977 handleHide(); 978 return ; 979 case RESET: 980 handleReset(); 981 return ; 982 case VERIFY_UNLOCK: 983 handleVerifyUnlock(); 984 return; 985 case NOTIFY_SCREEN_OFF: 986 handleNotifyScreenOff(); 987 return; 988 case NOTIFY_SCREEN_ON: 989 handleNotifyScreenOn((KeyguardViewManager.ShowListener)msg.obj); 990 return; 991 case WAKE_WHEN_READY: 992 handleWakeWhenReady(msg.arg1); 993 return; 994 case KEYGUARD_DONE: 995 handleKeyguardDone(msg.arg1 != 0); 996 return; 997 case KEYGUARD_DONE_DRAWING: 998 handleKeyguardDoneDrawing(); 999 return; 1000 case KEYGUARD_DONE_AUTHENTICATING: 1001 keyguardDone(true); 1002 return; 1003 case SET_HIDDEN: 1004 handleSetHidden(msg.arg1 != 0); 1005 break; 1006 case KEYGUARD_TIMEOUT: 1007 synchronized (KeyguardViewMediator.this) { 1008 doKeyguardLocked(); 1009 } 1010 break; 1011 } 1012 } 1013 }; 1014 1015 /** 1016 * @see #keyguardDone 1017 * @see #KEYGUARD_DONE 1018 */ handleKeyguardDone(boolean wakeup)1019 private void handleKeyguardDone(boolean wakeup) { 1020 if (DEBUG) Log.d(TAG, "handleKeyguardDone"); 1021 handleHide(); 1022 if (wakeup) { 1023 mPM.userActivity(SystemClock.uptimeMillis(), true); 1024 } 1025 mWakeLock.release(); 1026 mContext.sendBroadcast(mUserPresentIntent); 1027 } 1028 1029 /** 1030 * @see #keyguardDoneDrawing 1031 * @see #KEYGUARD_DONE_DRAWING 1032 */ handleKeyguardDoneDrawing()1033 private void handleKeyguardDoneDrawing() { 1034 synchronized(this) { 1035 if (false) Log.d(TAG, "handleKeyguardDoneDrawing"); 1036 if (mWaitingUntilKeyguardVisible) { 1037 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing: notifying mWaitingUntilKeyguardVisible"); 1038 mWaitingUntilKeyguardVisible = false; 1039 notifyAll(); 1040 1041 // there will usually be two of these sent, one as a timeout, and one 1042 // as a result of the callback, so remove any remaining messages from 1043 // the queue 1044 mHandler.removeMessages(KEYGUARD_DONE_DRAWING); 1045 } 1046 } 1047 } 1048 1049 /** 1050 * Handles the message sent by {@link #pokeWakelock} 1051 * @param seq used to determine if anything has changed since the message 1052 * was sent. 1053 * @see #TIMEOUT 1054 */ handleTimeout(int seq)1055 private void handleTimeout(int seq) { 1056 synchronized (KeyguardViewMediator.this) { 1057 if (DEBUG) Log.d(TAG, "handleTimeout"); 1058 if (seq == mWakelockSequence) { 1059 mWakeLock.release(); 1060 } 1061 } 1062 } 1063 playSounds(boolean locked)1064 private void playSounds(boolean locked) { 1065 // User feedback for keyguard. 1066 1067 if (mSuppressNextLockSound) { 1068 mSuppressNextLockSound = false; 1069 return; 1070 } 1071 1072 final ContentResolver cr = mContext.getContentResolver(); 1073 if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) { 1074 final int whichSound = locked 1075 ? mLockSoundId 1076 : mUnlockSoundId; 1077 mLockSounds.stop(mLockSoundStreamId); 1078 // Init mAudioManager 1079 if (mAudioManager == null) { 1080 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); 1081 if (mAudioManager == null) return; 1082 mMasterStreamMaxVolume = mAudioManager.getStreamMaxVolume(MASTER_STREAM_TYPE); 1083 } 1084 // If the stream is muted, don't play the sound 1085 if (mAudioManager.isStreamMute(MASTER_STREAM_TYPE)) return; 1086 1087 // Adjust the lock sound volume from a minimum of MIN_LOCK_VOLUME to a maximum 1088 // of MAX_LOCK_VOLUME, relative to the maximum level of the MASTER_STREAM_TYPE volume. 1089 float lockSoundVolume; 1090 int masterStreamVolume = mAudioManager.getStreamVolume(MASTER_STREAM_TYPE); 1091 if (masterStreamVolume == 0) { 1092 return; 1093 } else { 1094 lockSoundVolume = MIN_LOCK_VOLUME + (MAX_LOCK_VOLUME - MIN_LOCK_VOLUME) 1095 * ((float) masterStreamVolume / mMasterStreamMaxVolume); 1096 } 1097 1098 mLockSoundStreamId = mLockSounds.play(whichSound, lockSoundVolume, lockSoundVolume, 1, 1099 0, 1.0f); 1100 } 1101 } 1102 1103 /** 1104 * Handle message sent by {@link #showLocked}. 1105 * @see #SHOW 1106 */ handleShow()1107 private void handleShow() { 1108 synchronized (KeyguardViewMediator.this) { 1109 if (DEBUG) Log.d(TAG, "handleShow"); 1110 if (!mSystemReady) return; 1111 1112 mKeyguardViewManager.show(); 1113 mShowing = true; 1114 adjustUserActivityLocked(); 1115 adjustStatusBarLocked(); 1116 try { 1117 ActivityManagerNative.getDefault().closeSystemDialogs("lock"); 1118 } catch (RemoteException e) { 1119 } 1120 1121 // Do this at the end to not slow down display of the keyguard. 1122 playSounds(true); 1123 1124 mShowKeyguardWakeLock.release(); 1125 } 1126 } 1127 1128 /** 1129 * Handle message sent by {@link #hideLocked()} 1130 * @see #HIDE 1131 */ handleHide()1132 private void handleHide() { 1133 synchronized (KeyguardViewMediator.this) { 1134 if (DEBUG) Log.d(TAG, "handleHide"); 1135 if (mWakeAndHandOff.isHeld()) { 1136 Log.w(TAG, "attempt to hide the keyguard while waking, ignored"); 1137 return; 1138 } 1139 1140 // only play "unlock" noises if not on a call (since the incall UI 1141 // disables the keyguard) 1142 if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState)) { 1143 playSounds(false); 1144 } 1145 1146 mKeyguardViewManager.hide(); 1147 mShowing = false; 1148 adjustUserActivityLocked(); 1149 adjustStatusBarLocked(); 1150 } 1151 } 1152 adjustUserActivityLocked()1153 private void adjustUserActivityLocked() { 1154 // disable user activity if we are shown and not hidden 1155 if (DEBUG) Log.d(TAG, "adjustUserActivityLocked mShowing: " + mShowing + " mHidden: " + mHidden); 1156 boolean enabled = !mShowing || mHidden; 1157 mRealPowerManager.enableUserActivity(enabled); 1158 if (!enabled && mScreenOn) { 1159 // reinstate our short screen timeout policy 1160 pokeWakelock(); 1161 } 1162 } 1163 adjustStatusBarLocked()1164 private void adjustStatusBarLocked() { 1165 if (mStatusBarManager == null) { 1166 mStatusBarManager = (StatusBarManager) 1167 mContext.getSystemService(Context.STATUS_BAR_SERVICE); 1168 } 1169 if (mStatusBarManager == null) { 1170 Log.w(TAG, "Could not get status bar manager"); 1171 } else { 1172 if (mShowLockIcon) { 1173 // Give feedback to user when secure keyguard is active and engaged 1174 if (mShowing && isSecure()) { 1175 if (!mShowingLockIcon) { 1176 String contentDescription = mContext.getString( 1177 com.android.internal.R.string.status_bar_device_locked); 1178 mStatusBarManager.setIcon("secure", 1179 com.android.internal.R.drawable.stat_sys_secure, 0, 1180 contentDescription); 1181 mShowingLockIcon = true; 1182 } 1183 } else { 1184 if (mShowingLockIcon) { 1185 mStatusBarManager.removeIcon("secure"); 1186 mShowingLockIcon = false; 1187 } 1188 } 1189 } 1190 1191 // Disable aspects of the system/status/navigation bars that must not be re-enabled by 1192 // windows that appear on top, ever 1193 int flags = StatusBarManager.DISABLE_NONE; 1194 if (mShowing) { 1195 // disable navigation status bar components (home, recents) if lock screen is up 1196 flags |= StatusBarManager.DISABLE_RECENT; 1197 if (isSecure() || !ENABLE_INSECURE_STATUS_BAR_EXPAND) { 1198 // showing secure lockscreen; disable expanding. 1199 flags |= StatusBarManager.DISABLE_EXPAND; 1200 } 1201 if (isSecure()) { 1202 // showing secure lockscreen; disable ticker. 1203 flags |= StatusBarManager.DISABLE_NOTIFICATION_TICKER; 1204 } 1205 } 1206 1207 if (DEBUG) { 1208 Log.d(TAG, "adjustStatusBarLocked: mShowing=" + mShowing + " mHidden=" + mHidden 1209 + " isSecure=" + isSecure() + " --> flags=0x" + Integer.toHexString(flags)); 1210 } 1211 1212 mStatusBarManager.disable(flags); 1213 } 1214 } 1215 1216 /** 1217 * Handle message sent by {@link #wakeWhenReadyLocked(int)} 1218 * @param keyCode The key that woke the device. 1219 * @see #WAKE_WHEN_READY 1220 */ handleWakeWhenReady(int keyCode)1221 private void handleWakeWhenReady(int keyCode) { 1222 synchronized (KeyguardViewMediator.this) { 1223 if (DBG_WAKE) Log.d(TAG, "handleWakeWhenReady(" + keyCode + ")"); 1224 1225 // this should result in a call to 'poke wakelock' which will set a timeout 1226 // on releasing the wakelock 1227 if (!mKeyguardViewManager.wakeWhenReadyTq(keyCode)) { 1228 // poke wakelock ourselves if keyguard is no longer active 1229 Log.w(TAG, "mKeyguardViewManager.wakeWhenReadyTq did not poke wake lock, so poke it ourselves"); 1230 pokeWakelock(); 1231 } 1232 1233 /** 1234 * Now that the keyguard is ready and has poked the wake lock, we can 1235 * release the handoff wakelock 1236 */ 1237 mWakeAndHandOff.release(); 1238 1239 if (!mWakeLock.isHeld()) { 1240 Log.w(TAG, "mWakeLock not held in mKeyguardViewManager.wakeWhenReadyTq"); 1241 } 1242 } 1243 } 1244 1245 /** 1246 * Handle message sent by {@link #resetStateLocked()} 1247 * @see #RESET 1248 */ handleReset()1249 private void handleReset() { 1250 synchronized (KeyguardViewMediator.this) { 1251 if (DEBUG) Log.d(TAG, "handleReset"); 1252 mKeyguardViewManager.reset(); 1253 } 1254 } 1255 1256 /** 1257 * Handle message sent by {@link #verifyUnlock} 1258 * @see #RESET 1259 */ handleVerifyUnlock()1260 private void handleVerifyUnlock() { 1261 synchronized (KeyguardViewMediator.this) { 1262 if (DEBUG) Log.d(TAG, "handleVerifyUnlock"); 1263 mKeyguardViewManager.verifyUnlock(); 1264 mShowing = true; 1265 } 1266 } 1267 1268 /** 1269 * Handle message sent by {@link #notifyScreenOffLocked()} 1270 * @see #NOTIFY_SCREEN_OFF 1271 */ handleNotifyScreenOff()1272 private void handleNotifyScreenOff() { 1273 synchronized (KeyguardViewMediator.this) { 1274 if (DEBUG) Log.d(TAG, "handleNotifyScreenOff"); 1275 mKeyguardViewManager.onScreenTurnedOff(); 1276 } 1277 } 1278 1279 /** 1280 * Handle message sent by {@link #notifyScreenOnLocked()} 1281 * @see #NOTIFY_SCREEN_ON 1282 */ handleNotifyScreenOn(KeyguardViewManager.ShowListener showListener)1283 private void handleNotifyScreenOn(KeyguardViewManager.ShowListener showListener) { 1284 synchronized (KeyguardViewMediator.this) { 1285 if (DEBUG) Log.d(TAG, "handleNotifyScreenOn"); 1286 mKeyguardViewManager.onScreenTurnedOn(showListener); 1287 } 1288 } 1289 1290 /** {@inheritDoc} */ onClockVisibilityChanged()1291 public void onClockVisibilityChanged() { 1292 adjustStatusBarLocked(); 1293 } 1294 1295 /** {@inheritDoc} */ onPhoneStateChanged(int phoneState)1296 public void onPhoneStateChanged(int phoneState) { 1297 // ignored 1298 } 1299 1300 /** {@inheritDoc} */ onRefreshBatteryInfo(boolean showBatteryInfo, boolean pluggedIn, int batteryLevel)1301 public void onRefreshBatteryInfo(boolean showBatteryInfo, boolean pluggedIn, int batteryLevel) { 1302 // ignored 1303 } 1304 1305 /** {@inheritDoc} */ onRefreshCarrierInfo(CharSequence plmn, CharSequence spn)1306 public void onRefreshCarrierInfo(CharSequence plmn, CharSequence spn) { 1307 // ignored 1308 } 1309 1310 /** {@inheritDoc} */ onRingerModeChanged(int state)1311 public void onRingerModeChanged(int state) { 1312 // ignored 1313 } 1314 1315 /** {@inheritDoc} */ onTimeChanged()1316 public void onTimeChanged() { 1317 // ignored 1318 } 1319 1320 /** {@inheritDoc} */ onDeviceProvisioned()1321 public void onDeviceProvisioned() { 1322 mContext.sendBroadcast(mUserPresentIntent); 1323 } 1324 } 1325