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: |
| 208 | handleFingerprintAuthenticated(msg.arg1, msg.arg2); |
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 | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 351 | private void handleFingerprintAuthenticated(int fingerId, int groupId) { |
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) { |
| 527 | mHandler.obtainMessage(MSG_FINGERPRINT_AUTHENTICATED, |
| 528 | result.getFingerprint().getFingerId(), |
| 529 | result.getFingerprint().getGroupId()).sendToTarget(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | @Override |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 533 | public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) { |
| 534 | mHandler.obtainMessage(MSG_FINGERPRINT_HELP, helpMsgId, 0, helpString).sendToTarget(); |
| 535 | } |
| 536 | |
| 537 | @Override |
| 538 | public void onAuthenticationError(int errMsgId, CharSequence errString) { |
Jorim Jaggi | 570de1e | 2015-05-01 15:08:34 -0700 | [diff] [blame] | 539 | mHandler.obtainMessage(MSG_FINGERPRINT_ERROR, errMsgId, 0, errString).sendToTarget(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 540 | } |
| 541 | }; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 542 | private CancellationSignal mFingerprintCancelSignal; |
| 543 | private FingerprintManager mFpm; |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 544 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 545 | /** |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 546 | * When we receive a |
| 547 | * {@link com.android.internal.telephony.TelephonyIntents#ACTION_SIM_STATE_CHANGED} broadcast, |
Wink Saville | 37c124c | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 548 | * 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] | 549 | * 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] | 550 | * the intent and provide a {@link SimCard.State} result. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 551 | */ |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 552 | private static class SimData { |
| 553 | public State simState; |
| 554 | public int slotId; |
| 555 | public int subId; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 556 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 557 | SimData(State state, int slot, int id) { |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 558 | simState = state; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 559 | slotId = slot; |
| 560 | subId = id; |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 561 | } |
| 562 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 563 | static SimData fromIntent(Intent intent) { |
| 564 | State state; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 565 | if (!TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(intent.getAction())) { |
| 566 | throw new IllegalArgumentException("only handles intent ACTION_SIM_STATE_CHANGED"); |
| 567 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 568 | String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 569 | int slotId = intent.getIntExtra(PhoneConstants.SLOT_KEY, 0); |
| 570 | int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 571 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 572 | if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) { |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 573 | final String absentReason = intent |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 574 | .getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON); |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 575 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 576 | if (IccCardConstants.INTENT_VALUE_ABSENT_ON_PERM_DISABLED.equals( |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 577 | absentReason)) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 578 | state = IccCardConstants.State.PERM_DISABLED; |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 579 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 580 | state = IccCardConstants.State.ABSENT; |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 581 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 582 | } else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) { |
| 583 | state = IccCardConstants.State.READY; |
| 584 | } else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 585 | final String lockedReason = intent |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 586 | .getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON); |
| 587 | if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) { |
| 588 | state = IccCardConstants.State.PIN_REQUIRED; |
| 589 | } else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) { |
| 590 | state = IccCardConstants.State.PUK_REQUIRED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 591 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 592 | state = IccCardConstants.State.UNKNOWN; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 593 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 594 | } else if (IccCardConstants.INTENT_VALUE_LOCKED_NETWORK.equals(stateExtra)) { |
| 595 | state = IccCardConstants.State.NETWORK_LOCKED; |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 596 | } else if (IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(stateExtra) |
| 597 | || IccCardConstants.INTENT_VALUE_ICC_IMSI.equals(stateExtra)) { |
| 598 | // This is required because telephony doesn't return to "READY" after |
| 599 | // these state transitions. See bug 7197471. |
| 600 | state = IccCardConstants.State.READY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 601 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 602 | state = IccCardConstants.State.UNKNOWN; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 603 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 604 | return new SimData(state, slotId, subId); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | public String toString() { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 608 | return "SimData{state=" + simState + ",slotId=" + slotId + ",subId=" + subId + "}"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 612 | public static class BatteryStatus { |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 613 | public final int status; |
| 614 | public final int level; |
| 615 | public final int plugged; |
| 616 | public final int health; |
| 617 | public BatteryStatus(int status, int level, int plugged, int health) { |
| 618 | this.status = status; |
| 619 | this.level = level; |
| 620 | this.plugged = plugged; |
| 621 | this.health = health; |
| 622 | } |
| 623 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 624 | /** |
Brian Muramatsu | a92a01b | 2012-09-05 21:54:39 -0700 | [diff] [blame] | 625 | * Determine whether the device is plugged in (USB, power, or wireless). |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 626 | * @return true if the device is plugged in. |
| 627 | */ |
Adrian Roos | ad3bc7f | 2014-10-30 18:29:38 +0100 | [diff] [blame] | 628 | public boolean isPluggedIn() { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 629 | return plugged == BatteryManager.BATTERY_PLUGGED_AC |
Brian Muramatsu | a92a01b | 2012-09-05 21:54:39 -0700 | [diff] [blame] | 630 | || plugged == BatteryManager.BATTERY_PLUGGED_USB |
| 631 | || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | /** |
| 635 | * Whether or not the device is charged. Note that some devices never return 100% for |
| 636 | * battery level, so this allows either battery level or status to determine if the |
| 637 | * battery is charged. |
| 638 | * @return true if the device is charged |
| 639 | */ |
| 640 | public boolean isCharged() { |
| 641 | return status == BATTERY_STATUS_FULL || level >= 100; |
| 642 | } |
| 643 | |
| 644 | /** |
| 645 | * Whether battery is low and needs to be charged. |
| 646 | * @return true if battery is low |
| 647 | */ |
| 648 | public boolean isBatteryLow() { |
| 649 | return level < LOW_BATTERY_THRESHOLD; |
| 650 | } |
| 651 | |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 652 | } |
| 653 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 654 | public static KeyguardUpdateMonitor getInstance(Context context) { |
| 655 | if (sInstance == null) { |
| 656 | sInstance = new KeyguardUpdateMonitor(context); |
| 657 | } |
| 658 | return sInstance; |
| 659 | } |
| 660 | |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 661 | protected void handleScreenTurnedOn() { |
| 662 | final int count = mCallbacks.size(); |
| 663 | for (int i = 0; i < count; i++) { |
| 664 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 665 | if (cb != null) { |
| 666 | cb.onScreenTurnedOn(); |
| 667 | } |
| 668 | } |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 669 | updateFingerprintListeningState(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | protected void handleScreenTurnedOff(int arg1) { |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 673 | clearFingerprintRecognized(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 674 | final int count = mCallbacks.size(); |
| 675 | for (int i = 0; i < count; i++) { |
| 676 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 677 | if (cb != null) { |
| 678 | cb.onScreenTurnedOff(arg1); |
| 679 | } |
| 680 | } |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 681 | updateFingerprintListeningState(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Adam Powell | 43a372f | 2013-09-27 17:43:53 -0700 | [diff] [blame] | 684 | /** |
| 685 | * IMPORTANT: Must be called from UI thread. |
| 686 | */ |
| 687 | public void dispatchSetBackground(Bitmap bmp) { |
| 688 | if (DEBUG) Log.d(TAG, "dispatchSetBackground"); |
| 689 | final int count = mCallbacks.size(); |
| 690 | for (int i = 0; i < count; i++) { |
| 691 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 692 | if (cb != null) { |
| 693 | cb.onSetBackground(bmp); |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 698 | private void handleUserInfoChanged(int userId) { |
| 699 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 700 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 701 | if (cb != null) { |
| 702 | cb.onUserInfoChanged(userId); |
| 703 | } |
| 704 | } |
| 705 | } |
| 706 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 707 | private KeyguardUpdateMonitor(Context context) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 708 | mContext = context; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 709 | mSubscriptionManager = SubscriptionManager.from(context); |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 710 | mDeviceProvisioned = isDeviceProvisionedInSettingsDb(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 711 | // Since device can't be un-provisioned, we only need to register a content observer |
| 712 | // to update mDeviceProvisioned when we are... |
| 713 | if (!mDeviceProvisioned) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 714 | watchForDeviceProvisioning(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 715 | } |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 716 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 717 | // 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] | 718 | mBatteryStatus = new BatteryStatus(BATTERY_STATUS_UNKNOWN, 100, 0, 0); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 719 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 720 | // Watch for interesting updates |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 721 | final IntentFilter filter = new IntentFilter(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 722 | filter.addAction(Intent.ACTION_TIME_TICK); |
| 723 | filter.addAction(Intent.ACTION_TIME_CHANGED); |
| 724 | filter.addAction(Intent.ACTION_BATTERY_CHANGED); |
| 725 | filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); |
| 726 | filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 727 | filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 728 | filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 729 | context.registerReceiver(mBroadcastReceiver, filter); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 730 | |
Adam Cohen | c276e82 | 2012-11-08 13:01:08 -0800 | [diff] [blame] | 731 | final IntentFilter bootCompleteFilter = new IntentFilter(); |
| 732 | bootCompleteFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); |
| 733 | bootCompleteFilter.addAction(Intent.ACTION_BOOT_COMPLETED); |
| 734 | context.registerReceiver(mBroadcastReceiver, bootCompleteFilter); |
| 735 | |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 736 | final IntentFilter allUserFilter = new IntentFilter(); |
| 737 | allUserFilter.addAction(Intent.ACTION_USER_INFO_CHANGED); |
| 738 | allUserFilter.addAction(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED); |
| 739 | allUserFilter.addAction(ACTION_FACE_UNLOCK_STARTED); |
| 740 | allUserFilter.addAction(ACTION_FACE_UNLOCK_STOPPED); |
| 741 | allUserFilter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 742 | context.registerReceiverAsUser(mBroadcastAllReceiver, UserHandle.ALL, allUserFilter, |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 743 | null, null); |
| 744 | |
Wink Saville | 071743f | 2015-01-12 17:11:04 -0800 | [diff] [blame] | 745 | mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionListener); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 746 | try { |
| 747 | ActivityManagerNative.getDefault().registerUserSwitchObserver( |
| 748 | new IUserSwitchObserver.Stub() { |
| 749 | @Override |
| 750 | public void onUserSwitching(int newUserId, IRemoteCallback reply) { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 751 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHING, |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 752 | newUserId, 0, reply)); |
| 753 | } |
| 754 | @Override |
| 755 | public void onUserSwitchComplete(int newUserId) throws RemoteException { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 756 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCH_COMPLETE, |
Adrian Roos | be47b07 | 2014-09-03 00:08:56 +0200 | [diff] [blame] | 757 | newUserId, 0)); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 758 | } |
Kenny Guy | 4297962 | 2015-04-13 18:03:05 +0000 | [diff] [blame] | 759 | @Override |
| 760 | public void onForegroundProfileSwitch(int newProfileId) { |
| 761 | // Ignore. |
| 762 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 763 | }); |
| 764 | } catch (RemoteException e) { |
| 765 | // TODO Auto-generated catch block |
| 766 | e.printStackTrace(); |
| 767 | } |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 768 | |
Jorim Jaggi | 237b061 | 2015-05-01 14:28:49 -0700 | [diff] [blame] | 769 | mTrustManager = (TrustManager) context.getSystemService(Context.TRUST_SERVICE); |
| 770 | mTrustManager.registerTrustListener(this); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 771 | |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 772 | mFpm = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE); |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 773 | updateFingerprintListeningState(); |
| 774 | } |
| 775 | |
| 776 | private void updateFingerprintListeningState() { |
| 777 | boolean shouldListenForFingerprint = shouldListenForFingerprint(); |
| 778 | if (mFingerprintDetectionRunning && !shouldListenForFingerprint) { |
| 779 | stopListeningForFingerprint(); |
| 780 | } else if (!mFingerprintDetectionRunning && shouldListenForFingerprint) { |
| 781 | startListeningForFingerprint(); |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | private boolean shouldListenForFingerprint() { |
Jorim Jaggi | 237b061 | 2015-05-01 14:28:49 -0700 | [diff] [blame] | 786 | return mScreenOn && mKeyguardIsVisible && !mSwitchingUser |
| 787 | && mTrustManager.hasUserAuthenticatedSinceBoot(ActivityManager.getCurrentUser()); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 788 | } |
| 789 | |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 790 | private void startListeningForFingerprint() { |
| 791 | if (DEBUG) Log.v(TAG, "startListeningForFingerprint()"); |
Jorim Jaggi | 2aad7ee | 2015-04-14 15:25:06 -0700 | [diff] [blame] | 792 | int userId = ActivityManager.getCurrentUser(); |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 793 | if (mFpm != null && mFpm.isHardwareDetected() && !isFingerprintDisabled(userId) |
Jorim Jaggi | 2aad7ee | 2015-04-14 15:25:06 -0700 | [diff] [blame] | 794 | && mFpm.getEnrolledFingerprints(userId).size() > 0) { |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 795 | if (mFingerprintCancelSignal != null) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 796 | mFingerprintCancelSignal.cancel(); |
| 797 | } |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 798 | mFingerprintCancelSignal = new CancellationSignal(); |
Jorim Jaggi | 2aad7ee | 2015-04-14 15:25:06 -0700 | [diff] [blame] | 799 | mFpm.authenticate(null, mFingerprintCancelSignal, mAuthenticationCallback, 0, userId); |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 800 | setFingerprintRunningDetectionRunning(true); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 804 | private void stopListeningForFingerprint() { |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 805 | if (DEBUG) Log.v(TAG, "stopListeningForFingerprint()"); |
| 806 | if (isFingerprintDetectionRunning()) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 807 | mFingerprintCancelSignal.cancel(); |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 808 | mFingerprintCancelSignal = null; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 809 | } |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 810 | setFingerprintRunningDetectionRunning(false); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 811 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 812 | |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 813 | private boolean isDeviceProvisionedInSettingsDb() { |
| 814 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 815 | Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
| 816 | } |
| 817 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 818 | private void watchForDeviceProvisioning() { |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 819 | mDeviceProvisionedObserver = new ContentObserver(mHandler) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 820 | @Override |
| 821 | public void onChange(boolean selfChange) { |
| 822 | super.onChange(selfChange); |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 823 | mDeviceProvisioned = isDeviceProvisionedInSettingsDb(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 824 | if (mDeviceProvisioned) { |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 825 | mHandler.sendEmptyMessage(MSG_DEVICE_PROVISIONED); |
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 | if (DEBUG) Log.d(TAG, "DEVICE_PROVISIONED state = " + mDeviceProvisioned); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 828 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 829 | }; |
| 830 | |
| 831 | mContext.getContentResolver().registerContentObserver( |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 832 | Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 833 | false, mDeviceProvisionedObserver); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 834 | |
| 835 | // prevent a race condition between where we check the flag and where we register the |
| 836 | // observer by grabbing the value once again... |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 837 | boolean provisioned = isDeviceProvisionedInSettingsDb(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 838 | if (provisioned != mDeviceProvisioned) { |
| 839 | mDeviceProvisioned = provisioned; |
| 840 | if (mDeviceProvisioned) { |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 841 | mHandler.sendEmptyMessage(MSG_DEVICE_PROVISIONED); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 842 | } |
| 843 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 844 | } |
| 845 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 846 | /** |
| 847 | * Handle {@link #MSG_DPM_STATE_CHANGED} |
| 848 | */ |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 849 | protected void handleDevicePolicyManagerStateChanged() { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 850 | for (int i = mCallbacks.size() - 1; i >= 0; i--) { |
| 851 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 852 | if (cb != null) { |
| 853 | cb.onDevicePolicyManagerStateChanged(); |
| 854 | } |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 855 | } |
| 856 | } |
| 857 | |
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 | * Handle {@link #MSG_USER_SWITCHING} |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 860 | */ |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 861 | protected void handleUserSwitching(int userId, IRemoteCallback reply) { |
Jorim Jaggi | aa4d32a | 2015-05-13 16:30:04 -0700 | [diff] [blame] | 862 | mSwitchingUser = true; |
| 863 | updateFingerprintListeningState(); |
| 864 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 865 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 866 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 867 | if (cb != null) { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 868 | cb.onUserSwitching(userId); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 869 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 870 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 871 | try { |
| 872 | reply.sendResult(null); |
| 873 | } catch (RemoteException e) { |
| 874 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 875 | } |
| 876 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 877 | /** |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 878 | * Handle {@link #MSG_USER_SWITCH_COMPLETE} |
| 879 | */ |
| 880 | protected void handleUserSwitchComplete(int userId) { |
Jorim Jaggi | aa4d32a | 2015-05-13 16:30:04 -0700 | [diff] [blame] | 881 | mSwitchingUser = false; |
| 882 | updateFingerprintListeningState(); |
| 883 | |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 884 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 885 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 886 | if (cb != null) { |
| 887 | cb.onUserSwitchComplete(userId); |
| 888 | } |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | /** |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 893 | * This is exposed since {@link Intent#ACTION_BOOT_COMPLETED} is not sticky. If |
| 894 | * keyguard crashes sometime after boot, then it will never receive this |
| 895 | * broadcast and hence not handle the event. This method is ultimately called by |
| 896 | * PhoneWindowManager in this case. |
| 897 | */ |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 898 | public void dispatchBootCompleted() { |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 899 | mHandler.sendEmptyMessage(MSG_BOOT_COMPLETED); |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | /** |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 903 | * Handle {@link #MSG_BOOT_COMPLETED} |
| 904 | */ |
| 905 | protected void handleBootCompleted() { |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 906 | if (mBootCompleted) return; |
Adam Cohen | 4eb36cf | 2012-11-07 11:45:30 -0800 | [diff] [blame] | 907 | mBootCompleted = true; |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 908 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 909 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 910 | if (cb != null) { |
| 911 | cb.onBootCompleted(); |
| 912 | } |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | /** |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 917 | * 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] | 918 | * destroyed. |
| 919 | */ |
| 920 | public boolean hasBootCompleted() { |
| 921 | return mBootCompleted; |
| 922 | } |
| 923 | |
| 924 | /** |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 925 | * Handle {@link #MSG_DEVICE_PROVISIONED} |
| 926 | */ |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 927 | protected void handleDeviceProvisioned() { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 928 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 929 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 930 | if (cb != null) { |
| 931 | cb.onDeviceProvisioned(); |
| 932 | } |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 933 | } |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 934 | if (mDeviceProvisionedObserver != null) { |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 935 | // We don't need the observer anymore... |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 936 | mContext.getContentResolver().unregisterContentObserver(mDeviceProvisionedObserver); |
| 937 | mDeviceProvisionedObserver = null; |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 938 | } |
| 939 | } |
| 940 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 941 | /** |
| 942 | * Handle {@link #MSG_PHONE_STATE_CHANGED} |
| 943 | */ |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 944 | protected void handlePhoneStateChanged(String newState) { |
| 945 | if (DEBUG) Log.d(TAG, "handlePhoneStateChanged(" + newState + ")"); |
Jim Miller | 3f5f83b | 2011-09-26 15:17:05 -0700 | [diff] [blame] | 946 | if (TelephonyManager.EXTRA_STATE_IDLE.equals(newState)) { |
| 947 | mPhoneState = TelephonyManager.CALL_STATE_IDLE; |
| 948 | } else if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(newState)) { |
| 949 | mPhoneState = TelephonyManager.CALL_STATE_OFFHOOK; |
| 950 | } else if (TelephonyManager.EXTRA_STATE_RINGING.equals(newState)) { |
| 951 | mPhoneState = TelephonyManager.CALL_STATE_RINGING; |
| 952 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 953 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 954 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 955 | if (cb != null) { |
| 956 | cb.onPhoneStateChanged(mPhoneState); |
| 957 | } |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 961 | /** |
| 962 | * Handle {@link #MSG_RINGER_MODE_CHANGED} |
| 963 | */ |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 964 | protected void handleRingerModeChange(int mode) { |
| 965 | if (DEBUG) Log.d(TAG, "handleRingerModeChange(" + mode + ")"); |
Jim Miller | 3f5f83b | 2011-09-26 15:17:05 -0700 | [diff] [blame] | 966 | mRingMode = mode; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 967 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 968 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 969 | if (cb != null) { |
| 970 | cb.onRingerModeChanged(mode); |
| 971 | } |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 972 | } |
| 973 | } |
| 974 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 975 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 976 | * Handle {@link #MSG_TIME_UPDATE} |
| 977 | */ |
| 978 | private void handleTimeUpdate() { |
| 979 | if (DEBUG) Log.d(TAG, "handleTimeUpdate"); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 980 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 981 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 982 | if (cb != null) { |
| 983 | cb.onTimeChanged(); |
| 984 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 985 | } |
| 986 | } |
| 987 | |
| 988 | /** |
| 989 | * Handle {@link #MSG_BATTERY_UPDATE} |
| 990 | */ |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 991 | private void handleBatteryUpdate(BatteryStatus status) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 992 | if (DEBUG) Log.d(TAG, "handleBatteryUpdate"); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 993 | final boolean batteryUpdateInteresting = isBatteryUpdateInteresting(mBatteryStatus, status); |
| 994 | mBatteryStatus = status; |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 995 | if (batteryUpdateInteresting) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 996 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 997 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 998 | if (cb != null) { |
| 999 | cb.onRefreshBatteryInfo(status); |
| 1000 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1001 | } |
| 1002 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1006 | * Handle {@link #MSG_SIM_STATE_CHANGE} |
| 1007 | */ |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1008 | private void handleSimStateChange(int subId, int slotId, State state) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1009 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1010 | if (DEBUG_SIM_STATES) { |
| 1011 | Log.d(TAG, "handleSimStateChange(subId=" + subId + ", slotId=" |
| 1012 | + slotId + ", state=" + state +")"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1013 | } |
| 1014 | |
Wink Saville | a54bf65 | 2014-12-11 13:37:50 -0800 | [diff] [blame] | 1015 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1016 | Log.w(TAG, "invalid subId in handleSimStateChange()"); |
| 1017 | return; |
| 1018 | } |
| 1019 | |
| 1020 | SimData data = mSimDatas.get(subId); |
| 1021 | final boolean changed; |
| 1022 | if (data == null) { |
| 1023 | data = new SimData(state, slotId, subId); |
| 1024 | mSimDatas.put(subId, data); |
| 1025 | changed = true; // no data yet; force update |
| 1026 | } else { |
| 1027 | changed = (data.simState != state || data.subId != subId || data.slotId != slotId); |
| 1028 | data.simState = state; |
| 1029 | data.subId = subId; |
| 1030 | data.slotId = slotId; |
| 1031 | } |
| 1032 | if (changed && state != State.UNKNOWN) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1033 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1034 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1035 | if (cb != null) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1036 | cb.onSimStateChanged(subId, slotId, state); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1037 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1038 | } |
| 1039 | } |
| 1040 | } |
| 1041 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1042 | /** |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 1043 | * Handle {@link #MSG_KEYGUARD_VISIBILITY_CHANGED} |
| 1044 | */ |
| 1045 | private void handleKeyguardVisibilityChanged(int showing) { |
| 1046 | if (DEBUG) Log.d(TAG, "handleKeyguardVisibilityChanged(" + showing + ")"); |
Danielle Millett | 5d2404d | 2012-11-01 00:05:27 -0400 | [diff] [blame] | 1047 | boolean isShowing = (showing == 1); |
| 1048 | mKeyguardIsVisible = isShowing; |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 1049 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1050 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1051 | if (cb != null) { |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 1052 | cb.onKeyguardVisibilityChangedRaw(isShowing); |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 1053 | } |
| 1054 | } |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1055 | updateFingerprintListeningState(); |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 1056 | } |
| 1057 | |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 1058 | /** |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 1059 | * Handle {@link #MSG_KEYGUARD_BOUNCER_CHANGED} |
| 1060 | * @see #sendKeyguardBouncerChanged(boolean) |
| 1061 | */ |
| 1062 | private void handleKeyguardBouncerChanged(int bouncer) { |
| 1063 | if (DEBUG) Log.d(TAG, "handleKeyguardBouncerChanged(" + bouncer + ")"); |
| 1064 | boolean isBouncer = (bouncer == 1); |
| 1065 | mBouncer = isBouncer; |
| 1066 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1067 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1068 | if (cb != null) { |
| 1069 | cb.onKeyguardBouncerChanged(isBouncer); |
| 1070 | } |
| 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | /** |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 1075 | * Handle {@link #MSG_REPORT_EMERGENCY_CALL_ACTION} |
| 1076 | */ |
| 1077 | private void handleReportEmergencyCallAction() { |
| 1078 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1079 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1080 | if (cb != null) { |
| 1081 | cb.onEmergencyCallAction(); |
| 1082 | } |
| 1083 | } |
| 1084 | } |
| 1085 | |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1086 | private static boolean isBatteryUpdateInteresting(BatteryStatus old, BatteryStatus current) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1087 | final boolean nowPluggedIn = current.isPluggedIn(); |
| 1088 | final boolean wasPluggedIn = old.isPluggedIn(); |
Jim Miller | 79a444a | 2011-02-15 15:02:11 -0800 | [diff] [blame] | 1089 | final boolean stateChangedWhilePluggedIn = |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1090 | wasPluggedIn == true && nowPluggedIn == true |
| 1091 | && (old.status != current.status); |
| 1092 | |
| 1093 | // change in plug state is always interesting |
| 1094 | if (wasPluggedIn != nowPluggedIn || stateChangedWhilePluggedIn) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1095 | return true; |
| 1096 | } |
| 1097 | |
| 1098 | // change in battery level while plugged in |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1099 | if (nowPluggedIn && old.level != current.level) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1100 | return true; |
| 1101 | } |
| 1102 | |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1103 | // change where battery needs charging |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1104 | if (!nowPluggedIn && current.isBatteryLow() && current.level != old.level) { |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1105 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1106 | } |
| 1107 | return false; |
| 1108 | } |
| 1109 | |
| 1110 | /** |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1111 | * Remove the given observer's callback. |
| 1112 | * |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1113 | * @param callback The callback to remove |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1114 | */ |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1115 | public void removeCallback(KeyguardUpdateMonitorCallback callback) { |
| 1116 | if (DEBUG) Log.v(TAG, "*** unregister callback for " + callback); |
| 1117 | for (int i = mCallbacks.size() - 1; i >= 0; i--) { |
| 1118 | if (mCallbacks.get(i).get() == callback) { |
| 1119 | mCallbacks.remove(i); |
| 1120 | } |
| 1121 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1125 | * Register to receive notifications about general keyguard information |
| 1126 | * (see {@link InfoCallback}. |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1127 | * @param callback The callback to register |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1128 | */ |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1129 | public void registerCallback(KeyguardUpdateMonitorCallback callback) { |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1130 | if (DEBUG) Log.v(TAG, "*** register callback for " + callback); |
| 1131 | // Prevent adding duplicate callbacks |
| 1132 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1133 | if (mCallbacks.get(i).get() == callback) { |
| 1134 | if (DEBUG) Log.e(TAG, "Object tried to add another callback", |
| 1135 | new Exception("Called by")); |
| 1136 | return; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1137 | } |
| 1138 | } |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1139 | mCallbacks.add(new WeakReference<KeyguardUpdateMonitorCallback>(callback)); |
| 1140 | removeCallback(null); // remove unused references |
| 1141 | sendUpdates(callback); |
| 1142 | } |
| 1143 | |
| 1144 | private void sendUpdates(KeyguardUpdateMonitorCallback callback) { |
| 1145 | // Notify listener of the current state |
| 1146 | callback.onRefreshBatteryInfo(mBatteryStatus); |
| 1147 | callback.onTimeChanged(); |
| 1148 | callback.onRingerModeChanged(mRingMode); |
| 1149 | callback.onPhoneStateChanged(mPhoneState); |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 1150 | callback.onRefreshCarrierInfo(); |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1151 | callback.onClockVisibilityChanged(); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1152 | for (Entry<Integer, SimData> data : mSimDatas.entrySet()) { |
| 1153 | final SimData state = data.getValue(); |
| 1154 | callback.onSimStateChanged(state.subId, state.slotId, state.simState); |
| 1155 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1156 | } |
| 1157 | |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 1158 | public void sendKeyguardVisibilityChanged(boolean showing) { |
| 1159 | if (DEBUG) Log.d(TAG, "sendKeyguardVisibilityChanged(" + showing + ")"); |
| 1160 | Message message = mHandler.obtainMessage(MSG_KEYGUARD_VISIBILITY_CHANGED); |
| 1161 | message.arg1 = showing ? 1 : 0; |
| 1162 | message.sendToTarget(); |
| 1163 | } |
| 1164 | |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 1165 | /** |
| 1166 | * @see #handleKeyguardBouncerChanged(int) |
| 1167 | */ |
| 1168 | public void sendKeyguardBouncerChanged(boolean showingBouncer) { |
| 1169 | if (DEBUG) Log.d(TAG, "sendKeyguardBouncerChanged(" + showingBouncer + ")"); |
| 1170 | Message message = mHandler.obtainMessage(MSG_KEYGUARD_BOUNCER_CHANGED); |
| 1171 | message.arg1 = showingBouncer ? 1 : 0; |
| 1172 | message.sendToTarget(); |
| 1173 | } |
| 1174 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1175 | /** |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 1176 | * 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] | 1177 | * have the information earlier than waiting for the intent |
| 1178 | * broadcast from the telephony code. |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 1179 | * |
| 1180 | * NOTE: Because handleSimStateChange() invokes callbacks immediately without going |
| 1181 | * 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] | 1182 | */ |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1183 | public void reportSimUnlocked(int subId) { |
| 1184 | if (DEBUG_SIM_STATES) Log.v(TAG, "reportSimUnlocked(subId=" + subId + ")"); |
| 1185 | int slotId = SubscriptionManager.getSlotId(subId); |
| 1186 | handleSimStateChange(subId, slotId, State.READY); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1187 | } |
| 1188 | |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 1189 | /** |
| 1190 | * Report that the emergency call button has been pressed and the emergency dialer is |
| 1191 | * about to be displayed. |
| 1192 | * |
| 1193 | * @param bypassHandler runs immediately. |
| 1194 | * |
| 1195 | * NOTE: Must be called from UI thread if bypassHandler == true. |
| 1196 | */ |
| 1197 | public void reportEmergencyCallAction(boolean bypassHandler) { |
| 1198 | if (!bypassHandler) { |
| 1199 | mHandler.obtainMessage(MSG_REPORT_EMERGENCY_CALL_ACTION).sendToTarget(); |
| 1200 | } else { |
| 1201 | handleReportEmergencyCallAction(); |
| 1202 | } |
| 1203 | } |
| 1204 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1205 | /** |
| 1206 | * @return Whether the device is provisioned (whether they have gone through |
| 1207 | * the setup wizard) |
| 1208 | */ |
| 1209 | public boolean isDeviceProvisioned() { |
| 1210 | return mDeviceProvisioned; |
| 1211 | } |
| 1212 | |
Jorim Jaggi | 9f74303 | 2015-05-04 15:22:40 -0700 | [diff] [blame] | 1213 | public void clearFailedUnlockAttempts() { |
| 1214 | mFailedAttempts.delete(sCurrentUser); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1215 | } |
| 1216 | |
Jorim Jaggi | 9f74303 | 2015-05-04 15:22:40 -0700 | [diff] [blame] | 1217 | public int getFailedUnlockAttempts() { |
| 1218 | return mFailedAttempts.get(sCurrentUser, 0); |
| 1219 | } |
| 1220 | |
| 1221 | public void reportFailedUnlockAttempt() { |
| 1222 | mFailedAttempts.put(sCurrentUser, getFailedUnlockAttempts() + 1); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1223 | } |
| 1224 | |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 1225 | public void clearFingerprintRecognized() { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1226 | mUserFingerprintAuthenticated.clear(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 1227 | } |
| 1228 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1229 | public boolean isSimPinVoiceSecure() { |
| 1230 | // TODO: only count SIMs that handle voice |
| 1231 | return isSimPinSecure(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | public boolean isSimPinSecure() { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1235 | // True if any SIM is pin secure |
| 1236 | for (SubscriptionInfo info : getSubscriptionInfo(false /* forceReload */)) { |
| 1237 | if (isSimPinSecure(getSimState(info.getSubscriptionId()))) return true; |
| 1238 | } |
| 1239 | return false; |
| 1240 | } |
| 1241 | |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 1242 | public State getSimState(int subId) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1243 | if (mSimDatas.containsKey(subId)) { |
| 1244 | return mSimDatas.get(subId).simState; |
| 1245 | } else { |
| 1246 | return State.UNKNOWN; |
| 1247 | } |
| 1248 | } |
| 1249 | |
Jorim Jaggi | 01ba98b | 2015-01-13 21:33:45 +0100 | [diff] [blame] | 1250 | /** |
| 1251 | * @return true if and only if the state has changed for the specified {@code slotId} |
| 1252 | */ |
| 1253 | private boolean refreshSimState(int subId, int slotId) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1254 | |
| 1255 | // This is awful. It exists because there are two APIs for getting the SIM status |
| 1256 | // that don't return the complete set of values and have different types. In Keyguard we |
| 1257 | // need IccCardConstants, but TelephonyManager would only give us |
| 1258 | // TelephonyManager.SIM_STATE*, so we retrieve it manually. |
xinhe | 18b9c3c | 2014-12-02 15:03:20 -0800 | [diff] [blame] | 1259 | final TelephonyManager tele = TelephonyManager.from(mContext); |
| 1260 | int simState = tele.getSimState(slotId); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1261 | State state; |
| 1262 | try { |
xinhe | 18b9c3c | 2014-12-02 15:03:20 -0800 | [diff] [blame] | 1263 | state = State.intToState(simState); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1264 | } catch(IllegalArgumentException ex) { |
xinhe | 18b9c3c | 2014-12-02 15:03:20 -0800 | [diff] [blame] | 1265 | Log.w(TAG, "Unknown sim state: " + simState); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1266 | state = State.UNKNOWN; |
John Spurlock | 5b13e92 | 2015-01-07 11:04:58 -0500 | [diff] [blame] | 1267 | } |
Jorim Jaggi | 01ba98b | 2015-01-13 21:33:45 +0100 | [diff] [blame] | 1268 | SimData data = mSimDatas.get(subId); |
| 1269 | final boolean changed; |
| 1270 | if (data == null) { |
| 1271 | data = new SimData(state, slotId, subId); |
| 1272 | mSimDatas.put(subId, data); |
| 1273 | changed = true; // no data yet; force update |
| 1274 | } else { |
| 1275 | changed = data.simState != state; |
| 1276 | data.simState = state; |
| 1277 | } |
| 1278 | return changed; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | public static boolean isSimPinSecure(IccCardConstants.State state) { |
| 1282 | final IccCardConstants.State simState = state; |
| 1283 | return (simState == IccCardConstants.State.PIN_REQUIRED |
| 1284 | || simState == IccCardConstants.State.PUK_REQUIRED |
| 1285 | || simState == IccCardConstants.State.PERM_DISABLED); |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 1286 | } |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1287 | |
| 1288 | public DisplayClientState getCachedDisplayClientState() { |
| 1289 | return mDisplayClientState; |
| 1290 | } |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1291 | |
| 1292 | // TODO: use these callbacks elsewhere in place of the existing notifyScreen*() |
| 1293 | // (KeyguardViewMediator, KeyguardHostView) |
| 1294 | public void dispatchScreenTurnedOn() { |
| 1295 | synchronized (this) { |
| 1296 | mScreenOn = true; |
| 1297 | } |
| 1298 | mHandler.sendEmptyMessage(MSG_SCREEN_TURNED_ON); |
| 1299 | } |
| 1300 | |
John Spurlock | 36a1342 | 2015-03-24 21:15:48 -0400 | [diff] [blame] | 1301 | public void dispatchScreenTurnedOff(int why) { |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1302 | synchronized(this) { |
| 1303 | mScreenOn = false; |
| 1304 | } |
| 1305 | mHandler.sendMessage(mHandler.obtainMessage(MSG_SCREEN_TURNED_OFF, why, 0)); |
| 1306 | } |
| 1307 | |
| 1308 | public boolean isScreenOn() { |
| 1309 | return mScreenOn; |
| 1310 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1311 | |
| 1312 | /** |
| 1313 | * Find the next SubscriptionId for a SIM in the given state, favoring lower slot numbers first. |
| 1314 | * @param state |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1315 | * @return subid or {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} if none found |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1316 | */ |
| 1317 | public int getNextSubIdForState(State state) { |
| 1318 | List<SubscriptionInfo> list = getSubscriptionInfo(false /* forceReload */); |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1319 | int resultId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1320 | int bestSlotId = Integer.MAX_VALUE; // Favor lowest slot first |
| 1321 | for (int i = 0; i < list.size(); i++) { |
| 1322 | final SubscriptionInfo info = list.get(i); |
| 1323 | final int id = info.getSubscriptionId(); |
| 1324 | int slotId = SubscriptionManager.getSlotId(id); |
| 1325 | if (state == getSimState(id) && bestSlotId > slotId ) { |
| 1326 | resultId = id; |
| 1327 | bestSlotId = slotId; |
| 1328 | } |
| 1329 | } |
| 1330 | return resultId; |
| 1331 | } |
| 1332 | |
| 1333 | public SubscriptionInfo getSubscriptionInfoForSubId(int subId) { |
| 1334 | List<SubscriptionInfo> list = getSubscriptionInfo(false /* forceReload */); |
| 1335 | for (int i = 0; i < list.size(); i++) { |
| 1336 | SubscriptionInfo info = list.get(i); |
| 1337 | if (subId == info.getSubscriptionId()) return info; |
| 1338 | } |
| 1339 | return null; // not found |
| 1340 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1341 | } |