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