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; |
Lucas Dupin | 6c6d573 | 2019-08-27 17:36:05 -0700 | [diff] [blame] | 21 | import static android.content.Intent.ACTION_USER_REMOVED; |
| 22 | import static android.content.Intent.ACTION_USER_STOPPED; |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 23 | import static android.content.Intent.ACTION_USER_UNLOCKED; |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 24 | import static android.os.BatteryManager.BATTERY_HEALTH_UNKNOWN; |
| 25 | import static android.os.BatteryManager.BATTERY_STATUS_FULL; |
| 26 | import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN; |
| 27 | import static android.os.BatteryManager.EXTRA_HEALTH; |
| 28 | import static android.os.BatteryManager.EXTRA_LEVEL; |
| 29 | import static android.os.BatteryManager.EXTRA_MAX_CHARGING_CURRENT; |
| 30 | import static android.os.BatteryManager.EXTRA_MAX_CHARGING_VOLTAGE; |
| 31 | import static android.os.BatteryManager.EXTRA_PLUGGED; |
| 32 | import static android.os.BatteryManager.EXTRA_STATUS; |
Fabian Kozynski | ccde55d | 2019-06-26 10:06:09 -0400 | [diff] [blame] | 33 | import static android.telephony.PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE; |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 34 | |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame] | 35 | import static com.android.internal.telephony.PhoneConstants.MAX_PHONE_COUNT_DUAL_SIM; |
Lucas Dupin | 8eec268 | 2019-07-01 16:41:17 -0700 | [diff] [blame] | 36 | import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT; |
| 37 | import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW; |
| 38 | import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT; |
| 39 | import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT; |
| 40 | import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN; |
Lucas Dupin | 8968f6a | 2019-08-09 17:41:15 -0700 | [diff] [blame] | 41 | import static com.android.systemui.DejankUtils.whitelistIpcs; |
Lucas Dupin | 8eec268 | 2019-07-01 16:41:17 -0700 | [diff] [blame] | 42 | |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 43 | import android.annotation.AnyThread; |
| 44 | import android.annotation.MainThread; |
Jorim Jaggi | ccdfa93 | 2015-04-13 16:29:48 -0700 | [diff] [blame] | 45 | import android.app.ActivityManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 46 | import android.app.ActivityTaskManager; |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 47 | import android.app.AlarmManager; |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 48 | import android.app.PendingIntent; |
Sudheer Shanka | 2c4522c | 2016-08-27 20:53:28 -0700 | [diff] [blame] | 49 | import android.app.UserSwitchObserver; |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 50 | import android.app.admin.DevicePolicyManager; |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 51 | import android.app.trust.TrustManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 52 | import android.content.BroadcastReceiver; |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 53 | import android.content.ComponentName; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 54 | import android.content.Context; |
| 55 | import android.content.Intent; |
| 56 | import android.content.IntentFilter; |
Adrian Roos | ca8a216 | 2017-08-17 19:00:58 +0200 | [diff] [blame] | 57 | import android.content.pm.IPackageManager; |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 58 | import android.content.pm.PackageManager; |
| 59 | import android.content.pm.ResolveInfo; |
Lucas Dupin | f2c5350 | 2019-10-03 13:56:18 -0700 | [diff] [blame] | 60 | import android.content.pm.UserInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 61 | import android.database.ContentObserver; |
Kevin Chyn | b7b54a6 | 2018-09-28 18:48:12 -0700 | [diff] [blame] | 62 | import android.hardware.biometrics.BiometricManager; |
Kevin Chyn | 56233ab | 2018-09-20 17:10:57 -0700 | [diff] [blame] | 63 | import android.hardware.biometrics.BiometricSourceType; |
Kevin Chyn | b7b54a6 | 2018-09-28 18:48:12 -0700 | [diff] [blame] | 64 | import android.hardware.biometrics.IBiometricEnabledOnKeyguardCallback; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 65 | import android.hardware.face.FaceManager; |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 66 | import android.hardware.fingerprint.FingerprintManager; |
| 67 | import android.hardware.fingerprint.FingerprintManager.AuthenticationCallback; |
| 68 | import android.hardware.fingerprint.FingerprintManager.AuthenticationResult; |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 69 | import android.media.AudioManager; |
Jim Miller | 79a444a | 2011-02-15 15:02:11 -0800 | [diff] [blame] | 70 | import android.os.BatteryManager; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 71 | import android.os.CancellationSignal; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 72 | import android.os.Handler; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 73 | import android.os.IRemoteCallback; |
Jason Monk | 7bb5930 | 2018-05-10 19:38:18 -0700 | [diff] [blame] | 74 | import android.os.Looper; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 75 | import android.os.Message; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 76 | import android.os.RemoteException; |
Adrian Roos | ca8a216 | 2017-08-17 19:00:58 +0200 | [diff] [blame] | 77 | import android.os.ServiceManager; |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 78 | import android.os.Trace; |
Amith Yamasani | e8e93a1 | 2013-05-09 18:12:30 -0700 | [diff] [blame] | 79 | import android.os.UserHandle; |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 80 | import android.os.UserManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 81 | import android.provider.Settings; |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 82 | import android.service.dreams.DreamService; |
| 83 | import android.service.dreams.IDreamManager; |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame] | 84 | import android.telephony.CarrierConfigManager; |
Fabian Kozynski | ccde55d | 2019-06-26 10:06:09 -0400 | [diff] [blame] | 85 | import android.telephony.PhoneStateListener; |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 86 | import android.telephony.ServiceState; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 87 | import android.telephony.SubscriptionInfo; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 88 | import android.telephony.SubscriptionManager; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 89 | import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener; |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 90 | import android.telephony.TelephonyManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 91 | import android.util.Log; |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 92 | import android.util.SparseBooleanArray; |
| 93 | |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 94 | import com.android.internal.annotations.VisibleForTesting; |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 95 | import com.android.internal.telephony.IccCardConstants; |
| 96 | import com.android.internal.telephony.IccCardConstants.State; |
| 97 | import com.android.internal.telephony.PhoneConstants; |
| 98 | import com.android.internal.telephony.TelephonyIntents; |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 99 | import com.android.internal.widget.LockPatternUtils; |
Bill Lin | ef81cbd | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 100 | import com.android.settingslib.WirelessUtils; |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 101 | import com.android.systemui.DejankUtils; |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 102 | import com.android.systemui.DumpController; |
| 103 | import com.android.systemui.Dumpable; |
Hyunyoung Song | 8f9d34c | 2019-08-30 14:47:43 -0700 | [diff] [blame] | 104 | import com.android.systemui.R; |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 105 | import com.android.systemui.broadcast.BroadcastDispatcher; |
Dave Mankoff | f473681 | 2019-10-18 17:25:50 -0400 | [diff] [blame] | 106 | import com.android.systemui.dagger.qualifiers.MainLooper; |
Winson Chung | 2cf6ad8 | 2017-11-09 17:36:59 -0800 | [diff] [blame] | 107 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 108 | import com.android.systemui.shared.system.TaskStackChangeListener; |
Lucas Dupin | 9e484aa | 2019-06-24 13:38:00 -0700 | [diff] [blame] | 109 | import com.android.systemui.statusbar.phone.KeyguardBypassController; |
Kevin Chyn | 1123ba7 | 2018-10-26 10:34:06 -0700 | [diff] [blame] | 110 | |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 111 | import com.google.android.collect.Lists; |
| 112 | |
Jason Monk | ab52527 | 2015-07-13 17:02:49 -0400 | [diff] [blame] | 113 | import java.io.FileDescriptor; |
| 114 | import java.io.PrintWriter; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 115 | import java.lang.ref.WeakReference; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 116 | import java.util.ArrayList; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 117 | import java.util.HashMap; |
| 118 | import java.util.List; |
| 119 | import java.util.Map.Entry; |
Robert Snoeberger | 9c1074f | 2018-12-07 17:35:21 -0500 | [diff] [blame] | 120 | import java.util.TimeZone; |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 121 | import java.util.function.Consumer; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 122 | |
Dave Mankoff | e229469 | 2019-08-14 11:53:13 -0400 | [diff] [blame] | 123 | import javax.inject.Inject; |
Lucas Dupin | ab39e80 | 2019-10-08 14:42:00 -0700 | [diff] [blame] | 124 | import javax.inject.Singleton; |
Dave Mankoff | e229469 | 2019-08-14 11:53:13 -0400 | [diff] [blame] | 125 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 126 | /** |
| 127 | * Watches for updates that may be interesting to the keyguard, and provides |
| 128 | * the up to date information as well as a registration for callbacks that care |
| 129 | * to be updated. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 130 | */ |
Lucas Dupin | ab39e80 | 2019-10-08 14:42:00 -0700 | [diff] [blame] | 131 | @Singleton |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 132 | public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpable { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 133 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 134 | private static final String TAG = "KeyguardUpdateMonitor"; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 135 | private static final boolean DEBUG = KeyguardConstants.DEBUG; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 136 | private static final boolean DEBUG_SIM_STATES = KeyguardConstants.DEBUG_SIM_STATES; |
Lucas Dupin | 71d2fb2 | 2019-05-30 18:26:54 -0700 | [diff] [blame] | 137 | private static final boolean DEBUG_FACE = true; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 138 | private static final int LOW_BATTERY_THRESHOLD = 20; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 139 | |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 140 | private static final String ACTION_FACE_UNLOCK_STARTED |
| 141 | = "com.android.facelock.FACE_UNLOCK_STARTED"; |
| 142 | private static final String ACTION_FACE_UNLOCK_STOPPED |
| 143 | = "com.android.facelock.FACE_UNLOCK_STOPPED"; |
| 144 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 145 | // Callback messages |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 146 | private static final int MSG_TIME_UPDATE = 301; |
| 147 | private static final int MSG_BATTERY_UPDATE = 302; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 148 | private static final int MSG_SIM_STATE_CHANGE = 304; |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 149 | private static final int MSG_RINGER_MODE_CHANGED = 305; |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 150 | private static final int MSG_PHONE_STATE_CHANGED = 306; |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 151 | private static final int MSG_DEVICE_PROVISIONED = 308; |
Jim Miller | 5737534 | 2012-09-09 15:20:31 -0700 | [diff] [blame] | 152 | private static final int MSG_DPM_STATE_CHANGED = 309; |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 153 | private static final int MSG_USER_SWITCHING = 310; |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 154 | private static final int MSG_KEYGUARD_RESET = 312; |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 155 | private static final int MSG_BOOT_COMPLETED = 313; |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 156 | private static final int MSG_USER_SWITCH_COMPLETE = 314; |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 157 | private static final int MSG_USER_INFO_CHANGED = 317; |
| 158 | private static final int MSG_REPORT_EMERGENCY_CALL_ACTION = 318; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 159 | private static final int MSG_STARTED_WAKING_UP = 319; |
| 160 | private static final int MSG_FINISHED_GOING_TO_SLEEP = 320; |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 161 | private static final int MSG_STARTED_GOING_TO_SLEEP = 321; |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 162 | private static final int MSG_KEYGUARD_BOUNCER_CHANGED = 322; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 163 | private static final int MSG_FACE_UNLOCK_STATE_CHANGED = 327; |
| 164 | private static final int MSG_SIM_SUBSCRIPTION_INFO_CHANGED = 328; |
Jason Monk | 052082c | 2015-06-11 11:35:23 -0400 | [diff] [blame] | 165 | private static final int MSG_AIRPLANE_MODE_CHANGED = 329; |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 166 | private static final int MSG_SERVICE_STATE_CHANGE = 330; |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 167 | private static final int MSG_SCREEN_TURNED_ON = 331; |
| 168 | private static final int MSG_SCREEN_TURNED_OFF = 332; |
Selim Cinek | 9941539 | 2016-09-09 14:58:41 -0700 | [diff] [blame] | 169 | private static final int MSG_DREAMING_STATE_CHANGED = 333; |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 170 | private static final int MSG_USER_UNLOCKED = 334; |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 171 | private static final int MSG_ASSISTANT_STACK_CHANGED = 335; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 172 | private static final int MSG_BIOMETRIC_AUTHENTICATION_CONTINUE = 336; |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 173 | private static final int MSG_DEVICE_POLICY_MANAGER_STATE_CHANGED = 337; |
Bill Lin | ef81cbd | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 174 | private static final int MSG_TELEPHONY_CAPABLE = 338; |
Robert Snoeberger | 9c1074f | 2018-12-07 17:35:21 -0500 | [diff] [blame] | 175 | private static final int MSG_TIMEZONE_UPDATE = 339; |
Lucas Dupin | 6c6d573 | 2019-08-27 17:36:05 -0700 | [diff] [blame] | 176 | private static final int MSG_USER_STOPPED = 340; |
| 177 | private static final int MSG_USER_REMOVED = 341; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 178 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 179 | /** Biometric authentication state: Not listening. */ |
| 180 | private static final int BIOMETRIC_STATE_STOPPED = 0; |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 181 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 182 | /** Biometric authentication state: Listening. */ |
| 183 | private static final int BIOMETRIC_STATE_RUNNING = 1; |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 184 | |
| 185 | /** |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 186 | * Biometric authentication: Cancelling and waiting for the relevant biometric service to |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 187 | * send us the confirmation that cancellation has happened. |
| 188 | */ |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 189 | private static final int BIOMETRIC_STATE_CANCELLING = 2; |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 190 | |
| 191 | /** |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 192 | * Biometric state: During cancelling we got another request to start listening, so when we |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 193 | * receive the cancellation done signal, we should start listening again. |
| 194 | */ |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 195 | private static final int BIOMETRIC_STATE_CANCELLING_RESTARTING = 3; |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 196 | |
Lucas Dupin | 51996bb | 2019-05-16 17:56:43 -0700 | [diff] [blame] | 197 | private static final int BIOMETRIC_HELP_FINGERPRINT_NOT_RECOGNIZED = -1; |
| 198 | public static final int BIOMETRIC_HELP_FACE_NOT_RECOGNIZED = -2; |
| 199 | |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 200 | private static final int DEFAULT_CHARGING_VOLTAGE_MICRO_VOLT = 5000000; |
joshmccloskey | 7dee454 | 2019-07-31 18:35:33 -0700 | [diff] [blame] | 201 | /** |
| 202 | * If no cancel signal has been received after this amount of time, set the biometric running |
| 203 | * state to stopped to allow Keyguard to retry authentication. |
| 204 | */ |
| 205 | private static final int DEFAULT_CANCEL_SIGNAL_TIMEOUT = 3000; |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 206 | |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 207 | private static final ComponentName FALLBACK_HOME_COMPONENT = new ComponentName( |
| 208 | "com.android.settings", "com.android.settings.FallbackHome"); |
| 209 | |
Adrian Roos | ca8a216 | 2017-08-17 19:00:58 +0200 | [diff] [blame] | 210 | |
| 211 | /** |
| 212 | * If true, the system is in the half-boot-to-decryption-screen state. |
| 213 | * Prudently disable lockscreen. |
| 214 | */ |
| 215 | public static final boolean CORE_APPS_ONLY; |
Lucas Dupin | 71d2fb2 | 2019-05-30 18:26:54 -0700 | [diff] [blame] | 216 | |
Adrian Roos | ca8a216 | 2017-08-17 19:00:58 +0200 | [diff] [blame] | 217 | static { |
| 218 | try { |
| 219 | CORE_APPS_ONLY = IPackageManager.Stub.asInterface( |
| 220 | ServiceManager.getService("package")).isOnlyCoreApps(); |
| 221 | } catch (RemoteException e) { |
| 222 | throw e.rethrowFromSystemServer(); |
| 223 | } |
| 224 | } |
| 225 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 226 | private final Context mContext; |
Kevin Chyn | fdfd2d3 | 2019-03-01 14:52:15 -0800 | [diff] [blame] | 227 | private final boolean mIsPrimaryUser; |
Lucas Dupin | 10960bd | 2019-09-27 16:08:32 -0700 | [diff] [blame] | 228 | HashMap<Integer, SimData> mSimDatas = new HashMap<>(); |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 229 | HashMap<Integer, ServiceState> mServiceStates = new HashMap<Integer, ServiceState>(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 230 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 231 | private int mRingMode; |
| 232 | private int mPhoneState; |
Danielle Millett | 5d2404d | 2012-11-01 00:05:27 -0400 | [diff] [blame] | 233 | private boolean mKeyguardIsVisible; |
Kevin Chyn | f3b8fbd | 2017-05-03 22:24:31 -0700 | [diff] [blame] | 234 | private boolean mKeyguardGoingAway; |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 235 | private boolean mGoingToSleep; |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 236 | private boolean mBouncer; |
Lucas Dupin | e0516d5 | 2019-02-05 17:54:06 -0500 | [diff] [blame] | 237 | private boolean mAuthInterruptActive; |
Adam Cohen | 4eb36cf | 2012-11-07 11:45:30 -0800 | [diff] [blame] | 238 | private boolean mBootCompleted; |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 239 | private boolean mNeedsSlowUnlockTransition; |
Jorim Jaggi | d11d1a9 | 2016-08-16 16:02:32 -0700 | [diff] [blame] | 240 | private boolean mHasLockscreenWallpaper; |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 241 | private boolean mAssistantVisible; |
| 242 | private boolean mKeyguardOccluded; |
Kevin Chyn | 6951d3d | 2019-06-10 14:07:13 -0700 | [diff] [blame] | 243 | private boolean mSecureCameraLaunched; |
Bill Lin | ef81cbd | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 244 | @VisibleForTesting |
| 245 | protected boolean mTelephonyCapable; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 246 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 247 | // Device provisioning state |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 248 | private boolean mDeviceProvisioned; |
| 249 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 250 | // Battery status |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 251 | private BatteryStatus mBatteryStatus; |
| 252 | |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 253 | @VisibleForTesting |
| 254 | protected StrongAuthTracker mStrongAuthTracker; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 255 | |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 256 | private final ArrayList<WeakReference<KeyguardUpdateMonitorCallback>> |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 257 | mCallbacks = Lists.newArrayList(); |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 258 | private ContentObserver mDeviceProvisionedObserver; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 259 | |
Brian Colonna | a523989 | 2013-04-15 11:45:40 -0400 | [diff] [blame] | 260 | private boolean mSwitchingUser; |
| 261 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 262 | private boolean mDeviceInteractive; |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 263 | private boolean mScreenOn; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 264 | private SubscriptionManager mSubscriptionManager; |
| 265 | private List<SubscriptionInfo> mSubscriptionInfo; |
Jorim Jaggi | 237b061 | 2015-05-01 14:28:49 -0700 | [diff] [blame] | 266 | private TrustManager mTrustManager; |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 267 | private UserManager mUserManager; |
Lucas Dupin | 9e484aa | 2019-06-24 13:38:00 -0700 | [diff] [blame] | 268 | private KeyguardBypassController mKeyguardBypassController; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 269 | private int mFingerprintRunningState = BIOMETRIC_STATE_STOPPED; |
| 270 | private int mFaceRunningState = BIOMETRIC_STATE_STOPPED; |
Michal Karpinski | c52f867 | 2016-11-18 11:32:45 +0000 | [diff] [blame] | 271 | private LockPatternUtils mLockPatternUtils; |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 272 | private final IDreamManager mDreamManager; |
| 273 | private boolean mIsDreaming; |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 274 | private final DevicePolicyManager mDevicePolicyManager; |
| 275 | private boolean mLogoutEnabled; |
Lucas Dupin | ca88e5f | 2019-05-14 16:11:08 -0700 | [diff] [blame] | 276 | // If the user long pressed the lock icon, disabling face auth for the current session. |
| 277 | private boolean mLockIconPressed; |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame] | 278 | private int mActiveMobileDataSubscription = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 279 | |
Kevin Chyn | 0f3e0b1 | 2017-07-20 16:56:11 -0700 | [diff] [blame] | 280 | /** |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 281 | * Short delay before restarting biometric authentication after a successful try |
| 282 | * This should be slightly longer than the time between on<biometric>Authenticated |
| 283 | * (e.g. onFingerprintAuthenticated) and setKeyguardGoingAway(true). |
Kevin Chyn | 0f3e0b1 | 2017-07-20 16:56:11 -0700 | [diff] [blame] | 284 | */ |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 285 | private static final int BIOMETRIC_CONTINUE_DELAY_MS = 500; |
Kevin Chyn | 0f3e0b1 | 2017-07-20 16:56:11 -0700 | [diff] [blame] | 286 | |
Kevin Chyn | e1ac0c0 | 2019-07-26 17:54:46 -0700 | [diff] [blame] | 287 | // If the HAL dies or is unable to authenticate, keyguard should retry after a short delay |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 288 | private int mHardwareFingerprintUnavailableRetryCount = 0; |
| 289 | private int mHardwareFaceUnavailableRetryCount = 0; |
Kevin Chyn | e1ac0c0 | 2019-07-26 17:54:46 -0700 | [diff] [blame] | 290 | private static final int HAL_ERROR_RETRY_TIMEOUT = 500; // ms |
| 291 | private static final int HAL_ERROR_RETRY_MAX = 10; |
Kevin Chyn | 0c45b07 | 2017-04-24 16:27:11 -0700 | [diff] [blame] | 292 | |
joshmccloskey | 7dee454 | 2019-07-31 18:35:33 -0700 | [diff] [blame] | 293 | private final Runnable mCancelNotReceived = new Runnable() { |
| 294 | @Override |
| 295 | public void run() { |
| 296 | Log.w(TAG, "Cancel not received, transitioning to STOPPED"); |
| 297 | mFingerprintRunningState = mFaceRunningState = BIOMETRIC_STATE_STOPPED; |
| 298 | updateBiometricListeningState(); |
| 299 | } |
| 300 | }; |
| 301 | |
Dave Mankoff | e229469 | 2019-08-14 11:53:13 -0400 | [diff] [blame] | 302 | private final Handler mHandler; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 303 | |
Lucas Dupin | 7d95f15 | 2019-07-17 16:25:54 -0700 | [diff] [blame] | 304 | private SparseBooleanArray mFaceSettingEnabledForUser = new SparseBooleanArray(); |
Kevin Chyn | b7b54a6 | 2018-09-28 18:48:12 -0700 | [diff] [blame] | 305 | private BiometricManager mBiometricManager; |
| 306 | private IBiometricEnabledOnKeyguardCallback mBiometricEnabledCallback = |
| 307 | new IBiometricEnabledOnKeyguardCallback.Stub() { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 308 | @Override |
| 309 | public void onChanged(BiometricSourceType type, boolean enabled, int userId) |
| 310 | throws RemoteException { |
| 311 | if (type == BiometricSourceType.FACE) { |
| 312 | mFaceSettingEnabledForUser.put(userId, enabled); |
| 313 | updateFaceListeningState(); |
| 314 | } |
| 315 | } |
| 316 | }; |
Kevin Chyn | b7b54a6 | 2018-09-28 18:48:12 -0700 | [diff] [blame] | 317 | |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame] | 318 | @VisibleForTesting |
| 319 | public PhoneStateListener mPhoneStateListener = new PhoneStateListener() { |
Fabian Kozynski | ccde55d | 2019-06-26 10:06:09 -0400 | [diff] [blame] | 320 | @Override |
| 321 | public void onActiveDataSubscriptionIdChanged(int subId) { |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame] | 322 | mActiveMobileDataSubscription = subId; |
Fabian Kozynski | ccde55d | 2019-06-26 10:06:09 -0400 | [diff] [blame] | 323 | mHandler.sendEmptyMessage(MSG_SIM_SUBSCRIPTION_INFO_CHANGED); |
| 324 | } |
| 325 | }; |
| 326 | |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 327 | private OnSubscriptionsChangedListener mSubscriptionListener = |
| 328 | new OnSubscriptionsChangedListener() { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 329 | @Override |
| 330 | public void onSubscriptionsChanged() { |
| 331 | mHandler.sendEmptyMessage(MSG_SIM_SUBSCRIPTION_INFO_CHANGED); |
| 332 | } |
| 333 | }; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 334 | |
Lucas Dupin | 6c6d573 | 2019-08-27 17:36:05 -0700 | [diff] [blame] | 335 | private SparseBooleanArray mUserIsUnlocked = new SparseBooleanArray(); |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 336 | private SparseBooleanArray mUserHasTrust = new SparseBooleanArray(); |
Adrian Roos | 7861c66 | 2014-07-25 15:37:28 +0200 | [diff] [blame] | 337 | private SparseBooleanArray mUserTrustIsManaged = new SparseBooleanArray(); |
Lucas Dupin | f2c5350 | 2019-10-03 13:56:18 -0700 | [diff] [blame] | 338 | private SparseBooleanArray mUserTrustIsUsuallyManaged = new SparseBooleanArray(); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 339 | private SparseBooleanArray mUserFingerprintAuthenticated = new SparseBooleanArray(); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 340 | private SparseBooleanArray mUserFaceAuthenticated = new SparseBooleanArray(); |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 341 | private SparseBooleanArray mUserFaceUnlockRunning = new SparseBooleanArray(); |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 342 | |
Adrian Roos | d6aa6cb | 2015-04-16 19:31:29 -0700 | [diff] [blame] | 343 | private static int sCurrentUser; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 344 | private Runnable mUpdateBiometricListeningState = this::updateBiometricListeningState; |
Adrian Roos | d6aa6cb | 2015-04-16 19:31:29 -0700 | [diff] [blame] | 345 | |
| 346 | public synchronized static void setCurrentUser(int currentUser) { |
| 347 | sCurrentUser = currentUser; |
| 348 | } |
| 349 | |
| 350 | public synchronized static int getCurrentUser() { |
| 351 | return sCurrentUser; |
| 352 | } |
| 353 | |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 354 | @Override |
Adrian Roos | 94e15a5 | 2015-04-16 12:23:18 -0700 | [diff] [blame] | 355 | public void onTrustChanged(boolean enabled, int userId, int flags) { |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 356 | checkIsHandlerThread(); |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 357 | mUserHasTrust.put(userId, enabled); |
Adrian Roos | 2fe592d | 2014-05-17 03:11:59 +0200 | [diff] [blame] | 358 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 359 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 360 | if (cb != null) { |
| 361 | cb.onTrustChanged(userId); |
Adrian Roos | 94e15a5 | 2015-04-16 12:23:18 -0700 | [diff] [blame] | 362 | if (enabled && flags != 0) { |
| 363 | cb.onTrustGrantedWithFlags(flags, userId); |
Adrian Roos | 3c9a350 | 2014-08-06 19:09:45 +0200 | [diff] [blame] | 364 | } |
Adrian Roos | 2fe592d | 2014-05-17 03:11:59 +0200 | [diff] [blame] | 365 | } |
| 366 | } |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 367 | } |
| 368 | |
Lucas Dupin | ef88654 | 2018-01-03 16:03:07 -0800 | [diff] [blame] | 369 | @Override |
| 370 | public void onTrustError(CharSequence message) { |
| 371 | dispatchErrorMessage(message); |
| 372 | } |
| 373 | |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 374 | private void handleSimSubscriptionInfoChanged() { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 375 | checkIsHandlerThread(); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 376 | if (DEBUG_SIM_STATES) { |
| 377 | Log.v(TAG, "onSubscriptionInfoChanged()"); |
Fabian Kozynski | ccde55d | 2019-06-26 10:06:09 -0400 | [diff] [blame] | 378 | List<SubscriptionInfo> sil = mSubscriptionManager.getActiveSubscriptionInfoList(false); |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 379 | if (sil != null) { |
| 380 | for (SubscriptionInfo subInfo : sil) { |
| 381 | Log.v(TAG, "SubInfo:" + subInfo); |
| 382 | } |
| 383 | } else { |
| 384 | Log.v(TAG, "onSubscriptionInfoChanged: list is null"); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | List<SubscriptionInfo> subscriptionInfos = getSubscriptionInfo(true /* forceReload */); |
| 388 | |
| 389 | // Hack level over 9000: Because the subscription id is not yet valid when we see the |
| 390 | // first update in handleSimStateChange, we need to force refresh all all SIM states |
| 391 | // so the subscription id for them is consistent. |
Richard Chou | e0381b8 | 2018-04-24 03:48:59 +0000 | [diff] [blame] | 392 | ArrayList<SubscriptionInfo> changedSubscriptions = new ArrayList<>(); |
| 393 | for (int i = 0; i < subscriptionInfos.size(); i++) { |
| 394 | SubscriptionInfo info = subscriptionInfos.get(i); |
| 395 | boolean changed = refreshSimState(info.getSubscriptionId(), info.getSimSlotIndex()); |
| 396 | if (changed) { |
| 397 | changedSubscriptions.add(info); |
| 398 | } |
| 399 | } |
| 400 | for (int i = 0; i < changedSubscriptions.size(); i++) { |
| 401 | SimData data = mSimDatas.get(changedSubscriptions.get(i).getSubscriptionId()); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 402 | for (int j = 0; j < mCallbacks.size(); j++) { |
| 403 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get(); |
| 404 | if (cb != null) { |
| 405 | cb.onSimStateChanged(data.subId, data.slotId, data.simState); |
| 406 | } |
| 407 | } |
| 408 | } |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 409 | callbacksRefreshCarrierInfo(); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 410 | } |
| 411 | |
Jason Monk | 052082c | 2015-06-11 11:35:23 -0400 | [diff] [blame] | 412 | private void handleAirplaneModeChanged() { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 413 | callbacksRefreshCarrierInfo(); |
| 414 | } |
| 415 | |
| 416 | private void callbacksRefreshCarrierInfo() { |
| 417 | checkIsHandlerThread(); |
| 418 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 419 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
Jason Monk | 052082c | 2015-06-11 11:35:23 -0400 | [diff] [blame] | 420 | if (cb != null) { |
| 421 | cb.onRefreshCarrierInfo(); |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame] | 426 | /** |
| 427 | * @return List of SubscriptionInfo records, maybe empty but never null. |
| 428 | */ |
Adrian Roos | 316bf54 | 2016-08-23 17:53:07 +0200 | [diff] [blame] | 429 | public List<SubscriptionInfo> getSubscriptionInfo(boolean forceReload) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 430 | List<SubscriptionInfo> sil = mSubscriptionInfo; |
| 431 | if (sil == null || forceReload) { |
Fabian Kozynski | ccde55d | 2019-06-26 10:06:09 -0400 | [diff] [blame] | 432 | sil = mSubscriptionManager.getActiveSubscriptionInfoList(false); |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 433 | } |
| 434 | if (sil == null) { |
| 435 | // getActiveSubscriptionInfoList was null callers expect an empty list. |
| 436 | mSubscriptionInfo = new ArrayList<SubscriptionInfo>(); |
| 437 | } else { |
| 438 | mSubscriptionInfo = sil; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 439 | } |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame] | 440 | return new ArrayList<>(mSubscriptionInfo); |
| 441 | } |
| 442 | |
| 443 | /** |
| 444 | * This method returns filtered list of SubscriptionInfo from {@link #getSubscriptionInfo}. |
| 445 | * above. Maybe empty but never null. |
| 446 | * |
| 447 | * In DSDS mode if both subscriptions are grouped and one is opportunistic, we filter out one |
| 448 | * of them based on carrier config. e.g. In this case we should only show one carrier name |
| 449 | * on the status bar and quick settings. |
| 450 | */ |
| 451 | public List<SubscriptionInfo> getFilteredSubscriptionInfo(boolean forceReload) { |
| 452 | List<SubscriptionInfo> subscriptions = getSubscriptionInfo(false); |
| 453 | if (subscriptions.size() == MAX_PHONE_COUNT_DUAL_SIM) { |
| 454 | SubscriptionInfo info1 = subscriptions.get(0); |
| 455 | SubscriptionInfo info2 = subscriptions.get(1); |
| 456 | if (info1.getGroupUuid() != null && info1.getGroupUuid().equals(info2.getGroupUuid())) { |
| 457 | // If both subscriptions are primary, show both. |
| 458 | if (!info1.isOpportunistic() && !info2.isOpportunistic()) return subscriptions; |
| 459 | |
| 460 | // If carrier required, always show signal bar of primary subscription. |
| 461 | // Otherwise, show whichever subscription is currently active for Internet. |
| 462 | boolean alwaysShowPrimary = CarrierConfigManager.getDefaultConfig() |
| 463 | .getBoolean(CarrierConfigManager |
| 464 | .KEY_ALWAYS_SHOW_PRIMARY_SIGNAL_BAR_IN_OPPORTUNISTIC_NETWORK_BOOLEAN); |
| 465 | if (alwaysShowPrimary) { |
| 466 | subscriptions.remove(info1.isOpportunistic() ? info1 : info2); |
| 467 | } else { |
| 468 | subscriptions.remove(info1.getSubscriptionId() == mActiveMobileDataSubscription |
| 469 | ? info2 : info1); |
| 470 | } |
| 471 | |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | return subscriptions; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 476 | } |
| 477 | |
Adrian Roos | 7861c66 | 2014-07-25 15:37:28 +0200 | [diff] [blame] | 478 | @Override |
| 479 | public void onTrustManagedChanged(boolean managed, int userId) { |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 480 | checkIsHandlerThread(); |
Adrian Roos | 7861c66 | 2014-07-25 15:37:28 +0200 | [diff] [blame] | 481 | mUserTrustIsManaged.put(userId, managed); |
Lucas Dupin | f2c5350 | 2019-10-03 13:56:18 -0700 | [diff] [blame] | 482 | mUserTrustIsUsuallyManaged.put(userId, mTrustManager.isTrustUsuallyManaged(userId)); |
Adrian Roos | 7861c66 | 2014-07-25 15:37:28 +0200 | [diff] [blame] | 483 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 484 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 485 | if (cb != null) { |
| 486 | cb.onTrustManagedChanged(userId); |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
Kevin Chyn | f3b8fbd | 2017-05-03 22:24:31 -0700 | [diff] [blame] | 491 | /** |
| 492 | * Updates KeyguardUpdateMonitor's internal state to know if keyguard is goingAway |
Kevin Chyn | f3b8fbd | 2017-05-03 22:24:31 -0700 | [diff] [blame] | 493 | */ |
| 494 | public void setKeyguardGoingAway(boolean goingAway) { |
| 495 | mKeyguardGoingAway = goingAway; |
Kevin Chyn | e22f134 | 2017-09-26 10:03:38 -0700 | [diff] [blame] | 496 | updateFingerprintListeningState(); |
Kevin Chyn | f3b8fbd | 2017-05-03 22:24:31 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 499 | /** |
| 500 | * Updates KeyguardUpdateMonitor's internal state to know if keyguard is occluded |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 501 | */ |
| 502 | public void setKeyguardOccluded(boolean occluded) { |
| 503 | mKeyguardOccluded = occluded; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 504 | updateBiometricListeningState(); |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 507 | /** |
Kevin Chyn | 6951d3d | 2019-06-10 14:07:13 -0700 | [diff] [blame] | 508 | * Invoked when the secure camera is launched. |
| 509 | */ |
| 510 | public void onCameraLaunched() { |
| 511 | mSecureCameraLaunched = true; |
| 512 | updateBiometricListeningState(); |
| 513 | } |
| 514 | |
| 515 | /** |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 516 | * @return a cached version of DreamManager.isDreaming() |
| 517 | */ |
| 518 | public boolean isDreaming() { |
| 519 | return mIsDreaming; |
| 520 | } |
| 521 | |
| 522 | /** |
| 523 | * If the device is dreaming, awakens the device |
| 524 | */ |
| 525 | public void awakenFromDream() { |
| 526 | if (mIsDreaming && mDreamManager != null) { |
| 527 | try { |
| 528 | mDreamManager.awaken(); |
| 529 | } catch (RemoteException e) { |
| 530 | Log.e(TAG, "Unable to awaken from dream"); |
| 531 | } |
| 532 | } |
| 533 | } |
| 534 | |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 535 | @VisibleForTesting |
| 536 | protected void onFingerprintAuthenticated(int userId) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 537 | checkIsHandlerThread(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 538 | Trace.beginSection("KeyGuardUpdateMonitor#onFingerPrintAuthenticated"); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 539 | mUserFingerprintAuthenticated.put(userId, true); |
Kevin Chyn | 3fdbbf8 | 2017-05-06 15:11:53 -0700 | [diff] [blame] | 540 | // Update/refresh trust state only if user can skip bouncer |
| 541 | if (getUserCanSkipBouncer(userId)) { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 542 | mTrustManager.unlockedByBiometricForUser(userId, BiometricSourceType.FINGERPRINT); |
Kevin Chyn | 3fdbbf8 | 2017-05-06 15:11:53 -0700 | [diff] [blame] | 543 | } |
Kevin Chyn | 625a014 | 2017-04-10 14:53:59 -0700 | [diff] [blame] | 544 | // Don't send cancel if authentication succeeds |
| 545 | mFingerprintCancelSignal = null; |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 546 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 547 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 548 | if (cb != null) { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 549 | cb.onBiometricAuthenticated(userId, BiometricSourceType.FINGERPRINT); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 550 | } |
| 551 | } |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 552 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 553 | mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_BIOMETRIC_AUTHENTICATION_CONTINUE), |
| 554 | BIOMETRIC_CONTINUE_DELAY_MS); |
Kevin Chyn | 0f3e0b1 | 2017-07-20 16:56:11 -0700 | [diff] [blame] | 555 | |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 556 | // Only authenticate fingerprint once when assistant is visible |
| 557 | mAssistantVisible = false; |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 558 | |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 559 | Trace.endSection(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 562 | private void handleFingerprintAuthFailed() { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 563 | checkIsHandlerThread(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 564 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 565 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 566 | if (cb != null) { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 567 | cb.onBiometricAuthFailed(BiometricSourceType.FINGERPRINT); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 568 | } |
Jorim Jaggi | 007f0e8 | 2015-08-14 13:56:01 -0700 | [diff] [blame] | 569 | } |
Lucas Dupin | 51996bb | 2019-05-16 17:56:43 -0700 | [diff] [blame] | 570 | handleFingerprintHelp(BIOMETRIC_HELP_FINGERPRINT_NOT_RECOGNIZED, |
| 571 | mContext.getString(R.string.kg_fingerprint_not_recognized)); |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 572 | } |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 573 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 574 | private void handleFingerprintAcquired(int acquireInfo) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 575 | checkIsHandlerThread(); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 576 | if (acquireInfo != FingerprintManager.FINGERPRINT_ACQUIRED_GOOD) { |
| 577 | return; |
| 578 | } |
Jorim Jaggi | 007f0e8 | 2015-08-14 13:56:01 -0700 | [diff] [blame] | 579 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 580 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 581 | if (cb != null) { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 582 | cb.onBiometricAcquired(BiometricSourceType.FINGERPRINT); |
Jorim Jaggi | 007f0e8 | 2015-08-14 13:56:01 -0700 | [diff] [blame] | 583 | } |
| 584 | } |
| 585 | } |
| 586 | |
Jim Miller | 837fa7e | 2016-08-08 20:16:22 -0700 | [diff] [blame] | 587 | private void handleFingerprintAuthenticated(int authUserId) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 588 | Trace.beginSection("KeyGuardUpdateMonitor#handlerFingerPrintAuthenticated"); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 589 | try { |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 590 | final int userId; |
| 591 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 592 | userId = ActivityManager.getService().getCurrentUser().id; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 593 | } catch (RemoteException e) { |
| 594 | Log.e(TAG, "Failed to get current user id: ", e); |
| 595 | return; |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 596 | } |
Jim Miller | 837fa7e | 2016-08-08 20:16:22 -0700 | [diff] [blame] | 597 | if (userId != authUserId) { |
| 598 | Log.d(TAG, "Fingerprint authenticated for wrong user: " + authUserId); |
| 599 | return; |
| 600 | } |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 601 | if (isFingerprintDisabled(userId)) { |
| 602 | Log.d(TAG, "Fingerprint disabled by DPM for userId: " + userId); |
| 603 | return; |
| 604 | } |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 605 | onFingerprintAuthenticated(userId); |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 606 | } finally { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 607 | setFingerprintRunningState(BIOMETRIC_STATE_STOPPED); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 608 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 609 | Trace.endSection(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 612 | private void handleFingerprintHelp(int msgId, String helpString) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 613 | checkIsHandlerThread(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 614 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 615 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 616 | if (cb != null) { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 617 | cb.onBiometricHelp(msgId, helpString, BiometricSourceType.FINGERPRINT); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 618 | } |
| 619 | } |
| 620 | } |
| 621 | |
Kevin Chyn | 0c45b07 | 2017-04-24 16:27:11 -0700 | [diff] [blame] | 622 | private Runnable mRetryFingerprintAuthentication = new Runnable() { |
| 623 | @Override |
| 624 | public void run() { |
| 625 | Log.w(TAG, "Retrying fingerprint after HW unavailable, attempt " + |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 626 | mHardwareFingerprintUnavailableRetryCount); |
Kevin Chyn | 0c45b07 | 2017-04-24 16:27:11 -0700 | [diff] [blame] | 627 | updateFingerprintListeningState(); |
| 628 | } |
| 629 | }; |
| 630 | |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 631 | private void handleFingerprintError(int msgId, String errString) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 632 | checkIsHandlerThread(); |
joshmccloskey | 7dee454 | 2019-07-31 18:35:33 -0700 | [diff] [blame] | 633 | if (msgId == FingerprintManager.FINGERPRINT_ERROR_CANCELED && mHandler.hasCallbacks( |
| 634 | mCancelNotReceived)) { |
| 635 | mHandler.removeCallbacks(mCancelNotReceived); |
| 636 | } |
| 637 | |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 638 | if (msgId == FingerprintManager.FINGERPRINT_ERROR_CANCELED |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 639 | && mFingerprintRunningState == BIOMETRIC_STATE_CANCELLING_RESTARTING) { |
| 640 | setFingerprintRunningState(BIOMETRIC_STATE_STOPPED); |
Kevin Chyn | 1123ba7 | 2018-10-26 10:34:06 -0700 | [diff] [blame] | 641 | updateFingerprintListeningState(); |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 642 | } else { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 643 | setFingerprintRunningState(BIOMETRIC_STATE_STOPPED); |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 644 | } |
Kevin Chyn | 0c45b07 | 2017-04-24 16:27:11 -0700 | [diff] [blame] | 645 | |
| 646 | if (msgId == FingerprintManager.FINGERPRINT_ERROR_HW_UNAVAILABLE) { |
Kevin Chyn | e1ac0c0 | 2019-07-26 17:54:46 -0700 | [diff] [blame] | 647 | if (mHardwareFingerprintUnavailableRetryCount < HAL_ERROR_RETRY_MAX) { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 648 | mHardwareFingerprintUnavailableRetryCount++; |
Kevin Chyn | 0c45b07 | 2017-04-24 16:27:11 -0700 | [diff] [blame] | 649 | mHandler.removeCallbacks(mRetryFingerprintAuthentication); |
Kevin Chyn | e1ac0c0 | 2019-07-26 17:54:46 -0700 | [diff] [blame] | 650 | mHandler.postDelayed(mRetryFingerprintAuthentication, HAL_ERROR_RETRY_TIMEOUT); |
Kevin Chyn | 0c45b07 | 2017-04-24 16:27:11 -0700 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | |
Kevin Chyn | df9d33e | 2017-05-03 21:40:12 -0700 | [diff] [blame] | 654 | if (msgId == FingerprintManager.FINGERPRINT_ERROR_LOCKOUT_PERMANENT) { |
Lucas Dupin | 8eec268 | 2019-07-01 16:41:17 -0700 | [diff] [blame] | 655 | mLockPatternUtils.requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_LOCKOUT, |
Kevin Chyn | df9d33e | 2017-05-03 21:40:12 -0700 | [diff] [blame] | 656 | getCurrentUser()); |
| 657 | } |
| 658 | |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 659 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 660 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 661 | if (cb != null) { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 662 | cb.onBiometricError(msgId, errString, BiometricSourceType.FINGERPRINT); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | } |
| 666 | |
Jorim Jaggi | 3a46478 | 2015-08-28 16:59:13 -0700 | [diff] [blame] | 667 | private void handleFingerprintLockoutReset() { |
| 668 | updateFingerprintListeningState(); |
| 669 | } |
| 670 | |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 671 | private void setFingerprintRunningState(int fingerprintRunningState) { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 672 | boolean wasRunning = mFingerprintRunningState == BIOMETRIC_STATE_RUNNING; |
| 673 | boolean isRunning = fingerprintRunningState == BIOMETRIC_STATE_RUNNING; |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 674 | mFingerprintRunningState = fingerprintRunningState; |
Kevin Chyn | b4514d2 | 2019-04-15 13:47:25 -0700 | [diff] [blame] | 675 | Log.d(TAG, "fingerprintRunningState: " + mFingerprintRunningState); |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 676 | // Clients of KeyguardUpdateMonitor don't care about the internal state about the |
Kevin Chyn | b4514d2 | 2019-04-15 13:47:25 -0700 | [diff] [blame] | 677 | // asynchronousness of the cancel cycle. So only notify them if the actually running state |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 678 | // has changed. |
| 679 | if (wasRunning != isRunning) { |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 680 | notifyFingerprintRunningStateChanged(); |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | private void notifyFingerprintRunningStateChanged() { |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 685 | checkIsHandlerThread(); |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 686 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 687 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 688 | if (cb != null) { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 689 | cb.onBiometricRunningStateChanged(isFingerprintDetectionRunning(), |
| 690 | BiometricSourceType.FINGERPRINT); |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 691 | } |
| 692 | } |
| 693 | } |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 694 | |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 695 | @VisibleForTesting |
| 696 | protected void onFaceAuthenticated(int userId) { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 697 | Trace.beginSection("KeyGuardUpdateMonitor#onFaceAuthenticated"); |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 698 | checkIsHandlerThread(); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 699 | mUserFaceAuthenticated.put(userId, true); |
| 700 | // Update/refresh trust state only if user can skip bouncer |
| 701 | if (getUserCanSkipBouncer(userId)) { |
| 702 | mTrustManager.unlockedByBiometricForUser(userId, BiometricSourceType.FACE); |
| 703 | } |
| 704 | // Don't send cancel if authentication succeeds |
| 705 | mFaceCancelSignal = null; |
| 706 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 707 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 708 | if (cb != null) { |
| 709 | cb.onBiometricAuthenticated(userId, |
| 710 | BiometricSourceType.FACE); |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_BIOMETRIC_AUTHENTICATION_CONTINUE), |
| 715 | BIOMETRIC_CONTINUE_DELAY_MS); |
| 716 | |
| 717 | // Only authenticate face once when assistant is visible |
| 718 | mAssistantVisible = false; |
| 719 | |
| 720 | Trace.endSection(); |
| 721 | } |
| 722 | |
| 723 | private void handleFaceAuthFailed() { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 724 | checkIsHandlerThread(); |
Lucas Dupin | 3831481 | 2019-02-15 14:10:55 -0800 | [diff] [blame] | 725 | setFaceRunningState(BIOMETRIC_STATE_STOPPED); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 726 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 727 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 728 | if (cb != null) { |
| 729 | cb.onBiometricAuthFailed(BiometricSourceType.FACE); |
| 730 | } |
| 731 | } |
Lucas Dupin | 51996bb | 2019-05-16 17:56:43 -0700 | [diff] [blame] | 732 | handleFaceHelp(BIOMETRIC_HELP_FACE_NOT_RECOGNIZED, |
| 733 | mContext.getString(R.string.kg_face_not_recognized)); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | private void handleFaceAcquired(int acquireInfo) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 737 | checkIsHandlerThread(); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 738 | if (acquireInfo != FaceManager.FACE_ACQUIRED_GOOD) { |
| 739 | return; |
| 740 | } |
Lucas Dupin | 71d2fb2 | 2019-05-30 18:26:54 -0700 | [diff] [blame] | 741 | if (DEBUG_FACE) Log.d(TAG, "Face acquired"); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 742 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 743 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 744 | if (cb != null) { |
| 745 | cb.onBiometricAcquired(BiometricSourceType.FACE); |
| 746 | } |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | private void handleFaceAuthenticated(int authUserId) { |
| 751 | Trace.beginSection("KeyGuardUpdateMonitor#handlerFaceAuthenticated"); |
| 752 | try { |
Lucas Dupin | 9bae9c2 | 2019-06-04 16:37:40 -0700 | [diff] [blame] | 753 | if (mGoingToSleep) { |
| 754 | Log.d(TAG, "Aborted successful auth because device is going to sleep."); |
| 755 | return; |
| 756 | } |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 757 | final int userId; |
| 758 | try { |
| 759 | userId = ActivityManager.getService().getCurrentUser().id; |
| 760 | } catch (RemoteException e) { |
| 761 | Log.e(TAG, "Failed to get current user id: ", e); |
| 762 | return; |
| 763 | } |
| 764 | if (userId != authUserId) { |
| 765 | Log.d(TAG, "Face authenticated for wrong user: " + authUserId); |
| 766 | return; |
| 767 | } |
| 768 | if (isFaceDisabled(userId)) { |
| 769 | Log.d(TAG, "Face authentication disabled by DPM for userId: " + userId); |
| 770 | return; |
| 771 | } |
Lucas Dupin | 71d2fb2 | 2019-05-30 18:26:54 -0700 | [diff] [blame] | 772 | if (DEBUG_FACE) Log.d(TAG, "Face auth succeeded for user " + userId); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 773 | onFaceAuthenticated(userId); |
| 774 | } finally { |
| 775 | setFaceRunningState(BIOMETRIC_STATE_STOPPED); |
| 776 | } |
| 777 | Trace.endSection(); |
| 778 | } |
| 779 | |
| 780 | private void handleFaceHelp(int msgId, String helpString) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 781 | checkIsHandlerThread(); |
Lucas Dupin | 71d2fb2 | 2019-05-30 18:26:54 -0700 | [diff] [blame] | 782 | if (DEBUG_FACE) Log.d(TAG, "Face help received: " + helpString); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 783 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 784 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 785 | if (cb != null) { |
| 786 | cb.onBiometricHelp(msgId, helpString, BiometricSourceType.FACE); |
| 787 | } |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | private Runnable mRetryFaceAuthentication = new Runnable() { |
| 792 | @Override |
| 793 | public void run() { |
| 794 | Log.w(TAG, "Retrying face after HW unavailable, attempt " + |
| 795 | mHardwareFaceUnavailableRetryCount); |
| 796 | updateFaceListeningState(); |
| 797 | } |
| 798 | }; |
| 799 | |
| 800 | private void handleFaceError(int msgId, String errString) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 801 | checkIsHandlerThread(); |
Lucas Dupin | 71d2fb2 | 2019-05-30 18:26:54 -0700 | [diff] [blame] | 802 | if (DEBUG_FACE) Log.d(TAG, "Face error received: " + errString); |
joshmccloskey | 7dee454 | 2019-07-31 18:35:33 -0700 | [diff] [blame] | 803 | if (msgId == FaceManager.FACE_ERROR_CANCELED && mHandler.hasCallbacks(mCancelNotReceived)) { |
| 804 | mHandler.removeCallbacks(mCancelNotReceived); |
| 805 | } |
| 806 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 807 | if (msgId == FaceManager.FACE_ERROR_CANCELED |
| 808 | && mFaceRunningState == BIOMETRIC_STATE_CANCELLING_RESTARTING) { |
| 809 | setFaceRunningState(BIOMETRIC_STATE_STOPPED); |
Kevin Chyn | 1123ba7 | 2018-10-26 10:34:06 -0700 | [diff] [blame] | 810 | updateFaceListeningState(); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 811 | } else { |
| 812 | setFaceRunningState(BIOMETRIC_STATE_STOPPED); |
| 813 | } |
| 814 | |
Kevin Chyn | e1ac0c0 | 2019-07-26 17:54:46 -0700 | [diff] [blame] | 815 | if (msgId == FaceManager.FACE_ERROR_HW_UNAVAILABLE |
| 816 | || msgId == FaceManager.FACE_ERROR_UNABLE_TO_PROCESS) { |
| 817 | if (mHardwareFaceUnavailableRetryCount < HAL_ERROR_RETRY_MAX) { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 818 | mHardwareFaceUnavailableRetryCount++; |
| 819 | mHandler.removeCallbacks(mRetryFaceAuthentication); |
Kevin Chyn | e1ac0c0 | 2019-07-26 17:54:46 -0700 | [diff] [blame] | 820 | mHandler.postDelayed(mRetryFaceAuthentication, HAL_ERROR_RETRY_TIMEOUT); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 821 | } |
| 822 | } |
| 823 | |
| 824 | if (msgId == FaceManager.FACE_ERROR_LOCKOUT_PERMANENT) { |
Lucas Dupin | 8eec268 | 2019-07-01 16:41:17 -0700 | [diff] [blame] | 825 | mLockPatternUtils.requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_LOCKOUT, |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 826 | getCurrentUser()); |
| 827 | } |
| 828 | |
| 829 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 830 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 831 | if (cb != null) { |
| 832 | cb.onBiometricError(msgId, errString, |
| 833 | BiometricSourceType.FACE); |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | private void handleFaceLockoutReset() { |
| 839 | updateFaceListeningState(); |
| 840 | } |
| 841 | |
| 842 | private void setFaceRunningState(int faceRunningState) { |
| 843 | boolean wasRunning = mFaceRunningState == BIOMETRIC_STATE_RUNNING; |
| 844 | boolean isRunning = faceRunningState == BIOMETRIC_STATE_RUNNING; |
| 845 | mFaceRunningState = faceRunningState; |
Kevin Chyn | b4514d2 | 2019-04-15 13:47:25 -0700 | [diff] [blame] | 846 | Log.d(TAG, "faceRunningState: " + mFaceRunningState); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 847 | // Clients of KeyguardUpdateMonitor don't care about the internal state or about the |
Kevin Chyn | b4514d2 | 2019-04-15 13:47:25 -0700 | [diff] [blame] | 848 | // asynchronousness of the cancel cycle. So only notify them if the actually running state |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 849 | // has changed. |
| 850 | if (wasRunning != isRunning) { |
| 851 | notifyFaceRunningStateChanged(); |
| 852 | } |
| 853 | } |
| 854 | |
| 855 | private void notifyFaceRunningStateChanged() { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 856 | checkIsHandlerThread(); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 857 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 858 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 859 | if (cb != null) { |
| 860 | cb.onBiometricRunningStateChanged(isFaceDetectionRunning(), |
| 861 | BiometricSourceType.FACE); |
| 862 | } |
| 863 | } |
| 864 | } |
| 865 | |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 866 | private void handleFaceUnlockStateChanged(boolean running, int userId) { |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 867 | checkIsHandlerThread(); |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 868 | mUserFaceUnlockRunning.put(userId, running); |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 869 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 870 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 871 | if (cb != null) { |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 872 | cb.onFaceUnlockStateChanged(running, userId); |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 873 | } |
| 874 | } |
| 875 | } |
| 876 | |
Adrian Roos | 4a41017 | 2014-08-20 17:41:44 +0200 | [diff] [blame] | 877 | public boolean isFaceUnlockRunning(int userId) { |
| 878 | return mUserFaceUnlockRunning.get(userId); |
| 879 | } |
| 880 | |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 881 | public boolean isFingerprintDetectionRunning() { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 882 | return mFingerprintRunningState == BIOMETRIC_STATE_RUNNING; |
| 883 | } |
| 884 | |
| 885 | public boolean isFaceDetectionRunning() { |
| 886 | return mFaceRunningState == BIOMETRIC_STATE_RUNNING; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 889 | private boolean isTrustDisabled(int userId) { |
Adrian Roos | a4da9f6 | 2015-02-21 01:15:21 +0100 | [diff] [blame] | 890 | // Don't allow trust agent if device is secured with a SIM PIN. This is here |
| 891 | // mainly because there's no other way to prompt the user to enter their SIM PIN |
| 892 | // once they get past the keyguard screen. |
| 893 | final boolean disabledBySimPin = isSimPinSecure(); |
| 894 | return disabledBySimPin; |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 895 | } |
| 896 | |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 897 | private boolean isFingerprintDisabled(int userId) { |
| 898 | final DevicePolicyManager dpm = |
| 899 | (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE); |
| 900 | return dpm != null && (dpm.getKeyguardDisabledFeatures(null, userId) |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 901 | & DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT) != 0 |
Adrian Roos | 733b663 | 2015-08-21 14:32:35 -0700 | [diff] [blame] | 902 | || isSimPinSecure(); |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 903 | } |
| 904 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 905 | private boolean isFaceDisabled(int userId) { |
| 906 | final DevicePolicyManager dpm = |
| 907 | (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE); |
Lucas Dupin | 8968f6a | 2019-08-09 17:41:15 -0700 | [diff] [blame] | 908 | // TODO(b/140035044) |
| 909 | return whitelistIpcs(() -> dpm != null && (dpm.getKeyguardDisabledFeatures(null, userId) |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 910 | & DevicePolicyManager.KEYGUARD_DISABLE_FACE) != 0 |
Lucas Dupin | 8968f6a | 2019-08-09 17:41:15 -0700 | [diff] [blame] | 911 | || isSimPinSecure()); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | |
Selim Cinek | e8bae62 | 2015-07-15 13:24:06 -0700 | [diff] [blame] | 915 | public boolean getUserCanSkipBouncer(int userId) { |
Steven Wu | cfe398d | 2019-03-21 11:32:15 -0400 | [diff] [blame] | 916 | return getUserHasTrust(userId) || getUserUnlockedWithBiometric(userId); |
Selim Cinek | e8bae62 | 2015-07-15 13:24:06 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 919 | public boolean getUserHasTrust(int userId) { |
Selim Cinek | e8bae62 | 2015-07-15 13:24:06 -0700 | [diff] [blame] | 920 | return !isTrustDisabled(userId) && mUserHasTrust.get(userId); |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 921 | } |
| 922 | |
Steven Wu | cfe398d | 2019-03-21 11:32:15 -0400 | [diff] [blame] | 923 | /** |
| 924 | * Returns whether the user is unlocked with biometrics. |
| 925 | */ |
| 926 | public boolean getUserUnlockedWithBiometric(int userId) { |
| 927 | boolean fingerprintOrFace = mUserFingerprintAuthenticated.get(userId) |
| 928 | || mUserFaceAuthenticated.get(userId); |
| 929 | return fingerprintOrFace && isUnlockingWithBiometricAllowed(); |
| 930 | } |
| 931 | |
Adrian Roos | 7861c66 | 2014-07-25 15:37:28 +0200 | [diff] [blame] | 932 | public boolean getUserTrustIsManaged(int userId) { |
| 933 | return mUserTrustIsManaged.get(userId) && !isTrustDisabled(userId); |
| 934 | } |
| 935 | |
Lucas Dupin | f2c5350 | 2019-10-03 13:56:18 -0700 | [diff] [blame] | 936 | /** |
| 937 | * Cached version of {@link TrustManager#isTrustUsuallyManaged(int)}. |
| 938 | */ |
| 939 | public boolean isTrustUsuallyManaged(int userId) { |
| 940 | checkIsHandlerThread(); |
| 941 | return mUserTrustIsUsuallyManaged.get(userId); |
| 942 | } |
| 943 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 944 | public boolean isUnlockingWithBiometricAllowed() { |
| 945 | return mStrongAuthTracker.isUnlockingWithBiometricAllowed(); |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 946 | } |
| 947 | |
Lucas Dupin | 1601382 | 2018-05-17 18:00:16 -0700 | [diff] [blame] | 948 | public boolean isUserInLockdown(int userId) { |
Lucas Dupin | 8eec268 | 2019-07-01 16:41:17 -0700 | [diff] [blame] | 949 | return containsFlag(mStrongAuthTracker.getStrongAuthForUser(userId), |
| 950 | STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN); |
Lucas Dupin | 1601382 | 2018-05-17 18:00:16 -0700 | [diff] [blame] | 951 | } |
| 952 | |
Lucas Dupin | 7825b94 | 2019-06-03 20:22:39 -0700 | [diff] [blame] | 953 | public boolean userNeedsStrongAuth() { |
| 954 | return mStrongAuthTracker.getStrongAuthForUser(getCurrentUser()) |
| 955 | != LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED; |
| 956 | } |
| 957 | |
Lucas Dupin | 8eec268 | 2019-07-01 16:41:17 -0700 | [diff] [blame] | 958 | private boolean containsFlag(int haystack, int needle) { |
| 959 | return (haystack & needle) != 0; |
| 960 | } |
| 961 | |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 962 | public boolean needsSlowUnlockTransition() { |
| 963 | return mNeedsSlowUnlockTransition; |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 964 | } |
| 965 | |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 966 | public StrongAuthTracker getStrongAuthTracker() { |
| 967 | return mStrongAuthTracker; |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 968 | } |
| 969 | |
Adrian Roos | 1de8bcb | 2015-08-19 16:52:52 -0700 | [diff] [blame] | 970 | private void notifyStrongAuthStateChanged(int userId) { |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 971 | checkIsHandlerThread(); |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 972 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 973 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 974 | if (cb != null) { |
Adrian Roos | 1de8bcb | 2015-08-19 16:52:52 -0700 | [diff] [blame] | 975 | cb.onStrongAuthStateChanged(userId); |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 976 | } |
| 977 | } |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 978 | } |
| 979 | |
Adrian Roos | 91ba307 | 2017-02-14 16:50:46 +0100 | [diff] [blame] | 980 | public boolean isScreenOn() { |
| 981 | return mScreenOn; |
| 982 | } |
| 983 | |
Lucas Dupin | ef88654 | 2018-01-03 16:03:07 -0800 | [diff] [blame] | 984 | private void dispatchErrorMessage(CharSequence message) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 985 | checkIsHandlerThread(); |
Lucas Dupin | ef88654 | 2018-01-03 16:03:07 -0800 | [diff] [blame] | 986 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 987 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 988 | if (cb != null) { |
| 989 | cb.onTrustAgentErrorMessage(message); |
| 990 | } |
| 991 | } |
| 992 | } |
| 993 | |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 994 | @VisibleForTesting |
| 995 | void setAssistantVisible(boolean assistantVisible) { |
| 996 | mAssistantVisible = assistantVisible; |
| 997 | updateBiometricListeningState(); |
| 998 | } |
| 999 | |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 1000 | static class DisplayClientState { |
| 1001 | public int clientGeneration; |
| 1002 | public boolean clearing; |
| 1003 | public PendingIntent intent; |
| 1004 | public int playbackState; |
| 1005 | public long playbackEventTime; |
| 1006 | } |
| 1007 | |
| 1008 | private DisplayClientState mDisplayClientState = new DisplayClientState(); |
| 1009 | |
Lucas Dupin | 5e0f0d2 | 2018-02-26 13:32:16 -0800 | [diff] [blame] | 1010 | @VisibleForTesting |
Lucas Dupin | 7ff82b0 | 2018-05-16 12:14:10 -0700 | [diff] [blame] | 1011 | protected final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1012 | |
Jim Miller | d72d5ac | 2015-09-29 18:55:32 -0700 | [diff] [blame] | 1013 | @Override |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1014 | public void onReceive(Context context, Intent intent) { |
| 1015 | final String action = intent.getAction(); |
| 1016 | if (DEBUG) Log.d(TAG, "received broadcast " + action); |
| 1017 | |
| 1018 | if (Intent.ACTION_TIME_TICK.equals(action) |
Robert Snoeberger | 9c1074f | 2018-12-07 17:35:21 -0500 | [diff] [blame] | 1019 | || Intent.ACTION_TIME_CHANGED.equals(action)) { |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 1020 | mHandler.sendEmptyMessage(MSG_TIME_UPDATE); |
Robert Snoeberger | 9c1074f | 2018-12-07 17:35:21 -0500 | [diff] [blame] | 1021 | } else if (Intent.ACTION_TIMEZONE_CHANGED.equals(action)) { |
| 1022 | final Message msg = mHandler.obtainMessage( |
| 1023 | MSG_TIMEZONE_UPDATE, intent.getStringExtra("time-zone")); |
| 1024 | mHandler.sendMessage(msg); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1025 | } else if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { |
| 1026 | final int status = intent.getIntExtra(EXTRA_STATUS, BATTERY_STATUS_UNKNOWN); |
| 1027 | final int plugged = intent.getIntExtra(EXTRA_PLUGGED, 0); |
| 1028 | final int level = intent.getIntExtra(EXTRA_LEVEL, 0); |
| 1029 | final int health = intent.getIntExtra(EXTRA_HEALTH, BATTERY_HEALTH_UNKNOWN); |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 1030 | |
| 1031 | final int maxChargingMicroAmp = intent.getIntExtra(EXTRA_MAX_CHARGING_CURRENT, -1); |
| 1032 | int maxChargingMicroVolt = intent.getIntExtra(EXTRA_MAX_CHARGING_VOLTAGE, -1); |
| 1033 | final int maxChargingMicroWatt; |
| 1034 | |
| 1035 | if (maxChargingMicroVolt <= 0) { |
| 1036 | maxChargingMicroVolt = DEFAULT_CHARGING_VOLTAGE_MICRO_VOLT; |
| 1037 | } |
| 1038 | if (maxChargingMicroAmp > 0) { |
| 1039 | // Calculating muW = muA * muV / (10^6 mu^2 / mu); splitting up the divisor |
| 1040 | // to maintain precision equally on both factors. |
| 1041 | maxChargingMicroWatt = (maxChargingMicroAmp / 1000) |
| 1042 | * (maxChargingMicroVolt / 1000); |
| 1043 | } else { |
| 1044 | maxChargingMicroWatt = -1; |
| 1045 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1046 | final Message msg = mHandler.obtainMessage( |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 1047 | MSG_BATTERY_UPDATE, new BatteryStatus(status, level, plugged, health, |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 1048 | maxChargingMicroWatt)); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1049 | mHandler.sendMessage(msg); |
| 1050 | } else if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)) { |
Bill Lin | ef81cbd | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 1051 | SimData args = SimData.fromIntent(intent); |
Lucas Dupin | 5e0f0d2 | 2018-02-26 13:32:16 -0800 | [diff] [blame] | 1052 | // ACTION_SIM_STATE_CHANGED is rebroadcast after unlocking the device to |
| 1053 | // keep compatibility with apps that aren't direct boot aware. |
| 1054 | // SysUI should just ignore this broadcast because it was already received |
| 1055 | // and processed previously. |
| 1056 | if (intent.getBooleanExtra(TelephonyIntents.EXTRA_REBROADCAST_ON_UNLOCK, false)) { |
Bill Lin | ef81cbd | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 1057 | // Guarantee mTelephonyCapable state after SysUI crash and restart |
| 1058 | if (args.simState == State.ABSENT) { |
| 1059 | mHandler.obtainMessage(MSG_TELEPHONY_CAPABLE, true).sendToTarget(); |
| 1060 | } |
Lucas Dupin | 5e0f0d2 | 2018-02-26 13:32:16 -0800 | [diff] [blame] | 1061 | return; |
| 1062 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1063 | if (DEBUG_SIM_STATES) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1064 | Log.v(TAG, "action " + action |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1065 | + " state: " + intent.getStringExtra( |
| 1066 | IccCardConstants.INTENT_KEY_ICC_STATE) |
| 1067 | + " slotId: " + args.slotId + " subid: " + args.subId); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1068 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1069 | mHandler.obtainMessage(MSG_SIM_STATE_CHANGE, args.subId, args.slotId, args.simState) |
| 1070 | .sendToTarget(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1071 | } else if (AudioManager.RINGER_MODE_CHANGED_ACTION.equals(action)) { |
| 1072 | mHandler.sendMessage(mHandler.obtainMessage(MSG_RINGER_MODE_CHANGED, |
| 1073 | intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1), 0)); |
| 1074 | } else if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(action)) { |
| 1075 | String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); |
| 1076 | mHandler.sendMessage(mHandler.obtainMessage(MSG_PHONE_STATE_CHANGED, state)); |
Jason Monk | 052082c | 2015-06-11 11:35:23 -0400 | [diff] [blame] | 1077 | } else if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(action)) { |
| 1078 | mHandler.sendEmptyMessage(MSG_AIRPLANE_MODE_CHANGED); |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 1079 | } else if (Intent.ACTION_BOOT_COMPLETED.equals(action)) { |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 1080 | dispatchBootCompleted(); |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 1081 | } else if (TelephonyIntents.ACTION_SERVICE_STATE_CHANGED.equals(action)) { |
| 1082 | ServiceState serviceState = ServiceState.newFromBundle(intent.getExtras()); |
| 1083 | int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, |
| 1084 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
| 1085 | if (DEBUG) { |
| 1086 | Log.v(TAG, "action " + action + " serviceState=" + serviceState + " subId=" |
| 1087 | + subId); |
| 1088 | } |
Bonian Chen | a7e9e8c | 2019-06-02 23:59:31 +0000 | [diff] [blame] | 1089 | mHandler.sendMessage( |
| 1090 | mHandler.obtainMessage(MSG_SERVICE_STATE_CHANGE, subId, 0, serviceState)); |
Fabian Kozynski | ccde55d | 2019-06-26 10:06:09 -0400 | [diff] [blame] | 1091 | } else if (TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED.equals(action)) { |
| 1092 | mHandler.sendEmptyMessage(MSG_SIM_SUBSCRIPTION_INFO_CHANGED); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 1093 | } else if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED.equals( |
| 1094 | action)) { |
| 1095 | mHandler.sendEmptyMessage(MSG_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1096 | } |
| 1097 | } |
| 1098 | }; |
Jim Miller | 2de5ee8 | 2012-06-14 22:22:50 -0700 | [diff] [blame] | 1099 | |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 1100 | @VisibleForTesting |
| 1101 | protected final BroadcastReceiver mBroadcastAllReceiver = new BroadcastReceiver() { |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 1102 | |
Jim Miller | d72d5ac | 2015-09-29 18:55:32 -0700 | [diff] [blame] | 1103 | @Override |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 1104 | public void onReceive(Context context, Intent intent) { |
| 1105 | final String action = intent.getAction(); |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 1106 | if (AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED.equals(action)) { |
| 1107 | mHandler.sendEmptyMessage(MSG_TIME_UPDATE); |
| 1108 | } else if (Intent.ACTION_USER_INFO_CHANGED.equals(action)) { |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 1109 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_INFO_CHANGED, |
| 1110 | intent.getIntExtra(Intent.EXTRA_USER_HANDLE, getSendingUserId()), 0)); |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 1111 | } else if (ACTION_FACE_UNLOCK_STARTED.equals(action)) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1112 | Trace.beginSection( |
| 1113 | "KeyguardUpdateMonitor.mBroadcastAllReceiver#onReceive " |
| 1114 | + "ACTION_FACE_UNLOCK_STARTED"); |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 1115 | mHandler.sendMessage(mHandler.obtainMessage(MSG_FACE_UNLOCK_STATE_CHANGED, 1, |
| 1116 | getSendingUserId())); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1117 | Trace.endSection(); |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 1118 | } else if (ACTION_FACE_UNLOCK_STOPPED.equals(action)) { |
| 1119 | mHandler.sendMessage(mHandler.obtainMessage(MSG_FACE_UNLOCK_STATE_CHANGED, 0, |
| 1120 | getSendingUserId())); |
| 1121 | } else if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 1122 | .equals(action)) { |
| 1123 | mHandler.sendEmptyMessage(MSG_DPM_STATE_CHANGED); |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 1124 | } else if (ACTION_USER_UNLOCKED.equals(action)) { |
Lucas Dupin | 6c6d573 | 2019-08-27 17:36:05 -0700 | [diff] [blame] | 1125 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_UNLOCKED, |
| 1126 | getSendingUserId(), 0)); |
| 1127 | } else if (ACTION_USER_STOPPED.equals(action)) { |
| 1128 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_STOPPED, |
| 1129 | intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1), 0)); |
| 1130 | } else if (ACTION_USER_REMOVED.equals(action)) { |
| 1131 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_REMOVED, |
| 1132 | intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1), 0)); |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 1133 | } |
| 1134 | } |
| 1135 | }; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1136 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1137 | private final FingerprintManager.LockoutResetCallback mFingerprintLockoutResetCallback |
Jorim Jaggi | 3a46478 | 2015-08-28 16:59:13 -0700 | [diff] [blame] | 1138 | = new FingerprintManager.LockoutResetCallback() { |
| 1139 | @Override |
| 1140 | public void onLockoutReset() { |
| 1141 | handleFingerprintLockoutReset(); |
| 1142 | } |
| 1143 | }; |
| 1144 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1145 | private final FaceManager.LockoutResetCallback mFaceLockoutResetCallback |
| 1146 | = new FaceManager.LockoutResetCallback() { |
| 1147 | @Override |
| 1148 | public void onLockoutReset() { |
| 1149 | handleFaceLockoutReset(); |
| 1150 | } |
| 1151 | }; |
| 1152 | |
| 1153 | private FingerprintManager.AuthenticationCallback mFingerprintAuthenticationCallback |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1154 | = new AuthenticationCallback() { |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 1155 | |
| 1156 | @Override |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 1157 | public void onAuthenticationFailed() { |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 1158 | handleFingerprintAuthFailed(); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1159 | } |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 1160 | |
| 1161 | @Override |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1162 | public void onAuthenticationSucceeded(AuthenticationResult result) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1163 | Trace.beginSection("KeyguardUpdateMonitor#onAuthenticationSucceeded"); |
Jim Miller | 837fa7e | 2016-08-08 20:16:22 -0700 | [diff] [blame] | 1164 | handleFingerprintAuthenticated(result.getUserId()); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1165 | Trace.endSection(); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | @Override |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1169 | public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) { |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 1170 | handleFingerprintHelp(helpMsgId, helpString.toString()); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | @Override |
| 1174 | public void onAuthenticationError(int errMsgId, CharSequence errString) { |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 1175 | handleFingerprintError(errMsgId, errString.toString()); |
| 1176 | } |
| 1177 | |
| 1178 | @Override |
| 1179 | public void onAuthenticationAcquired(int acquireInfo) { |
| 1180 | handleFingerprintAcquired(acquireInfo); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 1181 | } |
| 1182 | }; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1183 | |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 1184 | @VisibleForTesting |
| 1185 | FaceManager.AuthenticationCallback mFaceAuthenticationCallback |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1186 | = new FaceManager.AuthenticationCallback() { |
| 1187 | |
| 1188 | @Override |
| 1189 | public void onAuthenticationFailed() { |
| 1190 | handleFaceAuthFailed(); |
| 1191 | } |
| 1192 | |
| 1193 | @Override |
| 1194 | public void onAuthenticationSucceeded(FaceManager.AuthenticationResult result) { |
| 1195 | Trace.beginSection("KeyguardUpdateMonitor#onAuthenticationSucceeded"); |
| 1196 | handleFaceAuthenticated(result.getUserId()); |
| 1197 | Trace.endSection(); |
| 1198 | } |
| 1199 | |
| 1200 | @Override |
| 1201 | public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) { |
| 1202 | handleFaceHelp(helpMsgId, helpString.toString()); |
| 1203 | } |
| 1204 | |
| 1205 | @Override |
| 1206 | public void onAuthenticationError(int errMsgId, CharSequence errString) { |
| 1207 | handleFaceError(errMsgId, errString.toString()); |
| 1208 | } |
| 1209 | |
| 1210 | @Override |
| 1211 | public void onAuthenticationAcquired(int acquireInfo) { |
| 1212 | handleFaceAcquired(acquireInfo); |
| 1213 | } |
| 1214 | }; |
| 1215 | |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1216 | private CancellationSignal mFingerprintCancelSignal; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1217 | private CancellationSignal mFaceCancelSignal; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1218 | private FingerprintManager mFpm; |
Kevin Chyn | b7b54a6 | 2018-09-28 18:48:12 -0700 | [diff] [blame] | 1219 | private FaceManager mFaceManager; |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 1220 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1221 | /** |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 1222 | * When we receive a |
| 1223 | * {@link com.android.internal.telephony.TelephonyIntents#ACTION_SIM_STATE_CHANGED} broadcast, |
Wink Saville | 37c124c | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 1224 | * 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] | 1225 | * 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] | 1226 | * the intent and provide a {@link SimCard.State} result. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1227 | */ |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1228 | private static class SimData { |
| 1229 | public State simState; |
| 1230 | public int slotId; |
| 1231 | public int subId; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1232 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1233 | SimData(State state, int slot, int id) { |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 1234 | simState = state; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1235 | slotId = slot; |
| 1236 | subId = id; |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 1237 | } |
| 1238 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1239 | static SimData fromIntent(Intent intent) { |
| 1240 | State state; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1241 | if (!TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(intent.getAction())) { |
| 1242 | throw new IllegalArgumentException("only handles intent ACTION_SIM_STATE_CHANGED"); |
| 1243 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1244 | String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE); |
Jayachandran C | bd48135 | 2019-05-21 16:02:23 -0700 | [diff] [blame] | 1245 | int slotId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1246 | int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1247 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1248 | if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) { |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 1249 | final String absentReason = intent |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1250 | .getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON); |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 1251 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1252 | if (IccCardConstants.INTENT_VALUE_ABSENT_ON_PERM_DISABLED.equals( |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 1253 | absentReason)) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1254 | state = IccCardConstants.State.PERM_DISABLED; |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 1255 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1256 | state = IccCardConstants.State.ABSENT; |
John Wang | b0b24b3 | 2011-06-10 17:23:51 -0700 | [diff] [blame] | 1257 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1258 | } else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) { |
| 1259 | state = IccCardConstants.State.READY; |
| 1260 | } else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1261 | final String lockedReason = intent |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1262 | .getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON); |
| 1263 | if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) { |
| 1264 | state = IccCardConstants.State.PIN_REQUIRED; |
| 1265 | } else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) { |
| 1266 | state = IccCardConstants.State.PUK_REQUIRED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1267 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1268 | state = IccCardConstants.State.UNKNOWN; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1269 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1270 | } else if (IccCardConstants.INTENT_VALUE_LOCKED_NETWORK.equals(stateExtra)) { |
| 1271 | state = IccCardConstants.State.NETWORK_LOCKED; |
Wileen Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 1272 | } else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) { |
| 1273 | state = IccCardConstants.State.CARD_IO_ERROR; |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 1274 | } else if (IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(stateExtra) |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1275 | || IccCardConstants.INTENT_VALUE_ICC_IMSI.equals(stateExtra)) { |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 1276 | // This is required because telephony doesn't return to "READY" after |
| 1277 | // these state transitions. See bug 7197471. |
| 1278 | state = IccCardConstants.State.READY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1279 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1280 | state = IccCardConstants.State.UNKNOWN; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1281 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1282 | return new SimData(state, slotId, subId); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1283 | } |
| 1284 | |
Jim Miller | d72d5ac | 2015-09-29 18:55:32 -0700 | [diff] [blame] | 1285 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1286 | public String toString() { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 1287 | return "SimData{state=" + simState + ",slotId=" + slotId + ",subId=" + subId + "}"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1288 | } |
| 1289 | } |
| 1290 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 1291 | public static class BatteryStatus { |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 1292 | public static final int CHARGING_UNKNOWN = -1; |
| 1293 | public static final int CHARGING_SLOWLY = 0; |
| 1294 | public static final int CHARGING_REGULAR = 1; |
| 1295 | public static final int CHARGING_FAST = 2; |
| 1296 | |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1297 | public final int status; |
| 1298 | public final int level; |
| 1299 | public final int plugged; |
| 1300 | public final int health; |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 1301 | public final int maxChargingWattage; |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1302 | |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 1303 | public BatteryStatus(int status, int level, int plugged, int health, |
| 1304 | int maxChargingWattage) { |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1305 | this.status = status; |
| 1306 | this.level = level; |
| 1307 | this.plugged = plugged; |
| 1308 | this.health = health; |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 1309 | this.maxChargingWattage = maxChargingWattage; |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1310 | } |
| 1311 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1312 | /** |
Brian Muramatsu | a92a01b | 2012-09-05 21:54:39 -0700 | [diff] [blame] | 1313 | * Determine whether the device is plugged in (USB, power, or wireless). |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1314 | * |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1315 | * @return true if the device is plugged in. |
| 1316 | */ |
Adrian Roos | ad3bc7f | 2014-10-30 18:29:38 +0100 | [diff] [blame] | 1317 | public boolean isPluggedIn() { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1318 | return plugged == BatteryManager.BATTERY_PLUGGED_AC |
Brian Muramatsu | a92a01b | 2012-09-05 21:54:39 -0700 | [diff] [blame] | 1319 | || plugged == BatteryManager.BATTERY_PLUGGED_USB |
| 1320 | || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | /** |
Beverly | 2034c83 | 2018-03-19 11:18:51 -0400 | [diff] [blame] | 1324 | * Determine whether the device is plugged in (USB, power). |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1325 | * |
Beverly | 2034c83 | 2018-03-19 11:18:51 -0400 | [diff] [blame] | 1326 | * @return true if the device is plugged in wired (as opposed to wireless) |
| 1327 | */ |
| 1328 | public boolean isPluggedInWired() { |
| 1329 | return plugged == BatteryManager.BATTERY_PLUGGED_AC |
| 1330 | || plugged == BatteryManager.BATTERY_PLUGGED_USB; |
| 1331 | } |
| 1332 | |
| 1333 | /** |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1334 | * Whether or not the device is charged. Note that some devices never return 100% for |
| 1335 | * battery level, so this allows either battery level or status to determine if the |
| 1336 | * battery is charged. |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1337 | * |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1338 | * @return true if the device is charged |
| 1339 | */ |
| 1340 | public boolean isCharged() { |
| 1341 | return status == BATTERY_STATUS_FULL || level >= 100; |
| 1342 | } |
| 1343 | |
| 1344 | /** |
| 1345 | * Whether battery is low and needs to be charged. |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1346 | * |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1347 | * @return true if battery is low |
| 1348 | */ |
| 1349 | public boolean isBatteryLow() { |
| 1350 | return level < LOW_BATTERY_THRESHOLD; |
| 1351 | } |
| 1352 | |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 1353 | public final int getChargingSpeed(int slowThreshold, int fastThreshold) { |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 1354 | return maxChargingWattage <= 0 ? CHARGING_UNKNOWN : |
| 1355 | maxChargingWattage < slowThreshold ? CHARGING_SLOWLY : |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1356 | maxChargingWattage > fastThreshold ? CHARGING_FAST : |
| 1357 | CHARGING_REGULAR; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 1358 | } |
Lucas Dupin | 3fcdd47 | 2018-01-19 19:06:45 -0800 | [diff] [blame] | 1359 | |
| 1360 | @Override |
| 1361 | public String toString() { |
| 1362 | return "BatteryStatus{status=" + status + ",level=" + level + ",plugged=" + plugged |
| 1363 | + ",health=" + health + ",maxChargingWattage=" + maxChargingWattage + "}"; |
| 1364 | } |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 1365 | } |
| 1366 | |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 1367 | public static class StrongAuthTracker extends LockPatternUtils.StrongAuthTracker { |
| 1368 | private final Consumer<Integer> mStrongAuthRequiredChangedCallback; |
| 1369 | |
| 1370 | public StrongAuthTracker(Context context, |
| 1371 | Consumer<Integer> strongAuthRequiredChangedCallback) { |
Rakesh Iyer | a7aa4d6 | 2016-01-19 17:27:23 -0800 | [diff] [blame] | 1372 | super(context); |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 1373 | mStrongAuthRequiredChangedCallback = strongAuthRequiredChangedCallback; |
Rakesh Iyer | a7aa4d6 | 2016-01-19 17:27:23 -0800 | [diff] [blame] | 1374 | } |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 1375 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1376 | public boolean isUnlockingWithBiometricAllowed() { |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 1377 | int userId = getCurrentUser(); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1378 | return isBiometricAllowedForUser(userId); |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | public boolean hasUserAuthenticatedSinceBoot() { |
| 1382 | int userId = getCurrentUser(); |
| 1383 | return (getStrongAuthForUser(userId) |
| 1384 | & STRONG_AUTH_REQUIRED_AFTER_BOOT) == 0; |
| 1385 | } |
| 1386 | |
| 1387 | @Override |
| 1388 | public void onStrongAuthRequiredChanged(int userId) { |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 1389 | mStrongAuthRequiredChangedCallback.accept(userId); |
Adrian Roos | b5e4722 | 2015-08-14 15:53:06 -0700 | [diff] [blame] | 1390 | } |
| 1391 | } |
| 1392 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1393 | protected void handleStartedWakingUp() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1394 | Trace.beginSection("KeyguardUpdateMonitor#handleStartedWakingUp"); |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1395 | checkIsHandlerThread(); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1396 | updateBiometricListeningState(); |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1397 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1398 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1399 | if (cb != null) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1400 | cb.onStartedWakingUp(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1401 | } |
| 1402 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 1403 | Trace.endSection(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 1406 | protected void handleStartedGoingToSleep(int arg1) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1407 | checkIsHandlerThread(); |
Curtis Belmonte | 6a0634d | 2019-08-19 13:13:01 -0700 | [diff] [blame] | 1408 | mLockIconPressed = false; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1409 | clearBiometricRecognized(); |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1410 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1411 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1412 | if (cb != null) { |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 1413 | cb.onStartedGoingToSleep(arg1); |
| 1414 | } |
| 1415 | } |
| 1416 | mGoingToSleep = true; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1417 | updateBiometricListeningState(); |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | protected void handleFinishedGoingToSleep(int arg1) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1421 | checkIsHandlerThread(); |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 1422 | mGoingToSleep = false; |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1423 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 1424 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1425 | if (cb != null) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 1426 | cb.onFinishedGoingToSleep(arg1); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1427 | } |
| 1428 | } |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1429 | updateBiometricListeningState(); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 1430 | } |
| 1431 | |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 1432 | private void handleScreenTurnedOn() { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1433 | checkIsHandlerThread(); |
| 1434 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 1435 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1436 | if (cb != null) { |
| 1437 | cb.onScreenTurnedOn(); |
| 1438 | } |
| 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | private void handleScreenTurnedOff() { |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 1443 | final String tag = "KeyguardUpdateMonitor#handleScreenTurnedOff"; |
| 1444 | DejankUtils.startDetectingBlockingIpcs(tag); |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1445 | checkIsHandlerThread(); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1446 | mHardwareFingerprintUnavailableRetryCount = 0; |
| 1447 | mHardwareFaceUnavailableRetryCount = 0; |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1448 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 1449 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1450 | if (cb != null) { |
| 1451 | cb.onScreenTurnedOff(); |
| 1452 | } |
| 1453 | } |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 1454 | DejankUtils.stopDetectingBlockingIpcs(tag); |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
Selim Cinek | 9941539 | 2016-09-09 14:58:41 -0700 | [diff] [blame] | 1457 | private void handleDreamingStateChanged(int dreamStart) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1458 | checkIsHandlerThread(); |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 1459 | mIsDreaming = dreamStart == 1; |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1460 | for (int i = 0; i < mCallbacks.size(); i++) { |
Selim Cinek | 9941539 | 2016-09-09 14:58:41 -0700 | [diff] [blame] | 1461 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1462 | if (cb != null) { |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 1463 | cb.onDreamingStateChanged(mIsDreaming); |
Selim Cinek | 9941539 | 2016-09-09 14:58:41 -0700 | [diff] [blame] | 1464 | } |
| 1465 | } |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1466 | updateBiometricListeningState(); |
Selim Cinek | 9941539 | 2016-09-09 14:58:41 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 1469 | private void handleUserInfoChanged(int userId) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1470 | checkIsHandlerThread(); |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 1471 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1472 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1473 | if (cb != null) { |
| 1474 | cb.onUserInfoChanged(userId); |
| 1475 | } |
| 1476 | } |
| 1477 | } |
| 1478 | |
Lucas Dupin | 6c6d573 | 2019-08-27 17:36:05 -0700 | [diff] [blame] | 1479 | private void handleUserUnlocked(int userId) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1480 | checkIsHandlerThread(); |
Lucas Dupin | 6c6d573 | 2019-08-27 17:36:05 -0700 | [diff] [blame] | 1481 | mUserIsUnlocked.put(userId, true); |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 1482 | mNeedsSlowUnlockTransition = resolveNeedsSlowUnlockTransition(); |
| 1483 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 1484 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 1485 | if (cb != null) { |
| 1486 | cb.onUserUnlocked(); |
| 1487 | } |
| 1488 | } |
| 1489 | } |
| 1490 | |
Lucas Dupin | 6c6d573 | 2019-08-27 17:36:05 -0700 | [diff] [blame] | 1491 | private void handleUserStopped(int userId) { |
| 1492 | checkIsHandlerThread(); |
| 1493 | mUserIsUnlocked.put(userId, mUserManager.isUserUnlocked(userId)); |
| 1494 | } |
| 1495 | |
Lucas Dupin | f2c5350 | 2019-10-03 13:56:18 -0700 | [diff] [blame] | 1496 | @VisibleForTesting |
| 1497 | void handleUserRemoved(int userId) { |
Lucas Dupin | 6c6d573 | 2019-08-27 17:36:05 -0700 | [diff] [blame] | 1498 | checkIsHandlerThread(); |
| 1499 | mUserIsUnlocked.delete(userId); |
Lucas Dupin | f2c5350 | 2019-10-03 13:56:18 -0700 | [diff] [blame] | 1500 | mUserTrustIsUsuallyManaged.delete(userId); |
Lucas Dupin | 6c6d573 | 2019-08-27 17:36:05 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 1503 | @VisibleForTesting |
Dave Mankoff | e229469 | 2019-08-14 11:53:13 -0400 | [diff] [blame] | 1504 | @Inject |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 1505 | protected KeyguardUpdateMonitor(Context context, @MainLooper Looper mainLooper, |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 1506 | BroadcastDispatcher broadcastDispatcher, |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 1507 | DumpController dumpController) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1508 | mContext = context; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1509 | mSubscriptionManager = SubscriptionManager.from(context); |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 1510 | mDeviceProvisioned = isDeviceProvisionedInSettingsDb(); |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 1511 | mStrongAuthTracker = new StrongAuthTracker(context, this::notifyStrongAuthStateChanged); |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 1512 | dumpController.registerDumpable(this); |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 1513 | |
Dave Mankoff | e229469 | 2019-08-14 11:53:13 -0400 | [diff] [blame] | 1514 | mHandler = new Handler(mainLooper) { |
| 1515 | @Override |
| 1516 | public void handleMessage(Message msg) { |
| 1517 | switch (msg.what) { |
| 1518 | case MSG_TIME_UPDATE: |
| 1519 | handleTimeUpdate(); |
| 1520 | break; |
| 1521 | case MSG_TIMEZONE_UPDATE: |
| 1522 | handleTimeZoneUpdate((String) msg.obj); |
| 1523 | break; |
| 1524 | case MSG_BATTERY_UPDATE: |
| 1525 | handleBatteryUpdate((BatteryStatus) msg.obj); |
| 1526 | break; |
| 1527 | case MSG_SIM_STATE_CHANGE: |
| 1528 | handleSimStateChange(msg.arg1, msg.arg2, (State) msg.obj); |
| 1529 | break; |
| 1530 | case MSG_RINGER_MODE_CHANGED: |
| 1531 | handleRingerModeChange(msg.arg1); |
| 1532 | break; |
| 1533 | case MSG_PHONE_STATE_CHANGED: |
| 1534 | handlePhoneStateChanged((String) msg.obj); |
| 1535 | break; |
| 1536 | case MSG_DEVICE_PROVISIONED: |
| 1537 | handleDeviceProvisioned(); |
| 1538 | break; |
| 1539 | case MSG_DPM_STATE_CHANGED: |
| 1540 | handleDevicePolicyManagerStateChanged(); |
| 1541 | break; |
| 1542 | case MSG_USER_SWITCHING: |
| 1543 | handleUserSwitching(msg.arg1, (IRemoteCallback) msg.obj); |
| 1544 | break; |
| 1545 | case MSG_USER_SWITCH_COMPLETE: |
| 1546 | handleUserSwitchComplete(msg.arg1); |
| 1547 | break; |
| 1548 | case MSG_KEYGUARD_RESET: |
| 1549 | handleKeyguardReset(); |
| 1550 | break; |
| 1551 | case MSG_KEYGUARD_BOUNCER_CHANGED: |
| 1552 | handleKeyguardBouncerChanged(msg.arg1); |
| 1553 | break; |
| 1554 | case MSG_BOOT_COMPLETED: |
| 1555 | handleBootCompleted(); |
| 1556 | break; |
| 1557 | case MSG_USER_INFO_CHANGED: |
| 1558 | handleUserInfoChanged(msg.arg1); |
| 1559 | break; |
| 1560 | case MSG_REPORT_EMERGENCY_CALL_ACTION: |
| 1561 | handleReportEmergencyCallAction(); |
| 1562 | break; |
| 1563 | case MSG_STARTED_GOING_TO_SLEEP: |
| 1564 | handleStartedGoingToSleep(msg.arg1); |
| 1565 | break; |
| 1566 | case MSG_FINISHED_GOING_TO_SLEEP: |
| 1567 | handleFinishedGoingToSleep(msg.arg1); |
| 1568 | break; |
| 1569 | case MSG_STARTED_WAKING_UP: |
| 1570 | Trace.beginSection("KeyguardUpdateMonitor#handler MSG_STARTED_WAKING_UP"); |
| 1571 | handleStartedWakingUp(); |
| 1572 | Trace.endSection(); |
| 1573 | break; |
| 1574 | case MSG_FACE_UNLOCK_STATE_CHANGED: |
| 1575 | Trace.beginSection( |
| 1576 | "KeyguardUpdateMonitor#handler MSG_FACE_UNLOCK_STATE_CHANGED"); |
| 1577 | handleFaceUnlockStateChanged(msg.arg1 != 0, msg.arg2); |
| 1578 | Trace.endSection(); |
| 1579 | break; |
| 1580 | case MSG_SIM_SUBSCRIPTION_INFO_CHANGED: |
| 1581 | handleSimSubscriptionInfoChanged(); |
| 1582 | break; |
| 1583 | case MSG_AIRPLANE_MODE_CHANGED: |
| 1584 | handleAirplaneModeChanged(); |
| 1585 | break; |
| 1586 | case MSG_SERVICE_STATE_CHANGE: |
| 1587 | handleServiceStateChange(msg.arg1, (ServiceState) msg.obj); |
| 1588 | break; |
| 1589 | case MSG_SCREEN_TURNED_ON: |
| 1590 | handleScreenTurnedOn(); |
| 1591 | break; |
| 1592 | case MSG_SCREEN_TURNED_OFF: |
| 1593 | Trace.beginSection("KeyguardUpdateMonitor#handler MSG_SCREEN_TURNED_ON"); |
| 1594 | handleScreenTurnedOff(); |
| 1595 | Trace.endSection(); |
| 1596 | break; |
| 1597 | case MSG_DREAMING_STATE_CHANGED: |
| 1598 | handleDreamingStateChanged(msg.arg1); |
| 1599 | break; |
| 1600 | case MSG_USER_UNLOCKED: |
| 1601 | handleUserUnlocked(msg.arg1); |
| 1602 | break; |
| 1603 | case MSG_USER_STOPPED: |
| 1604 | handleUserStopped(msg.arg1); |
| 1605 | break; |
| 1606 | case MSG_USER_REMOVED: |
| 1607 | handleUserRemoved(msg.arg1); |
| 1608 | break; |
| 1609 | case MSG_ASSISTANT_STACK_CHANGED: |
| 1610 | setAssistantVisible((boolean) msg.obj); |
| 1611 | break; |
| 1612 | case MSG_BIOMETRIC_AUTHENTICATION_CONTINUE: |
| 1613 | updateBiometricListeningState(); |
| 1614 | break; |
| 1615 | case MSG_DEVICE_POLICY_MANAGER_STATE_CHANGED: |
| 1616 | updateLogoutEnabled(); |
| 1617 | break; |
| 1618 | case MSG_TELEPHONY_CAPABLE: |
| 1619 | updateTelephonyCapable((boolean) msg.obj); |
| 1620 | break; |
| 1621 | default: |
| 1622 | super.handleMessage(msg); |
| 1623 | break; |
| 1624 | } |
| 1625 | } |
| 1626 | }; |
| 1627 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1628 | // Since device can't be un-provisioned, we only need to register a content observer |
| 1629 | // to update mDeviceProvisioned when we are... |
| 1630 | if (!mDeviceProvisioned) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1631 | watchForDeviceProvisioning(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1632 | } |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 1633 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1634 | // 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] | 1635 | 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] | 1636 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 1637 | // Watch for interesting updates |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1638 | final IntentFilter filter = new IntentFilter(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1639 | filter.addAction(Intent.ACTION_TIME_TICK); |
| 1640 | filter.addAction(Intent.ACTION_TIME_CHANGED); |
| 1641 | filter.addAction(Intent.ACTION_BATTERY_CHANGED); |
| 1642 | filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); |
Jason Monk | 052082c | 2015-06-11 11:35:23 -0400 | [diff] [blame] | 1643 | filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1644 | filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 1645 | filter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); |
Fabian Kozynski | ccde55d | 2019-06-26 10:06:09 -0400 | [diff] [blame] | 1646 | filter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED); |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 1647 | filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 1648 | filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 1649 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 1650 | broadcastDispatcher.registerReceiver(mBroadcastReceiver, filter, mHandler); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1651 | |
Adam Cohen | c276e82 | 2012-11-08 13:01:08 -0800 | [diff] [blame] | 1652 | final IntentFilter bootCompleteFilter = new IntentFilter(); |
| 1653 | bootCompleteFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); |
| 1654 | bootCompleteFilter.addAction(Intent.ACTION_BOOT_COMPLETED); |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 1655 | broadcastDispatcher.registerReceiver(mBroadcastReceiver, bootCompleteFilter, mHandler); |
Adam Cohen | c276e82 | 2012-11-08 13:01:08 -0800 | [diff] [blame] | 1656 | |
Adrian Roos | 48c796c | 2014-09-01 14:59:23 +0200 | [diff] [blame] | 1657 | final IntentFilter allUserFilter = new IntentFilter(); |
| 1658 | allUserFilter.addAction(Intent.ACTION_USER_INFO_CHANGED); |
| 1659 | allUserFilter.addAction(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED); |
| 1660 | allUserFilter.addAction(ACTION_FACE_UNLOCK_STARTED); |
| 1661 | allUserFilter.addAction(ACTION_FACE_UNLOCK_STOPPED); |
| 1662 | allUserFilter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 1663 | allUserFilter.addAction(ACTION_USER_UNLOCKED); |
Lucas Dupin | 6c6d573 | 2019-08-27 17:36:05 -0700 | [diff] [blame] | 1664 | allUserFilter.addAction(ACTION_USER_STOPPED); |
| 1665 | allUserFilter.addAction(ACTION_USER_REMOVED); |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 1666 | broadcastDispatcher.registerReceiver(mBroadcastAllReceiver, allUserFilter, mHandler, |
| 1667 | UserHandle.ALL); |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 1668 | |
Wink Saville | 071743f | 2015-01-12 17:11:04 -0800 | [diff] [blame] | 1669 | mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionListener); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1670 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1671 | ActivityManager.getService().registerUserSwitchObserver( |
Sudheer Shanka | 2c4522c | 2016-08-27 20:53:28 -0700 | [diff] [blame] | 1672 | new UserSwitchObserver() { |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1673 | @Override |
| 1674 | public void onUserSwitching(int newUserId, IRemoteCallback reply) { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 1675 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHING, |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1676 | newUserId, 0, reply)); |
| 1677 | } |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1678 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1679 | @Override |
| 1680 | public void onUserSwitchComplete(int newUserId) throws RemoteException { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 1681 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCH_COMPLETE, |
Adrian Roos | be47b07 | 2014-09-03 00:08:56 +0200 | [diff] [blame] | 1682 | newUserId, 0)); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1683 | } |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 1684 | }, TAG); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1685 | } catch (RemoteException e) { |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 1686 | e.rethrowAsRuntimeException(); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1687 | } |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 1688 | |
Lucas Dupin | f2c5350 | 2019-10-03 13:56:18 -0700 | [diff] [blame] | 1689 | mTrustManager = context.getSystemService(TrustManager.class); |
Jorim Jaggi | 237b061 | 2015-05-01 14:28:49 -0700 | [diff] [blame] | 1690 | mTrustManager.registerTrustListener(this); |
Michal Karpinski | c52f867 | 2016-11-18 11:32:45 +0000 | [diff] [blame] | 1691 | mLockPatternUtils = new LockPatternUtils(context); |
| 1692 | mLockPatternUtils.registerStrongAuthTracker(mStrongAuthTracker); |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 1693 | |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 1694 | mDreamManager = IDreamManager.Stub.asInterface( |
| 1695 | ServiceManager.getService(DreamService.DREAM_SERVICE)); |
| 1696 | |
Jorim Jaggi | 3f12426 | 2016-11-22 13:45:17 +0100 | [diff] [blame] | 1697 | if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) { |
| 1698 | mFpm = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE); |
| 1699 | } |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1700 | if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE)) { |
Kevin Chyn | b7b54a6 | 2018-09-28 18:48:12 -0700 | [diff] [blame] | 1701 | mFaceManager = (FaceManager) context.getSystemService(Context.FACE_SERVICE); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1702 | } |
Kevin Chyn | b7b54a6 | 2018-09-28 18:48:12 -0700 | [diff] [blame] | 1703 | |
| 1704 | if (mFpm != null || mFaceManager != null) { |
| 1705 | mBiometricManager = context.getSystemService(BiometricManager.class); |
| 1706 | mBiometricManager.registerEnabledOnKeyguardCallback(mBiometricEnabledCallback); |
| 1707 | } |
| 1708 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1709 | updateBiometricListeningState(); |
Jorim Jaggi | 3a46478 | 2015-08-28 16:59:13 -0700 | [diff] [blame] | 1710 | if (mFpm != null) { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1711 | mFpm.addLockoutResetCallback(mFingerprintLockoutResetCallback); |
| 1712 | } |
Kevin Chyn | b7b54a6 | 2018-09-28 18:48:12 -0700 | [diff] [blame] | 1713 | if (mFaceManager != null) { |
| 1714 | mFaceManager.addLockoutResetCallback(mFaceLockoutResetCallback); |
Jorim Jaggi | 3a46478 | 2015-08-28 16:59:13 -0700 | [diff] [blame] | 1715 | } |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 1716 | |
Winson Chung | 2cf6ad8 | 2017-11-09 17:36:59 -0800 | [diff] [blame] | 1717 | ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener); |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 1718 | mUserManager = context.getSystemService(UserManager.class); |
Kevin Chyn | fdfd2d3 | 2019-03-01 14:52:15 -0800 | [diff] [blame] | 1719 | mIsPrimaryUser = mUserManager.isPrimaryUser(); |
Lucas Dupin | 6c6d573 | 2019-08-27 17:36:05 -0700 | [diff] [blame] | 1720 | int user = ActivityManager.getCurrentUser(); |
| 1721 | mUserIsUnlocked.put(user, mUserManager.isUserUnlocked(user)); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 1722 | mDevicePolicyManager = context.getSystemService(DevicePolicyManager.class); |
| 1723 | mLogoutEnabled = mDevicePolicyManager.isLogoutEnabled(); |
Lucas Dupin | f2c5350 | 2019-10-03 13:56:18 -0700 | [diff] [blame] | 1724 | List<UserInfo> allUsers = mUserManager.getUsers(); |
| 1725 | for (UserInfo userInfo : allUsers) { |
| 1726 | mUserTrustIsUsuallyManaged.put(userInfo.id, |
| 1727 | mTrustManager.isTrustUsuallyManaged(userInfo.id)); |
| 1728 | } |
Bill Lin | ef81cbd | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 1729 | updateAirplaneModeState(); |
Fabian Kozynski | ccde55d | 2019-06-26 10:06:09 -0400 | [diff] [blame] | 1730 | |
| 1731 | TelephonyManager telephony = |
| 1732 | (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); |
| 1733 | if (telephony != null) { |
| 1734 | telephony.listen(mPhoneStateListener, LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE); |
| 1735 | } |
Bill Lin | ef81cbd | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | private void updateAirplaneModeState() { |
| 1739 | // ACTION_AIRPLANE_MODE_CHANGED do not broadcast if device set AirplaneMode ON and boot |
| 1740 | if (!WirelessUtils.isAirplaneModeOn(mContext) |
| 1741 | || mHandler.hasMessages(MSG_AIRPLANE_MODE_CHANGED)) { |
| 1742 | return; |
| 1743 | } |
| 1744 | mHandler.sendEmptyMessage(MSG_AIRPLANE_MODE_CHANGED); |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1745 | } |
| 1746 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1747 | private void updateBiometricListeningState() { |
| 1748 | updateFingerprintListeningState(); |
| 1749 | updateFaceListeningState(); |
| 1750 | } |
| 1751 | |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1752 | private void updateFingerprintListeningState() { |
Kevin Chyn | 0f3e0b1 | 2017-07-20 16:56:11 -0700 | [diff] [blame] | 1753 | // If this message exists, we should not authenticate again until this message is |
| 1754 | // consumed by the handler |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1755 | if (mHandler.hasMessages(MSG_BIOMETRIC_AUTHENTICATION_CONTINUE)) { |
Kevin Chyn | 0f3e0b1 | 2017-07-20 16:56:11 -0700 | [diff] [blame] | 1756 | return; |
| 1757 | } |
Kevin Chyn | 0c45b07 | 2017-04-24 16:27:11 -0700 | [diff] [blame] | 1758 | mHandler.removeCallbacks(mRetryFingerprintAuthentication); |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1759 | boolean shouldListenForFingerprint = shouldListenForFingerprint(); |
Adrian Roos | 2aaf944 | 2018-11-20 16:57:33 +0100 | [diff] [blame] | 1760 | boolean runningOrRestarting = mFingerprintRunningState == BIOMETRIC_STATE_RUNNING |
| 1761 | || mFingerprintRunningState == BIOMETRIC_STATE_CANCELLING_RESTARTING; |
| 1762 | if (runningOrRestarting && !shouldListenForFingerprint) { |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1763 | stopListeningForFingerprint(); |
Adrian Roos | 2aaf944 | 2018-11-20 16:57:33 +0100 | [diff] [blame] | 1764 | } else if (!runningOrRestarting && shouldListenForFingerprint) { |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1765 | startListeningForFingerprint(); |
| 1766 | } |
| 1767 | } |
| 1768 | |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 1769 | /** |
Lucas Dupin | 6c6d573 | 2019-08-27 17:36:05 -0700 | [diff] [blame] | 1770 | * If a user is encrypted or not. |
| 1771 | * This is NOT related to the lock screen being visible or not. |
| 1772 | * |
| 1773 | * @param userId The user. |
| 1774 | * @return {@code true} when encrypted. |
| 1775 | * @see UserManager#isUserUnlocked() |
| 1776 | * @see Intent#ACTION_USER_UNLOCKED |
| 1777 | */ |
| 1778 | public boolean isUserUnlocked(int userId) { |
| 1779 | return mUserIsUnlocked.get(userId); |
| 1780 | } |
| 1781 | |
| 1782 | /** |
Lucas Dupin | e0516d5 | 2019-02-05 17:54:06 -0500 | [diff] [blame] | 1783 | * Called whenever passive authentication is requested or aborted by a sensor. |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 1784 | * |
Lucas Dupin | e0516d5 | 2019-02-05 17:54:06 -0500 | [diff] [blame] | 1785 | * @param active If the interrupt started or ended. |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 1786 | */ |
Lucas Dupin | e0516d5 | 2019-02-05 17:54:06 -0500 | [diff] [blame] | 1787 | public void onAuthInterruptDetected(boolean active) { |
| 1788 | if (DEBUG) Log.d(TAG, "onAuthInterruptDetected(" + active + ")"); |
| 1789 | if (mAuthInterruptActive == active) { |
| 1790 | return; |
| 1791 | } |
| 1792 | mAuthInterruptActive = active; |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 1793 | updateFaceListeningState(); |
| 1794 | } |
| 1795 | |
Lucas Dupin | 8f3faac | 2019-03-12 15:28:49 -0700 | [diff] [blame] | 1796 | /** |
| 1797 | * Requests face authentication if we're on a state where it's allowed. |
| 1798 | * This will re-trigger auth in case it fails. |
| 1799 | */ |
| 1800 | public void requestFaceAuth() { |
| 1801 | if (DEBUG) Log.d(TAG, "requestFaceAuth()"); |
| 1802 | updateFaceListeningState(); |
| 1803 | } |
| 1804 | |
Lucas Dupin | ccf6721 | 2019-08-07 12:53:02 -0700 | [diff] [blame] | 1805 | /** |
| 1806 | * In case face auth is running, cancel it. |
| 1807 | */ |
| 1808 | public void cancelFaceAuth() { |
| 1809 | stopListeningForFace(); |
| 1810 | } |
| 1811 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1812 | private void updateFaceListeningState() { |
| 1813 | // If this message exists, we should not authenticate again until this message is |
| 1814 | // consumed by the handler |
| 1815 | if (mHandler.hasMessages(MSG_BIOMETRIC_AUTHENTICATION_CONTINUE)) { |
| 1816 | return; |
| 1817 | } |
| 1818 | mHandler.removeCallbacks(mRetryFaceAuthentication); |
| 1819 | boolean shouldListenForFace = shouldListenForFace(); |
| 1820 | if (mFaceRunningState == BIOMETRIC_STATE_RUNNING && !shouldListenForFace) { |
| 1821 | stopListeningForFace(); |
| 1822 | } else if (mFaceRunningState != BIOMETRIC_STATE_RUNNING |
| 1823 | && shouldListenForFace) { |
| 1824 | startListeningForFace(); |
| 1825 | } |
| 1826 | } |
| 1827 | |
Kevin Chyn | 129f60f | 2017-08-11 17:24:42 -0700 | [diff] [blame] | 1828 | private boolean shouldListenForFingerprintAssistant() { |
| 1829 | return mAssistantVisible && mKeyguardOccluded |
| 1830 | && !mUserFingerprintAuthenticated.get(getCurrentUser(), false) |
| 1831 | && !mUserHasTrust.get(getCurrentUser(), false); |
| 1832 | } |
| 1833 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1834 | private boolean shouldListenForFaceAssistant() { |
| 1835 | return mAssistantVisible && mKeyguardOccluded |
| 1836 | && !mUserFaceAuthenticated.get(getCurrentUser(), false) |
| 1837 | && !mUserHasTrust.get(getCurrentUser(), false); |
| 1838 | } |
| 1839 | |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1840 | private boolean shouldListenForFingerprint() { |
Kevin Chyn | fdfd2d3 | 2019-03-01 14:52:15 -0800 | [diff] [blame] | 1841 | // Only listen if this KeyguardUpdateMonitor belongs to the primary user. There is an |
| 1842 | // instance of KeyguardUpdateMonitor for each user but KeyguardUpdateMonitor is user-aware. |
| 1843 | final boolean shouldListen = (mKeyguardIsVisible || !mDeviceInteractive || |
Kevin Chyn | 0f3e0b1 | 2017-07-20 16:56:11 -0700 | [diff] [blame] | 1844 | (mBouncer && !mKeyguardGoingAway) || mGoingToSleep || |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 1845 | shouldListenForFingerprintAssistant() || (mKeyguardOccluded && mIsDreaming)) |
Lucas Dupin | c12fad3 | 2019-05-14 20:59:17 +0000 | [diff] [blame] | 1846 | && !mSwitchingUser && !isFingerprintDisabled(getCurrentUser()) |
Kevin Chyn | 225eea7 | 2019-03-06 16:42:00 -0800 | [diff] [blame] | 1847 | && (!mKeyguardGoingAway || !mDeviceInteractive) && mIsPrimaryUser; |
Kevin Chyn | fdfd2d3 | 2019-03-01 14:52:15 -0800 | [diff] [blame] | 1848 | return shouldListen; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
Lucas Dupin | 4b75b19 | 2019-08-29 14:46:29 -0700 | [diff] [blame] | 1851 | /** |
| 1852 | * If face auth is allows to scan on this exact moment. |
| 1853 | */ |
| 1854 | public boolean shouldListenForFace() { |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 1855 | final boolean awakeKeyguard = mKeyguardIsVisible && mDeviceInteractive && !mGoingToSleep; |
| 1856 | final int user = getCurrentUser(); |
Robert Snoeberger | 5dcdf35 | 2019-06-24 11:28:28 -0400 | [diff] [blame] | 1857 | final int strongAuth = mStrongAuthTracker.getStrongAuthForUser(user); |
| 1858 | final boolean isLockOutOrLockDown = |
Lucas Dupin | 8eec268 | 2019-07-01 16:41:17 -0700 | [diff] [blame] | 1859 | containsFlag(strongAuth, STRONG_AUTH_REQUIRED_AFTER_LOCKOUT) |
| 1860 | || containsFlag(strongAuth, STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW) |
| 1861 | || containsFlag(strongAuth, STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN); |
| 1862 | final boolean isEncryptedOrTimedOut = |
| 1863 | containsFlag(strongAuth, STRONG_AUTH_REQUIRED_AFTER_BOOT) |
| 1864 | || containsFlag(strongAuth, STRONG_AUTH_REQUIRED_AFTER_TIMEOUT); |
Lucas Dupin | 9e484aa | 2019-06-24 13:38:00 -0700 | [diff] [blame] | 1865 | |
Lucas Dupin | 4befb74 | 2019-07-01 11:31:31 -0700 | [diff] [blame] | 1866 | boolean canBypass = mKeyguardBypassController != null |
| 1867 | && mKeyguardBypassController.canBypass(); |
Lucas Dupin | 9e484aa | 2019-06-24 13:38:00 -0700 | [diff] [blame] | 1868 | // There's no reason to ask the HAL for authentication when the user can dismiss the |
| 1869 | // bouncer, unless we're bypassing and need to auto-dismiss the lock screen even when |
| 1870 | // TrustAgents or biometrics are keeping the device unlocked. |
Lucas Dupin | 4befb74 | 2019-07-01 11:31:31 -0700 | [diff] [blame] | 1871 | boolean becauseCannotSkipBouncer = !getUserCanSkipBouncer(user) || canBypass; |
Lucas Dupin | 9e484aa | 2019-06-24 13:38:00 -0700 | [diff] [blame] | 1872 | |
Lucas Dupin | 8eec268 | 2019-07-01 16:41:17 -0700 | [diff] [blame] | 1873 | // Scan even when encrypted or timeout to show a preemptive bouncer when bypassing. |
| 1874 | // Lockout/lockdown modes shouldn't scan, since they are more explicit. |
| 1875 | boolean strongAuthAllowsScanning = (!isEncryptedOrTimedOut || canBypass && !mBouncer) |
| 1876 | && !isLockOutOrLockDown; |
| 1877 | |
Kevin Chyn | fdfd2d3 | 2019-03-01 14:52:15 -0800 | [diff] [blame] | 1878 | // Only listen if this KeyguardUpdateMonitor belongs to the primary user. There is an |
| 1879 | // instance of KeyguardUpdateMonitor for each user but KeyguardUpdateMonitor is user-aware. |
Lucas Dupin | e0516d5 | 2019-02-05 17:54:06 -0500 | [diff] [blame] | 1880 | return (mBouncer || mAuthInterruptActive || awakeKeyguard || shouldListenForFaceAssistant()) |
Lucas Dupin | 9e484aa | 2019-06-24 13:38:00 -0700 | [diff] [blame] | 1881 | && !mSwitchingUser && !isFaceDisabled(user) && becauseCannotSkipBouncer |
Lucas Dupin | 7d95f15 | 2019-07-17 16:25:54 -0700 | [diff] [blame] | 1882 | && !mKeyguardGoingAway && mFaceSettingEnabledForUser.get(user) && !mLockIconPressed |
Lucas Dupin | 8eec268 | 2019-07-01 16:41:17 -0700 | [diff] [blame] | 1883 | && strongAuthAllowsScanning && mIsPrimaryUser |
| 1884 | && !mSecureCameraLaunched; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1885 | } |
| 1886 | |
Lucas Dupin | ca88e5f | 2019-05-14 16:11:08 -0700 | [diff] [blame] | 1887 | /** |
| 1888 | * Whenever the lock icon is long pressed, disabling trust agents. |
| 1889 | * This means that we cannot auth passively (face) until the user presses power. |
| 1890 | */ |
| 1891 | public void onLockIconPressed() { |
| 1892 | mLockIconPressed = true; |
Curtis Belmonte | c48eff5 | 2019-08-21 15:51:34 -0700 | [diff] [blame] | 1893 | final int userId = getCurrentUser(); |
| 1894 | mUserFaceAuthenticated.put(userId, false); |
Lucas Dupin | ca88e5f | 2019-05-14 16:11:08 -0700 | [diff] [blame] | 1895 | updateFaceListeningState(); |
Curtis Belmonte | c48eff5 | 2019-08-21 15:51:34 -0700 | [diff] [blame] | 1896 | mStrongAuthTracker.onStrongAuthRequiredChanged(userId); |
Lucas Dupin | ca88e5f | 2019-05-14 16:11:08 -0700 | [diff] [blame] | 1897 | } |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1898 | |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 1899 | private void startListeningForFingerprint() { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1900 | if (mFingerprintRunningState == BIOMETRIC_STATE_CANCELLING) { |
| 1901 | setFingerprintRunningState(BIOMETRIC_STATE_CANCELLING_RESTARTING); |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 1902 | return; |
| 1903 | } |
Adrian Roos | 2aaf944 | 2018-11-20 16:57:33 +0100 | [diff] [blame] | 1904 | if (mFingerprintRunningState == BIOMETRIC_STATE_CANCELLING_RESTARTING) { |
| 1905 | // Waiting for restart via handleFingerprintError(). |
| 1906 | return; |
| 1907 | } |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 1908 | if (DEBUG) Log.v(TAG, "startListeningForFingerprint()"); |
Lucas Dupin | 8f3faac | 2019-03-12 15:28:49 -0700 | [diff] [blame] | 1909 | int userId = getCurrentUser(); |
Jorim Jaggi | 71448a7 | 2015-08-18 19:49:04 -0700 | [diff] [blame] | 1910 | if (isUnlockWithFingerprintPossible(userId)) { |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 1911 | if (mFingerprintCancelSignal != null) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1912 | mFingerprintCancelSignal.cancel(); |
| 1913 | } |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 1914 | mFingerprintCancelSignal = new CancellationSignal(); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1915 | mFpm.authenticate(null, mFingerprintCancelSignal, 0, mFingerprintAuthenticationCallback, |
| 1916 | null, userId); |
| 1917 | setFingerprintRunningState(BIOMETRIC_STATE_RUNNING); |
| 1918 | } |
| 1919 | } |
| 1920 | |
| 1921 | private void startListeningForFace() { |
| 1922 | if (mFaceRunningState == BIOMETRIC_STATE_CANCELLING) { |
| 1923 | setFaceRunningState(BIOMETRIC_STATE_CANCELLING_RESTARTING); |
| 1924 | return; |
| 1925 | } |
| 1926 | if (DEBUG) Log.v(TAG, "startListeningForFace()"); |
Lucas Dupin | 8f3faac | 2019-03-12 15:28:49 -0700 | [diff] [blame] | 1927 | int userId = getCurrentUser(); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1928 | if (isUnlockWithFacePossible(userId)) { |
| 1929 | if (mFaceCancelSignal != null) { |
| 1930 | mFaceCancelSignal.cancel(); |
| 1931 | } |
| 1932 | mFaceCancelSignal = new CancellationSignal(); |
Kevin Chyn | b7b54a6 | 2018-09-28 18:48:12 -0700 | [diff] [blame] | 1933 | mFaceManager.authenticate(null, mFaceCancelSignal, 0, |
Kevin Chyn | 8d2694a | 2019-04-11 18:30:40 -0700 | [diff] [blame] | 1934 | mFaceAuthenticationCallback, null, userId); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1935 | setFaceRunningState(BIOMETRIC_STATE_RUNNING); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1936 | } |
| 1937 | } |
| 1938 | |
Lucas Dupin | 8d48fc4 | 2019-04-25 14:34:12 -0700 | [diff] [blame] | 1939 | /** |
| 1940 | * If biometrics hardware is available, not disabled, and user has enrolled templates. |
| 1941 | * This does NOT check if the device is encrypted or in lockdown. |
| 1942 | * |
| 1943 | * @param userId User that's trying to unlock. |
| 1944 | * @return {@code true} if possible. |
| 1945 | */ |
| 1946 | public boolean isUnlockingWithBiometricsPossible(int userId) { |
| 1947 | return isUnlockWithFacePossible(userId) || isUnlockWithFingerprintPossible(userId); |
| 1948 | } |
| 1949 | |
| 1950 | private boolean isUnlockWithFingerprintPossible(int userId) { |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 1951 | return mFpm != null && mFpm.isHardwareDetected() && !isFingerprintDisabled(userId) |
| 1952 | && mFpm.getEnrolledFingerprints(userId).size() > 0; |
| 1953 | } |
| 1954 | |
Lucas Dupin | 4c50704 | 2019-07-22 16:47:34 -0700 | [diff] [blame] | 1955 | private boolean isUnlockWithFacePossible(int userId) { |
| 1956 | return isFaceAuthEnabledForUser(userId) && !isFaceDisabled(userId); |
| 1957 | } |
| 1958 | |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 1959 | /** |
Lucas Dupin | 7d95f15 | 2019-07-17 16:25:54 -0700 | [diff] [blame] | 1960 | * If face hardware is available, user has enrolled and enabled auth via setting. |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 1961 | */ |
Lucas Dupin | 4c50704 | 2019-07-22 16:47:34 -0700 | [diff] [blame] | 1962 | public boolean isFaceAuthEnabledForUser(int userId) { |
Lucas Dupin | 8968f6a | 2019-08-09 17:41:15 -0700 | [diff] [blame] | 1963 | // TODO(b/140034352) |
| 1964 | return whitelistIpcs(() -> mFaceManager != null && mFaceManager.isHardwareDetected() |
Lucas Dupin | 7d95f15 | 2019-07-17 16:25:54 -0700 | [diff] [blame] | 1965 | && mFaceManager.hasEnrolledTemplates(userId) |
Lucas Dupin | 8968f6a | 2019-08-09 17:41:15 -0700 | [diff] [blame] | 1966 | && mFaceSettingEnabledForUser.get(userId)); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1967 | } |
| 1968 | |
Jorim Jaggi | ea65706 | 2015-04-28 13:45:11 -0700 | [diff] [blame] | 1969 | private void stopListeningForFingerprint() { |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 1970 | if (DEBUG) Log.v(TAG, "stopListeningForFingerprint()"); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1971 | if (mFingerprintRunningState == BIOMETRIC_STATE_RUNNING) { |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 1972 | if (mFingerprintCancelSignal != null) { |
| 1973 | mFingerprintCancelSignal.cancel(); |
| 1974 | mFingerprintCancelSignal = null; |
joshmccloskey | 7dee454 | 2019-07-31 18:35:33 -0700 | [diff] [blame] | 1975 | if (!mHandler.hasCallbacks(mCancelNotReceived)) { |
| 1976 | mHandler.postDelayed(mCancelNotReceived, DEFAULT_CANCEL_SIGNAL_TIMEOUT); |
| 1977 | } |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 1978 | } |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1979 | setFingerprintRunningState(BIOMETRIC_STATE_CANCELLING); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1980 | } |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1981 | if (mFingerprintRunningState == BIOMETRIC_STATE_CANCELLING_RESTARTING) { |
| 1982 | setFingerprintRunningState(BIOMETRIC_STATE_CANCELLING); |
| 1983 | } |
| 1984 | } |
| 1985 | |
| 1986 | private void stopListeningForFace() { |
| 1987 | if (DEBUG) Log.v(TAG, "stopListeningForFace()"); |
| 1988 | if (mFaceRunningState == BIOMETRIC_STATE_RUNNING) { |
| 1989 | if (mFaceCancelSignal != null) { |
| 1990 | mFaceCancelSignal.cancel(); |
| 1991 | mFaceCancelSignal = null; |
joshmccloskey | 7dee454 | 2019-07-31 18:35:33 -0700 | [diff] [blame] | 1992 | if (!mHandler.hasCallbacks(mCancelNotReceived)) { |
| 1993 | mHandler.postDelayed(mCancelNotReceived, DEFAULT_CANCEL_SIGNAL_TIMEOUT); |
| 1994 | } |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1995 | } |
| 1996 | setFaceRunningState(BIOMETRIC_STATE_CANCELLING); |
| 1997 | } |
| 1998 | if (mFaceRunningState == BIOMETRIC_STATE_CANCELLING_RESTARTING) { |
| 1999 | setFaceRunningState(BIOMETRIC_STATE_CANCELLING); |
Jorim Jaggi | 86bed40 | 2015-08-20 18:20:02 -0700 | [diff] [blame] | 2000 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2001 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2002 | |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 2003 | private boolean isDeviceProvisionedInSettingsDb() { |
| 2004 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 2005 | Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
| 2006 | } |
| 2007 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2008 | private void watchForDeviceProvisioning() { |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 2009 | mDeviceProvisionedObserver = new ContentObserver(mHandler) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2010 | @Override |
| 2011 | public void onChange(boolean selfChange) { |
| 2012 | super.onChange(selfChange); |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 2013 | mDeviceProvisioned = isDeviceProvisionedInSettingsDb(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2014 | if (mDeviceProvisioned) { |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 2015 | mHandler.sendEmptyMessage(MSG_DEVICE_PROVISIONED); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2016 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2017 | if (DEBUG) Log.d(TAG, "DEVICE_PROVISIONED state = " + mDeviceProvisioned); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2018 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2019 | }; |
| 2020 | |
| 2021 | mContext.getContentResolver().registerContentObserver( |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 2022 | Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 2023 | false, mDeviceProvisionedObserver); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2024 | |
| 2025 | // prevent a race condition between where we check the flag and where we register the |
| 2026 | // observer by grabbing the value once again... |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 2027 | boolean provisioned = isDeviceProvisionedInSettingsDb(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2028 | if (provisioned != mDeviceProvisioned) { |
| 2029 | mDeviceProvisioned = provisioned; |
| 2030 | if (mDeviceProvisioned) { |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 2031 | mHandler.sendEmptyMessage(MSG_DEVICE_PROVISIONED); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2032 | } |
| 2033 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2034 | } |
| 2035 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2036 | /** |
Jorim Jaggi | d11d1a9 | 2016-08-16 16:02:32 -0700 | [diff] [blame] | 2037 | * Update the state whether Keyguard currently has a lockscreen wallpaper. |
| 2038 | * |
| 2039 | * @param hasLockscreenWallpaper Whether Keyguard has a lockscreen wallpaper. |
| 2040 | */ |
| 2041 | public void setHasLockscreenWallpaper(boolean hasLockscreenWallpaper) { |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 2042 | checkIsHandlerThread(); |
Jorim Jaggi | d11d1a9 | 2016-08-16 16:02:32 -0700 | [diff] [blame] | 2043 | if (hasLockscreenWallpaper != mHasLockscreenWallpaper) { |
| 2044 | mHasLockscreenWallpaper = hasLockscreenWallpaper; |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2045 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jorim Jaggi | d11d1a9 | 2016-08-16 16:02:32 -0700 | [diff] [blame] | 2046 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 2047 | if (cb != null) { |
| 2048 | cb.onHasLockscreenWallpaperChanged(hasLockscreenWallpaper); |
| 2049 | } |
| 2050 | } |
| 2051 | } |
| 2052 | } |
| 2053 | |
| 2054 | /** |
| 2055 | * @return Whether Keyguard has a lockscreen wallpaper. |
| 2056 | */ |
| 2057 | public boolean hasLockscreenWallpaper() { |
| 2058 | return mHasLockscreenWallpaper; |
| 2059 | } |
| 2060 | |
| 2061 | /** |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2062 | * Handle {@link #MSG_DPM_STATE_CHANGED} |
| 2063 | */ |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 2064 | private void handleDevicePolicyManagerStateChanged() { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2065 | checkIsHandlerThread(); |
Adrian Roos | 733b663 | 2015-08-21 14:32:35 -0700 | [diff] [blame] | 2066 | updateFingerprintListeningState(); |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2067 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 2068 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 2069 | if (cb != null) { |
| 2070 | cb.onDevicePolicyManagerStateChanged(); |
| 2071 | } |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 2072 | } |
| 2073 | } |
| 2074 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2075 | /** |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 2076 | * Handle {@link #MSG_USER_SWITCHING} |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2077 | */ |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 2078 | private void handleUserSwitching(int userId, IRemoteCallback reply) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2079 | checkIsHandlerThread(); |
Lucas Dupin | f2c5350 | 2019-10-03 13:56:18 -0700 | [diff] [blame] | 2080 | mUserTrustIsUsuallyManaged.put(userId, mTrustManager.isTrustUsuallyManaged(userId)); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2081 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 2082 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 2083 | if (cb != null) { |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 2084 | cb.onUserSwitching(userId); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 2085 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 2086 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 2087 | try { |
| 2088 | reply.sendResult(null); |
| 2089 | } catch (RemoteException e) { |
| 2090 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 2091 | } |
| 2092 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2093 | /** |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 2094 | * Handle {@link #MSG_USER_SWITCH_COMPLETE} |
| 2095 | */ |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 2096 | private void handleUserSwitchComplete(int userId) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2097 | checkIsHandlerThread(); |
Chris Wren | f41c61b | 2012-11-29 15:19:54 -0500 | [diff] [blame] | 2098 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 2099 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 2100 | if (cb != null) { |
| 2101 | cb.onUserSwitchComplete(userId); |
| 2102 | } |
| 2103 | } |
| 2104 | } |
| 2105 | |
| 2106 | /** |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 2107 | * This is exposed since {@link Intent#ACTION_BOOT_COMPLETED} is not sticky. If |
| 2108 | * keyguard crashes sometime after boot, then it will never receive this |
| 2109 | * broadcast and hence not handle the event. This method is ultimately called by |
| 2110 | * PhoneWindowManager in this case. |
| 2111 | */ |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 2112 | public void dispatchBootCompleted() { |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 2113 | mHandler.sendEmptyMessage(MSG_BOOT_COMPLETED); |
Jim Miller | 90873d5 | 2013-09-26 18:11:38 -0700 | [diff] [blame] | 2114 | } |
| 2115 | |
| 2116 | /** |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 2117 | * Handle {@link #MSG_BOOT_COMPLETED} |
| 2118 | */ |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 2119 | private void handleBootCompleted() { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2120 | checkIsHandlerThread(); |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 2121 | if (mBootCompleted) return; |
Adam Cohen | 4eb36cf | 2012-11-07 11:45:30 -0800 | [diff] [blame] | 2122 | mBootCompleted = true; |
Adam Cohen | efb3ffb | 2012-11-06 16:55:32 -0800 | [diff] [blame] | 2123 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 2124 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 2125 | if (cb != null) { |
| 2126 | cb.onBootCompleted(); |
| 2127 | } |
| 2128 | } |
| 2129 | } |
| 2130 | |
| 2131 | /** |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2132 | * 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] | 2133 | * destroyed. |
| 2134 | */ |
| 2135 | public boolean hasBootCompleted() { |
| 2136 | return mBootCompleted; |
| 2137 | } |
| 2138 | |
| 2139 | /** |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2140 | * Handle {@link #MSG_DEVICE_PROVISIONED} |
| 2141 | */ |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 2142 | private void handleDeviceProvisioned() { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2143 | checkIsHandlerThread(); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2144 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 2145 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 2146 | if (cb != null) { |
| 2147 | cb.onDeviceProvisioned(); |
| 2148 | } |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 2149 | } |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 2150 | if (mDeviceProvisionedObserver != null) { |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 2151 | // We don't need the observer anymore... |
Michael Jurka | fff5614 | 2012-11-28 16:51:00 -0800 | [diff] [blame] | 2152 | mContext.getContentResolver().unregisterContentObserver(mDeviceProvisionedObserver); |
| 2153 | mDeviceProvisionedObserver = null; |
Nick Pelly | 24d7b5f | 2011-10-11 12:51:09 -0700 | [diff] [blame] | 2154 | } |
| 2155 | } |
| 2156 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2157 | /** |
| 2158 | * Handle {@link #MSG_PHONE_STATE_CHANGED} |
| 2159 | */ |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 2160 | private void handlePhoneStateChanged(String newState) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2161 | checkIsHandlerThread(); |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 2162 | if (DEBUG) Log.d(TAG, "handlePhoneStateChanged(" + newState + ")"); |
Jim Miller | 3f5f83b | 2011-09-26 15:17:05 -0700 | [diff] [blame] | 2163 | if (TelephonyManager.EXTRA_STATE_IDLE.equals(newState)) { |
| 2164 | mPhoneState = TelephonyManager.CALL_STATE_IDLE; |
| 2165 | } else if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(newState)) { |
| 2166 | mPhoneState = TelephonyManager.CALL_STATE_OFFHOOK; |
| 2167 | } else if (TelephonyManager.EXTRA_STATE_RINGING.equals(newState)) { |
| 2168 | mPhoneState = TelephonyManager.CALL_STATE_RINGING; |
| 2169 | } |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2170 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 2171 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 2172 | if (cb != null) { |
| 2173 | cb.onPhoneStateChanged(mPhoneState); |
| 2174 | } |
Jim Miller | c23024d | 2010-02-24 15:37:00 -0800 | [diff] [blame] | 2175 | } |
| 2176 | } |
| 2177 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2178 | /** |
| 2179 | * Handle {@link #MSG_RINGER_MODE_CHANGED} |
| 2180 | */ |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 2181 | private void handleRingerModeChange(int mode) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2182 | checkIsHandlerThread(); |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 2183 | if (DEBUG) Log.d(TAG, "handleRingerModeChange(" + mode + ")"); |
Jim Miller | 3f5f83b | 2011-09-26 15:17:05 -0700 | [diff] [blame] | 2184 | mRingMode = mode; |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2185 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 2186 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 2187 | if (cb != null) { |
| 2188 | cb.onRingerModeChanged(mode); |
| 2189 | } |
Jim Miller | 47088bb | 2009-11-24 00:40:16 -0800 | [diff] [blame] | 2190 | } |
| 2191 | } |
| 2192 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2193 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2194 | * Handle {@link #MSG_TIME_UPDATE} |
| 2195 | */ |
| 2196 | private void handleTimeUpdate() { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2197 | checkIsHandlerThread(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2198 | if (DEBUG) Log.d(TAG, "handleTimeUpdate"); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2199 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 2200 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 2201 | if (cb != null) { |
| 2202 | cb.onTimeChanged(); |
| 2203 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2204 | } |
| 2205 | } |
| 2206 | |
| 2207 | /** |
Robert Snoeberger | 9c1074f | 2018-12-07 17:35:21 -0500 | [diff] [blame] | 2208 | * Handle (@line #MSG_TIMEZONE_UPDATE} |
| 2209 | */ |
| 2210 | private void handleTimeZoneUpdate(String timeZone) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2211 | checkIsHandlerThread(); |
Robert Snoeberger | 9c1074f | 2018-12-07 17:35:21 -0500 | [diff] [blame] | 2212 | if (DEBUG) Log.d(TAG, "handleTimeZoneUpdate"); |
| 2213 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 2214 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 2215 | if (cb != null) { |
| 2216 | cb.onTimeZoneChanged(TimeZone.getTimeZone(timeZone)); |
| 2217 | // Also notify callbacks about time change to remain compatible. |
| 2218 | cb.onTimeChanged(); |
| 2219 | } |
| 2220 | } |
| 2221 | } |
| 2222 | |
| 2223 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2224 | * Handle {@link #MSG_BATTERY_UPDATE} |
| 2225 | */ |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2226 | private void handleBatteryUpdate(BatteryStatus status) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2227 | checkIsHandlerThread(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2228 | if (DEBUG) Log.d(TAG, "handleBatteryUpdate"); |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2229 | final boolean batteryUpdateInteresting = isBatteryUpdateInteresting(mBatteryStatus, status); |
| 2230 | mBatteryStatus = status; |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 2231 | if (batteryUpdateInteresting) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2232 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 2233 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 2234 | if (cb != null) { |
| 2235 | cb.onRefreshBatteryInfo(status); |
| 2236 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2237 | } |
| 2238 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | /** |
Bill Lin | ef81cbd | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 2242 | * Handle Telephony status during Boot for CarrierText display policy |
| 2243 | */ |
| 2244 | @VisibleForTesting |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2245 | void updateTelephonyCapable(boolean capable) { |
| 2246 | checkIsHandlerThread(); |
Bill Lin | ef81cbd | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 2247 | if (capable == mTelephonyCapable) { |
| 2248 | return; |
| 2249 | } |
| 2250 | mTelephonyCapable = capable; |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2251 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 2252 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
Bill Lin | ef81cbd | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 2253 | if (cb != null) { |
| 2254 | cb.onTelephonyCapable(mTelephonyCapable); |
| 2255 | } |
| 2256 | } |
| 2257 | } |
| 2258 | |
| 2259 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2260 | * Handle {@link #MSG_SIM_STATE_CHANGE} |
| 2261 | */ |
Lucas Dupin | 5e0f0d2 | 2018-02-26 13:32:16 -0800 | [diff] [blame] | 2262 | @VisibleForTesting |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 2263 | void handleSimStateChange(int subId, int slotId, State state) { |
| 2264 | checkIsHandlerThread(); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 2265 | if (DEBUG_SIM_STATES) { |
| 2266 | Log.d(TAG, "handleSimStateChange(subId=" + subId + ", slotId=" |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2267 | + slotId + ", state=" + state + ")"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2268 | } |
| 2269 | |
Lucas Dupin | 2e0d495 | 2018-12-05 20:03:53 -0800 | [diff] [blame] | 2270 | boolean becameAbsent = false; |
Wink Saville | a54bf65 | 2014-12-11 13:37:50 -0800 | [diff] [blame] | 2271 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 2272 | Log.w(TAG, "invalid subId in handleSimStateChange()"); |
andychou | 695a760 | 2019-05-16 23:14:00 +0800 | [diff] [blame] | 2273 | /* Only handle No SIM(ABSENT) and Card Error(CARD_IO_ERROR) due to |
| 2274 | * handleServiceStateChange() handle other case */ |
Bill Lin | ef81cbd | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 2275 | if (state == State.ABSENT) { |
| 2276 | updateTelephonyCapable(true); |
Lucas Dupin | 2e0d495 | 2018-12-05 20:03:53 -0800 | [diff] [blame] | 2277 | // Even though the subscription is not valid anymore, we need to notify that the |
| 2278 | // SIM card was removed so we can update the UI. |
| 2279 | becameAbsent = true; |
Brad Ebinger | e6c6f72 | 2018-12-20 21:11:44 -0800 | [diff] [blame] | 2280 | for (SimData data : mSimDatas.values()) { |
| 2281 | // Set the SIM state of all SimData associated with that slot to ABSENT se we |
| 2282 | // do not move back into PIN/PUK locked and not detect the change below. |
| 2283 | if (data.slotId == slotId) { |
| 2284 | data.simState = State.ABSENT; |
| 2285 | } |
| 2286 | } |
andychou | 695a760 | 2019-05-16 23:14:00 +0800 | [diff] [blame] | 2287 | } else if (state == State.CARD_IO_ERROR) { |
| 2288 | updateTelephonyCapable(true); |
Lucas Dupin | 2e0d495 | 2018-12-05 20:03:53 -0800 | [diff] [blame] | 2289 | } else { |
| 2290 | return; |
Bill Lin | ef81cbd | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 2291 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | SimData data = mSimDatas.get(subId); |
| 2295 | final boolean changed; |
| 2296 | if (data == null) { |
| 2297 | data = new SimData(state, slotId, subId); |
| 2298 | mSimDatas.put(subId, data); |
| 2299 | changed = true; // no data yet; force update |
| 2300 | } else { |
| 2301 | changed = (data.simState != state || data.subId != subId || data.slotId != slotId); |
| 2302 | data.simState = state; |
| 2303 | data.subId = subId; |
| 2304 | data.slotId = slotId; |
| 2305 | } |
Lucas Dupin | 2e0d495 | 2018-12-05 20:03:53 -0800 | [diff] [blame] | 2306 | if ((changed || becameAbsent) && state != State.UNKNOWN) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2307 | for (int i = 0; i < mCallbacks.size(); i++) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 2308 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 2309 | if (cb != null) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 2310 | cb.onSimStateChanged(subId, slotId, state); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 2311 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2312 | } |
| 2313 | } |
| 2314 | } |
| 2315 | |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2316 | /** |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 2317 | * Handle {@link #MSG_SERVICE_STATE_CHANGE} |
| 2318 | */ |
Bill Lin | ef81cbd | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 2319 | @VisibleForTesting |
| 2320 | void handleServiceStateChange(int subId, ServiceState serviceState) { |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 2321 | if (DEBUG) { |
| 2322 | Log.d(TAG, |
| 2323 | "handleServiceStateChange(subId=" + subId + ", serviceState=" + serviceState); |
| 2324 | } |
| 2325 | |
| 2326 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2327 | Log.w(TAG, "invalid subId in handleServiceStateChange()"); |
| 2328 | return; |
Bill Lin | ef81cbd | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 2329 | } else { |
| 2330 | updateTelephonyCapable(true); |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | mServiceStates.put(subId, serviceState); |
| 2334 | |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2335 | callbacksRefreshCarrierInfo(); |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 2336 | } |
| 2337 | |
Lucas Dupin | f8463ee | 2018-06-11 16:18:15 -0700 | [diff] [blame] | 2338 | public boolean isKeyguardVisible() { |
| 2339 | return mKeyguardIsVisible; |
| 2340 | } |
| 2341 | |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 2342 | /** |
Jorim Jaggi | 6a15d52 | 2015-09-22 15:55:33 -0700 | [diff] [blame] | 2343 | * Notifies that the visibility state of Keyguard has changed. |
| 2344 | * |
| 2345 | * <p>Needs to be called from the main thread. |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 2346 | */ |
Jorim Jaggi | 6a15d52 | 2015-09-22 15:55:33 -0700 | [diff] [blame] | 2347 | public void onKeyguardVisibilityChanged(boolean showing) { |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 2348 | checkIsHandlerThread(); |
Kevin Chyn | b4514d2 | 2019-04-15 13:47:25 -0700 | [diff] [blame] | 2349 | Log.d(TAG, "onKeyguardVisibilityChanged(" + showing + ")"); |
Jorim Jaggi | 6a15d52 | 2015-09-22 15:55:33 -0700 | [diff] [blame] | 2350 | mKeyguardIsVisible = showing; |
Kevin Chyn | 6951d3d | 2019-06-10 14:07:13 -0700 | [diff] [blame] | 2351 | |
| 2352 | if (showing) { |
| 2353 | mSecureCameraLaunched = false; |
| 2354 | } |
| 2355 | |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 2356 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 2357 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 2358 | if (cb != null) { |
Jorim Jaggi | 6a15d52 | 2015-09-22 15:55:33 -0700 | [diff] [blame] | 2359 | cb.onKeyguardVisibilityChangedRaw(showing); |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 2360 | } |
| 2361 | } |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 2362 | updateBiometricListeningState(); |
Danielle Millett | f6d0fc1 | 2012-10-23 16:16:52 -0400 | [diff] [blame] | 2363 | } |
| 2364 | |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 2365 | /** |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 2366 | * Handle {@link #MSG_KEYGUARD_RESET} |
| 2367 | */ |
| 2368 | private void handleKeyguardReset() { |
| 2369 | if (DEBUG) Log.d(TAG, "handleKeyguardReset"); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 2370 | updateBiometricListeningState(); |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 2371 | mNeedsSlowUnlockTransition = resolveNeedsSlowUnlockTransition(); |
| 2372 | } |
| 2373 | |
| 2374 | private boolean resolveNeedsSlowUnlockTransition() { |
Lucas Dupin | 6c6d573 | 2019-08-27 17:36:05 -0700 | [diff] [blame] | 2375 | if (isUserUnlocked(getCurrentUser())) { |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 2376 | return false; |
| 2377 | } |
| 2378 | Intent homeIntent = new Intent(Intent.ACTION_MAIN) |
| 2379 | .addCategory(Intent.CATEGORY_HOME); |
| 2380 | ResolveInfo resolveInfo = mContext.getPackageManager().resolveActivity(homeIntent, |
| 2381 | 0 /* flags */); |
| 2382 | return FALLBACK_HOME_COMPONENT.equals(resolveInfo.getComponentInfo().getComponentName()); |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | /** |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 2386 | * Handle {@link #MSG_KEYGUARD_BOUNCER_CHANGED} |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2387 | * |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 2388 | * @see #sendKeyguardBouncerChanged(boolean) |
| 2389 | */ |
| 2390 | private void handleKeyguardBouncerChanged(int bouncer) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2391 | checkIsHandlerThread(); |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 2392 | if (DEBUG) Log.d(TAG, "handleKeyguardBouncerChanged(" + bouncer + ")"); |
| 2393 | boolean isBouncer = (bouncer == 1); |
| 2394 | mBouncer = isBouncer; |
Kevin Chyn | d038189 | 2019-07-11 16:25:36 -0700 | [diff] [blame] | 2395 | |
| 2396 | if (isBouncer) { |
| 2397 | // If the bouncer is shown, always clear this flag. This can happen in the following |
| 2398 | // situations: 1) Default camera with SHOW_WHEN_LOCKED is not chosen yet. 2) Secure |
| 2399 | // camera requests dismiss keyguard (tapping on photos for example). When these happen, |
| 2400 | // face auth should resume. |
| 2401 | mSecureCameraLaunched = false; |
| 2402 | } |
| 2403 | |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 2404 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 2405 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 2406 | if (cb != null) { |
| 2407 | cb.onKeyguardBouncerChanged(isBouncer); |
| 2408 | } |
| 2409 | } |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 2410 | updateBiometricListeningState(); |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | /** |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 2414 | * Handle {@link #MSG_REPORT_EMERGENCY_CALL_ACTION} |
| 2415 | */ |
| 2416 | private void handleReportEmergencyCallAction() { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2417 | checkIsHandlerThread(); |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 2418 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 2419 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 2420 | if (cb != null) { |
| 2421 | cb.onEmergencyCallAction(); |
| 2422 | } |
| 2423 | } |
| 2424 | } |
| 2425 | |
Lucas Dupin | 4272f44 | 2018-01-13 22:00:35 -0800 | [diff] [blame] | 2426 | private boolean isBatteryUpdateInteresting(BatteryStatus old, BatteryStatus current) { |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2427 | final boolean nowPluggedIn = current.isPluggedIn(); |
| 2428 | final boolean wasPluggedIn = old.isPluggedIn(); |
Lucas Dupin | 4272f44 | 2018-01-13 22:00:35 -0800 | [diff] [blame] | 2429 | final boolean stateChangedWhilePluggedIn = wasPluggedIn && nowPluggedIn |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2430 | && (old.status != current.status); |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 2431 | |
| 2432 | // change in plug state is always interesting |
| 2433 | if (wasPluggedIn != nowPluggedIn || stateChangedWhilePluggedIn) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2434 | return true; |
| 2435 | } |
| 2436 | |
Lucas Dupin | 3fcdd47 | 2018-01-19 19:06:45 -0800 | [diff] [blame] | 2437 | // change in battery level |
| 2438 | if (old.level != current.level) { |
Jim Miller | 16464b8 | 2011-10-20 21:10:13 -0700 | [diff] [blame] | 2439 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2440 | } |
Adrian Roos | 76dc5a5 | 2015-07-21 16:20:36 -0700 | [diff] [blame] | 2441 | |
| 2442 | // change in charging current while plugged in |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 2443 | if (nowPluggedIn && current.maxChargingWattage != old.maxChargingWattage) { |
Adrian Roos | 76dc5a5 | 2015-07-21 16:20:36 -0700 | [diff] [blame] | 2444 | return true; |
| 2445 | } |
| 2446 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2447 | return false; |
| 2448 | } |
| 2449 | |
| 2450 | /** |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2451 | * Remove the given observer's callback. |
| 2452 | * |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 2453 | * @param callback The callback to remove |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2454 | */ |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 2455 | public void removeCallback(KeyguardUpdateMonitorCallback callback) { |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 2456 | checkIsHandlerThread(); |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2457 | if (DEBUG) { |
| 2458 | Log.v(TAG, "*** unregister callback for " + callback); |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 2459 | } |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2460 | |
| 2461 | mCallbacks.removeIf(el -> el.get() == callback); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2462 | } |
| 2463 | |
| 2464 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2465 | * Register to receive notifications about general keyguard information |
| 2466 | * (see {@link InfoCallback}. |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2467 | * |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 2468 | * @param callback The callback to register |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2469 | */ |
Jim Miller | bbf1a74 | 2012-07-17 18:30:30 -0700 | [diff] [blame] | 2470 | public void registerCallback(KeyguardUpdateMonitorCallback callback) { |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 2471 | checkIsHandlerThread(); |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 2472 | if (DEBUG) Log.v(TAG, "*** register callback for " + callback); |
| 2473 | // Prevent adding duplicate callbacks |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2474 | |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 2475 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 2476 | if (mCallbacks.get(i).get() == callback) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2477 | if (DEBUG) { |
| 2478 | Log.e(TAG, "Object tried to add another callback", |
| 2479 | new Exception("Called by")); |
| 2480 | } |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 2481 | return; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 2482 | } |
| 2483 | } |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2484 | mCallbacks.add(new WeakReference<>(callback)); |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 2485 | removeCallback(null); // remove unused references |
| 2486 | sendUpdates(callback); |
| 2487 | } |
| 2488 | |
Lucas Dupin | 9e484aa | 2019-06-24 13:38:00 -0700 | [diff] [blame] | 2489 | public void setKeyguardBypassController(KeyguardBypassController keyguardBypassController) { |
| 2490 | mKeyguardBypassController = keyguardBypassController; |
| 2491 | } |
| 2492 | |
Lucas Dupin | c12fad3 | 2019-05-14 20:59:17 +0000 | [diff] [blame] | 2493 | public boolean isSwitchingUser() { |
| 2494 | return mSwitchingUser; |
| 2495 | } |
| 2496 | |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 2497 | @AnyThread |
Evan Rosky | 1839645 | 2016-07-27 15:19:37 -0700 | [diff] [blame] | 2498 | public void setSwitchingUser(boolean switching) { |
Lucas Dupin | c12fad3 | 2019-05-14 20:59:17 +0000 | [diff] [blame] | 2499 | mSwitchingUser = switching; |
Selim Cinek | bbe1924 | 2017-12-08 15:42:08 -0800 | [diff] [blame] | 2500 | // Since this comes in on a binder thread, we need to post if first |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 2501 | mHandler.post(mUpdateBiometricListeningState); |
Evan Rosky | 1839645 | 2016-07-27 15:19:37 -0700 | [diff] [blame] | 2502 | } |
| 2503 | |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 2504 | private void sendUpdates(KeyguardUpdateMonitorCallback callback) { |
| 2505 | // Notify listener of the current state |
| 2506 | callback.onRefreshBatteryInfo(mBatteryStatus); |
| 2507 | callback.onTimeChanged(); |
| 2508 | callback.onRingerModeChanged(mRingMode); |
| 2509 | callback.onPhoneStateChanged(mPhoneState); |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 2510 | callback.onRefreshCarrierInfo(); |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 2511 | callback.onClockVisibilityChanged(); |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 2512 | callback.onKeyguardVisibilityChangedRaw(mKeyguardIsVisible); |
Bill Lin | ef81cbd | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 2513 | callback.onTelephonyCapable(mTelephonyCapable); |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 2514 | for (Entry<Integer, SimData> data : mSimDatas.entrySet()) { |
| 2515 | final SimData state = data.getValue(); |
| 2516 | callback.onSimStateChanged(state.subId, state.slotId, state.simState); |
| 2517 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2518 | } |
| 2519 | |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 2520 | public void sendKeyguardReset() { |
| 2521 | mHandler.obtainMessage(MSG_KEYGUARD_RESET).sendToTarget(); |
| 2522 | } |
| 2523 | |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 2524 | /** |
| 2525 | * @see #handleKeyguardBouncerChanged(int) |
| 2526 | */ |
| 2527 | public void sendKeyguardBouncerChanged(boolean showingBouncer) { |
| 2528 | if (DEBUG) Log.d(TAG, "sendKeyguardBouncerChanged(" + showingBouncer + ")"); |
| 2529 | Message message = mHandler.obtainMessage(MSG_KEYGUARD_BOUNCER_CHANGED); |
| 2530 | message.arg1 = showingBouncer ? 1 : 0; |
| 2531 | message.sendToTarget(); |
| 2532 | } |
| 2533 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2534 | /** |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 2535 | * 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] | 2536 | * have the information earlier than waiting for the intent |
| 2537 | * broadcast from the telephony code. |
Jim Miller | 90d5d46 | 2011-11-17 16:57:01 -0800 | [diff] [blame] | 2538 | * |
| 2539 | * NOTE: Because handleSimStateChange() invokes callbacks immediately without going |
| 2540 | * 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] | 2541 | */ |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 2542 | @MainThread |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 2543 | public void reportSimUnlocked(int subId) { |
| 2544 | if (DEBUG_SIM_STATES) Log.v(TAG, "reportSimUnlocked(subId=" + subId + ")"); |
Lucas Dupin | 10960bd | 2019-09-27 16:08:32 -0700 | [diff] [blame] | 2545 | handleSimStateChange(subId, getSlotId(subId), State.READY); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2546 | } |
| 2547 | |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 2548 | /** |
| 2549 | * Report that the emergency call button has been pressed and the emergency dialer is |
| 2550 | * about to be displayed. |
| 2551 | * |
| 2552 | * @param bypassHandler runs immediately. |
| 2553 | * |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2554 | * NOTE: Must be called from UI thread if bypassHandler == true. |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 2555 | */ |
| 2556 | public void reportEmergencyCallAction(boolean bypassHandler) { |
| 2557 | if (!bypassHandler) { |
| 2558 | mHandler.obtainMessage(MSG_REPORT_EMERGENCY_CALL_ACTION).sendToTarget(); |
| 2559 | } else { |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 2560 | checkIsHandlerThread(); |
Brian Colonna | 7fce380 | 2013-09-17 15:51:32 -0400 | [diff] [blame] | 2561 | handleReportEmergencyCallAction(); |
| 2562 | } |
| 2563 | } |
| 2564 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2565 | /** |
| 2566 | * @return Whether the device is provisioned (whether they have gone through |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2567 | * the setup wizard) |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2568 | */ |
| 2569 | public boolean isDeviceProvisioned() { |
| 2570 | return mDeviceProvisioned; |
| 2571 | } |
| 2572 | |
Kensuke Matsui | 21d1bf1 | 2017-03-14 13:27:20 +0900 | [diff] [blame] | 2573 | public ServiceState getServiceState(int subId) { |
| 2574 | return mServiceStates.get(subId); |
| 2575 | } |
| 2576 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 2577 | public void clearBiometricRecognized() { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2578 | checkIsHandlerThread(); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 2579 | mUserFingerprintAuthenticated.clear(); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 2580 | mUserFaceAuthenticated.clear(); |
| 2581 | mTrustManager.clearAllBiometricRecognized(BiometricSourceType.FINGERPRINT); |
| 2582 | mTrustManager.clearAllBiometricRecognized(BiometricSourceType.FACE); |
Aran Ink | 4c0d560 | 2019-06-21 14:27:32 -0400 | [diff] [blame] | 2583 | |
| 2584 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 2585 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 2586 | if (cb != null) { |
| 2587 | cb.onBiometricsCleared(); |
| 2588 | } |
| 2589 | } |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 2590 | } |
| 2591 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 2592 | public boolean isSimPinVoiceSecure() { |
| 2593 | // TODO: only count SIMs that handle voice |
| 2594 | return isSimPinSecure(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 2595 | } |
| 2596 | |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 2597 | /** |
| 2598 | * If any SIM cards are currently secure. |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2599 | * |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 2600 | * @see #isSimPinSecure(State) |
| 2601 | */ |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 2602 | public boolean isSimPinSecure() { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 2603 | // True if any SIM is pin secure |
| 2604 | for (SubscriptionInfo info : getSubscriptionInfo(false /* forceReload */)) { |
| 2605 | if (isSimPinSecure(getSimState(info.getSubscriptionId()))) return true; |
| 2606 | } |
| 2607 | return false; |
| 2608 | } |
| 2609 | |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 2610 | public State getSimState(int subId) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 2611 | if (mSimDatas.containsKey(subId)) { |
| 2612 | return mSimDatas.get(subId).simState; |
| 2613 | } else { |
| 2614 | return State.UNKNOWN; |
| 2615 | } |
| 2616 | } |
| 2617 | |
Lucas Dupin | 10960bd | 2019-09-27 16:08:32 -0700 | [diff] [blame] | 2618 | private int getSlotId(int subId) { |
| 2619 | if (!mSimDatas.containsKey(subId)) { |
| 2620 | refreshSimState(subId, SubscriptionManager.getSlotIndex(subId)); |
| 2621 | } |
| 2622 | return mSimDatas.get(subId).slotId; |
| 2623 | } |
| 2624 | |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 2625 | private final TaskStackChangeListener |
| 2626 | mTaskStackListener = new TaskStackChangeListener() { |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 2627 | @Override |
| 2628 | public void onTaskStackChangedBackground() { |
| 2629 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2630 | ActivityManager.StackInfo info = ActivityTaskManager.getService().getStackInfo( |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2631 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_ASSISTANT); |
Kevin Chyn | 2fefd46 | 2017-04-28 12:18:19 -0700 | [diff] [blame] | 2632 | if (info == null) { |
| 2633 | return; |
| 2634 | } |
| 2635 | mHandler.sendMessage(mHandler.obtainMessage(MSG_ASSISTANT_STACK_CHANGED, |
| 2636 | info.visible)); |
| 2637 | } catch (RemoteException e) { |
| 2638 | Log.e(TAG, "unable to check task stack", e); |
| 2639 | } |
| 2640 | } |
| 2641 | }; |
| 2642 | |
Jorim Jaggi | 01ba98b | 2015-01-13 21:33:45 +0100 | [diff] [blame] | 2643 | /** |
Richard Chou | e0381b8 | 2018-04-24 03:48:59 +0000 | [diff] [blame] | 2644 | * @return true if and only if the state has changed for the specified {@code slotId} |
Jorim Jaggi | 01ba98b | 2015-01-13 21:33:45 +0100 | [diff] [blame] | 2645 | */ |
Richard Chou | e0381b8 | 2018-04-24 03:48:59 +0000 | [diff] [blame] | 2646 | private boolean refreshSimState(int subId, int slotId) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 2647 | |
| 2648 | // This is awful. It exists because there are two APIs for getting the SIM status |
| 2649 | // that don't return the complete set of values and have different types. In Keyguard we |
| 2650 | // need IccCardConstants, but TelephonyManager would only give us |
| 2651 | // TelephonyManager.SIM_STATE*, so we retrieve it manually. |
xinhe | 18b9c3c | 2014-12-02 15:03:20 -0800 | [diff] [blame] | 2652 | final TelephonyManager tele = TelephonyManager.from(mContext); |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2653 | int simState = tele.getSimState(slotId); |
Richard Chou | e0381b8 | 2018-04-24 03:48:59 +0000 | [diff] [blame] | 2654 | State state; |
| 2655 | try { |
| 2656 | state = State.intToState(simState); |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2657 | } catch (IllegalArgumentException ex) { |
Richard Chou | e0381b8 | 2018-04-24 03:48:59 +0000 | [diff] [blame] | 2658 | Log.w(TAG, "Unknown sim state: " + simState); |
| 2659 | state = State.UNKNOWN; |
John Spurlock | 5b13e92 | 2015-01-07 11:04:58 -0500 | [diff] [blame] | 2660 | } |
Richard Chou | e0381b8 | 2018-04-24 03:48:59 +0000 | [diff] [blame] | 2661 | SimData data = mSimDatas.get(subId); |
| 2662 | final boolean changed; |
| 2663 | if (data == null) { |
| 2664 | data = new SimData(state, slotId, subId); |
| 2665 | mSimDatas.put(subId, data); |
| 2666 | changed = true; // no data yet; force update |
| 2667 | } else { |
| 2668 | changed = data.simState != state; |
| 2669 | data.simState = state; |
Jorim Jaggi | 01ba98b | 2015-01-13 21:33:45 +0100 | [diff] [blame] | 2670 | } |
Richard Chou | e0381b8 | 2018-04-24 03:48:59 +0000 | [diff] [blame] | 2671 | return changed; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 2672 | } |
| 2673 | |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 2674 | /** |
| 2675 | * If the {@code state} is currently requiring a SIM PIN, PUK, or is disabled. |
| 2676 | */ |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 2677 | public static boolean isSimPinSecure(IccCardConstants.State state) { |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 2678 | return (state == IccCardConstants.State.PIN_REQUIRED |
| 2679 | || state == IccCardConstants.State.PUK_REQUIRED |
| 2680 | || state == IccCardConstants.State.PERM_DISABLED); |
Jim Miller | b030476 | 2012-03-13 20:01:25 -0700 | [diff] [blame] | 2681 | } |
Jim Miller | 8f09fd2 | 2013-03-14 19:04:28 -0700 | [diff] [blame] | 2682 | |
| 2683 | public DisplayClientState getCachedDisplayClientState() { |
| 2684 | return mDisplayClientState; |
| 2685 | } |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 2686 | |
| 2687 | // TODO: use these callbacks elsewhere in place of the existing notifyScreen*() |
| 2688 | // (KeyguardViewMediator, KeyguardHostView) |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 2689 | public void dispatchStartedWakingUp() { |
| 2690 | synchronized (this) { |
| 2691 | mDeviceInteractive = true; |
| 2692 | } |
| 2693 | mHandler.sendEmptyMessage(MSG_STARTED_WAKING_UP); |
| 2694 | } |
| 2695 | |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 2696 | public void dispatchStartedGoingToSleep(int why) { |
| 2697 | mHandler.sendMessage(mHandler.obtainMessage(MSG_STARTED_GOING_TO_SLEEP, why, 0)); |
| 2698 | } |
| 2699 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 2700 | public void dispatchFinishedGoingToSleep(int why) { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2701 | synchronized (this) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 2702 | mDeviceInteractive = false; |
| 2703 | } |
| 2704 | mHandler.sendMessage(mHandler.obtainMessage(MSG_FINISHED_GOING_TO_SLEEP, why, 0)); |
| 2705 | } |
| 2706 | |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 2707 | public void dispatchScreenTurnedOn() { |
| 2708 | synchronized (this) { |
| 2709 | mScreenOn = true; |
| 2710 | } |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 2711 | mHandler.sendEmptyMessage(MSG_SCREEN_TURNED_ON); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 2712 | } |
| 2713 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 2714 | public void dispatchScreenTurnedOff() { |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2715 | synchronized (this) { |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 2716 | mScreenOn = false; |
| 2717 | } |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 2718 | mHandler.sendEmptyMessage(MSG_SCREEN_TURNED_OFF); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 2719 | } |
| 2720 | |
Selim Cinek | 9941539 | 2016-09-09 14:58:41 -0700 | [diff] [blame] | 2721 | public void dispatchDreamingStarted() { |
| 2722 | mHandler.sendMessage(mHandler.obtainMessage(MSG_DREAMING_STATE_CHANGED, 1, 0)); |
| 2723 | } |
| 2724 | |
| 2725 | public void dispatchDreamingStopped() { |
| 2726 | mHandler.sendMessage(mHandler.obtainMessage(MSG_DREAMING_STATE_CHANGED, 0, 0)); |
| 2727 | } |
| 2728 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 2729 | public boolean isDeviceInteractive() { |
| 2730 | return mDeviceInteractive; |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 2731 | } |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 2732 | |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 2733 | public boolean isGoingToSleep() { |
| 2734 | return mGoingToSleep; |
| 2735 | } |
| 2736 | |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 2737 | /** |
| 2738 | * Find the next SubscriptionId for a SIM in the given state, favoring lower slot numbers first. |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2739 | * |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 2740 | * @return subid or {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} if none found |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 2741 | */ |
| 2742 | public int getNextSubIdForState(State state) { |
| 2743 | List<SubscriptionInfo> list = getSubscriptionInfo(false /* forceReload */); |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 2744 | int resultId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 2745 | int bestSlotId = Integer.MAX_VALUE; // Favor lowest slot first |
| 2746 | for (int i = 0; i < list.size(); i++) { |
| 2747 | final SubscriptionInfo info = list.get(i); |
| 2748 | final int id = info.getSubscriptionId(); |
Lucas Dupin | 10960bd | 2019-09-27 16:08:32 -0700 | [diff] [blame] | 2749 | int slotId = getSlotId(id); |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2750 | if (state == getSimState(id) && bestSlotId > slotId) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 2751 | resultId = id; |
| 2752 | bestSlotId = slotId; |
| 2753 | } |
| 2754 | } |
| 2755 | return resultId; |
| 2756 | } |
| 2757 | |
| 2758 | public SubscriptionInfo getSubscriptionInfoForSubId(int subId) { |
| 2759 | List<SubscriptionInfo> list = getSubscriptionInfo(false /* forceReload */); |
| 2760 | for (int i = 0; i < list.size(); i++) { |
| 2761 | SubscriptionInfo info = list.get(i); |
| 2762 | if (subId == info.getSubscriptionId()) return info; |
| 2763 | } |
| 2764 | return null; // not found |
| 2765 | } |
Jason Monk | ab52527 | 2015-07-13 17:02:49 -0400 | [diff] [blame] | 2766 | |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 2767 | /** |
| 2768 | * @return a cached version of DevicePolicyManager.isLogoutEnabled() |
| 2769 | */ |
| 2770 | public boolean isLogoutEnabled() { |
| 2771 | return mLogoutEnabled; |
| 2772 | } |
| 2773 | |
| 2774 | private void updateLogoutEnabled() { |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 2775 | checkIsHandlerThread(); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 2776 | boolean logoutEnabled = mDevicePolicyManager.isLogoutEnabled(); |
| 2777 | if (mLogoutEnabled != logoutEnabled) { |
| 2778 | mLogoutEnabled = logoutEnabled; |
Dave Mankoff | 4b0ab65 | 2019-08-07 09:49:20 -0400 | [diff] [blame] | 2779 | |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 2780 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 2781 | KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); |
| 2782 | if (cb != null) { |
| 2783 | cb.onLogoutEnabledChanged(); |
| 2784 | } |
| 2785 | } |
| 2786 | } |
| 2787 | } |
| 2788 | |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 2789 | private void checkIsHandlerThread() { |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 2790 | if (!mHandler.getLooper().isCurrentThread()) { |
Dave Mankoff | 898e1bb | 2019-09-25 17:54:19 -0400 | [diff] [blame] | 2791 | Log.wtfStack(TAG, "must call on mHandler's thread " |
Adrian Roos | 30a2ae6 | 2018-04-25 19:09:50 +0200 | [diff] [blame] | 2792 | + mHandler.getLooper().getThread() + ", not " + Thread.currentThread()); |
| 2793 | } |
| 2794 | } |
| 2795 | |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 2796 | @Override |
Jason Monk | ab52527 | 2015-07-13 17:02:49 -0400 | [diff] [blame] | 2797 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 2798 | pw.println("KeyguardUpdateMonitor state:"); |
| 2799 | pw.println(" SIM States:"); |
| 2800 | for (SimData data : mSimDatas.values()) { |
| 2801 | pw.println(" " + data.toString()); |
| 2802 | } |
| 2803 | pw.println(" Subs:"); |
| 2804 | if (mSubscriptionInfo != null) { |
| 2805 | for (int i = 0; i < mSubscriptionInfo.size(); i++) { |
| 2806 | pw.println(" " + mSubscriptionInfo.get(i)); |
| 2807 | } |
| 2808 | } |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame] | 2809 | pw.println(" Current active data subId=" + mActiveMobileDataSubscription); |
Jason Monk | ab52527 | 2015-07-13 17:02:49 -0400 | [diff] [blame] | 2810 | pw.println(" Service states:"); |
| 2811 | for (int subId : mServiceStates.keySet()) { |
| 2812 | pw.println(" " + subId + "=" + mServiceStates.get(subId)); |
| 2813 | } |
Jim Miller | d72d5ac | 2015-09-29 18:55:32 -0700 | [diff] [blame] | 2814 | if (mFpm != null && mFpm.isHardwareDetected()) { |
| 2815 | final int userId = ActivityManager.getCurrentUser(); |
| 2816 | final int strongAuthFlags = mStrongAuthTracker.getStrongAuthForUser(userId); |
| 2817 | pw.println(" Fingerprint state (user=" + userId + ")"); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 2818 | pw.println(" allowed=" + isUnlockingWithBiometricAllowed()); |
Jim Miller | d72d5ac | 2015-09-29 18:55:32 -0700 | [diff] [blame] | 2819 | pw.println(" auth'd=" + mUserFingerprintAuthenticated.get(userId)); |
| 2820 | pw.println(" authSinceBoot=" |
| 2821 | + getStrongAuthTracker().hasUserAuthenticatedSinceBoot()); |
| 2822 | pw.println(" disabled(DPM)=" + isFingerprintDisabled(userId)); |
| 2823 | pw.println(" possible=" + isUnlockWithFingerprintPossible(userId)); |
Adrian Roos | 2aaf944 | 2018-11-20 16:57:33 +0100 | [diff] [blame] | 2824 | pw.println(" listening: actual=" + mFingerprintRunningState |
| 2825 | + " expected=" + (shouldListenForFingerprint() ? 1 : 0)); |
Jim Miller | d72d5ac | 2015-09-29 18:55:32 -0700 | [diff] [blame] | 2826 | pw.println(" strongAuthFlags=" + Integer.toHexString(strongAuthFlags)); |
Jim Miller | d72d5ac | 2015-09-29 18:55:32 -0700 | [diff] [blame] | 2827 | pw.println(" trustManaged=" + getUserTrustIsManaged(userId)); |
| 2828 | } |
Kevin Chyn | b7b54a6 | 2018-09-28 18:48:12 -0700 | [diff] [blame] | 2829 | if (mFaceManager != null && mFaceManager.isHardwareDetected()) { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 2830 | final int userId = ActivityManager.getCurrentUser(); |
| 2831 | final int strongAuthFlags = mStrongAuthTracker.getStrongAuthForUser(userId); |
| 2832 | pw.println(" Face authentication state (user=" + userId + ")"); |
| 2833 | pw.println(" allowed=" + isUnlockingWithBiometricAllowed()); |
| 2834 | pw.println(" auth'd=" + mUserFaceAuthenticated.get(userId)); |
| 2835 | pw.println(" authSinceBoot=" |
| 2836 | + getStrongAuthTracker().hasUserAuthenticatedSinceBoot()); |
| 2837 | pw.println(" disabled(DPM)=" + isFaceDisabled(userId)); |
| 2838 | pw.println(" possible=" + isUnlockWithFacePossible(userId)); |
| 2839 | pw.println(" strongAuthFlags=" + Integer.toHexString(strongAuthFlags)); |
| 2840 | pw.println(" trustManaged=" + getUserTrustIsManaged(userId)); |
Lucas Dupin | 7d95f15 | 2019-07-17 16:25:54 -0700 | [diff] [blame] | 2841 | pw.println(" enabledByUser=" + mFaceSettingEnabledForUser.get(userId)); |
Kevin Chyn | d038189 | 2019-07-11 16:25:36 -0700 | [diff] [blame] | 2842 | pw.println(" mSecureCameraLaunched=" + mSecureCameraLaunched); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 2843 | } |
Jason Monk | ab52527 | 2015-07-13 17:02:49 -0400 | [diff] [blame] | 2844 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2845 | } |