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