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