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