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