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