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