The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 17 | package com.android.keyguard; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 18 | |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 19 | import static android.content.Intent.ACTION_USER_UNLOCKED; |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 20 | import static android.os.BatteryManager.BATTERY_HEALTH_UNKNOWN; |
| 21 | import static android.os.BatteryManager.BATTERY_STATUS_FULL; |
| 22 | import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN; |
| 23 | import static android.os.BatteryManager.EXTRA_HEALTH; |
| 24 | import static android.os.BatteryManager.EXTRA_LEVEL; |
| 25 | import static android.os.BatteryManager.EXTRA_MAX_CHARGING_CURRENT; |
| 26 | import static android.os.BatteryManager.EXTRA_MAX_CHARGING_VOLTAGE; |
| 27 | import static android.os.BatteryManager.EXTRA_PLUGGED; |
| 28 | import static android.os.BatteryManager.EXTRA_STATUS; |
| 29 | |
Jorim Jaggi | ccdfa93 | 2015-04-13 16:29:48 -0700 | [diff] [blame] | 30 | import android.app.ActivityManager; |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 31 | import android.app.AlarmManager; |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 32 | import android.app.PendingIntent; |
Sudheer Shanka | 2c4522c | 2016-08-27 20:53:28 -0700 | [diff] [blame] | 33 | import android.app.UserSwitchObserver; |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 34 | import android.app.admin.DevicePolicyManager; |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 35 | import android.app.trust.TrustManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 36 | import android.content.BroadcastReceiver; |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 37 | import android.content.ComponentName; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 38 | import android.content.Context; |
| 39 | import android.content.Intent; |
| 40 | import android.content.IntentFilter; |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 41 | import android.content.pm.PackageManager; |
| 42 | import android.content.pm.ResolveInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 43 | import android.database.ContentObserver; |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 44 | import android.graphics.Bitmap; |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 45 | import android.hardware.fingerprint.FingerprintManager; |
| 46 | import android.hardware.fingerprint.FingerprintManager.AuthenticationCallback; |
| 47 | import android.hardware.fingerprint.FingerprintManager.AuthenticationResult; |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 48 | import android.media.AudioManager; |
Jim Miller | 79a444a | 2011-02-15 15:02:11 -0800 | [diff] [blame] | 49 | import android.os.BatteryManager; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 50 | import android.os.CancellationSignal; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 51 | import android.os.Handler; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 52 | import android.os.IRemoteCallback; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 53 | import android.os.Message; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 54 | import android.os.RemoteException; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 55 | import android.os.SystemClock; |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 56 | import android.os.Trace; |
Amith Yamasani | e8e93a1 | 2013-05-09 18:12:30 -0700 | [diff] [blame] | 57 | import android.os.UserHandle; |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 58 | import android.os.UserManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 59 | import android.provider.Settings; |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 60 | import android.telephony.ServiceState; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 61 | import android.telephony.SubscriptionInfo; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 62 | import android.telephony.SubscriptionManager; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 63 | import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener; |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 64 | import android.telephony.TelephonyManager; |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 65 | import android.util.ArraySet; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 66 | import android.util.Log; |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 67 | import android.util.SparseBooleanArray; |
Jorim Jaggi | 9f74303 | 2015-05-04 15:22:40 -0700 | [diff] [blame] | 68 | import android.util.SparseIntArray; |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 69 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 70 | import com.google.android.collect.Lists; |
| 71 | |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 72 | import com.android.internal.telephony.IccCardConstants; |
| 73 | import com.android.internal.telephony.IccCardConstants.State; |
| 74 | import com.android.internal.telephony.PhoneConstants; |
| 75 | import com.android.internal.telephony.TelephonyIntents; |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 76 | import com.android.internal.widget.LockPatternUtils; |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 77 | |
Jason Monk | ab52527 | 2015-07-13 17:02:49 -0400 | [diff] [blame] | 78 | import java.io.FileDescriptor; |
| 79 | import java.io.PrintWriter; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 80 | import java.lang.ref.WeakReference; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 81 | import java.util.ArrayList; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 82 | import java.util.HashMap; |
| 83 | import java.util.List; |
| 84 | import java.util.Map.Entry; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * Watches for updates that may be interesting to the keyguard, and provides |
| 88 | * the up to date information as well as a registration for callbacks that care |
| 89 | * to be updated. |
| 90 | * |
| 91 | * Note: under time crunch, this has been extended to include some stuff that |
| 92 | * doesn't really belong here. see {@link #handleBatteryUpdate} where it shutdowns |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 93 | * the device, and {@link #getFailedUnlockAttempts()}, {@link #reportFailedAttempt()} |
| 94 | * and {@link #clearFailedUnlockAttempts()}. Maybe we should rename this 'KeyguardContext'... |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 95 | */ |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 96 | public class KeyguardUpdateMonitor implements TrustManager.TrustListener { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 97 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 98 | private static final String TAG = "KeyguardUpdateMonitor"; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 99 | private static final boolean DEBUG = KeyguardConstants.DEBUG; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 100 | private static final boolean DEBUG_SIM_STATES = KeyguardConstants.DEBUG_SIM_STATES; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 101 | private static final int LOW_BATTERY_THRESHOLD = 20; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 102 | |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 103 | private static final String ACTION_FACE_UNLOCK_STARTED |
| 104 | = "com.android.facelock.FACE_UNLOCK_STARTED"; |
| 105 | private static final String ACTION_FACE_UNLOCK_STOPPED |
| 106 | = "com.android.facelock.FACE_UNLOCK_STOPPED"; |
| 107 | |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 108 | private static final String ACTION_STRONG_AUTH_TIMEOUT = |
| 109 | "com.android.systemui.ACTION_STRONG_AUTH_TIMEOUT"; |
| 110 | private static final String USER_ID = "com.android.systemui.USER_ID"; |
| 111 | |
| 112 | private static final String PERMISSION_SELF = "com.android.systemui.permission.SELF"; |
| 113 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 114 | // Callback messages |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 115 | private static final int MSG_TIME_UPDATE = 301; |
| 116 | private static final int MSG_BATTERY_UPDATE = 302; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 117 | private static final int MSG_SIM_STATE_CHANGE = 304; |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 118 | private static final int MSG_RINGER_MODE_CHANGED = 305; |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 119 | private static final int MSG_PHONE_STATE_CHANGED = 306; |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 120 | private static final int MSG_DEVICE_PROVISIONED = 308; |
Jim Miller | 5737534 | 2012-09-09 15:20:31 -0700 | [diff] [blame] | 121 | private static final int MSG_DPM_STATE_CHANGED = 309; |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 122 | private static final int MSG_USER_SWITCHING = 310; |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 123 | private static final int MSG_KEYGUARD_RESET = 312; |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 124 | private static final int MSG_BOOT_COMPLETED = 313; |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 125 | private static final int MSG_USER_SWITCH_COMPLETE = 314; |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 126 | private static final int MSG_USER_INFO_CHANGED = 317; |
| 127 | private static final int MSG_REPORT_EMERGENCY_CALL_ACTION = 318; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 128 | private static final int MSG_STARTED_WAKING_UP = 319; |
| 129 | private static final int MSG_FINISHED_GOING_TO_SLEEP = 320; |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 130 | private static final int MSG_STARTED_GOING_TO_SLEEP = 321; |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 131 | private static final int MSG_KEYGUARD_BOUNCER_CHANGED = 322; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 132 | private static final int MSG_FACE_UNLOCK_STATE_CHANGED = 327; |
| 133 | private static final int MSG_SIM_SUBSCRIPTION_INFO_CHANGED = 328; |
Jason Monk | 052082c | 2015-06-11 11:35:23 -0400 | [diff] [blame] | 134 | private static final int MSG_AIRPLANE_MODE_CHANGED = 329; |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 135 | private static final int MSG_SERVICE_STATE_CHANGE = 330; |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 136 | private static final int MSG_SCREEN_TURNED_ON = 331; |
| 137 | private static final int MSG_SCREEN_TURNED_OFF = 332; |
Selim Cinek | 9941539 | 2016-09-09 14:58:41 -0700 | [diff] [blame] | 138 | private static final int MSG_DREAMING_STATE_CHANGED = 333; |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 139 | private static final int MSG_USER_UNLOCKED = 334; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 140 | |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 141 | /** Fingerprint state: Not listening to fingerprint. */ |
| 142 | private static final int FINGERPRINT_STATE_STOPPED = 0; |
| 143 | |
| 144 | /** Fingerprint state: Listening. */ |
| 145 | private static final int FINGERPRINT_STATE_RUNNING = 1; |
| 146 | |
| 147 | /** |
| 148 | * Fingerprint state: Cancelling and waiting for the confirmation from FingerprintService to |
| 149 | * send us the confirmation that cancellation has happened. |
| 150 | */ |
| 151 | private static final int FINGERPRINT_STATE_CANCELLING = 2; |
| 152 | |
| 153 | /** |
| 154 | * Fingerprint state: During cancelling we got another request to start listening, so when we |
| 155 | * receive the cancellation done signal, we should start listening again. |
| 156 | */ |
| 157 | private static final int FINGERPRINT_STATE_CANCELLING_RESTARTING = 3; |
| 158 | |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 159 | private static final int DEFAULT_CHARGING_VOLTAGE_MICRO_VOLT = 5000000; |
| 160 | |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 161 | private static final ComponentName FALLBACK_HOME_COMPONENT = new ComponentName( |
| 162 | "com.android.settings", "com.android.settings.FallbackHome"); |
| 163 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 164 | private static KeyguardUpdateMonitor sInstance; |
| 165 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 166 | private final Context mContext; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 167 | HashMap<Integer, SimData> mSimDatas = new HashMap<Integer, SimData>(); |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 168 | HashMap<Integer, ServiceState> mServiceStates = new HashMap<Integer, ServiceState>(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 169 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 170 | private int mRingMode; |
| 171 | private int mPhoneState; |
Danielle Millett | 5d2404d | 2012-11-01 00:05:27 -0400 | [diff] [blame] | 172 | private boolean mKeyguardIsVisible; |
Jorim Jaggi | 71448a7 | 2015-08-18 19:49:04 -0700 | [diff] [blame] | 173 | |
| 174 | /** |
| 175 | * If true, fingerprint was already authenticated and we don't need to start listening again |
| 176 | * until the Keyguard has been dismissed. |
| 177 | */ |
| 178 | private boolean mFingerprintAlreadyAuthenticated; |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 179 | private boolean mGoingToSleep; |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 180 | private boolean mBouncer; |
Adam Cohen | 4eb36cf | 2012-11-07 11:45:30 -0800 | [diff] [blame] | 181 | private boolean mBootCompleted; |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 182 | private boolean mNeedsSlowUnlockTransition; |
Jorim Jaggi | d11d1a9 | 2016-08-16 16:02:32 -0700 | [diff] [blame] | 183 | private boolean mHasLockscreenWallpaper; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 184 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 185 | // Device provisioning state |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 186 | private boolean mDeviceProvisioned; |
| 187 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 188 | // Battery status |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 189 | private BatteryStatus mBatteryStatus; |
| 190 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 191 | // Password attempts |
Jorim Jaggi | 9f74303 | 2015-05-04 15:22:40 -0700 | [diff] [blame] | 192 | private SparseIntArray mFailedAttempts = new SparseIntArray(); |
Brian Colonna | cc4104f | 2012-10-09 17:50:46 -0400 | [diff] [blame] | 193 | |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 194 | /** Tracks whether strong authentication hasn't been used since quite some time per user. */ |
Adrian Roos | 1de8bcb | 2015-08-19 16:52:52 -0700 | [diff] [blame] | 195 | private ArraySet<Integer> mStrongAuthNotTimedOut = new ArraySet<>(); |
Rakesh Iyer | a7aa4d6 | 2016-01-19 17:27:23 -0800 | [diff] [blame] | 196 | private final StrongAuthTracker mStrongAuthTracker; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 197 | |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 198 | private final ArrayList<WeakReference<KeyguardUpdateMonitorCallback>> |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 199 | mCallbacks = Lists.newArrayList(); |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 200 | private ContentObserver mDeviceProvisionedObserver; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 201 | |
Brian Colonna | a523989 | 2013-04-15 11:45:40 -0400 | [diff] [blame] | 202 | private boolean mSwitchingUser; |
| 203 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 204 | private boolean mDeviceInteractive; |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 205 | private boolean mScreenOn; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 206 | private SubscriptionManager mSubscriptionManager; |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 207 | private AlarmManager mAlarmManager; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 208 | private List<SubscriptionInfo> mSubscriptionInfo; |
Jorim Jaggi | 237b061 | 2015-05-01 14:28:49 -0700 | [diff] [blame] | 209 | private TrustManager mTrustManager; |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 210 | private UserManager mUserManager; |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 211 | private int mFingerprintRunningState = FINGERPRINT_STATE_STOPPED; |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 212 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 213 | private final Handler mHandler = new Handler() { |
| 214 | @Override |
| 215 | public void handleMessage(Message msg) { |
| 216 | switch (msg.what) { |
| 217 | case MSG_TIME_UPDATE: |
| 218 | handleTimeUpdate(); |
| 219 | break; |
| 220 | case MSG_BATTERY_UPDATE: |
| 221 | handleBatteryUpdate((BatteryStatus) msg.obj); |
| 222 | break; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 223 | case MSG_SIM_STATE_CHANGE: |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 224 | handleSimStateChange(msg.arg1, msg.arg2, (State) msg.obj); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 225 | break; |
| 226 | case MSG_RINGER_MODE_CHANGED: |
| 227 | handleRingerModeChange(msg.arg1); |
| 228 | break; |
| 229 | case MSG_PHONE_STATE_CHANGED: |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 230 | handlePhoneStateChanged((String) msg.obj); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 231 | break; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 232 | case MSG_DEVICE_PROVISIONED: |
| 233 | handleDeviceProvisioned(); |
| 234 | break; |
| 235 | case MSG_DPM_STATE_CHANGED: |
| 236 | handleDevicePolicyManagerStateChanged(); |
| 237 | break; |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 238 | case MSG_USER_SWITCHING: |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 239 | handleUserSwitching(msg.arg1, (IRemoteCallback) msg.obj); |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 240 | break; |
| 241 | case MSG_USER_SWITCH_COMPLETE: |
| 242 | handleUserSwitchComplete(msg.arg1); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 243 | break; |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 244 | case MSG_KEYGUARD_RESET: |
| 245 | handleKeyguardReset(); |
| 246 | break; |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 247 | case MSG_KEYGUARD_BOUNCER_CHANGED: |
| 248 | handleKeyguardBouncerChanged(msg.arg1); |
| 249 | break; |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 250 | case MSG_BOOT_COMPLETED: |
| 251 | handleBootCompleted(); |
| 252 | break; |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 253 | case MSG_USER_INFO_CHANGED: |
| 254 | handleUserInfoChanged(msg.arg1); |
| 255 | break; |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 256 | case MSG_REPORT_EMERGENCY_CALL_ACTION: |
| 257 | handleReportEmergencyCallAction(); |
| 258 | break; |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 259 | case MSG_STARTED_GOING_TO_SLEEP: |
| 260 | handleStartedGoingToSleep(msg.arg1); |
| 261 | break; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 262 | case MSG_FINISHED_GOING_TO_SLEEP: |
| 263 | handleFinishedGoingToSleep(msg.arg1); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 264 | break; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 265 | case MSG_STARTED_WAKING_UP: |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 266 | Trace.beginSection("KeyguardUpdateMonitor#handler MSG_STARTED_WAKING_UP"); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 267 | handleStartedWakingUp(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 268 | Trace.endSection(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 269 | break; |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 270 | case MSG_FACE_UNLOCK_STATE_CHANGED: |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 271 | Trace.beginSection("KeyguardUpdateMonitor#handler MSG_FACE_UNLOCK_STATE_CHANGED"); |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 272 | handleFaceUnlockStateChanged(msg.arg1 != 0, msg.arg2); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 273 | Trace.endSection(); |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 274 | break; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 275 | case MSG_SIM_SUBSCRIPTION_INFO_CHANGED: |
| 276 | handleSimSubscriptionInfoChanged(); |
| 277 | break; |
Jason Monk | 052082c | 2015-06-11 11:35:23 -0400 | [diff] [blame] | 278 | case MSG_AIRPLANE_MODE_CHANGED: |
| 279 | handleAirplaneModeChanged(); |
| 280 | break; |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 281 | case MSG_SERVICE_STATE_CHANGE: |
| 282 | handleServiceStateChange(msg.arg1, (ServiceState) msg.obj); |
| 283 | break; |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 284 | case MSG_SCREEN_TURNED_ON: |
| 285 | handleScreenTurnedOn(); |
| 286 | break; |
| 287 | case MSG_SCREEN_TURNED_OFF: |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 288 | Trace.beginSection("KeyguardUpdateMonitor#handler MSG_SCREEN_TURNED_ON"); |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 289 | handleScreenTurnedOff(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 290 | Trace.endSection(); |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 291 | break; |
Selim Cinek | 9941539 | 2016-09-09 14:58:41 -0700 | [diff] [blame] | 292 | case MSG_DREAMING_STATE_CHANGED: |
| 293 | handleDreamingStateChanged(msg.arg1); |
| 294 | break; |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 295 | case MSG_USER_UNLOCKED: |
| 296 | handleUserUnlocked(); |
| 297 | break; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | }; |
| 301 | |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 302 | private OnSubscriptionsChangedListener mSubscriptionListener = |
| 303 | new OnSubscriptionsChangedListener() { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 304 | @Override |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 305 | public void onSubscriptionsChanged() { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 306 | mHandler.sendEmptyMessage(MSG_SIM_SUBSCRIPTION_INFO_CHANGED); |
| 307 | } |
| 308 | }; |
| 309 | |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 310 | private SparseBooleanArray mUserHasTrust = new SparseBooleanArray(); |
Adrian Roos | 7861c66 | 2014-07-25 15:37:28 +0200 | [diff] [blame] | 311 | private SparseBooleanArray mUserTrustIsManaged = new SparseBooleanArray(); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 312 | private SparseBooleanArray mUserFingerprintAuthenticated = new SparseBooleanArray(); |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 313 | private SparseBooleanArray mUserFaceUnlockRunning = new SparseBooleanArray(); |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 314 | |
Adrian Roos | d6aa6cb | 2015-04-16 19:31:29 -0700 | [diff] [blame] | 315 | private static int sCurrentUser; |
| 316 | |
| 317 | public synchronized static void setCurrentUser(int currentUser) { |
| 318 | sCurrentUser = currentUser; |
| 319 | } |
| 320 | |
| 321 | public synchronized static int getCurrentUser() { |
| 322 | return sCurrentUser; |
| 323 | } |
| 324 | |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 325 | @Override |
Adrian Roos | 94e15a5 | 2015-04-16 12:23:18 -0700 | [diff] [blame] | 326 | public void onTrustChanged(boolean enabled, int userId, int flags) { |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 327 | mUserHasTrust.put(userId, enabled); |
Adrian Roos | 2fe592d | 2014-05-17 03:11:59 +0200 | [diff] [blame] | 328 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 329 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 330 | if (cb != null) { |
| 331 | cb.onTrustChanged(userId); |
Adrian Roos | 94e15a5 | 2015-04-16 12:23:18 -0700 | [diff] [blame] | 332 | if (enabled && flags != 0) { |
| 333 | cb.onTrustGrantedWithFlags(flags, userId); |
Adrian Roos | 3c9a350 | 2014-08-06 19:09:45 +0200 | [diff] [blame] | 334 | } |
Adrian Roos | 2fe592d | 2014-05-17 03:11:59 +0200 | [diff] [blame] | 335 | } |
| 336 | } |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 337 | } |
| 338 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 339 | protected void handleSimSubscriptionInfoChanged() { |
| 340 | if (DEBUG_SIM_STATES) { |
| 341 | Log.v(TAG, "onSubscriptionInfoChanged()"); |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 342 | List<SubscriptionInfo> sil = mSubscriptionManager.getActiveSubscriptionInfoList(); |
| 343 | if (sil != null) { |
| 344 | for (SubscriptionInfo subInfo : sil) { |
| 345 | Log.v(TAG, "SubInfo:" + subInfo); |
| 346 | } |
| 347 | } else { |
| 348 | Log.v(TAG, "onSubscriptionInfoChanged: list is null"); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | List<SubscriptionInfo> subscriptionInfos = getSubscriptionInfo(true /* forceReload */); |
| 352 | |
| 353 | // Hack level over 9000: Because the subscription id is not yet valid when we see the |
| 354 | // first update in handleSimStateChange, we need to force refresh all all SIM states |
| 355 | // so the subscription id for them is consistent. |
Jorim Jaggi | 01ba98b | 2015-01-13 21:33:45 +0100 | [diff] [blame] | 356 | ArrayList<SubscriptionInfo> changedSubscriptions = new ArrayList<>(); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 357 | for (int i = 0; i < subscriptionInfos.size(); i++) { |
| 358 | SubscriptionInfo info = subscriptionInfos.get(i); |
Jorim Jaggi | 01ba98b | 2015-01-13 21:33:45 +0100 | [diff] [blame] | 359 | boolean changed = refreshSimState(info.getSubscriptionId(), info.getSimSlotIndex()); |
| 360 | if (changed) { |
| 361 | changedSubscriptions.add(info); |
| 362 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 363 | } |
Jorim Jaggi | 01ba98b | 2015-01-13 21:33:45 +0100 | [diff] [blame] | 364 | for (int i = 0; i < changedSubscriptions.size(); i++) { |
| 365 | SimData data = mSimDatas.get(changedSubscriptions.get(i).getSubscriptionId()); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 366 | for (int j = 0; j < mCallbacks.size(); j++) { |
| 367 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get(); |
| 368 | if (cb != null) { |
| 369 | cb.onSimStateChanged(data.subId, data.slotId, data.simState); |
| 370 | } |
| 371 | } |
| 372 | } |
Jason Monk | 6c985dc | 2015-01-09 16:07:14 -0500 | [diff] [blame] | 373 | for (int j = 0; j < mCallbacks.size(); j++) { |
| 374 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get(); |
| 375 | if (cb != null) { |
| 376 | cb.onRefreshCarrierInfo(); |
| 377 | } |
| 378 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 379 | } |
| 380 | |
Jason Monk | 052082c | 2015-06-11 11:35:23 -0400 | [diff] [blame] | 381 | private void handleAirplaneModeChanged() { |
| 382 | for (int j = 0; j < mCallbacks.size(); j++) { |
| 383 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get(); |
| 384 | if (cb != null) { |
| 385 | cb.onRefreshCarrierInfo(); |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 390 | /** @return List of SubscriptionInfo records, maybe empty but never null */ |
Adrian Roos | 316bf54 | 2016-08-23 17:53:07 +0200 | [diff] [blame] | 391 | public List<SubscriptionInfo> getSubscriptionInfo(boolean forceReload) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 392 | List<SubscriptionInfo> sil = mSubscriptionInfo; |
| 393 | if (sil == null || forceReload) { |
| 394 | sil = mSubscriptionManager.getActiveSubscriptionInfoList(); |
| 395 | } |
| 396 | if (sil == null) { |
| 397 | // getActiveSubscriptionInfoList was null callers expect an empty list. |
| 398 | mSubscriptionInfo = new ArrayList<SubscriptionInfo>(); |
| 399 | } else { |
| 400 | mSubscriptionInfo = sil; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 401 | } |
| 402 | return mSubscriptionInfo; |
| 403 | } |
| 404 | |
Adrian Roos | 7861c66 | 2014-07-25 15:37:28 +0200 | [diff] [blame] | 405 | @Override |
| 406 | public void onTrustManagedChanged(boolean managed, int userId) { |
| 407 | mUserTrustIsManaged.put(userId, managed); |
| 408 | |
| 409 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 410 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 411 | if (cb != null) { |
| 412 | cb.onTrustManagedChanged(userId); |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 417 | private void onFingerprintAuthenticated(int userId) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 418 | Trace.beginSection("KeyGuardUpdateMonitor#onFingerPrintAuthenticated"); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 419 | mUserFingerprintAuthenticated.put(userId, true); |
Jorim Jaggi | 71448a7 | 2015-08-18 19:49:04 -0700 | [diff] [blame] | 420 | |
| 421 | // If fingerprint unlocking is allowed, this event will lead to a Keyguard dismiss or to a |
| 422 | // wake-up (if Keyguard is not showing), so we don't need to listen until Keyguard is |
| 423 | // fully gone. |
| 424 | mFingerprintAlreadyAuthenticated = isUnlockingWithFingerprintAllowed(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 425 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 426 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 427 | if (cb != null) { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 428 | cb.onFingerprintAuthenticated(userId); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 429 | } |
| 430 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 431 | Trace.endSection(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 434 | private void handleFingerprintAuthFailed() { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 435 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 436 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 437 | if (cb != null) { |
| 438 | cb.onFingerprintAuthFailed(); |
| 439 | } |
Jorim Jaggi | 007f0e8 | 2015-08-14 13:56:01 -0700 | [diff] [blame] | 440 | } |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 441 | handleFingerprintHelp(-1, mContext.getString(R.string.fingerprint_not_recognized)); |
| 442 | } |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 443 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 444 | private void handleFingerprintAcquired(int acquireInfo) { |
| 445 | if (acquireInfo != FingerprintManager.FINGERPRINT_ACQUIRED_GOOD) { |
| 446 | return; |
| 447 | } |
Jorim Jaggi | 007f0e8 | 2015-08-14 13:56:01 -0700 | [diff] [blame] | 448 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 449 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 450 | if (cb != null) { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 451 | cb.onFingerprintAcquired(); |
Jorim Jaggi | 007f0e8 | 2015-08-14 13:56:01 -0700 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | } |
| 455 | |
Jim Miller | 837fa7e | 2016-08-08 20:16:22 -0700 | [diff] [blame] | 456 | private void handleFingerprintAuthenticated(int authUserId) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 457 | Trace.beginSection("KeyGuardUpdateMonitor#handlerFingerPrintAuthenticated"); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 458 | try { |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 459 | final int userId; |
| 460 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 461 | userId = ActivityManager.getService().getCurrentUser().id; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 462 | } catch (RemoteException e) { |
| 463 | Log.e(TAG, "Failed to get current user id: ", e); |
| 464 | return; |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 465 | } |
Jim Miller | 837fa7e | 2016-08-08 20:16:22 -0700 | [diff] [blame] | 466 | if (userId != authUserId) { |
| 467 | Log.d(TAG, "Fingerprint authenticated for wrong user: " + authUserId); |
| 468 | return; |
| 469 | } |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 470 | if (isFingerprintDisabled(userId)) { |
| 471 | Log.d(TAG, "Fingerprint disabled by DPM for userId: " + userId); |
| 472 | return; |
| 473 | } |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 474 | onFingerprintAuthenticated(userId); |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 475 | } finally { |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 476 | setFingerprintRunningState(FINGERPRINT_STATE_STOPPED); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 477 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 478 | Trace.endSection(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 481 | private void handleFingerprintHelp(int msgId, String helpString) { |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 482 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 483 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 484 | if (cb != null) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 485 | cb.onFingerprintHelp(msgId, helpString); |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | private void handleFingerprintError(int msgId, String errString) { |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 491 | if (msgId == FingerprintManager.FINGERPRINT_ERROR_CANCELED |
| 492 | && mFingerprintRunningState == FINGERPRINT_STATE_CANCELLING_RESTARTING) { |
| 493 | setFingerprintRunningState(FINGERPRINT_STATE_STOPPED); |
| 494 | startListeningForFingerprint(); |
| 495 | } else { |
| 496 | setFingerprintRunningState(FINGERPRINT_STATE_STOPPED); |
| 497 | } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 498 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 499 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 500 | if (cb != null) { |
| 501 | cb.onFingerprintError(msgId, errString); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | } |
| 505 | |
Jorim Jaggi | 3a46478 | 2015-08-28 16:59:13 -0700 | [diff] [blame] | 506 | private void handleFingerprintLockoutReset() { |
| 507 | updateFingerprintListeningState(); |
| 508 | } |
| 509 | |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 510 | private void setFingerprintRunningState(int fingerprintRunningState) { |
| 511 | boolean wasRunning = mFingerprintRunningState == FINGERPRINT_STATE_RUNNING; |
| 512 | boolean isRunning = fingerprintRunningState == FINGERPRINT_STATE_RUNNING; |
| 513 | mFingerprintRunningState = fingerprintRunningState; |
| 514 | |
| 515 | // Clients of KeyguardUpdateMonitor don't care about the internal state about the |
| 516 | // asynchronousness of the cancel cycle. So only notify them if the actualy running state |
| 517 | // has changed. |
| 518 | if (wasRunning != isRunning) { |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 519 | notifyFingerprintRunningStateChanged(); |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | private void notifyFingerprintRunningStateChanged() { |
| 524 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 525 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 526 | if (cb != null) { |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 527 | cb.onFingerprintRunningStateChanged(isFingerprintDetectionRunning()); |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | } |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 531 | private void handleFaceUnlockStateChanged(boolean running, int userId) { |
| 532 | mUserFaceUnlockRunning.put(userId, running); |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 533 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 534 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 535 | if (cb != null) { |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 536 | cb.onFaceUnlockStateChanged(running, userId); |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | } |
| 540 | |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 541 | public boolean isFaceUnlockRunning(int userId) { |
| 542 | return mUserFaceUnlockRunning.get(userId); |
| 543 | } |
| 544 | |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 545 | public boolean isFingerprintDetectionRunning() { |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 546 | return mFingerprintRunningState == FINGERPRINT_STATE_RUNNING; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 549 | private boolean isTrustDisabled(int userId) { |
Adrian Roos | a4da9f6 | 2015-02-21 01:15:21 +0100 | [diff] [blame] | 550 | // Don't allow trust agent if device is secured with a SIM PIN. This is here |
| 551 | // mainly because there's no other way to prompt the user to enter their SIM PIN |
| 552 | // once they get past the keyguard screen. |
| 553 | final boolean disabledBySimPin = isSimPinSecure(); |
| 554 | return disabledBySimPin; |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 557 | private boolean isFingerprintDisabled(int userId) { |
| 558 | final DevicePolicyManager dpm = |
| 559 | (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE); |
| 560 | return dpm != null && (dpm.getKeyguardDisabledFeatures(null, userId) |
Adrian Roos | 733b663 | 2015-08-21 14:32:35 -0700 | [diff] [blame] | 561 | & DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT) != 0 |
| 562 | || isSimPinSecure(); |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Selim Cinek | e8bae62 | 2015-07-15 13:24:06 -0700 | [diff] [blame] | 565 | public boolean getUserCanSkipBouncer(int userId) { |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 566 | return getUserHasTrust(userId) || (mUserFingerprintAuthenticated.get(userId) |
| 567 | && isUnlockingWithFingerprintAllowed()); |
Selim Cinek | e8bae62 | 2015-07-15 13:24:06 -0700 | [diff] [blame] | 568 | } |
| 569 | |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 570 | public boolean getUserHasTrust(int userId) { |
Selim Cinek | e8bae62 | 2015-07-15 13:24:06 -0700 | [diff] [blame] | 571 | return !isTrustDisabled(userId) && mUserHasTrust.get(userId); |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 572 | } |
| 573 | |
Adrian Roos | 7861c66 | 2014-07-25 15:37:28 +0200 | [diff] [blame] | 574 | public boolean getUserTrustIsManaged(int userId) { |
| 575 | return mUserTrustIsManaged.get(userId) && !isTrustDisabled(userId); |
| 576 | } |
| 577 | |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 578 | public boolean isUnlockingWithFingerprintAllowed() { |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 579 | return mStrongAuthTracker.isUnlockingWithFingerprintAllowed() |
| 580 | && !hasFingerprintUnlockTimedOut(sCurrentUser); |
| 581 | } |
| 582 | |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 583 | public boolean needsSlowUnlockTransition() { |
| 584 | return mNeedsSlowUnlockTransition; |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 587 | public StrongAuthTracker getStrongAuthTracker() { |
| 588 | return mStrongAuthTracker; |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | /** |
| 592 | * @return true if the user hasn't use strong authentication (pattern, PIN, password) since a |
| 593 | * while and thus can't unlock with fingerprint, false otherwise |
| 594 | */ |
| 595 | public boolean hasFingerprintUnlockTimedOut(int userId) { |
Adrian Roos | 1de8bcb | 2015-08-19 16:52:52 -0700 | [diff] [blame] | 596 | return !mStrongAuthNotTimedOut.contains(userId); |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | public void reportSuccessfulStrongAuthUnlockAttempt() { |
Adrian Roos | 1de8bcb | 2015-08-19 16:52:52 -0700 | [diff] [blame] | 600 | mStrongAuthNotTimedOut.add(sCurrentUser); |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 601 | scheduleStrongAuthTimeout(); |
Jim Miller | e0507bb | 2015-08-12 20:30:34 -0700 | [diff] [blame] | 602 | if (mFpm != null) { |
| 603 | byte[] token = null; /* TODO: pass real auth token once fp HAL supports it */ |
| 604 | mFpm.resetTimeout(token); |
| 605 | } |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | private void scheduleStrongAuthTimeout() { |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 609 | final DevicePolicyManager dpm = |
| 610 | (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE); |
| 611 | long when = SystemClock.elapsedRealtime() + dpm.getRequiredStrongAuthTimeout(null, |
| 612 | sCurrentUser); |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 613 | Intent intent = new Intent(ACTION_STRONG_AUTH_TIMEOUT); |
| 614 | intent.putExtra(USER_ID, sCurrentUser); |
| 615 | PendingIntent sender = PendingIntent.getBroadcast(mContext, |
| 616 | sCurrentUser, intent, PendingIntent.FLAG_CANCEL_CURRENT); |
| 617 | mAlarmManager.set(AlarmManager.ELAPSED_REALTIME, when, sender); |
Adrian Roos | 1de8bcb | 2015-08-19 16:52:52 -0700 | [diff] [blame] | 618 | notifyStrongAuthStateChanged(sCurrentUser); |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Adrian Roos | 1de8bcb | 2015-08-19 16:52:52 -0700 | [diff] [blame] | 621 | private void notifyStrongAuthStateChanged(int userId) { |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 622 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 623 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 624 | if (cb != null) { |
Adrian Roos | 1de8bcb | 2015-08-19 16:52:52 -0700 | [diff] [blame] | 625 | cb.onStrongAuthStateChanged(userId); |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 626 | } |
| 627 | } |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 630 | static class DisplayClientState { |
| 631 | public int clientGeneration; |
| 632 | public boolean clearing; |
| 633 | public PendingIntent intent; |
| 634 | public int playbackState; |
| 635 | public long playbackEventTime; |
| 636 | } |
| 637 | |
| 638 | private DisplayClientState mDisplayClientState = new DisplayClientState(); |
| 639 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 640 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 641 | |
Jim Miller | d72d5ac | 2015-09-29 18:55:32 -0700 | [diff] [blame] | 642 | @Override |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 643 | public void onReceive(Context context, Intent intent) { |
| 644 | final String action = intent.getAction(); |
| 645 | if (DEBUG) Log.d(TAG, "received broadcast " + action); |
| 646 | |
| 647 | if (Intent.ACTION_TIME_TICK.equals(action) |
| 648 | || Intent.ACTION_TIME_CHANGED.equals(action) |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 649 | || Intent.ACTION_TIMEZONE_CHANGED.equals(action)) { |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 650 | mHandler.sendEmptyMessage(MSG_TIME_UPDATE); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 651 | } else if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { |
| 652 | final int status = intent.getIntExtra(EXTRA_STATUS, BATTERY_STATUS_UNKNOWN); |
| 653 | final int plugged = intent.getIntExtra(EXTRA_PLUGGED, 0); |
| 654 | final int level = intent.getIntExtra(EXTRA_LEVEL, 0); |
| 655 | final int health = intent.getIntExtra(EXTRA_HEALTH, BATTERY_HEALTH_UNKNOWN); |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 656 | |
| 657 | final int maxChargingMicroAmp = intent.getIntExtra(EXTRA_MAX_CHARGING_CURRENT, -1); |
| 658 | int maxChargingMicroVolt = intent.getIntExtra(EXTRA_MAX_CHARGING_VOLTAGE, -1); |
| 659 | final int maxChargingMicroWatt; |
| 660 | |
| 661 | if (maxChargingMicroVolt <= 0) { |
| 662 | maxChargingMicroVolt = DEFAULT_CHARGING_VOLTAGE_MICRO_VOLT; |
| 663 | } |
| 664 | if (maxChargingMicroAmp > 0) { |
| 665 | // Calculating muW = muA * muV / (10^6 mu^2 / mu); splitting up the divisor |
| 666 | // to maintain precision equally on both factors. |
| 667 | maxChargingMicroWatt = (maxChargingMicroAmp / 1000) |
| 668 | * (maxChargingMicroVolt / 1000); |
| 669 | } else { |
| 670 | maxChargingMicroWatt = -1; |
| 671 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 672 | final Message msg = mHandler.obtainMessage( |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 673 | MSG_BATTERY_UPDATE, new BatteryStatus(status, level, plugged, health, |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 674 | maxChargingMicroWatt)); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 675 | mHandler.sendMessage(msg); |
| 676 | } else if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 677 | SimData args = SimData.fromIntent(intent); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 678 | if (DEBUG_SIM_STATES) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 679 | Log.v(TAG, "action " + action |
| 680 | + " state: " + intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE) |
| 681 | + " slotId: " + args.slotId + " subid: " + args.subId); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 682 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 683 | mHandler.obtainMessage(MSG_SIM_STATE_CHANGE, args.subId, args.slotId, args.simState) |
| 684 | .sendToTarget(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 685 | } else if (AudioManager.RINGER_MODE_CHANGED_ACTION.equals(action)) { |
| 686 | mHandler.sendMessage(mHandler.obtainMessage(MSG_RINGER_MODE_CHANGED, |
| 687 | intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1), 0)); |
| 688 | } else if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(action)) { |
| 689 | String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); |
| 690 | mHandler.sendMessage(mHandler.obtainMessage(MSG_PHONE_STATE_CHANGED, state)); |
Jason Monk | 052082c | 2015-06-11 11:35:23 -0400 | [diff] [blame] | 691 | } else if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(action)) { |
| 692 | mHandler.sendEmptyMessage(MSG_AIRPLANE_MODE_CHANGED); |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 693 | } else if (Intent.ACTION_BOOT_COMPLETED.equals(action)) { |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 694 | dispatchBootCompleted(); |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 695 | } else if (TelephonyIntents.ACTION_SERVICE_STATE_CHANGED.equals(action)) { |
| 696 | ServiceState serviceState = ServiceState.newFromBundle(intent.getExtras()); |
| 697 | int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, |
| 698 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
| 699 | if (DEBUG) { |
| 700 | Log.v(TAG, "action " + action + " serviceState=" + serviceState + " subId=" |
| 701 | + subId); |
| 702 | } |
| 703 | mHandler.sendMessage( |
| 704 | mHandler.obtainMessage(MSG_SERVICE_STATE_CHANGE, subId, 0, serviceState)); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 705 | } |
| 706 | } |
| 707 | }; |
Jim Miller | 2de5ee8 | 2012-06-14 22:22:50 -0700 | [diff] [blame] | 708 | |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 709 | private final BroadcastReceiver mBroadcastAllReceiver = new BroadcastReceiver() { |
| 710 | |
Jim Miller | d72d5ac | 2015-09-29 18:55:32 -0700 | [diff] [blame] | 711 | @Override |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 712 | public void onReceive(Context context, Intent intent) { |
| 713 | final String action = intent.getAction(); |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 714 | if (AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED.equals(action)) { |
| 715 | mHandler.sendEmptyMessage(MSG_TIME_UPDATE); |
| 716 | } else if (Intent.ACTION_USER_INFO_CHANGED.equals(action)) { |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 717 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_INFO_CHANGED, |
| 718 | intent.getIntExtra(Intent.EXTRA_USER_HANDLE, getSendingUserId()), 0)); |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 719 | } else if (ACTION_FACE_UNLOCK_STARTED.equals(action)) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 720 | Trace.beginSection("KeyguardUpdateMonitor.mBroadcastAllReceiver#onReceive ACTION_FACE_UNLOCK_STARTED"); |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 721 | mHandler.sendMessage(mHandler.obtainMessage(MSG_FACE_UNLOCK_STATE_CHANGED, 1, |
| 722 | getSendingUserId())); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 723 | Trace.endSection(); |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 724 | } else if (ACTION_FACE_UNLOCK_STOPPED.equals(action)) { |
| 725 | mHandler.sendMessage(mHandler.obtainMessage(MSG_FACE_UNLOCK_STATE_CHANGED, 0, |
| 726 | getSendingUserId())); |
| 727 | } else if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 728 | .equals(action)) { |
| 729 | mHandler.sendEmptyMessage(MSG_DPM_STATE_CHANGED); |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 730 | } else if (ACTION_USER_UNLOCKED.equals(action)) { |
| 731 | mHandler.sendEmptyMessage(MSG_USER_UNLOCKED); |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 732 | } |
| 733 | } |
| 734 | }; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 735 | |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 736 | private final BroadcastReceiver mStrongAuthTimeoutReceiver = new BroadcastReceiver() { |
| 737 | @Override |
| 738 | public void onReceive(Context context, Intent intent) { |
| 739 | if (ACTION_STRONG_AUTH_TIMEOUT.equals(intent.getAction())) { |
| 740 | int userId = intent.getIntExtra(USER_ID, -1); |
Adrian Roos | 1de8bcb | 2015-08-19 16:52:52 -0700 | [diff] [blame] | 741 | mStrongAuthNotTimedOut.remove(userId); |
| 742 | notifyStrongAuthStateChanged(userId); |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | }; |
| 746 | |
Jorim Jaggi | 3a46478 | 2015-08-28 16:59:13 -0700 | [diff] [blame] | 747 | private final FingerprintManager.LockoutResetCallback mLockoutResetCallback |
| 748 | = new FingerprintManager.LockoutResetCallback() { |
| 749 | @Override |
| 750 | public void onLockoutReset() { |
| 751 | handleFingerprintLockoutReset(); |
| 752 | } |
| 753 | }; |
| 754 | |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 755 | private FingerprintManager.AuthenticationCallback mAuthenticationCallback |
| 756 | = new AuthenticationCallback() { |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 757 | |
| 758 | @Override |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 759 | public void onAuthenticationFailed() { |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 760 | handleFingerprintAuthFailed(); |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 761 | }; |
| 762 | |
| 763 | @Override |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 764 | public void onAuthenticationSucceeded(AuthenticationResult result) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 765 | Trace.beginSection("KeyguardUpdateMonitor#onAuthenticationSucceeded"); |
Jim Miller | 837fa7e | 2016-08-08 20:16:22 -0700 | [diff] [blame] | 766 | handleFingerprintAuthenticated(result.getUserId()); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 767 | Trace.endSection(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | @Override |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 771 | public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) { |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 772 | handleFingerprintHelp(helpMsgId, helpString.toString()); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | @Override |
| 776 | public void onAuthenticationError(int errMsgId, CharSequence errString) { |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 777 | handleFingerprintError(errMsgId, errString.toString()); |
| 778 | } |
| 779 | |
| 780 | @Override |
| 781 | public void onAuthenticationAcquired(int acquireInfo) { |
| 782 | handleFingerprintAcquired(acquireInfo); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 783 | } |
| 784 | }; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 785 | private CancellationSignal mFingerprintCancelSignal; |
| 786 | private FingerprintManager mFpm; |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 787 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 788 | /** |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 789 | * When we receive a |
| 790 | * {@link com.android.internal.telephony.TelephonyIntents#ACTION_SIM_STATE_CHANGED} broadcast, |
Wink Saville | 37c124c | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 791 | * and then pass a result via our handler to {@link KeyguardUpdateMonitor#handleSimStateChange}, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 792 | * we need a single object to pass to the handler. This class helps decode |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 793 | * the intent and provide a {@link SimCard.State} result. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 794 | */ |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 795 | private static class SimData { |
| 796 | public State simState; |
| 797 | public int slotId; |
| 798 | public int subId; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 799 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 800 | SimData(State state, int slot, int id) { |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 801 | simState = state; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 802 | slotId = slot; |
| 803 | subId = id; |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 804 | } |
| 805 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 806 | static SimData fromIntent(Intent intent) { |
| 807 | State state; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 808 | if (!TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(intent.getAction())) { |
| 809 | throw new IllegalArgumentException("only handles intent ACTION_SIM_STATE_CHANGED"); |
| 810 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 811 | String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 812 | int slotId = intent.getIntExtra(PhoneConstants.SLOT_KEY, 0); |
| 813 | int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 814 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 815 | if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) { |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 816 | final String absentReason = intent |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 817 | .getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON); |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 818 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 819 | if (IccCardConstants.INTENT_VALUE_ABSENT_ON_PERM_DISABLED.equals( |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 820 | absentReason)) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 821 | state = IccCardConstants.State.PERM_DISABLED; |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 822 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 823 | state = IccCardConstants.State.ABSENT; |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 824 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 825 | } else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) { |
| 826 | state = IccCardConstants.State.READY; |
| 827 | } else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 828 | final String lockedReason = intent |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 829 | .getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON); |
| 830 | if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) { |
| 831 | state = IccCardConstants.State.PIN_REQUIRED; |
| 832 | } else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) { |
| 833 | state = IccCardConstants.State.PUK_REQUIRED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 834 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 835 | state = IccCardConstants.State.UNKNOWN; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 836 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 837 | } else if (IccCardConstants.INTENT_VALUE_LOCKED_NETWORK.equals(stateExtra)) { |
| 838 | state = IccCardConstants.State.NETWORK_LOCKED; |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 839 | } else if (IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(stateExtra) |
| 840 | || IccCardConstants.INTENT_VALUE_ICC_IMSI.equals(stateExtra)) { |
| 841 | // This is required because telephony doesn't return to "READY" after |
| 842 | // these state transitions. See bug 7197471. |
| 843 | state = IccCardConstants.State.READY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 844 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 845 | state = IccCardConstants.State.UNKNOWN; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 846 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 847 | return new SimData(state, slotId, subId); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 848 | } |
| 849 | |
Jim Miller | d72d5ac | 2015-09-29 18:55:32 -0700 | [diff] [blame] | 850 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 851 | public String toString() { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 852 | return "SimData{state=" + simState + ",slotId=" + slotId + ",subId=" + subId + "}"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 853 | } |
| 854 | } |
| 855 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 856 | public static class BatteryStatus { |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 857 | public static final int CHARGING_UNKNOWN = -1; |
| 858 | public static final int CHARGING_SLOWLY = 0; |
| 859 | public static final int CHARGING_REGULAR = 1; |
| 860 | public static final int CHARGING_FAST = 2; |
| 861 | |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 862 | public final int status; |
| 863 | public final int level; |
| 864 | public final int plugged; |
| 865 | public final int health; |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 866 | public final int maxChargingWattage; |
| 867 | public BatteryStatus(int status, int level, int plugged, int health, |
| 868 | int maxChargingWattage) { |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 869 | this.status = status; |
| 870 | this.level = level; |
| 871 | this.plugged = plugged; |
| 872 | this.health = health; |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 873 | this.maxChargingWattage = maxChargingWattage; |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 874 | } |
| 875 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 876 | /** |
Brian Muramatsu | a92a01b | 2012-09-05 21:54:39 -0700 | [diff] [blame] | 877 | * Determine whether the device is plugged in (USB, power, or wireless). |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 878 | * @return true if the device is plugged in. |
| 879 | */ |
Adrian Roos | ad3bc7f | 2014-10-30 18:29:38 +0100 | [diff] [blame] | 880 | public boolean isPluggedIn() { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 881 | return plugged == BatteryManager.BATTERY_PLUGGED_AC |
Brian Muramatsu | a92a01b | 2012-09-05 21:54:39 -0700 | [diff] [blame] | 882 | || plugged == BatteryManager.BATTERY_PLUGGED_USB |
| 883 | || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | /** |
| 887 | * Whether or not the device is charged. Note that some devices never return 100% for |
| 888 | * battery level, so this allows either battery level or status to determine if the |
| 889 | * battery is charged. |
| 890 | * @return true if the device is charged |
| 891 | */ |
| 892 | public boolean isCharged() { |
| 893 | return status == BATTERY_STATUS_FULL || level >= 100; |
| 894 | } |
| 895 | |
| 896 | /** |
| 897 | * Whether battery is low and needs to be charged. |
| 898 | * @return true if battery is low |
| 899 | */ |
| 900 | public boolean isBatteryLow() { |
| 901 | return level < LOW_BATTERY_THRESHOLD; |
| 902 | } |
| 903 | |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 904 | public final int getChargingSpeed(int slowThreshold, int fastThreshold) { |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 905 | return maxChargingWattage <= 0 ? CHARGING_UNKNOWN : |
| 906 | maxChargingWattage < slowThreshold ? CHARGING_SLOWLY : |
| 907 | maxChargingWattage > fastThreshold ? CHARGING_FAST : |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 908 | CHARGING_REGULAR; |
| 909 | } |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 910 | } |
| 911 | |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 912 | public class StrongAuthTracker extends LockPatternUtils.StrongAuthTracker { |
Rakesh Iyer | a7aa4d6 | 2016-01-19 17:27:23 -0800 | [diff] [blame] | 913 | public StrongAuthTracker(Context context) { |
| 914 | super(context); |
| 915 | } |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 916 | |
| 917 | public boolean isUnlockingWithFingerprintAllowed() { |
| 918 | int userId = getCurrentUser(); |
| 919 | return isFingerprintAllowedForUser(userId); |
| 920 | } |
| 921 | |
| 922 | public boolean hasUserAuthenticatedSinceBoot() { |
| 923 | int userId = getCurrentUser(); |
| 924 | return (getStrongAuthForUser(userId) |
| 925 | & STRONG_AUTH_REQUIRED_AFTER_BOOT) == 0; |
| 926 | } |
| 927 | |
| 928 | @Override |
| 929 | public void onStrongAuthRequiredChanged(int userId) { |
Adrian Roos | 1de8bcb | 2015-08-19 16:52:52 -0700 | [diff] [blame] | 930 | notifyStrongAuthStateChanged(userId); |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 931 | } |
| 932 | } |
| 933 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 934 | public static KeyguardUpdateMonitor getInstance(Context context) { |
| 935 | if (sInstance == null) { |
| 936 | sInstance = new KeyguardUpdateMonitor(context); |
| 937 | } |
| 938 | return sInstance; |
| 939 | } |
| 940 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 941 | protected void handleStartedWakingUp() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 942 | Trace.beginSection("KeyguardUpdateMonitor#handleStartedWakingUp"); |
Jorim Jaggi | 864e64b | 2015-05-20 14:13:23 -0700 | [diff] [blame] | 943 | updateFingerprintListeningState(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 944 | final int count = mCallbacks.size(); |
| 945 | for (int i = 0; i < count; i++) { |
| 946 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 947 | if (cb != null) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 948 | cb.onStartedWakingUp(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 949 | } |
| 950 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 951 | Trace.endSection(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 952 | } |
| 953 | |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 954 | protected void handleStartedGoingToSleep(int arg1) { |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 955 | clearFingerprintRecognized(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 956 | final int count = mCallbacks.size(); |
| 957 | for (int i = 0; i < count; i++) { |
| 958 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 959 | if (cb != null) { |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 960 | cb.onStartedGoingToSleep(arg1); |
| 961 | } |
| 962 | } |
| 963 | mGoingToSleep = true; |
| 964 | mFingerprintAlreadyAuthenticated = false; |
| 965 | updateFingerprintListeningState(); |
| 966 | } |
| 967 | |
| 968 | protected void handleFinishedGoingToSleep(int arg1) { |
| 969 | mGoingToSleep = false; |
| 970 | final int count = mCallbacks.size(); |
| 971 | for (int i = 0; i < count; i++) { |
| 972 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 973 | if (cb != null) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 974 | cb.onFinishedGoingToSleep(arg1); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 975 | } |
| 976 | } |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 977 | updateFingerprintListeningState(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 978 | } |
| 979 | |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 980 | private void handleScreenTurnedOn() { |
| 981 | final int count = mCallbacks.size(); |
| 982 | for (int i = 0; i < count; i++) { |
| 983 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 984 | if (cb != null) { |
| 985 | cb.onScreenTurnedOn(); |
| 986 | } |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | private void handleScreenTurnedOff() { |
| 991 | final int count = mCallbacks.size(); |
| 992 | for (int i = 0; i < count; i++) { |
| 993 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 994 | if (cb != null) { |
| 995 | cb.onScreenTurnedOff(); |
| 996 | } |
| 997 | } |
| 998 | } |
| 999 | |
Selim Cinek | 9941539 | 2016-09-09 14:58:41 -0700 | [diff] [blame] | 1000 | private void handleDreamingStateChanged(int dreamStart) { |
| 1001 | final int count = mCallbacks.size(); |
| 1002 | boolean showingDream = dreamStart == 1; |
| 1003 | for (int i = 0; i < count; i++) { |
| 1004 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1005 | if (cb != null) { |
| 1006 | cb.onDreamingStateChanged(showingDream); |
| 1007 | } |
| 1008 | } |
| 1009 | } |
| 1010 | |
Adam Powell | 43a372f | 2013-09-27 17:43:53 -0700 | [diff] [blame] | 1011 | /** |
| 1012 | * IMPORTANT: Must be called from UI thread. |
| 1013 | */ |
| 1014 | public void dispatchSetBackground(Bitmap bmp) { |
| 1015 | if (DEBUG) Log.d(TAG, "dispatchSetBackground"); |
| 1016 | final int count = mCallbacks.size(); |
| 1017 | for (int i = 0; i < count; i++) { |
| 1018 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1019 | if (cb != null) { |
| 1020 | cb.onSetBackground(bmp); |
| 1021 | } |
| 1022 | } |
| 1023 | } |
| 1024 | |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 1025 | private void handleUserInfoChanged(int userId) { |
| 1026 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1027 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1028 | if (cb != null) { |
| 1029 | cb.onUserInfoChanged(userId); |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 1034 | private void handleUserUnlocked() { |
| 1035 | mNeedsSlowUnlockTransition = resolveNeedsSlowUnlockTransition(); |
| 1036 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1037 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1038 | if (cb != null) { |
| 1039 | cb.onUserUnlocked(); |
| 1040 | } |
| 1041 | } |
| 1042 | } |
| 1043 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1044 | private KeyguardUpdateMonitor(Context context) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1045 | mContext = context; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1046 | mSubscriptionManager = SubscriptionManager.from(context); |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 1047 | mAlarmManager = context.getSystemService(AlarmManager.class); |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 1048 | mDeviceProvisioned = isDeviceProvisionedInSettingsDb(); |
Rakesh Iyer | a7aa4d6 | 2016-01-19 17:27:23 -0800 | [diff] [blame] | 1049 | mStrongAuthTracker = new StrongAuthTracker(context); |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 1050 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1051 | // Since device can't be un-provisioned, we only need to register a content observer |
| 1052 | // to update mDeviceProvisioned when we are... |
| 1053 | if (!mDeviceProvisioned) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1054 | watchForDeviceProvisioning(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1055 | } |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 1056 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1057 | // Take a guess at initial SIM state, battery status and PLMN until we get an update |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 1058 | mBatteryStatus = new BatteryStatus(BATTERY_STATUS_UNKNOWN, 100, 0, 0, 0); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1059 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1060 | // Watch for interesting updates |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1061 | final IntentFilter filter = new IntentFilter(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1062 | filter.addAction(Intent.ACTION_TIME_TICK); |
| 1063 | filter.addAction(Intent.ACTION_TIME_CHANGED); |
| 1064 | filter.addAction(Intent.ACTION_BATTERY_CHANGED); |
| 1065 | filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); |
Jason Monk | 052082c | 2015-06-11 11:35:23 -0400 | [diff] [blame] | 1066 | filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1067 | filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 1068 | filter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 1069 | filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 1070 | filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1071 | context.registerReceiver(mBroadcastReceiver, filter); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1072 | |
Adam Cohen | c276e82 | 2012-11-08 13:01:08 -0800 | [diff] [blame] | 1073 | final IntentFilter bootCompleteFilter = new IntentFilter(); |
| 1074 | bootCompleteFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); |
| 1075 | bootCompleteFilter.addAction(Intent.ACTION_BOOT_COMPLETED); |
| 1076 | context.registerReceiver(mBroadcastReceiver, bootCompleteFilter); |
| 1077 | |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 1078 | final IntentFilter allUserFilter = new IntentFilter(); |
| 1079 | allUserFilter.addAction(Intent.ACTION_USER_INFO_CHANGED); |
| 1080 | allUserFilter.addAction(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED); |
| 1081 | allUserFilter.addAction(ACTION_FACE_UNLOCK_STARTED); |
| 1082 | allUserFilter.addAction(ACTION_FACE_UNLOCK_STOPPED); |
| 1083 | allUserFilter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 1084 | allUserFilter.addAction(ACTION_USER_UNLOCKED); |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 1085 | context.registerReceiverAsUser(mBroadcastAllReceiver, UserHandle.ALL, allUserFilter, |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 1086 | null, null); |
| 1087 | |
Wink Saville | 071743f | 2015-01-12 17:11:04 -0800 | [diff] [blame] | 1088 | mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionListener); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1089 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1090 | ActivityManager.getService().registerUserSwitchObserver( |
Sudheer Shanka | 2c4522c | 2016-08-27 20:53:28 -0700 | [diff] [blame] | 1091 | new UserSwitchObserver() { |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1092 | @Override |
| 1093 | public void onUserSwitching(int newUserId, IRemoteCallback reply) { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 1094 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHING, |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1095 | newUserId, 0, reply)); |
| 1096 | } |
| 1097 | @Override |
| 1098 | public void onUserSwitchComplete(int newUserId) throws RemoteException { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 1099 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCH_COMPLETE, |
Adrian Roos | be47b07 | 2014-09-03 00:08:56 +0200 | [diff] [blame] | 1100 | newUserId, 0)); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1101 | } |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 1102 | }, TAG); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1103 | } catch (RemoteException e) { |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 1104 | e.rethrowAsRuntimeException(); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1105 | } |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 1106 | |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 1107 | IntentFilter strongAuthTimeoutFilter = new IntentFilter(); |
| 1108 | strongAuthTimeoutFilter.addAction(ACTION_STRONG_AUTH_TIMEOUT); |
| 1109 | context.registerReceiver(mStrongAuthTimeoutReceiver, strongAuthTimeoutFilter, |
| 1110 | PERMISSION_SELF, null /* handler */); |
Jorim Jaggi | 237b061 | 2015-05-01 14:28:49 -0700 | [diff] [blame] | 1111 | mTrustManager = (TrustManager) context.getSystemService(Context.TRUST_SERVICE); |
| 1112 | mTrustManager.registerTrustListener(this); |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 1113 | new LockPatternUtils(context).registerStrongAuthTracker(mStrongAuthTracker); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 1114 | |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1115 | mFpm = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE); |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1116 | updateFingerprintListeningState(); |
Jorim Jaggi | 3a46478 | 2015-08-28 16:59:13 -0700 | [diff] [blame] | 1117 | if (mFpm != null) { |
| 1118 | mFpm.addLockoutResetCallback(mLockoutResetCallback); |
| 1119 | } |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 1120 | |
| 1121 | mUserManager = context.getSystemService(UserManager.class); |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | private void updateFingerprintListeningState() { |
| 1125 | boolean shouldListenForFingerprint = shouldListenForFingerprint(); |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 1126 | if (mFingerprintRunningState == FINGERPRINT_STATE_RUNNING && !shouldListenForFingerprint) { |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1127 | stopListeningForFingerprint(); |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 1128 | } else if (mFingerprintRunningState != FINGERPRINT_STATE_RUNNING |
| 1129 | && shouldListenForFingerprint) { |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1130 | startListeningForFingerprint(); |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | private boolean shouldListenForFingerprint() { |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 1135 | return (mKeyguardIsVisible || !mDeviceInteractive || mBouncer || mGoingToSleep) |
| 1136 | && !mSwitchingUser && !mFingerprintAlreadyAuthenticated |
| 1137 | && !isFingerprintDisabled(getCurrentUser()); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1138 | } |
| 1139 | |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 1140 | private void startListeningForFingerprint() { |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 1141 | if (mFingerprintRunningState == FINGERPRINT_STATE_CANCELLING) { |
| 1142 | setFingerprintRunningState(FINGERPRINT_STATE_CANCELLING_RESTARTING); |
| 1143 | return; |
| 1144 | } |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 1145 | if (DEBUG) Log.v(TAG, "startListeningForFingerprint()"); |
Jorim Jaggi | 2aad7ee | 2015-04-14 15:25:06 -0700 | [diff] [blame] | 1146 | int userId = ActivityManager.getCurrentUser(); |
Jorim Jaggi | 71448a7 | 2015-08-18 19:49:04 -0700 | [diff] [blame] | 1147 | if (isUnlockWithFingerprintPossible(userId)) { |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 1148 | if (mFingerprintCancelSignal != null) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1149 | mFingerprintCancelSignal.cancel(); |
| 1150 | } |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 1151 | mFingerprintCancelSignal = new CancellationSignal(); |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 1152 | mFpm.authenticate(null, mFingerprintCancelSignal, 0, mAuthenticationCallback, null, userId); |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 1153 | setFingerprintRunningState(FINGERPRINT_STATE_RUNNING); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 1157 | public boolean isUnlockWithFingerprintPossible(int userId) { |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 1158 | return mFpm != null && mFpm.isHardwareDetected() && !isFingerprintDisabled(userId) |
| 1159 | && mFpm.getEnrolledFingerprints(userId).size() > 0; |
| 1160 | } |
| 1161 | |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1162 | private void stopListeningForFingerprint() { |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 1163 | if (DEBUG) Log.v(TAG, "stopListeningForFingerprint()"); |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 1164 | if (mFingerprintRunningState == FINGERPRINT_STATE_RUNNING) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1165 | mFingerprintCancelSignal.cancel(); |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 1166 | mFingerprintCancelSignal = null; |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 1167 | setFingerprintRunningState(FINGERPRINT_STATE_CANCELLING); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1168 | } |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 1169 | if (mFingerprintRunningState == FINGERPRINT_STATE_CANCELLING_RESTARTING) { |
| 1170 | setFingerprintRunningState(FINGERPRINT_STATE_CANCELLING); |
| 1171 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1172 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1173 | |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 1174 | private boolean isDeviceProvisionedInSettingsDb() { |
| 1175 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 1176 | Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
| 1177 | } |
| 1178 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1179 | private void watchForDeviceProvisioning() { |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 1180 | mDeviceProvisionedObserver = new ContentObserver(mHandler) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1181 | @Override |
| 1182 | public void onChange(boolean selfChange) { |
| 1183 | super.onChange(selfChange); |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 1184 | mDeviceProvisioned = isDeviceProvisionedInSettingsDb(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1185 | if (mDeviceProvisioned) { |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 1186 | mHandler.sendEmptyMessage(MSG_DEVICE_PROVISIONED); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1187 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1188 | if (DEBUG) Log.d(TAG, "DEVICE_PROVISIONED state = " + mDeviceProvisioned); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1189 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1190 | }; |
| 1191 | |
| 1192 | mContext.getContentResolver().registerContentObserver( |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 1193 | Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 1194 | false, mDeviceProvisionedObserver); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1195 | |
| 1196 | // prevent a race condition between where we check the flag and where we register the |
| 1197 | // observer by grabbing the value once again... |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 1198 | boolean provisioned = isDeviceProvisionedInSettingsDb(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1199 | if (provisioned != mDeviceProvisioned) { |
| 1200 | mDeviceProvisioned = provisioned; |
| 1201 | if (mDeviceProvisioned) { |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 1202 | mHandler.sendEmptyMessage(MSG_DEVICE_PROVISIONED); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1203 | } |
| 1204 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1205 | } |
| 1206 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1207 | /** |
Jorim Jaggi | d11d1a9 | 2016-08-16 16:02:32 -0700 | [diff] [blame] | 1208 | * Update the state whether Keyguard currently has a lockscreen wallpaper. |
| 1209 | * |
| 1210 | * @param hasLockscreenWallpaper Whether Keyguard has a lockscreen wallpaper. |
| 1211 | */ |
| 1212 | public void setHasLockscreenWallpaper(boolean hasLockscreenWallpaper) { |
| 1213 | if (hasLockscreenWallpaper != mHasLockscreenWallpaper) { |
| 1214 | mHasLockscreenWallpaper = hasLockscreenWallpaper; |
| 1215 | for (int i = mCallbacks.size() - 1; i >= 0; i--) { |
| 1216 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1217 | if (cb != null) { |
| 1218 | cb.onHasLockscreenWallpaperChanged(hasLockscreenWallpaper); |
| 1219 | } |
| 1220 | } |
| 1221 | } |
| 1222 | } |
| 1223 | |
| 1224 | /** |
| 1225 | * @return Whether Keyguard has a lockscreen wallpaper. |
| 1226 | */ |
| 1227 | public boolean hasLockscreenWallpaper() { |
| 1228 | return mHasLockscreenWallpaper; |
| 1229 | } |
| 1230 | |
| 1231 | /** |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1232 | * Handle {@link #MSG_DPM_STATE_CHANGED} |
| 1233 | */ |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 1234 | protected void handleDevicePolicyManagerStateChanged() { |
Adrian Roos | 733b663 | 2015-08-21 14:32:35 -0700 | [diff] [blame] | 1235 | updateFingerprintListeningState(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1236 | for (int i = mCallbacks.size() - 1; i >= 0; i--) { |
| 1237 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1238 | if (cb != null) { |
| 1239 | cb.onDevicePolicyManagerStateChanged(); |
| 1240 | } |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 1241 | } |
| 1242 | } |
| 1243 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1244 | /** |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 1245 | * Handle {@link #MSG_USER_SWITCHING} |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1246 | */ |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 1247 | protected void handleUserSwitching(int userId, IRemoteCallback reply) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1248 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1249 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1250 | if (cb != null) { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 1251 | cb.onUserSwitching(userId); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1252 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 1253 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1254 | try { |
| 1255 | reply.sendResult(null); |
| 1256 | } catch (RemoteException e) { |
| 1257 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 1258 | } |
| 1259 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1260 | /** |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 1261 | * Handle {@link #MSG_USER_SWITCH_COMPLETE} |
| 1262 | */ |
| 1263 | protected void handleUserSwitchComplete(int userId) { |
| 1264 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1265 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1266 | if (cb != null) { |
| 1267 | cb.onUserSwitchComplete(userId); |
| 1268 | } |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | /** |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 1273 | * This is exposed since {@link Intent#ACTION_BOOT_COMPLETED} is not sticky. If |
| 1274 | * keyguard crashes sometime after boot, then it will never receive this |
| 1275 | * broadcast and hence not handle the event. This method is ultimately called by |
| 1276 | * PhoneWindowManager in this case. |
| 1277 | */ |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1278 | public void dispatchBootCompleted() { |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 1279 | mHandler.sendEmptyMessage(MSG_BOOT_COMPLETED); |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | /** |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 1283 | * Handle {@link #MSG_BOOT_COMPLETED} |
| 1284 | */ |
| 1285 | protected void handleBootCompleted() { |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 1286 | if (mBootCompleted) return; |
Adam Cohen | 4eb36cf | 2012-11-07 11:45:30 -0800 | [diff] [blame] | 1287 | mBootCompleted = true; |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 1288 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1289 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1290 | if (cb != null) { |
| 1291 | cb.onBootCompleted(); |
| 1292 | } |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | /** |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1297 | * We need to store this state in the KeyguardUpdateMonitor since this class will not be |
Adam Cohen | 4eb36cf | 2012-11-07 11:45:30 -0800 | [diff] [blame] | 1298 | * destroyed. |
| 1299 | */ |
| 1300 | public boolean hasBootCompleted() { |
| 1301 | return mBootCompleted; |
| 1302 | } |
| 1303 | |
| 1304 | /** |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1305 | * Handle {@link #MSG_DEVICE_PROVISIONED} |
| 1306 | */ |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 1307 | protected void handleDeviceProvisioned() { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1308 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1309 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1310 | if (cb != null) { |
| 1311 | cb.onDeviceProvisioned(); |
| 1312 | } |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 1313 | } |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 1314 | if (mDeviceProvisionedObserver != null) { |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 1315 | // We don't need the observer anymore... |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 1316 | mContext.getContentResolver().unregisterContentObserver(mDeviceProvisionedObserver); |
| 1317 | mDeviceProvisionedObserver = null; |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 1318 | } |
| 1319 | } |
| 1320 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1321 | /** |
| 1322 | * Handle {@link #MSG_PHONE_STATE_CHANGED} |
| 1323 | */ |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 1324 | protected void handlePhoneStateChanged(String newState) { |
| 1325 | if (DEBUG) Log.d(TAG, "handlePhoneStateChanged(" + newState + ")"); |
Jim Miller | 3f5f83b | 2011-09-26 15:17:05 -0700 | [diff] [blame] | 1326 | if (TelephonyManager.EXTRA_STATE_IDLE.equals(newState)) { |
| 1327 | mPhoneState = TelephonyManager.CALL_STATE_IDLE; |
| 1328 | } else if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(newState)) { |
| 1329 | mPhoneState = TelephonyManager.CALL_STATE_OFFHOOK; |
| 1330 | } else if (TelephonyManager.EXTRA_STATE_RINGING.equals(newState)) { |
| 1331 | mPhoneState = TelephonyManager.CALL_STATE_RINGING; |
| 1332 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1333 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1334 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1335 | if (cb != null) { |
| 1336 | cb.onPhoneStateChanged(mPhoneState); |
| 1337 | } |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 1338 | } |
| 1339 | } |
| 1340 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1341 | /** |
| 1342 | * Handle {@link #MSG_RINGER_MODE_CHANGED} |
| 1343 | */ |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 1344 | protected void handleRingerModeChange(int mode) { |
| 1345 | if (DEBUG) Log.d(TAG, "handleRingerModeChange(" + mode + ")"); |
Jim Miller | 3f5f83b | 2011-09-26 15:17:05 -0700 | [diff] [blame] | 1346 | mRingMode = mode; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1347 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1348 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1349 | if (cb != null) { |
| 1350 | cb.onRingerModeChanged(mode); |
| 1351 | } |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 1352 | } |
| 1353 | } |
| 1354 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1355 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1356 | * Handle {@link #MSG_TIME_UPDATE} |
| 1357 | */ |
| 1358 | private void handleTimeUpdate() { |
| 1359 | if (DEBUG) Log.d(TAG, "handleTimeUpdate"); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1360 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1361 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1362 | if (cb != null) { |
| 1363 | cb.onTimeChanged(); |
| 1364 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1365 | } |
| 1366 | } |
| 1367 | |
| 1368 | /** |
| 1369 | * Handle {@link #MSG_BATTERY_UPDATE} |
| 1370 | */ |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1371 | private void handleBatteryUpdate(BatteryStatus status) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1372 | if (DEBUG) Log.d(TAG, "handleBatteryUpdate"); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1373 | final boolean batteryUpdateInteresting = isBatteryUpdateInteresting(mBatteryStatus, status); |
| 1374 | mBatteryStatus = status; |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1375 | if (batteryUpdateInteresting) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1376 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1377 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1378 | if (cb != null) { |
| 1379 | cb.onRefreshBatteryInfo(status); |
| 1380 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1381 | } |
| 1382 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1386 | * Handle {@link #MSG_SIM_STATE_CHANGE} |
| 1387 | */ |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1388 | private void handleSimStateChange(int subId, int slotId, State state) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1389 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1390 | if (DEBUG_SIM_STATES) { |
| 1391 | Log.d(TAG, "handleSimStateChange(subId=" + subId + ", slotId=" |
| 1392 | + slotId + ", state=" + state +")"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1393 | } |
| 1394 | |
Wink Saville | a54bf65 | 2014-12-11 13:37:50 -0800 | [diff] [blame] | 1395 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1396 | Log.w(TAG, "invalid subId in handleSimStateChange()"); |
| 1397 | return; |
| 1398 | } |
| 1399 | |
| 1400 | SimData data = mSimDatas.get(subId); |
| 1401 | final boolean changed; |
| 1402 | if (data == null) { |
| 1403 | data = new SimData(state, slotId, subId); |
| 1404 | mSimDatas.put(subId, data); |
| 1405 | changed = true; // no data yet; force update |
| 1406 | } else { |
| 1407 | changed = (data.simState != state || data.subId != subId || data.slotId != slotId); |
| 1408 | data.simState = state; |
| 1409 | data.subId = subId; |
| 1410 | data.slotId = slotId; |
| 1411 | } |
| 1412 | if (changed && state != State.UNKNOWN) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1413 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1414 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1415 | if (cb != null) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1416 | cb.onSimStateChanged(subId, slotId, state); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1417 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1418 | } |
| 1419 | } |
| 1420 | } |
| 1421 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1422 | /** |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 1423 | * Handle {@link #MSG_SERVICE_STATE_CHANGE} |
| 1424 | */ |
| 1425 | private void handleServiceStateChange(int subId, ServiceState serviceState) { |
| 1426 | if (DEBUG) { |
| 1427 | Log.d(TAG, |
| 1428 | "handleServiceStateChange(subId=" + subId + ", serviceState=" + serviceState); |
| 1429 | } |
| 1430 | |
| 1431 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1432 | Log.w(TAG, "invalid subId in handleServiceStateChange()"); |
| 1433 | return; |
| 1434 | } |
| 1435 | |
| 1436 | mServiceStates.put(subId, serviceState); |
| 1437 | |
| 1438 | for (int j = 0; j < mCallbacks.size(); j++) { |
| 1439 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get(); |
| 1440 | if (cb != null) { |
| 1441 | cb.onRefreshCarrierInfo(); |
| 1442 | } |
| 1443 | } |
| 1444 | } |
| 1445 | |
| 1446 | /** |
Jorim Jaggi | 6a15d52 | 2015-09-22 15:55:33 -0700 | [diff] [blame] | 1447 | * Notifies that the visibility state of Keyguard has changed. |
| 1448 | * |
| 1449 | * <p>Needs to be called from the main thread. |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 1450 | */ |
Jorim Jaggi | 6a15d52 | 2015-09-22 15:55:33 -0700 | [diff] [blame] | 1451 | public void onKeyguardVisibilityChanged(boolean showing) { |
| 1452 | if (DEBUG) Log.d(TAG, "onKeyguardVisibilityChanged(" + showing + ")"); |
| 1453 | mKeyguardIsVisible = showing; |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 1454 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1455 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1456 | if (cb != null) { |
Jorim Jaggi | 6a15d52 | 2015-09-22 15:55:33 -0700 | [diff] [blame] | 1457 | cb.onKeyguardVisibilityChangedRaw(showing); |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 1458 | } |
| 1459 | } |
Jorim Jaggi | 6a15d52 | 2015-09-22 15:55:33 -0700 | [diff] [blame] | 1460 | if (!showing) { |
Jorim Jaggi | 71448a7 | 2015-08-18 19:49:04 -0700 | [diff] [blame] | 1461 | mFingerprintAlreadyAuthenticated = false; |
| 1462 | } |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1463 | updateFingerprintListeningState(); |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 1464 | } |
| 1465 | |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 1466 | /** |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 1467 | * Handle {@link #MSG_KEYGUARD_RESET} |
| 1468 | */ |
| 1469 | private void handleKeyguardReset() { |
| 1470 | if (DEBUG) Log.d(TAG, "handleKeyguardReset"); |
Adrian Roos | f6d51ac | 2015-09-02 13:26:25 -0700 | [diff] [blame] | 1471 | updateFingerprintListeningState(); |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 1472 | mNeedsSlowUnlockTransition = resolveNeedsSlowUnlockTransition(); |
| 1473 | } |
| 1474 | |
| 1475 | private boolean resolveNeedsSlowUnlockTransition() { |
| 1476 | if (mUserManager.isUserUnlocked(getCurrentUser())) { |
| 1477 | return false; |
| 1478 | } |
| 1479 | Intent homeIntent = new Intent(Intent.ACTION_MAIN) |
| 1480 | .addCategory(Intent.CATEGORY_HOME); |
| 1481 | ResolveInfo resolveInfo = mContext.getPackageManager().resolveActivity(homeIntent, |
| 1482 | 0 /* flags */); |
| 1483 | return FALLBACK_HOME_COMPONENT.equals(resolveInfo.getComponentInfo().getComponentName()); |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | /** |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 1487 | * Handle {@link #MSG_KEYGUARD_BOUNCER_CHANGED} |
| 1488 | * @see #sendKeyguardBouncerChanged(boolean) |
| 1489 | */ |
| 1490 | private void handleKeyguardBouncerChanged(int bouncer) { |
| 1491 | if (DEBUG) Log.d(TAG, "handleKeyguardBouncerChanged(" + bouncer + ")"); |
| 1492 | boolean isBouncer = (bouncer == 1); |
| 1493 | mBouncer = isBouncer; |
| 1494 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1495 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1496 | if (cb != null) { |
| 1497 | cb.onKeyguardBouncerChanged(isBouncer); |
| 1498 | } |
| 1499 | } |
Jorim Jaggi | 3cf7eef | 2015-09-10 14:36:19 -0700 | [diff] [blame] | 1500 | updateFingerprintListeningState(); |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | /** |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 1504 | * Handle {@link #MSG_REPORT_EMERGENCY_CALL_ACTION} |
| 1505 | */ |
| 1506 | private void handleReportEmergencyCallAction() { |
| 1507 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1508 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1509 | if (cb != null) { |
| 1510 | cb.onEmergencyCallAction(); |
| 1511 | } |
| 1512 | } |
| 1513 | } |
| 1514 | |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1515 | private static boolean isBatteryUpdateInteresting(BatteryStatus old, BatteryStatus current) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1516 | final boolean nowPluggedIn = current.isPluggedIn(); |
| 1517 | final boolean wasPluggedIn = old.isPluggedIn(); |
Jim Miller | 79a444a | 2011-02-15 15:02:11 -0800 | [diff] [blame] | 1518 | final boolean stateChangedWhilePluggedIn = |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1519 | wasPluggedIn == true && nowPluggedIn == true |
| 1520 | && (old.status != current.status); |
| 1521 | |
| 1522 | // change in plug state is always interesting |
| 1523 | if (wasPluggedIn != nowPluggedIn || stateChangedWhilePluggedIn) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1524 | return true; |
| 1525 | } |
| 1526 | |
| 1527 | // change in battery level while plugged in |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1528 | if (nowPluggedIn && old.level != current.level) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1529 | return true; |
| 1530 | } |
| 1531 | |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1532 | // change where battery needs charging |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1533 | if (!nowPluggedIn && current.isBatteryLow() && current.level != old.level) { |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1534 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1535 | } |
Adrian Roos | 76dc5a5 | 2015-07-21 16:20:36 -0700 | [diff] [blame] | 1536 | |
| 1537 | // change in charging current while plugged in |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 1538 | if (nowPluggedIn && current.maxChargingWattage != old.maxChargingWattage) { |
Adrian Roos | 76dc5a5 | 2015-07-21 16:20:36 -0700 | [diff] [blame] | 1539 | return true; |
| 1540 | } |
| 1541 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1542 | return false; |
| 1543 | } |
| 1544 | |
| 1545 | /** |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1546 | * Remove the given observer's callback. |
| 1547 | * |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1548 | * @param callback The callback to remove |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1549 | */ |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1550 | public void removeCallback(KeyguardUpdateMonitorCallback callback) { |
| 1551 | if (DEBUG) Log.v(TAG, "*** unregister callback for " + callback); |
| 1552 | for (int i = mCallbacks.size() - 1; i >= 0; i--) { |
| 1553 | if (mCallbacks.get(i).get() == callback) { |
| 1554 | mCallbacks.remove(i); |
| 1555 | } |
| 1556 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1560 | * Register to receive notifications about general keyguard information |
| 1561 | * (see {@link InfoCallback}. |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1562 | * @param callback The callback to register |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1563 | */ |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1564 | public void registerCallback(KeyguardUpdateMonitorCallback callback) { |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1565 | if (DEBUG) Log.v(TAG, "*** register callback for " + callback); |
| 1566 | // Prevent adding duplicate callbacks |
| 1567 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1568 | if (mCallbacks.get(i).get() == callback) { |
| 1569 | if (DEBUG) Log.e(TAG, "Object tried to add another callback", |
| 1570 | new Exception("Called by")); |
| 1571 | return; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1572 | } |
| 1573 | } |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1574 | mCallbacks.add(new WeakReference<KeyguardUpdateMonitorCallback>(callback)); |
| 1575 | removeCallback(null); // remove unused references |
| 1576 | sendUpdates(callback); |
| 1577 | } |
| 1578 | |
Evan Rosky | 1839645 | 2016-07-27 15:19:37 -0700 | [diff] [blame] | 1579 | public boolean isSwitchingUser() { |
| 1580 | return mSwitchingUser; |
| 1581 | } |
| 1582 | |
| 1583 | public void setSwitchingUser(boolean switching) { |
| 1584 | mSwitchingUser = switching; |
| 1585 | updateFingerprintListeningState(); |
| 1586 | } |
| 1587 | |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1588 | private void sendUpdates(KeyguardUpdateMonitorCallback callback) { |
| 1589 | // Notify listener of the current state |
| 1590 | callback.onRefreshBatteryInfo(mBatteryStatus); |
| 1591 | callback.onTimeChanged(); |
| 1592 | callback.onRingerModeChanged(mRingMode); |
| 1593 | callback.onPhoneStateChanged(mPhoneState); |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 1594 | callback.onRefreshCarrierInfo(); |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1595 | callback.onClockVisibilityChanged(); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1596 | for (Entry<Integer, SimData> data : mSimDatas.entrySet()) { |
| 1597 | final SimData state = data.getValue(); |
| 1598 | callback.onSimStateChanged(state.subId, state.slotId, state.simState); |
| 1599 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1600 | } |
| 1601 | |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 1602 | public void sendKeyguardReset() { |
| 1603 | mHandler.obtainMessage(MSG_KEYGUARD_RESET).sendToTarget(); |
| 1604 | } |
| 1605 | |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 1606 | /** |
| 1607 | * @see #handleKeyguardBouncerChanged(int) |
| 1608 | */ |
| 1609 | public void sendKeyguardBouncerChanged(boolean showingBouncer) { |
| 1610 | if (DEBUG) Log.d(TAG, "sendKeyguardBouncerChanged(" + showingBouncer + ")"); |
| 1611 | Message message = mHandler.obtainMessage(MSG_KEYGUARD_BOUNCER_CHANGED); |
| 1612 | message.arg1 = showingBouncer ? 1 : 0; |
| 1613 | message.sendToTarget(); |
| 1614 | } |
| 1615 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1616 | /** |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 1617 | * Report that the user successfully entered the SIM PIN or PUK/SIM PIN so we |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1618 | * have the information earlier than waiting for the intent |
| 1619 | * broadcast from the telephony code. |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 1620 | * |
| 1621 | * NOTE: Because handleSimStateChange() invokes callbacks immediately without going |
| 1622 | * through mHandler, this *must* be called from the UI thread. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1623 | */ |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1624 | public void reportSimUnlocked(int subId) { |
| 1625 | if (DEBUG_SIM_STATES) Log.v(TAG, "reportSimUnlocked(subId=" + subId + ")"); |
| 1626 | int slotId = SubscriptionManager.getSlotId(subId); |
| 1627 | handleSimStateChange(subId, slotId, State.READY); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1628 | } |
| 1629 | |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 1630 | /** |
| 1631 | * Report that the emergency call button has been pressed and the emergency dialer is |
| 1632 | * about to be displayed. |
| 1633 | * |
| 1634 | * @param bypassHandler runs immediately. |
| 1635 | * |
| 1636 | * NOTE: Must be called from UI thread if bypassHandler == true. |
| 1637 | */ |
| 1638 | public void reportEmergencyCallAction(boolean bypassHandler) { |
| 1639 | if (!bypassHandler) { |
| 1640 | mHandler.obtainMessage(MSG_REPORT_EMERGENCY_CALL_ACTION).sendToTarget(); |
| 1641 | } else { |
| 1642 | handleReportEmergencyCallAction(); |
| 1643 | } |
| 1644 | } |
| 1645 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1646 | /** |
| 1647 | * @return Whether the device is provisioned (whether they have gone through |
| 1648 | * the setup wizard) |
| 1649 | */ |
| 1650 | public boolean isDeviceProvisioned() { |
| 1651 | return mDeviceProvisioned; |
| 1652 | } |
| 1653 | |
Jorim Jaggi | 9f74303 | 2015-05-04 15:22:40 -0700 | [diff] [blame] | 1654 | public void clearFailedUnlockAttempts() { |
| 1655 | mFailedAttempts.delete(sCurrentUser); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1656 | } |
| 1657 | |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 1658 | public int getFailedUnlockAttempts(int userId) { |
| 1659 | return mFailedAttempts.get(userId, 0); |
Jorim Jaggi | 9f74303 | 2015-05-04 15:22:40 -0700 | [diff] [blame] | 1660 | } |
| 1661 | |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 1662 | public void reportFailedStrongAuthUnlockAttempt(int userId) { |
| 1663 | mFailedAttempts.put(userId, getFailedUnlockAttempts(userId) + 1); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1664 | } |
| 1665 | |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 1666 | public void clearFingerprintRecognized() { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1667 | mUserFingerprintAuthenticated.clear(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1670 | public boolean isSimPinVoiceSecure() { |
| 1671 | // TODO: only count SIMs that handle voice |
| 1672 | return isSimPinSecure(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | public boolean isSimPinSecure() { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1676 | // True if any SIM is pin secure |
| 1677 | for (SubscriptionInfo info : getSubscriptionInfo(false /* forceReload */)) { |
| 1678 | if (isSimPinSecure(getSimState(info.getSubscriptionId()))) return true; |
| 1679 | } |
| 1680 | return false; |
| 1681 | } |
| 1682 | |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 1683 | public State getSimState(int subId) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1684 | if (mSimDatas.containsKey(subId)) { |
| 1685 | return mSimDatas.get(subId).simState; |
| 1686 | } else { |
| 1687 | return State.UNKNOWN; |
| 1688 | } |
| 1689 | } |
| 1690 | |
Jorim Jaggi | 01ba98b | 2015-01-13 21:33:45 +0100 | [diff] [blame] | 1691 | /** |
| 1692 | * @return true if and only if the state has changed for the specified {@code slotId} |
| 1693 | */ |
| 1694 | private boolean refreshSimState(int subId, int slotId) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1695 | |
| 1696 | // This is awful. It exists because there are two APIs for getting the SIM status |
| 1697 | // that don't return the complete set of values and have different types. In Keyguard we |
| 1698 | // need IccCardConstants, but TelephonyManager would only give us |
| 1699 | // TelephonyManager.SIM_STATE*, so we retrieve it manually. |
xinhe | 18b9c3c | 2014-12-02 15:03:20 -0800 | [diff] [blame] | 1700 | final TelephonyManager tele = TelephonyManager.from(mContext); |
| 1701 | int simState = tele.getSimState(slotId); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1702 | State state; |
| 1703 | try { |
xinhe | 18b9c3c | 2014-12-02 15:03:20 -0800 | [diff] [blame] | 1704 | state = State.intToState(simState); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1705 | } catch(IllegalArgumentException ex) { |
xinhe | 18b9c3c | 2014-12-02 15:03:20 -0800 | [diff] [blame] | 1706 | Log.w(TAG, "Unknown sim state: " + simState); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1707 | state = State.UNKNOWN; |
John Spurlock | 5b13e92 | 2015-01-07 11:04:58 -0500 | [diff] [blame] | 1708 | } |
Jorim Jaggi | 01ba98b | 2015-01-13 21:33:45 +0100 | [diff] [blame] | 1709 | SimData data = mSimDatas.get(subId); |
| 1710 | final boolean changed; |
| 1711 | if (data == null) { |
| 1712 | data = new SimData(state, slotId, subId); |
| 1713 | mSimDatas.put(subId, data); |
| 1714 | changed = true; // no data yet; force update |
| 1715 | } else { |
| 1716 | changed = data.simState != state; |
| 1717 | data.simState = state; |
| 1718 | } |
| 1719 | return changed; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | public static boolean isSimPinSecure(IccCardConstants.State state) { |
| 1723 | final IccCardConstants.State simState = state; |
| 1724 | return (simState == IccCardConstants.State.PIN_REQUIRED |
| 1725 | || simState == IccCardConstants.State.PUK_REQUIRED |
| 1726 | || simState == IccCardConstants.State.PERM_DISABLED); |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 1727 | } |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1728 | |
| 1729 | public DisplayClientState getCachedDisplayClientState() { |
| 1730 | return mDisplayClientState; |
| 1731 | } |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1732 | |
| 1733 | // TODO: use these callbacks elsewhere in place of the existing notifyScreen*() |
| 1734 | // (KeyguardViewMediator, KeyguardHostView) |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1735 | public void dispatchStartedWakingUp() { |
| 1736 | synchronized (this) { |
| 1737 | mDeviceInteractive = true; |
| 1738 | } |
| 1739 | mHandler.sendEmptyMessage(MSG_STARTED_WAKING_UP); |
| 1740 | } |
| 1741 | |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 1742 | public void dispatchStartedGoingToSleep(int why) { |
| 1743 | mHandler.sendMessage(mHandler.obtainMessage(MSG_STARTED_GOING_TO_SLEEP, why, 0)); |
| 1744 | } |
| 1745 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1746 | public void dispatchFinishedGoingToSleep(int why) { |
| 1747 | synchronized(this) { |
| 1748 | mDeviceInteractive = false; |
| 1749 | } |
| 1750 | mHandler.sendMessage(mHandler.obtainMessage(MSG_FINISHED_GOING_TO_SLEEP, why, 0)); |
| 1751 | } |
| 1752 | |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1753 | public void dispatchScreenTurnedOn() { |
| 1754 | synchronized (this) { |
| 1755 | mScreenOn = true; |
| 1756 | } |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 1757 | mHandler.sendEmptyMessage(MSG_SCREEN_TURNED_ON); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1758 | } |
| 1759 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1760 | public void dispatchScreenTurnedOff() { |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1761 | synchronized(this) { |
| 1762 | mScreenOn = false; |
| 1763 | } |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 1764 | mHandler.sendEmptyMessage(MSG_SCREEN_TURNED_OFF); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
Selim Cinek | 9941539 | 2016-09-09 14:58:41 -0700 | [diff] [blame] | 1767 | public void dispatchDreamingStarted() { |
| 1768 | mHandler.sendMessage(mHandler.obtainMessage(MSG_DREAMING_STATE_CHANGED, 1, 0)); |
| 1769 | } |
| 1770 | |
| 1771 | public void dispatchDreamingStopped() { |
| 1772 | mHandler.sendMessage(mHandler.obtainMessage(MSG_DREAMING_STATE_CHANGED, 0, 0)); |
| 1773 | } |
| 1774 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1775 | public boolean isDeviceInteractive() { |
| 1776 | return mDeviceInteractive; |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1777 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1778 | |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 1779 | public boolean isGoingToSleep() { |
| 1780 | return mGoingToSleep; |
| 1781 | } |
| 1782 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1783 | /** |
| 1784 | * Find the next SubscriptionId for a SIM in the given state, favoring lower slot numbers first. |
| 1785 | * @param state |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1786 | * @return subid or {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} if none found |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1787 | */ |
| 1788 | public int getNextSubIdForState(State state) { |
| 1789 | List<SubscriptionInfo> list = getSubscriptionInfo(false /* forceReload */); |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1790 | int resultId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1791 | int bestSlotId = Integer.MAX_VALUE; // Favor lowest slot first |
| 1792 | for (int i = 0; i < list.size(); i++) { |
| 1793 | final SubscriptionInfo info = list.get(i); |
| 1794 | final int id = info.getSubscriptionId(); |
| 1795 | int slotId = SubscriptionManager.getSlotId(id); |
| 1796 | if (state == getSimState(id) && bestSlotId > slotId ) { |
| 1797 | resultId = id; |
| 1798 | bestSlotId = slotId; |
| 1799 | } |
| 1800 | } |
| 1801 | return resultId; |
| 1802 | } |
| 1803 | |
| 1804 | public SubscriptionInfo getSubscriptionInfoForSubId(int subId) { |
| 1805 | List<SubscriptionInfo> list = getSubscriptionInfo(false /* forceReload */); |
| 1806 | for (int i = 0; i < list.size(); i++) { |
| 1807 | SubscriptionInfo info = list.get(i); |
| 1808 | if (subId == info.getSubscriptionId()) return info; |
| 1809 | } |
| 1810 | return null; // not found |
| 1811 | } |
Jason Monk | ab52527 | 2015-07-13 17:02:49 -0400 | [diff] [blame] | 1812 | |
| 1813 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1814 | pw.println("KeyguardUpdateMonitor state:"); |
| 1815 | pw.println(" SIM States:"); |
| 1816 | for (SimData data : mSimDatas.values()) { |
| 1817 | pw.println(" " + data.toString()); |
| 1818 | } |
| 1819 | pw.println(" Subs:"); |
| 1820 | if (mSubscriptionInfo != null) { |
| 1821 | for (int i = 0; i < mSubscriptionInfo.size(); i++) { |
| 1822 | pw.println(" " + mSubscriptionInfo.get(i)); |
| 1823 | } |
| 1824 | } |
| 1825 | pw.println(" Service states:"); |
| 1826 | for (int subId : mServiceStates.keySet()) { |
| 1827 | pw.println(" " + subId + "=" + mServiceStates.get(subId)); |
| 1828 | } |
Jim Miller | d72d5ac | 2015-09-29 18:55:32 -0700 | [diff] [blame] | 1829 | if (mFpm != null && mFpm.isHardwareDetected()) { |
| 1830 | final int userId = ActivityManager.getCurrentUser(); |
| 1831 | final int strongAuthFlags = mStrongAuthTracker.getStrongAuthForUser(userId); |
| 1832 | pw.println(" Fingerprint state (user=" + userId + ")"); |
| 1833 | pw.println(" allowed=" + isUnlockingWithFingerprintAllowed()); |
| 1834 | pw.println(" auth'd=" + mUserFingerprintAuthenticated.get(userId)); |
| 1835 | pw.println(" authSinceBoot=" |
| 1836 | + getStrongAuthTracker().hasUserAuthenticatedSinceBoot()); |
| 1837 | pw.println(" disabled(DPM)=" + isFingerprintDisabled(userId)); |
| 1838 | pw.println(" possible=" + isUnlockWithFingerprintPossible(userId)); |
| 1839 | pw.println(" strongAuthFlags=" + Integer.toHexString(strongAuthFlags)); |
| 1840 | pw.println(" timedout=" + hasFingerprintUnlockTimedOut(userId)); |
| 1841 | pw.println(" trustManaged=" + getUserTrustIsManaged(userId)); |
| 1842 | } |
Jason Monk | ab52527 | 2015-07-13 17:02:49 -0400 | [diff] [blame] | 1843 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1844 | } |