The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 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 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 17 | package com.android.keyguard; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 18 | |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 19 | import com.android.internal.policy.IKeyguardExitCallback; |
| 20 | import com.android.internal.policy.IKeyguardShowCallback; |
Jim Miller | bc4603b | 2010-08-30 21:21:34 -0700 | [diff] [blame] | 21 | import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT; |
| 22 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 23 | import android.app.Activity; |
Dianne Hackborn | 4994c66 | 2009-09-23 22:21:23 -0700 | [diff] [blame] | 24 | import android.app.ActivityManagerNative; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 25 | import android.app.AlarmManager; |
| 26 | import android.app.PendingIntent; |
John Spurlock | 43d8451 | 2012-11-09 10:27:33 -0500 | [diff] [blame] | 27 | import android.app.SearchManager; |
Mike Lockwood | 5f892c1 | 2009-11-19 23:39:13 -0500 | [diff] [blame] | 28 | import android.app.StatusBarManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 29 | import android.content.BroadcastReceiver; |
Daniel Sandler | db783bd | 2010-02-11 15:27:37 -0500 | [diff] [blame] | 30 | import android.content.ContentResolver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 31 | import android.content.Context; |
| 32 | import android.content.Intent; |
| 33 | import android.content.IntentFilter; |
Daniel Sandler | aec967a | 2010-02-20 01:05:22 -0500 | [diff] [blame] | 34 | import android.media.AudioManager; |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 35 | import android.media.SoundPool; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 36 | import android.os.Bundle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 37 | import android.os.Handler; |
Jeff Brown | 109025d | 2012-08-14 20:41:30 -0700 | [diff] [blame] | 38 | import android.os.Looper; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 39 | import android.os.Message; |
| 40 | import android.os.PowerManager; |
Dianne Hackborn | 4994c66 | 2009-09-23 22:21:23 -0700 | [diff] [blame] | 41 | import android.os.RemoteException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 42 | import android.os.SystemClock; |
Jim Miller | 1b15202 | 2009-10-28 16:08:15 -0700 | [diff] [blame] | 43 | import android.os.SystemProperties; |
Jeff Sharkey | 6a25cbd | 2012-08-23 12:14:26 -0700 | [diff] [blame] | 44 | import android.os.UserHandle; |
Amith Yamasani | b70ff9a | 2012-09-07 18:28:11 -0700 | [diff] [blame] | 45 | import android.os.UserManager; |
Daniel Sandler | db783bd | 2010-02-11 15:27:37 -0500 | [diff] [blame] | 46 | import android.provider.Settings; |
Karl Rosaen | ab10008 | 2009-03-24 22:35:17 -0700 | [diff] [blame] | 47 | import android.telephony.TelephonyManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 48 | import android.util.EventLog; |
Karl Rosaen | ab10008 | 2009-03-24 22:35:17 -0700 | [diff] [blame] | 49 | import android.util.Log; |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 50 | import android.util.Slog; |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 51 | import android.view.MotionEvent; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 52 | import android.view.WindowManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 53 | import android.view.WindowManagerPolicy; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 54 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 55 | import com.android.internal.telephony.IccCardConstants; |
| 56 | import com.android.internal.widget.LockPatternUtils; |
| 57 | |
Wink Saville | 37c124c | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 58 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 59 | /** |
| 60 | * Mediates requests related to the keyguard. This includes queries about the |
| 61 | * state of the keyguard, power management events that effect whether the keyguard |
| 62 | * should be shown or reset, callbacks to the phone window manager to notify |
| 63 | * it of when the keyguard is showing, and events from the keyguard view itself |
| 64 | * stating that the keyguard was succesfully unlocked. |
| 65 | * |
| 66 | * Note that the keyguard view is shown when the screen is off (as appropriate) |
| 67 | * so that once the screen comes on, it will be ready immediately. |
| 68 | * |
| 69 | * Example queries about the keyguard: |
| 70 | * - is {movement, key} one that should wake the keygaurd? |
| 71 | * - is the keyguard showing? |
| 72 | * - are input events restricted due to the state of the keyguard? |
| 73 | * |
| 74 | * Callbacks to the phone window manager: |
| 75 | * - the keyguard is showing |
| 76 | * |
| 77 | * Example external events that translate to keyguard view changes: |
| 78 | * - screen turned off -> reset the keyguard, and show it so it will be ready |
| 79 | * next time the screen turns on |
| 80 | * - keyboard is slid open -> if the keyguard is not secure, hide it |
| 81 | * |
| 82 | * Events from the keyguard view: |
| 83 | * - user succesfully unlocked keyguard -> hide keyguard view, and no longer |
| 84 | * restrict input events. |
| 85 | * |
| 86 | * Note: in addition to normal power managment events that effect the state of |
| 87 | * whether the keyguard should be showing, external apps and services may request |
| 88 | * that the keyguard be disabled via {@link #setKeyguardEnabled(boolean)}. When |
| 89 | * false, this will override all other conditions for turning on the keyguard. |
| 90 | * |
| 91 | * Threading and synchronization: |
| 92 | * This class is created by the initialization routine of the {@link WindowManagerPolicy}, |
| 93 | * and runs on its thread. The keyguard UI is created from that thread in the |
| 94 | * constructor of this class. The apis may be called from other threads, including the |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 95 | * {@link com.android.server.input.InputManagerService}'s and {@link android.view.WindowManager}'s. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 96 | * Therefore, methods on this class are synchronized, and any action that is pointed |
| 97 | * directly to the keyguard UI is posted to a {@link Handler} to ensure it is taken on the UI |
| 98 | * thread of the keyguard. |
| 99 | */ |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 100 | public class KeyguardViewMediator { |
Jim Miller | bc4603b | 2010-08-30 21:21:34 -0700 | [diff] [blame] | 101 | private static final int KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT = 30000; |
Jim Miller | 9b1db68 | 2012-10-25 19:31:19 -0700 | [diff] [blame] | 102 | final static boolean DEBUG = false; |
Joe Onorato | 431bb22 | 2010-10-18 19:13:23 -0400 | [diff] [blame] | 103 | private final static boolean DBG_WAKE = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 104 | |
| 105 | private final static String TAG = "KeyguardViewMediator"; |
| 106 | |
Jim Miller | 9c20d0e9 | 2010-01-20 15:00:23 -0800 | [diff] [blame] | 107 | private static final String DELAYED_KEYGUARD_ACTION = |
Wink Saville | 37c124c | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 108 | "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 109 | |
| 110 | // used for handler messages |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 111 | private static final int SHOW = 2; |
| 112 | private static final int HIDE = 3; |
| 113 | private static final int RESET = 4; |
| 114 | private static final int VERIFY_UNLOCK = 5; |
| 115 | private static final int NOTIFY_SCREEN_OFF = 6; |
| 116 | private static final int NOTIFY_SCREEN_ON = 7; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 117 | private static final int KEYGUARD_DONE = 9; |
| 118 | private static final int KEYGUARD_DONE_DRAWING = 10; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 119 | private static final int KEYGUARD_DONE_AUTHENTICATING = 11; |
Mike Lockwood | 9200a39 | 2009-11-17 20:25:58 -0500 | [diff] [blame] | 120 | private static final int SET_HIDDEN = 12; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 121 | private static final int KEYGUARD_TIMEOUT = 13; |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 122 | private static final int SHOW_ASSISTANT = 14; |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 123 | private static final int DISPATCH_EVENT = 15; |
Jim Miller | 138f25d | 2013-09-25 13:46:58 -0700 | [diff] [blame] | 124 | private static final int LAUNCH_CAMERA = 16; |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 125 | private static final int DISMISS = 17; |
Jim Miller | 9c20d0e9 | 2010-01-20 15:00:23 -0800 | [diff] [blame] | 126 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 127 | /** |
| 128 | * The default amount of time we stay awake (used for all key input) |
| 129 | */ |
Jim Miller | 7727469 | 2011-01-17 15:28:21 -0800 | [diff] [blame] | 130 | protected static final int AWAKE_INTERVAL_DEFAULT_MS = 10000; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 131 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 132 | /** |
| 133 | * How long to wait after the screen turns off due to timeout before |
| 134 | * turning on the keyguard (i.e, the user has this much time to turn |
| 135 | * the screen back on without having to face the keyguard). |
| 136 | */ |
Jim Miller | bc4603b | 2010-08-30 21:21:34 -0700 | [diff] [blame] | 137 | private static final int KEYGUARD_LOCK_AFTER_DELAY_DEFAULT = 5000; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 138 | |
| 139 | /** |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 140 | * How long we'll wait for the {@link ViewMediatorCallback#keyguardDoneDrawing()} |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 141 | * callback before unblocking a call to {@link #setKeyguardEnabled(boolean)} |
| 142 | * that is reenabling the keyguard. |
| 143 | */ |
| 144 | private static final int KEYGUARD_DONE_DRAWING_TIMEOUT_MS = 2000; |
Jim Miller | 9c20d0e9 | 2010-01-20 15:00:23 -0800 | [diff] [blame] | 145 | |
Daniel Sandler | 74d188c | 2011-08-10 00:00:31 -0400 | [diff] [blame] | 146 | /** |
Jeff Sharkey | f52c70b | 2011-08-30 22:05:47 -0700 | [diff] [blame] | 147 | * Allow the user to expand the status bar when the keyguard is engaged |
| 148 | * (without a pattern or password). |
Daniel Sandler | 74d188c | 2011-08-10 00:00:31 -0400 | [diff] [blame] | 149 | */ |
Jeff Sharkey | f52c70b | 2011-08-30 22:05:47 -0700 | [diff] [blame] | 150 | private static final boolean ENABLE_INSECURE_STATUS_BAR_EXPAND = true; |
Daniel Sandler | 74d188c | 2011-08-10 00:00:31 -0400 | [diff] [blame] | 151 | |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 152 | /** |
| 153 | * Allow the user to expand the status bar when a SECURE keyguard is engaged |
| 154 | * and {@link Settings.Secure#LOCK_SCREEN_ALLOW_NOTIFICATIONS} is set |
| 155 | * (private notifications will be masked). |
| 156 | */ |
| 157 | private static final boolean ENABLE_SECURE_STATUS_BAR_EXPAND = true; |
| 158 | |
| 159 | /** |
| 160 | * Default value of {@link Settings.Secure#LOCK_SCREEN_ALLOW_NOTIFICATIONS}. |
| 161 | */ |
| 162 | private static final boolean ALLOW_NOTIFICATIONS_DEFAULT = false; |
| 163 | |
Amith Yamasani | 8cb751b | 2011-09-30 15:39:41 -0700 | [diff] [blame] | 164 | /** The stream type that the lock sounds are tied to. */ |
Eric Laurent | 6d51766 | 2012-04-23 18:42:39 -0700 | [diff] [blame] | 165 | private int mMasterStreamType; |
Amith Yamasani | 8cb751b | 2011-09-30 15:39:41 -0700 | [diff] [blame] | 166 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 167 | private Context mContext; |
| 168 | private AlarmManager mAlarmManager; |
Amith Yamasani | 8cb751b | 2011-09-30 15:39:41 -0700 | [diff] [blame] | 169 | private AudioManager mAudioManager; |
Mike Lockwood | 5f892c1 | 2009-11-19 23:39:13 -0500 | [diff] [blame] | 170 | private StatusBarManager mStatusBarManager; |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 171 | private boolean mSwitchingUser; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 172 | |
| 173 | private boolean mSystemReady; |
Daniel Sandler | 0060a9b | 2010-03-15 23:09:57 -0400 | [diff] [blame] | 174 | |
| 175 | // Whether the next call to playSounds() should be skipped. Defaults to |
| 176 | // true because the first lock (on boot) should be silent. |
| 177 | private boolean mSuppressNextLockSound = true; |
| 178 | |
Jim Miller | 9c20d0e9 | 2010-01-20 15:00:23 -0800 | [diff] [blame] | 179 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 180 | /** High level access to the power manager for WakeLocks */ |
| 181 | private PowerManager mPM; |
| 182 | |
Amith Yamasani | b70ff9a | 2012-09-07 18:28:11 -0700 | [diff] [blame] | 183 | /** UserManager for querying number of users */ |
| 184 | private UserManager mUserManager; |
| 185 | |
John Spurlock | 43d8451 | 2012-11-09 10:27:33 -0500 | [diff] [blame] | 186 | /** SearchManager for determining whether or not search assistant is available */ |
| 187 | private SearchManager mSearchManager; |
| 188 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 189 | /** |
Mike Lockwood | 674d3e4 | 2009-10-06 09:28:54 -0400 | [diff] [blame] | 190 | * Used to keep the device awake while to ensure the keyguard finishes opening before |
| 191 | * we sleep. |
| 192 | */ |
| 193 | private PowerManager.WakeLock mShowKeyguardWakeLock; |
| 194 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 195 | private KeyguardViewManager mKeyguardViewManager; |
| 196 | |
| 197 | // these are protected by synchronized (this) |
| 198 | |
| 199 | /** |
Mike Lockwood | 5d258b6 | 2009-12-02 13:50:45 -0500 | [diff] [blame] | 200 | * External apps (like the phone app) can tell us to disable the keygaurd. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 201 | */ |
| 202 | private boolean mExternallyEnabled = true; |
| 203 | |
| 204 | /** |
| 205 | * Remember if an external call to {@link #setKeyguardEnabled} with value |
| 206 | * false caused us to hide the keyguard, so that we need to reshow it once |
| 207 | * the keygaurd is reenabled with another call with value true. |
| 208 | */ |
| 209 | private boolean mNeedToReshowWhenReenabled = false; |
| 210 | |
| 211 | // cached value of whether we are showing (need to know this to quickly |
| 212 | // answer whether the input should be restricted) |
Jim Miller | e5f17ab | 2013-11-13 15:40:48 -0800 | [diff] [blame] | 213 | private boolean mShowing; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 214 | |
Mike Lockwood | 09a4040 | 2009-11-08 00:33:23 -0500 | [diff] [blame] | 215 | // true if the keyguard is hidden by another window |
| 216 | private boolean mHidden = false; |
| 217 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 218 | /** |
| 219 | * Helps remember whether the screen has turned on since the last time |
| 220 | * it turned off due to timeout. see {@link #onScreenTurnedOff(int)} |
| 221 | */ |
| 222 | private int mDelayedShowingSequence; |
| 223 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 224 | /** |
| 225 | * If the user has disabled the keyguard, then requests to exit, this is |
| 226 | * how we'll ultimately let them know whether it was successful. We use this |
| 227 | * var being non-null as an indicator that there is an in progress request. |
| 228 | */ |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 229 | private IKeyguardExitCallback mExitSecureCallback; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 230 | |
| 231 | // the properties of the keyguard |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 232 | |
| 233 | private KeyguardUpdateMonitor mUpdateMonitor; |
| 234 | |
Daniel Hansson | 4b71686 | 2012-03-29 11:02:05 +0200 | [diff] [blame] | 235 | private boolean mScreenOn; |
Karl Rosaen | ab10008 | 2009-03-24 22:35:17 -0700 | [diff] [blame] | 236 | |
Daniel Sandler | f2d8e74 | 2010-02-22 13:09:48 -0500 | [diff] [blame] | 237 | // last known state of the cellular connection |
| 238 | private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE; |
| 239 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 240 | /** |
The Android Open Source Project | c84bf28 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 241 | * we send this intent when the keyguard is dismissed. |
| 242 | */ |
Jim Miller | 17f509a | 2013-02-28 18:36:12 -0800 | [diff] [blame] | 243 | private static final Intent USER_PRESENT_INTENT = new Intent(Intent.ACTION_USER_PRESENT) |
| 244 | .addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING |
| 245 | | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
The Android Open Source Project | c84bf28 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 246 | |
| 247 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 248 | * {@link #setKeyguardEnabled} waits on this condition when it reenables |
| 249 | * the keyguard. |
| 250 | */ |
| 251 | private boolean mWaitingUntilKeyguardVisible = false; |
Jim Miller | bc4603b | 2010-08-30 21:21:34 -0700 | [diff] [blame] | 252 | private LockPatternUtils mLockPatternUtils; |
John Spurlock | 34c4fe5 | 2012-11-07 10:12:29 -0500 | [diff] [blame] | 253 | private boolean mKeyguardDonePending = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 254 | |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 255 | private SoundPool mLockSounds; |
| 256 | private int mLockSoundId; |
| 257 | private int mUnlockSoundId; |
| 258 | private int mLockSoundStreamId; |
Jean-Michel Trivi | c55b393 | 2012-06-05 11:57:59 -0700 | [diff] [blame] | 259 | |
| 260 | /** |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 261 | * Tracks value of {@link Settings.Secure#LOCK_SCREEN_ALLOW_NOTIFICATIONS}. |
| 262 | */ |
| 263 | private boolean mAllowNotificationsWhenSecure; |
| 264 | |
| 265 | /** |
Jean-Michel Trivi | c55b393 | 2012-06-05 11:57:59 -0700 | [diff] [blame] | 266 | * The volume applied to the lock/unlock sounds. |
| 267 | */ |
| 268 | private final float mLockSoundVolume; |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 269 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 270 | /** |
Jim Miller | 3192148f | 2013-11-06 20:43:55 -0800 | [diff] [blame] | 271 | * For managing external displays |
| 272 | */ |
| 273 | private KeyguardDisplayManager mKeyguardDisplayManager; |
| 274 | |
| 275 | /** |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 276 | * Cache of avatar drawables, for use by KeyguardMultiUserAvatar. |
| 277 | */ |
| 278 | private static MultiUserAvatarCache sMultiUserAvatarCache = new MultiUserAvatarCache(); |
| 279 | |
| 280 | /** |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 281 | * The callback used by the keyguard view to tell the {@link KeyguardViewMediator} |
| 282 | * various things. |
| 283 | */ |
| 284 | public interface ViewMediatorCallback { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 285 | /** |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 286 | * Reports user activity and requests that the screen stay on. |
| 287 | */ |
| 288 | void userActivity(); |
| 289 | |
| 290 | /** |
| 291 | * Reports user activity and requests that the screen stay on for at least |
| 292 | * the specified amount of time. |
| 293 | * @param millis The amount of time in millis. This value is currently ignored. |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 294 | */ |
Jeff Brown | 3dc524b | 2012-09-30 19:49:11 -0700 | [diff] [blame] | 295 | void userActivity(long millis); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 296 | |
| 297 | /** |
| 298 | * Report that the keyguard is done. |
| 299 | * @param authenticated Whether the user securely got past the keyguard. |
| 300 | * the only reason for this to be false is if the keyguard was instructed |
| 301 | * to appear temporarily to verify the user is supposed to get past the |
| 302 | * keyguard, and the user fails to do so. |
| 303 | */ |
| 304 | void keyguardDone(boolean authenticated); |
| 305 | |
| 306 | /** |
| 307 | * Report that the keyguard is done drawing. |
| 308 | */ |
| 309 | void keyguardDoneDrawing(); |
| 310 | |
| 311 | /** |
| 312 | * Tell ViewMediator that the current view needs IME input |
| 313 | * @param needsInput |
| 314 | */ |
| 315 | void setNeedsInput(boolean needsInput); |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 316 | |
| 317 | /** |
| 318 | * Tell view mediator that the keyguard view's desired user activity timeout |
| 319 | * has changed and needs to be reapplied to the window. |
| 320 | */ |
| 321 | void onUserActivityTimeoutChanged(); |
John Spurlock | 34c4fe5 | 2012-11-07 10:12:29 -0500 | [diff] [blame] | 322 | |
| 323 | /** |
| 324 | * Report that the keyguard is dismissable, pending the next keyguardDone call. |
| 325 | */ |
| 326 | void keyguardDonePending(); |
Jim Miller | 0b9d8ac | 2013-11-07 19:15:49 -0800 | [diff] [blame] | 327 | |
| 328 | /** |
| 329 | * Report when keyguard is actually gone |
| 330 | */ |
| 331 | void keyguardGone(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 334 | KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() { |
| 335 | |
| 336 | @Override |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 337 | public void onUserSwitching(int userId) { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 338 | // Note that the mLockPatternUtils user has already been updated from setCurrentUser. |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 339 | // We need to force a reset of the views, since lockNow (called by |
| 340 | // ActivityManagerService) will not reconstruct the keyguard if it is already showing. |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 341 | synchronized (KeyguardViewMediator.this) { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 342 | mSwitchingUser = true; |
Winson Chung | f7614fc | 2012-11-26 14:43:24 -0800 | [diff] [blame] | 343 | resetStateLocked(null); |
John Spurlock | 4e6922d | 2012-10-04 14:51:51 -0400 | [diff] [blame] | 344 | adjustStatusBarLocked(); |
Brian Colonna | a523989 | 2013-04-15 11:45:40 -0400 | [diff] [blame] | 345 | // When we switch users we want to bring the new user to the biometric unlock even |
| 346 | // if the current user has gone to the backup. |
| 347 | KeyguardUpdateMonitor.getInstance(mContext).setAlternateUnlockEnabled(true); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 348 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | @Override |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 352 | public void onUserSwitchComplete(int userId) { |
| 353 | mSwitchingUser = false; |
| 354 | } |
| 355 | |
| 356 | @Override |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 357 | public void onUserRemoved(int userId) { |
| 358 | mLockPatternUtils.removeUser(userId); |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 359 | sMultiUserAvatarCache.clear(userId); |
| 360 | } |
| 361 | |
| 362 | @Override |
| 363 | public void onUserInfoChanged(int userId) { |
| 364 | sMultiUserAvatarCache.clear(userId); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | @Override |
| 368 | void onPhoneStateChanged(int phoneState) { |
| 369 | synchronized (KeyguardViewMediator.this) { |
| 370 | if (TelephonyManager.CALL_STATE_IDLE == phoneState // call ending |
| 371 | && !mScreenOn // screen off |
| 372 | && mExternallyEnabled) { // not disabled by any app |
| 373 | |
| 374 | // note: this is a way to gracefully reenable the keyguard when the call |
| 375 | // ends and the screen is off without always reenabling the keyguard |
| 376 | // each time the screen turns off while in call (and having an occasional ugly |
| 377 | // flicker while turning back on the screen and disabling the keyguard again). |
| 378 | if (DEBUG) Log.d(TAG, "screen is off and call ended, let's make sure the " |
| 379 | + "keyguard is showing"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 380 | doKeyguardLocked(null); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | }; |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 384 | |
| 385 | @Override |
| 386 | public void onClockVisibilityChanged() { |
| 387 | adjustStatusBarLocked(); |
| 388 | } |
| 389 | |
| 390 | @Override |
| 391 | public void onDeviceProvisioned() { |
Jim Miller | 3fd47af | 2012-09-21 19:55:27 -0700 | [diff] [blame] | 392 | sendUserPresentBroadcast(); |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 395 | @Override |
| 396 | public void onSimStateChanged(IccCardConstants.State simState) { |
| 397 | if (DEBUG) Log.d(TAG, "onSimStateChanged: " + simState); |
| 398 | |
| 399 | switch (simState) { |
| 400 | case NOT_READY: |
| 401 | case ABSENT: |
| 402 | // only force lock screen in case of missing sim if user hasn't |
| 403 | // gone through setup wizard |
| 404 | synchronized (this) { |
| 405 | if (!mUpdateMonitor.isDeviceProvisioned()) { |
| 406 | if (!isShowing()) { |
| 407 | if (DEBUG) Log.d(TAG, "ICC_ABSENT isn't showing," |
| 408 | + " we need to show the keyguard since the " |
| 409 | + "device isn't provisioned yet."); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 410 | doKeyguardLocked(null); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 411 | } else { |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 412 | resetStateLocked(null); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | } |
| 416 | break; |
| 417 | case PIN_REQUIRED: |
| 418 | case PUK_REQUIRED: |
| 419 | synchronized (this) { |
| 420 | if (!isShowing()) { |
| 421 | if (DEBUG) Log.d(TAG, "INTENT_VALUE_ICC_LOCKED and keygaurd isn't " |
| 422 | + "showing; need to show keyguard so user can enter sim pin"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 423 | doKeyguardLocked(null); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 424 | } else { |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 425 | resetStateLocked(null); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | break; |
| 429 | case PERM_DISABLED: |
| 430 | synchronized (this) { |
| 431 | if (!isShowing()) { |
| 432 | if (DEBUG) Log.d(TAG, "PERM_DISABLED and " |
| 433 | + "keygaurd isn't showing."); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 434 | doKeyguardLocked(null); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 435 | } else { |
| 436 | if (DEBUG) Log.d(TAG, "PERM_DISABLED, resetStateLocked to" |
| 437 | + "show permanently disabled message in lockscreen."); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 438 | resetStateLocked(null); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 439 | } |
| 440 | } |
| 441 | break; |
| 442 | case READY: |
| 443 | synchronized (this) { |
| 444 | if (isShowing()) { |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 445 | resetStateLocked(null); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 446 | } |
| 447 | } |
| 448 | break; |
| 449 | } |
| 450 | } |
| 451 | |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 452 | }; |
| 453 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 454 | ViewMediatorCallback mViewMediatorCallback = new ViewMediatorCallback() { |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 455 | public void userActivity() { |
| 456 | KeyguardViewMediator.this.userActivity(); |
| 457 | } |
| 458 | |
Jeff Brown | 3dc524b | 2012-09-30 19:49:11 -0700 | [diff] [blame] | 459 | public void userActivity(long holdMs) { |
| 460 | KeyguardViewMediator.this.userActivity(holdMs); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | public void keyguardDone(boolean authenticated) { |
| 464 | KeyguardViewMediator.this.keyguardDone(authenticated, true); |
| 465 | } |
| 466 | |
| 467 | public void keyguardDoneDrawing() { |
| 468 | mHandler.sendEmptyMessage(KEYGUARD_DONE_DRAWING); |
| 469 | } |
| 470 | |
| 471 | @Override |
| 472 | public void setNeedsInput(boolean needsInput) { |
| 473 | mKeyguardViewManager.setNeedsInput(needsInput); |
| 474 | } |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 475 | |
| 476 | @Override |
| 477 | public void onUserActivityTimeoutChanged() { |
| 478 | mKeyguardViewManager.updateUserActivityTimeout(); |
| 479 | } |
John Spurlock | 34c4fe5 | 2012-11-07 10:12:29 -0500 | [diff] [blame] | 480 | |
| 481 | @Override |
| 482 | public void keyguardDonePending() { |
| 483 | mKeyguardDonePending = true; |
| 484 | } |
Jim Miller | 0b9d8ac | 2013-11-07 19:15:49 -0800 | [diff] [blame] | 485 | |
| 486 | @Override |
| 487 | public void keyguardGone() { |
| 488 | mKeyguardDisplayManager.hide(); |
| 489 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 490 | }; |
| 491 | |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 492 | private void userActivity() { |
Jeff Brown | 3dc524b | 2012-09-30 19:49:11 -0700 | [diff] [blame] | 493 | userActivity(AWAKE_INTERVAL_DEFAULT_MS); |
| 494 | } |
| 495 | |
| 496 | public void userActivity(long holdMs) { |
| 497 | // We ignore the hold time. Eventually we should remove it. |
| 498 | // Instead, the keyguard window has an explicit user activity timeout set on it. |
| 499 | mPM.userActivity(SystemClock.uptimeMillis(), false); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | /** |
| 503 | * Construct a KeyguardViewMediator |
| 504 | * @param context |
| 505 | * @param lockPatternUtils optional mock interface for LockPatternUtils |
| 506 | */ |
| 507 | public KeyguardViewMediator(Context context, LockPatternUtils lockPatternUtils) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 508 | mContext = context; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 509 | mPM = (PowerManager) context.getSystemService(Context.POWER_SERVICE); |
Amith Yamasani | b70ff9a | 2012-09-07 18:28:11 -0700 | [diff] [blame] | 510 | mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); |
Mike Lockwood | 674d3e4 | 2009-10-06 09:28:54 -0400 | [diff] [blame] | 511 | mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard"); |
| 512 | mShowKeyguardWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 513 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 514 | mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(DELAYED_KEYGUARD_ACTION)); |
| 515 | |
Jim Miller | 3192148f | 2013-11-06 20:43:55 -0800 | [diff] [blame] | 516 | mKeyguardDisplayManager = new KeyguardDisplayManager(context); |
| 517 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 518 | mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 519 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 520 | mUpdateMonitor = KeyguardUpdateMonitor.getInstance(context); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 521 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 522 | mLockPatternUtils = lockPatternUtils != null |
| 523 | ? lockPatternUtils : new LockPatternUtils(mContext); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 524 | mLockPatternUtils.setCurrentUser(UserHandle.USER_OWNER); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 525 | |
Jim Miller | e5f17ab | 2013-11-13 15:40:48 -0800 | [diff] [blame] | 526 | // Assume keyguard is showing (unless it's disabled) until we know for sure... |
Jim Miller | 299422b | 2013-11-14 14:15:02 -0800 | [diff] [blame] | 527 | mShowing = (mUpdateMonitor.isDeviceProvisioned() || mLockPatternUtils.isSecure()) |
| 528 | && !mLockPatternUtils.isLockScreenDisabled(); |
Jim Miller | e5f17ab | 2013-11-13 15:40:48 -0800 | [diff] [blame] | 529 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 530 | WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 531 | |
| 532 | mKeyguardViewManager = new KeyguardViewManager(context, wm, mViewMediatorCallback, |
| 533 | mLockPatternUtils); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 534 | |
Daniel Sandler | 687a327 | 2010-03-13 15:44:47 -0500 | [diff] [blame] | 535 | final ContentResolver cr = mContext.getContentResolver(); |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 536 | |
Daniel Hansson | 4b71686 | 2012-03-29 11:02:05 +0200 | [diff] [blame] | 537 | mScreenOn = mPM.isScreenOn(); |
| 538 | |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 539 | mLockSounds = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0); |
Jim Miller | b14288d | 2012-09-30 18:25:05 -0700 | [diff] [blame] | 540 | String soundPath = Settings.Global.getString(cr, Settings.Global.LOCK_SOUND); |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 541 | if (soundPath != null) { |
| 542 | mLockSoundId = mLockSounds.load(soundPath, 1); |
| 543 | } |
| 544 | if (soundPath == null || mLockSoundId == 0) { |
Jim Miller | b14288d | 2012-09-30 18:25:05 -0700 | [diff] [blame] | 545 | Log.w(TAG, "failed to load lock sound from " + soundPath); |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 546 | } |
Jim Miller | b14288d | 2012-09-30 18:25:05 -0700 | [diff] [blame] | 547 | soundPath = Settings.Global.getString(cr, Settings.Global.UNLOCK_SOUND); |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 548 | if (soundPath != null) { |
| 549 | mUnlockSoundId = mLockSounds.load(soundPath, 1); |
| 550 | } |
| 551 | if (soundPath == null || mUnlockSoundId == 0) { |
Jim Miller | b14288d | 2012-09-30 18:25:05 -0700 | [diff] [blame] | 552 | Log.w(TAG, "failed to load unlock sound from " + soundPath); |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 553 | } |
Jean-Michel Trivi | c55b393 | 2012-06-05 11:57:59 -0700 | [diff] [blame] | 554 | int lockSoundDefaultAttenuation = context.getResources().getInteger( |
| 555 | com.android.internal.R.integer.config_lockSoundVolumeDb); |
Jean-Michel Trivi | f2b0c11 | 2012-07-09 11:59:11 -0700 | [diff] [blame] | 556 | mLockSoundVolume = (float)Math.pow(10, (float)lockSoundDefaultAttenuation/20); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | /** |
| 560 | * Let us know that the system is ready after startup. |
| 561 | */ |
| 562 | public void onSystemReady() { |
John Spurlock | 43d8451 | 2012-11-09 10:27:33 -0500 | [diff] [blame] | 563 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 564 | synchronized (this) { |
| 565 | if (DEBUG) Log.d(TAG, "onSystemReady"); |
| 566 | mSystemReady = true; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 567 | mUpdateMonitor.registerCallback(mUpdateCallback); |
Jim Miller | 0869770 | 2012-10-22 16:49:52 -0700 | [diff] [blame] | 568 | |
Brian Colonna | d4a3e5d | 2012-11-01 16:20:24 -0400 | [diff] [blame] | 569 | // Suppress biometric unlock right after boot until things have settled if it is the |
| 570 | // selected security method, otherwise unsuppress it. It must be unsuppressed if it is |
| 571 | // not the selected security method for the following reason: if the user starts |
| 572 | // without a screen lock selected, the biometric unlock would be suppressed the first |
| 573 | // time they try to use it. |
| 574 | // |
| 575 | // Note that the biometric unlock will still not show if it is not the selected method. |
| 576 | // Calling setAlternateUnlockEnabled(true) simply says don't suppress it if it is the |
| 577 | // selected method. |
| 578 | if (mLockPatternUtils.usingBiometricWeak() |
| 579 | && mLockPatternUtils.isBiometricWeakInstalled()) { |
| 580 | if (DEBUG) Log.d(TAG, "suppressing biometric unlock during boot"); |
| 581 | mUpdateMonitor.setAlternateUnlockEnabled(false); |
| 582 | } else { |
| 583 | mUpdateMonitor.setAlternateUnlockEnabled(true); |
| 584 | } |
Jim Miller | 0869770 | 2012-10-22 16:49:52 -0700 | [diff] [blame] | 585 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 586 | doKeyguardLocked(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 587 | } |
Jim Miller | 3fd47af | 2012-09-21 19:55:27 -0700 | [diff] [blame] | 588 | // Most services aren't available until the system reaches the ready state, so we |
| 589 | // send it here when the device first boots. |
| 590 | maybeSendUserPresentBroadcast(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | /** |
| 594 | * Called to let us know the screen was turned off. |
Mike Lockwood | ce27776 | 2009-12-03 08:41:44 -0500 | [diff] [blame] | 595 | * @param why either {@link WindowManagerPolicy#OFF_BECAUSE_OF_USER}, |
| 596 | * {@link WindowManagerPolicy#OFF_BECAUSE_OF_TIMEOUT} or |
| 597 | * {@link WindowManagerPolicy#OFF_BECAUSE_OF_PROX_SENSOR}. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 598 | */ |
| 599 | public void onScreenTurnedOff(int why) { |
| 600 | synchronized (this) { |
Karl Rosaen | ab10008 | 2009-03-24 22:35:17 -0700 | [diff] [blame] | 601 | mScreenOn = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 602 | if (DEBUG) Log.d(TAG, "onScreenTurnedOff(" + why + ")"); |
| 603 | |
John Spurlock | 14adfe4 | 2012-11-08 10:29:26 -0500 | [diff] [blame] | 604 | mKeyguardDonePending = false; |
| 605 | |
Jim Miller | a4edd15 | 2012-01-06 18:24:04 -0800 | [diff] [blame] | 606 | // Lock immediately based on setting if secure (user has a pin/pattern/password). |
| 607 | // This also "locks" the device when not secure to provide easy access to the |
| 608 | // camera while preventing unwanted input. |
| 609 | final boolean lockImmediately = |
| 610 | mLockPatternUtils.getPowerButtonInstantlyLocks() || !mLockPatternUtils.isSecure(); |
| 611 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 612 | if (mExitSecureCallback != null) { |
| 613 | if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 614 | try { |
| 615 | mExitSecureCallback.onKeyguardExitResult(false); |
| 616 | } catch (RemoteException e) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 617 | Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 618 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 619 | mExitSecureCallback = null; |
| 620 | if (!mExternallyEnabled) { |
Jim Miller | 9c20d0e9 | 2010-01-20 15:00:23 -0800 | [diff] [blame] | 621 | hideLocked(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 622 | } |
| 623 | } else if (mShowing) { |
| 624 | notifyScreenOffLocked(); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 625 | resetStateLocked(null); |
Jim Miller | a4edd15 | 2012-01-06 18:24:04 -0800 | [diff] [blame] | 626 | } else if (why == WindowManagerPolicy.OFF_BECAUSE_OF_TIMEOUT |
| 627 | || (why == WindowManagerPolicy.OFF_BECAUSE_OF_USER && !lockImmediately)) { |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 628 | doKeyguardLaterLocked(); |
Mike Lockwood | ce27776 | 2009-12-03 08:41:44 -0500 | [diff] [blame] | 629 | } else if (why == WindowManagerPolicy.OFF_BECAUSE_OF_PROX_SENSOR) { |
| 630 | // Do not enable the keyguard if the prox sensor forced the screen off. |
Mike Lockwood | 016e397 | 2009-09-17 11:45:06 -0400 | [diff] [blame] | 631 | } else { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 632 | doKeyguardLocked(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 633 | } |
| 634 | } |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 635 | KeyguardUpdateMonitor.getInstance(mContext).dispatchScreenTurndOff(why); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 636 | } |
| 637 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 638 | private void doKeyguardLaterLocked() { |
| 639 | // if the screen turned off because of timeout or the user hit the power button |
| 640 | // and we don't need to lock immediately, set an alarm |
| 641 | // to enable it a little bit later (i.e, give the user a chance |
| 642 | // to turn the screen back on within a certain window without |
| 643 | // having to unlock the screen) |
| 644 | final ContentResolver cr = mContext.getContentResolver(); |
| 645 | |
| 646 | // From DisplaySettings |
| 647 | long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT, |
| 648 | KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT); |
| 649 | |
| 650 | // From SecuritySettings |
| 651 | final long lockAfterTimeout = Settings.Secure.getInt(cr, |
| 652 | Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, |
| 653 | KEYGUARD_LOCK_AFTER_DELAY_DEFAULT); |
| 654 | |
| 655 | // From DevicePolicyAdmin |
| 656 | final long policyTimeout = mLockPatternUtils.getDevicePolicyManager() |
| 657 | .getMaximumTimeToLock(null, mLockPatternUtils.getCurrentUser()); |
| 658 | |
| 659 | long timeout; |
| 660 | if (policyTimeout > 0) { |
| 661 | // policy in effect. Make sure we don't go beyond policy limit. |
| 662 | displayTimeout = Math.max(displayTimeout, 0); // ignore negative values |
| 663 | timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout); |
| 664 | } else { |
| 665 | timeout = lockAfterTimeout; |
| 666 | } |
| 667 | |
| 668 | if (timeout <= 0) { |
| 669 | // Lock now |
| 670 | mSuppressNextLockSound = true; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 671 | doKeyguardLocked(null); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 672 | } else { |
| 673 | // Lock in the future |
| 674 | long when = SystemClock.elapsedRealtime() + timeout; |
| 675 | Intent intent = new Intent(DELAYED_KEYGUARD_ACTION); |
| 676 | intent.putExtra("seq", mDelayedShowingSequence); |
| 677 | PendingIntent sender = PendingIntent.getBroadcast(mContext, |
| 678 | 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); |
| 679 | mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender); |
| 680 | if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = " |
| 681 | + mDelayedShowingSequence); |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | private void cancelDoKeyguardLaterLocked() { |
| 686 | mDelayedShowingSequence++; |
| 687 | } |
| 688 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 689 | /** |
| 690 | * Let's us know the screen was turned on. |
| 691 | */ |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 692 | public void onScreenTurnedOn(IKeyguardShowCallback callback) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 693 | synchronized (this) { |
Karl Rosaen | ab10008 | 2009-03-24 22:35:17 -0700 | [diff] [blame] | 694 | mScreenOn = true; |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 695 | cancelDoKeyguardLaterLocked(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 696 | if (DEBUG) Log.d(TAG, "onScreenTurnedOn, seq = " + mDelayedShowingSequence); |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 697 | if (callback != null) { |
| 698 | notifyScreenOnLocked(callback); |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 699 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 700 | } |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 701 | KeyguardUpdateMonitor.getInstance(mContext).dispatchScreenTurnedOn(); |
Jim Miller | 3fd47af | 2012-09-21 19:55:27 -0700 | [diff] [blame] | 702 | maybeSendUserPresentBroadcast(); |
| 703 | } |
| 704 | |
| 705 | private void maybeSendUserPresentBroadcast() { |
| 706 | if (mSystemReady && mLockPatternUtils.isLockScreenDisabled() |
| 707 | && mUserManager.getUsers(true).size() == 1) { |
| 708 | // Lock screen is disabled because the user has set the preference to "None". |
| 709 | // In this case, send out ACTION_USER_PRESENT here instead of in |
| 710 | // handleKeyguardDone() |
| 711 | sendUserPresentBroadcast(); |
| 712 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | /** |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 716 | * A dream started. We should lock after the usual screen-off lock timeout but only |
| 717 | * if there is a secure lock pattern. |
| 718 | */ |
| 719 | public void onDreamingStarted() { |
| 720 | synchronized (this) { |
| 721 | if (mScreenOn && mLockPatternUtils.isSecure()) { |
| 722 | doKeyguardLaterLocked(); |
| 723 | } |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | /** |
| 728 | * A dream stopped. |
| 729 | */ |
| 730 | public void onDreamingStopped() { |
| 731 | synchronized (this) { |
| 732 | if (mScreenOn) { |
| 733 | cancelDoKeyguardLaterLocked(); |
| 734 | } |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 739 | * Same semantics as {@link WindowManagerPolicy#enableKeyguard}; provide |
| 740 | * a way for external stuff to override normal keyguard behavior. For instance |
| 741 | * the phone app disables the keyguard when it receives incoming calls. |
| 742 | */ |
| 743 | public void setKeyguardEnabled(boolean enabled) { |
| 744 | synchronized (this) { |
| 745 | if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")"); |
| 746 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 747 | mExternallyEnabled = enabled; |
| 748 | |
| 749 | if (!enabled && mShowing) { |
| 750 | if (mExitSecureCallback != null) { |
| 751 | if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring"); |
| 752 | // we're in the process of handling a request to verify the user |
| 753 | // can get past the keyguard. ignore extraneous requests to disable / reenable |
| 754 | return; |
| 755 | } |
| 756 | |
| 757 | // hiding keyguard that is showing, remember to reshow later |
| 758 | if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, " |
| 759 | + "disabling status bar expansion"); |
| 760 | mNeedToReshowWhenReenabled = true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 761 | hideLocked(); |
| 762 | } else if (enabled && mNeedToReshowWhenReenabled) { |
| 763 | // reenabled after previously hidden, reshow |
| 764 | if (DEBUG) Log.d(TAG, "previously hidden, reshowing, reenabling " |
| 765 | + "status bar expansion"); |
| 766 | mNeedToReshowWhenReenabled = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 767 | |
| 768 | if (mExitSecureCallback != null) { |
| 769 | if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 770 | try { |
| 771 | mExitSecureCallback.onKeyguardExitResult(false); |
| 772 | } catch (RemoteException e) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 773 | Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 774 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 775 | mExitSecureCallback = null; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 776 | resetStateLocked(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 777 | } else { |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 778 | showLocked(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 779 | |
| 780 | // block until we know the keygaurd is done drawing (and post a message |
| 781 | // to unblock us after a timeout so we don't risk blocking too long |
| 782 | // and causing an ANR). |
| 783 | mWaitingUntilKeyguardVisible = true; |
| 784 | mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING, KEYGUARD_DONE_DRAWING_TIMEOUT_MS); |
| 785 | if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false"); |
| 786 | while (mWaitingUntilKeyguardVisible) { |
| 787 | try { |
| 788 | wait(); |
| 789 | } catch (InterruptedException e) { |
| 790 | Thread.currentThread().interrupt(); |
| 791 | } |
| 792 | } |
| 793 | if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible"); |
| 794 | } |
| 795 | } |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | /** |
| 800 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 801 | */ |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 802 | public void verifyUnlock(IKeyguardExitCallback callback) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 803 | synchronized (this) { |
| 804 | if (DEBUG) Log.d(TAG, "verifyUnlock"); |
| 805 | if (!mUpdateMonitor.isDeviceProvisioned()) { |
| 806 | // don't allow this api when the device isn't provisioned |
| 807 | if (DEBUG) Log.d(TAG, "ignoring because device isn't provisioned"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 808 | try { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 809 | callback.onKeyguardExitResult(false); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 810 | } catch (RemoteException e) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 811 | Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 812 | } |
Mike Lockwood | 5d258b6 | 2009-12-02 13:50:45 -0500 | [diff] [blame] | 813 | } else if (mExternallyEnabled) { |
| 814 | // this only applies when the user has externally disabled the |
| 815 | // keyguard. this is unexpected and means the user is not |
| 816 | // using the api properly. |
| 817 | Log.w(TAG, "verifyUnlock called when not externally disabled"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 818 | try { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 819 | callback.onKeyguardExitResult(false); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 820 | } catch (RemoteException e) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 821 | Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 822 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 823 | } else if (mExitSecureCallback != null) { |
| 824 | // already in progress with someone else |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 825 | try { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 826 | callback.onKeyguardExitResult(false); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 827 | } catch (RemoteException e) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 828 | Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 829 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 830 | } else { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 831 | mExitSecureCallback = callback; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 832 | verifyUnlockLocked(); |
| 833 | } |
| 834 | } |
| 835 | } |
| 836 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 837 | /** |
| 838 | * Is the keyguard currently showing? |
| 839 | */ |
| 840 | public boolean isShowing() { |
| 841 | return mShowing; |
| 842 | } |
| 843 | |
| 844 | /** |
Dianne Hackborn | 9dc06cc | 2009-11-17 18:19:23 -0800 | [diff] [blame] | 845 | * Is the keyguard currently showing and not being force hidden? |
| 846 | */ |
| 847 | public boolean isShowingAndNotHidden() { |
| 848 | return mShowing && !mHidden; |
| 849 | } |
| 850 | |
| 851 | /** |
Mike Lockwood | 09a4040 | 2009-11-08 00:33:23 -0500 | [diff] [blame] | 852 | * Notify us when the keyguard is hidden by another window |
| 853 | */ |
| 854 | public void setHidden(boolean isHidden) { |
Mike Lockwood | b17b2fb | 2009-11-09 16:01:37 -0500 | [diff] [blame] | 855 | if (DEBUG) Log.d(TAG, "setHidden " + isHidden); |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 856 | mUpdateMonitor.sendKeyguardVisibilityChanged(!isHidden); |
Mike Lockwood | 9200a39 | 2009-11-17 20:25:58 -0500 | [diff] [blame] | 857 | mHandler.removeMessages(SET_HIDDEN); |
| 858 | Message msg = mHandler.obtainMessage(SET_HIDDEN, (isHidden ? 1 : 0), 0); |
| 859 | mHandler.sendMessage(msg); |
| 860 | } |
| 861 | |
| 862 | /** |
| 863 | * Handles SET_HIDDEN message sent by setHidden() |
| 864 | */ |
| 865 | private void handleSetHidden(boolean isHidden) { |
Mike Lockwood | 09a4040 | 2009-11-08 00:33:23 -0500 | [diff] [blame] | 866 | synchronized (KeyguardViewMediator.this) { |
Mike Lockwood | 9200a39 | 2009-11-17 20:25:58 -0500 | [diff] [blame] | 867 | if (mHidden != isHidden) { |
| 868 | mHidden = isHidden; |
Dianne Hackborn | ff5b158 | 2012-04-12 17:24:07 -0700 | [diff] [blame] | 869 | updateActivityLockScreenState(); |
Mike Lockwood | 5f892c1 | 2009-11-19 23:39:13 -0500 | [diff] [blame] | 870 | adjustStatusBarLocked(); |
Mike Lockwood | 9200a39 | 2009-11-17 20:25:58 -0500 | [diff] [blame] | 871 | } |
Mike Lockwood | 09a4040 | 2009-11-08 00:33:23 -0500 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | |
| 875 | /** |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 876 | * Used by PhoneWindowManager to enable the keyguard due to a user activity timeout. |
| 877 | * This must be safe to call from any thread and with any window manager locks held. |
| 878 | */ |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 879 | public void doKeyguardTimeout(Bundle options) { |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 880 | mHandler.removeMessages(KEYGUARD_TIMEOUT); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 881 | Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT, options); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 882 | mHandler.sendMessage(msg); |
| 883 | } |
| 884 | |
| 885 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 886 | * Given the state of the keyguard, is the input restricted? |
| 887 | * Input is restricted when the keyguard is showing, or when the keyguard |
| 888 | * was suppressed by an app that disabled the keyguard or we haven't been provisioned yet. |
| 889 | */ |
| 890 | public boolean isInputRestricted() { |
| 891 | return mShowing || mNeedToReshowWhenReenabled || !mUpdateMonitor.isDeviceProvisioned(); |
| 892 | } |
| 893 | |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 894 | /** |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 895 | * Enable the keyguard if the settings are appropriate. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 896 | */ |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 897 | private void doKeyguardLocked(Bundle options) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 898 | // if another app is disabling us, don't show |
| 899 | if (!mExternallyEnabled) { |
| 900 | if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled"); |
Karl Rosaen | ab10008 | 2009-03-24 22:35:17 -0700 | [diff] [blame] | 901 | |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 902 | // note: we *should* set mNeedToReshowWhenReenabled=true here, but that makes |
| 903 | // for an occasional ugly flicker in this situation: |
| 904 | // 1) receive a call with the screen on (no keyguard) or make a call |
| 905 | // 2) screen times out |
| 906 | // 3) user hits key to turn screen back on |
| 907 | // instead, we reenable the keyguard when we know the screen is off and the call |
| 908 | // ends (see the broadcast receiver below) |
| 909 | // TODO: clean this up when we have better support at the window manager level |
| 910 | // for apps that wish to be on top of the keyguard |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 911 | return; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 912 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 913 | |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 914 | // note whether notification access should be allowed |
| 915 | mAllowNotificationsWhenSecure = ENABLE_SECURE_STATUS_BAR_EXPAND |
| 916 | && 0 != Settings.Secure.getInt( |
| 917 | mContext.getContentResolver(), |
| 918 | Settings.Secure.LOCK_SCREEN_ALLOW_NOTIFICATIONS, |
| 919 | ALLOW_NOTIFICATIONS_DEFAULT ? 1 : 0); |
| 920 | |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 921 | // if the keyguard is already showing, don't bother |
| 922 | if (mKeyguardViewManager.isShowing()) { |
| 923 | if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing"); |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 924 | return; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | // if the setup wizard hasn't run yet, don't show |
| 928 | final boolean requireSim = !SystemProperties.getBoolean("keyguard.no_require_sim", |
| 929 | false); |
| 930 | final boolean provisioned = mUpdateMonitor.isDeviceProvisioned(); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 931 | final IccCardConstants.State state = mUpdateMonitor.getSimState(); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 932 | final boolean lockedOrMissing = state.isPinLocked() |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 933 | || ((state == IccCardConstants.State.ABSENT |
| 934 | || state == IccCardConstants.State.PERM_DISABLED) |
Jim Miller | 9fa1ada | 2011-10-31 18:21:49 -0700 | [diff] [blame] | 935 | && requireSim); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 936 | |
| 937 | if (!lockedOrMissing && !provisioned) { |
| 938 | if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned" |
| 939 | + " and the sim is not locked or missing"); |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 940 | return; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 941 | } |
| 942 | |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 943 | if (mUserManager.getUsers(true).size() < 2 |
Amith Yamasani | b70ff9a | 2012-09-07 18:28:11 -0700 | [diff] [blame] | 944 | && mLockPatternUtils.isLockScreenDisabled() && !lockedOrMissing) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 945 | if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off"); |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 946 | return; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen"); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 950 | showLocked(options); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | /** |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 954 | * Dismiss the keyguard through the security layers. |
| 955 | */ |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 956 | public void handleDismiss() { |
Jim Miller | 87d0366 | 2012-11-05 20:28:09 -0800 | [diff] [blame] | 957 | if (mShowing && !mHidden) { |
| 958 | mKeyguardViewManager.dismiss(); |
| 959 | } |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 962 | public void dismiss() { |
| 963 | mHandler.sendEmptyMessage(DISMISS); |
| 964 | } |
| 965 | |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 966 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 967 | * Send message to keyguard telling it to reset its state. |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 968 | * @param options options about how to show the keyguard |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 969 | * @see #handleReset() |
| 970 | */ |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 971 | private void resetStateLocked(Bundle options) { |
Jim Miller | 4894a01 | 2013-04-03 15:23:55 -0700 | [diff] [blame] | 972 | if (DEBUG) Log.e(TAG, "resetStateLocked"); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 973 | Message msg = mHandler.obtainMessage(RESET, options); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 974 | mHandler.sendMessage(msg); |
| 975 | } |
| 976 | |
| 977 | /** |
| 978 | * Send message to keyguard telling it to verify unlock |
| 979 | * @see #handleVerifyUnlock() |
| 980 | */ |
| 981 | private void verifyUnlockLocked() { |
| 982 | if (DEBUG) Log.d(TAG, "verifyUnlockLocked"); |
| 983 | mHandler.sendEmptyMessage(VERIFY_UNLOCK); |
| 984 | } |
| 985 | |
| 986 | |
| 987 | /** |
| 988 | * Send a message to keyguard telling it the screen just turned on. |
| 989 | * @see #onScreenTurnedOff(int) |
| 990 | * @see #handleNotifyScreenOff |
| 991 | */ |
| 992 | private void notifyScreenOffLocked() { |
| 993 | if (DEBUG) Log.d(TAG, "notifyScreenOffLocked"); |
| 994 | mHandler.sendEmptyMessage(NOTIFY_SCREEN_OFF); |
| 995 | } |
| 996 | |
| 997 | /** |
| 998 | * Send a message to keyguard telling it the screen just turned on. |
Jim Miller | 9c20d0e9 | 2010-01-20 15:00:23 -0800 | [diff] [blame] | 999 | * @see #onScreenTurnedOn() |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1000 | * @see #handleNotifyScreenOn |
| 1001 | */ |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 1002 | private void notifyScreenOnLocked(IKeyguardShowCallback result) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1003 | if (DEBUG) Log.d(TAG, "notifyScreenOnLocked"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1004 | Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_ON, result); |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 1005 | mHandler.sendMessage(msg); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1009 | * Send message to keyguard telling it to show itself |
| 1010 | * @see #handleShow() |
| 1011 | */ |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1012 | private void showLocked(Bundle options) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1013 | if (DEBUG) Log.d(TAG, "showLocked"); |
Mike Lockwood | 674d3e4 | 2009-10-06 09:28:54 -0400 | [diff] [blame] | 1014 | // ensure we stay awake until we are finished displaying the keyguard |
| 1015 | mShowKeyguardWakeLock.acquire(); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1016 | Message msg = mHandler.obtainMessage(SHOW, options); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1017 | mHandler.sendMessage(msg); |
| 1018 | } |
| 1019 | |
| 1020 | /** |
| 1021 | * Send message to keyguard telling it to hide itself |
Jim Miller | 9c20d0e9 | 2010-01-20 15:00:23 -0800 | [diff] [blame] | 1022 | * @see #handleHide() |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1023 | */ |
| 1024 | private void hideLocked() { |
| 1025 | if (DEBUG) Log.d(TAG, "hideLocked"); |
| 1026 | Message msg = mHandler.obtainMessage(HIDE); |
| 1027 | mHandler.sendMessage(msg); |
| 1028 | } |
| 1029 | |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 1030 | public boolean isSecure() { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1031 | return mLockPatternUtils.isSecure() |
| 1032 | || KeyguardUpdateMonitor.getInstance(mContext).isSimPinSecure(); |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 1033 | } |
Jim Miller | 9c20d0e9 | 2010-01-20 15:00:23 -0800 | [diff] [blame] | 1034 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 1035 | /** |
| 1036 | * Update the newUserId. Call while holding WindowManagerService lock. |
Jim Miller | ee82f8f | 2012-10-01 16:26:18 -0700 | [diff] [blame] | 1037 | * NOTE: Should only be called by KeyguardViewMediator in response to the user id changing. |
| 1038 | * |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 1039 | * @param newUserId The id of the incoming user. |
| 1040 | */ |
| 1041 | public void setCurrentUser(int newUserId) { |
| 1042 | mLockPatternUtils.setCurrentUser(newUserId); |
| 1043 | } |
| 1044 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1045 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 1046 | @Override |
| 1047 | public void onReceive(Context context, Intent intent) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1048 | if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) { |
| 1049 | final int sequence = intent.getIntExtra("seq", 0); |
Jim Miller | f344735 | 2011-08-07 14:00:09 -0700 | [diff] [blame] | 1050 | if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = " |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1051 | + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 1052 | synchronized (KeyguardViewMediator.this) { |
| 1053 | if (mDelayedShowingSequence == sequence) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1054 | // Don't play lockscreen SFX if the screen went off due to timeout. |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 1055 | mSuppressNextLockSound = true; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1056 | doKeyguardLocked(null); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 1057 | } |
Daniel Sandler | f2d8e74 | 2010-02-22 13:09:48 -0500 | [diff] [blame] | 1058 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1059 | } |
| 1060 | } |
| 1061 | }; |
| 1062 | |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 1063 | public void keyguardDone(boolean authenticated, boolean wakeup) { |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1064 | if (DEBUG) Log.d(TAG, "keyguardDone(" + authenticated + ")"); |
| 1065 | EventLog.writeEvent(70000, 2); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1066 | synchronized (this) { |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1067 | mKeyguardDonePending = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1068 | } |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1069 | Message msg = mHandler.obtainMessage(KEYGUARD_DONE, authenticated ? 1 : 0, wakeup ? 1 : 0); |
| 1070 | mHandler.sendMessage(msg); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1074 | * This handler will be associated with the policy thread, which will also |
| 1075 | * be the UI thread of the keyguard. Since the apis of the policy, and therefore |
| 1076 | * this class, can be called by other threads, any action that directly |
| 1077 | * interacts with the keyguard ui should be posted to this handler, rather |
| 1078 | * than called directly. |
| 1079 | */ |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1080 | private Handler mHandler = new Handler(Looper.myLooper(), null, true /*async*/) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1081 | @Override |
Wink Saville | 37c124c | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 1082 | public void handleMessage(Message msg) { |
| 1083 | switch (msg.what) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1084 | case SHOW: |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1085 | handleShow((Bundle) msg.obj); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1086 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1087 | case HIDE: |
| 1088 | handleHide(); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1089 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1090 | case RESET: |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1091 | handleReset((Bundle) msg.obj); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1092 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1093 | case VERIFY_UNLOCK: |
| 1094 | handleVerifyUnlock(); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1095 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1096 | case NOTIFY_SCREEN_OFF: |
| 1097 | handleNotifyScreenOff(); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1098 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1099 | case NOTIFY_SCREEN_ON: |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 1100 | handleNotifyScreenOn((IKeyguardShowCallback) msg.obj); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1101 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1102 | case KEYGUARD_DONE: |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 1103 | handleKeyguardDone(msg.arg1 != 0, msg.arg2 != 0); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1104 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1105 | case KEYGUARD_DONE_DRAWING: |
| 1106 | handleKeyguardDoneDrawing(); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1107 | break; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1108 | case KEYGUARD_DONE_AUTHENTICATING: |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1109 | keyguardDone(true, true); |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1110 | break; |
Mike Lockwood | 9200a39 | 2009-11-17 20:25:58 -0500 | [diff] [blame] | 1111 | case SET_HIDDEN: |
| 1112 | handleSetHidden(msg.arg1 != 0); |
| 1113 | break; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 1114 | case KEYGUARD_TIMEOUT: |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 1115 | synchronized (KeyguardViewMediator.this) { |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1116 | doKeyguardLocked((Bundle) msg.obj); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 1117 | } |
| 1118 | break; |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 1119 | case SHOW_ASSISTANT: |
| 1120 | handleShowAssistant(); |
| 1121 | break; |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 1122 | case DISPATCH_EVENT: |
| 1123 | handleDispatchEvent((MotionEvent) msg.obj); |
| 1124 | break; |
Jim Miller | 138f25d | 2013-09-25 13:46:58 -0700 | [diff] [blame] | 1125 | case LAUNCH_CAMERA: |
| 1126 | handleLaunchCamera(); |
| 1127 | break; |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1128 | case DISMISS: |
| 1129 | handleDismiss(); |
| 1130 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1131 | } |
| 1132 | } |
| 1133 | }; |
| 1134 | |
| 1135 | /** |
| 1136 | * @see #keyguardDone |
| 1137 | * @see #KEYGUARD_DONE |
| 1138 | */ |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 1139 | private void handleKeyguardDone(boolean authenticated, boolean wakeup) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1140 | if (DEBUG) Log.d(TAG, "handleKeyguardDone"); |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 1141 | |
| 1142 | if (authenticated) { |
| 1143 | mUpdateMonitor.clearFailedUnlockAttempts(); |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 1144 | } |
Jeff Sharkey | 6a25cbd | 2012-08-23 12:14:26 -0700 | [diff] [blame] | 1145 | |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 1146 | if (mExitSecureCallback != null) { |
| 1147 | try { |
| 1148 | mExitSecureCallback.onKeyguardExitResult(authenticated); |
| 1149 | } catch (RemoteException e) { |
| 1150 | Slog.w(TAG, "Failed to call onKeyguardExitResult(" + authenticated + ")", e); |
| 1151 | } |
| 1152 | |
| 1153 | mExitSecureCallback = null; |
| 1154 | |
| 1155 | if (authenticated) { |
| 1156 | // after succesfully exiting securely, no need to reshow |
| 1157 | // the keyguard when they've released the lock |
| 1158 | mExternallyEnabled = true; |
| 1159 | mNeedToReshowWhenReenabled = false; |
| 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | handleHide(); |
Jim Miller | 3fd47af | 2012-09-21 19:55:27 -0700 | [diff] [blame] | 1164 | sendUserPresentBroadcast(); |
| 1165 | } |
| 1166 | |
Jim Miller | 138f25d | 2013-09-25 13:46:58 -0700 | [diff] [blame] | 1167 | protected void handleLaunchCamera() { |
| 1168 | mKeyguardViewManager.launchCamera(); |
| 1169 | } |
| 1170 | |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 1171 | protected void handleDispatchEvent(MotionEvent event) { |
| 1172 | mKeyguardViewManager.dispatch(event); |
| 1173 | } |
| 1174 | |
Jim Miller | 3fd47af | 2012-09-21 19:55:27 -0700 | [diff] [blame] | 1175 | private void sendUserPresentBroadcast() { |
Jim Miller | 17f509a | 2013-02-28 18:36:12 -0800 | [diff] [blame] | 1176 | final UserHandle currentUser = new UserHandle(mLockPatternUtils.getCurrentUser()); |
| 1177 | mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, currentUser); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | /** |
| 1181 | * @see #keyguardDoneDrawing |
| 1182 | * @see #KEYGUARD_DONE_DRAWING |
| 1183 | */ |
| 1184 | private void handleKeyguardDoneDrawing() { |
| 1185 | synchronized(this) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1186 | if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1187 | if (mWaitingUntilKeyguardVisible) { |
| 1188 | if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing: notifying mWaitingUntilKeyguardVisible"); |
| 1189 | mWaitingUntilKeyguardVisible = false; |
| 1190 | notifyAll(); |
| 1191 | |
| 1192 | // there will usually be two of these sent, one as a timeout, and one |
| 1193 | // as a result of the callback, so remove any remaining messages from |
| 1194 | // the queue |
| 1195 | mHandler.removeMessages(KEYGUARD_DONE_DRAWING); |
| 1196 | } |
| 1197 | } |
| 1198 | } |
| 1199 | |
Daniel Sandler | db783bd | 2010-02-11 15:27:37 -0500 | [diff] [blame] | 1200 | private void playSounds(boolean locked) { |
| 1201 | // User feedback for keyguard. |
Daniel Sandler | 0060a9b | 2010-03-15 23:09:57 -0400 | [diff] [blame] | 1202 | |
| 1203 | if (mSuppressNextLockSound) { |
| 1204 | mSuppressNextLockSound = false; |
| 1205 | return; |
| 1206 | } |
| 1207 | |
Daniel Sandler | db783bd | 2010-02-11 15:27:37 -0500 | [diff] [blame] | 1208 | final ContentResolver cr = mContext.getContentResolver(); |
Amith Yamasani | 8cb751b | 2011-09-30 15:39:41 -0700 | [diff] [blame] | 1209 | if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) { |
Marco Nelissen | d5545bd | 2011-09-29 12:49:17 -0700 | [diff] [blame] | 1210 | final int whichSound = locked |
| 1211 | ? mLockSoundId |
| 1212 | : mUnlockSoundId; |
| 1213 | mLockSounds.stop(mLockSoundStreamId); |
Amith Yamasani | 8cb751b | 2011-09-30 15:39:41 -0700 | [diff] [blame] | 1214 | // Init mAudioManager |
| 1215 | if (mAudioManager == null) { |
| 1216 | mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); |
| 1217 | if (mAudioManager == null) return; |
Eric Laurent | 6d51766 | 2012-04-23 18:42:39 -0700 | [diff] [blame] | 1218 | mMasterStreamType = mAudioManager.getMasterStreamType(); |
Amith Yamasani | 8cb751b | 2011-09-30 15:39:41 -0700 | [diff] [blame] | 1219 | } |
| 1220 | // If the stream is muted, don't play the sound |
Eric Laurent | 6d51766 | 2012-04-23 18:42:39 -0700 | [diff] [blame] | 1221 | if (mAudioManager.isStreamMute(mMasterStreamType)) return; |
Amith Yamasani | 8cb751b | 2011-09-30 15:39:41 -0700 | [diff] [blame] | 1222 | |
Jean-Michel Trivi | c55b393 | 2012-06-05 11:57:59 -0700 | [diff] [blame] | 1223 | mLockSoundStreamId = mLockSounds.play(whichSound, |
| 1224 | mLockSoundVolume, mLockSoundVolume, 1/*priortiy*/, 0/*loop*/, 1.0f/*rate*/); |
Daniel Sandler | db783bd | 2010-02-11 15:27:37 -0500 | [diff] [blame] | 1225 | } |
Jim Miller | 2a98a4c | 2010-11-19 18:49:26 -0800 | [diff] [blame] | 1226 | } |
Daniel Sandler | db783bd | 2010-02-11 15:27:37 -0500 | [diff] [blame] | 1227 | |
Dianne Hackborn | ff5b158 | 2012-04-12 17:24:07 -0700 | [diff] [blame] | 1228 | private void updateActivityLockScreenState() { |
| 1229 | try { |
Jim Miller | 6001379 | 2013-10-03 18:31:34 -0700 | [diff] [blame] | 1230 | ActivityManagerNative.getDefault().setLockScreenShown(mShowing && !mHidden); |
Dianne Hackborn | ff5b158 | 2012-04-12 17:24:07 -0700 | [diff] [blame] | 1231 | } catch (RemoteException e) { |
| 1232 | } |
| 1233 | } |
| 1234 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1235 | /** |
| 1236 | * Handle message sent by {@link #showLocked}. |
| 1237 | * @see #SHOW |
| 1238 | */ |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1239 | private void handleShow(Bundle options) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1240 | synchronized (KeyguardViewMediator.this) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1241 | if (!mSystemReady) { |
| 1242 | if (DEBUG) Log.d(TAG, "ignoring handleShow because system is not ready."); |
| 1243 | return; |
| 1244 | } else { |
| 1245 | if (DEBUG) Log.d(TAG, "handleShow"); |
| 1246 | } |
Jim Miller | 9c20d0e9 | 2010-01-20 15:00:23 -0800 | [diff] [blame] | 1247 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1248 | mKeyguardViewManager.show(options); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1249 | mShowing = true; |
John Spurlock | 14adfe4 | 2012-11-08 10:29:26 -0500 | [diff] [blame] | 1250 | mKeyguardDonePending = false; |
Dianne Hackborn | ff5b158 | 2012-04-12 17:24:07 -0700 | [diff] [blame] | 1251 | updateActivityLockScreenState(); |
Mike Lockwood | 5f892c1 | 2009-11-19 23:39:13 -0500 | [diff] [blame] | 1252 | adjustStatusBarLocked(); |
Jeff Brown | 3dc524b | 2012-09-30 19:49:11 -0700 | [diff] [blame] | 1253 | userActivity(); |
Dianne Hackborn | 4994c66 | 2009-09-23 22:21:23 -0700 | [diff] [blame] | 1254 | try { |
| 1255 | ActivityManagerNative.getDefault().closeSystemDialogs("lock"); |
| 1256 | } catch (RemoteException e) { |
| 1257 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 1258 | |
| 1259 | // Do this at the end to not slow down display of the keyguard. |
| 1260 | playSounds(true); |
| 1261 | |
Mike Lockwood | 674d3e4 | 2009-10-06 09:28:54 -0400 | [diff] [blame] | 1262 | mShowKeyguardWakeLock.release(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1263 | } |
Jim Miller | 3192148f | 2013-11-06 20:43:55 -0800 | [diff] [blame] | 1264 | mKeyguardDisplayManager.show(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | /** |
| 1268 | * Handle message sent by {@link #hideLocked()} |
| 1269 | * @see #HIDE |
| 1270 | */ |
| 1271 | private void handleHide() { |
| 1272 | synchronized (KeyguardViewMediator.this) { |
| 1273 | if (DEBUG) Log.d(TAG, "handleHide"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1274 | |
Daniel Sandler | f2d8e74 | 2010-02-22 13:09:48 -0500 | [diff] [blame] | 1275 | // only play "unlock" noises if not on a call (since the incall UI |
| 1276 | // disables the keyguard) |
| 1277 | if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState)) { |
| 1278 | playSounds(false); |
| 1279 | } |
Daniel Sandler | db783bd | 2010-02-11 15:27:37 -0500 | [diff] [blame] | 1280 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1281 | mKeyguardViewManager.hide(); |
| 1282 | mShowing = false; |
John Spurlock | 14adfe4 | 2012-11-08 10:29:26 -0500 | [diff] [blame] | 1283 | mKeyguardDonePending = false; |
Dianne Hackborn | ff5b158 | 2012-04-12 17:24:07 -0700 | [diff] [blame] | 1284 | updateActivityLockScreenState(); |
Mike Lockwood | 5f892c1 | 2009-11-19 23:39:13 -0500 | [diff] [blame] | 1285 | adjustStatusBarLocked(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1286 | } |
| 1287 | } |
| 1288 | |
Mike Lockwood | 5f892c1 | 2009-11-19 23:39:13 -0500 | [diff] [blame] | 1289 | private void adjustStatusBarLocked() { |
| 1290 | if (mStatusBarManager == null) { |
| 1291 | mStatusBarManager = (StatusBarManager) |
| 1292 | mContext.getSystemService(Context.STATUS_BAR_SERVICE); |
| 1293 | } |
| 1294 | if (mStatusBarManager == null) { |
| 1295 | Log.w(TAG, "Could not get status bar manager"); |
| 1296 | } else { |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 1297 | // Disable aspects of the system/status/navigation bars that must not be re-enabled by |
| 1298 | // windows that appear on top, ever |
Jeff Sharkey | f52c70b | 2011-08-30 22:05:47 -0700 | [diff] [blame] | 1299 | int flags = StatusBarManager.DISABLE_NONE; |
Mike Lockwood | e3646dd | 2011-09-01 12:46:28 -0400 | [diff] [blame] | 1300 | if (mShowing) { |
Jim Miller | e23ab8b | 2012-09-16 15:45:44 -0700 | [diff] [blame] | 1301 | // Permanently disable components not available when keyguard is enabled |
| 1302 | // (like recents). Temporary enable/disable (e.g. the "back" button) are |
| 1303 | // done in KeyguardHostView. |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 1304 | flags |= StatusBarManager.DISABLE_RECENT; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1305 | if ((isSecure() && !mAllowNotificationsWhenSecure) |
| 1306 | || !ENABLE_INSECURE_STATUS_BAR_EXPAND) { |
Mike Lockwood | e3646dd | 2011-09-01 12:46:28 -0400 | [diff] [blame] | 1307 | // showing secure lockscreen; disable expanding. |
| 1308 | flags |= StatusBarManager.DISABLE_EXPAND; |
| 1309 | } |
Jeff Sharkey | 4519a02 | 2011-09-07 23:24:53 -0700 | [diff] [blame] | 1310 | if (isSecure()) { |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1311 | // showing secure lockscreen; disable ticker and switch private notifications |
| 1312 | // to show their public versions, if available. |
| 1313 | flags |= StatusBarManager.DISABLE_PRIVATE_NOTIFICATIONS; |
Jeff Sharkey | 4519a02 | 2011-09-07 23:24:53 -0700 | [diff] [blame] | 1314 | } |
John Spurlock | 43d8451 | 2012-11-09 10:27:33 -0500 | [diff] [blame] | 1315 | if (!isAssistantAvailable()) { |
| 1316 | flags |= StatusBarManager.DISABLE_SEARCH; |
| 1317 | } |
Jeff Sharkey | f52c70b | 2011-08-30 22:05:47 -0700 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | if (DEBUG) { |
Jeff Sharkey | 4519a02 | 2011-09-07 23:24:53 -0700 | [diff] [blame] | 1321 | Log.d(TAG, "adjustStatusBarLocked: mShowing=" + mShowing + " mHidden=" + mHidden |
| 1322 | + " isSecure=" + isSecure() + " --> flags=0x" + Integer.toHexString(flags)); |
Jeff Sharkey | f52c70b | 2011-08-30 22:05:47 -0700 | [diff] [blame] | 1323 | } |
| 1324 | |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 1325 | if (!(mContext instanceof Activity)) { |
| 1326 | mStatusBarManager.disable(flags); |
| 1327 | } |
Mike Lockwood | 5f892c1 | 2009-11-19 23:39:13 -0500 | [diff] [blame] | 1328 | } |
| 1329 | } |
| 1330 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1331 | /** |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1332 | * Handle message sent by {@link #resetStateLocked(Bundle)} |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1333 | * @see #RESET |
| 1334 | */ |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1335 | private void handleReset(Bundle options) { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 1336 | if (options == null) { |
| 1337 | options = new Bundle(); |
| 1338 | } |
| 1339 | options.putBoolean(KeyguardViewManager.IS_SWITCHING_USER, mSwitchingUser); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1340 | synchronized (KeyguardViewMediator.this) { |
| 1341 | if (DEBUG) Log.d(TAG, "handleReset"); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 1342 | mKeyguardViewManager.reset(options); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | /** |
| 1347 | * Handle message sent by {@link #verifyUnlock} |
Craig Mautner | 904732c | 2012-10-17 15:20:24 -0700 | [diff] [blame] | 1348 | * @see #VERIFY_UNLOCK |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1349 | */ |
| 1350 | private void handleVerifyUnlock() { |
| 1351 | synchronized (KeyguardViewMediator.this) { |
| 1352 | if (DEBUG) Log.d(TAG, "handleVerifyUnlock"); |
| 1353 | mKeyguardViewManager.verifyUnlock(); |
| 1354 | mShowing = true; |
Dianne Hackborn | ff5b158 | 2012-04-12 17:24:07 -0700 | [diff] [blame] | 1355 | updateActivityLockScreenState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | /** |
| 1360 | * Handle message sent by {@link #notifyScreenOffLocked()} |
| 1361 | * @see #NOTIFY_SCREEN_OFF |
| 1362 | */ |
| 1363 | private void handleNotifyScreenOff() { |
| 1364 | synchronized (KeyguardViewMediator.this) { |
| 1365 | if (DEBUG) Log.d(TAG, "handleNotifyScreenOff"); |
| 1366 | mKeyguardViewManager.onScreenTurnedOff(); |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | /** |
| 1371 | * Handle message sent by {@link #notifyScreenOnLocked()} |
| 1372 | * @see #NOTIFY_SCREEN_ON |
| 1373 | */ |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 1374 | private void handleNotifyScreenOn(IKeyguardShowCallback callback) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1375 | synchronized (KeyguardViewMediator.this) { |
| 1376 | if (DEBUG) Log.d(TAG, "handleNotifyScreenOn"); |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 1377 | mKeyguardViewManager.onScreenTurnedOn(callback); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1378 | } |
| 1379 | } |
Jeff Sharkey | 054340d | 2011-09-01 22:28:03 -0700 | [diff] [blame] | 1380 | |
John Spurlock | 34c4fe5 | 2012-11-07 10:12:29 -0500 | [diff] [blame] | 1381 | public boolean isDismissable() { |
| 1382 | return mKeyguardDonePending || !isSecure(); |
| 1383 | } |
| 1384 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 1385 | public void showAssistant() { |
| 1386 | Message msg = mHandler.obtainMessage(SHOW_ASSISTANT); |
| 1387 | mHandler.sendMessage(msg); |
| 1388 | } |
| 1389 | |
| 1390 | public void handleShowAssistant() { |
| 1391 | mKeyguardViewManager.showAssistant(); |
| 1392 | } |
| 1393 | |
John Spurlock | 43d8451 | 2012-11-09 10:27:33 -0500 | [diff] [blame] | 1394 | private boolean isAssistantAvailable() { |
| 1395 | return mSearchManager != null |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1396 | && mSearchManager.getAssistIntent(mContext, false, UserHandle.USER_CURRENT) != null; |
John Spurlock | 43d8451 | 2012-11-09 10:27:33 -0500 | [diff] [blame] | 1397 | } |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 1398 | |
| 1399 | public static MultiUserAvatarCache getAvatarCache() { |
| 1400 | return sMultiUserAvatarCache; |
| 1401 | } |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 1402 | |
| 1403 | public void dispatch(MotionEvent event) { |
| 1404 | Message msg = mHandler.obtainMessage(DISPATCH_EVENT, event); |
| 1405 | mHandler.sendMessage(msg); |
| 1406 | } |
Jim Miller | 138f25d | 2013-09-25 13:46:58 -0700 | [diff] [blame] | 1407 | |
| 1408 | public void launchCamera() { |
| 1409 | Message msg = mHandler.obtainMessage(LAUNCH_CAMERA); |
| 1410 | mHandler.sendMessage(msg); |
| 1411 | } |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 1412 | |
| 1413 | public void onBootCompleted() { |
| 1414 | mUpdateMonitor.dispatchBootCompleted(); |
| 1415 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1416 | } |