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