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