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; |
| 32 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 33 | import static android.os.BatteryManager.BATTERY_STATUS_FULL; |
| 34 | import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN; |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 35 | import static android.os.BatteryManager.BATTERY_HEALTH_UNKNOWN; |
| 36 | import static android.os.BatteryManager.EXTRA_STATUS; |
| 37 | import static android.os.BatteryManager.EXTRA_PLUGGED; |
| 38 | import static android.os.BatteryManager.EXTRA_LEVEL; |
| 39 | import static android.os.BatteryManager.EXTRA_HEALTH; |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 40 | |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 41 | import android.media.AudioManager; |
Jim Miller | 79a444a | 2011-02-15 15:02:11 -0800 | [diff] [blame] | 42 | import android.os.BatteryManager; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 43 | import android.os.CancellationSignal; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 44 | import android.os.Handler; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 45 | import android.os.IRemoteCallback; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 46 | import android.os.Message; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 47 | import android.os.RemoteException; |
Amith Yamasani | e8e93a1 | 2013-05-09 18:12:30 -0700 | [diff] [blame] | 48 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 49 | import android.provider.Settings; |
Dianne Hackborn | b7e787f | 2009-05-07 15:55:42 -0700 | [diff] [blame] | 50 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 51 | import com.android.internal.telephony.IccCardConstants; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 52 | import com.android.internal.telephony.IccCardConstants.State; |
| 53 | import com.android.internal.telephony.PhoneConstants; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 54 | import com.android.internal.telephony.TelephonyIntents; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 55 | |
Jim Miller | ebbf205 | 2015-03-31 17:24:34 -0700 | [diff] [blame] | 56 | import android.hardware.fingerprint.FingerprintManager; |
| 57 | import android.hardware.fingerprint.FingerprintManager.AuthenticationCallback; |
Jim Miller | ebbf205 | 2015-03-31 17:24:34 -0700 | [diff] [blame] | 58 | import android.hardware.fingerprint.FingerprintManager.AuthenticationResult; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 59 | import android.telephony.SubscriptionInfo; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 60 | import android.telephony.SubscriptionManager; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 61 | import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener; |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 62 | import android.telephony.TelephonyManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 63 | import android.util.Log; |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 64 | import android.util.SparseBooleanArray; |
Jorim Jaggi | 9f74303 | 2015-05-04 15:22:40 -0700 | [diff] [blame] | 65 | import android.util.SparseIntArray; |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 66 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 67 | import com.google.android.collect.Lists; |
| 68 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 69 | import java.lang.ref.WeakReference; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 70 | import java.util.ArrayList; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 71 | import java.util.HashMap; |
| 72 | import java.util.List; |
| 73 | import java.util.Map.Entry; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Watches for updates that may be interesting to the keyguard, and provides |
| 77 | * the up to date information as well as a registration for callbacks that care |
| 78 | * to be updated. |
| 79 | * |
| 80 | * Note: under time crunch, this has been extended to include some stuff that |
| 81 | * doesn't really belong here. see {@link #handleBatteryUpdate} where it shutdowns |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 82 | * the device, and {@link #getFailedUnlockAttempts()}, {@link #reportFailedAttempt()} |
| 83 | * and {@link #clearFailedUnlockAttempts()}. Maybe we should rename this 'KeyguardContext'... |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 84 | */ |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 85 | public class KeyguardUpdateMonitor implements TrustManager.TrustListener { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 86 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 87 | private static final String TAG = "KeyguardUpdateMonitor"; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 88 | private static final boolean DEBUG = KeyguardConstants.DEBUG; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 89 | private static final boolean DEBUG_SIM_STATES = KeyguardConstants.DEBUG_SIM_STATES; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 90 | private static final int LOW_BATTERY_THRESHOLD = 20; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 91 | |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 92 | private static final String ACTION_FACE_UNLOCK_STARTED |
| 93 | = "com.android.facelock.FACE_UNLOCK_STARTED"; |
| 94 | private static final String ACTION_FACE_UNLOCK_STOPPED |
| 95 | = "com.android.facelock.FACE_UNLOCK_STOPPED"; |
| 96 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 97 | // Callback messages |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 98 | private static final int MSG_TIME_UPDATE = 301; |
| 99 | private static final int MSG_BATTERY_UPDATE = 302; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 100 | private static final int MSG_SIM_STATE_CHANGE = 304; |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 101 | private static final int MSG_RINGER_MODE_CHANGED = 305; |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 102 | private static final int MSG_PHONE_STATE_CHANGED = 306; |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 103 | private static final int MSG_DEVICE_PROVISIONED = 308; |
Jim Miller | 5737534 | 2012-09-09 15:20:31 -0700 | [diff] [blame] | 104 | private static final int MSG_DPM_STATE_CHANGED = 309; |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 105 | private static final int MSG_USER_SWITCHING = 310; |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 106 | private static final int MSG_KEYGUARD_VISIBILITY_CHANGED = 312; |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 107 | private static final int MSG_BOOT_COMPLETED = 313; |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 108 | private static final int MSG_USER_SWITCH_COMPLETE = 314; |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 109 | private static final int MSG_USER_INFO_CHANGED = 317; |
| 110 | private static final int MSG_REPORT_EMERGENCY_CALL_ACTION = 318; |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 111 | private static final int MSG_SCREEN_TURNED_ON = 319; |
| 112 | private static final int MSG_SCREEN_TURNED_OFF = 320; |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 113 | private static final int MSG_KEYGUARD_BOUNCER_CHANGED = 322; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 114 | private static final int MSG_FINGERPRINT_AUTHENTICATED = 323; |
| 115 | private static final int MSG_FINGERPRINT_ERROR = 324; |
| 116 | private static final int MSG_FINGERPRINT_HELP = 325; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 117 | private static final int MSG_FINGERPRINT_AUTH_FAILED = 326; |
| 118 | private static final int MSG_FACE_UNLOCK_STATE_CHANGED = 327; |
| 119 | private static final int MSG_SIM_SUBSCRIPTION_INFO_CHANGED = 328; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 120 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 121 | private static KeyguardUpdateMonitor sInstance; |
| 122 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 123 | private final Context mContext; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 124 | HashMap<Integer, SimData> mSimDatas = new HashMap<Integer, SimData>(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 125 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 126 | private int mRingMode; |
| 127 | private int mPhoneState; |
Danielle Millett | 5d2404d | 2012-11-01 00:05:27 -0400 | [diff] [blame] | 128 | private boolean mKeyguardIsVisible; |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 129 | private boolean mBouncer; |
Adam Cohen | 4eb36cf | 2012-11-07 11:45:30 -0800 | [diff] [blame] | 130 | private boolean mBootCompleted; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 131 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 132 | // Device provisioning state |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 133 | private boolean mDeviceProvisioned; |
| 134 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 135 | // Battery status |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 136 | private BatteryStatus mBatteryStatus; |
| 137 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 138 | // Password attempts |
Jorim Jaggi | 9f74303 | 2015-05-04 15:22:40 -0700 | [diff] [blame] | 139 | private SparseIntArray mFailedAttempts = new SparseIntArray(); |
Brian Colonna | cc4104f | 2012-10-09 17:50:46 -0400 | [diff] [blame] | 140 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 141 | private boolean mClockVisible; |
| 142 | |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 143 | private final ArrayList<WeakReference<KeyguardUpdateMonitorCallback>> |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 144 | mCallbacks = Lists.newArrayList(); |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 145 | private ContentObserver mDeviceProvisionedObserver; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 146 | |
Brian Colonna | a523989 | 2013-04-15 11:45:40 -0400 | [diff] [blame] | 147 | private boolean mSwitchingUser; |
| 148 | |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 149 | private boolean mScreenOn; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 150 | private SubscriptionManager mSubscriptionManager; |
| 151 | private List<SubscriptionInfo> mSubscriptionInfo; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 152 | private boolean mFingerprintDetectionRunning; |
Jorim Jaggi | 237b061 | 2015-05-01 14:28:49 -0700 | [diff] [blame] | 153 | private TrustManager mTrustManager; |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 154 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 155 | private final Handler mHandler = new Handler() { |
| 156 | @Override |
| 157 | public void handleMessage(Message msg) { |
| 158 | switch (msg.what) { |
| 159 | case MSG_TIME_UPDATE: |
| 160 | handleTimeUpdate(); |
| 161 | break; |
| 162 | case MSG_BATTERY_UPDATE: |
| 163 | handleBatteryUpdate((BatteryStatus) msg.obj); |
| 164 | break; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 165 | case MSG_SIM_STATE_CHANGE: |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 166 | handleSimStateChange(msg.arg1, msg.arg2, (State) msg.obj); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 167 | break; |
| 168 | case MSG_RINGER_MODE_CHANGED: |
| 169 | handleRingerModeChange(msg.arg1); |
| 170 | break; |
| 171 | case MSG_PHONE_STATE_CHANGED: |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 172 | handlePhoneStateChanged((String) msg.obj); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 173 | break; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 174 | case MSG_DEVICE_PROVISIONED: |
| 175 | handleDeviceProvisioned(); |
| 176 | break; |
| 177 | case MSG_DPM_STATE_CHANGED: |
| 178 | handleDevicePolicyManagerStateChanged(); |
| 179 | break; |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 180 | case MSG_USER_SWITCHING: |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 181 | handleUserSwitching(msg.arg1, (IRemoteCallback) msg.obj); |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 182 | break; |
| 183 | case MSG_USER_SWITCH_COMPLETE: |
| 184 | handleUserSwitchComplete(msg.arg1); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 185 | break; |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 186 | case MSG_KEYGUARD_VISIBILITY_CHANGED: |
| 187 | handleKeyguardVisibilityChanged(msg.arg1); |
| 188 | break; |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 189 | case MSG_KEYGUARD_BOUNCER_CHANGED: |
| 190 | handleKeyguardBouncerChanged(msg.arg1); |
| 191 | break; |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 192 | case MSG_BOOT_COMPLETED: |
| 193 | handleBootCompleted(); |
| 194 | break; |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 195 | case MSG_USER_INFO_CHANGED: |
| 196 | handleUserInfoChanged(msg.arg1); |
| 197 | break; |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 198 | case MSG_REPORT_EMERGENCY_CALL_ACTION: |
| 199 | handleReportEmergencyCallAction(); |
| 200 | break; |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 201 | case MSG_SCREEN_TURNED_OFF: |
| 202 | handleScreenTurnedOff(msg.arg1); |
| 203 | break; |
| 204 | case MSG_SCREEN_TURNED_ON: |
| 205 | handleScreenTurnedOn(); |
| 206 | break; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 207 | case MSG_FINGERPRINT_AUTHENTICATED: |
Jim Miller | 4f364c9 | 2015-06-08 19:24:13 -0700 | [diff] [blame^] | 208 | handleFingerprintAuthenticated(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 209 | break; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 210 | case MSG_FINGERPRINT_HELP: |
| 211 | handleFingerprintHelp(msg.arg1 /* msgId */, (String) msg.obj /* errString */); |
| 212 | break; |
| 213 | case MSG_FINGERPRINT_ERROR: |
| 214 | handleFingerprintError(msg.arg1 /* msgId */, (String) msg.obj /* errString */); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 215 | break; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 216 | case MSG_FINGERPRINT_AUTH_FAILED: |
| 217 | handleFingerprintAuthFailed(); |
| 218 | break; |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 219 | case MSG_FACE_UNLOCK_STATE_CHANGED: |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 220 | handleFaceUnlockStateChanged(msg.arg1 != 0, msg.arg2); |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 221 | break; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 222 | case MSG_SIM_SUBSCRIPTION_INFO_CHANGED: |
| 223 | handleSimSubscriptionInfoChanged(); |
| 224 | break; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | }; |
| 228 | |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 229 | private OnSubscriptionsChangedListener mSubscriptionListener = |
| 230 | new OnSubscriptionsChangedListener() { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 231 | @Override |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 232 | public void onSubscriptionsChanged() { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 233 | mHandler.sendEmptyMessage(MSG_SIM_SUBSCRIPTION_INFO_CHANGED); |
| 234 | } |
| 235 | }; |
| 236 | |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 237 | private SparseBooleanArray mUserHasTrust = new SparseBooleanArray(); |
Adrian Roos | 7861c66 | 2014-07-25 15:37:28 +0200 | [diff] [blame] | 238 | private SparseBooleanArray mUserTrustIsManaged = new SparseBooleanArray(); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 239 | private SparseBooleanArray mUserFingerprintAuthenticated = new SparseBooleanArray(); |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 240 | private SparseBooleanArray mUserFaceUnlockRunning = new SparseBooleanArray(); |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 241 | |
Adrian Roos | d6aa6cb | 2015-04-16 19:31:29 -0700 | [diff] [blame] | 242 | private static int sCurrentUser; |
| 243 | |
| 244 | public synchronized static void setCurrentUser(int currentUser) { |
| 245 | sCurrentUser = currentUser; |
| 246 | } |
| 247 | |
| 248 | public synchronized static int getCurrentUser() { |
| 249 | return sCurrentUser; |
| 250 | } |
| 251 | |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 252 | @Override |
Adrian Roos | 94e15a5 | 2015-04-16 12:23:18 -0700 | [diff] [blame] | 253 | public void onTrustChanged(boolean enabled, int userId, int flags) { |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 254 | mUserHasTrust.put(userId, enabled); |
Adrian Roos | 2fe592d | 2014-05-17 03:11:59 +0200 | [diff] [blame] | 255 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 256 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 257 | if (cb != null) { |
| 258 | cb.onTrustChanged(userId); |
Adrian Roos | 94e15a5 | 2015-04-16 12:23:18 -0700 | [diff] [blame] | 259 | if (enabled && flags != 0) { |
| 260 | cb.onTrustGrantedWithFlags(flags, userId); |
Adrian Roos | 3c9a350 | 2014-08-06 19:09:45 +0200 | [diff] [blame] | 261 | } |
Adrian Roos | 2fe592d | 2014-05-17 03:11:59 +0200 | [diff] [blame] | 262 | } |
| 263 | } |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 264 | } |
| 265 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 266 | protected void handleSimSubscriptionInfoChanged() { |
| 267 | if (DEBUG_SIM_STATES) { |
| 268 | Log.v(TAG, "onSubscriptionInfoChanged()"); |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 269 | List<SubscriptionInfo> sil = mSubscriptionManager.getActiveSubscriptionInfoList(); |
| 270 | if (sil != null) { |
| 271 | for (SubscriptionInfo subInfo : sil) { |
| 272 | Log.v(TAG, "SubInfo:" + subInfo); |
| 273 | } |
| 274 | } else { |
| 275 | Log.v(TAG, "onSubscriptionInfoChanged: list is null"); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | List<SubscriptionInfo> subscriptionInfos = getSubscriptionInfo(true /* forceReload */); |
| 279 | |
| 280 | // Hack level over 9000: Because the subscription id is not yet valid when we see the |
| 281 | // first update in handleSimStateChange, we need to force refresh all all SIM states |
| 282 | // so the subscription id for them is consistent. |
Jorim Jaggi | 01ba98b | 2015-01-13 21:33:45 +0100 | [diff] [blame] | 283 | ArrayList<SubscriptionInfo> changedSubscriptions = new ArrayList<>(); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 284 | for (int i = 0; i < subscriptionInfos.size(); i++) { |
| 285 | SubscriptionInfo info = subscriptionInfos.get(i); |
Jorim Jaggi | 01ba98b | 2015-01-13 21:33:45 +0100 | [diff] [blame] | 286 | boolean changed = refreshSimState(info.getSubscriptionId(), info.getSimSlotIndex()); |
| 287 | if (changed) { |
| 288 | changedSubscriptions.add(info); |
| 289 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 290 | } |
Jorim Jaggi | 01ba98b | 2015-01-13 21:33:45 +0100 | [diff] [blame] | 291 | for (int i = 0; i < changedSubscriptions.size(); i++) { |
| 292 | SimData data = mSimDatas.get(changedSubscriptions.get(i).getSubscriptionId()); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 293 | for (int j = 0; j < mCallbacks.size(); j++) { |
| 294 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get(); |
| 295 | if (cb != null) { |
| 296 | cb.onSimStateChanged(data.subId, data.slotId, data.simState); |
| 297 | } |
| 298 | } |
| 299 | } |
Jason Monk | 6c985dc | 2015-01-09 16:07:14 -0500 | [diff] [blame] | 300 | for (int j = 0; j < mCallbacks.size(); j++) { |
| 301 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get(); |
| 302 | if (cb != null) { |
| 303 | cb.onRefreshCarrierInfo(); |
| 304 | } |
| 305 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 306 | } |
| 307 | |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 308 | /** @return List of SubscriptionInfo records, maybe empty but never null */ |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 309 | List<SubscriptionInfo> getSubscriptionInfo(boolean forceReload) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 310 | List<SubscriptionInfo> sil = mSubscriptionInfo; |
| 311 | if (sil == null || forceReload) { |
| 312 | sil = mSubscriptionManager.getActiveSubscriptionInfoList(); |
| 313 | } |
| 314 | if (sil == null) { |
| 315 | // getActiveSubscriptionInfoList was null callers expect an empty list. |
| 316 | mSubscriptionInfo = new ArrayList<SubscriptionInfo>(); |
| 317 | } else { |
| 318 | mSubscriptionInfo = sil; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 319 | } |
| 320 | return mSubscriptionInfo; |
| 321 | } |
| 322 | |
Adrian Roos | 7861c66 | 2014-07-25 15:37:28 +0200 | [diff] [blame] | 323 | @Override |
| 324 | public void onTrustManagedChanged(boolean managed, int userId) { |
| 325 | mUserTrustIsManaged.put(userId, managed); |
| 326 | |
| 327 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 328 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 329 | if (cb != null) { |
| 330 | cb.onTrustManagedChanged(userId); |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 335 | private void onFingerprintAuthenticated(int userId) { |
| 336 | mUserFingerprintAuthenticated.put(userId, true); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 337 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 338 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 339 | if (cb != null) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 340 | cb.onFingerprintAuthenticated(userId); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 345 | private void handleFingerprintAuthFailed() { |
| 346 | // FingerprintManager will allow us to retry a few times before finally giving up. |
| 347 | // TODO: Figure out the proper logic to stop this call when max tries is reached. |
| 348 | handleFingerprintHelp(-1, mContext.getString(R.string.fingerprint_not_recognized)); |
| 349 | } |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 350 | |
Jim Miller | 4f364c9 | 2015-06-08 19:24:13 -0700 | [diff] [blame^] | 351 | private void handleFingerprintAuthenticated() { |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 352 | try { |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 353 | final int userId; |
| 354 | try { |
| 355 | userId = ActivityManagerNative.getDefault().getCurrentUser().id; |
| 356 | } catch (RemoteException e) { |
| 357 | Log.e(TAG, "Failed to get current user id: ", e); |
| 358 | return; |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 359 | } |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 360 | if (isFingerprintDisabled(userId)) { |
| 361 | Log.d(TAG, "Fingerprint disabled by DPM for userId: " + userId); |
| 362 | return; |
| 363 | } |
Jim Miller | be67542 | 2015-05-11 20:45:25 -0700 | [diff] [blame] | 364 | onFingerprintAuthenticated(userId); |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 365 | } finally { |
| 366 | setFingerprintRunningDetectionRunning(false); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 370 | private void handleFingerprintHelp(int msgId, String helpString) { |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 371 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 372 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 373 | if (cb != null) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 374 | cb.onFingerprintHelp(msgId, helpString); |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | private void handleFingerprintError(int msgId, String errString) { |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 380 | setFingerprintRunningDetectionRunning(false); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 381 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 382 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 383 | if (cb != null) { |
| 384 | cb.onFingerprintError(msgId, errString); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | } |
| 388 | |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 389 | private void setFingerprintRunningDetectionRunning(boolean running) { |
| 390 | if (running != mFingerprintDetectionRunning) { |
| 391 | mFingerprintDetectionRunning = running; |
| 392 | notifyFingerprintRunningStateChanged(); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | private void notifyFingerprintRunningStateChanged() { |
| 397 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 398 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 399 | if (cb != null) { |
| 400 | cb.onFingerprintRunningStateChanged(mFingerprintDetectionRunning); |
| 401 | } |
| 402 | } |
| 403 | } |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 404 | private void handleFaceUnlockStateChanged(boolean running, int userId) { |
| 405 | mUserFaceUnlockRunning.put(userId, running); |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 406 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 407 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 408 | if (cb != null) { |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 409 | cb.onFaceUnlockStateChanged(running, userId); |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | } |
| 413 | |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 414 | public boolean isFaceUnlockRunning(int userId) { |
| 415 | return mUserFaceUnlockRunning.get(userId); |
| 416 | } |
| 417 | |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 418 | public boolean isFingerprintDetectionRunning() { |
| 419 | return mFingerprintDetectionRunning; |
| 420 | } |
| 421 | |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 422 | private boolean isTrustDisabled(int userId) { |
Adrian Roos | a4da9f6 | 2015-02-21 01:15:21 +0100 | [diff] [blame] | 423 | // Don't allow trust agent if device is secured with a SIM PIN. This is here |
| 424 | // mainly because there's no other way to prompt the user to enter their SIM PIN |
| 425 | // once they get past the keyguard screen. |
| 426 | final boolean disabledBySimPin = isSimPinSecure(); |
| 427 | return disabledBySimPin; |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 430 | private boolean isFingerprintDisabled(int userId) { |
| 431 | final DevicePolicyManager dpm = |
| 432 | (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE); |
| 433 | return dpm != null && (dpm.getKeyguardDisabledFeatures(null, userId) |
| 434 | & DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT) != 0; |
| 435 | } |
| 436 | |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 437 | public boolean getUserHasTrust(int userId) { |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 438 | return !isTrustDisabled(userId) && mUserHasTrust.get(userId) |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 439 | || mUserFingerprintAuthenticated.get(userId); |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 440 | } |
| 441 | |
Adrian Roos | 7861c66 | 2014-07-25 15:37:28 +0200 | [diff] [blame] | 442 | public boolean getUserTrustIsManaged(int userId) { |
| 443 | return mUserTrustIsManaged.get(userId) && !isTrustDisabled(userId); |
| 444 | } |
| 445 | |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 446 | static class DisplayClientState { |
| 447 | public int clientGeneration; |
| 448 | public boolean clearing; |
| 449 | public PendingIntent intent; |
| 450 | public int playbackState; |
| 451 | public long playbackEventTime; |
| 452 | } |
| 453 | |
| 454 | private DisplayClientState mDisplayClientState = new DisplayClientState(); |
| 455 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 456 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 457 | |
| 458 | public void onReceive(Context context, Intent intent) { |
| 459 | final String action = intent.getAction(); |
| 460 | if (DEBUG) Log.d(TAG, "received broadcast " + action); |
| 461 | |
| 462 | if (Intent.ACTION_TIME_TICK.equals(action) |
| 463 | || Intent.ACTION_TIME_CHANGED.equals(action) |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 464 | || Intent.ACTION_TIMEZONE_CHANGED.equals(action)) { |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 465 | mHandler.sendEmptyMessage(MSG_TIME_UPDATE); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 466 | } else if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { |
| 467 | final int status = intent.getIntExtra(EXTRA_STATUS, BATTERY_STATUS_UNKNOWN); |
| 468 | final int plugged = intent.getIntExtra(EXTRA_PLUGGED, 0); |
| 469 | final int level = intent.getIntExtra(EXTRA_LEVEL, 0); |
| 470 | final int health = intent.getIntExtra(EXTRA_HEALTH, BATTERY_HEALTH_UNKNOWN); |
| 471 | final Message msg = mHandler.obtainMessage( |
| 472 | MSG_BATTERY_UPDATE, new BatteryStatus(status, level, plugged, health)); |
| 473 | mHandler.sendMessage(msg); |
| 474 | } else if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 475 | SimData args = SimData.fromIntent(intent); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 476 | if (DEBUG_SIM_STATES) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 477 | Log.v(TAG, "action " + action |
| 478 | + " state: " + intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE) |
| 479 | + " slotId: " + args.slotId + " subid: " + args.subId); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 480 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 481 | mHandler.obtainMessage(MSG_SIM_STATE_CHANGE, args.subId, args.slotId, args.simState) |
| 482 | .sendToTarget(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 483 | } else if (AudioManager.RINGER_MODE_CHANGED_ACTION.equals(action)) { |
| 484 | mHandler.sendMessage(mHandler.obtainMessage(MSG_RINGER_MODE_CHANGED, |
| 485 | intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1), 0)); |
| 486 | } else if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(action)) { |
| 487 | String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); |
| 488 | mHandler.sendMessage(mHandler.obtainMessage(MSG_PHONE_STATE_CHANGED, state)); |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 489 | } else if (Intent.ACTION_BOOT_COMPLETED.equals(action)) { |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 490 | dispatchBootCompleted(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | }; |
Jim Miller | 2de5ee8 | 2012-06-14 22:22:50 -0700 | [diff] [blame] | 494 | |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 495 | private final BroadcastReceiver mBroadcastAllReceiver = new BroadcastReceiver() { |
| 496 | |
| 497 | public void onReceive(Context context, Intent intent) { |
| 498 | final String action = intent.getAction(); |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 499 | if (AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED.equals(action)) { |
| 500 | mHandler.sendEmptyMessage(MSG_TIME_UPDATE); |
| 501 | } else if (Intent.ACTION_USER_INFO_CHANGED.equals(action)) { |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 502 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_INFO_CHANGED, |
| 503 | intent.getIntExtra(Intent.EXTRA_USER_HANDLE, getSendingUserId()), 0)); |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 504 | } else if (ACTION_FACE_UNLOCK_STARTED.equals(action)) { |
| 505 | mHandler.sendMessage(mHandler.obtainMessage(MSG_FACE_UNLOCK_STATE_CHANGED, 1, |
| 506 | getSendingUserId())); |
| 507 | } else if (ACTION_FACE_UNLOCK_STOPPED.equals(action)) { |
| 508 | mHandler.sendMessage(mHandler.obtainMessage(MSG_FACE_UNLOCK_STATE_CHANGED, 0, |
| 509 | getSendingUserId())); |
| 510 | } else if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 511 | .equals(action)) { |
| 512 | mHandler.sendEmptyMessage(MSG_DPM_STATE_CHANGED); |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | }; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 516 | |
| 517 | private FingerprintManager.AuthenticationCallback mAuthenticationCallback |
| 518 | = new AuthenticationCallback() { |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 519 | |
| 520 | @Override |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 521 | public void onAuthenticationFailed() { |
| 522 | mHandler.obtainMessage(MSG_FINGERPRINT_AUTH_FAILED).sendToTarget(); |
| 523 | }; |
| 524 | |
| 525 | @Override |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 526 | public void onAuthenticationSucceeded(AuthenticationResult result) { |
Jim Miller | 4f364c9 | 2015-06-08 19:24:13 -0700 | [diff] [blame^] | 527 | mHandler.obtainMessage(MSG_FINGERPRINT_AUTHENTICATED).sendToTarget(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | @Override |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 531 | public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) { |
| 532 | mHandler.obtainMessage(MSG_FINGERPRINT_HELP, helpMsgId, 0, helpString).sendToTarget(); |
| 533 | } |
| 534 | |
| 535 | @Override |
| 536 | public void onAuthenticationError(int errMsgId, CharSequence errString) { |
Jorim Jaggi | 570de1e | 2015-05-01 15:08:34 -0700 | [diff] [blame] | 537 | mHandler.obtainMessage(MSG_FINGERPRINT_ERROR, errMsgId, 0, errString).sendToTarget(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 538 | } |
| 539 | }; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 540 | private CancellationSignal mFingerprintCancelSignal; |
| 541 | private FingerprintManager mFpm; |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 542 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 543 | /** |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 544 | * When we receive a |
| 545 | * {@link com.android.internal.telephony.TelephonyIntents#ACTION_SIM_STATE_CHANGED} broadcast, |
Wink Saville | 37c124c | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 546 | * 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] | 547 | * 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] | 548 | * the intent and provide a {@link SimCard.State} result. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 549 | */ |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 550 | private static class SimData { |
| 551 | public State simState; |
| 552 | public int slotId; |
| 553 | public int subId; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 554 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 555 | SimData(State state, int slot, int id) { |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 556 | simState = state; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 557 | slotId = slot; |
| 558 | subId = id; |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 559 | } |
| 560 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 561 | static SimData fromIntent(Intent intent) { |
| 562 | State state; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 563 | if (!TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(intent.getAction())) { |
| 564 | throw new IllegalArgumentException("only handles intent ACTION_SIM_STATE_CHANGED"); |
| 565 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 566 | String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 567 | int slotId = intent.getIntExtra(PhoneConstants.SLOT_KEY, 0); |
| 568 | int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 569 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 570 | if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) { |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 571 | final String absentReason = intent |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 572 | .getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON); |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 573 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 574 | if (IccCardConstants.INTENT_VALUE_ABSENT_ON_PERM_DISABLED.equals( |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 575 | absentReason)) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 576 | state = IccCardConstants.State.PERM_DISABLED; |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 577 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 578 | state = IccCardConstants.State.ABSENT; |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 579 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 580 | } else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) { |
| 581 | state = IccCardConstants.State.READY; |
| 582 | } else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 583 | final String lockedReason = intent |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 584 | .getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON); |
| 585 | if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) { |
| 586 | state = IccCardConstants.State.PIN_REQUIRED; |
| 587 | } else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) { |
| 588 | state = IccCardConstants.State.PUK_REQUIRED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 589 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 590 | state = IccCardConstants.State.UNKNOWN; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 591 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 592 | } else if (IccCardConstants.INTENT_VALUE_LOCKED_NETWORK.equals(stateExtra)) { |
| 593 | state = IccCardConstants.State.NETWORK_LOCKED; |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 594 | } else if (IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(stateExtra) |
| 595 | || IccCardConstants.INTENT_VALUE_ICC_IMSI.equals(stateExtra)) { |
| 596 | // This is required because telephony doesn't return to "READY" after |
| 597 | // these state transitions. See bug 7197471. |
| 598 | state = IccCardConstants.State.READY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 599 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 600 | state = IccCardConstants.State.UNKNOWN; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 601 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 602 | return new SimData(state, slotId, subId); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | public String toString() { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 606 | return "SimData{state=" + simState + ",slotId=" + slotId + ",subId=" + subId + "}"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 607 | } |
| 608 | } |
| 609 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 610 | public static class BatteryStatus { |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 611 | public final int status; |
| 612 | public final int level; |
| 613 | public final int plugged; |
| 614 | public final int health; |
| 615 | public BatteryStatus(int status, int level, int plugged, int health) { |
| 616 | this.status = status; |
| 617 | this.level = level; |
| 618 | this.plugged = plugged; |
| 619 | this.health = health; |
| 620 | } |
| 621 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 622 | /** |
Brian Muramatsu | a92a01b | 2012-09-05 21:54:39 -0700 | [diff] [blame] | 623 | * Determine whether the device is plugged in (USB, power, or wireless). |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 624 | * @return true if the device is plugged in. |
| 625 | */ |
Adrian Roos | ad3bc7f | 2014-10-30 18:29:38 +0100 | [diff] [blame] | 626 | public boolean isPluggedIn() { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 627 | return plugged == BatteryManager.BATTERY_PLUGGED_AC |
Brian Muramatsu | a92a01b | 2012-09-05 21:54:39 -0700 | [diff] [blame] | 628 | || plugged == BatteryManager.BATTERY_PLUGGED_USB |
| 629 | || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | /** |
| 633 | * Whether or not the device is charged. Note that some devices never return 100% for |
| 634 | * battery level, so this allows either battery level or status to determine if the |
| 635 | * battery is charged. |
| 636 | * @return true if the device is charged |
| 637 | */ |
| 638 | public boolean isCharged() { |
| 639 | return status == BATTERY_STATUS_FULL || level >= 100; |
| 640 | } |
| 641 | |
| 642 | /** |
| 643 | * Whether battery is low and needs to be charged. |
| 644 | * @return true if battery is low |
| 645 | */ |
| 646 | public boolean isBatteryLow() { |
| 647 | return level < LOW_BATTERY_THRESHOLD; |
| 648 | } |
| 649 | |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 650 | } |
| 651 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 652 | public static KeyguardUpdateMonitor getInstance(Context context) { |
| 653 | if (sInstance == null) { |
| 654 | sInstance = new KeyguardUpdateMonitor(context); |
| 655 | } |
| 656 | return sInstance; |
| 657 | } |
| 658 | |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 659 | protected void handleScreenTurnedOn() { |
Jorim Jaggi | 864e64b | 2015-05-20 14:13:23 -0700 | [diff] [blame] | 660 | updateFingerprintListeningState(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 661 | final int count = mCallbacks.size(); |
| 662 | for (int i = 0; i < count; i++) { |
| 663 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 664 | if (cb != null) { |
| 665 | cb.onScreenTurnedOn(); |
| 666 | } |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | protected void handleScreenTurnedOff(int arg1) { |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 671 | clearFingerprintRecognized(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 672 | final int count = mCallbacks.size(); |
| 673 | for (int i = 0; i < count; i++) { |
| 674 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 675 | if (cb != null) { |
| 676 | cb.onScreenTurnedOff(arg1); |
| 677 | } |
| 678 | } |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 679 | updateFingerprintListeningState(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 680 | } |
| 681 | |
Adam Powell | 43a372f | 2013-09-27 17:43:53 -0700 | [diff] [blame] | 682 | /** |
| 683 | * IMPORTANT: Must be called from UI thread. |
| 684 | */ |
| 685 | public void dispatchSetBackground(Bitmap bmp) { |
| 686 | if (DEBUG) Log.d(TAG, "dispatchSetBackground"); |
| 687 | final int count = mCallbacks.size(); |
| 688 | for (int i = 0; i < count; i++) { |
| 689 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 690 | if (cb != null) { |
| 691 | cb.onSetBackground(bmp); |
| 692 | } |
| 693 | } |
| 694 | } |
| 695 | |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 696 | private void handleUserInfoChanged(int userId) { |
| 697 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 698 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 699 | if (cb != null) { |
| 700 | cb.onUserInfoChanged(userId); |
| 701 | } |
| 702 | } |
| 703 | } |
| 704 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 705 | private KeyguardUpdateMonitor(Context context) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 706 | mContext = context; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 707 | mSubscriptionManager = SubscriptionManager.from(context); |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 708 | mDeviceProvisioned = isDeviceProvisionedInSettingsDb(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 709 | // Since device can't be un-provisioned, we only need to register a content observer |
| 710 | // to update mDeviceProvisioned when we are... |
| 711 | if (!mDeviceProvisioned) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 712 | watchForDeviceProvisioning(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 713 | } |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 714 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 715 | // Take a guess at initial SIM state, battery status and PLMN until we get an update |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 716 | mBatteryStatus = new BatteryStatus(BATTERY_STATUS_UNKNOWN, 100, 0, 0); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 717 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 718 | // Watch for interesting updates |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 719 | final IntentFilter filter = new IntentFilter(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 720 | filter.addAction(Intent.ACTION_TIME_TICK); |
| 721 | filter.addAction(Intent.ACTION_TIME_CHANGED); |
| 722 | filter.addAction(Intent.ACTION_BATTERY_CHANGED); |
| 723 | filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); |
| 724 | filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 725 | filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 726 | filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 727 | context.registerReceiver(mBroadcastReceiver, filter); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 728 | |
Adam Cohen | c276e82 | 2012-11-08 13:01:08 -0800 | [diff] [blame] | 729 | final IntentFilter bootCompleteFilter = new IntentFilter(); |
| 730 | bootCompleteFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); |
| 731 | bootCompleteFilter.addAction(Intent.ACTION_BOOT_COMPLETED); |
| 732 | context.registerReceiver(mBroadcastReceiver, bootCompleteFilter); |
| 733 | |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 734 | final IntentFilter allUserFilter = new IntentFilter(); |
| 735 | allUserFilter.addAction(Intent.ACTION_USER_INFO_CHANGED); |
| 736 | allUserFilter.addAction(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED); |
| 737 | allUserFilter.addAction(ACTION_FACE_UNLOCK_STARTED); |
| 738 | allUserFilter.addAction(ACTION_FACE_UNLOCK_STOPPED); |
| 739 | allUserFilter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 740 | context.registerReceiverAsUser(mBroadcastAllReceiver, UserHandle.ALL, allUserFilter, |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 741 | null, null); |
| 742 | |
Wink Saville | 071743f | 2015-01-12 17:11:04 -0800 | [diff] [blame] | 743 | mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionListener); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 744 | try { |
| 745 | ActivityManagerNative.getDefault().registerUserSwitchObserver( |
| 746 | new IUserSwitchObserver.Stub() { |
| 747 | @Override |
| 748 | public void onUserSwitching(int newUserId, IRemoteCallback reply) { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 749 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHING, |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 750 | newUserId, 0, reply)); |
| 751 | } |
| 752 | @Override |
| 753 | public void onUserSwitchComplete(int newUserId) throws RemoteException { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 754 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCH_COMPLETE, |
Adrian Roos | be47b07 | 2014-09-03 00:08:56 +0200 | [diff] [blame] | 755 | newUserId, 0)); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 756 | } |
Kenny Guy | 4297962 | 2015-04-13 18:03:05 +0000 | [diff] [blame] | 757 | @Override |
| 758 | public void onForegroundProfileSwitch(int newProfileId) { |
| 759 | // Ignore. |
| 760 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 761 | }); |
| 762 | } catch (RemoteException e) { |
| 763 | // TODO Auto-generated catch block |
| 764 | e.printStackTrace(); |
| 765 | } |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 766 | |
Jorim Jaggi | 237b061 | 2015-05-01 14:28:49 -0700 | [diff] [blame] | 767 | mTrustManager = (TrustManager) context.getSystemService(Context.TRUST_SERVICE); |
| 768 | mTrustManager.registerTrustListener(this); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 769 | |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 770 | mFpm = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE); |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 771 | updateFingerprintListeningState(); |
| 772 | } |
| 773 | |
| 774 | private void updateFingerprintListeningState() { |
| 775 | boolean shouldListenForFingerprint = shouldListenForFingerprint(); |
| 776 | if (mFingerprintDetectionRunning && !shouldListenForFingerprint) { |
| 777 | stopListeningForFingerprint(); |
| 778 | } else if (!mFingerprintDetectionRunning && shouldListenForFingerprint) { |
| 779 | startListeningForFingerprint(); |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | private boolean shouldListenForFingerprint() { |
Jorim Jaggi | 237b061 | 2015-05-01 14:28:49 -0700 | [diff] [blame] | 784 | return mScreenOn && mKeyguardIsVisible && !mSwitchingUser |
| 785 | && mTrustManager.hasUserAuthenticatedSinceBoot(ActivityManager.getCurrentUser()); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 788 | private void startListeningForFingerprint() { |
| 789 | if (DEBUG) Log.v(TAG, "startListeningForFingerprint()"); |
Jorim Jaggi | 2aad7ee | 2015-04-14 15:25:06 -0700 | [diff] [blame] | 790 | int userId = ActivityManager.getCurrentUser(); |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 791 | if (mFpm != null && mFpm.isHardwareDetected() && !isFingerprintDisabled(userId) |
Jorim Jaggi | 2aad7ee | 2015-04-14 15:25:06 -0700 | [diff] [blame] | 792 | && mFpm.getEnrolledFingerprints(userId).size() > 0) { |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 793 | if (mFingerprintCancelSignal != null) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 794 | mFingerprintCancelSignal.cancel(); |
| 795 | } |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 796 | mFingerprintCancelSignal = new CancellationSignal(); |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 797 | mFpm.authenticate(null, mFingerprintCancelSignal, 0, mAuthenticationCallback, null, userId); |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 798 | setFingerprintRunningDetectionRunning(true); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 799 | } |
| 800 | } |
| 801 | |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 802 | private void stopListeningForFingerprint() { |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 803 | if (DEBUG) Log.v(TAG, "stopListeningForFingerprint()"); |
| 804 | if (isFingerprintDetectionRunning()) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 805 | mFingerprintCancelSignal.cancel(); |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 806 | mFingerprintCancelSignal = null; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 807 | } |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 808 | setFingerprintRunningDetectionRunning(false); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 809 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 810 | |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 811 | private boolean isDeviceProvisionedInSettingsDb() { |
| 812 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 813 | Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
| 814 | } |
| 815 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 816 | private void watchForDeviceProvisioning() { |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 817 | mDeviceProvisionedObserver = new ContentObserver(mHandler) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 818 | @Override |
| 819 | public void onChange(boolean selfChange) { |
| 820 | super.onChange(selfChange); |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 821 | mDeviceProvisioned = isDeviceProvisionedInSettingsDb(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 822 | if (mDeviceProvisioned) { |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 823 | mHandler.sendEmptyMessage(MSG_DEVICE_PROVISIONED); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 824 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 825 | if (DEBUG) Log.d(TAG, "DEVICE_PROVISIONED state = " + mDeviceProvisioned); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 826 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 827 | }; |
| 828 | |
| 829 | mContext.getContentResolver().registerContentObserver( |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 830 | Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 831 | false, mDeviceProvisionedObserver); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 832 | |
| 833 | // prevent a race condition between where we check the flag and where we register the |
| 834 | // observer by grabbing the value once again... |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 835 | boolean provisioned = isDeviceProvisionedInSettingsDb(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 836 | if (provisioned != mDeviceProvisioned) { |
| 837 | mDeviceProvisioned = provisioned; |
| 838 | if (mDeviceProvisioned) { |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 839 | mHandler.sendEmptyMessage(MSG_DEVICE_PROVISIONED); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 840 | } |
| 841 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 842 | } |
| 843 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 844 | /** |
| 845 | * Handle {@link #MSG_DPM_STATE_CHANGED} |
| 846 | */ |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 847 | protected void handleDevicePolicyManagerStateChanged() { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 848 | for (int i = mCallbacks.size() - 1; i >= 0; i--) { |
| 849 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 850 | if (cb != null) { |
| 851 | cb.onDevicePolicyManagerStateChanged(); |
| 852 | } |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 853 | } |
| 854 | } |
| 855 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 856 | /** |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 857 | * Handle {@link #MSG_USER_SWITCHING} |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 858 | */ |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 859 | protected void handleUserSwitching(int userId, IRemoteCallback reply) { |
Jorim Jaggi | aa4d32a | 2015-05-13 16:30:04 -0700 | [diff] [blame] | 860 | mSwitchingUser = true; |
| 861 | updateFingerprintListeningState(); |
| 862 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 863 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 864 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 865 | if (cb != null) { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 866 | cb.onUserSwitching(userId); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 867 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 868 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 869 | try { |
| 870 | reply.sendResult(null); |
| 871 | } catch (RemoteException e) { |
| 872 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 875 | /** |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 876 | * Handle {@link #MSG_USER_SWITCH_COMPLETE} |
| 877 | */ |
| 878 | protected void handleUserSwitchComplete(int userId) { |
Jorim Jaggi | aa4d32a | 2015-05-13 16:30:04 -0700 | [diff] [blame] | 879 | mSwitchingUser = false; |
| 880 | updateFingerprintListeningState(); |
| 881 | |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 882 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 883 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 884 | if (cb != null) { |
| 885 | cb.onUserSwitchComplete(userId); |
| 886 | } |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | /** |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 891 | * This is exposed since {@link Intent#ACTION_BOOT_COMPLETED} is not sticky. If |
| 892 | * keyguard crashes sometime after boot, then it will never receive this |
| 893 | * broadcast and hence not handle the event. This method is ultimately called by |
| 894 | * PhoneWindowManager in this case. |
| 895 | */ |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 896 | public void dispatchBootCompleted() { |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 897 | mHandler.sendEmptyMessage(MSG_BOOT_COMPLETED); |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | /** |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 901 | * Handle {@link #MSG_BOOT_COMPLETED} |
| 902 | */ |
| 903 | protected void handleBootCompleted() { |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 904 | if (mBootCompleted) return; |
Adam Cohen | 4eb36cf | 2012-11-07 11:45:30 -0800 | [diff] [blame] | 905 | mBootCompleted = true; |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 906 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 907 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 908 | if (cb != null) { |
| 909 | cb.onBootCompleted(); |
| 910 | } |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | /** |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 915 | * 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] | 916 | * destroyed. |
| 917 | */ |
| 918 | public boolean hasBootCompleted() { |
| 919 | return mBootCompleted; |
| 920 | } |
| 921 | |
| 922 | /** |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 923 | * Handle {@link #MSG_DEVICE_PROVISIONED} |
| 924 | */ |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 925 | protected void handleDeviceProvisioned() { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 926 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 927 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 928 | if (cb != null) { |
| 929 | cb.onDeviceProvisioned(); |
| 930 | } |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 931 | } |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 932 | if (mDeviceProvisionedObserver != null) { |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 933 | // We don't need the observer anymore... |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 934 | mContext.getContentResolver().unregisterContentObserver(mDeviceProvisionedObserver); |
| 935 | mDeviceProvisionedObserver = null; |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 936 | } |
| 937 | } |
| 938 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 939 | /** |
| 940 | * Handle {@link #MSG_PHONE_STATE_CHANGED} |
| 941 | */ |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 942 | protected void handlePhoneStateChanged(String newState) { |
| 943 | if (DEBUG) Log.d(TAG, "handlePhoneStateChanged(" + newState + ")"); |
Jim Miller | 3f5f83b | 2011-09-26 15:17:05 -0700 | [diff] [blame] | 944 | if (TelephonyManager.EXTRA_STATE_IDLE.equals(newState)) { |
| 945 | mPhoneState = TelephonyManager.CALL_STATE_IDLE; |
| 946 | } else if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(newState)) { |
| 947 | mPhoneState = TelephonyManager.CALL_STATE_OFFHOOK; |
| 948 | } else if (TelephonyManager.EXTRA_STATE_RINGING.equals(newState)) { |
| 949 | mPhoneState = TelephonyManager.CALL_STATE_RINGING; |
| 950 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 951 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 952 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 953 | if (cb != null) { |
| 954 | cb.onPhoneStateChanged(mPhoneState); |
| 955 | } |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 956 | } |
| 957 | } |
| 958 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 959 | /** |
| 960 | * Handle {@link #MSG_RINGER_MODE_CHANGED} |
| 961 | */ |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 962 | protected void handleRingerModeChange(int mode) { |
| 963 | if (DEBUG) Log.d(TAG, "handleRingerModeChange(" + mode + ")"); |
Jim Miller | 3f5f83b | 2011-09-26 15:17:05 -0700 | [diff] [blame] | 964 | mRingMode = mode; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 965 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 966 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 967 | if (cb != null) { |
| 968 | cb.onRingerModeChanged(mode); |
| 969 | } |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 970 | } |
| 971 | } |
| 972 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 973 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 974 | * Handle {@link #MSG_TIME_UPDATE} |
| 975 | */ |
| 976 | private void handleTimeUpdate() { |
| 977 | if (DEBUG) Log.d(TAG, "handleTimeUpdate"); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 978 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 979 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 980 | if (cb != null) { |
| 981 | cb.onTimeChanged(); |
| 982 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | |
| 986 | /** |
| 987 | * Handle {@link #MSG_BATTERY_UPDATE} |
| 988 | */ |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 989 | private void handleBatteryUpdate(BatteryStatus status) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 990 | if (DEBUG) Log.d(TAG, "handleBatteryUpdate"); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 991 | final boolean batteryUpdateInteresting = isBatteryUpdateInteresting(mBatteryStatus, status); |
| 992 | mBatteryStatus = status; |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 993 | if (batteryUpdateInteresting) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 994 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 995 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 996 | if (cb != null) { |
| 997 | cb.onRefreshBatteryInfo(status); |
| 998 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 999 | } |
| 1000 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1004 | * Handle {@link #MSG_SIM_STATE_CHANGE} |
| 1005 | */ |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1006 | private void handleSimStateChange(int subId, int slotId, State state) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1007 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1008 | if (DEBUG_SIM_STATES) { |
| 1009 | Log.d(TAG, "handleSimStateChange(subId=" + subId + ", slotId=" |
| 1010 | + slotId + ", state=" + state +")"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1011 | } |
| 1012 | |
Wink Saville | a54bf65 | 2014-12-11 13:37:50 -0800 | [diff] [blame] | 1013 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1014 | Log.w(TAG, "invalid subId in handleSimStateChange()"); |
| 1015 | return; |
| 1016 | } |
| 1017 | |
| 1018 | SimData data = mSimDatas.get(subId); |
| 1019 | final boolean changed; |
| 1020 | if (data == null) { |
| 1021 | data = new SimData(state, slotId, subId); |
| 1022 | mSimDatas.put(subId, data); |
| 1023 | changed = true; // no data yet; force update |
| 1024 | } else { |
| 1025 | changed = (data.simState != state || data.subId != subId || data.slotId != slotId); |
| 1026 | data.simState = state; |
| 1027 | data.subId = subId; |
| 1028 | data.slotId = slotId; |
| 1029 | } |
| 1030 | if (changed && state != State.UNKNOWN) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1031 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1032 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1033 | if (cb != null) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1034 | cb.onSimStateChanged(subId, slotId, state); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1035 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1036 | } |
| 1037 | } |
| 1038 | } |
| 1039 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1040 | /** |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 1041 | * Handle {@link #MSG_KEYGUARD_VISIBILITY_CHANGED} |
| 1042 | */ |
| 1043 | private void handleKeyguardVisibilityChanged(int showing) { |
| 1044 | if (DEBUG) Log.d(TAG, "handleKeyguardVisibilityChanged(" + showing + ")"); |
Danielle Millett | 5d2404d | 2012-11-01 00:05:27 -0400 | [diff] [blame] | 1045 | boolean isShowing = (showing == 1); |
| 1046 | mKeyguardIsVisible = isShowing; |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 1047 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1048 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1049 | if (cb != null) { |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 1050 | cb.onKeyguardVisibilityChangedRaw(isShowing); |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 1051 | } |
| 1052 | } |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1053 | updateFingerprintListeningState(); |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 1054 | } |
| 1055 | |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 1056 | /** |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 1057 | * Handle {@link #MSG_KEYGUARD_BOUNCER_CHANGED} |
| 1058 | * @see #sendKeyguardBouncerChanged(boolean) |
| 1059 | */ |
| 1060 | private void handleKeyguardBouncerChanged(int bouncer) { |
| 1061 | if (DEBUG) Log.d(TAG, "handleKeyguardBouncerChanged(" + bouncer + ")"); |
| 1062 | boolean isBouncer = (bouncer == 1); |
| 1063 | mBouncer = isBouncer; |
| 1064 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1065 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1066 | if (cb != null) { |
| 1067 | cb.onKeyguardBouncerChanged(isBouncer); |
| 1068 | } |
| 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | /** |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 1073 | * Handle {@link #MSG_REPORT_EMERGENCY_CALL_ACTION} |
| 1074 | */ |
| 1075 | private void handleReportEmergencyCallAction() { |
| 1076 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1077 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1078 | if (cb != null) { |
| 1079 | cb.onEmergencyCallAction(); |
| 1080 | } |
| 1081 | } |
| 1082 | } |
| 1083 | |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1084 | private static boolean isBatteryUpdateInteresting(BatteryStatus old, BatteryStatus current) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1085 | final boolean nowPluggedIn = current.isPluggedIn(); |
| 1086 | final boolean wasPluggedIn = old.isPluggedIn(); |
Jim Miller | 79a444a | 2011-02-15 15:02:11 -0800 | [diff] [blame] | 1087 | final boolean stateChangedWhilePluggedIn = |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1088 | wasPluggedIn == true && nowPluggedIn == true |
| 1089 | && (old.status != current.status); |
| 1090 | |
| 1091 | // change in plug state is always interesting |
| 1092 | if (wasPluggedIn != nowPluggedIn || stateChangedWhilePluggedIn) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1093 | return true; |
| 1094 | } |
| 1095 | |
| 1096 | // change in battery level while plugged in |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1097 | if (nowPluggedIn && old.level != current.level) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1098 | return true; |
| 1099 | } |
| 1100 | |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1101 | // change where battery needs charging |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1102 | if (!nowPluggedIn && current.isBatteryLow() && current.level != old.level) { |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1103 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1104 | } |
| 1105 | return false; |
| 1106 | } |
| 1107 | |
| 1108 | /** |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1109 | * Remove the given observer's callback. |
| 1110 | * |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1111 | * @param callback The callback to remove |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1112 | */ |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1113 | public void removeCallback(KeyguardUpdateMonitorCallback callback) { |
| 1114 | if (DEBUG) Log.v(TAG, "*** unregister callback for " + callback); |
| 1115 | for (int i = mCallbacks.size() - 1; i >= 0; i--) { |
| 1116 | if (mCallbacks.get(i).get() == callback) { |
| 1117 | mCallbacks.remove(i); |
| 1118 | } |
| 1119 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1123 | * Register to receive notifications about general keyguard information |
| 1124 | * (see {@link InfoCallback}. |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1125 | * @param callback The callback to register |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1126 | */ |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1127 | public void registerCallback(KeyguardUpdateMonitorCallback callback) { |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1128 | if (DEBUG) Log.v(TAG, "*** register callback for " + callback); |
| 1129 | // Prevent adding duplicate callbacks |
| 1130 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1131 | if (mCallbacks.get(i).get() == callback) { |
| 1132 | if (DEBUG) Log.e(TAG, "Object tried to add another callback", |
| 1133 | new Exception("Called by")); |
| 1134 | return; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1135 | } |
| 1136 | } |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1137 | mCallbacks.add(new WeakReference<KeyguardUpdateMonitorCallback>(callback)); |
| 1138 | removeCallback(null); // remove unused references |
| 1139 | sendUpdates(callback); |
| 1140 | } |
| 1141 | |
| 1142 | private void sendUpdates(KeyguardUpdateMonitorCallback callback) { |
| 1143 | // Notify listener of the current state |
| 1144 | callback.onRefreshBatteryInfo(mBatteryStatus); |
| 1145 | callback.onTimeChanged(); |
| 1146 | callback.onRingerModeChanged(mRingMode); |
| 1147 | callback.onPhoneStateChanged(mPhoneState); |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 1148 | callback.onRefreshCarrierInfo(); |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1149 | callback.onClockVisibilityChanged(); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1150 | for (Entry<Integer, SimData> data : mSimDatas.entrySet()) { |
| 1151 | final SimData state = data.getValue(); |
| 1152 | callback.onSimStateChanged(state.subId, state.slotId, state.simState); |
| 1153 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1154 | } |
| 1155 | |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 1156 | public void sendKeyguardVisibilityChanged(boolean showing) { |
| 1157 | if (DEBUG) Log.d(TAG, "sendKeyguardVisibilityChanged(" + showing + ")"); |
| 1158 | Message message = mHandler.obtainMessage(MSG_KEYGUARD_VISIBILITY_CHANGED); |
| 1159 | message.arg1 = showing ? 1 : 0; |
| 1160 | message.sendToTarget(); |
| 1161 | } |
| 1162 | |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 1163 | /** |
| 1164 | * @see #handleKeyguardBouncerChanged(int) |
| 1165 | */ |
| 1166 | public void sendKeyguardBouncerChanged(boolean showingBouncer) { |
| 1167 | if (DEBUG) Log.d(TAG, "sendKeyguardBouncerChanged(" + showingBouncer + ")"); |
| 1168 | Message message = mHandler.obtainMessage(MSG_KEYGUARD_BOUNCER_CHANGED); |
| 1169 | message.arg1 = showingBouncer ? 1 : 0; |
| 1170 | message.sendToTarget(); |
| 1171 | } |
| 1172 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1173 | /** |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 1174 | * 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] | 1175 | * have the information earlier than waiting for the intent |
| 1176 | * broadcast from the telephony code. |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 1177 | * |
| 1178 | * NOTE: Because handleSimStateChange() invokes callbacks immediately without going |
| 1179 | * 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] | 1180 | */ |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1181 | public void reportSimUnlocked(int subId) { |
| 1182 | if (DEBUG_SIM_STATES) Log.v(TAG, "reportSimUnlocked(subId=" + subId + ")"); |
| 1183 | int slotId = SubscriptionManager.getSlotId(subId); |
| 1184 | handleSimStateChange(subId, slotId, State.READY); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1185 | } |
| 1186 | |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 1187 | /** |
| 1188 | * Report that the emergency call button has been pressed and the emergency dialer is |
| 1189 | * about to be displayed. |
| 1190 | * |
| 1191 | * @param bypassHandler runs immediately. |
| 1192 | * |
| 1193 | * NOTE: Must be called from UI thread if bypassHandler == true. |
| 1194 | */ |
| 1195 | public void reportEmergencyCallAction(boolean bypassHandler) { |
| 1196 | if (!bypassHandler) { |
| 1197 | mHandler.obtainMessage(MSG_REPORT_EMERGENCY_CALL_ACTION).sendToTarget(); |
| 1198 | } else { |
| 1199 | handleReportEmergencyCallAction(); |
| 1200 | } |
| 1201 | } |
| 1202 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1203 | /** |
| 1204 | * @return Whether the device is provisioned (whether they have gone through |
| 1205 | * the setup wizard) |
| 1206 | */ |
| 1207 | public boolean isDeviceProvisioned() { |
| 1208 | return mDeviceProvisioned; |
| 1209 | } |
| 1210 | |
Jorim Jaggi | 9f74303 | 2015-05-04 15:22:40 -0700 | [diff] [blame] | 1211 | public void clearFailedUnlockAttempts() { |
| 1212 | mFailedAttempts.delete(sCurrentUser); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1213 | } |
| 1214 | |
Jorim Jaggi | 9f74303 | 2015-05-04 15:22:40 -0700 | [diff] [blame] | 1215 | public int getFailedUnlockAttempts() { |
| 1216 | return mFailedAttempts.get(sCurrentUser, 0); |
| 1217 | } |
| 1218 | |
| 1219 | public void reportFailedUnlockAttempt() { |
| 1220 | mFailedAttempts.put(sCurrentUser, getFailedUnlockAttempts() + 1); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1221 | } |
| 1222 | |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 1223 | public void clearFingerprintRecognized() { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1224 | mUserFingerprintAuthenticated.clear(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 1225 | } |
| 1226 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1227 | public boolean isSimPinVoiceSecure() { |
| 1228 | // TODO: only count SIMs that handle voice |
| 1229 | return isSimPinSecure(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | public boolean isSimPinSecure() { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1233 | // True if any SIM is pin secure |
| 1234 | for (SubscriptionInfo info : getSubscriptionInfo(false /* forceReload */)) { |
| 1235 | if (isSimPinSecure(getSimState(info.getSubscriptionId()))) return true; |
| 1236 | } |
| 1237 | return false; |
| 1238 | } |
| 1239 | |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 1240 | public State getSimState(int subId) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1241 | if (mSimDatas.containsKey(subId)) { |
| 1242 | return mSimDatas.get(subId).simState; |
| 1243 | } else { |
| 1244 | return State.UNKNOWN; |
| 1245 | } |
| 1246 | } |
| 1247 | |
Jorim Jaggi | 01ba98b | 2015-01-13 21:33:45 +0100 | [diff] [blame] | 1248 | /** |
| 1249 | * @return true if and only if the state has changed for the specified {@code slotId} |
| 1250 | */ |
| 1251 | private boolean refreshSimState(int subId, int slotId) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1252 | |
| 1253 | // This is awful. It exists because there are two APIs for getting the SIM status |
| 1254 | // that don't return the complete set of values and have different types. In Keyguard we |
| 1255 | // need IccCardConstants, but TelephonyManager would only give us |
| 1256 | // TelephonyManager.SIM_STATE*, so we retrieve it manually. |
xinhe | 18b9c3c | 2014-12-02 15:03:20 -0800 | [diff] [blame] | 1257 | final TelephonyManager tele = TelephonyManager.from(mContext); |
| 1258 | int simState = tele.getSimState(slotId); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1259 | State state; |
| 1260 | try { |
xinhe | 18b9c3c | 2014-12-02 15:03:20 -0800 | [diff] [blame] | 1261 | state = State.intToState(simState); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1262 | } catch(IllegalArgumentException ex) { |
xinhe | 18b9c3c | 2014-12-02 15:03:20 -0800 | [diff] [blame] | 1263 | Log.w(TAG, "Unknown sim state: " + simState); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1264 | state = State.UNKNOWN; |
John Spurlock | 5b13e92 | 2015-01-07 11:04:58 -0500 | [diff] [blame] | 1265 | } |
Jorim Jaggi | 01ba98b | 2015-01-13 21:33:45 +0100 | [diff] [blame] | 1266 | SimData data = mSimDatas.get(subId); |
| 1267 | final boolean changed; |
| 1268 | if (data == null) { |
| 1269 | data = new SimData(state, slotId, subId); |
| 1270 | mSimDatas.put(subId, data); |
| 1271 | changed = true; // no data yet; force update |
| 1272 | } else { |
| 1273 | changed = data.simState != state; |
| 1274 | data.simState = state; |
| 1275 | } |
| 1276 | return changed; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | public static boolean isSimPinSecure(IccCardConstants.State state) { |
| 1280 | final IccCardConstants.State simState = state; |
| 1281 | return (simState == IccCardConstants.State.PIN_REQUIRED |
| 1282 | || simState == IccCardConstants.State.PUK_REQUIRED |
| 1283 | || simState == IccCardConstants.State.PERM_DISABLED); |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 1284 | } |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1285 | |
| 1286 | public DisplayClientState getCachedDisplayClientState() { |
| 1287 | return mDisplayClientState; |
| 1288 | } |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1289 | |
| 1290 | // TODO: use these callbacks elsewhere in place of the existing notifyScreen*() |
| 1291 | // (KeyguardViewMediator, KeyguardHostView) |
| 1292 | public void dispatchScreenTurnedOn() { |
| 1293 | synchronized (this) { |
| 1294 | mScreenOn = true; |
| 1295 | } |
| 1296 | mHandler.sendEmptyMessage(MSG_SCREEN_TURNED_ON); |
| 1297 | } |
| 1298 | |
John Spurlock | 36a1342 | 2015-03-24 21:15:48 -0400 | [diff] [blame] | 1299 | public void dispatchScreenTurnedOff(int why) { |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1300 | synchronized(this) { |
| 1301 | mScreenOn = false; |
| 1302 | } |
| 1303 | mHandler.sendMessage(mHandler.obtainMessage(MSG_SCREEN_TURNED_OFF, why, 0)); |
| 1304 | } |
| 1305 | |
| 1306 | public boolean isScreenOn() { |
| 1307 | return mScreenOn; |
| 1308 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1309 | |
| 1310 | /** |
| 1311 | * Find the next SubscriptionId for a SIM in the given state, favoring lower slot numbers first. |
| 1312 | * @param state |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1313 | * @return subid or {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} if none found |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1314 | */ |
| 1315 | public int getNextSubIdForState(State state) { |
| 1316 | List<SubscriptionInfo> list = getSubscriptionInfo(false /* forceReload */); |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1317 | int resultId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1318 | int bestSlotId = Integer.MAX_VALUE; // Favor lowest slot first |
| 1319 | for (int i = 0; i < list.size(); i++) { |
| 1320 | final SubscriptionInfo info = list.get(i); |
| 1321 | final int id = info.getSubscriptionId(); |
| 1322 | int slotId = SubscriptionManager.getSlotId(id); |
| 1323 | if (state == getSimState(id) && bestSlotId > slotId ) { |
| 1324 | resultId = id; |
| 1325 | bestSlotId = slotId; |
| 1326 | } |
| 1327 | } |
| 1328 | return resultId; |
| 1329 | } |
| 1330 | |
| 1331 | public SubscriptionInfo getSubscriptionInfoForSubId(int subId) { |
| 1332 | List<SubscriptionInfo> list = getSubscriptionInfo(false /* forceReload */); |
| 1333 | for (int i = 0; i < list.size(); i++) { |
| 1334 | SubscriptionInfo info = list.get(i); |
| 1335 | if (subId == info.getSubscriptionId()) return info; |
| 1336 | } |
| 1337 | return null; // not found |
| 1338 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1339 | } |