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 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; |
| 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 21 | import static android.content.Intent.ACTION_USER_UNLOCKED; |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 22 | import static android.os.BatteryManager.BATTERY_HEALTH_UNKNOWN; |
| 23 | import static android.os.BatteryManager.BATTERY_STATUS_FULL; |
| 24 | import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN; |
| 25 | import static android.os.BatteryManager.EXTRA_HEALTH; |
| 26 | import static android.os.BatteryManager.EXTRA_LEVEL; |
| 27 | import static android.os.BatteryManager.EXTRA_MAX_CHARGING_CURRENT; |
| 28 | import static android.os.BatteryManager.EXTRA_MAX_CHARGING_VOLTAGE; |
| 29 | import static android.os.BatteryManager.EXTRA_PLUGGED; |
| 30 | import static android.os.BatteryManager.EXTRA_STATUS; |
| 31 | |
Jorim Jaggi | ccdfa93 | 2015-04-13 16:29:48 -0700 | [diff] [blame] | 32 | import android.app.ActivityManager; |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 33 | import android.app.AlarmManager; |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 34 | import android.app.PendingIntent; |
Sudheer Shanka | 2c4522c | 2016-08-27 20:53:28 -0700 | [diff] [blame] | 35 | import android.app.UserSwitchObserver; |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 36 | import android.app.admin.DevicePolicyManager; |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 37 | import android.app.trust.TrustManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 38 | import android.content.BroadcastReceiver; |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 39 | import android.content.ComponentName; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 40 | import android.content.Context; |
| 41 | import android.content.Intent; |
| 42 | import android.content.IntentFilter; |
Adrian Roos | ca8a216 | 2017-08-17 19:00:58 +0200 | [diff] [blame] | 43 | import android.content.pm.IPackageManager; |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 44 | import android.content.pm.PackageManager; |
| 45 | import android.content.pm.ResolveInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 46 | import android.database.ContentObserver; |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 47 | import android.graphics.Bitmap; |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 48 | import android.hardware.fingerprint.FingerprintManager; |
| 49 | import android.hardware.fingerprint.FingerprintManager.AuthenticationCallback; |
| 50 | import android.hardware.fingerprint.FingerprintManager.AuthenticationResult; |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 51 | import android.media.AudioManager; |
Jim Miller | 79a444a | 2011-02-15 15:02:11 -0800 | [diff] [blame] | 52 | import android.os.BatteryManager; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 53 | import android.os.CancellationSignal; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 54 | import android.os.Handler; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 55 | import android.os.IRemoteCallback; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 56 | import android.os.Message; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 57 | import android.os.RemoteException; |
Adrian Roos | ca8a216 | 2017-08-17 19:00:58 +0200 | [diff] [blame] | 58 | import android.os.ServiceManager; |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 59 | import android.os.Trace; |
Amith Yamasani | e8e93a1 | 2013-05-09 18:12:30 -0700 | [diff] [blame] | 60 | import android.os.UserHandle; |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 61 | import android.os.UserManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 62 | import android.provider.Settings; |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 63 | import android.service.dreams.DreamService; |
| 64 | import android.service.dreams.IDreamManager; |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 65 | import android.telephony.ServiceState; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 66 | import android.telephony.SubscriptionInfo; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 67 | import android.telephony.SubscriptionManager; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 68 | import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener; |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 69 | import android.telephony.TelephonyManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 70 | import android.util.Log; |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 71 | import android.util.SparseBooleanArray; |
Jorim Jaggi | 9f74303 | 2015-05-04 15:22:40 -0700 | [diff] [blame] | 72 | import android.util.SparseIntArray; |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 73 | |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 74 | import com.android.internal.annotations.VisibleForTesting; |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 75 | import com.android.internal.telephony.IccCardConstants; |
| 76 | import com.android.internal.telephony.IccCardConstants.State; |
| 77 | import com.android.internal.telephony.PhoneConstants; |
| 78 | import com.android.internal.telephony.TelephonyIntents; |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 79 | import com.android.internal.widget.LockPatternUtils; |
Winson Chung | aa35745 | 2017-10-31 11:35:30 -0700 | [diff] [blame] | 80 | import com.android.systemui.recents.misc.SysUiTaskStackChangeListener; |
Winson Chung | 2cf6ad8 | 2017-11-09 17:36:59 -0800 | [diff] [blame] | 81 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 82 | |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 83 | import com.google.android.collect.Lists; |
| 84 | |
Jason Monk | ab52527 | 2015-07-13 17:02:49 -0400 | [diff] [blame] | 85 | import java.io.FileDescriptor; |
| 86 | import java.io.PrintWriter; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 87 | import java.lang.ref.WeakReference; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 88 | import java.util.ArrayList; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 89 | import java.util.HashMap; |
richard chou | b1b24e7 | 2018-03-22 14:39:43 +0800 | [diff] [blame] | 90 | import java.util.HashSet; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 91 | import java.util.List; |
| 92 | import java.util.Map.Entry; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * Watches for updates that may be interesting to the keyguard, and provides |
| 96 | * the up to date information as well as a registration for callbacks that care |
| 97 | * to be updated. |
| 98 | * |
| 99 | * Note: under time crunch, this has been extended to include some stuff that |
| 100 | * doesn't really belong here. see {@link #handleBatteryUpdate} where it shutdowns |
Jim Miller | 258341c | 2012-08-30 16:50:10 -0700 | [diff] [blame] | 101 | * the device, and {@link #getFailedUnlockAttempts()}, {@link #reportFailedAttempt()} |
| 102 | * and {@link #clearFailedUnlockAttempts()}. Maybe we should rename this 'KeyguardContext'... |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 103 | */ |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 104 | public class KeyguardUpdateMonitor implements TrustManager.TrustListener { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 105 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 106 | private static final String TAG = "KeyguardUpdateMonitor"; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 107 | private static final boolean DEBUG = KeyguardConstants.DEBUG; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 108 | private static final boolean DEBUG_SIM_STATES = KeyguardConstants.DEBUG_SIM_STATES; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 109 | private static final int LOW_BATTERY_THRESHOLD = 20; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 110 | |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 111 | private static final String ACTION_FACE_UNLOCK_STARTED |
| 112 | = "com.android.facelock.FACE_UNLOCK_STARTED"; |
| 113 | private static final String ACTION_FACE_UNLOCK_STOPPED |
| 114 | = "com.android.facelock.FACE_UNLOCK_STOPPED"; |
| 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_RESET = 312; |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 126 | private static final int MSG_BOOT_COMPLETED = 313; |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 127 | private static final int MSG_USER_SWITCH_COMPLETE = 314; |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 128 | private static final int MSG_USER_INFO_CHANGED = 317; |
| 129 | private static final int MSG_REPORT_EMERGENCY_CALL_ACTION = 318; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 130 | private static final int MSG_STARTED_WAKING_UP = 319; |
| 131 | private static final int MSG_FINISHED_GOING_TO_SLEEP = 320; |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 132 | private static final int MSG_STARTED_GOING_TO_SLEEP = 321; |
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; |
Selim Cinek | 9941539 | 2016-09-09 14:58:41 -0700 | [diff] [blame] | 140 | private static final int MSG_DREAMING_STATE_CHANGED = 333; |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 141 | private static final int MSG_USER_UNLOCKED = 334; |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 142 | private static final int MSG_ASSISTANT_STACK_CHANGED = 335; |
Kevin Chyn | 0f3e0b1 | 2017-07-20 16:56:11 -0700 | [diff] [blame] | 143 | private static final int MSG_FINGERPRINT_AUTHENTICATION_CONTINUE = 336; |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 144 | private static final int MSG_DEVICE_POLICY_MANAGER_STATE_CHANGED = 337; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 145 | |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 146 | /** Fingerprint state: Not listening to fingerprint. */ |
| 147 | private static final int FINGERPRINT_STATE_STOPPED = 0; |
| 148 | |
| 149 | /** Fingerprint state: Listening. */ |
| 150 | private static final int FINGERPRINT_STATE_RUNNING = 1; |
| 151 | |
| 152 | /** |
| 153 | * Fingerprint state: Cancelling and waiting for the confirmation from FingerprintService to |
| 154 | * send us the confirmation that cancellation has happened. |
| 155 | */ |
| 156 | private static final int FINGERPRINT_STATE_CANCELLING = 2; |
| 157 | |
| 158 | /** |
| 159 | * Fingerprint state: During cancelling we got another request to start listening, so when we |
| 160 | * receive the cancellation done signal, we should start listening again. |
| 161 | */ |
| 162 | private static final int FINGERPRINT_STATE_CANCELLING_RESTARTING = 3; |
| 163 | |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 164 | private static final int DEFAULT_CHARGING_VOLTAGE_MICRO_VOLT = 5000000; |
| 165 | |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 166 | private static final ComponentName FALLBACK_HOME_COMPONENT = new ComponentName( |
| 167 | "com.android.settings", "com.android.settings.FallbackHome"); |
| 168 | |
Adrian Roos | ca8a216 | 2017-08-17 19:00:58 +0200 | [diff] [blame] | 169 | |
| 170 | /** |
| 171 | * If true, the system is in the half-boot-to-decryption-screen state. |
| 172 | * Prudently disable lockscreen. |
| 173 | */ |
| 174 | public static final boolean CORE_APPS_ONLY; |
| 175 | static { |
| 176 | try { |
| 177 | CORE_APPS_ONLY = IPackageManager.Stub.asInterface( |
| 178 | ServiceManager.getService("package")).isOnlyCoreApps(); |
| 179 | } catch (RemoteException e) { |
| 180 | throw e.rethrowFromSystemServer(); |
| 181 | } |
| 182 | } |
| 183 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 184 | private static KeyguardUpdateMonitor sInstance; |
| 185 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 186 | private final Context mContext; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 187 | HashMap<Integer, SimData> mSimDatas = new HashMap<Integer, SimData>(); |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 188 | HashMap<Integer, ServiceState> mServiceStates = new HashMap<Integer, ServiceState>(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 189 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 190 | private int mRingMode; |
| 191 | private int mPhoneState; |
Danielle Millett | 5d2404d | 2012-11-01 00:05:27 -0400 | [diff] [blame] | 192 | private boolean mKeyguardIsVisible; |
Kevin Chyn | f3b8fbd | 2017-05-03 22:24:31 -0700 | [diff] [blame] | 193 | private boolean mKeyguardGoingAway; |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 194 | private boolean mGoingToSleep; |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 195 | private boolean mBouncer; |
Adam Cohen | 4eb36cf | 2012-11-07 11:45:30 -0800 | [diff] [blame] | 196 | private boolean mBootCompleted; |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 197 | private boolean mNeedsSlowUnlockTransition; |
Jorim Jaggi | d11d1a9 | 2016-08-16 16:02:32 -0700 | [diff] [blame] | 198 | private boolean mHasLockscreenWallpaper; |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 199 | private boolean mAssistantVisible; |
| 200 | private boolean mKeyguardOccluded; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 201 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 202 | // Device provisioning state |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 203 | private boolean mDeviceProvisioned; |
| 204 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 205 | // Battery status |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 206 | private BatteryStatus mBatteryStatus; |
| 207 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 208 | // Password attempts |
Jorim Jaggi | 9f74303 | 2015-05-04 15:22:40 -0700 | [diff] [blame] | 209 | private SparseIntArray mFailedAttempts = new SparseIntArray(); |
Brian Colonna | cc4104f | 2012-10-09 17:50:46 -0400 | [diff] [blame] | 210 | |
Rakesh Iyer | a7aa4d6 | 2016-01-19 17:27:23 -0800 | [diff] [blame] | 211 | private final StrongAuthTracker mStrongAuthTracker; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 212 | |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 213 | private final ArrayList<WeakReference<KeyguardUpdateMonitorCallback>> |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 214 | mCallbacks = Lists.newArrayList(); |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 215 | private ContentObserver mDeviceProvisionedObserver; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 216 | |
Brian Colonna | a523989 | 2013-04-15 11:45:40 -0400 | [diff] [blame] | 217 | private boolean mSwitchingUser; |
| 218 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 219 | private boolean mDeviceInteractive; |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 220 | private boolean mScreenOn; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 221 | private SubscriptionManager mSubscriptionManager; |
| 222 | private List<SubscriptionInfo> mSubscriptionInfo; |
Jorim Jaggi | 237b061 | 2015-05-01 14:28:49 -0700 | [diff] [blame] | 223 | private TrustManager mTrustManager; |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 224 | private UserManager mUserManager; |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 225 | private int mFingerprintRunningState = FINGERPRINT_STATE_STOPPED; |
Michal Karpinski | c52f867 | 2016-11-18 11:32:45 +0000 | [diff] [blame] | 226 | private LockPatternUtils mLockPatternUtils; |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 227 | private final IDreamManager mDreamManager; |
| 228 | private boolean mIsDreaming; |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 229 | private final DevicePolicyManager mDevicePolicyManager; |
| 230 | private boolean mLogoutEnabled; |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 231 | |
Kevin Chyn | 0f3e0b1 | 2017-07-20 16:56:11 -0700 | [diff] [blame] | 232 | /** |
| 233 | * Short delay before restarting fingerprint authentication after a successful try |
| 234 | * This should be slightly longer than the time between onFingerprintAuthenticated and |
| 235 | * setKeyguardGoingAway(true). |
| 236 | */ |
| 237 | private static final int FINGERPRINT_CONTINUE_DELAY_MS = 500; |
| 238 | |
Kevin Chyn | 0c45b07 | 2017-04-24 16:27:11 -0700 | [diff] [blame] | 239 | // If FP daemon dies, keyguard should retry after a short delay |
| 240 | private int mHardwareUnavailableRetryCount = 0; |
| 241 | private static final int HW_UNAVAILABLE_TIMEOUT = 3000; // ms |
| 242 | private static final int HW_UNAVAILABLE_RETRY_MAX = 3; |
| 243 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 244 | private final Handler mHandler = new Handler() { |
| 245 | @Override |
| 246 | public void handleMessage(Message msg) { |
| 247 | switch (msg.what) { |
| 248 | case MSG_TIME_UPDATE: |
| 249 | handleTimeUpdate(); |
| 250 | break; |
| 251 | case MSG_BATTERY_UPDATE: |
| 252 | handleBatteryUpdate((BatteryStatus) msg.obj); |
| 253 | break; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 254 | case MSG_SIM_STATE_CHANGE: |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 255 | handleSimStateChange(msg.arg1, msg.arg2, (State) msg.obj); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 256 | break; |
| 257 | case MSG_RINGER_MODE_CHANGED: |
| 258 | handleRingerModeChange(msg.arg1); |
| 259 | break; |
| 260 | case MSG_PHONE_STATE_CHANGED: |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 261 | handlePhoneStateChanged((String) msg.obj); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 262 | break; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 263 | case MSG_DEVICE_PROVISIONED: |
| 264 | handleDeviceProvisioned(); |
| 265 | break; |
| 266 | case MSG_DPM_STATE_CHANGED: |
| 267 | handleDevicePolicyManagerStateChanged(); |
| 268 | break; |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 269 | case MSG_USER_SWITCHING: |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 270 | handleUserSwitching(msg.arg1, (IRemoteCallback) msg.obj); |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 271 | break; |
| 272 | case MSG_USER_SWITCH_COMPLETE: |
| 273 | handleUserSwitchComplete(msg.arg1); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 274 | break; |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 275 | case MSG_KEYGUARD_RESET: |
| 276 | handleKeyguardReset(); |
| 277 | break; |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 278 | case MSG_KEYGUARD_BOUNCER_CHANGED: |
| 279 | handleKeyguardBouncerChanged(msg.arg1); |
| 280 | break; |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 281 | case MSG_BOOT_COMPLETED: |
| 282 | handleBootCompleted(); |
| 283 | break; |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 284 | case MSG_USER_INFO_CHANGED: |
| 285 | handleUserInfoChanged(msg.arg1); |
| 286 | break; |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 287 | case MSG_REPORT_EMERGENCY_CALL_ACTION: |
| 288 | handleReportEmergencyCallAction(); |
| 289 | break; |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 290 | case MSG_STARTED_GOING_TO_SLEEP: |
| 291 | handleStartedGoingToSleep(msg.arg1); |
| 292 | break; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 293 | case MSG_FINISHED_GOING_TO_SLEEP: |
| 294 | handleFinishedGoingToSleep(msg.arg1); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 295 | break; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 296 | case MSG_STARTED_WAKING_UP: |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 297 | Trace.beginSection("KeyguardUpdateMonitor#handler MSG_STARTED_WAKING_UP"); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 298 | handleStartedWakingUp(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 299 | Trace.endSection(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 300 | break; |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 301 | case MSG_FACE_UNLOCK_STATE_CHANGED: |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 302 | Trace.beginSection("KeyguardUpdateMonitor#handler MSG_FACE_UNLOCK_STATE_CHANGED"); |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 303 | handleFaceUnlockStateChanged(msg.arg1 != 0, msg.arg2); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 304 | Trace.endSection(); |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 305 | break; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 306 | case MSG_SIM_SUBSCRIPTION_INFO_CHANGED: |
| 307 | handleSimSubscriptionInfoChanged(); |
| 308 | break; |
Jason Monk | 052082c | 2015-06-11 11:35:23 -0400 | [diff] [blame] | 309 | case MSG_AIRPLANE_MODE_CHANGED: |
| 310 | handleAirplaneModeChanged(); |
| 311 | break; |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 312 | case MSG_SERVICE_STATE_CHANGE: |
| 313 | handleServiceStateChange(msg.arg1, (ServiceState) msg.obj); |
| 314 | break; |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 315 | case MSG_SCREEN_TURNED_ON: |
| 316 | handleScreenTurnedOn(); |
| 317 | break; |
| 318 | case MSG_SCREEN_TURNED_OFF: |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 319 | Trace.beginSection("KeyguardUpdateMonitor#handler MSG_SCREEN_TURNED_ON"); |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 320 | handleScreenTurnedOff(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 321 | Trace.endSection(); |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 322 | break; |
Selim Cinek | 9941539 | 2016-09-09 14:58:41 -0700 | [diff] [blame] | 323 | case MSG_DREAMING_STATE_CHANGED: |
| 324 | handleDreamingStateChanged(msg.arg1); |
| 325 | break; |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 326 | case MSG_USER_UNLOCKED: |
| 327 | handleUserUnlocked(); |
| 328 | break; |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 329 | case MSG_ASSISTANT_STACK_CHANGED: |
| 330 | mAssistantVisible = (boolean)msg.obj; |
| 331 | updateFingerprintListeningState(); |
| 332 | break; |
Kevin Chyn | 0f3e0b1 | 2017-07-20 16:56:11 -0700 | [diff] [blame] | 333 | case MSG_FINGERPRINT_AUTHENTICATION_CONTINUE: |
| 334 | updateFingerprintListeningState(); |
| 335 | break; |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 336 | case MSG_DEVICE_POLICY_MANAGER_STATE_CHANGED: |
| 337 | updateLogoutEnabled(); |
| 338 | break; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | }; |
| 342 | |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 343 | private OnSubscriptionsChangedListener mSubscriptionListener = |
| 344 | new OnSubscriptionsChangedListener() { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 345 | @Override |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 346 | public void onSubscriptionsChanged() { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 347 | mHandler.sendEmptyMessage(MSG_SIM_SUBSCRIPTION_INFO_CHANGED); |
| 348 | } |
| 349 | }; |
| 350 | |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 351 | private SparseBooleanArray mUserHasTrust = new SparseBooleanArray(); |
Adrian Roos | 7861c66 | 2014-07-25 15:37:28 +0200 | [diff] [blame] | 352 | private SparseBooleanArray mUserTrustIsManaged = new SparseBooleanArray(); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 353 | private SparseBooleanArray mUserFingerprintAuthenticated = new SparseBooleanArray(); |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 354 | private SparseBooleanArray mUserFaceUnlockRunning = new SparseBooleanArray(); |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 355 | |
Adrian Roos | d6aa6cb | 2015-04-16 19:31:29 -0700 | [diff] [blame] | 356 | private static int sCurrentUser; |
Selim Cinek | bbe1924 | 2017-12-08 15:42:08 -0800 | [diff] [blame] | 357 | private Runnable mUpdateFingerprintListeningState = this::updateFingerprintListeningState; |
Adrian Roos | d6aa6cb | 2015-04-16 19:31:29 -0700 | [diff] [blame] | 358 | |
| 359 | public synchronized static void setCurrentUser(int currentUser) { |
| 360 | sCurrentUser = currentUser; |
| 361 | } |
| 362 | |
| 363 | public synchronized static int getCurrentUser() { |
| 364 | return sCurrentUser; |
| 365 | } |
| 366 | |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 367 | @Override |
Adrian Roos | 94e15a5 | 2015-04-16 12:23:18 -0700 | [diff] [blame] | 368 | public void onTrustChanged(boolean enabled, int userId, int flags) { |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 369 | mUserHasTrust.put(userId, enabled); |
Adrian Roos | 2fe592d | 2014-05-17 03:11:59 +0200 | [diff] [blame] | 370 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 371 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 372 | if (cb != null) { |
| 373 | cb.onTrustChanged(userId); |
Adrian Roos | 94e15a5 | 2015-04-16 12:23:18 -0700 | [diff] [blame] | 374 | if (enabled && flags != 0) { |
| 375 | cb.onTrustGrantedWithFlags(flags, userId); |
Adrian Roos | 3c9a350 | 2014-08-06 19:09:45 +0200 | [diff] [blame] | 376 | } |
Adrian Roos | 2fe592d | 2014-05-17 03:11:59 +0200 | [diff] [blame] | 377 | } |
| 378 | } |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 379 | } |
| 380 | |
Lucas Dupin | ef88654 | 2018-01-03 16:03:07 -0800 | [diff] [blame] | 381 | @Override |
| 382 | public void onTrustError(CharSequence message) { |
| 383 | dispatchErrorMessage(message); |
| 384 | } |
| 385 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 386 | protected void handleSimSubscriptionInfoChanged() { |
| 387 | if (DEBUG_SIM_STATES) { |
| 388 | Log.v(TAG, "onSubscriptionInfoChanged()"); |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 389 | List<SubscriptionInfo> sil = mSubscriptionManager.getActiveSubscriptionInfoList(); |
| 390 | if (sil != null) { |
| 391 | for (SubscriptionInfo subInfo : sil) { |
| 392 | Log.v(TAG, "SubInfo:" + subInfo); |
| 393 | } |
| 394 | } else { |
| 395 | Log.v(TAG, "onSubscriptionInfoChanged: list is null"); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | List<SubscriptionInfo> subscriptionInfos = getSubscriptionInfo(true /* forceReload */); |
| 399 | |
| 400 | // Hack level over 9000: Because the subscription id is not yet valid when we see the |
| 401 | // first update in handleSimStateChange, we need to force refresh all all SIM states |
| 402 | // so the subscription id for them is consistent. |
richard chou | b1b24e7 | 2018-03-22 14:39:43 +0800 | [diff] [blame] | 403 | List<Integer> changedSubscriptionIds = refreshSimState(subscriptionInfos); |
| 404 | for (int i = 0; i < changedSubscriptionIds.size(); i++) { |
| 405 | SimData data = mSimDatas.get(changedSubscriptionIds.get(i)); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 406 | for (int j = 0; j < mCallbacks.size(); j++) { |
| 407 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get(); |
| 408 | if (cb != null) { |
| 409 | cb.onSimStateChanged(data.subId, data.slotId, data.simState); |
| 410 | } |
| 411 | } |
| 412 | } |
Jason Monk | 6c985dc | 2015-01-09 16:07:14 -0500 | [diff] [blame] | 413 | for (int j = 0; j < mCallbacks.size(); j++) { |
| 414 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get(); |
| 415 | if (cb != null) { |
| 416 | cb.onRefreshCarrierInfo(); |
| 417 | } |
| 418 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 419 | } |
| 420 | |
Jason Monk | 052082c | 2015-06-11 11:35:23 -0400 | [diff] [blame] | 421 | private void handleAirplaneModeChanged() { |
| 422 | for (int j = 0; j < mCallbacks.size(); j++) { |
| 423 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get(); |
| 424 | if (cb != null) { |
| 425 | cb.onRefreshCarrierInfo(); |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 430 | /** @return List of SubscriptionInfo records, maybe empty but never null */ |
Adrian Roos | 316bf54 | 2016-08-23 17:53:07 +0200 | [diff] [blame] | 431 | public List<SubscriptionInfo> getSubscriptionInfo(boolean forceReload) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 432 | List<SubscriptionInfo> sil = mSubscriptionInfo; |
| 433 | if (sil == null || forceReload) { |
| 434 | sil = mSubscriptionManager.getActiveSubscriptionInfoList(); |
| 435 | } |
| 436 | if (sil == null) { |
| 437 | // getActiveSubscriptionInfoList was null callers expect an empty list. |
| 438 | mSubscriptionInfo = new ArrayList<SubscriptionInfo>(); |
| 439 | } else { |
| 440 | mSubscriptionInfo = sil; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 441 | } |
| 442 | return mSubscriptionInfo; |
| 443 | } |
| 444 | |
Adrian Roos | 7861c66 | 2014-07-25 15:37:28 +0200 | [diff] [blame] | 445 | @Override |
| 446 | public void onTrustManagedChanged(boolean managed, int userId) { |
| 447 | mUserTrustIsManaged.put(userId, managed); |
| 448 | |
| 449 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 450 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 451 | if (cb != null) { |
| 452 | cb.onTrustManagedChanged(userId); |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | |
Kevin Chyn | f3b8fbd | 2017-05-03 22:24:31 -0700 | [diff] [blame] | 457 | /** |
| 458 | * Updates KeyguardUpdateMonitor's internal state to know if keyguard is goingAway |
| 459 | * @param goingAway |
| 460 | */ |
| 461 | public void setKeyguardGoingAway(boolean goingAway) { |
| 462 | mKeyguardGoingAway = goingAway; |
Kevin Chyn | e22f134 | 2017-09-26 10:03:38 -0700 | [diff] [blame] | 463 | updateFingerprintListeningState(); |
Kevin Chyn | f3b8fbd | 2017-05-03 22:24:31 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 466 | /** |
| 467 | * Updates KeyguardUpdateMonitor's internal state to know if keyguard is occluded |
| 468 | * @param occluded |
| 469 | */ |
| 470 | public void setKeyguardOccluded(boolean occluded) { |
| 471 | mKeyguardOccluded = occluded; |
| 472 | updateFingerprintListeningState(); |
| 473 | } |
| 474 | |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 475 | /** |
| 476 | * @return a cached version of DreamManager.isDreaming() |
| 477 | */ |
| 478 | public boolean isDreaming() { |
| 479 | return mIsDreaming; |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * If the device is dreaming, awakens the device |
| 484 | */ |
| 485 | public void awakenFromDream() { |
| 486 | if (mIsDreaming && mDreamManager != null) { |
| 487 | try { |
| 488 | mDreamManager.awaken(); |
| 489 | } catch (RemoteException e) { |
| 490 | Log.e(TAG, "Unable to awaken from dream"); |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 495 | private void onFingerprintAuthenticated(int userId) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 496 | Trace.beginSection("KeyGuardUpdateMonitor#onFingerPrintAuthenticated"); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 497 | mUserFingerprintAuthenticated.put(userId, true); |
Kevin Chyn | 3fdbbf8 | 2017-05-06 15:11:53 -0700 | [diff] [blame] | 498 | // Update/refresh trust state only if user can skip bouncer |
| 499 | if (getUserCanSkipBouncer(userId)) { |
| 500 | mTrustManager.unlockedByFingerprintForUser(userId); |
| 501 | } |
Kevin Chyn | 625a014 | 2017-04-10 14:53:59 -0700 | [diff] [blame] | 502 | // Don't send cancel if authentication succeeds |
| 503 | mFingerprintCancelSignal = null; |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 504 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 505 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 506 | if (cb != null) { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 507 | cb.onFingerprintAuthenticated(userId); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 508 | } |
| 509 | } |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 510 | |
Kevin Chyn | 0f3e0b1 | 2017-07-20 16:56:11 -0700 | [diff] [blame] | 511 | mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_FINGERPRINT_AUTHENTICATION_CONTINUE), |
| 512 | FINGERPRINT_CONTINUE_DELAY_MS); |
| 513 | |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 514 | // Only authenticate fingerprint once when assistant is visible |
| 515 | mAssistantVisible = false; |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 516 | |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 517 | Trace.endSection(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 520 | private void handleFingerprintAuthFailed() { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 521 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 522 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 523 | if (cb != null) { |
| 524 | cb.onFingerprintAuthFailed(); |
| 525 | } |
Jorim Jaggi | 007f0e8 | 2015-08-14 13:56:01 -0700 | [diff] [blame] | 526 | } |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 527 | handleFingerprintHelp(-1, mContext.getString(R.string.fingerprint_not_recognized)); |
| 528 | } |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 529 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 530 | private void handleFingerprintAcquired(int acquireInfo) { |
| 531 | if (acquireInfo != FingerprintManager.FINGERPRINT_ACQUIRED_GOOD) { |
| 532 | return; |
| 533 | } |
Jorim Jaggi | 007f0e8 | 2015-08-14 13:56:01 -0700 | [diff] [blame] | 534 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 535 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 536 | if (cb != null) { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 537 | cb.onFingerprintAcquired(); |
Jorim Jaggi | 007f0e8 | 2015-08-14 13:56:01 -0700 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | } |
| 541 | |
Jim Miller | 837fa7e | 2016-08-08 20:16:22 -0700 | [diff] [blame] | 542 | private void handleFingerprintAuthenticated(int authUserId) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 543 | Trace.beginSection("KeyGuardUpdateMonitor#handlerFingerPrintAuthenticated"); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 544 | try { |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 545 | final int userId; |
| 546 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 547 | userId = ActivityManager.getService().getCurrentUser().id; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 548 | } catch (RemoteException e) { |
| 549 | Log.e(TAG, "Failed to get current user id: ", e); |
| 550 | return; |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 551 | } |
Jim Miller | 837fa7e | 2016-08-08 20:16:22 -0700 | [diff] [blame] | 552 | if (userId != authUserId) { |
| 553 | Log.d(TAG, "Fingerprint authenticated for wrong user: " + authUserId); |
| 554 | return; |
| 555 | } |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 556 | if (isFingerprintDisabled(userId)) { |
| 557 | Log.d(TAG, "Fingerprint disabled by DPM for userId: " + userId); |
| 558 | return; |
| 559 | } |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 560 | onFingerprintAuthenticated(userId); |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 561 | } finally { |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 562 | setFingerprintRunningState(FINGERPRINT_STATE_STOPPED); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 563 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 564 | Trace.endSection(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 567 | private void handleFingerprintHelp(int msgId, String helpString) { |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 568 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 569 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 570 | if (cb != null) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 571 | cb.onFingerprintHelp(msgId, helpString); |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | |
Kevin Chyn | 0c45b07 | 2017-04-24 16:27:11 -0700 | [diff] [blame] | 576 | private Runnable mRetryFingerprintAuthentication = new Runnable() { |
| 577 | @Override |
| 578 | public void run() { |
| 579 | Log.w(TAG, "Retrying fingerprint after HW unavailable, attempt " + |
| 580 | mHardwareUnavailableRetryCount); |
| 581 | updateFingerprintListeningState(); |
| 582 | } |
| 583 | }; |
| 584 | |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 585 | private void handleFingerprintError(int msgId, String errString) { |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 586 | if (msgId == FingerprintManager.FINGERPRINT_ERROR_CANCELED |
| 587 | && mFingerprintRunningState == FINGERPRINT_STATE_CANCELLING_RESTARTING) { |
| 588 | setFingerprintRunningState(FINGERPRINT_STATE_STOPPED); |
| 589 | startListeningForFingerprint(); |
| 590 | } else { |
| 591 | setFingerprintRunningState(FINGERPRINT_STATE_STOPPED); |
| 592 | } |
Kevin Chyn | 0c45b07 | 2017-04-24 16:27:11 -0700 | [diff] [blame] | 593 | |
| 594 | if (msgId == FingerprintManager.FINGERPRINT_ERROR_HW_UNAVAILABLE) { |
| 595 | if (mHardwareUnavailableRetryCount < HW_UNAVAILABLE_RETRY_MAX) { |
| 596 | mHardwareUnavailableRetryCount++; |
| 597 | mHandler.removeCallbacks(mRetryFingerprintAuthentication); |
| 598 | mHandler.postDelayed(mRetryFingerprintAuthentication, HW_UNAVAILABLE_TIMEOUT); |
| 599 | } |
| 600 | } |
| 601 | |
Kevin Chyn | df9d33e | 2017-05-03 21:40:12 -0700 | [diff] [blame] | 602 | if (msgId == FingerprintManager.FINGERPRINT_ERROR_LOCKOUT_PERMANENT) { |
| 603 | mLockPatternUtils.requireStrongAuth( |
| 604 | LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT, |
| 605 | getCurrentUser()); |
| 606 | } |
| 607 | |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 608 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 609 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 610 | if (cb != null) { |
| 611 | cb.onFingerprintError(msgId, errString); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | } |
| 615 | |
Jorim Jaggi | 3a46478 | 2015-08-28 16:59:13 -0700 | [diff] [blame] | 616 | private void handleFingerprintLockoutReset() { |
| 617 | updateFingerprintListeningState(); |
| 618 | } |
| 619 | |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 620 | private void setFingerprintRunningState(int fingerprintRunningState) { |
| 621 | boolean wasRunning = mFingerprintRunningState == FINGERPRINT_STATE_RUNNING; |
| 622 | boolean isRunning = fingerprintRunningState == FINGERPRINT_STATE_RUNNING; |
| 623 | mFingerprintRunningState = fingerprintRunningState; |
| 624 | |
| 625 | // Clients of KeyguardUpdateMonitor don't care about the internal state about the |
| 626 | // asynchronousness of the cancel cycle. So only notify them if the actualy running state |
| 627 | // has changed. |
| 628 | if (wasRunning != isRunning) { |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 629 | notifyFingerprintRunningStateChanged(); |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | private void notifyFingerprintRunningStateChanged() { |
| 634 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 635 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 636 | if (cb != null) { |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 637 | cb.onFingerprintRunningStateChanged(isFingerprintDetectionRunning()); |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | } |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 641 | private void handleFaceUnlockStateChanged(boolean running, int userId) { |
| 642 | mUserFaceUnlockRunning.put(userId, running); |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 643 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 644 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 645 | if (cb != null) { |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 646 | cb.onFaceUnlockStateChanged(running, userId); |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 647 | } |
| 648 | } |
| 649 | } |
| 650 | |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 651 | public boolean isFaceUnlockRunning(int userId) { |
| 652 | return mUserFaceUnlockRunning.get(userId); |
| 653 | } |
| 654 | |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 655 | public boolean isFingerprintDetectionRunning() { |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 656 | return mFingerprintRunningState == FINGERPRINT_STATE_RUNNING; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 659 | private boolean isTrustDisabled(int userId) { |
Adrian Roos | a4da9f6 | 2015-02-21 01:15:21 +0100 | [diff] [blame] | 660 | // Don't allow trust agent if device is secured with a SIM PIN. This is here |
| 661 | // mainly because there's no other way to prompt the user to enter their SIM PIN |
| 662 | // once they get past the keyguard screen. |
| 663 | final boolean disabledBySimPin = isSimPinSecure(); |
| 664 | return disabledBySimPin; |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 667 | private boolean isFingerprintDisabled(int userId) { |
| 668 | final DevicePolicyManager dpm = |
| 669 | (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE); |
| 670 | return dpm != null && (dpm.getKeyguardDisabledFeatures(null, userId) |
Adrian Roos | 733b663 | 2015-08-21 14:32:35 -0700 | [diff] [blame] | 671 | & DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT) != 0 |
| 672 | || isSimPinSecure(); |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Selim Cinek | e8bae62 | 2015-07-15 13:24:06 -0700 | [diff] [blame] | 675 | public boolean getUserCanSkipBouncer(int userId) { |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 676 | return getUserHasTrust(userId) || (mUserFingerprintAuthenticated.get(userId) |
| 677 | && isUnlockingWithFingerprintAllowed()); |
Selim Cinek | e8bae62 | 2015-07-15 13:24:06 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 680 | public boolean getUserHasTrust(int userId) { |
Selim Cinek | e8bae62 | 2015-07-15 13:24:06 -0700 | [diff] [blame] | 681 | return !isTrustDisabled(userId) && mUserHasTrust.get(userId); |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 682 | } |
| 683 | |
Adrian Roos | 7861c66 | 2014-07-25 15:37:28 +0200 | [diff] [blame] | 684 | public boolean getUserTrustIsManaged(int userId) { |
| 685 | return mUserTrustIsManaged.get(userId) && !isTrustDisabled(userId); |
| 686 | } |
| 687 | |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 688 | public boolean isUnlockingWithFingerprintAllowed() { |
Michal Karpinski | c52f867 | 2016-11-18 11:32:45 +0000 | [diff] [blame] | 689 | return mStrongAuthTracker.isUnlockingWithFingerprintAllowed(); |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 690 | } |
| 691 | |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 692 | public boolean needsSlowUnlockTransition() { |
| 693 | return mNeedsSlowUnlockTransition; |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 696 | public StrongAuthTracker getStrongAuthTracker() { |
| 697 | return mStrongAuthTracker; |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 698 | } |
| 699 | |
Adrian Roos | 1de8bcb | 2015-08-19 16:52:52 -0700 | [diff] [blame] | 700 | private void notifyStrongAuthStateChanged(int userId) { |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 701 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 702 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 703 | if (cb != null) { |
Adrian Roos | 1de8bcb | 2015-08-19 16:52:52 -0700 | [diff] [blame] | 704 | cb.onStrongAuthStateChanged(userId); |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 705 | } |
| 706 | } |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Adrian Roos | 91ba307 | 2017-02-14 16:50:46 +0100 | [diff] [blame] | 709 | public boolean isScreenOn() { |
| 710 | return mScreenOn; |
| 711 | } |
| 712 | |
Lucas Dupin | ef88654 | 2018-01-03 16:03:07 -0800 | [diff] [blame] | 713 | private void dispatchErrorMessage(CharSequence message) { |
| 714 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 715 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 716 | if (cb != null) { |
| 717 | cb.onTrustAgentErrorMessage(message); |
| 718 | } |
| 719 | } |
| 720 | } |
| 721 | |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 722 | static class DisplayClientState { |
| 723 | public int clientGeneration; |
| 724 | public boolean clearing; |
| 725 | public PendingIntent intent; |
| 726 | public int playbackState; |
| 727 | public long playbackEventTime; |
| 728 | } |
| 729 | |
| 730 | private DisplayClientState mDisplayClientState = new DisplayClientState(); |
| 731 | |
Lucas Dupin | 5e0f0d2 | 2018-02-26 13:32:16 -0800 | [diff] [blame] | 732 | @VisibleForTesting |
| 733 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 734 | |
Jim Miller | d72d5ac | 2015-09-29 18:55:32 -0700 | [diff] [blame] | 735 | @Override |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 736 | public void onReceive(Context context, Intent intent) { |
| 737 | final String action = intent.getAction(); |
| 738 | if (DEBUG) Log.d(TAG, "received broadcast " + action); |
| 739 | |
| 740 | if (Intent.ACTION_TIME_TICK.equals(action) |
| 741 | || Intent.ACTION_TIME_CHANGED.equals(action) |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 742 | || Intent.ACTION_TIMEZONE_CHANGED.equals(action)) { |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 743 | mHandler.sendEmptyMessage(MSG_TIME_UPDATE); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 744 | } else if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { |
| 745 | final int status = intent.getIntExtra(EXTRA_STATUS, BATTERY_STATUS_UNKNOWN); |
| 746 | final int plugged = intent.getIntExtra(EXTRA_PLUGGED, 0); |
| 747 | final int level = intent.getIntExtra(EXTRA_LEVEL, 0); |
| 748 | final int health = intent.getIntExtra(EXTRA_HEALTH, BATTERY_HEALTH_UNKNOWN); |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 749 | |
| 750 | final int maxChargingMicroAmp = intent.getIntExtra(EXTRA_MAX_CHARGING_CURRENT, -1); |
| 751 | int maxChargingMicroVolt = intent.getIntExtra(EXTRA_MAX_CHARGING_VOLTAGE, -1); |
| 752 | final int maxChargingMicroWatt; |
| 753 | |
| 754 | if (maxChargingMicroVolt <= 0) { |
| 755 | maxChargingMicroVolt = DEFAULT_CHARGING_VOLTAGE_MICRO_VOLT; |
| 756 | } |
| 757 | if (maxChargingMicroAmp > 0) { |
| 758 | // Calculating muW = muA * muV / (10^6 mu^2 / mu); splitting up the divisor |
| 759 | // to maintain precision equally on both factors. |
| 760 | maxChargingMicroWatt = (maxChargingMicroAmp / 1000) |
| 761 | * (maxChargingMicroVolt / 1000); |
| 762 | } else { |
| 763 | maxChargingMicroWatt = -1; |
| 764 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 765 | final Message msg = mHandler.obtainMessage( |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 766 | MSG_BATTERY_UPDATE, new BatteryStatus(status, level, plugged, health, |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 767 | maxChargingMicroWatt)); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 768 | mHandler.sendMessage(msg); |
| 769 | } else if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)) { |
Lucas Dupin | 5e0f0d2 | 2018-02-26 13:32:16 -0800 | [diff] [blame] | 770 | // ACTION_SIM_STATE_CHANGED is rebroadcast after unlocking the device to |
| 771 | // keep compatibility with apps that aren't direct boot aware. |
| 772 | // SysUI should just ignore this broadcast because it was already received |
| 773 | // and processed previously. |
| 774 | if (intent.getBooleanExtra(TelephonyIntents.EXTRA_REBROADCAST_ON_UNLOCK, false)) { |
| 775 | return; |
| 776 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 777 | SimData args = SimData.fromIntent(intent); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 778 | if (DEBUG_SIM_STATES) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 779 | Log.v(TAG, "action " + action |
| 780 | + " state: " + intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE) |
| 781 | + " slotId: " + args.slotId + " subid: " + args.subId); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 782 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 783 | mHandler.obtainMessage(MSG_SIM_STATE_CHANGE, args.subId, args.slotId, args.simState) |
| 784 | .sendToTarget(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 785 | } else if (AudioManager.RINGER_MODE_CHANGED_ACTION.equals(action)) { |
| 786 | mHandler.sendMessage(mHandler.obtainMessage(MSG_RINGER_MODE_CHANGED, |
| 787 | intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1), 0)); |
| 788 | } else if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(action)) { |
| 789 | String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); |
| 790 | mHandler.sendMessage(mHandler.obtainMessage(MSG_PHONE_STATE_CHANGED, state)); |
Jason Monk | 052082c | 2015-06-11 11:35:23 -0400 | [diff] [blame] | 791 | } else if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(action)) { |
| 792 | mHandler.sendEmptyMessage(MSG_AIRPLANE_MODE_CHANGED); |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 793 | } else if (Intent.ACTION_BOOT_COMPLETED.equals(action)) { |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 794 | dispatchBootCompleted(); |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 795 | } else if (TelephonyIntents.ACTION_SERVICE_STATE_CHANGED.equals(action)) { |
| 796 | ServiceState serviceState = ServiceState.newFromBundle(intent.getExtras()); |
| 797 | int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, |
| 798 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
| 799 | if (DEBUG) { |
| 800 | Log.v(TAG, "action " + action + " serviceState=" + serviceState + " subId=" |
| 801 | + subId); |
| 802 | } |
| 803 | mHandler.sendMessage( |
| 804 | mHandler.obtainMessage(MSG_SERVICE_STATE_CHANGE, subId, 0, serviceState)); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 805 | } else if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED.equals( |
| 806 | action)) { |
| 807 | mHandler.sendEmptyMessage(MSG_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 808 | } |
| 809 | } |
| 810 | }; |
Jim Miller | 2de5ee8 | 2012-06-14 22:22:50 -0700 | [diff] [blame] | 811 | |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 812 | private final BroadcastReceiver mBroadcastAllReceiver = new BroadcastReceiver() { |
| 813 | |
Jim Miller | d72d5ac | 2015-09-29 18:55:32 -0700 | [diff] [blame] | 814 | @Override |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 815 | public void onReceive(Context context, Intent intent) { |
| 816 | final String action = intent.getAction(); |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 817 | if (AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED.equals(action)) { |
| 818 | mHandler.sendEmptyMessage(MSG_TIME_UPDATE); |
| 819 | } else if (Intent.ACTION_USER_INFO_CHANGED.equals(action)) { |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 820 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_INFO_CHANGED, |
| 821 | intent.getIntExtra(Intent.EXTRA_USER_HANDLE, getSendingUserId()), 0)); |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 822 | } else if (ACTION_FACE_UNLOCK_STARTED.equals(action)) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 823 | Trace.beginSection("KeyguardUpdateMonitor.mBroadcastAllReceiver#onReceive ACTION_FACE_UNLOCK_STARTED"); |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 824 | mHandler.sendMessage(mHandler.obtainMessage(MSG_FACE_UNLOCK_STATE_CHANGED, 1, |
| 825 | getSendingUserId())); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 826 | Trace.endSection(); |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 827 | } else if (ACTION_FACE_UNLOCK_STOPPED.equals(action)) { |
| 828 | mHandler.sendMessage(mHandler.obtainMessage(MSG_FACE_UNLOCK_STATE_CHANGED, 0, |
| 829 | getSendingUserId())); |
| 830 | } else if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 831 | .equals(action)) { |
| 832 | mHandler.sendEmptyMessage(MSG_DPM_STATE_CHANGED); |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 833 | } else if (ACTION_USER_UNLOCKED.equals(action)) { |
| 834 | mHandler.sendEmptyMessage(MSG_USER_UNLOCKED); |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 835 | } |
| 836 | } |
| 837 | }; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 838 | |
Jorim Jaggi | 3a46478 | 2015-08-28 16:59:13 -0700 | [diff] [blame] | 839 | private final FingerprintManager.LockoutResetCallback mLockoutResetCallback |
| 840 | = new FingerprintManager.LockoutResetCallback() { |
| 841 | @Override |
| 842 | public void onLockoutReset() { |
| 843 | handleFingerprintLockoutReset(); |
| 844 | } |
| 845 | }; |
| 846 | |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 847 | private FingerprintManager.AuthenticationCallback mAuthenticationCallback |
| 848 | = new AuthenticationCallback() { |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 849 | |
| 850 | @Override |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 851 | public void onAuthenticationFailed() { |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 852 | handleFingerprintAuthFailed(); |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 853 | }; |
| 854 | |
| 855 | @Override |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 856 | public void onAuthenticationSucceeded(AuthenticationResult result) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 857 | Trace.beginSection("KeyguardUpdateMonitor#onAuthenticationSucceeded"); |
Jim Miller | 837fa7e | 2016-08-08 20:16:22 -0700 | [diff] [blame] | 858 | handleFingerprintAuthenticated(result.getUserId()); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 859 | Trace.endSection(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | @Override |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 863 | public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) { |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 864 | handleFingerprintHelp(helpMsgId, helpString.toString()); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | @Override |
| 868 | public void onAuthenticationError(int errMsgId, CharSequence errString) { |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 869 | handleFingerprintError(errMsgId, errString.toString()); |
| 870 | } |
| 871 | |
| 872 | @Override |
| 873 | public void onAuthenticationAcquired(int acquireInfo) { |
| 874 | handleFingerprintAcquired(acquireInfo); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 875 | } |
| 876 | }; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 877 | private CancellationSignal mFingerprintCancelSignal; |
| 878 | private FingerprintManager mFpm; |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 879 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 880 | /** |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 881 | * When we receive a |
| 882 | * {@link com.android.internal.telephony.TelephonyIntents#ACTION_SIM_STATE_CHANGED} broadcast, |
Wink Saville | 37c124c | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 883 | * 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] | 884 | * 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] | 885 | * the intent and provide a {@link SimCard.State} result. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 886 | */ |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 887 | private static class SimData { |
| 888 | public State simState; |
| 889 | public int slotId; |
| 890 | public int subId; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 891 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 892 | SimData(State state, int slot, int id) { |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 893 | simState = state; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 894 | slotId = slot; |
| 895 | subId = id; |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 896 | } |
| 897 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 898 | static SimData fromIntent(Intent intent) { |
| 899 | State state; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 900 | if (!TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(intent.getAction())) { |
| 901 | throw new IllegalArgumentException("only handles intent ACTION_SIM_STATE_CHANGED"); |
| 902 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 903 | String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 904 | int slotId = intent.getIntExtra(PhoneConstants.SLOT_KEY, 0); |
| 905 | int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 906 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 907 | if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) { |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 908 | final String absentReason = intent |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 909 | .getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON); |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 910 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 911 | if (IccCardConstants.INTENT_VALUE_ABSENT_ON_PERM_DISABLED.equals( |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 912 | absentReason)) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 913 | state = IccCardConstants.State.PERM_DISABLED; |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 914 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 915 | state = IccCardConstants.State.ABSENT; |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 916 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 917 | } else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) { |
| 918 | state = IccCardConstants.State.READY; |
| 919 | } else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 920 | final String lockedReason = intent |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 921 | .getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON); |
| 922 | if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) { |
| 923 | state = IccCardConstants.State.PIN_REQUIRED; |
| 924 | } else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) { |
| 925 | state = IccCardConstants.State.PUK_REQUIRED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 926 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 927 | state = IccCardConstants.State.UNKNOWN; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 928 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 929 | } else if (IccCardConstants.INTENT_VALUE_LOCKED_NETWORK.equals(stateExtra)) { |
| 930 | state = IccCardConstants.State.NETWORK_LOCKED; |
Wileen Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 931 | } else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) { |
| 932 | state = IccCardConstants.State.CARD_IO_ERROR; |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 933 | } else if (IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(stateExtra) |
| 934 | || IccCardConstants.INTENT_VALUE_ICC_IMSI.equals(stateExtra)) { |
| 935 | // This is required because telephony doesn't return to "READY" after |
| 936 | // these state transitions. See bug 7197471. |
| 937 | state = IccCardConstants.State.READY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 938 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 939 | state = IccCardConstants.State.UNKNOWN; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 940 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 941 | return new SimData(state, slotId, subId); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 942 | } |
| 943 | |
Jim Miller | d72d5ac | 2015-09-29 18:55:32 -0700 | [diff] [blame] | 944 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 945 | public String toString() { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 946 | return "SimData{state=" + simState + ",slotId=" + slotId + ",subId=" + subId + "}"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 947 | } |
| 948 | } |
| 949 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 950 | public static class BatteryStatus { |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 951 | public static final int CHARGING_UNKNOWN = -1; |
| 952 | public static final int CHARGING_SLOWLY = 0; |
| 953 | public static final int CHARGING_REGULAR = 1; |
| 954 | public static final int CHARGING_FAST = 2; |
| 955 | |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 956 | public final int status; |
| 957 | public final int level; |
| 958 | public final int plugged; |
| 959 | public final int health; |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 960 | public final int maxChargingWattage; |
| 961 | public BatteryStatus(int status, int level, int plugged, int health, |
| 962 | int maxChargingWattage) { |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 963 | this.status = status; |
| 964 | this.level = level; |
| 965 | this.plugged = plugged; |
| 966 | this.health = health; |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 967 | this.maxChargingWattage = maxChargingWattage; |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 968 | } |
| 969 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 970 | /** |
Brian Muramatsu | a92a01b | 2012-09-05 21:54:39 -0700 | [diff] [blame] | 971 | * Determine whether the device is plugged in (USB, power, or wireless). |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 972 | * @return true if the device is plugged in. |
| 973 | */ |
Adrian Roos | ad3bc7f | 2014-10-30 18:29:38 +0100 | [diff] [blame] | 974 | public boolean isPluggedIn() { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 975 | return plugged == BatteryManager.BATTERY_PLUGGED_AC |
Brian Muramatsu | a92a01b | 2012-09-05 21:54:39 -0700 | [diff] [blame] | 976 | || plugged == BatteryManager.BATTERY_PLUGGED_USB |
| 977 | || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | /** |
Beverly | 2034c83 | 2018-03-19 11:18:51 -0400 | [diff] [blame] | 981 | * Determine whether the device is plugged in (USB, power). |
| 982 | * @return true if the device is plugged in wired (as opposed to wireless) |
| 983 | */ |
| 984 | public boolean isPluggedInWired() { |
| 985 | return plugged == BatteryManager.BATTERY_PLUGGED_AC |
| 986 | || plugged == BatteryManager.BATTERY_PLUGGED_USB; |
| 987 | } |
| 988 | |
| 989 | /** |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 990 | * Whether or not the device is charged. Note that some devices never return 100% for |
| 991 | * battery level, so this allows either battery level or status to determine if the |
| 992 | * battery is charged. |
| 993 | * @return true if the device is charged |
| 994 | */ |
| 995 | public boolean isCharged() { |
| 996 | return status == BATTERY_STATUS_FULL || level >= 100; |
| 997 | } |
| 998 | |
| 999 | /** |
| 1000 | * Whether battery is low and needs to be charged. |
| 1001 | * @return true if battery is low |
| 1002 | */ |
| 1003 | public boolean isBatteryLow() { |
| 1004 | return level < LOW_BATTERY_THRESHOLD; |
| 1005 | } |
| 1006 | |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 1007 | public final int getChargingSpeed(int slowThreshold, int fastThreshold) { |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 1008 | return maxChargingWattage <= 0 ? CHARGING_UNKNOWN : |
| 1009 | maxChargingWattage < slowThreshold ? CHARGING_SLOWLY : |
| 1010 | maxChargingWattage > fastThreshold ? CHARGING_FAST : |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 1011 | CHARGING_REGULAR; |
| 1012 | } |
Lucas Dupin | 3fcdd47 | 2018-01-19 19:06:45 -0800 | [diff] [blame] | 1013 | |
| 1014 | @Override |
| 1015 | public String toString() { |
| 1016 | return "BatteryStatus{status=" + status + ",level=" + level + ",plugged=" + plugged |
| 1017 | + ",health=" + health + ",maxChargingWattage=" + maxChargingWattage + "}"; |
| 1018 | } |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1019 | } |
| 1020 | |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 1021 | public class StrongAuthTracker extends LockPatternUtils.StrongAuthTracker { |
Rakesh Iyer | a7aa4d6 | 2016-01-19 17:27:23 -0800 | [diff] [blame] | 1022 | public StrongAuthTracker(Context context) { |
| 1023 | super(context); |
| 1024 | } |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 1025 | |
| 1026 | public boolean isUnlockingWithFingerprintAllowed() { |
| 1027 | int userId = getCurrentUser(); |
| 1028 | return isFingerprintAllowedForUser(userId); |
| 1029 | } |
| 1030 | |
| 1031 | public boolean hasUserAuthenticatedSinceBoot() { |
| 1032 | int userId = getCurrentUser(); |
| 1033 | return (getStrongAuthForUser(userId) |
| 1034 | & STRONG_AUTH_REQUIRED_AFTER_BOOT) == 0; |
| 1035 | } |
| 1036 | |
| 1037 | @Override |
| 1038 | public void onStrongAuthRequiredChanged(int userId) { |
Adrian Roos | 1de8bcb | 2015-08-19 16:52:52 -0700 | [diff] [blame] | 1039 | notifyStrongAuthStateChanged(userId); |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 1040 | } |
| 1041 | } |
| 1042 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1043 | public static KeyguardUpdateMonitor getInstance(Context context) { |
| 1044 | if (sInstance == null) { |
| 1045 | sInstance = new KeyguardUpdateMonitor(context); |
| 1046 | } |
| 1047 | return sInstance; |
| 1048 | } |
| 1049 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1050 | protected void handleStartedWakingUp() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1051 | Trace.beginSection("KeyguardUpdateMonitor#handleStartedWakingUp"); |
Jorim Jaggi | 864e64b | 2015-05-20 14:13:23 -0700 | [diff] [blame] | 1052 | updateFingerprintListeningState(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1053 | final int count = mCallbacks.size(); |
| 1054 | for (int i = 0; i < count; i++) { |
| 1055 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1056 | if (cb != null) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1057 | cb.onStartedWakingUp(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1058 | } |
| 1059 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1060 | Trace.endSection(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 1063 | protected void handleStartedGoingToSleep(int arg1) { |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 1064 | clearFingerprintRecognized(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1065 | final int count = mCallbacks.size(); |
| 1066 | for (int i = 0; i < count; i++) { |
| 1067 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1068 | if (cb != null) { |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 1069 | cb.onStartedGoingToSleep(arg1); |
| 1070 | } |
| 1071 | } |
| 1072 | mGoingToSleep = true; |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 1073 | updateFingerprintListeningState(); |
| 1074 | } |
| 1075 | |
| 1076 | protected void handleFinishedGoingToSleep(int arg1) { |
| 1077 | mGoingToSleep = false; |
| 1078 | final int count = mCallbacks.size(); |
| 1079 | for (int i = 0; i < count; i++) { |
| 1080 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1081 | if (cb != null) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1082 | cb.onFinishedGoingToSleep(arg1); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1083 | } |
| 1084 | } |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1085 | updateFingerprintListeningState(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1086 | } |
| 1087 | |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 1088 | private void handleScreenTurnedOn() { |
| 1089 | final int count = mCallbacks.size(); |
| 1090 | for (int i = 0; i < count; i++) { |
| 1091 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1092 | if (cb != null) { |
| 1093 | cb.onScreenTurnedOn(); |
| 1094 | } |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | private void handleScreenTurnedOff() { |
Kevin Chyn | 0c45b07 | 2017-04-24 16:27:11 -0700 | [diff] [blame] | 1099 | mHardwareUnavailableRetryCount = 0; |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 1100 | final int count = mCallbacks.size(); |
| 1101 | for (int i = 0; i < count; i++) { |
| 1102 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1103 | if (cb != null) { |
| 1104 | cb.onScreenTurnedOff(); |
| 1105 | } |
| 1106 | } |
| 1107 | } |
| 1108 | |
Selim Cinek | 9941539 | 2016-09-09 14:58:41 -0700 | [diff] [blame] | 1109 | private void handleDreamingStateChanged(int dreamStart) { |
| 1110 | final int count = mCallbacks.size(); |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 1111 | mIsDreaming = dreamStart == 1; |
Selim Cinek | 9941539 | 2016-09-09 14:58:41 -0700 | [diff] [blame] | 1112 | for (int i = 0; i < count; i++) { |
| 1113 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1114 | if (cb != null) { |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 1115 | cb.onDreamingStateChanged(mIsDreaming); |
Selim Cinek | 9941539 | 2016-09-09 14:58:41 -0700 | [diff] [blame] | 1116 | } |
| 1117 | } |
Kevin Chyn | 20a68dc | 2017-09-21 11:41:01 -0700 | [diff] [blame] | 1118 | updateFingerprintListeningState(); |
Selim Cinek | 9941539 | 2016-09-09 14:58:41 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
Adam Powell | 43a372f | 2013-09-27 17:43:53 -0700 | [diff] [blame] | 1121 | /** |
| 1122 | * IMPORTANT: Must be called from UI thread. |
| 1123 | */ |
| 1124 | public void dispatchSetBackground(Bitmap bmp) { |
| 1125 | if (DEBUG) Log.d(TAG, "dispatchSetBackground"); |
| 1126 | final int count = mCallbacks.size(); |
| 1127 | for (int i = 0; i < count; i++) { |
| 1128 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1129 | if (cb != null) { |
| 1130 | cb.onSetBackground(bmp); |
| 1131 | } |
| 1132 | } |
| 1133 | } |
| 1134 | |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 1135 | private void handleUserInfoChanged(int userId) { |
| 1136 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1137 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1138 | if (cb != null) { |
| 1139 | cb.onUserInfoChanged(userId); |
| 1140 | } |
| 1141 | } |
| 1142 | } |
| 1143 | |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 1144 | private void handleUserUnlocked() { |
| 1145 | mNeedsSlowUnlockTransition = resolveNeedsSlowUnlockTransition(); |
| 1146 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1147 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1148 | if (cb != null) { |
| 1149 | cb.onUserUnlocked(); |
| 1150 | } |
| 1151 | } |
| 1152 | } |
| 1153 | |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 1154 | @VisibleForTesting |
| 1155 | protected KeyguardUpdateMonitor(Context context) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1156 | mContext = context; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1157 | mSubscriptionManager = SubscriptionManager.from(context); |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 1158 | mDeviceProvisioned = isDeviceProvisionedInSettingsDb(); |
Rakesh Iyer | a7aa4d6 | 2016-01-19 17:27:23 -0800 | [diff] [blame] | 1159 | mStrongAuthTracker = new StrongAuthTracker(context); |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 1160 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1161 | // Since device can't be un-provisioned, we only need to register a content observer |
| 1162 | // to update mDeviceProvisioned when we are... |
| 1163 | if (!mDeviceProvisioned) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1164 | watchForDeviceProvisioning(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1165 | } |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 1166 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1167 | // 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] | 1168 | 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] | 1169 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1170 | // Watch for interesting updates |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1171 | final IntentFilter filter = new IntentFilter(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1172 | filter.addAction(Intent.ACTION_TIME_TICK); |
| 1173 | filter.addAction(Intent.ACTION_TIME_CHANGED); |
| 1174 | filter.addAction(Intent.ACTION_BATTERY_CHANGED); |
| 1175 | filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); |
Jason Monk | 052082c | 2015-06-11 11:35:23 -0400 | [diff] [blame] | 1176 | filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1177 | filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 1178 | filter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 1179 | filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 1180 | filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 1181 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1182 | context.registerReceiver(mBroadcastReceiver, filter); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1183 | |
Adam Cohen | c276e82 | 2012-11-08 13:01:08 -0800 | [diff] [blame] | 1184 | final IntentFilter bootCompleteFilter = new IntentFilter(); |
| 1185 | bootCompleteFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); |
| 1186 | bootCompleteFilter.addAction(Intent.ACTION_BOOT_COMPLETED); |
| 1187 | context.registerReceiver(mBroadcastReceiver, bootCompleteFilter); |
| 1188 | |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 1189 | final IntentFilter allUserFilter = new IntentFilter(); |
| 1190 | allUserFilter.addAction(Intent.ACTION_USER_INFO_CHANGED); |
| 1191 | allUserFilter.addAction(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED); |
| 1192 | allUserFilter.addAction(ACTION_FACE_UNLOCK_STARTED); |
| 1193 | allUserFilter.addAction(ACTION_FACE_UNLOCK_STOPPED); |
| 1194 | allUserFilter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 1195 | allUserFilter.addAction(ACTION_USER_UNLOCKED); |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 1196 | context.registerReceiverAsUser(mBroadcastAllReceiver, UserHandle.ALL, allUserFilter, |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 1197 | null, null); |
| 1198 | |
Wink Saville | 071743f | 2015-01-12 17:11:04 -0800 | [diff] [blame] | 1199 | mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionListener); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1200 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1201 | ActivityManager.getService().registerUserSwitchObserver( |
Sudheer Shanka | 2c4522c | 2016-08-27 20:53:28 -0700 | [diff] [blame] | 1202 | new UserSwitchObserver() { |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1203 | @Override |
| 1204 | public void onUserSwitching(int newUserId, IRemoteCallback reply) { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 1205 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHING, |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1206 | newUserId, 0, reply)); |
| 1207 | } |
| 1208 | @Override |
| 1209 | public void onUserSwitchComplete(int newUserId) throws RemoteException { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 1210 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCH_COMPLETE, |
Adrian Roos | be47b07 | 2014-09-03 00:08:56 +0200 | [diff] [blame] | 1211 | newUserId, 0)); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1212 | } |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 1213 | }, TAG); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1214 | } catch (RemoteException e) { |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 1215 | e.rethrowAsRuntimeException(); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1216 | } |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 1217 | |
Jorim Jaggi | 237b061 | 2015-05-01 14:28:49 -0700 | [diff] [blame] | 1218 | mTrustManager = (TrustManager) context.getSystemService(Context.TRUST_SERVICE); |
| 1219 | mTrustManager.registerTrustListener(this); |
Michal Karpinski | c52f867 | 2016-11-18 11:32:45 +0000 | [diff] [blame] | 1220 | mLockPatternUtils = new LockPatternUtils(context); |
| 1221 | mLockPatternUtils.registerStrongAuthTracker(mStrongAuthTracker); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 1222 | |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 1223 | mDreamManager = IDreamManager.Stub.asInterface( |
| 1224 | ServiceManager.getService(DreamService.DREAM_SERVICE)); |
| 1225 | |
Jorim Jaggi | 3f12426 | 2016-11-22 13:45:17 +0100 | [diff] [blame] | 1226 | if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) { |
| 1227 | mFpm = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE); |
| 1228 | } |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1229 | updateFingerprintListeningState(); |
Jorim Jaggi | 3a46478 | 2015-08-28 16:59:13 -0700 | [diff] [blame] | 1230 | if (mFpm != null) { |
| 1231 | mFpm.addLockoutResetCallback(mLockoutResetCallback); |
| 1232 | } |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 1233 | |
Winson Chung | 2cf6ad8 | 2017-11-09 17:36:59 -0800 | [diff] [blame] | 1234 | ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener); |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 1235 | mUserManager = context.getSystemService(UserManager.class); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 1236 | mDevicePolicyManager = context.getSystemService(DevicePolicyManager.class); |
| 1237 | mLogoutEnabled = mDevicePolicyManager.isLogoutEnabled(); |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | private void updateFingerprintListeningState() { |
Kevin Chyn | 0f3e0b1 | 2017-07-20 16:56:11 -0700 | [diff] [blame] | 1241 | // If this message exists, we should not authenticate again until this message is |
| 1242 | // consumed by the handler |
| 1243 | if (mHandler.hasMessages(MSG_FINGERPRINT_AUTHENTICATION_CONTINUE)) { |
| 1244 | return; |
| 1245 | } |
Kevin Chyn | 0c45b07 | 2017-04-24 16:27:11 -0700 | [diff] [blame] | 1246 | mHandler.removeCallbacks(mRetryFingerprintAuthentication); |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1247 | boolean shouldListenForFingerprint = shouldListenForFingerprint(); |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 1248 | if (mFingerprintRunningState == FINGERPRINT_STATE_RUNNING && !shouldListenForFingerprint) { |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1249 | stopListeningForFingerprint(); |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 1250 | } else if (mFingerprintRunningState != FINGERPRINT_STATE_RUNNING |
| 1251 | && shouldListenForFingerprint) { |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1252 | startListeningForFingerprint(); |
| 1253 | } |
| 1254 | } |
| 1255 | |
Kevin Chyn | 129f60f | 2017-08-11 17:24:42 -0700 | [diff] [blame] | 1256 | private boolean shouldListenForFingerprintAssistant() { |
| 1257 | return mAssistantVisible && mKeyguardOccluded |
| 1258 | && !mUserFingerprintAuthenticated.get(getCurrentUser(), false) |
| 1259 | && !mUserHasTrust.get(getCurrentUser(), false); |
| 1260 | } |
| 1261 | |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1262 | private boolean shouldListenForFingerprint() { |
Kevin Chyn | f3b8fbd | 2017-05-03 22:24:31 -0700 | [diff] [blame] | 1263 | return (mKeyguardIsVisible || !mDeviceInteractive || |
Kevin Chyn | 0f3e0b1 | 2017-07-20 16:56:11 -0700 | [diff] [blame] | 1264 | (mBouncer && !mKeyguardGoingAway) || mGoingToSleep || |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 1265 | shouldListenForFingerprintAssistant() || (mKeyguardOccluded && mIsDreaming)) |
Kevin Chyn | 0f3e0b1 | 2017-07-20 16:56:11 -0700 | [diff] [blame] | 1266 | && !mSwitchingUser && !isFingerprintDisabled(getCurrentUser()) |
| 1267 | && !mKeyguardGoingAway; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 1270 | private void startListeningForFingerprint() { |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 1271 | if (mFingerprintRunningState == FINGERPRINT_STATE_CANCELLING) { |
| 1272 | setFingerprintRunningState(FINGERPRINT_STATE_CANCELLING_RESTARTING); |
| 1273 | return; |
| 1274 | } |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 1275 | if (DEBUG) Log.v(TAG, "startListeningForFingerprint()"); |
Jorim Jaggi | 2aad7ee | 2015-04-14 15:25:06 -0700 | [diff] [blame] | 1276 | int userId = ActivityManager.getCurrentUser(); |
Jorim Jaggi | 71448a7 | 2015-08-18 19:49:04 -0700 | [diff] [blame] | 1277 | if (isUnlockWithFingerprintPossible(userId)) { |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 1278 | if (mFingerprintCancelSignal != null) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1279 | mFingerprintCancelSignal.cancel(); |
| 1280 | } |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 1281 | mFingerprintCancelSignal = new CancellationSignal(); |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 1282 | mFpm.authenticate(null, mFingerprintCancelSignal, 0, mAuthenticationCallback, null, |
| 1283 | userId); |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 1284 | setFingerprintRunningState(FINGERPRINT_STATE_RUNNING); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1285 | } |
| 1286 | } |
| 1287 | |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 1288 | public boolean isUnlockWithFingerprintPossible(int userId) { |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 1289 | return mFpm != null && mFpm.isHardwareDetected() && !isFingerprintDisabled(userId) |
| 1290 | && mFpm.getEnrolledFingerprints(userId).size() > 0; |
| 1291 | } |
| 1292 | |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1293 | private void stopListeningForFingerprint() { |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 1294 | if (DEBUG) Log.v(TAG, "stopListeningForFingerprint()"); |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 1295 | if (mFingerprintRunningState == FINGERPRINT_STATE_RUNNING) { |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 1296 | if (mFingerprintCancelSignal != null) { |
| 1297 | mFingerprintCancelSignal.cancel(); |
| 1298 | mFingerprintCancelSignal = null; |
| 1299 | } |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 1300 | setFingerprintRunningState(FINGERPRINT_STATE_CANCELLING); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1301 | } |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 1302 | if (mFingerprintRunningState == FINGERPRINT_STATE_CANCELLING_RESTARTING) { |
| 1303 | setFingerprintRunningState(FINGERPRINT_STATE_CANCELLING); |
| 1304 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1305 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1306 | |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 1307 | private boolean isDeviceProvisionedInSettingsDb() { |
| 1308 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 1309 | Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
| 1310 | } |
| 1311 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1312 | private void watchForDeviceProvisioning() { |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 1313 | mDeviceProvisionedObserver = new ContentObserver(mHandler) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1314 | @Override |
| 1315 | public void onChange(boolean selfChange) { |
| 1316 | super.onChange(selfChange); |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 1317 | mDeviceProvisioned = isDeviceProvisionedInSettingsDb(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1318 | if (mDeviceProvisioned) { |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 1319 | mHandler.sendEmptyMessage(MSG_DEVICE_PROVISIONED); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1320 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1321 | if (DEBUG) Log.d(TAG, "DEVICE_PROVISIONED state = " + mDeviceProvisioned); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1322 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1323 | }; |
| 1324 | |
| 1325 | mContext.getContentResolver().registerContentObserver( |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 1326 | Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 1327 | false, mDeviceProvisionedObserver); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1328 | |
| 1329 | // prevent a race condition between where we check the flag and where we register the |
| 1330 | // observer by grabbing the value once again... |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 1331 | boolean provisioned = isDeviceProvisionedInSettingsDb(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1332 | if (provisioned != mDeviceProvisioned) { |
| 1333 | mDeviceProvisioned = provisioned; |
| 1334 | if (mDeviceProvisioned) { |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 1335 | mHandler.sendEmptyMessage(MSG_DEVICE_PROVISIONED); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1336 | } |
| 1337 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1338 | } |
| 1339 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1340 | /** |
Jorim Jaggi | d11d1a9 | 2016-08-16 16:02:32 -0700 | [diff] [blame] | 1341 | * Update the state whether Keyguard currently has a lockscreen wallpaper. |
| 1342 | * |
| 1343 | * @param hasLockscreenWallpaper Whether Keyguard has a lockscreen wallpaper. |
| 1344 | */ |
| 1345 | public void setHasLockscreenWallpaper(boolean hasLockscreenWallpaper) { |
| 1346 | if (hasLockscreenWallpaper != mHasLockscreenWallpaper) { |
| 1347 | mHasLockscreenWallpaper = hasLockscreenWallpaper; |
| 1348 | for (int i = mCallbacks.size() - 1; i >= 0; i--) { |
| 1349 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1350 | if (cb != null) { |
| 1351 | cb.onHasLockscreenWallpaperChanged(hasLockscreenWallpaper); |
| 1352 | } |
| 1353 | } |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | /** |
| 1358 | * @return Whether Keyguard has a lockscreen wallpaper. |
| 1359 | */ |
| 1360 | public boolean hasLockscreenWallpaper() { |
| 1361 | return mHasLockscreenWallpaper; |
| 1362 | } |
| 1363 | |
| 1364 | /** |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1365 | * Handle {@link #MSG_DPM_STATE_CHANGED} |
| 1366 | */ |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 1367 | protected void handleDevicePolicyManagerStateChanged() { |
Adrian Roos | 733b663 | 2015-08-21 14:32:35 -0700 | [diff] [blame] | 1368 | updateFingerprintListeningState(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1369 | for (int i = mCallbacks.size() - 1; i >= 0; i--) { |
| 1370 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1371 | if (cb != null) { |
| 1372 | cb.onDevicePolicyManagerStateChanged(); |
| 1373 | } |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 1374 | } |
| 1375 | } |
| 1376 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1377 | /** |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 1378 | * Handle {@link #MSG_USER_SWITCHING} |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1379 | */ |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 1380 | protected void handleUserSwitching(int userId, IRemoteCallback reply) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1381 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1382 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1383 | if (cb != null) { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 1384 | cb.onUserSwitching(userId); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1385 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 1386 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1387 | try { |
| 1388 | reply.sendResult(null); |
| 1389 | } catch (RemoteException e) { |
| 1390 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 1391 | } |
| 1392 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1393 | /** |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 1394 | * Handle {@link #MSG_USER_SWITCH_COMPLETE} |
| 1395 | */ |
| 1396 | protected void handleUserSwitchComplete(int userId) { |
| 1397 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1398 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1399 | if (cb != null) { |
| 1400 | cb.onUserSwitchComplete(userId); |
| 1401 | } |
| 1402 | } |
| 1403 | } |
| 1404 | |
| 1405 | /** |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 1406 | * This is exposed since {@link Intent#ACTION_BOOT_COMPLETED} is not sticky. If |
| 1407 | * keyguard crashes sometime after boot, then it will never receive this |
| 1408 | * broadcast and hence not handle the event. This method is ultimately called by |
| 1409 | * PhoneWindowManager in this case. |
| 1410 | */ |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1411 | public void dispatchBootCompleted() { |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 1412 | mHandler.sendEmptyMessage(MSG_BOOT_COMPLETED); |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | /** |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 1416 | * Handle {@link #MSG_BOOT_COMPLETED} |
| 1417 | */ |
| 1418 | protected void handleBootCompleted() { |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 1419 | if (mBootCompleted) return; |
Adam Cohen | 4eb36cf | 2012-11-07 11:45:30 -0800 | [diff] [blame] | 1420 | mBootCompleted = true; |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 1421 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1422 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1423 | if (cb != null) { |
| 1424 | cb.onBootCompleted(); |
| 1425 | } |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | /** |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1430 | * 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] | 1431 | * destroyed. |
| 1432 | */ |
| 1433 | public boolean hasBootCompleted() { |
| 1434 | return mBootCompleted; |
| 1435 | } |
| 1436 | |
| 1437 | /** |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1438 | * Handle {@link #MSG_DEVICE_PROVISIONED} |
| 1439 | */ |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 1440 | protected void handleDeviceProvisioned() { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1441 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1442 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1443 | if (cb != null) { |
| 1444 | cb.onDeviceProvisioned(); |
| 1445 | } |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 1446 | } |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 1447 | if (mDeviceProvisionedObserver != null) { |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 1448 | // We don't need the observer anymore... |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 1449 | mContext.getContentResolver().unregisterContentObserver(mDeviceProvisionedObserver); |
| 1450 | mDeviceProvisionedObserver = null; |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 1451 | } |
| 1452 | } |
| 1453 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1454 | /** |
| 1455 | * Handle {@link #MSG_PHONE_STATE_CHANGED} |
| 1456 | */ |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 1457 | protected void handlePhoneStateChanged(String newState) { |
| 1458 | if (DEBUG) Log.d(TAG, "handlePhoneStateChanged(" + newState + ")"); |
Jim Miller | 3f5f83b | 2011-09-26 15:17:05 -0700 | [diff] [blame] | 1459 | if (TelephonyManager.EXTRA_STATE_IDLE.equals(newState)) { |
| 1460 | mPhoneState = TelephonyManager.CALL_STATE_IDLE; |
| 1461 | } else if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(newState)) { |
| 1462 | mPhoneState = TelephonyManager.CALL_STATE_OFFHOOK; |
| 1463 | } else if (TelephonyManager.EXTRA_STATE_RINGING.equals(newState)) { |
| 1464 | mPhoneState = TelephonyManager.CALL_STATE_RINGING; |
| 1465 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1466 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1467 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1468 | if (cb != null) { |
| 1469 | cb.onPhoneStateChanged(mPhoneState); |
| 1470 | } |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 1471 | } |
| 1472 | } |
| 1473 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1474 | /** |
| 1475 | * Handle {@link #MSG_RINGER_MODE_CHANGED} |
| 1476 | */ |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 1477 | protected void handleRingerModeChange(int mode) { |
| 1478 | if (DEBUG) Log.d(TAG, "handleRingerModeChange(" + mode + ")"); |
Jim Miller | 3f5f83b | 2011-09-26 15:17:05 -0700 | [diff] [blame] | 1479 | mRingMode = mode; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1480 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1481 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1482 | if (cb != null) { |
| 1483 | cb.onRingerModeChanged(mode); |
| 1484 | } |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 1485 | } |
| 1486 | } |
| 1487 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1488 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1489 | * Handle {@link #MSG_TIME_UPDATE} |
| 1490 | */ |
| 1491 | private void handleTimeUpdate() { |
| 1492 | if (DEBUG) Log.d(TAG, "handleTimeUpdate"); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1493 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1494 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1495 | if (cb != null) { |
| 1496 | cb.onTimeChanged(); |
| 1497 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1498 | } |
| 1499 | } |
| 1500 | |
| 1501 | /** |
| 1502 | * Handle {@link #MSG_BATTERY_UPDATE} |
| 1503 | */ |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1504 | private void handleBatteryUpdate(BatteryStatus status) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1505 | if (DEBUG) Log.d(TAG, "handleBatteryUpdate"); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1506 | final boolean batteryUpdateInteresting = isBatteryUpdateInteresting(mBatteryStatus, status); |
| 1507 | mBatteryStatus = status; |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1508 | if (batteryUpdateInteresting) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1509 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1510 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1511 | if (cb != null) { |
| 1512 | cb.onRefreshBatteryInfo(status); |
| 1513 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1514 | } |
| 1515 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1519 | * Handle {@link #MSG_SIM_STATE_CHANGE} |
| 1520 | */ |
Lucas Dupin | 5e0f0d2 | 2018-02-26 13:32:16 -0800 | [diff] [blame] | 1521 | @VisibleForTesting |
| 1522 | protected void handleSimStateChange(int subId, int slotId, State state) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1523 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1524 | if (DEBUG_SIM_STATES) { |
| 1525 | Log.d(TAG, "handleSimStateChange(subId=" + subId + ", slotId=" |
| 1526 | + slotId + ", state=" + state +")"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1527 | } |
| 1528 | |
Wink Saville | a54bf65 | 2014-12-11 13:37:50 -0800 | [diff] [blame] | 1529 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1530 | Log.w(TAG, "invalid subId in handleSimStateChange()"); |
| 1531 | return; |
| 1532 | } |
| 1533 | |
| 1534 | SimData data = mSimDatas.get(subId); |
| 1535 | final boolean changed; |
| 1536 | if (data == null) { |
| 1537 | data = new SimData(state, slotId, subId); |
| 1538 | mSimDatas.put(subId, data); |
| 1539 | changed = true; // no data yet; force update |
| 1540 | } else { |
| 1541 | changed = (data.simState != state || data.subId != subId || data.slotId != slotId); |
| 1542 | data.simState = state; |
| 1543 | data.subId = subId; |
| 1544 | data.slotId = slotId; |
| 1545 | } |
| 1546 | if (changed && state != State.UNKNOWN) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1547 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1548 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1549 | if (cb != null) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1550 | cb.onSimStateChanged(subId, slotId, state); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1551 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1552 | } |
| 1553 | } |
| 1554 | } |
| 1555 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1556 | /** |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 1557 | * Handle {@link #MSG_SERVICE_STATE_CHANGE} |
| 1558 | */ |
| 1559 | private void handleServiceStateChange(int subId, ServiceState serviceState) { |
| 1560 | if (DEBUG) { |
| 1561 | Log.d(TAG, |
| 1562 | "handleServiceStateChange(subId=" + subId + ", serviceState=" + serviceState); |
| 1563 | } |
| 1564 | |
| 1565 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1566 | Log.w(TAG, "invalid subId in handleServiceStateChange()"); |
| 1567 | return; |
| 1568 | } |
| 1569 | |
| 1570 | mServiceStates.put(subId, serviceState); |
| 1571 | |
| 1572 | for (int j = 0; j < mCallbacks.size(); j++) { |
| 1573 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get(); |
| 1574 | if (cb != null) { |
| 1575 | cb.onRefreshCarrierInfo(); |
| 1576 | } |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | /** |
Jorim Jaggi | 6a15d52 | 2015-09-22 15:55:33 -0700 | [diff] [blame] | 1581 | * Notifies that the visibility state of Keyguard has changed. |
| 1582 | * |
| 1583 | * <p>Needs to be called from the main thread. |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 1584 | */ |
Jorim Jaggi | 6a15d52 | 2015-09-22 15:55:33 -0700 | [diff] [blame] | 1585 | public void onKeyguardVisibilityChanged(boolean showing) { |
| 1586 | if (DEBUG) Log.d(TAG, "onKeyguardVisibilityChanged(" + showing + ")"); |
| 1587 | mKeyguardIsVisible = showing; |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 1588 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1589 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1590 | if (cb != null) { |
Jorim Jaggi | 6a15d52 | 2015-09-22 15:55:33 -0700 | [diff] [blame] | 1591 | cb.onKeyguardVisibilityChangedRaw(showing); |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 1592 | } |
| 1593 | } |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1594 | updateFingerprintListeningState(); |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 1595 | } |
| 1596 | |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 1597 | /** |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 1598 | * Handle {@link #MSG_KEYGUARD_RESET} |
| 1599 | */ |
| 1600 | private void handleKeyguardReset() { |
| 1601 | if (DEBUG) Log.d(TAG, "handleKeyguardReset"); |
Adrian Roos | f6d51ac | 2015-09-02 13:26:25 -0700 | [diff] [blame] | 1602 | updateFingerprintListeningState(); |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 1603 | mNeedsSlowUnlockTransition = resolveNeedsSlowUnlockTransition(); |
| 1604 | } |
| 1605 | |
| 1606 | private boolean resolveNeedsSlowUnlockTransition() { |
| 1607 | if (mUserManager.isUserUnlocked(getCurrentUser())) { |
| 1608 | return false; |
| 1609 | } |
| 1610 | Intent homeIntent = new Intent(Intent.ACTION_MAIN) |
| 1611 | .addCategory(Intent.CATEGORY_HOME); |
| 1612 | ResolveInfo resolveInfo = mContext.getPackageManager().resolveActivity(homeIntent, |
| 1613 | 0 /* flags */); |
| 1614 | return FALLBACK_HOME_COMPONENT.equals(resolveInfo.getComponentInfo().getComponentName()); |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | /** |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 1618 | * Handle {@link #MSG_KEYGUARD_BOUNCER_CHANGED} |
| 1619 | * @see #sendKeyguardBouncerChanged(boolean) |
| 1620 | */ |
| 1621 | private void handleKeyguardBouncerChanged(int bouncer) { |
| 1622 | if (DEBUG) Log.d(TAG, "handleKeyguardBouncerChanged(" + bouncer + ")"); |
| 1623 | boolean isBouncer = (bouncer == 1); |
| 1624 | mBouncer = isBouncer; |
| 1625 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1626 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1627 | if (cb != null) { |
| 1628 | cb.onKeyguardBouncerChanged(isBouncer); |
| 1629 | } |
| 1630 | } |
Jorim Jaggi | 3cf7eef | 2015-09-10 14:36:19 -0700 | [diff] [blame] | 1631 | updateFingerprintListeningState(); |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 1632 | } |
| 1633 | |
| 1634 | /** |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 1635 | * Handle {@link #MSG_REPORT_EMERGENCY_CALL_ACTION} |
| 1636 | */ |
| 1637 | private void handleReportEmergencyCallAction() { |
| 1638 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1639 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1640 | if (cb != null) { |
| 1641 | cb.onEmergencyCallAction(); |
| 1642 | } |
| 1643 | } |
| 1644 | } |
| 1645 | |
Lucas Dupin | 4272f44 | 2018-01-13 22:00:35 -0800 | [diff] [blame] | 1646 | private boolean isBatteryUpdateInteresting(BatteryStatus old, BatteryStatus current) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1647 | final boolean nowPluggedIn = current.isPluggedIn(); |
| 1648 | final boolean wasPluggedIn = old.isPluggedIn(); |
Lucas Dupin | 4272f44 | 2018-01-13 22:00:35 -0800 | [diff] [blame] | 1649 | final boolean stateChangedWhilePluggedIn = wasPluggedIn && nowPluggedIn |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1650 | && (old.status != current.status); |
| 1651 | |
| 1652 | // change in plug state is always interesting |
| 1653 | if (wasPluggedIn != nowPluggedIn || stateChangedWhilePluggedIn) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1654 | return true; |
| 1655 | } |
| 1656 | |
Lucas Dupin | 3fcdd47 | 2018-01-19 19:06:45 -0800 | [diff] [blame] | 1657 | // change in battery level |
| 1658 | if (old.level != current.level) { |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1659 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1660 | } |
Adrian Roos | 76dc5a5 | 2015-07-21 16:20:36 -0700 | [diff] [blame] | 1661 | |
| 1662 | // change in charging current while plugged in |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 1663 | if (nowPluggedIn && current.maxChargingWattage != old.maxChargingWattage) { |
Adrian Roos | 76dc5a5 | 2015-07-21 16:20:36 -0700 | [diff] [blame] | 1664 | return true; |
| 1665 | } |
| 1666 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1667 | return false; |
| 1668 | } |
| 1669 | |
| 1670 | /** |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1671 | * Remove the given observer's callback. |
| 1672 | * |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1673 | * @param callback The callback to remove |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1674 | */ |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1675 | public void removeCallback(KeyguardUpdateMonitorCallback callback) { |
| 1676 | if (DEBUG) Log.v(TAG, "*** unregister callback for " + callback); |
| 1677 | for (int i = mCallbacks.size() - 1; i >= 0; i--) { |
| 1678 | if (mCallbacks.get(i).get() == callback) { |
| 1679 | mCallbacks.remove(i); |
| 1680 | } |
| 1681 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1685 | * Register to receive notifications about general keyguard information |
| 1686 | * (see {@link InfoCallback}. |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1687 | * @param callback The callback to register |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1688 | */ |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1689 | public void registerCallback(KeyguardUpdateMonitorCallback callback) { |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1690 | if (DEBUG) Log.v(TAG, "*** register callback for " + callback); |
| 1691 | // Prevent adding duplicate callbacks |
| 1692 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1693 | if (mCallbacks.get(i).get() == callback) { |
| 1694 | if (DEBUG) Log.e(TAG, "Object tried to add another callback", |
| 1695 | new Exception("Called by")); |
| 1696 | return; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1697 | } |
| 1698 | } |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1699 | mCallbacks.add(new WeakReference<KeyguardUpdateMonitorCallback>(callback)); |
| 1700 | removeCallback(null); // remove unused references |
| 1701 | sendUpdates(callback); |
| 1702 | } |
| 1703 | |
Evan Rosky | 1839645 | 2016-07-27 15:19:37 -0700 | [diff] [blame] | 1704 | public boolean isSwitchingUser() { |
| 1705 | return mSwitchingUser; |
| 1706 | } |
| 1707 | |
| 1708 | public void setSwitchingUser(boolean switching) { |
| 1709 | mSwitchingUser = switching; |
Selim Cinek | bbe1924 | 2017-12-08 15:42:08 -0800 | [diff] [blame] | 1710 | // Since this comes in on a binder thread, we need to post if first |
| 1711 | mHandler.post(mUpdateFingerprintListeningState); |
Evan Rosky | 1839645 | 2016-07-27 15:19:37 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1714 | private void sendUpdates(KeyguardUpdateMonitorCallback callback) { |
| 1715 | // Notify listener of the current state |
| 1716 | callback.onRefreshBatteryInfo(mBatteryStatus); |
| 1717 | callback.onTimeChanged(); |
| 1718 | callback.onRingerModeChanged(mRingMode); |
| 1719 | callback.onPhoneStateChanged(mPhoneState); |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 1720 | callback.onRefreshCarrierInfo(); |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 1721 | callback.onClockVisibilityChanged(); |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 1722 | callback.onKeyguardVisibilityChangedRaw(mKeyguardIsVisible); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1723 | for (Entry<Integer, SimData> data : mSimDatas.entrySet()) { |
| 1724 | final SimData state = data.getValue(); |
| 1725 | callback.onSimStateChanged(state.subId, state.slotId, state.simState); |
| 1726 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1727 | } |
| 1728 | |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 1729 | public void sendKeyguardReset() { |
| 1730 | mHandler.obtainMessage(MSG_KEYGUARD_RESET).sendToTarget(); |
| 1731 | } |
| 1732 | |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 1733 | /** |
| 1734 | * @see #handleKeyguardBouncerChanged(int) |
| 1735 | */ |
| 1736 | public void sendKeyguardBouncerChanged(boolean showingBouncer) { |
| 1737 | if (DEBUG) Log.d(TAG, "sendKeyguardBouncerChanged(" + showingBouncer + ")"); |
| 1738 | Message message = mHandler.obtainMessage(MSG_KEYGUARD_BOUNCER_CHANGED); |
| 1739 | message.arg1 = showingBouncer ? 1 : 0; |
| 1740 | message.sendToTarget(); |
| 1741 | } |
| 1742 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1743 | /** |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 1744 | * 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] | 1745 | * have the information earlier than waiting for the intent |
| 1746 | * broadcast from the telephony code. |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 1747 | * |
| 1748 | * NOTE: Because handleSimStateChange() invokes callbacks immediately without going |
| 1749 | * 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] | 1750 | */ |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1751 | public void reportSimUnlocked(int subId) { |
| 1752 | if (DEBUG_SIM_STATES) Log.v(TAG, "reportSimUnlocked(subId=" + subId + ")"); |
Sanket Padawe | 7e46025 | 2017-03-10 16:18:20 -0800 | [diff] [blame] | 1753 | int slotId = SubscriptionManager.getSlotIndex(subId); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1754 | handleSimStateChange(subId, slotId, State.READY); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1755 | } |
| 1756 | |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 1757 | /** |
| 1758 | * Report that the emergency call button has been pressed and the emergency dialer is |
| 1759 | * about to be displayed. |
| 1760 | * |
| 1761 | * @param bypassHandler runs immediately. |
| 1762 | * |
| 1763 | * NOTE: Must be called from UI thread if bypassHandler == true. |
| 1764 | */ |
| 1765 | public void reportEmergencyCallAction(boolean bypassHandler) { |
| 1766 | if (!bypassHandler) { |
| 1767 | mHandler.obtainMessage(MSG_REPORT_EMERGENCY_CALL_ACTION).sendToTarget(); |
| 1768 | } else { |
| 1769 | handleReportEmergencyCallAction(); |
| 1770 | } |
| 1771 | } |
| 1772 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1773 | /** |
| 1774 | * @return Whether the device is provisioned (whether they have gone through |
| 1775 | * the setup wizard) |
| 1776 | */ |
| 1777 | public boolean isDeviceProvisioned() { |
| 1778 | return mDeviceProvisioned; |
| 1779 | } |
| 1780 | |
Jorim Jaggi | 9f74303 | 2015-05-04 15:22:40 -0700 | [diff] [blame] | 1781 | public void clearFailedUnlockAttempts() { |
| 1782 | mFailedAttempts.delete(sCurrentUser); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1783 | } |
| 1784 | |
Kensuke Matsui | 21d1bf1 | 2017-03-14 13:27:20 +0900 | [diff] [blame] | 1785 | public ServiceState getServiceState(int subId) { |
| 1786 | return mServiceStates.get(subId); |
| 1787 | } |
| 1788 | |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 1789 | public int getFailedUnlockAttempts(int userId) { |
| 1790 | return mFailedAttempts.get(userId, 0); |
Jorim Jaggi | 9f74303 | 2015-05-04 15:22:40 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 1793 | public void reportFailedStrongAuthUnlockAttempt(int userId) { |
| 1794 | mFailedAttempts.put(userId, getFailedUnlockAttempts(userId) + 1); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1795 | } |
| 1796 | |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 1797 | public void clearFingerprintRecognized() { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1798 | mUserFingerprintAuthenticated.clear(); |
Kevin Chyn | 3fdbbf8 | 2017-05-06 15:11:53 -0700 | [diff] [blame] | 1799 | mTrustManager.clearAllFingerprints(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1802 | public boolean isSimPinVoiceSecure() { |
| 1803 | // TODO: only count SIMs that handle voice |
| 1804 | return isSimPinSecure(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | public boolean isSimPinSecure() { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1808 | // True if any SIM is pin secure |
| 1809 | for (SubscriptionInfo info : getSubscriptionInfo(false /* forceReload */)) { |
| 1810 | if (isSimPinSecure(getSimState(info.getSubscriptionId()))) return true; |
| 1811 | } |
| 1812 | return false; |
| 1813 | } |
| 1814 | |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 1815 | public State getSimState(int subId) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1816 | if (mSimDatas.containsKey(subId)) { |
| 1817 | return mSimDatas.get(subId).simState; |
| 1818 | } else { |
| 1819 | return State.UNKNOWN; |
| 1820 | } |
| 1821 | } |
| 1822 | |
Winson Chung | aa35745 | 2017-10-31 11:35:30 -0700 | [diff] [blame] | 1823 | private final SysUiTaskStackChangeListener |
| 1824 | mTaskStackListener = new SysUiTaskStackChangeListener() { |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 1825 | @Override |
| 1826 | public void onTaskStackChangedBackground() { |
| 1827 | try { |
| 1828 | ActivityManager.StackInfo info = ActivityManager.getService().getStackInfo( |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 1829 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_ASSISTANT); |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 1830 | if (info == null) { |
| 1831 | return; |
| 1832 | } |
| 1833 | mHandler.sendMessage(mHandler.obtainMessage(MSG_ASSISTANT_STACK_CHANGED, |
| 1834 | info.visible)); |
| 1835 | } catch (RemoteException e) { |
| 1836 | Log.e(TAG, "unable to check task stack", e); |
| 1837 | } |
| 1838 | } |
| 1839 | }; |
| 1840 | |
Jorim Jaggi | 01ba98b | 2015-01-13 21:33:45 +0100 | [diff] [blame] | 1841 | /** |
richard chou | b1b24e7 | 2018-03-22 14:39:43 +0800 | [diff] [blame] | 1842 | * @return A list of changed subscriptions, maybe empty but never null |
Jorim Jaggi | 01ba98b | 2015-01-13 21:33:45 +0100 | [diff] [blame] | 1843 | */ |
richard chou | b1b24e7 | 2018-03-22 14:39:43 +0800 | [diff] [blame] | 1844 | private List<Integer> refreshSimState(final List<SubscriptionInfo> activeSubscriptionInfos) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1845 | |
| 1846 | // This is awful. It exists because there are two APIs for getting the SIM status |
| 1847 | // that don't return the complete set of values and have different types. In Keyguard we |
| 1848 | // need IccCardConstants, but TelephonyManager would only give us |
| 1849 | // TelephonyManager.SIM_STATE*, so we retrieve it manually. |
xinhe | 18b9c3c | 2014-12-02 15:03:20 -0800 | [diff] [blame] | 1850 | final TelephonyManager tele = TelephonyManager.from(mContext); |
richard chou | b1b24e7 | 2018-03-22 14:39:43 +0800 | [diff] [blame] | 1851 | ArrayList<Integer> changedSubscriptionIds = new ArrayList<>(); |
| 1852 | HashSet<Integer> activeSubIds = new HashSet<>(); |
richard chou | 3e7c7ca | 2018-04-12 14:25:16 +0800 | [diff] [blame] | 1853 | HashSet<Integer> activeSlotIds = new HashSet<>(); |
richard chou | b1b24e7 | 2018-03-22 14:39:43 +0800 | [diff] [blame] | 1854 | |
| 1855 | for (SubscriptionInfo info : activeSubscriptionInfos) { |
| 1856 | int subId = info.getSubscriptionId(); |
| 1857 | int slotId = info.getSimSlotIndex(); |
| 1858 | int simState = tele.getSimState(slotId); |
| 1859 | State state; |
| 1860 | try { |
| 1861 | state = State.intToState(simState); |
| 1862 | } catch(IllegalArgumentException ex) { |
| 1863 | Log.w(TAG, "Unknown sim state: " + simState); |
| 1864 | state = State.UNKNOWN; |
| 1865 | } |
| 1866 | |
| 1867 | SimData data = mSimDatas.get(subId); |
| 1868 | final boolean changed; |
| 1869 | if (data == null) { |
| 1870 | data = new SimData(state, slotId, subId); |
| 1871 | mSimDatas.put(subId, data); |
| 1872 | changed = true; // no data yet; force update |
| 1873 | } else { |
| 1874 | changed = data.simState != state; |
| 1875 | data.simState = state; |
| 1876 | } |
| 1877 | if (changed) { |
| 1878 | changedSubscriptionIds.add(subId); |
| 1879 | } |
| 1880 | |
| 1881 | activeSubIds.add(subId); |
richard chou | 3e7c7ca | 2018-04-12 14:25:16 +0800 | [diff] [blame] | 1882 | activeSlotIds.add(slotId); |
John Spurlock | 5b13e92 | 2015-01-07 11:04:58 -0500 | [diff] [blame] | 1883 | } |
richard chou | b1b24e7 | 2018-03-22 14:39:43 +0800 | [diff] [blame] | 1884 | |
| 1885 | for (SimData data : mSimDatas.values()) { |
richard chou | 3e7c7ca | 2018-04-12 14:25:16 +0800 | [diff] [blame] | 1886 | if (!activeSubIds.contains(data.subId) |
| 1887 | && !activeSlotIds.contains(data.slotId) |
| 1888 | && data.simState != State.ABSENT) { |
richard chou | b1b24e7 | 2018-03-22 14:39:43 +0800 | [diff] [blame] | 1889 | // for the inactive subscriptions, reset state to ABSENT |
richard chou | 3e7c7ca | 2018-04-12 14:25:16 +0800 | [diff] [blame] | 1890 | if (DEBUG_SIM_STATES) Log.d(TAG, "reset state to ABSENT for subId:" + data.subId); |
richard chou | b1b24e7 | 2018-03-22 14:39:43 +0800 | [diff] [blame] | 1891 | data.simState = State.ABSENT; |
| 1892 | changedSubscriptionIds.add(data.subId); |
| 1893 | } |
Jorim Jaggi | 01ba98b | 2015-01-13 21:33:45 +0100 | [diff] [blame] | 1894 | } |
richard chou | b1b24e7 | 2018-03-22 14:39:43 +0800 | [diff] [blame] | 1895 | |
| 1896 | return changedSubscriptionIds; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | public static boolean isSimPinSecure(IccCardConstants.State state) { |
| 1900 | final IccCardConstants.State simState = state; |
| 1901 | return (simState == IccCardConstants.State.PIN_REQUIRED |
| 1902 | || simState == IccCardConstants.State.PUK_REQUIRED |
| 1903 | || simState == IccCardConstants.State.PERM_DISABLED); |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 1904 | } |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1905 | |
| 1906 | public DisplayClientState getCachedDisplayClientState() { |
| 1907 | return mDisplayClientState; |
| 1908 | } |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1909 | |
| 1910 | // TODO: use these callbacks elsewhere in place of the existing notifyScreen*() |
| 1911 | // (KeyguardViewMediator, KeyguardHostView) |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1912 | public void dispatchStartedWakingUp() { |
| 1913 | synchronized (this) { |
| 1914 | mDeviceInteractive = true; |
| 1915 | } |
| 1916 | mHandler.sendEmptyMessage(MSG_STARTED_WAKING_UP); |
| 1917 | } |
| 1918 | |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 1919 | public void dispatchStartedGoingToSleep(int why) { |
| 1920 | mHandler.sendMessage(mHandler.obtainMessage(MSG_STARTED_GOING_TO_SLEEP, why, 0)); |
| 1921 | } |
| 1922 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1923 | public void dispatchFinishedGoingToSleep(int why) { |
| 1924 | synchronized(this) { |
| 1925 | mDeviceInteractive = false; |
| 1926 | } |
| 1927 | mHandler.sendMessage(mHandler.obtainMessage(MSG_FINISHED_GOING_TO_SLEEP, why, 0)); |
| 1928 | } |
| 1929 | |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1930 | public void dispatchScreenTurnedOn() { |
| 1931 | synchronized (this) { |
| 1932 | mScreenOn = true; |
| 1933 | } |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 1934 | mHandler.sendEmptyMessage(MSG_SCREEN_TURNED_ON); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1935 | } |
| 1936 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1937 | public void dispatchScreenTurnedOff() { |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1938 | synchronized(this) { |
| 1939 | mScreenOn = false; |
| 1940 | } |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 1941 | mHandler.sendEmptyMessage(MSG_SCREEN_TURNED_OFF); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1942 | } |
| 1943 | |
Selim Cinek | 9941539 | 2016-09-09 14:58:41 -0700 | [diff] [blame] | 1944 | public void dispatchDreamingStarted() { |
| 1945 | mHandler.sendMessage(mHandler.obtainMessage(MSG_DREAMING_STATE_CHANGED, 1, 0)); |
| 1946 | } |
| 1947 | |
| 1948 | public void dispatchDreamingStopped() { |
| 1949 | mHandler.sendMessage(mHandler.obtainMessage(MSG_DREAMING_STATE_CHANGED, 0, 0)); |
| 1950 | } |
| 1951 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1952 | public boolean isDeviceInteractive() { |
| 1953 | return mDeviceInteractive; |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1954 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1955 | |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 1956 | public boolean isGoingToSleep() { |
| 1957 | return mGoingToSleep; |
| 1958 | } |
| 1959 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1960 | /** |
| 1961 | * Find the next SubscriptionId for a SIM in the given state, favoring lower slot numbers first. |
| 1962 | * @param state |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1963 | * @return subid or {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} if none found |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1964 | */ |
| 1965 | public int getNextSubIdForState(State state) { |
| 1966 | List<SubscriptionInfo> list = getSubscriptionInfo(false /* forceReload */); |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1967 | int resultId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1968 | int bestSlotId = Integer.MAX_VALUE; // Favor lowest slot first |
| 1969 | for (int i = 0; i < list.size(); i++) { |
| 1970 | final SubscriptionInfo info = list.get(i); |
| 1971 | final int id = info.getSubscriptionId(); |
Sanket Padawe | 7e46025 | 2017-03-10 16:18:20 -0800 | [diff] [blame] | 1972 | int slotId = SubscriptionManager.getSlotIndex(id); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1973 | if (state == getSimState(id) && bestSlotId > slotId ) { |
| 1974 | resultId = id; |
| 1975 | bestSlotId = slotId; |
| 1976 | } |
| 1977 | } |
| 1978 | return resultId; |
| 1979 | } |
| 1980 | |
| 1981 | public SubscriptionInfo getSubscriptionInfoForSubId(int subId) { |
| 1982 | List<SubscriptionInfo> list = getSubscriptionInfo(false /* forceReload */); |
| 1983 | for (int i = 0; i < list.size(); i++) { |
| 1984 | SubscriptionInfo info = list.get(i); |
| 1985 | if (subId == info.getSubscriptionId()) return info; |
| 1986 | } |
| 1987 | return null; // not found |
| 1988 | } |
Jason Monk | ab52527 | 2015-07-13 17:02:49 -0400 | [diff] [blame] | 1989 | |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 1990 | /** |
| 1991 | * @return a cached version of DevicePolicyManager.isLogoutEnabled() |
| 1992 | */ |
| 1993 | public boolean isLogoutEnabled() { |
| 1994 | return mLogoutEnabled; |
| 1995 | } |
| 1996 | |
| 1997 | private void updateLogoutEnabled() { |
| 1998 | boolean logoutEnabled = mDevicePolicyManager.isLogoutEnabled(); |
| 1999 | if (mLogoutEnabled != logoutEnabled) { |
| 2000 | mLogoutEnabled = logoutEnabled; |
| 2001 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 2002 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 2003 | if (cb != null) { |
| 2004 | cb.onLogoutEnabledChanged(); |
| 2005 | } |
| 2006 | } |
| 2007 | } |
| 2008 | } |
| 2009 | |
Jason Monk | ab52527 | 2015-07-13 17:02:49 -0400 | [diff] [blame] | 2010 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 2011 | pw.println("KeyguardUpdateMonitor state:"); |
| 2012 | pw.println(" SIM States:"); |
| 2013 | for (SimData data : mSimDatas.values()) { |
| 2014 | pw.println(" " + data.toString()); |
| 2015 | } |
| 2016 | pw.println(" Subs:"); |
| 2017 | if (mSubscriptionInfo != null) { |
| 2018 | for (int i = 0; i < mSubscriptionInfo.size(); i++) { |
| 2019 | pw.println(" " + mSubscriptionInfo.get(i)); |
| 2020 | } |
| 2021 | } |
| 2022 | pw.println(" Service states:"); |
| 2023 | for (int subId : mServiceStates.keySet()) { |
| 2024 | pw.println(" " + subId + "=" + mServiceStates.get(subId)); |
| 2025 | } |
Jim Miller | d72d5ac | 2015-09-29 18:55:32 -0700 | [diff] [blame] | 2026 | if (mFpm != null && mFpm.isHardwareDetected()) { |
| 2027 | final int userId = ActivityManager.getCurrentUser(); |
| 2028 | final int strongAuthFlags = mStrongAuthTracker.getStrongAuthForUser(userId); |
| 2029 | pw.println(" Fingerprint state (user=" + userId + ")"); |
| 2030 | pw.println(" allowed=" + isUnlockingWithFingerprintAllowed()); |
| 2031 | pw.println(" auth'd=" + mUserFingerprintAuthenticated.get(userId)); |
| 2032 | pw.println(" authSinceBoot=" |
| 2033 | + getStrongAuthTracker().hasUserAuthenticatedSinceBoot()); |
| 2034 | pw.println(" disabled(DPM)=" + isFingerprintDisabled(userId)); |
| 2035 | pw.println(" possible=" + isUnlockWithFingerprintPossible(userId)); |
| 2036 | pw.println(" strongAuthFlags=" + Integer.toHexString(strongAuthFlags)); |
Jim Miller | d72d5ac | 2015-09-29 18:55:32 -0700 | [diff] [blame] | 2037 | pw.println(" trustManaged=" + getUserTrustIsManaged(userId)); |
| 2038 | } |
Jason Monk | ab52527 | 2015-07-13 17:02:49 -0400 | [diff] [blame] | 2039 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2040 | } |