blob: 6685db130d4ae0f2167d07e353da6efda5eef5c6 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
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 Miller5ecd8112013-01-09 18:50:26 -080017package com.android.keyguard;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080018
Wale Ogunwale68278562017-09-23 17:13:55 -070019import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT;
20import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
Lucas Dupin6c6d5732019-08-27 17:36:05 -070021import static android.content.Intent.ACTION_USER_REMOVED;
22import static android.content.Intent.ACTION_USER_STOPPED;
Jorim Jaggidadafd42016-09-30 07:20:25 -070023import static android.content.Intent.ACTION_USER_UNLOCKED;
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070024import static android.os.BatteryManager.BATTERY_HEALTH_UNKNOWN;
25import static android.os.BatteryManager.BATTERY_STATUS_FULL;
26import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN;
27import static android.os.BatteryManager.EXTRA_HEALTH;
28import static android.os.BatteryManager.EXTRA_LEVEL;
29import static android.os.BatteryManager.EXTRA_MAX_CHARGING_CURRENT;
30import static android.os.BatteryManager.EXTRA_MAX_CHARGING_VOLTAGE;
31import static android.os.BatteryManager.EXTRA_PLUGGED;
32import static android.os.BatteryManager.EXTRA_STATUS;
Fabian Kozynskiccde55d2019-06-26 10:06:09 -040033import static android.telephony.PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE;
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070034
Malcolm Chen5c63b512019-08-13 13:24:07 -070035import static com.android.internal.telephony.PhoneConstants.MAX_PHONE_COUNT_DUAL_SIM;
Lucas Dupin8eec2682019-07-01 16:41:17 -070036import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT;
37import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW;
38import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT;
39import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT;
40import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN;
Lucas Dupin8968f6a2019-08-09 17:41:15 -070041import static com.android.systemui.DejankUtils.whitelistIpcs;
Lucas Dupin8eec2682019-07-01 16:41:17 -070042
Adrian Roos30a2ae62018-04-25 19:09:50 +020043import android.annotation.AnyThread;
44import android.annotation.MainThread;
Jorim Jaggiccdfa932015-04-13 16:29:48 -070045import android.app.ActivityManager;
Wale Ogunwale04d9cb52018-04-30 13:55:07 -070046import android.app.ActivityTaskManager;
Jorim Jaggic7dea6e2014-07-26 14:36:57 +020047import android.app.AlarmManager;
Jim Miller8f09fd22013-03-14 19:04:28 -070048import android.app.PendingIntent;
Sudheer Shanka2c4522c2016-08-27 20:53:28 -070049import android.app.UserSwitchObserver;
Jim Millerb0304762012-03-13 20:01:25 -070050import android.app.admin.DevicePolicyManager;
Adrian Roos46842d92014-03-27 14:58:03 +010051import android.app.trust.TrustManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080052import android.content.BroadcastReceiver;
Jorim Jaggi031f7952016-09-01 16:39:26 -070053import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080054import android.content.Context;
55import android.content.Intent;
56import android.content.IntentFilter;
Adrian Roosca8a2162017-08-17 19:00:58 +020057import android.content.pm.IPackageManager;
Jorim Jaggi031f7952016-09-01 16:39:26 -070058import android.content.pm.PackageManager;
59import android.content.pm.ResolveInfo;
Lucas Dupinf2c53502019-10-03 13:56:18 -070060import android.content.pm.UserInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080061import android.database.ContentObserver;
Kevin Chynb7b54a62018-09-28 18:48:12 -070062import android.hardware.biometrics.BiometricManager;
Kevin Chyn56233ab2018-09-20 17:10:57 -070063import android.hardware.biometrics.BiometricSourceType;
Kevin Chynb7b54a62018-09-28 18:48:12 -070064import android.hardware.biometrics.IBiometricEnabledOnKeyguardCallback;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020065import android.hardware.face.FaceManager;
Jorim Jaggi86bed402015-08-20 18:20:02 -070066import android.hardware.fingerprint.FingerprintManager;
67import android.hardware.fingerprint.FingerprintManager.AuthenticationCallback;
68import android.hardware.fingerprint.FingerprintManager.AuthenticationResult;
Jim Miller47088bb2009-11-24 00:40:16 -080069import android.media.AudioManager;
Jim Miller79a444a2011-02-15 15:02:11 -080070import android.os.BatteryManager;
Jim Miller9f0753f2015-03-23 23:59:22 -070071import android.os.CancellationSignal;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080072import android.os.Handler;
Dianne Hackborn5dc5a002012-09-15 19:33:48 -070073import android.os.IRemoteCallback;
Jason Monk7bb59302018-05-10 19:38:18 -070074import android.os.Looper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080075import android.os.Message;
Dianne Hackborn5dc5a002012-09-15 19:33:48 -070076import android.os.RemoteException;
Adrian Roosca8a2162017-08-17 19:00:58 +020077import android.os.ServiceManager;
Nick Desaulniers1d396752016-07-25 15:05:33 -070078import android.os.Trace;
Amith Yamasanie8e93a12013-05-09 18:12:30 -070079import android.os.UserHandle;
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070080import android.os.UserManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080081import android.provider.Settings;
Kevin Chyn36778ff2017-09-07 19:55:38 -070082import android.service.dreams.DreamService;
83import android.service.dreams.IDreamManager;
Malcolm Chen5c63b512019-08-13 13:24:07 -070084import android.telephony.CarrierConfigManager;
Fabian Kozynskiccde55d2019-06-26 10:06:09 -040085import android.telephony.PhoneStateListener;
Etan Cohen47051d82015-07-06 16:19:04 -070086import android.telephony.ServiceState;
Jim Miller52a61332014-11-12 19:29:51 -080087import android.telephony.SubscriptionInfo;
Jim Miller52a61332014-11-12 19:29:51 -080088import android.telephony.SubscriptionManager;
Wink Savilled09c4ca2014-11-22 10:08:16 -080089import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
Jim Millerc23024d2010-02-24 15:37:00 -080090import android.telephony.TelephonyManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080091import android.util.Log;
Adrian Roos46842d92014-03-27 14:58:03 +010092import android.util.SparseBooleanArray;
93
Lucas Dupin7517b5d2017-08-22 12:51:25 -070094import com.android.internal.annotations.VisibleForTesting;
Jorim Jaggi86bed402015-08-20 18:20:02 -070095import com.android.internal.telephony.IccCardConstants;
96import com.android.internal.telephony.IccCardConstants.State;
97import com.android.internal.telephony.PhoneConstants;
98import com.android.internal.telephony.TelephonyIntents;
Adrian Roosb5e47222015-08-14 15:53:06 -070099import com.android.internal.widget.LockPatternUtils;
Bill Linef81cbd2018-07-05 17:48:49 +0800100import com.android.settingslib.WirelessUtils;
Lucas Dupind236ee32019-10-08 15:33:59 -0700101import com.android.systemui.DejankUtils;
Lucas Dupin64171fe2019-10-30 14:28:29 -0700102import com.android.systemui.DumpController;
103import com.android.systemui.Dumpable;
Hyunyoung Song8f9d34c2019-08-30 14:47:43 -0700104import com.android.systemui.R;
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000105import com.android.systemui.broadcast.BroadcastDispatcher;
Dave Mankofff4736812019-10-18 17:25:50 -0400106import com.android.systemui.dagger.qualifiers.MainLooper;
Winson Chung2cf6ad82017-11-09 17:36:59 -0800107import com.android.systemui.shared.system.ActivityManagerWrapper;
Winson Chung67f5c8b2018-09-24 12:09:19 -0700108import com.android.systemui.shared.system.TaskStackChangeListener;
Lucas Dupin9e484aa2019-06-24 13:38:00 -0700109import com.android.systemui.statusbar.phone.KeyguardBypassController;
Kevin Chyn1123ba72018-10-26 10:34:06 -0700110
Kevin Chyn36778ff2017-09-07 19:55:38 -0700111import com.google.android.collect.Lists;
112
Jason Monkab525272015-07-13 17:02:49 -0400113import java.io.FileDescriptor;
114import java.io.PrintWriter;
Jim Millerdcb3d842012-08-23 19:18:12 -0700115import java.lang.ref.WeakReference;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800116import java.util.ArrayList;
Jim Miller52a61332014-11-12 19:29:51 -0800117import java.util.HashMap;
118import java.util.List;
119import java.util.Map.Entry;
Robert Snoeberger9c1074f2018-12-07 17:35:21 -0500120import java.util.TimeZone;
Lucas Dupin3d053532019-01-29 12:35:22 -0800121import java.util.function.Consumer;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800122
Dave Mankoffe2294692019-08-14 11:53:13 -0400123import javax.inject.Inject;
Lucas Dupinab39e802019-10-08 14:42:00 -0700124import javax.inject.Singleton;
Dave Mankoffe2294692019-08-14 11:53:13 -0400125
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800126/**
127 * Watches for updates that may be interesting to the keyguard, and provides
128 * the up to date information as well as a registration for callbacks that care
129 * to be updated.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800130 */
Lucas Dupinab39e802019-10-08 14:42:00 -0700131@Singleton
Lucas Dupin64171fe2019-10-30 14:28:29 -0700132public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpable {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800133
Jim Millerbbf1a742012-07-17 18:30:30 -0700134 private static final String TAG = "KeyguardUpdateMonitor";
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100135 private static final boolean DEBUG = KeyguardConstants.DEBUG;
Jim Miller52a61332014-11-12 19:29:51 -0800136 private static final boolean DEBUG_SIM_STATES = KeyguardConstants.DEBUG_SIM_STATES;
Lucas Dupin71d2fb22019-05-30 18:26:54 -0700137 private static final boolean DEBUG_FACE = true;
Jim Millerbbf1a742012-07-17 18:30:30 -0700138 private static final int LOW_BATTERY_THRESHOLD = 20;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800139
Jorim Jaggie7b12522014-08-06 16:41:21 +0200140 private static final String ACTION_FACE_UNLOCK_STARTED
141 = "com.android.facelock.FACE_UNLOCK_STARTED";
142 private static final String ACTION_FACE_UNLOCK_STOPPED
143 = "com.android.facelock.FACE_UNLOCK_STOPPED";
144
Jim Millerbbf1a742012-07-17 18:30:30 -0700145 // Callback messages
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800146 private static final int MSG_TIME_UPDATE = 301;
147 private static final int MSG_BATTERY_UPDATE = 302;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800148 private static final int MSG_SIM_STATE_CHANGE = 304;
Jim Miller47088bb2009-11-24 00:40:16 -0800149 private static final int MSG_RINGER_MODE_CHANGED = 305;
Jim Millerc23024d2010-02-24 15:37:00 -0800150 private static final int MSG_PHONE_STATE_CHANGED = 306;
Nick Pelly24d7b5f2011-10-11 12:51:09 -0700151 private static final int MSG_DEVICE_PROVISIONED = 308;
Jim Miller57375342012-09-09 15:20:31 -0700152 private static final int MSG_DPM_STATE_CHANGED = 309;
Chris Wrenf41c61b2012-11-29 15:19:54 -0500153 private static final int MSG_USER_SWITCHING = 310;
Selim Cinek1fcafc42015-07-20 14:39:25 -0700154 private static final int MSG_KEYGUARD_RESET = 312;
Jim Millerf41fc962014-06-18 16:33:51 -0700155 private static final int MSG_BOOT_COMPLETED = 313;
Chris Wrenf41c61b2012-11-29 15:19:54 -0500156 private static final int MSG_USER_SWITCH_COMPLETE = 314;
Jim Millerf41fc962014-06-18 16:33:51 -0700157 private static final int MSG_USER_INFO_CHANGED = 317;
158 private static final int MSG_REPORT_EMERGENCY_CALL_ACTION = 318;
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700159 private static final int MSG_STARTED_WAKING_UP = 319;
160 private static final int MSG_FINISHED_GOING_TO_SLEEP = 320;
Jorim Jaggi95e40382015-09-16 15:53:42 -0700161 private static final int MSG_STARTED_GOING_TO_SLEEP = 321;
Adrian Roosb6011622014-05-14 15:52:53 +0200162 private static final int MSG_KEYGUARD_BOUNCER_CHANGED = 322;
Jim Millerce7eb6d2015-04-03 19:29:13 -0700163 private static final int MSG_FACE_UNLOCK_STATE_CHANGED = 327;
164 private static final int MSG_SIM_SUBSCRIPTION_INFO_CHANGED = 328;
Jason Monk052082c2015-06-11 11:35:23 -0400165 private static final int MSG_AIRPLANE_MODE_CHANGED = 329;
Etan Cohen47051d82015-07-06 16:19:04 -0700166 private static final int MSG_SERVICE_STATE_CHANGE = 330;
Jorim Jaggif1518da2015-07-30 11:56:36 -0700167 private static final int MSG_SCREEN_TURNED_ON = 331;
168 private static final int MSG_SCREEN_TURNED_OFF = 332;
Selim Cinek99415392016-09-09 14:58:41 -0700169 private static final int MSG_DREAMING_STATE_CHANGED = 333;
Jorim Jaggidadafd42016-09-30 07:20:25 -0700170 private static final int MSG_USER_UNLOCKED = 334;
Kevin Chyn2fefd462017-04-28 12:18:19 -0700171 private static final int MSG_ASSISTANT_STACK_CHANGED = 335;
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200172 private static final int MSG_BIOMETRIC_AUTHENTICATION_CONTINUE = 336;
Alex Chauff7653d2018-02-01 17:18:08 +0000173 private static final int MSG_DEVICE_POLICY_MANAGER_STATE_CHANGED = 337;
Bill Linef81cbd2018-07-05 17:48:49 +0800174 private static final int MSG_TELEPHONY_CAPABLE = 338;
Robert Snoeberger9c1074f2018-12-07 17:35:21 -0500175 private static final int MSG_TIMEZONE_UPDATE = 339;
Lucas Dupin6c6d5732019-08-27 17:36:05 -0700176 private static final int MSG_USER_STOPPED = 340;
177 private static final int MSG_USER_REMOVED = 341;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800178
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200179 /** Biometric authentication state: Not listening. */
180 private static final int BIOMETRIC_STATE_STOPPED = 0;
Jorim Jaggi86bed402015-08-20 18:20:02 -0700181
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200182 /** Biometric authentication state: Listening. */
183 private static final int BIOMETRIC_STATE_RUNNING = 1;
Jorim Jaggi86bed402015-08-20 18:20:02 -0700184
185 /**
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200186 * Biometric authentication: Cancelling and waiting for the relevant biometric service to
Jorim Jaggi86bed402015-08-20 18:20:02 -0700187 * send us the confirmation that cancellation has happened.
188 */
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200189 private static final int BIOMETRIC_STATE_CANCELLING = 2;
Jorim Jaggi86bed402015-08-20 18:20:02 -0700190
191 /**
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200192 * Biometric state: During cancelling we got another request to start listening, so when we
Jorim Jaggi86bed402015-08-20 18:20:02 -0700193 * receive the cancellation done signal, we should start listening again.
194 */
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200195 private static final int BIOMETRIC_STATE_CANCELLING_RESTARTING = 3;
Jorim Jaggi86bed402015-08-20 18:20:02 -0700196
Lucas Dupin51996bb2019-05-16 17:56:43 -0700197 private static final int BIOMETRIC_HELP_FINGERPRINT_NOT_RECOGNIZED = -1;
198 public static final int BIOMETRIC_HELP_FACE_NOT_RECOGNIZED = -2;
199
Adrian Roos0c859ae2015-11-23 16:47:50 -0800200 private static final int DEFAULT_CHARGING_VOLTAGE_MICRO_VOLT = 5000000;
joshmccloskey7dee4542019-07-31 18:35:33 -0700201 /**
202 * If no cancel signal has been received after this amount of time, set the biometric running
203 * state to stopped to allow Keyguard to retry authentication.
204 */
205 private static final int DEFAULT_CANCEL_SIGNAL_TIMEOUT = 3000;
Adrian Roos0c859ae2015-11-23 16:47:50 -0800206
Jorim Jaggi031f7952016-09-01 16:39:26 -0700207 private static final ComponentName FALLBACK_HOME_COMPONENT = new ComponentName(
208 "com.android.settings", "com.android.settings.FallbackHome");
209
Adrian Roosca8a2162017-08-17 19:00:58 +0200210
211 /**
212 * If true, the system is in the half-boot-to-decryption-screen state.
213 * Prudently disable lockscreen.
214 */
215 public static final boolean CORE_APPS_ONLY;
Lucas Dupin71d2fb22019-05-30 18:26:54 -0700216
Adrian Roosca8a2162017-08-17 19:00:58 +0200217 static {
218 try {
219 CORE_APPS_ONLY = IPackageManager.Stub.asInterface(
220 ServiceManager.getService("package")).isOnlyCoreApps();
221 } catch (RemoteException e) {
222 throw e.rethrowFromSystemServer();
223 }
224 }
225
Jim Millerbbf1a742012-07-17 18:30:30 -0700226 private final Context mContext;
Kevin Chynfdfd2d32019-03-01 14:52:15 -0800227 private final boolean mIsPrimaryUser;
Lucas Dupin10960bd2019-09-27 16:08:32 -0700228 HashMap<Integer, SimData> mSimDatas = new HashMap<>();
Etan Cohen47051d82015-07-06 16:19:04 -0700229 HashMap<Integer, ServiceState> mServiceStates = new HashMap<Integer, ServiceState>();
Jim Millerbbf1a742012-07-17 18:30:30 -0700230
Jim Millerbbf1a742012-07-17 18:30:30 -0700231 private int mRingMode;
232 private int mPhoneState;
Danielle Millett5d2404d2012-11-01 00:05:27 -0400233 private boolean mKeyguardIsVisible;
Kevin Chynf3b8fbd2017-05-03 22:24:31 -0700234 private boolean mKeyguardGoingAway;
Jorim Jaggi95e40382015-09-16 15:53:42 -0700235 private boolean mGoingToSleep;
Adrian Roosb6011622014-05-14 15:52:53 +0200236 private boolean mBouncer;
Lucas Dupine0516d52019-02-05 17:54:06 -0500237 private boolean mAuthInterruptActive;
Adam Cohen4eb36cf2012-11-07 11:45:30 -0800238 private boolean mBootCompleted;
Jorim Jaggi031f7952016-09-01 16:39:26 -0700239 private boolean mNeedsSlowUnlockTransition;
Jorim Jaggid11d1a92016-08-16 16:02:32 -0700240 private boolean mHasLockscreenWallpaper;
Kevin Chyn2fefd462017-04-28 12:18:19 -0700241 private boolean mAssistantVisible;
242 private boolean mKeyguardOccluded;
Kevin Chyn6951d3d2019-06-10 14:07:13 -0700243 private boolean mSecureCameraLaunched;
Bill Linef81cbd2018-07-05 17:48:49 +0800244 @VisibleForTesting
245 protected boolean mTelephonyCapable;
Jim Millerbbf1a742012-07-17 18:30:30 -0700246
Jim Millerdcb3d842012-08-23 19:18:12 -0700247 // Device provisioning state
Jim Millerbbf1a742012-07-17 18:30:30 -0700248 private boolean mDeviceProvisioned;
249
Jim Millerdcb3d842012-08-23 19:18:12 -0700250 // Battery status
Jim Millerbbf1a742012-07-17 18:30:30 -0700251 private BatteryStatus mBatteryStatus;
252
Lucas Dupin3d053532019-01-29 12:35:22 -0800253 @VisibleForTesting
254 protected StrongAuthTracker mStrongAuthTracker;
Jim Millerbbf1a742012-07-17 18:30:30 -0700255
Jim Miller6212cc02012-09-05 17:35:31 -0700256 private final ArrayList<WeakReference<KeyguardUpdateMonitorCallback>>
Jim Millerdcb3d842012-08-23 19:18:12 -0700257 mCallbacks = Lists.newArrayList();
Michael Jurkafff56142012-11-28 16:51:00 -0800258 private ContentObserver mDeviceProvisionedObserver;
Jim Millerbbf1a742012-07-17 18:30:30 -0700259
Brian Colonnaa5239892013-04-15 11:45:40 -0400260 private boolean mSwitchingUser;
261
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700262 private boolean mDeviceInteractive;
Jim Miller20daffd2013-10-07 14:59:53 -0700263 private boolean mScreenOn;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800264 private SubscriptionManager mSubscriptionManager;
265 private List<SubscriptionInfo> mSubscriptionInfo;
Jorim Jaggi237b0612015-05-01 14:28:49 -0700266 private TrustManager mTrustManager;
Jorim Jaggie8fde5d2016-06-30 23:41:37 -0700267 private UserManager mUserManager;
Lucas Dupin9e484aa2019-06-24 13:38:00 -0700268 private KeyguardBypassController mKeyguardBypassController;
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200269 private int mFingerprintRunningState = BIOMETRIC_STATE_STOPPED;
270 private int mFaceRunningState = BIOMETRIC_STATE_STOPPED;
Michal Karpinskic52f8672016-11-18 11:32:45 +0000271 private LockPatternUtils mLockPatternUtils;
Kevin Chyn36778ff2017-09-07 19:55:38 -0700272 private final IDreamManager mDreamManager;
273 private boolean mIsDreaming;
Alex Chauff7653d2018-02-01 17:18:08 +0000274 private final DevicePolicyManager mDevicePolicyManager;
275 private boolean mLogoutEnabled;
Lucas Dupinca88e5f2019-05-14 16:11:08 -0700276 // If the user long pressed the lock icon, disabling face auth for the current session.
277 private boolean mLockIconPressed;
Malcolm Chen5c63b512019-08-13 13:24:07 -0700278 private int mActiveMobileDataSubscription = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Jim Miller20daffd2013-10-07 14:59:53 -0700279
Kevin Chyn0f3e0b12017-07-20 16:56:11 -0700280 /**
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200281 * 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 Chyn0f3e0b12017-07-20 16:56:11 -0700284 */
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200285 private static final int BIOMETRIC_CONTINUE_DELAY_MS = 500;
Kevin Chyn0f3e0b12017-07-20 16:56:11 -0700286
Kevin Chyne1ac0c02019-07-26 17:54:46 -0700287 // If the HAL dies or is unable to authenticate, keyguard should retry after a short delay
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200288 private int mHardwareFingerprintUnavailableRetryCount = 0;
289 private int mHardwareFaceUnavailableRetryCount = 0;
Kevin Chyne1ac0c02019-07-26 17:54:46 -0700290 private static final int HAL_ERROR_RETRY_TIMEOUT = 500; // ms
291 private static final int HAL_ERROR_RETRY_MAX = 10;
Kevin Chyn0c45b072017-04-24 16:27:11 -0700292
joshmccloskey7dee4542019-07-31 18:35:33 -0700293 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 Mankoffe2294692019-08-14 11:53:13 -0400302 private final Handler mHandler;
Jim Millerbbf1a742012-07-17 18:30:30 -0700303
Lucas Dupin7d95f152019-07-17 16:25:54 -0700304 private SparseBooleanArray mFaceSettingEnabledForUser = new SparseBooleanArray();
Kevin Chynb7b54a62018-09-28 18:48:12 -0700305 private BiometricManager mBiometricManager;
306 private IBiometricEnabledOnKeyguardCallback mBiometricEnabledCallback =
307 new IBiometricEnabledOnKeyguardCallback.Stub() {
Dave Mankoff4b0ab652019-08-07 09:49:20 -0400308 @Override
309 public void onChanged(BiometricSourceType type, boolean enabled, int userId)
310 throws RemoteException {
311 if (type == BiometricSourceType.FACE) {
312 mFaceSettingEnabledForUser.put(userId, enabled);
313 updateFaceListeningState();
314 }
315 }
316 };
Kevin Chynb7b54a62018-09-28 18:48:12 -0700317
Malcolm Chen5c63b512019-08-13 13:24:07 -0700318 @VisibleForTesting
319 public PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
Fabian Kozynskiccde55d2019-06-26 10:06:09 -0400320 @Override
321 public void onActiveDataSubscriptionIdChanged(int subId) {
Malcolm Chen5c63b512019-08-13 13:24:07 -0700322 mActiveMobileDataSubscription = subId;
Fabian Kozynskiccde55d2019-06-26 10:06:09 -0400323 mHandler.sendEmptyMessage(MSG_SIM_SUBSCRIPTION_INFO_CHANGED);
324 }
325 };
326
Wink Savilled09c4ca2014-11-22 10:08:16 -0800327 private OnSubscriptionsChangedListener mSubscriptionListener =
328 new OnSubscriptionsChangedListener() {
Dave Mankoff4b0ab652019-08-07 09:49:20 -0400329 @Override
330 public void onSubscriptionsChanged() {
331 mHandler.sendEmptyMessage(MSG_SIM_SUBSCRIPTION_INFO_CHANGED);
332 }
333 };
Jim Miller52a61332014-11-12 19:29:51 -0800334
Lucas Dupin6c6d5732019-08-27 17:36:05 -0700335 private SparseBooleanArray mUserIsUnlocked = new SparseBooleanArray();
Adrian Roos46842d92014-03-27 14:58:03 +0100336 private SparseBooleanArray mUserHasTrust = new SparseBooleanArray();
Adrian Roos7861c662014-07-25 15:37:28 +0200337 private SparseBooleanArray mUserTrustIsManaged = new SparseBooleanArray();
Lucas Dupinf2c53502019-10-03 13:56:18 -0700338 private SparseBooleanArray mUserTrustIsUsuallyManaged = new SparseBooleanArray();
Jim Miller9f0753f2015-03-23 23:59:22 -0700339 private SparseBooleanArray mUserFingerprintAuthenticated = new SparseBooleanArray();
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200340 private SparseBooleanArray mUserFaceAuthenticated = new SparseBooleanArray();
Adrian Roos4a410172014-08-20 17:41:44 +0200341 private SparseBooleanArray mUserFaceUnlockRunning = new SparseBooleanArray();
Adrian Roos46842d92014-03-27 14:58:03 +0100342
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700343 private static int sCurrentUser;
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200344 private Runnable mUpdateBiometricListeningState = this::updateBiometricListeningState;
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700345
346 public synchronized static void setCurrentUser(int currentUser) {
347 sCurrentUser = currentUser;
348 }
349
350 public synchronized static int getCurrentUser() {
351 return sCurrentUser;
352 }
353
Adrian Roos46842d92014-03-27 14:58:03 +0100354 @Override
Adrian Roos94e15a52015-04-16 12:23:18 -0700355 public void onTrustChanged(boolean enabled, int userId, int flags) {
Adrian Roos30a2ae62018-04-25 19:09:50 +0200356 checkIsHandlerThread();
Adrian Roos46842d92014-03-27 14:58:03 +0100357 mUserHasTrust.put(userId, enabled);
Adrian Roos2fe592d2014-05-17 03:11:59 +0200358 for (int i = 0; i < mCallbacks.size(); i++) {
359 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
360 if (cb != null) {
361 cb.onTrustChanged(userId);
Adrian Roos94e15a52015-04-16 12:23:18 -0700362 if (enabled && flags != 0) {
363 cb.onTrustGrantedWithFlags(flags, userId);
Adrian Roos3c9a3502014-08-06 19:09:45 +0200364 }
Adrian Roos2fe592d2014-05-17 03:11:59 +0200365 }
366 }
Adrian Roos46842d92014-03-27 14:58:03 +0100367 }
368
Lucas Dupinef886542018-01-03 16:03:07 -0800369 @Override
370 public void onTrustError(CharSequence message) {
371 dispatchErrorMessage(message);
372 }
373
Adrian Roos30a2ae62018-04-25 19:09:50 +0200374 private void handleSimSubscriptionInfoChanged() {
Dave Mankoff4b0ab652019-08-07 09:49:20 -0400375 checkIsHandlerThread();
Jim Miller52a61332014-11-12 19:29:51 -0800376 if (DEBUG_SIM_STATES) {
377 Log.v(TAG, "onSubscriptionInfoChanged()");
Fabian Kozynskiccde55d2019-06-26 10:06:09 -0400378 List<SubscriptionInfo> sil = mSubscriptionManager.getActiveSubscriptionInfoList(false);
Wink Savilled09c4ca2014-11-22 10:08:16 -0800379 if (sil != null) {
380 for (SubscriptionInfo subInfo : sil) {
381 Log.v(TAG, "SubInfo:" + subInfo);
382 }
383 } else {
384 Log.v(TAG, "onSubscriptionInfoChanged: list is null");
Jim Miller52a61332014-11-12 19:29:51 -0800385 }
386 }
387 List<SubscriptionInfo> subscriptionInfos = getSubscriptionInfo(true /* forceReload */);
388
389 // Hack level over 9000: Because the subscription id is not yet valid when we see the
390 // first update in handleSimStateChange, we need to force refresh all all SIM states
391 // so the subscription id for them is consistent.
Richard Choue0381b82018-04-24 03:48:59 +0000392 ArrayList<SubscriptionInfo> changedSubscriptions = new ArrayList<>();
393 for (int i = 0; i < subscriptionInfos.size(); i++) {
394 SubscriptionInfo info = subscriptionInfos.get(i);
395 boolean changed = refreshSimState(info.getSubscriptionId(), info.getSimSlotIndex());
396 if (changed) {
397 changedSubscriptions.add(info);
398 }
399 }
400 for (int i = 0; i < changedSubscriptions.size(); i++) {
401 SimData data = mSimDatas.get(changedSubscriptions.get(i).getSubscriptionId());
Jim Miller52a61332014-11-12 19:29:51 -0800402 for (int j = 0; j < mCallbacks.size(); j++) {
403 KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get();
404 if (cb != null) {
405 cb.onSimStateChanged(data.subId, data.slotId, data.simState);
406 }
407 }
408 }
Dave Mankoff4b0ab652019-08-07 09:49:20 -0400409 callbacksRefreshCarrierInfo();
Jim Miller52a61332014-11-12 19:29:51 -0800410 }
411
Jason Monk052082c2015-06-11 11:35:23 -0400412 private void handleAirplaneModeChanged() {
Dave Mankoff4b0ab652019-08-07 09:49:20 -0400413 callbacksRefreshCarrierInfo();
414 }
415
416 private void callbacksRefreshCarrierInfo() {
417 checkIsHandlerThread();
418 for (int i = 0; i < mCallbacks.size(); i++) {
419 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
Jason Monk052082c2015-06-11 11:35:23 -0400420 if (cb != null) {
421 cb.onRefreshCarrierInfo();
422 }
423 }
424 }
425
Malcolm Chen5c63b512019-08-13 13:24:07 -0700426 /**
427 * @return List of SubscriptionInfo records, maybe empty but never null.
428 */
Adrian Roos316bf542016-08-23 17:53:07 +0200429 public List<SubscriptionInfo> getSubscriptionInfo(boolean forceReload) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800430 List<SubscriptionInfo> sil = mSubscriptionInfo;
431 if (sil == null || forceReload) {
Fabian Kozynskiccde55d2019-06-26 10:06:09 -0400432 sil = mSubscriptionManager.getActiveSubscriptionInfoList(false);
Wink Savilled09c4ca2014-11-22 10:08:16 -0800433 }
434 if (sil == null) {
435 // getActiveSubscriptionInfoList was null callers expect an empty list.
436 mSubscriptionInfo = new ArrayList<SubscriptionInfo>();
437 } else {
438 mSubscriptionInfo = sil;
Jim Miller52a61332014-11-12 19:29:51 -0800439 }
Malcolm Chen5c63b512019-08-13 13:24:07 -0700440 return new ArrayList<>(mSubscriptionInfo);
441 }
442
443 /**
444 * This method returns filtered list of SubscriptionInfo from {@link #getSubscriptionInfo}.
445 * above. Maybe empty but never null.
446 *
447 * In DSDS mode if both subscriptions are grouped and one is opportunistic, we filter out one
448 * of them based on carrier config. e.g. In this case we should only show one carrier name
449 * on the status bar and quick settings.
450 */
451 public List<SubscriptionInfo> getFilteredSubscriptionInfo(boolean forceReload) {
452 List<SubscriptionInfo> subscriptions = getSubscriptionInfo(false);
453 if (subscriptions.size() == MAX_PHONE_COUNT_DUAL_SIM) {
454 SubscriptionInfo info1 = subscriptions.get(0);
455 SubscriptionInfo info2 = subscriptions.get(1);
456 if (info1.getGroupUuid() != null && info1.getGroupUuid().equals(info2.getGroupUuid())) {
457 // If both subscriptions are primary, show both.
458 if (!info1.isOpportunistic() && !info2.isOpportunistic()) return subscriptions;
459
460 // If carrier required, always show signal bar of primary subscription.
461 // Otherwise, show whichever subscription is currently active for Internet.
462 boolean alwaysShowPrimary = CarrierConfigManager.getDefaultConfig()
463 .getBoolean(CarrierConfigManager
464 .KEY_ALWAYS_SHOW_PRIMARY_SIGNAL_BAR_IN_OPPORTUNISTIC_NETWORK_BOOLEAN);
465 if (alwaysShowPrimary) {
466 subscriptions.remove(info1.isOpportunistic() ? info1 : info2);
467 } else {
468 subscriptions.remove(info1.getSubscriptionId() == mActiveMobileDataSubscription
469 ? info2 : info1);
470 }
471
472 }
473 }
474
475 return subscriptions;
Jim Miller52a61332014-11-12 19:29:51 -0800476 }
477
Adrian Roos7861c662014-07-25 15:37:28 +0200478 @Override
479 public void onTrustManagedChanged(boolean managed, int userId) {
Adrian Roos30a2ae62018-04-25 19:09:50 +0200480 checkIsHandlerThread();
Adrian Roos7861c662014-07-25 15:37:28 +0200481 mUserTrustIsManaged.put(userId, managed);
Lucas Dupinf2c53502019-10-03 13:56:18 -0700482 mUserTrustIsUsuallyManaged.put(userId, mTrustManager.isTrustUsuallyManaged(userId));
Adrian Roos7861c662014-07-25 15:37:28 +0200483 for (int i = 0; i < mCallbacks.size(); i++) {
484 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
485 if (cb != null) {
486 cb.onTrustManagedChanged(userId);
487 }
488 }
489 }
490
Kevin Chynf3b8fbd2017-05-03 22:24:31 -0700491 /**
492 * Updates KeyguardUpdateMonitor's internal state to know if keyguard is goingAway
Kevin Chynf3b8fbd2017-05-03 22:24:31 -0700493 */
494 public void setKeyguardGoingAway(boolean goingAway) {
495 mKeyguardGoingAway = goingAway;
Kevin Chyne22f1342017-09-26 10:03:38 -0700496 updateFingerprintListeningState();
Kevin Chynf3b8fbd2017-05-03 22:24:31 -0700497 }
498
Kevin Chyn2fefd462017-04-28 12:18:19 -0700499 /**
500 * Updates KeyguardUpdateMonitor's internal state to know if keyguard is occluded
Kevin Chyn2fefd462017-04-28 12:18:19 -0700501 */
502 public void setKeyguardOccluded(boolean occluded) {
503 mKeyguardOccluded = occluded;
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200504 updateBiometricListeningState();
Kevin Chyn2fefd462017-04-28 12:18:19 -0700505 }
506
Kevin Chyn36778ff2017-09-07 19:55:38 -0700507 /**
Kevin Chyn6951d3d2019-06-10 14:07:13 -0700508 * Invoked when the secure camera is launched.
509 */
510 public void onCameraLaunched() {
511 mSecureCameraLaunched = true;
512 updateBiometricListeningState();
513 }
514
515 /**
Kevin Chyn36778ff2017-09-07 19:55:38 -0700516 * @return a cached version of DreamManager.isDreaming()
517 */
518 public boolean isDreaming() {
519 return mIsDreaming;
520 }
521
522 /**
523 * If the device is dreaming, awakens the device
524 */
525 public void awakenFromDream() {
526 if (mIsDreaming && mDreamManager != null) {
527 try {
528 mDreamManager.awaken();
529 } catch (RemoteException e) {
530 Log.e(TAG, "Unable to awaken from dream");
531 }
532 }
533 }
534
Lucas Dupin3d053532019-01-29 12:35:22 -0800535 @VisibleForTesting
536 protected void onFingerprintAuthenticated(int userId) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -0400537 checkIsHandlerThread();
Nick Desaulniers1d396752016-07-25 15:05:33 -0700538 Trace.beginSection("KeyGuardUpdateMonitor#onFingerPrintAuthenticated");
Jim Miller9f0753f2015-03-23 23:59:22 -0700539 mUserFingerprintAuthenticated.put(userId, true);
Kevin Chyn3fdbbf82017-05-06 15:11:53 -0700540 // Update/refresh trust state only if user can skip bouncer
541 if (getUserCanSkipBouncer(userId)) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200542 mTrustManager.unlockedByBiometricForUser(userId, BiometricSourceType.FINGERPRINT);
Kevin Chyn3fdbbf82017-05-06 15:11:53 -0700543 }
Kevin Chyn625a0142017-04-10 14:53:59 -0700544 // Don't send cancel if authentication succeeds
545 mFingerprintCancelSignal = null;
Jim Millerf41fc962014-06-18 16:33:51 -0700546 for (int i = 0; i < mCallbacks.size(); i++) {
547 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
548 if (cb != null) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200549 cb.onBiometricAuthenticated(userId, BiometricSourceType.FINGERPRINT);
Jim Millerf41fc962014-06-18 16:33:51 -0700550 }
551 }
Kevin Chyn2fefd462017-04-28 12:18:19 -0700552
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200553 mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_BIOMETRIC_AUTHENTICATION_CONTINUE),
554 BIOMETRIC_CONTINUE_DELAY_MS);
Kevin Chyn0f3e0b12017-07-20 16:56:11 -0700555
Kevin Chyn2fefd462017-04-28 12:18:19 -0700556 // Only authenticate fingerprint once when assistant is visible
557 mAssistantVisible = false;
Kevin Chyn2fefd462017-04-28 12:18:19 -0700558
Nick Desaulniers1d396752016-07-25 15:05:33 -0700559 Trace.endSection();
Jim Millerf41fc962014-06-18 16:33:51 -0700560 }
561
Jim Millerce7eb6d2015-04-03 19:29:13 -0700562 private void handleFingerprintAuthFailed() {
Dave Mankoff4b0ab652019-08-07 09:49:20 -0400563 checkIsHandlerThread();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700564 for (int i = 0; i < mCallbacks.size(); i++) {
565 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
566 if (cb != null) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200567 cb.onBiometricAuthFailed(BiometricSourceType.FINGERPRINT);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700568 }
Jorim Jaggi007f0e82015-08-14 13:56:01 -0700569 }
Lucas Dupin51996bb2019-05-16 17:56:43 -0700570 handleFingerprintHelp(BIOMETRIC_HELP_FINGERPRINT_NOT_RECOGNIZED,
571 mContext.getString(R.string.kg_fingerprint_not_recognized));
Jim Millerce7eb6d2015-04-03 19:29:13 -0700572 }
Jim Millerf41fc962014-06-18 16:33:51 -0700573
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700574 private void handleFingerprintAcquired(int acquireInfo) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -0400575 checkIsHandlerThread();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700576 if (acquireInfo != FingerprintManager.FINGERPRINT_ACQUIRED_GOOD) {
577 return;
578 }
Jorim Jaggi007f0e82015-08-14 13:56:01 -0700579 for (int i = 0; i < mCallbacks.size(); i++) {
580 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
581 if (cb != null) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200582 cb.onBiometricAcquired(BiometricSourceType.FINGERPRINT);
Jorim Jaggi007f0e82015-08-14 13:56:01 -0700583 }
584 }
585 }
586
Jim Miller837fa7e2016-08-08 20:16:22 -0700587 private void handleFingerprintAuthenticated(int authUserId) {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700588 Trace.beginSection("KeyGuardUpdateMonitor#handlerFingerPrintAuthenticated");
Jim Millerf41fc962014-06-18 16:33:51 -0700589 try {
Jorim Jaggi27c9b742015-04-09 10:34:49 -0700590 final int userId;
591 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800592 userId = ActivityManager.getService().getCurrentUser().id;
Jorim Jaggi27c9b742015-04-09 10:34:49 -0700593 } catch (RemoteException e) {
594 Log.e(TAG, "Failed to get current user id: ", e);
595 return;
Jim Millerf41fc962014-06-18 16:33:51 -0700596 }
Jim Miller837fa7e2016-08-08 20:16:22 -0700597 if (userId != authUserId) {
598 Log.d(TAG, "Fingerprint authenticated for wrong user: " + authUserId);
599 return;
600 }
Jorim Jaggi27c9b742015-04-09 10:34:49 -0700601 if (isFingerprintDisabled(userId)) {
602 Log.d(TAG, "Fingerprint disabled by DPM for userId: " + userId);
603 return;
604 }
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700605 onFingerprintAuthenticated(userId);
Jorim Jaggi27c9b742015-04-09 10:34:49 -0700606 } finally {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200607 setFingerprintRunningState(BIOMETRIC_STATE_STOPPED);
Jim Millerf41fc962014-06-18 16:33:51 -0700608 }
Nick Desaulniers1d396752016-07-25 15:05:33 -0700609 Trace.endSection();
Jim Millerf41fc962014-06-18 16:33:51 -0700610 }
611
Jim Miller9f0753f2015-03-23 23:59:22 -0700612 private void handleFingerprintHelp(int msgId, String helpString) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -0400613 checkIsHandlerThread();
Jim Millerf41fc962014-06-18 16:33:51 -0700614 for (int i = 0; i < mCallbacks.size(); i++) {
615 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
616 if (cb != null) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200617 cb.onBiometricHelp(msgId, helpString, BiometricSourceType.FINGERPRINT);
Jim Miller9f0753f2015-03-23 23:59:22 -0700618 }
619 }
620 }
621
Kevin Chyn0c45b072017-04-24 16:27:11 -0700622 private Runnable mRetryFingerprintAuthentication = new Runnable() {
623 @Override
624 public void run() {
625 Log.w(TAG, "Retrying fingerprint after HW unavailable, attempt " +
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200626 mHardwareFingerprintUnavailableRetryCount);
Kevin Chyn0c45b072017-04-24 16:27:11 -0700627 updateFingerprintListeningState();
628 }
629 };
630
Jim Miller9f0753f2015-03-23 23:59:22 -0700631 private void handleFingerprintError(int msgId, String errString) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -0400632 checkIsHandlerThread();
joshmccloskey7dee4542019-07-31 18:35:33 -0700633 if (msgId == FingerprintManager.FINGERPRINT_ERROR_CANCELED && mHandler.hasCallbacks(
634 mCancelNotReceived)) {
635 mHandler.removeCallbacks(mCancelNotReceived);
636 }
637
Jorim Jaggi86bed402015-08-20 18:20:02 -0700638 if (msgId == FingerprintManager.FINGERPRINT_ERROR_CANCELED
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200639 && mFingerprintRunningState == BIOMETRIC_STATE_CANCELLING_RESTARTING) {
640 setFingerprintRunningState(BIOMETRIC_STATE_STOPPED);
Kevin Chyn1123ba72018-10-26 10:34:06 -0700641 updateFingerprintListeningState();
Jorim Jaggi86bed402015-08-20 18:20:02 -0700642 } else {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200643 setFingerprintRunningState(BIOMETRIC_STATE_STOPPED);
Jorim Jaggi86bed402015-08-20 18:20:02 -0700644 }
Kevin Chyn0c45b072017-04-24 16:27:11 -0700645
646 if (msgId == FingerprintManager.FINGERPRINT_ERROR_HW_UNAVAILABLE) {
Kevin Chyne1ac0c02019-07-26 17:54:46 -0700647 if (mHardwareFingerprintUnavailableRetryCount < HAL_ERROR_RETRY_MAX) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200648 mHardwareFingerprintUnavailableRetryCount++;
Kevin Chyn0c45b072017-04-24 16:27:11 -0700649 mHandler.removeCallbacks(mRetryFingerprintAuthentication);
Kevin Chyne1ac0c02019-07-26 17:54:46 -0700650 mHandler.postDelayed(mRetryFingerprintAuthentication, HAL_ERROR_RETRY_TIMEOUT);
Kevin Chyn0c45b072017-04-24 16:27:11 -0700651 }
652 }
653
Kevin Chyndf9d33e2017-05-03 21:40:12 -0700654 if (msgId == FingerprintManager.FINGERPRINT_ERROR_LOCKOUT_PERMANENT) {
Lucas Dupin8eec2682019-07-01 16:41:17 -0700655 mLockPatternUtils.requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_LOCKOUT,
Kevin Chyndf9d33e2017-05-03 21:40:12 -0700656 getCurrentUser());
657 }
658
Jim Miller9f0753f2015-03-23 23:59:22 -0700659 for (int i = 0; i < mCallbacks.size(); i++) {
660 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
661 if (cb != null) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200662 cb.onBiometricError(msgId, errString, BiometricSourceType.FINGERPRINT);
Jim Millerf41fc962014-06-18 16:33:51 -0700663 }
664 }
665 }
666
Jorim Jaggi3a464782015-08-28 16:59:13 -0700667 private void handleFingerprintLockoutReset() {
668 updateFingerprintListeningState();
669 }
670
Jorim Jaggi86bed402015-08-20 18:20:02 -0700671 private void setFingerprintRunningState(int fingerprintRunningState) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200672 boolean wasRunning = mFingerprintRunningState == BIOMETRIC_STATE_RUNNING;
673 boolean isRunning = fingerprintRunningState == BIOMETRIC_STATE_RUNNING;
Jorim Jaggi86bed402015-08-20 18:20:02 -0700674 mFingerprintRunningState = fingerprintRunningState;
Kevin Chynb4514d22019-04-15 13:47:25 -0700675 Log.d(TAG, "fingerprintRunningState: " + mFingerprintRunningState);
Jorim Jaggi86bed402015-08-20 18:20:02 -0700676 // Clients of KeyguardUpdateMonitor don't care about the internal state about the
Kevin Chynb4514d22019-04-15 13:47:25 -0700677 // asynchronousness of the cancel cycle. So only notify them if the actually running state
Jorim Jaggi86bed402015-08-20 18:20:02 -0700678 // has changed.
679 if (wasRunning != isRunning) {
Jorim Jaggi27c9b742015-04-09 10:34:49 -0700680 notifyFingerprintRunningStateChanged();
681 }
682 }
683
684 private void notifyFingerprintRunningStateChanged() {
Adrian Roos30a2ae62018-04-25 19:09:50 +0200685 checkIsHandlerThread();
Jorim Jaggi27c9b742015-04-09 10:34:49 -0700686 for (int i = 0; i < mCallbacks.size(); i++) {
687 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
688 if (cb != null) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200689 cb.onBiometricRunningStateChanged(isFingerprintDetectionRunning(),
690 BiometricSourceType.FINGERPRINT);
Jorim Jaggi27c9b742015-04-09 10:34:49 -0700691 }
692 }
693 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200694
Lucas Dupin3d053532019-01-29 12:35:22 -0800695 @VisibleForTesting
696 protected void onFaceAuthenticated(int userId) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200697 Trace.beginSection("KeyGuardUpdateMonitor#onFaceAuthenticated");
Dave Mankoff4b0ab652019-08-07 09:49:20 -0400698 checkIsHandlerThread();
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200699 mUserFaceAuthenticated.put(userId, true);
700 // Update/refresh trust state only if user can skip bouncer
701 if (getUserCanSkipBouncer(userId)) {
702 mTrustManager.unlockedByBiometricForUser(userId, BiometricSourceType.FACE);
703 }
704 // Don't send cancel if authentication succeeds
705 mFaceCancelSignal = null;
706 for (int i = 0; i < mCallbacks.size(); i++) {
707 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
708 if (cb != null) {
709 cb.onBiometricAuthenticated(userId,
710 BiometricSourceType.FACE);
711 }
712 }
713
714 mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_BIOMETRIC_AUTHENTICATION_CONTINUE),
715 BIOMETRIC_CONTINUE_DELAY_MS);
716
717 // Only authenticate face once when assistant is visible
718 mAssistantVisible = false;
719
720 Trace.endSection();
721 }
722
723 private void handleFaceAuthFailed() {
Dave Mankoff4b0ab652019-08-07 09:49:20 -0400724 checkIsHandlerThread();
Lucas Dupin38314812019-02-15 14:10:55 -0800725 setFaceRunningState(BIOMETRIC_STATE_STOPPED);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200726 for (int i = 0; i < mCallbacks.size(); i++) {
727 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
728 if (cb != null) {
729 cb.onBiometricAuthFailed(BiometricSourceType.FACE);
730 }
731 }
Lucas Dupin51996bb2019-05-16 17:56:43 -0700732 handleFaceHelp(BIOMETRIC_HELP_FACE_NOT_RECOGNIZED,
733 mContext.getString(R.string.kg_face_not_recognized));
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200734 }
735
736 private void handleFaceAcquired(int acquireInfo) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -0400737 checkIsHandlerThread();
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200738 if (acquireInfo != FaceManager.FACE_ACQUIRED_GOOD) {
739 return;
740 }
Lucas Dupin71d2fb22019-05-30 18:26:54 -0700741 if (DEBUG_FACE) Log.d(TAG, "Face acquired");
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200742 for (int i = 0; i < mCallbacks.size(); i++) {
743 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
744 if (cb != null) {
745 cb.onBiometricAcquired(BiometricSourceType.FACE);
746 }
747 }
748 }
749
750 private void handleFaceAuthenticated(int authUserId) {
751 Trace.beginSection("KeyGuardUpdateMonitor#handlerFaceAuthenticated");
752 try {
Lucas Dupin9bae9c22019-06-04 16:37:40 -0700753 if (mGoingToSleep) {
754 Log.d(TAG, "Aborted successful auth because device is going to sleep.");
755 return;
756 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200757 final int userId;
758 try {
759 userId = ActivityManager.getService().getCurrentUser().id;
760 } catch (RemoteException e) {
761 Log.e(TAG, "Failed to get current user id: ", e);
762 return;
763 }
764 if (userId != authUserId) {
765 Log.d(TAG, "Face authenticated for wrong user: " + authUserId);
766 return;
767 }
768 if (isFaceDisabled(userId)) {
769 Log.d(TAG, "Face authentication disabled by DPM for userId: " + userId);
770 return;
771 }
Lucas Dupin71d2fb22019-05-30 18:26:54 -0700772 if (DEBUG_FACE) Log.d(TAG, "Face auth succeeded for user " + userId);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200773 onFaceAuthenticated(userId);
774 } finally {
775 setFaceRunningState(BIOMETRIC_STATE_STOPPED);
776 }
777 Trace.endSection();
778 }
779
780 private void handleFaceHelp(int msgId, String helpString) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -0400781 checkIsHandlerThread();
Lucas Dupin71d2fb22019-05-30 18:26:54 -0700782 if (DEBUG_FACE) Log.d(TAG, "Face help received: " + helpString);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200783 for (int i = 0; i < mCallbacks.size(); i++) {
784 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
785 if (cb != null) {
786 cb.onBiometricHelp(msgId, helpString, BiometricSourceType.FACE);
787 }
788 }
789 }
790
791 private Runnable mRetryFaceAuthentication = new Runnable() {
792 @Override
793 public void run() {
794 Log.w(TAG, "Retrying face after HW unavailable, attempt " +
795 mHardwareFaceUnavailableRetryCount);
796 updateFaceListeningState();
797 }
798 };
799
800 private void handleFaceError(int msgId, String errString) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -0400801 checkIsHandlerThread();
Lucas Dupin71d2fb22019-05-30 18:26:54 -0700802 if (DEBUG_FACE) Log.d(TAG, "Face error received: " + errString);
joshmccloskey7dee4542019-07-31 18:35:33 -0700803 if (msgId == FaceManager.FACE_ERROR_CANCELED && mHandler.hasCallbacks(mCancelNotReceived)) {
804 mHandler.removeCallbacks(mCancelNotReceived);
805 }
806
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200807 if (msgId == FaceManager.FACE_ERROR_CANCELED
808 && mFaceRunningState == BIOMETRIC_STATE_CANCELLING_RESTARTING) {
809 setFaceRunningState(BIOMETRIC_STATE_STOPPED);
Kevin Chyn1123ba72018-10-26 10:34:06 -0700810 updateFaceListeningState();
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200811 } else {
812 setFaceRunningState(BIOMETRIC_STATE_STOPPED);
813 }
814
Kevin Chyne1ac0c02019-07-26 17:54:46 -0700815 if (msgId == FaceManager.FACE_ERROR_HW_UNAVAILABLE
816 || msgId == FaceManager.FACE_ERROR_UNABLE_TO_PROCESS) {
817 if (mHardwareFaceUnavailableRetryCount < HAL_ERROR_RETRY_MAX) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200818 mHardwareFaceUnavailableRetryCount++;
819 mHandler.removeCallbacks(mRetryFaceAuthentication);
Kevin Chyne1ac0c02019-07-26 17:54:46 -0700820 mHandler.postDelayed(mRetryFaceAuthentication, HAL_ERROR_RETRY_TIMEOUT);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200821 }
822 }
823
824 if (msgId == FaceManager.FACE_ERROR_LOCKOUT_PERMANENT) {
Lucas Dupin8eec2682019-07-01 16:41:17 -0700825 mLockPatternUtils.requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_LOCKOUT,
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200826 getCurrentUser());
827 }
828
829 for (int i = 0; i < mCallbacks.size(); i++) {
830 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
831 if (cb != null) {
832 cb.onBiometricError(msgId, errString,
833 BiometricSourceType.FACE);
834 }
835 }
836 }
837
838 private void handleFaceLockoutReset() {
839 updateFaceListeningState();
840 }
841
842 private void setFaceRunningState(int faceRunningState) {
843 boolean wasRunning = mFaceRunningState == BIOMETRIC_STATE_RUNNING;
844 boolean isRunning = faceRunningState == BIOMETRIC_STATE_RUNNING;
845 mFaceRunningState = faceRunningState;
Kevin Chynb4514d22019-04-15 13:47:25 -0700846 Log.d(TAG, "faceRunningState: " + mFaceRunningState);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200847 // Clients of KeyguardUpdateMonitor don't care about the internal state or about the
Kevin Chynb4514d22019-04-15 13:47:25 -0700848 // asynchronousness of the cancel cycle. So only notify them if the actually running state
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200849 // has changed.
850 if (wasRunning != isRunning) {
851 notifyFaceRunningStateChanged();
852 }
853 }
854
855 private void notifyFaceRunningStateChanged() {
Dave Mankoff4b0ab652019-08-07 09:49:20 -0400856 checkIsHandlerThread();
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200857 for (int i = 0; i < mCallbacks.size(); i++) {
858 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
859 if (cb != null) {
860 cb.onBiometricRunningStateChanged(isFaceDetectionRunning(),
861 BiometricSourceType.FACE);
862 }
863 }
864 }
865
Adrian Roos4a410172014-08-20 17:41:44 +0200866 private void handleFaceUnlockStateChanged(boolean running, int userId) {
Adrian Roos30a2ae62018-04-25 19:09:50 +0200867 checkIsHandlerThread();
Adrian Roos4a410172014-08-20 17:41:44 +0200868 mUserFaceUnlockRunning.put(userId, running);
Jorim Jaggie7b12522014-08-06 16:41:21 +0200869 for (int i = 0; i < mCallbacks.size(); i++) {
870 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
871 if (cb != null) {
Adrian Roos4a410172014-08-20 17:41:44 +0200872 cb.onFaceUnlockStateChanged(running, userId);
Jorim Jaggie7b12522014-08-06 16:41:21 +0200873 }
874 }
875 }
876
Adrian Roos4a410172014-08-20 17:41:44 +0200877 public boolean isFaceUnlockRunning(int userId) {
878 return mUserFaceUnlockRunning.get(userId);
879 }
880
Jorim Jaggi27c9b742015-04-09 10:34:49 -0700881 public boolean isFingerprintDetectionRunning() {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200882 return mFingerprintRunningState == BIOMETRIC_STATE_RUNNING;
883 }
884
885 public boolean isFaceDetectionRunning() {
886 return mFaceRunningState == BIOMETRIC_STATE_RUNNING;
Jorim Jaggi27c9b742015-04-09 10:34:49 -0700887 }
888
Jim Miller50e62182014-04-23 17:25:00 -0700889 private boolean isTrustDisabled(int userId) {
Adrian Roosa4da9f62015-02-21 01:15:21 +0100890 // Don't allow trust agent if device is secured with a SIM PIN. This is here
891 // mainly because there's no other way to prompt the user to enter their SIM PIN
892 // once they get past the keyguard screen.
893 final boolean disabledBySimPin = isSimPinSecure();
894 return disabledBySimPin;
Jim Miller50e62182014-04-23 17:25:00 -0700895 }
896
Jim Miller06e34502014-07-17 14:46:05 -0700897 private boolean isFingerprintDisabled(int userId) {
898 final DevicePolicyManager dpm =
899 (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
900 return dpm != null && (dpm.getKeyguardDisabledFeatures(null, userId)
Dave Mankoff4b0ab652019-08-07 09:49:20 -0400901 & DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT) != 0
Adrian Roos733b6632015-08-21 14:32:35 -0700902 || isSimPinSecure();
Jim Miller06e34502014-07-17 14:46:05 -0700903 }
904
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200905 private boolean isFaceDisabled(int userId) {
906 final DevicePolicyManager dpm =
907 (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
Lucas Dupin8968f6a2019-08-09 17:41:15 -0700908 // TODO(b/140035044)
909 return whitelistIpcs(() -> dpm != null && (dpm.getKeyguardDisabledFeatures(null, userId)
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200910 & DevicePolicyManager.KEYGUARD_DISABLE_FACE) != 0
Lucas Dupin8968f6a2019-08-09 17:41:15 -0700911 || isSimPinSecure());
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200912 }
913
914
Selim Cineke8bae622015-07-15 13:24:06 -0700915 public boolean getUserCanSkipBouncer(int userId) {
Steven Wucfe398d2019-03-21 11:32:15 -0400916 return getUserHasTrust(userId) || getUserUnlockedWithBiometric(userId);
Selim Cineke8bae622015-07-15 13:24:06 -0700917 }
918
Adrian Roos46842d92014-03-27 14:58:03 +0100919 public boolean getUserHasTrust(int userId) {
Selim Cineke8bae622015-07-15 13:24:06 -0700920 return !isTrustDisabled(userId) && mUserHasTrust.get(userId);
Adrian Roos46842d92014-03-27 14:58:03 +0100921 }
922
Steven Wucfe398d2019-03-21 11:32:15 -0400923 /**
924 * Returns whether the user is unlocked with biometrics.
925 */
926 public boolean getUserUnlockedWithBiometric(int userId) {
927 boolean fingerprintOrFace = mUserFingerprintAuthenticated.get(userId)
928 || mUserFaceAuthenticated.get(userId);
929 return fingerprintOrFace && isUnlockingWithBiometricAllowed();
930 }
931
Adrian Roos7861c662014-07-25 15:37:28 +0200932 public boolean getUserTrustIsManaged(int userId) {
933 return mUserTrustIsManaged.get(userId) && !isTrustDisabled(userId);
934 }
935
Lucas Dupinf2c53502019-10-03 13:56:18 -0700936 /**
937 * Cached version of {@link TrustManager#isTrustUsuallyManaged(int)}.
938 */
939 public boolean isTrustUsuallyManaged(int userId) {
940 checkIsHandlerThread();
941 return mUserTrustIsUsuallyManaged.get(userId);
942 }
943
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200944 public boolean isUnlockingWithBiometricAllowed() {
945 return mStrongAuthTracker.isUnlockingWithBiometricAllowed();
Adrian Roosb5e47222015-08-14 15:53:06 -0700946 }
947
Lucas Dupin16013822018-05-17 18:00:16 -0700948 public boolean isUserInLockdown(int userId) {
Lucas Dupin8eec2682019-07-01 16:41:17 -0700949 return containsFlag(mStrongAuthTracker.getStrongAuthForUser(userId),
950 STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN);
Lucas Dupin16013822018-05-17 18:00:16 -0700951 }
952
Lucas Dupin7825b942019-06-03 20:22:39 -0700953 public boolean userNeedsStrongAuth() {
954 return mStrongAuthTracker.getStrongAuthForUser(getCurrentUser())
955 != LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED;
956 }
957
Lucas Dupin8eec2682019-07-01 16:41:17 -0700958 private boolean containsFlag(int haystack, int needle) {
959 return (haystack & needle) != 0;
960 }
961
Jorim Jaggi031f7952016-09-01 16:39:26 -0700962 public boolean needsSlowUnlockTransition() {
963 return mNeedsSlowUnlockTransition;
Jorim Jaggie8fde5d2016-06-30 23:41:37 -0700964 }
965
Adrian Roosb5e47222015-08-14 15:53:06 -0700966 public StrongAuthTracker getStrongAuthTracker() {
967 return mStrongAuthTracker;
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -0700968 }
969
Adrian Roos1de8bcb2015-08-19 16:52:52 -0700970 private void notifyStrongAuthStateChanged(int userId) {
Adrian Roos30a2ae62018-04-25 19:09:50 +0200971 checkIsHandlerThread();
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -0700972 for (int i = 0; i < mCallbacks.size(); i++) {
973 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
974 if (cb != null) {
Adrian Roos1de8bcb2015-08-19 16:52:52 -0700975 cb.onStrongAuthStateChanged(userId);
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -0700976 }
977 }
Selim Cinek1fcafc42015-07-20 14:39:25 -0700978 }
979
Adrian Roos91ba3072017-02-14 16:50:46 +0100980 public boolean isScreenOn() {
981 return mScreenOn;
982 }
983
Lucas Dupinef886542018-01-03 16:03:07 -0800984 private void dispatchErrorMessage(CharSequence message) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -0400985 checkIsHandlerThread();
Lucas Dupinef886542018-01-03 16:03:07 -0800986 for (int i = 0; i < mCallbacks.size(); i++) {
987 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
988 if (cb != null) {
989 cb.onTrustAgentErrorMessage(message);
990 }
991 }
992 }
993
Lucas Dupin3d053532019-01-29 12:35:22 -0800994 @VisibleForTesting
995 void setAssistantVisible(boolean assistantVisible) {
996 mAssistantVisible = assistantVisible;
997 updateBiometricListeningState();
998 }
999
Jim Miller8f09fd22013-03-14 19:04:28 -07001000 static class DisplayClientState {
1001 public int clientGeneration;
1002 public boolean clearing;
1003 public PendingIntent intent;
1004 public int playbackState;
1005 public long playbackEventTime;
1006 }
1007
1008 private DisplayClientState mDisplayClientState = new DisplayClientState();
1009
Lucas Dupin5e0f0d22018-02-26 13:32:16 -08001010 @VisibleForTesting
Lucas Dupin7ff82b02018-05-16 12:14:10 -07001011 protected final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
Jim Millerbbf1a742012-07-17 18:30:30 -07001012
Jim Millerd72d5ac2015-09-29 18:55:32 -07001013 @Override
Jim Millerbbf1a742012-07-17 18:30:30 -07001014 public void onReceive(Context context, Intent intent) {
1015 final String action = intent.getAction();
1016 if (DEBUG) Log.d(TAG, "received broadcast " + action);
1017
1018 if (Intent.ACTION_TIME_TICK.equals(action)
Robert Snoeberger9c1074f2018-12-07 17:35:21 -05001019 || Intent.ACTION_TIME_CHANGED.equals(action)) {
Jim Miller90873d52013-09-26 18:11:38 -07001020 mHandler.sendEmptyMessage(MSG_TIME_UPDATE);
Robert Snoeberger9c1074f2018-12-07 17:35:21 -05001021 } else if (Intent.ACTION_TIMEZONE_CHANGED.equals(action)) {
1022 final Message msg = mHandler.obtainMessage(
1023 MSG_TIMEZONE_UPDATE, intent.getStringExtra("time-zone"));
1024 mHandler.sendMessage(msg);
Jim Millerbbf1a742012-07-17 18:30:30 -07001025 } else if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
1026 final int status = intent.getIntExtra(EXTRA_STATUS, BATTERY_STATUS_UNKNOWN);
1027 final int plugged = intent.getIntExtra(EXTRA_PLUGGED, 0);
1028 final int level = intent.getIntExtra(EXTRA_LEVEL, 0);
1029 final int health = intent.getIntExtra(EXTRA_HEALTH, BATTERY_HEALTH_UNKNOWN);
Adrian Roos0c859ae2015-11-23 16:47:50 -08001030
1031 final int maxChargingMicroAmp = intent.getIntExtra(EXTRA_MAX_CHARGING_CURRENT, -1);
1032 int maxChargingMicroVolt = intent.getIntExtra(EXTRA_MAX_CHARGING_VOLTAGE, -1);
1033 final int maxChargingMicroWatt;
1034
1035 if (maxChargingMicroVolt <= 0) {
1036 maxChargingMicroVolt = DEFAULT_CHARGING_VOLTAGE_MICRO_VOLT;
1037 }
1038 if (maxChargingMicroAmp > 0) {
1039 // Calculating muW = muA * muV / (10^6 mu^2 / mu); splitting up the divisor
1040 // to maintain precision equally on both factors.
1041 maxChargingMicroWatt = (maxChargingMicroAmp / 1000)
1042 * (maxChargingMicroVolt / 1000);
1043 } else {
1044 maxChargingMicroWatt = -1;
1045 }
Jim Millerbbf1a742012-07-17 18:30:30 -07001046 final Message msg = mHandler.obtainMessage(
Adrian Roos7b043112015-07-10 13:00:33 -07001047 MSG_BATTERY_UPDATE, new BatteryStatus(status, level, plugged, health,
Adrian Roos0c859ae2015-11-23 16:47:50 -08001048 maxChargingMicroWatt));
Jim Millerbbf1a742012-07-17 18:30:30 -07001049 mHandler.sendMessage(msg);
1050 } else if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)) {
Bill Linef81cbd2018-07-05 17:48:49 +08001051 SimData args = SimData.fromIntent(intent);
Lucas Dupin5e0f0d22018-02-26 13:32:16 -08001052 // ACTION_SIM_STATE_CHANGED is rebroadcast after unlocking the device to
1053 // keep compatibility with apps that aren't direct boot aware.
1054 // SysUI should just ignore this broadcast because it was already received
1055 // and processed previously.
1056 if (intent.getBooleanExtra(TelephonyIntents.EXTRA_REBROADCAST_ON_UNLOCK, false)) {
Bill Linef81cbd2018-07-05 17:48:49 +08001057 // Guarantee mTelephonyCapable state after SysUI crash and restart
1058 if (args.simState == State.ABSENT) {
1059 mHandler.obtainMessage(MSG_TELEPHONY_CAPABLE, true).sendToTarget();
1060 }
Lucas Dupin5e0f0d22018-02-26 13:32:16 -08001061 return;
1062 }
Jim Millerbbf1a742012-07-17 18:30:30 -07001063 if (DEBUG_SIM_STATES) {
Jim Miller52a61332014-11-12 19:29:51 -08001064 Log.v(TAG, "action " + action
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001065 + " state: " + intent.getStringExtra(
1066 IccCardConstants.INTENT_KEY_ICC_STATE)
1067 + " slotId: " + args.slotId + " subid: " + args.subId);
Jim Millerbbf1a742012-07-17 18:30:30 -07001068 }
Jim Miller52a61332014-11-12 19:29:51 -08001069 mHandler.obtainMessage(MSG_SIM_STATE_CHANGE, args.subId, args.slotId, args.simState)
1070 .sendToTarget();
Jim Millerbbf1a742012-07-17 18:30:30 -07001071 } else if (AudioManager.RINGER_MODE_CHANGED_ACTION.equals(action)) {
1072 mHandler.sendMessage(mHandler.obtainMessage(MSG_RINGER_MODE_CHANGED,
1073 intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1), 0));
1074 } else if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(action)) {
1075 String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
1076 mHandler.sendMessage(mHandler.obtainMessage(MSG_PHONE_STATE_CHANGED, state));
Jason Monk052082c2015-06-11 11:35:23 -04001077 } else if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(action)) {
1078 mHandler.sendEmptyMessage(MSG_AIRPLANE_MODE_CHANGED);
Adam Cohenefb3ffb2012-11-06 16:55:32 -08001079 } else if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
Jim Miller90873d52013-09-26 18:11:38 -07001080 dispatchBootCompleted();
Etan Cohen47051d82015-07-06 16:19:04 -07001081 } else if (TelephonyIntents.ACTION_SERVICE_STATE_CHANGED.equals(action)) {
1082 ServiceState serviceState = ServiceState.newFromBundle(intent.getExtras());
1083 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
1084 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1085 if (DEBUG) {
1086 Log.v(TAG, "action " + action + " serviceState=" + serviceState + " subId="
1087 + subId);
1088 }
Bonian Chena7e9e8c2019-06-02 23:59:31 +00001089 mHandler.sendMessage(
1090 mHandler.obtainMessage(MSG_SERVICE_STATE_CHANGE, subId, 0, serviceState));
Fabian Kozynskiccde55d2019-06-26 10:06:09 -04001091 } else if (TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED.equals(action)) {
1092 mHandler.sendEmptyMessage(MSG_SIM_SUBSCRIPTION_INFO_CHANGED);
Alex Chauff7653d2018-02-01 17:18:08 +00001093 } else if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED.equals(
1094 action)) {
1095 mHandler.sendEmptyMessage(MSG_DEVICE_POLICY_MANAGER_STATE_CHANGED);
Jim Millerbbf1a742012-07-17 18:30:30 -07001096 }
1097 }
1098 };
Jim Miller2de5ee82012-06-14 22:22:50 -07001099
Lucas Dupin3d053532019-01-29 12:35:22 -08001100 @VisibleForTesting
1101 protected final BroadcastReceiver mBroadcastAllReceiver = new BroadcastReceiver() {
Amith Yamasani6fc1d4e2013-05-08 16:43:58 -07001102
Jim Millerd72d5ac2015-09-29 18:55:32 -07001103 @Override
Amith Yamasani6fc1d4e2013-05-08 16:43:58 -07001104 public void onReceive(Context context, Intent intent) {
1105 final String action = intent.getAction();
Adrian Roos48c796c2014-09-01 14:59:23 +02001106 if (AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED.equals(action)) {
1107 mHandler.sendEmptyMessage(MSG_TIME_UPDATE);
1108 } else if (Intent.ACTION_USER_INFO_CHANGED.equals(action)) {
Amith Yamasani6fc1d4e2013-05-08 16:43:58 -07001109 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_INFO_CHANGED,
1110 intent.getIntExtra(Intent.EXTRA_USER_HANDLE, getSendingUserId()), 0));
Adrian Roos48c796c2014-09-01 14:59:23 +02001111 } else if (ACTION_FACE_UNLOCK_STARTED.equals(action)) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001112 Trace.beginSection(
1113 "KeyguardUpdateMonitor.mBroadcastAllReceiver#onReceive "
1114 + "ACTION_FACE_UNLOCK_STARTED");
Adrian Roos48c796c2014-09-01 14:59:23 +02001115 mHandler.sendMessage(mHandler.obtainMessage(MSG_FACE_UNLOCK_STATE_CHANGED, 1,
1116 getSendingUserId()));
Nick Desaulniers1d396752016-07-25 15:05:33 -07001117 Trace.endSection();
Adrian Roos48c796c2014-09-01 14:59:23 +02001118 } else if (ACTION_FACE_UNLOCK_STOPPED.equals(action)) {
1119 mHandler.sendMessage(mHandler.obtainMessage(MSG_FACE_UNLOCK_STATE_CHANGED, 0,
1120 getSendingUserId()));
1121 } else if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
1122 .equals(action)) {
1123 mHandler.sendEmptyMessage(MSG_DPM_STATE_CHANGED);
Jorim Jaggidadafd42016-09-30 07:20:25 -07001124 } else if (ACTION_USER_UNLOCKED.equals(action)) {
Lucas Dupin6c6d5732019-08-27 17:36:05 -07001125 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_UNLOCKED,
1126 getSendingUserId(), 0));
1127 } else if (ACTION_USER_STOPPED.equals(action)) {
1128 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_STOPPED,
1129 intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1), 0));
1130 } else if (ACTION_USER_REMOVED.equals(action)) {
1131 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_REMOVED,
1132 intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1), 0));
Amith Yamasani6fc1d4e2013-05-08 16:43:58 -07001133 }
1134 }
1135 };
Jim Miller9f0753f2015-03-23 23:59:22 -07001136
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001137 private final FingerprintManager.LockoutResetCallback mFingerprintLockoutResetCallback
Jorim Jaggi3a464782015-08-28 16:59:13 -07001138 = new FingerprintManager.LockoutResetCallback() {
1139 @Override
1140 public void onLockoutReset() {
1141 handleFingerprintLockoutReset();
1142 }
1143 };
1144
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001145 private final FaceManager.LockoutResetCallback mFaceLockoutResetCallback
1146 = new FaceManager.LockoutResetCallback() {
1147 @Override
1148 public void onLockoutReset() {
1149 handleFaceLockoutReset();
1150 }
1151 };
1152
1153 private FingerprintManager.AuthenticationCallback mFingerprintAuthenticationCallback
Jim Miller9f0753f2015-03-23 23:59:22 -07001154 = new AuthenticationCallback() {
Jim Millerf41fc962014-06-18 16:33:51 -07001155
1156 @Override
Jim Millerce7eb6d2015-04-03 19:29:13 -07001157 public void onAuthenticationFailed() {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001158 handleFingerprintAuthFailed();
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001159 }
Jim Millerce7eb6d2015-04-03 19:29:13 -07001160
1161 @Override
Jim Miller9f0753f2015-03-23 23:59:22 -07001162 public void onAuthenticationSucceeded(AuthenticationResult result) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001163 Trace.beginSection("KeyguardUpdateMonitor#onAuthenticationSucceeded");
Jim Miller837fa7e2016-08-08 20:16:22 -07001164 handleFingerprintAuthenticated(result.getUserId());
Nick Desaulniers1d396752016-07-25 15:05:33 -07001165 Trace.endSection();
Jim Millerf41fc962014-06-18 16:33:51 -07001166 }
1167
1168 @Override
Jim Miller9f0753f2015-03-23 23:59:22 -07001169 public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001170 handleFingerprintHelp(helpMsgId, helpString.toString());
Jim Miller9f0753f2015-03-23 23:59:22 -07001171 }
1172
1173 @Override
1174 public void onAuthenticationError(int errMsgId, CharSequence errString) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001175 handleFingerprintError(errMsgId, errString.toString());
1176 }
1177
1178 @Override
1179 public void onAuthenticationAcquired(int acquireInfo) {
1180 handleFingerprintAcquired(acquireInfo);
Jim Millerf41fc962014-06-18 16:33:51 -07001181 }
1182 };
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001183
Lucas Dupin3d053532019-01-29 12:35:22 -08001184 @VisibleForTesting
1185 FaceManager.AuthenticationCallback mFaceAuthenticationCallback
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001186 = new FaceManager.AuthenticationCallback() {
1187
1188 @Override
1189 public void onAuthenticationFailed() {
1190 handleFaceAuthFailed();
1191 }
1192
1193 @Override
1194 public void onAuthenticationSucceeded(FaceManager.AuthenticationResult result) {
1195 Trace.beginSection("KeyguardUpdateMonitor#onAuthenticationSucceeded");
1196 handleFaceAuthenticated(result.getUserId());
1197 Trace.endSection();
1198 }
1199
1200 @Override
1201 public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
1202 handleFaceHelp(helpMsgId, helpString.toString());
1203 }
1204
1205 @Override
1206 public void onAuthenticationError(int errMsgId, CharSequence errString) {
1207 handleFaceError(errMsgId, errString.toString());
1208 }
1209
1210 @Override
1211 public void onAuthenticationAcquired(int acquireInfo) {
1212 handleFaceAcquired(acquireInfo);
1213 }
1214 };
1215
Jim Miller9f0753f2015-03-23 23:59:22 -07001216 private CancellationSignal mFingerprintCancelSignal;
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001217 private CancellationSignal mFaceCancelSignal;
Jim Miller9f0753f2015-03-23 23:59:22 -07001218 private FingerprintManager mFpm;
Kevin Chynb7b54a62018-09-28 18:48:12 -07001219 private FaceManager mFaceManager;
Amith Yamasani6fc1d4e2013-05-08 16:43:58 -07001220
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001221 /**
Jim Miller47088bb2009-11-24 00:40:16 -08001222 * When we receive a
1223 * {@link com.android.internal.telephony.TelephonyIntents#ACTION_SIM_STATE_CHANGED} broadcast,
Wink Saville37c124c2009-04-02 01:37:02 -07001224 * and then pass a result via our handler to {@link KeyguardUpdateMonitor#handleSimStateChange},
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001225 * we need a single object to pass to the handler. This class helps decode
Jim Miller47088bb2009-11-24 00:40:16 -08001226 * the intent and provide a {@link SimCard.State} result.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001227 */
Jim Miller52a61332014-11-12 19:29:51 -08001228 private static class SimData {
1229 public State simState;
1230 public int slotId;
1231 public int subId;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001232
Jim Miller52a61332014-11-12 19:29:51 -08001233 SimData(State state, int slot, int id) {
Jim Miller90d5d462011-11-17 16:57:01 -08001234 simState = state;
Jim Miller52a61332014-11-12 19:29:51 -08001235 slotId = slot;
1236 subId = id;
Jim Miller90d5d462011-11-17 16:57:01 -08001237 }
1238
Jim Miller52a61332014-11-12 19:29:51 -08001239 static SimData fromIntent(Intent intent) {
1240 State state;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001241 if (!TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(intent.getAction())) {
1242 throw new IllegalArgumentException("only handles intent ACTION_SIM_STATE_CHANGED");
1243 }
Wink Savillea639b312012-07-10 12:37:54 -07001244 String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
Jayachandran Cbd481352019-05-21 16:02:23 -07001245 int slotId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Jim Miller52a61332014-11-12 19:29:51 -08001246 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001247 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Savillea639b312012-07-10 12:37:54 -07001248 if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
John Wangb0b24b32011-06-10 17:23:51 -07001249 final String absentReason = intent
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001250 .getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON);
John Wangb0b24b32011-06-10 17:23:51 -07001251
Wink Savillea639b312012-07-10 12:37:54 -07001252 if (IccCardConstants.INTENT_VALUE_ABSENT_ON_PERM_DISABLED.equals(
John Wangb0b24b32011-06-10 17:23:51 -07001253 absentReason)) {
Wink Savillea639b312012-07-10 12:37:54 -07001254 state = IccCardConstants.State.PERM_DISABLED;
John Wangb0b24b32011-06-10 17:23:51 -07001255 } else {
Wink Savillea639b312012-07-10 12:37:54 -07001256 state = IccCardConstants.State.ABSENT;
John Wangb0b24b32011-06-10 17:23:51 -07001257 }
Wink Savillea639b312012-07-10 12:37:54 -07001258 } else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
1259 state = IccCardConstants.State.READY;
1260 } else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001261 final String lockedReason = intent
Wink Savillea639b312012-07-10 12:37:54 -07001262 .getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON);
1263 if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) {
1264 state = IccCardConstants.State.PIN_REQUIRED;
1265 } else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
1266 state = IccCardConstants.State.PUK_REQUIRED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001267 } else {
Wink Savillea639b312012-07-10 12:37:54 -07001268 state = IccCardConstants.State.UNKNOWN;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001269 }
Wink Savillea639b312012-07-10 12:37:54 -07001270 } else if (IccCardConstants.INTENT_VALUE_LOCKED_NETWORK.equals(stateExtra)) {
1271 state = IccCardConstants.State.NETWORK_LOCKED;
Wileen Chiu6b8b22e2014-10-29 22:48:21 +05301272 } else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) {
1273 state = IccCardConstants.State.CARD_IO_ERROR;
Jim Miller109f1fd2012-09-19 20:44:16 -07001274 } else if (IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(stateExtra)
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001275 || IccCardConstants.INTENT_VALUE_ICC_IMSI.equals(stateExtra)) {
Jim Miller109f1fd2012-09-19 20:44:16 -07001276 // This is required because telephony doesn't return to "READY" after
1277 // these state transitions. See bug 7197471.
1278 state = IccCardConstants.State.READY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001279 } else {
Wink Savillea639b312012-07-10 12:37:54 -07001280 state = IccCardConstants.State.UNKNOWN;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001281 }
Jim Miller52a61332014-11-12 19:29:51 -08001282 return new SimData(state, slotId, subId);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001283 }
1284
Jim Millerd72d5ac2015-09-29 18:55:32 -07001285 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001286 public String toString() {
Jim Miller52a61332014-11-12 19:29:51 -08001287 return "SimData{state=" + simState + ",slotId=" + slotId + ",subId=" + subId + "}";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001288 }
1289 }
1290
Adrian Roos12c1ef52014-06-04 13:54:08 +02001291 public static class BatteryStatus {
Adrian Roos7b043112015-07-10 13:00:33 -07001292 public static final int CHARGING_UNKNOWN = -1;
1293 public static final int CHARGING_SLOWLY = 0;
1294 public static final int CHARGING_REGULAR = 1;
1295 public static final int CHARGING_FAST = 2;
1296
Jim Miller16464b82011-10-20 21:10:13 -07001297 public final int status;
1298 public final int level;
1299 public final int plugged;
1300 public final int health;
Adrian Roos0c859ae2015-11-23 16:47:50 -08001301 public final int maxChargingWattage;
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001302
Adrian Roos0c859ae2015-11-23 16:47:50 -08001303 public BatteryStatus(int status, int level, int plugged, int health,
1304 int maxChargingWattage) {
Jim Miller16464b82011-10-20 21:10:13 -07001305 this.status = status;
1306 this.level = level;
1307 this.plugged = plugged;
1308 this.health = health;
Adrian Roos0c859ae2015-11-23 16:47:50 -08001309 this.maxChargingWattage = maxChargingWattage;
Jim Miller16464b82011-10-20 21:10:13 -07001310 }
1311
Jim Millerbbf1a742012-07-17 18:30:30 -07001312 /**
Brian Muramatsua92a01b2012-09-05 21:54:39 -07001313 * Determine whether the device is plugged in (USB, power, or wireless).
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001314 *
Jim Millerbbf1a742012-07-17 18:30:30 -07001315 * @return true if the device is plugged in.
1316 */
Adrian Roosad3bc7f2014-10-30 18:29:38 +01001317 public boolean isPluggedIn() {
Jim Millerbbf1a742012-07-17 18:30:30 -07001318 return plugged == BatteryManager.BATTERY_PLUGGED_AC
Brian Muramatsua92a01b2012-09-05 21:54:39 -07001319 || plugged == BatteryManager.BATTERY_PLUGGED_USB
1320 || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS;
Jim Millerbbf1a742012-07-17 18:30:30 -07001321 }
1322
1323 /**
Beverly2034c832018-03-19 11:18:51 -04001324 * Determine whether the device is plugged in (USB, power).
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001325 *
Beverly2034c832018-03-19 11:18:51 -04001326 * @return true if the device is plugged in wired (as opposed to wireless)
1327 */
1328 public boolean isPluggedInWired() {
1329 return plugged == BatteryManager.BATTERY_PLUGGED_AC
1330 || plugged == BatteryManager.BATTERY_PLUGGED_USB;
1331 }
1332
1333 /**
Jim Millerbbf1a742012-07-17 18:30:30 -07001334 * Whether or not the device is charged. Note that some devices never return 100% for
1335 * battery level, so this allows either battery level or status to determine if the
1336 * battery is charged.
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001337 *
Jim Millerbbf1a742012-07-17 18:30:30 -07001338 * @return true if the device is charged
1339 */
1340 public boolean isCharged() {
1341 return status == BATTERY_STATUS_FULL || level >= 100;
1342 }
1343
1344 /**
1345 * Whether battery is low and needs to be charged.
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001346 *
Jim Millerbbf1a742012-07-17 18:30:30 -07001347 * @return true if battery is low
1348 */
1349 public boolean isBatteryLow() {
1350 return level < LOW_BATTERY_THRESHOLD;
1351 }
1352
Adrian Roos7b043112015-07-10 13:00:33 -07001353 public final int getChargingSpeed(int slowThreshold, int fastThreshold) {
Adrian Roos0c859ae2015-11-23 16:47:50 -08001354 return maxChargingWattage <= 0 ? CHARGING_UNKNOWN :
1355 maxChargingWattage < slowThreshold ? CHARGING_SLOWLY :
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001356 maxChargingWattage > fastThreshold ? CHARGING_FAST :
1357 CHARGING_REGULAR;
Adrian Roos7b043112015-07-10 13:00:33 -07001358 }
Lucas Dupin3fcdd472018-01-19 19:06:45 -08001359
1360 @Override
1361 public String toString() {
1362 return "BatteryStatus{status=" + status + ",level=" + level + ",plugged=" + plugged
1363 + ",health=" + health + ",maxChargingWattage=" + maxChargingWattage + "}";
1364 }
Jim Miller16464b82011-10-20 21:10:13 -07001365 }
1366
Lucas Dupin3d053532019-01-29 12:35:22 -08001367 public static class StrongAuthTracker extends LockPatternUtils.StrongAuthTracker {
1368 private final Consumer<Integer> mStrongAuthRequiredChangedCallback;
1369
1370 public StrongAuthTracker(Context context,
1371 Consumer<Integer> strongAuthRequiredChangedCallback) {
Rakesh Iyera7aa4d62016-01-19 17:27:23 -08001372 super(context);
Lucas Dupin3d053532019-01-29 12:35:22 -08001373 mStrongAuthRequiredChangedCallback = strongAuthRequiredChangedCallback;
Rakesh Iyera7aa4d62016-01-19 17:27:23 -08001374 }
Adrian Roosb5e47222015-08-14 15:53:06 -07001375
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001376 public boolean isUnlockingWithBiometricAllowed() {
Adrian Roosb5e47222015-08-14 15:53:06 -07001377 int userId = getCurrentUser();
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001378 return isBiometricAllowedForUser(userId);
Adrian Roosb5e47222015-08-14 15:53:06 -07001379 }
1380
1381 public boolean hasUserAuthenticatedSinceBoot() {
1382 int userId = getCurrentUser();
1383 return (getStrongAuthForUser(userId)
1384 & STRONG_AUTH_REQUIRED_AFTER_BOOT) == 0;
1385 }
1386
1387 @Override
1388 public void onStrongAuthRequiredChanged(int userId) {
Lucas Dupin3d053532019-01-29 12:35:22 -08001389 mStrongAuthRequiredChangedCallback.accept(userId);
Adrian Roosb5e47222015-08-14 15:53:06 -07001390 }
1391 }
1392
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001393 protected void handleStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001394 Trace.beginSection("KeyguardUpdateMonitor#handleStartedWakingUp");
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001395 checkIsHandlerThread();
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001396 updateBiometricListeningState();
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001397 for (int i = 0; i < mCallbacks.size(); i++) {
Jim Miller20daffd2013-10-07 14:59:53 -07001398 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
1399 if (cb != null) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001400 cb.onStartedWakingUp();
Jim Miller20daffd2013-10-07 14:59:53 -07001401 }
1402 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001403 Trace.endSection();
Jim Miller20daffd2013-10-07 14:59:53 -07001404 }
1405
Jorim Jaggi95e40382015-09-16 15:53:42 -07001406 protected void handleStartedGoingToSleep(int arg1) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001407 checkIsHandlerThread();
Curtis Belmonte6a0634d2019-08-19 13:13:01 -07001408 mLockIconPressed = false;
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001409 clearBiometricRecognized();
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001410 for (int i = 0; i < mCallbacks.size(); i++) {
Jim Miller20daffd2013-10-07 14:59:53 -07001411 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
1412 if (cb != null) {
Jorim Jaggi95e40382015-09-16 15:53:42 -07001413 cb.onStartedGoingToSleep(arg1);
1414 }
1415 }
1416 mGoingToSleep = true;
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001417 updateBiometricListeningState();
Jorim Jaggi95e40382015-09-16 15:53:42 -07001418 }
1419
1420 protected void handleFinishedGoingToSleep(int arg1) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001421 checkIsHandlerThread();
Jorim Jaggi95e40382015-09-16 15:53:42 -07001422 mGoingToSleep = false;
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001423 for (int i = 0; i < mCallbacks.size(); i++) {
Jorim Jaggi95e40382015-09-16 15:53:42 -07001424 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
1425 if (cb != null) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001426 cb.onFinishedGoingToSleep(arg1);
Jim Miller20daffd2013-10-07 14:59:53 -07001427 }
1428 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001429 updateBiometricListeningState();
Jim Miller20daffd2013-10-07 14:59:53 -07001430 }
1431
Jorim Jaggif1518da2015-07-30 11:56:36 -07001432 private void handleScreenTurnedOn() {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001433 checkIsHandlerThread();
1434 for (int i = 0; i < mCallbacks.size(); i++) {
Jorim Jaggif1518da2015-07-30 11:56:36 -07001435 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
1436 if (cb != null) {
1437 cb.onScreenTurnedOn();
1438 }
1439 }
1440 }
1441
1442 private void handleScreenTurnedOff() {
Lucas Dupind236ee32019-10-08 15:33:59 -07001443 final String tag = "KeyguardUpdateMonitor#handleScreenTurnedOff";
1444 DejankUtils.startDetectingBlockingIpcs(tag);
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001445 checkIsHandlerThread();
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001446 mHardwareFingerprintUnavailableRetryCount = 0;
1447 mHardwareFaceUnavailableRetryCount = 0;
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001448 for (int i = 0; i < mCallbacks.size(); i++) {
Jorim Jaggif1518da2015-07-30 11:56:36 -07001449 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
1450 if (cb != null) {
1451 cb.onScreenTurnedOff();
1452 }
1453 }
Lucas Dupind236ee32019-10-08 15:33:59 -07001454 DejankUtils.stopDetectingBlockingIpcs(tag);
Jorim Jaggif1518da2015-07-30 11:56:36 -07001455 }
1456
Selim Cinek99415392016-09-09 14:58:41 -07001457 private void handleDreamingStateChanged(int dreamStart) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001458 checkIsHandlerThread();
Kevin Chyn36778ff2017-09-07 19:55:38 -07001459 mIsDreaming = dreamStart == 1;
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001460 for (int i = 0; i < mCallbacks.size(); i++) {
Selim Cinek99415392016-09-09 14:58:41 -07001461 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
1462 if (cb != null) {
Kevin Chyn36778ff2017-09-07 19:55:38 -07001463 cb.onDreamingStateChanged(mIsDreaming);
Selim Cinek99415392016-09-09 14:58:41 -07001464 }
1465 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001466 updateBiometricListeningState();
Selim Cinek99415392016-09-09 14:58:41 -07001467 }
1468
Amith Yamasani6fc1d4e2013-05-08 16:43:58 -07001469 private void handleUserInfoChanged(int userId) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001470 checkIsHandlerThread();
Amith Yamasani6fc1d4e2013-05-08 16:43:58 -07001471 for (int i = 0; i < mCallbacks.size(); i++) {
1472 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
1473 if (cb != null) {
1474 cb.onUserInfoChanged(userId);
1475 }
1476 }
1477 }
1478
Lucas Dupin6c6d5732019-08-27 17:36:05 -07001479 private void handleUserUnlocked(int userId) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001480 checkIsHandlerThread();
Lucas Dupin6c6d5732019-08-27 17:36:05 -07001481 mUserIsUnlocked.put(userId, true);
Jorim Jaggidadafd42016-09-30 07:20:25 -07001482 mNeedsSlowUnlockTransition = resolveNeedsSlowUnlockTransition();
1483 for (int i = 0; i < mCallbacks.size(); i++) {
1484 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
1485 if (cb != null) {
1486 cb.onUserUnlocked();
1487 }
1488 }
1489 }
1490
Lucas Dupin6c6d5732019-08-27 17:36:05 -07001491 private void handleUserStopped(int userId) {
1492 checkIsHandlerThread();
1493 mUserIsUnlocked.put(userId, mUserManager.isUserUnlocked(userId));
1494 }
1495
Lucas Dupinf2c53502019-10-03 13:56:18 -07001496 @VisibleForTesting
1497 void handleUserRemoved(int userId) {
Lucas Dupin6c6d5732019-08-27 17:36:05 -07001498 checkIsHandlerThread();
1499 mUserIsUnlocked.delete(userId);
Lucas Dupinf2c53502019-10-03 13:56:18 -07001500 mUserTrustIsUsuallyManaged.delete(userId);
Lucas Dupin6c6d5732019-08-27 17:36:05 -07001501 }
1502
Lucas Dupin7517b5d2017-08-22 12:51:25 -07001503 @VisibleForTesting
Dave Mankoffe2294692019-08-14 11:53:13 -04001504 @Inject
Lucas Dupin64171fe2019-10-30 14:28:29 -07001505 protected KeyguardUpdateMonitor(Context context, @MainLooper Looper mainLooper,
Fabian Kozynski5ca7a512019-10-16 19:56:11 +00001506 BroadcastDispatcher broadcastDispatcher,
Lucas Dupin64171fe2019-10-30 14:28:29 -07001507 DumpController dumpController) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001508 mContext = context;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001509 mSubscriptionManager = SubscriptionManager.from(context);
Michael Jurkafff56142012-11-28 16:51:00 -08001510 mDeviceProvisioned = isDeviceProvisionedInSettingsDb();
Lucas Dupin3d053532019-01-29 12:35:22 -08001511 mStrongAuthTracker = new StrongAuthTracker(context, this::notifyStrongAuthStateChanged);
Lucas Dupin64171fe2019-10-30 14:28:29 -07001512 dumpController.registerDumpable(this);
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -07001513
Dave Mankoffe2294692019-08-14 11:53:13 -04001514 mHandler = new Handler(mainLooper) {
1515 @Override
1516 public void handleMessage(Message msg) {
1517 switch (msg.what) {
1518 case MSG_TIME_UPDATE:
1519 handleTimeUpdate();
1520 break;
1521 case MSG_TIMEZONE_UPDATE:
1522 handleTimeZoneUpdate((String) msg.obj);
1523 break;
1524 case MSG_BATTERY_UPDATE:
1525 handleBatteryUpdate((BatteryStatus) msg.obj);
1526 break;
1527 case MSG_SIM_STATE_CHANGE:
1528 handleSimStateChange(msg.arg1, msg.arg2, (State) msg.obj);
1529 break;
1530 case MSG_RINGER_MODE_CHANGED:
1531 handleRingerModeChange(msg.arg1);
1532 break;
1533 case MSG_PHONE_STATE_CHANGED:
1534 handlePhoneStateChanged((String) msg.obj);
1535 break;
1536 case MSG_DEVICE_PROVISIONED:
1537 handleDeviceProvisioned();
1538 break;
1539 case MSG_DPM_STATE_CHANGED:
1540 handleDevicePolicyManagerStateChanged();
1541 break;
1542 case MSG_USER_SWITCHING:
1543 handleUserSwitching(msg.arg1, (IRemoteCallback) msg.obj);
1544 break;
1545 case MSG_USER_SWITCH_COMPLETE:
1546 handleUserSwitchComplete(msg.arg1);
1547 break;
1548 case MSG_KEYGUARD_RESET:
1549 handleKeyguardReset();
1550 break;
1551 case MSG_KEYGUARD_BOUNCER_CHANGED:
1552 handleKeyguardBouncerChanged(msg.arg1);
1553 break;
1554 case MSG_BOOT_COMPLETED:
1555 handleBootCompleted();
1556 break;
1557 case MSG_USER_INFO_CHANGED:
1558 handleUserInfoChanged(msg.arg1);
1559 break;
1560 case MSG_REPORT_EMERGENCY_CALL_ACTION:
1561 handleReportEmergencyCallAction();
1562 break;
1563 case MSG_STARTED_GOING_TO_SLEEP:
1564 handleStartedGoingToSleep(msg.arg1);
1565 break;
1566 case MSG_FINISHED_GOING_TO_SLEEP:
1567 handleFinishedGoingToSleep(msg.arg1);
1568 break;
1569 case MSG_STARTED_WAKING_UP:
1570 Trace.beginSection("KeyguardUpdateMonitor#handler MSG_STARTED_WAKING_UP");
1571 handleStartedWakingUp();
1572 Trace.endSection();
1573 break;
1574 case MSG_FACE_UNLOCK_STATE_CHANGED:
1575 Trace.beginSection(
1576 "KeyguardUpdateMonitor#handler MSG_FACE_UNLOCK_STATE_CHANGED");
1577 handleFaceUnlockStateChanged(msg.arg1 != 0, msg.arg2);
1578 Trace.endSection();
1579 break;
1580 case MSG_SIM_SUBSCRIPTION_INFO_CHANGED:
1581 handleSimSubscriptionInfoChanged();
1582 break;
1583 case MSG_AIRPLANE_MODE_CHANGED:
1584 handleAirplaneModeChanged();
1585 break;
1586 case MSG_SERVICE_STATE_CHANGE:
1587 handleServiceStateChange(msg.arg1, (ServiceState) msg.obj);
1588 break;
1589 case MSG_SCREEN_TURNED_ON:
1590 handleScreenTurnedOn();
1591 break;
1592 case MSG_SCREEN_TURNED_OFF:
1593 Trace.beginSection("KeyguardUpdateMonitor#handler MSG_SCREEN_TURNED_ON");
1594 handleScreenTurnedOff();
1595 Trace.endSection();
1596 break;
1597 case MSG_DREAMING_STATE_CHANGED:
1598 handleDreamingStateChanged(msg.arg1);
1599 break;
1600 case MSG_USER_UNLOCKED:
1601 handleUserUnlocked(msg.arg1);
1602 break;
1603 case MSG_USER_STOPPED:
1604 handleUserStopped(msg.arg1);
1605 break;
1606 case MSG_USER_REMOVED:
1607 handleUserRemoved(msg.arg1);
1608 break;
1609 case MSG_ASSISTANT_STACK_CHANGED:
1610 setAssistantVisible((boolean) msg.obj);
1611 break;
1612 case MSG_BIOMETRIC_AUTHENTICATION_CONTINUE:
1613 updateBiometricListeningState();
1614 break;
1615 case MSG_DEVICE_POLICY_MANAGER_STATE_CHANGED:
1616 updateLogoutEnabled();
1617 break;
1618 case MSG_TELEPHONY_CAPABLE:
1619 updateTelephonyCapable((boolean) msg.obj);
1620 break;
1621 default:
1622 super.handleMessage(msg);
1623 break;
1624 }
1625 }
1626 };
1627
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001628 // Since device can't be un-provisioned, we only need to register a content observer
1629 // to update mDeviceProvisioned when we are...
1630 if (!mDeviceProvisioned) {
Jim Millerbbf1a742012-07-17 18:30:30 -07001631 watchForDeviceProvisioning();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001632 }
Jim Miller47088bb2009-11-24 00:40:16 -08001633
Jim Millerbbf1a742012-07-17 18:30:30 -07001634 // Take a guess at initial SIM state, battery status and PLMN until we get an update
Adrian Roos7b043112015-07-10 13:00:33 -07001635 mBatteryStatus = new BatteryStatus(BATTERY_STATUS_UNKNOWN, 100, 0, 0, 0);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001636
Jim Millerbbf1a742012-07-17 18:30:30 -07001637 // Watch for interesting updates
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001638 final IntentFilter filter = new IntentFilter();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001639 filter.addAction(Intent.ACTION_TIME_TICK);
1640 filter.addAction(Intent.ACTION_TIME_CHANGED);
1641 filter.addAction(Intent.ACTION_BATTERY_CHANGED);
1642 filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
Jason Monk052082c2015-06-11 11:35:23 -04001643 filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001644 filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
Etan Cohen47051d82015-07-06 16:19:04 -07001645 filter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Fabian Kozynskiccde55d2019-06-26 10:06:09 -04001646 filter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
Jim Millerc23024d2010-02-24 15:37:00 -08001647 filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Jim Miller47088bb2009-11-24 00:40:16 -08001648 filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
Alex Chauff7653d2018-02-01 17:18:08 +00001649 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +00001650 broadcastDispatcher.registerReceiver(mBroadcastReceiver, filter, mHandler);
Dianne Hackborn5dc5a002012-09-15 19:33:48 -07001651
Adam Cohenc276e822012-11-08 13:01:08 -08001652 final IntentFilter bootCompleteFilter = new IntentFilter();
1653 bootCompleteFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
1654 bootCompleteFilter.addAction(Intent.ACTION_BOOT_COMPLETED);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +00001655 broadcastDispatcher.registerReceiver(mBroadcastReceiver, bootCompleteFilter, mHandler);
Adam Cohenc276e822012-11-08 13:01:08 -08001656
Adrian Roos48c796c2014-09-01 14:59:23 +02001657 final IntentFilter allUserFilter = new IntentFilter();
1658 allUserFilter.addAction(Intent.ACTION_USER_INFO_CHANGED);
1659 allUserFilter.addAction(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED);
1660 allUserFilter.addAction(ACTION_FACE_UNLOCK_STARTED);
1661 allUserFilter.addAction(ACTION_FACE_UNLOCK_STOPPED);
1662 allUserFilter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
Jorim Jaggidadafd42016-09-30 07:20:25 -07001663 allUserFilter.addAction(ACTION_USER_UNLOCKED);
Lucas Dupin6c6d5732019-08-27 17:36:05 -07001664 allUserFilter.addAction(ACTION_USER_STOPPED);
1665 allUserFilter.addAction(ACTION_USER_REMOVED);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +00001666 broadcastDispatcher.registerReceiver(mBroadcastAllReceiver, allUserFilter, mHandler,
1667 UserHandle.ALL);
Amith Yamasani6fc1d4e2013-05-08 16:43:58 -07001668
Wink Saville071743f2015-01-12 17:11:04 -08001669 mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionListener);
Dianne Hackborn5dc5a002012-09-15 19:33:48 -07001670 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001671 ActivityManager.getService().registerUserSwitchObserver(
Sudheer Shanka2c4522c2016-08-27 20:53:28 -07001672 new UserSwitchObserver() {
Dianne Hackborn5dc5a002012-09-15 19:33:48 -07001673 @Override
1674 public void onUserSwitching(int newUserId, IRemoteCallback reply) {
Chris Wrenf41c61b2012-11-29 15:19:54 -05001675 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHING,
Dianne Hackborn5dc5a002012-09-15 19:33:48 -07001676 newUserId, 0, reply));
1677 }
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001678
Dianne Hackborn5dc5a002012-09-15 19:33:48 -07001679 @Override
1680 public void onUserSwitchComplete(int newUserId) throws RemoteException {
Chris Wrenf41c61b2012-11-29 15:19:54 -05001681 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCH_COMPLETE,
Adrian Roosbe47b072014-09-03 00:08:56 +02001682 newUserId, 0));
Dianne Hackborn5dc5a002012-09-15 19:33:48 -07001683 }
Fyodor Kupolov0b77ef92016-06-20 17:16:52 -07001684 }, TAG);
Dianne Hackborn5dc5a002012-09-15 19:33:48 -07001685 } catch (RemoteException e) {
Fyodor Kupolov0b77ef92016-06-20 17:16:52 -07001686 e.rethrowAsRuntimeException();
Dianne Hackborn5dc5a002012-09-15 19:33:48 -07001687 }
Adrian Roos46842d92014-03-27 14:58:03 +01001688
Lucas Dupinf2c53502019-10-03 13:56:18 -07001689 mTrustManager = context.getSystemService(TrustManager.class);
Jorim Jaggi237b0612015-05-01 14:28:49 -07001690 mTrustManager.registerTrustListener(this);
Michal Karpinskic52f8672016-11-18 11:32:45 +00001691 mLockPatternUtils = new LockPatternUtils(context);
1692 mLockPatternUtils.registerStrongAuthTracker(mStrongAuthTracker);
Jim Millerf41fc962014-06-18 16:33:51 -07001693
Kevin Chyn36778ff2017-09-07 19:55:38 -07001694 mDreamManager = IDreamManager.Stub.asInterface(
1695 ServiceManager.getService(DreamService.DREAM_SERVICE));
1696
Jorim Jaggi3f124262016-11-22 13:45:17 +01001697 if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) {
1698 mFpm = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
1699 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001700 if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE)) {
Kevin Chynb7b54a62018-09-28 18:48:12 -07001701 mFaceManager = (FaceManager) context.getSystemService(Context.FACE_SERVICE);
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001702 }
Kevin Chynb7b54a62018-09-28 18:48:12 -07001703
1704 if (mFpm != null || mFaceManager != null) {
1705 mBiometricManager = context.getSystemService(BiometricManager.class);
1706 mBiometricManager.registerEnabledOnKeyguardCallback(mBiometricEnabledCallback);
1707 }
1708
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001709 updateBiometricListeningState();
Jorim Jaggi3a464782015-08-28 16:59:13 -07001710 if (mFpm != null) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001711 mFpm.addLockoutResetCallback(mFingerprintLockoutResetCallback);
1712 }
Kevin Chynb7b54a62018-09-28 18:48:12 -07001713 if (mFaceManager != null) {
1714 mFaceManager.addLockoutResetCallback(mFaceLockoutResetCallback);
Jorim Jaggi3a464782015-08-28 16:59:13 -07001715 }
Jorim Jaggie8fde5d2016-06-30 23:41:37 -07001716
Winson Chung2cf6ad82017-11-09 17:36:59 -08001717 ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
Jorim Jaggie8fde5d2016-06-30 23:41:37 -07001718 mUserManager = context.getSystemService(UserManager.class);
Kevin Chynfdfd2d32019-03-01 14:52:15 -08001719 mIsPrimaryUser = mUserManager.isPrimaryUser();
Lucas Dupin6c6d5732019-08-27 17:36:05 -07001720 int user = ActivityManager.getCurrentUser();
1721 mUserIsUnlocked.put(user, mUserManager.isUserUnlocked(user));
Alex Chauff7653d2018-02-01 17:18:08 +00001722 mDevicePolicyManager = context.getSystemService(DevicePolicyManager.class);
1723 mLogoutEnabled = mDevicePolicyManager.isLogoutEnabled();
Lucas Dupinf2c53502019-10-03 13:56:18 -07001724 List<UserInfo> allUsers = mUserManager.getUsers();
1725 for (UserInfo userInfo : allUsers) {
1726 mUserTrustIsUsuallyManaged.put(userInfo.id,
1727 mTrustManager.isTrustUsuallyManaged(userInfo.id));
1728 }
Bill Linef81cbd2018-07-05 17:48:49 +08001729 updateAirplaneModeState();
Fabian Kozynskiccde55d2019-06-26 10:06:09 -04001730
1731 TelephonyManager telephony =
1732 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
1733 if (telephony != null) {
1734 telephony.listen(mPhoneStateListener, LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE);
1735 }
Bill Linef81cbd2018-07-05 17:48:49 +08001736 }
1737
1738 private void updateAirplaneModeState() {
1739 // ACTION_AIRPLANE_MODE_CHANGED do not broadcast if device set AirplaneMode ON and boot
1740 if (!WirelessUtils.isAirplaneModeOn(mContext)
1741 || mHandler.hasMessages(MSG_AIRPLANE_MODE_CHANGED)) {
1742 return;
1743 }
1744 mHandler.sendEmptyMessage(MSG_AIRPLANE_MODE_CHANGED);
Jorim Jaggiea657062015-04-28 13:45:11 -07001745 }
1746
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001747 private void updateBiometricListeningState() {
1748 updateFingerprintListeningState();
1749 updateFaceListeningState();
1750 }
1751
Jorim Jaggiea657062015-04-28 13:45:11 -07001752 private void updateFingerprintListeningState() {
Kevin Chyn0f3e0b12017-07-20 16:56:11 -07001753 // If this message exists, we should not authenticate again until this message is
1754 // consumed by the handler
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001755 if (mHandler.hasMessages(MSG_BIOMETRIC_AUTHENTICATION_CONTINUE)) {
Kevin Chyn0f3e0b12017-07-20 16:56:11 -07001756 return;
1757 }
Kevin Chyn0c45b072017-04-24 16:27:11 -07001758 mHandler.removeCallbacks(mRetryFingerprintAuthentication);
Jorim Jaggiea657062015-04-28 13:45:11 -07001759 boolean shouldListenForFingerprint = shouldListenForFingerprint();
Adrian Roos2aaf9442018-11-20 16:57:33 +01001760 boolean runningOrRestarting = mFingerprintRunningState == BIOMETRIC_STATE_RUNNING
1761 || mFingerprintRunningState == BIOMETRIC_STATE_CANCELLING_RESTARTING;
1762 if (runningOrRestarting && !shouldListenForFingerprint) {
Jorim Jaggiea657062015-04-28 13:45:11 -07001763 stopListeningForFingerprint();
Adrian Roos2aaf9442018-11-20 16:57:33 +01001764 } else if (!runningOrRestarting && shouldListenForFingerprint) {
Jorim Jaggiea657062015-04-28 13:45:11 -07001765 startListeningForFingerprint();
1766 }
1767 }
1768
Lucas Dupin3d053532019-01-29 12:35:22 -08001769 /**
Lucas Dupin6c6d5732019-08-27 17:36:05 -07001770 * If a user is encrypted or not.
1771 * This is NOT related to the lock screen being visible or not.
1772 *
1773 * @param userId The user.
1774 * @return {@code true} when encrypted.
1775 * @see UserManager#isUserUnlocked()
1776 * @see Intent#ACTION_USER_UNLOCKED
1777 */
1778 public boolean isUserUnlocked(int userId) {
1779 return mUserIsUnlocked.get(userId);
1780 }
1781
1782 /**
Lucas Dupine0516d52019-02-05 17:54:06 -05001783 * Called whenever passive authentication is requested or aborted by a sensor.
Dave Mankoff4b0ab652019-08-07 09:49:20 -04001784 *
Lucas Dupine0516d52019-02-05 17:54:06 -05001785 * @param active If the interrupt started or ended.
Lucas Dupin3d053532019-01-29 12:35:22 -08001786 */
Lucas Dupine0516d52019-02-05 17:54:06 -05001787 public void onAuthInterruptDetected(boolean active) {
1788 if (DEBUG) Log.d(TAG, "onAuthInterruptDetected(" + active + ")");
1789 if (mAuthInterruptActive == active) {
1790 return;
1791 }
1792 mAuthInterruptActive = active;
Lucas Dupin3d053532019-01-29 12:35:22 -08001793 updateFaceListeningState();
1794 }
1795
Lucas Dupin8f3faac2019-03-12 15:28:49 -07001796 /**
1797 * Requests face authentication if we're on a state where it's allowed.
1798 * This will re-trigger auth in case it fails.
1799 */
1800 public void requestFaceAuth() {
1801 if (DEBUG) Log.d(TAG, "requestFaceAuth()");
1802 updateFaceListeningState();
1803 }
1804
Lucas Dupinccf67212019-08-07 12:53:02 -07001805 /**
1806 * In case face auth is running, cancel it.
1807 */
1808 public void cancelFaceAuth() {
1809 stopListeningForFace();
1810 }
1811
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001812 private void updateFaceListeningState() {
1813 // If this message exists, we should not authenticate again until this message is
1814 // consumed by the handler
1815 if (mHandler.hasMessages(MSG_BIOMETRIC_AUTHENTICATION_CONTINUE)) {
1816 return;
1817 }
1818 mHandler.removeCallbacks(mRetryFaceAuthentication);
1819 boolean shouldListenForFace = shouldListenForFace();
1820 if (mFaceRunningState == BIOMETRIC_STATE_RUNNING && !shouldListenForFace) {
1821 stopListeningForFace();
1822 } else if (mFaceRunningState != BIOMETRIC_STATE_RUNNING
1823 && shouldListenForFace) {
1824 startListeningForFace();
1825 }
1826 }
1827
Kevin Chyn129f60f2017-08-11 17:24:42 -07001828 private boolean shouldListenForFingerprintAssistant() {
1829 return mAssistantVisible && mKeyguardOccluded
1830 && !mUserFingerprintAuthenticated.get(getCurrentUser(), false)
1831 && !mUserHasTrust.get(getCurrentUser(), false);
1832 }
1833
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001834 private boolean shouldListenForFaceAssistant() {
1835 return mAssistantVisible && mKeyguardOccluded
1836 && !mUserFaceAuthenticated.get(getCurrentUser(), false)
1837 && !mUserHasTrust.get(getCurrentUser(), false);
1838 }
1839
Jorim Jaggiea657062015-04-28 13:45:11 -07001840 private boolean shouldListenForFingerprint() {
Kevin Chynfdfd2d32019-03-01 14:52:15 -08001841 // Only listen if this KeyguardUpdateMonitor belongs to the primary user. There is an
1842 // instance of KeyguardUpdateMonitor for each user but KeyguardUpdateMonitor is user-aware.
1843 final boolean shouldListen = (mKeyguardIsVisible || !mDeviceInteractive ||
Kevin Chyn0f3e0b12017-07-20 16:56:11 -07001844 (mBouncer && !mKeyguardGoingAway) || mGoingToSleep ||
Kevin Chyn36778ff2017-09-07 19:55:38 -07001845 shouldListenForFingerprintAssistant() || (mKeyguardOccluded && mIsDreaming))
Lucas Dupinc12fad32019-05-14 20:59:17 +00001846 && !mSwitchingUser && !isFingerprintDisabled(getCurrentUser())
Kevin Chyn225eea72019-03-06 16:42:00 -08001847 && (!mKeyguardGoingAway || !mDeviceInteractive) && mIsPrimaryUser;
Kevin Chynfdfd2d32019-03-01 14:52:15 -08001848 return shouldListen;
Jim Miller9f0753f2015-03-23 23:59:22 -07001849 }
1850
Lucas Dupin4b75b192019-08-29 14:46:29 -07001851 /**
1852 * If face auth is allows to scan on this exact moment.
1853 */
1854 public boolean shouldListenForFace() {
Lucas Dupin3d053532019-01-29 12:35:22 -08001855 final boolean awakeKeyguard = mKeyguardIsVisible && mDeviceInteractive && !mGoingToSleep;
1856 final int user = getCurrentUser();
Robert Snoeberger5dcdf352019-06-24 11:28:28 -04001857 final int strongAuth = mStrongAuthTracker.getStrongAuthForUser(user);
1858 final boolean isLockOutOrLockDown =
Lucas Dupin8eec2682019-07-01 16:41:17 -07001859 containsFlag(strongAuth, STRONG_AUTH_REQUIRED_AFTER_LOCKOUT)
1860 || containsFlag(strongAuth, STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW)
1861 || containsFlag(strongAuth, STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN);
1862 final boolean isEncryptedOrTimedOut =
1863 containsFlag(strongAuth, STRONG_AUTH_REQUIRED_AFTER_BOOT)
1864 || containsFlag(strongAuth, STRONG_AUTH_REQUIRED_AFTER_TIMEOUT);
Lucas Dupin9e484aa2019-06-24 13:38:00 -07001865
Lucas Dupin4befb742019-07-01 11:31:31 -07001866 boolean canBypass = mKeyguardBypassController != null
1867 && mKeyguardBypassController.canBypass();
Lucas Dupin9e484aa2019-06-24 13:38:00 -07001868 // There's no reason to ask the HAL for authentication when the user can dismiss the
1869 // bouncer, unless we're bypassing and need to auto-dismiss the lock screen even when
1870 // TrustAgents or biometrics are keeping the device unlocked.
Lucas Dupin4befb742019-07-01 11:31:31 -07001871 boolean becauseCannotSkipBouncer = !getUserCanSkipBouncer(user) || canBypass;
Lucas Dupin9e484aa2019-06-24 13:38:00 -07001872
Lucas Dupin8eec2682019-07-01 16:41:17 -07001873 // Scan even when encrypted or timeout to show a preemptive bouncer when bypassing.
1874 // Lockout/lockdown modes shouldn't scan, since they are more explicit.
1875 boolean strongAuthAllowsScanning = (!isEncryptedOrTimedOut || canBypass && !mBouncer)
1876 && !isLockOutOrLockDown;
1877
Kevin Chynfdfd2d32019-03-01 14:52:15 -08001878 // Only listen if this KeyguardUpdateMonitor belongs to the primary user. There is an
1879 // instance of KeyguardUpdateMonitor for each user but KeyguardUpdateMonitor is user-aware.
Lucas Dupine0516d52019-02-05 17:54:06 -05001880 return (mBouncer || mAuthInterruptActive || awakeKeyguard || shouldListenForFaceAssistant())
Lucas Dupin9e484aa2019-06-24 13:38:00 -07001881 && !mSwitchingUser && !isFaceDisabled(user) && becauseCannotSkipBouncer
Lucas Dupin7d95f152019-07-17 16:25:54 -07001882 && !mKeyguardGoingAway && mFaceSettingEnabledForUser.get(user) && !mLockIconPressed
Lucas Dupin8eec2682019-07-01 16:41:17 -07001883 && strongAuthAllowsScanning && mIsPrimaryUser
1884 && !mSecureCameraLaunched;
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001885 }
1886
Lucas Dupinca88e5f2019-05-14 16:11:08 -07001887 /**
1888 * Whenever the lock icon is long pressed, disabling trust agents.
1889 * This means that we cannot auth passively (face) until the user presses power.
1890 */
1891 public void onLockIconPressed() {
1892 mLockIconPressed = true;
Curtis Belmontec48eff52019-08-21 15:51:34 -07001893 final int userId = getCurrentUser();
1894 mUserFaceAuthenticated.put(userId, false);
Lucas Dupinca88e5f2019-05-14 16:11:08 -07001895 updateFaceListeningState();
Curtis Belmontec48eff52019-08-21 15:51:34 -07001896 mStrongAuthTracker.onStrongAuthRequiredChanged(userId);
Lucas Dupinca88e5f2019-05-14 16:11:08 -07001897 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001898
Jim Millerce7eb6d2015-04-03 19:29:13 -07001899 private void startListeningForFingerprint() {
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001900 if (mFingerprintRunningState == BIOMETRIC_STATE_CANCELLING) {
1901 setFingerprintRunningState(BIOMETRIC_STATE_CANCELLING_RESTARTING);
Jorim Jaggi86bed402015-08-20 18:20:02 -07001902 return;
1903 }
Adrian Roos2aaf9442018-11-20 16:57:33 +01001904 if (mFingerprintRunningState == BIOMETRIC_STATE_CANCELLING_RESTARTING) {
1905 // Waiting for restart via handleFingerprintError().
1906 return;
1907 }
Jim Millerce7eb6d2015-04-03 19:29:13 -07001908 if (DEBUG) Log.v(TAG, "startListeningForFingerprint()");
Lucas Dupin8f3faac2019-03-12 15:28:49 -07001909 int userId = getCurrentUser();
Jorim Jaggi71448a72015-08-18 19:49:04 -07001910 if (isUnlockWithFingerprintPossible(userId)) {
Jim Millerce7eb6d2015-04-03 19:29:13 -07001911 if (mFingerprintCancelSignal != null) {
Jim Miller9f0753f2015-03-23 23:59:22 -07001912 mFingerprintCancelSignal.cancel();
1913 }
Jim Millerce7eb6d2015-04-03 19:29:13 -07001914 mFingerprintCancelSignal = new CancellationSignal();
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001915 mFpm.authenticate(null, mFingerprintCancelSignal, 0, mFingerprintAuthenticationCallback,
1916 null, userId);
1917 setFingerprintRunningState(BIOMETRIC_STATE_RUNNING);
1918 }
1919 }
1920
1921 private void startListeningForFace() {
1922 if (mFaceRunningState == BIOMETRIC_STATE_CANCELLING) {
1923 setFaceRunningState(BIOMETRIC_STATE_CANCELLING_RESTARTING);
1924 return;
1925 }
1926 if (DEBUG) Log.v(TAG, "startListeningForFace()");
Lucas Dupin8f3faac2019-03-12 15:28:49 -07001927 int userId = getCurrentUser();
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001928 if (isUnlockWithFacePossible(userId)) {
1929 if (mFaceCancelSignal != null) {
1930 mFaceCancelSignal.cancel();
1931 }
1932 mFaceCancelSignal = new CancellationSignal();
Kevin Chynb7b54a62018-09-28 18:48:12 -07001933 mFaceManager.authenticate(null, mFaceCancelSignal, 0,
Kevin Chyn8d2694a2019-04-11 18:30:40 -07001934 mFaceAuthenticationCallback, null, userId);
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001935 setFaceRunningState(BIOMETRIC_STATE_RUNNING);
Jim Miller9f0753f2015-03-23 23:59:22 -07001936 }
1937 }
1938
Lucas Dupin8d48fc42019-04-25 14:34:12 -07001939 /**
1940 * If biometrics hardware is available, not disabled, and user has enrolled templates.
1941 * This does NOT check if the device is encrypted or in lockdown.
1942 *
1943 * @param userId User that's trying to unlock.
1944 * @return {@code true} if possible.
1945 */
1946 public boolean isUnlockingWithBiometricsPossible(int userId) {
1947 return isUnlockWithFacePossible(userId) || isUnlockWithFingerprintPossible(userId);
1948 }
1949
1950 private boolean isUnlockWithFingerprintPossible(int userId) {
Selim Cinek3122fa82015-06-18 01:38:59 -07001951 return mFpm != null && mFpm.isHardwareDetected() && !isFingerprintDisabled(userId)
1952 && mFpm.getEnrolledFingerprints(userId).size() > 0;
1953 }
1954
Lucas Dupin4c507042019-07-22 16:47:34 -07001955 private boolean isUnlockWithFacePossible(int userId) {
1956 return isFaceAuthEnabledForUser(userId) && !isFaceDisabled(userId);
1957 }
1958
Lucas Dupin7156bc72019-05-03 19:37:39 -07001959 /**
Lucas Dupin7d95f152019-07-17 16:25:54 -07001960 * If face hardware is available, user has enrolled and enabled auth via setting.
Lucas Dupin7156bc72019-05-03 19:37:39 -07001961 */
Lucas Dupin4c507042019-07-22 16:47:34 -07001962 public boolean isFaceAuthEnabledForUser(int userId) {
Lucas Dupin8968f6a2019-08-09 17:41:15 -07001963 // TODO(b/140034352)
1964 return whitelistIpcs(() -> mFaceManager != null && mFaceManager.isHardwareDetected()
Lucas Dupin7d95f152019-07-17 16:25:54 -07001965 && mFaceManager.hasEnrolledTemplates(userId)
Lucas Dupin8968f6a2019-08-09 17:41:15 -07001966 && mFaceSettingEnabledForUser.get(userId));
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001967 }
1968
Jorim Jaggiea657062015-04-28 13:45:11 -07001969 private void stopListeningForFingerprint() {
Jim Millerce7eb6d2015-04-03 19:29:13 -07001970 if (DEBUG) Log.v(TAG, "stopListeningForFingerprint()");
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001971 if (mFingerprintRunningState == BIOMETRIC_STATE_RUNNING) {
Kevin Chyn2fefd462017-04-28 12:18:19 -07001972 if (mFingerprintCancelSignal != null) {
1973 mFingerprintCancelSignal.cancel();
1974 mFingerprintCancelSignal = null;
joshmccloskey7dee4542019-07-31 18:35:33 -07001975 if (!mHandler.hasCallbacks(mCancelNotReceived)) {
1976 mHandler.postDelayed(mCancelNotReceived, DEFAULT_CANCEL_SIGNAL_TIMEOUT);
1977 }
Kevin Chyn2fefd462017-04-28 12:18:19 -07001978 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001979 setFingerprintRunningState(BIOMETRIC_STATE_CANCELLING);
Jim Miller9f0753f2015-03-23 23:59:22 -07001980 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001981 if (mFingerprintRunningState == BIOMETRIC_STATE_CANCELLING_RESTARTING) {
1982 setFingerprintRunningState(BIOMETRIC_STATE_CANCELLING);
1983 }
1984 }
1985
1986 private void stopListeningForFace() {
1987 if (DEBUG) Log.v(TAG, "stopListeningForFace()");
1988 if (mFaceRunningState == BIOMETRIC_STATE_RUNNING) {
1989 if (mFaceCancelSignal != null) {
1990 mFaceCancelSignal.cancel();
1991 mFaceCancelSignal = null;
joshmccloskey7dee4542019-07-31 18:35:33 -07001992 if (!mHandler.hasCallbacks(mCancelNotReceived)) {
1993 mHandler.postDelayed(mCancelNotReceived, DEFAULT_CANCEL_SIGNAL_TIMEOUT);
1994 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001995 }
1996 setFaceRunningState(BIOMETRIC_STATE_CANCELLING);
1997 }
1998 if (mFaceRunningState == BIOMETRIC_STATE_CANCELLING_RESTARTING) {
1999 setFaceRunningState(BIOMETRIC_STATE_CANCELLING);
Jorim Jaggi86bed402015-08-20 18:20:02 -07002000 }
Jim Millerbbf1a742012-07-17 18:30:30 -07002001 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002002
Michael Jurkafff56142012-11-28 16:51:00 -08002003 private boolean isDeviceProvisionedInSettingsDb() {
2004 return Settings.Global.getInt(mContext.getContentResolver(),
2005 Settings.Global.DEVICE_PROVISIONED, 0) != 0;
2006 }
2007
Jim Millerbbf1a742012-07-17 18:30:30 -07002008 private void watchForDeviceProvisioning() {
Michael Jurkafff56142012-11-28 16:51:00 -08002009 mDeviceProvisionedObserver = new ContentObserver(mHandler) {
Jim Millerbbf1a742012-07-17 18:30:30 -07002010 @Override
2011 public void onChange(boolean selfChange) {
2012 super.onChange(selfChange);
Michael Jurkafff56142012-11-28 16:51:00 -08002013 mDeviceProvisioned = isDeviceProvisionedInSettingsDb();
Jim Millerbbf1a742012-07-17 18:30:30 -07002014 if (mDeviceProvisioned) {
Jim Miller90873d52013-09-26 18:11:38 -07002015 mHandler.sendEmptyMessage(MSG_DEVICE_PROVISIONED);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002016 }
Jim Millerbbf1a742012-07-17 18:30:30 -07002017 if (DEBUG) Log.d(TAG, "DEVICE_PROVISIONED state = " + mDeviceProvisioned);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002018 }
Jim Millerbbf1a742012-07-17 18:30:30 -07002019 };
2020
2021 mContext.getContentResolver().registerContentObserver(
Jeff Brownbf6f6f92012-09-25 15:03:20 -07002022 Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED),
Michael Jurkafff56142012-11-28 16:51:00 -08002023 false, mDeviceProvisionedObserver);
Jim Millerbbf1a742012-07-17 18:30:30 -07002024
2025 // prevent a race condition between where we check the flag and where we register the
2026 // observer by grabbing the value once again...
Michael Jurkafff56142012-11-28 16:51:00 -08002027 boolean provisioned = isDeviceProvisionedInSettingsDb();
Jim Millerbbf1a742012-07-17 18:30:30 -07002028 if (provisioned != mDeviceProvisioned) {
2029 mDeviceProvisioned = provisioned;
2030 if (mDeviceProvisioned) {
Jim Miller90873d52013-09-26 18:11:38 -07002031 mHandler.sendEmptyMessage(MSG_DEVICE_PROVISIONED);
Jim Millerbbf1a742012-07-17 18:30:30 -07002032 }
2033 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002034 }
2035
Jim Millerbbf1a742012-07-17 18:30:30 -07002036 /**
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002037 * Update the state whether Keyguard currently has a lockscreen wallpaper.
2038 *
2039 * @param hasLockscreenWallpaper Whether Keyguard has a lockscreen wallpaper.
2040 */
2041 public void setHasLockscreenWallpaper(boolean hasLockscreenWallpaper) {
Adrian Roos30a2ae62018-04-25 19:09:50 +02002042 checkIsHandlerThread();
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002043 if (hasLockscreenWallpaper != mHasLockscreenWallpaper) {
2044 mHasLockscreenWallpaper = hasLockscreenWallpaper;
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002045 for (int i = 0; i < mCallbacks.size(); i++) {
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002046 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
2047 if (cb != null) {
2048 cb.onHasLockscreenWallpaperChanged(hasLockscreenWallpaper);
2049 }
2050 }
2051 }
2052 }
2053
2054 /**
2055 * @return Whether Keyguard has a lockscreen wallpaper.
2056 */
2057 public boolean hasLockscreenWallpaper() {
2058 return mHasLockscreenWallpaper;
2059 }
2060
2061 /**
Jim Millerbbf1a742012-07-17 18:30:30 -07002062 * Handle {@link #MSG_DPM_STATE_CHANGED}
2063 */
Adrian Roos30a2ae62018-04-25 19:09:50 +02002064 private void handleDevicePolicyManagerStateChanged() {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002065 checkIsHandlerThread();
Adrian Roos733b6632015-08-21 14:32:35 -07002066 updateFingerprintListeningState();
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002067 for (int i = 0; i < mCallbacks.size(); i++) {
Jim Millerdcb3d842012-08-23 19:18:12 -07002068 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
2069 if (cb != null) {
2070 cb.onDevicePolicyManagerStateChanged();
2071 }
Jim Millerb0304762012-03-13 20:01:25 -07002072 }
2073 }
2074
Jim Millerbbf1a742012-07-17 18:30:30 -07002075 /**
Chris Wrenf41c61b2012-11-29 15:19:54 -05002076 * Handle {@link #MSG_USER_SWITCHING}
Jim Millerbbf1a742012-07-17 18:30:30 -07002077 */
Adrian Roos30a2ae62018-04-25 19:09:50 +02002078 private void handleUserSwitching(int userId, IRemoteCallback reply) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002079 checkIsHandlerThread();
Lucas Dupinf2c53502019-10-03 13:56:18 -07002080 mUserTrustIsUsuallyManaged.put(userId, mTrustManager.isTrustUsuallyManaged(userId));
Jim Millerbbf1a742012-07-17 18:30:30 -07002081 for (int i = 0; i < mCallbacks.size(); i++) {
Jim Millerdcb3d842012-08-23 19:18:12 -07002082 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
2083 if (cb != null) {
Chris Wrenf41c61b2012-11-29 15:19:54 -05002084 cb.onUserSwitching(userId);
Jim Millerdcb3d842012-08-23 19:18:12 -07002085 }
Amith Yamasani52c489c2012-03-28 11:42:42 -07002086 }
Dianne Hackborn5dc5a002012-09-15 19:33:48 -07002087 try {
2088 reply.sendResult(null);
2089 } catch (RemoteException e) {
2090 }
Amith Yamasani52c489c2012-03-28 11:42:42 -07002091 }
2092
Jim Millerbbf1a742012-07-17 18:30:30 -07002093 /**
Chris Wrenf41c61b2012-11-29 15:19:54 -05002094 * Handle {@link #MSG_USER_SWITCH_COMPLETE}
2095 */
Adrian Roos30a2ae62018-04-25 19:09:50 +02002096 private void handleUserSwitchComplete(int userId) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002097 checkIsHandlerThread();
Chris Wrenf41c61b2012-11-29 15:19:54 -05002098 for (int i = 0; i < mCallbacks.size(); i++) {
2099 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
2100 if (cb != null) {
2101 cb.onUserSwitchComplete(userId);
2102 }
2103 }
2104 }
2105
2106 /**
Jim Miller90873d52013-09-26 18:11:38 -07002107 * This is exposed since {@link Intent#ACTION_BOOT_COMPLETED} is not sticky. If
2108 * keyguard crashes sometime after boot, then it will never receive this
2109 * broadcast and hence not handle the event. This method is ultimately called by
2110 * PhoneWindowManager in this case.
2111 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002112 public void dispatchBootCompleted() {
Jim Millere5f910a2013-10-16 18:15:46 -07002113 mHandler.sendEmptyMessage(MSG_BOOT_COMPLETED);
Jim Miller90873d52013-09-26 18:11:38 -07002114 }
2115
2116 /**
Adam Cohenefb3ffb2012-11-06 16:55:32 -08002117 * Handle {@link #MSG_BOOT_COMPLETED}
2118 */
Adrian Roos30a2ae62018-04-25 19:09:50 +02002119 private void handleBootCompleted() {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002120 checkIsHandlerThread();
Jim Millere5f910a2013-10-16 18:15:46 -07002121 if (mBootCompleted) return;
Adam Cohen4eb36cf2012-11-07 11:45:30 -08002122 mBootCompleted = true;
Adam Cohenefb3ffb2012-11-06 16:55:32 -08002123 for (int i = 0; i < mCallbacks.size(); i++) {
2124 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
2125 if (cb != null) {
2126 cb.onBootCompleted();
2127 }
2128 }
2129 }
2130
2131 /**
Jim Miller5ecd8112013-01-09 18:50:26 -08002132 * We need to store this state in the KeyguardUpdateMonitor since this class will not be
Adam Cohen4eb36cf2012-11-07 11:45:30 -08002133 * destroyed.
2134 */
2135 public boolean hasBootCompleted() {
2136 return mBootCompleted;
2137 }
2138
2139 /**
Jim Millerbbf1a742012-07-17 18:30:30 -07002140 * Handle {@link #MSG_DEVICE_PROVISIONED}
2141 */
Adrian Roos30a2ae62018-04-25 19:09:50 +02002142 private void handleDeviceProvisioned() {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002143 checkIsHandlerThread();
Jim Millerbbf1a742012-07-17 18:30:30 -07002144 for (int i = 0; i < mCallbacks.size(); i++) {
Jim Millerdcb3d842012-08-23 19:18:12 -07002145 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
2146 if (cb != null) {
2147 cb.onDeviceProvisioned();
2148 }
Nick Pelly24d7b5f2011-10-11 12:51:09 -07002149 }
Michael Jurkafff56142012-11-28 16:51:00 -08002150 if (mDeviceProvisionedObserver != null) {
Nick Pelly24d7b5f2011-10-11 12:51:09 -07002151 // We don't need the observer anymore...
Michael Jurkafff56142012-11-28 16:51:00 -08002152 mContext.getContentResolver().unregisterContentObserver(mDeviceProvisionedObserver);
2153 mDeviceProvisionedObserver = null;
Nick Pelly24d7b5f2011-10-11 12:51:09 -07002154 }
2155 }
2156
Jim Millerbbf1a742012-07-17 18:30:30 -07002157 /**
2158 * Handle {@link #MSG_PHONE_STATE_CHANGED}
2159 */
Adrian Roos30a2ae62018-04-25 19:09:50 +02002160 private void handlePhoneStateChanged(String newState) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002161 checkIsHandlerThread();
Jim Millerc23024d2010-02-24 15:37:00 -08002162 if (DEBUG) Log.d(TAG, "handlePhoneStateChanged(" + newState + ")");
Jim Miller3f5f83b2011-09-26 15:17:05 -07002163 if (TelephonyManager.EXTRA_STATE_IDLE.equals(newState)) {
2164 mPhoneState = TelephonyManager.CALL_STATE_IDLE;
2165 } else if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(newState)) {
2166 mPhoneState = TelephonyManager.CALL_STATE_OFFHOOK;
2167 } else if (TelephonyManager.EXTRA_STATE_RINGING.equals(newState)) {
2168 mPhoneState = TelephonyManager.CALL_STATE_RINGING;
2169 }
Jim Millerbbf1a742012-07-17 18:30:30 -07002170 for (int i = 0; i < mCallbacks.size(); i++) {
Jim Millerdcb3d842012-08-23 19:18:12 -07002171 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
2172 if (cb != null) {
2173 cb.onPhoneStateChanged(mPhoneState);
2174 }
Jim Millerc23024d2010-02-24 15:37:00 -08002175 }
2176 }
2177
Jim Millerbbf1a742012-07-17 18:30:30 -07002178 /**
2179 * Handle {@link #MSG_RINGER_MODE_CHANGED}
2180 */
Adrian Roos30a2ae62018-04-25 19:09:50 +02002181 private void handleRingerModeChange(int mode) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002182 checkIsHandlerThread();
Jim Miller47088bb2009-11-24 00:40:16 -08002183 if (DEBUG) Log.d(TAG, "handleRingerModeChange(" + mode + ")");
Jim Miller3f5f83b2011-09-26 15:17:05 -07002184 mRingMode = mode;
Jim Millerbbf1a742012-07-17 18:30:30 -07002185 for (int i = 0; i < mCallbacks.size(); i++) {
Jim Millerdcb3d842012-08-23 19:18:12 -07002186 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
2187 if (cb != null) {
2188 cb.onRingerModeChanged(mode);
2189 }
Jim Miller47088bb2009-11-24 00:40:16 -08002190 }
2191 }
2192
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002193 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002194 * Handle {@link #MSG_TIME_UPDATE}
2195 */
2196 private void handleTimeUpdate() {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002197 checkIsHandlerThread();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002198 if (DEBUG) Log.d(TAG, "handleTimeUpdate");
Jim Millerbbf1a742012-07-17 18:30:30 -07002199 for (int i = 0; i < mCallbacks.size(); i++) {
Jim Millerdcb3d842012-08-23 19:18:12 -07002200 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
2201 if (cb != null) {
2202 cb.onTimeChanged();
2203 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002204 }
2205 }
2206
2207 /**
Robert Snoeberger9c1074f2018-12-07 17:35:21 -05002208 * Handle (@line #MSG_TIMEZONE_UPDATE}
2209 */
2210 private void handleTimeZoneUpdate(String timeZone) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002211 checkIsHandlerThread();
Robert Snoeberger9c1074f2018-12-07 17:35:21 -05002212 if (DEBUG) Log.d(TAG, "handleTimeZoneUpdate");
2213 for (int i = 0; i < mCallbacks.size(); i++) {
2214 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
2215 if (cb != null) {
2216 cb.onTimeZoneChanged(TimeZone.getTimeZone(timeZone));
2217 // Also notify callbacks about time change to remain compatible.
2218 cb.onTimeChanged();
2219 }
2220 }
2221 }
2222
2223 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002224 * Handle {@link #MSG_BATTERY_UPDATE}
2225 */
Jim Millerbbf1a742012-07-17 18:30:30 -07002226 private void handleBatteryUpdate(BatteryStatus status) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002227 checkIsHandlerThread();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002228 if (DEBUG) Log.d(TAG, "handleBatteryUpdate");
Jim Millerbbf1a742012-07-17 18:30:30 -07002229 final boolean batteryUpdateInteresting = isBatteryUpdateInteresting(mBatteryStatus, status);
2230 mBatteryStatus = status;
Jim Miller16464b82011-10-20 21:10:13 -07002231 if (batteryUpdateInteresting) {
Jim Millerbbf1a742012-07-17 18:30:30 -07002232 for (int i = 0; i < mCallbacks.size(); i++) {
Jim Millerdcb3d842012-08-23 19:18:12 -07002233 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
2234 if (cb != null) {
2235 cb.onRefreshBatteryInfo(status);
2236 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002237 }
2238 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002239 }
2240
2241 /**
Bill Linef81cbd2018-07-05 17:48:49 +08002242 * Handle Telephony status during Boot for CarrierText display policy
2243 */
2244 @VisibleForTesting
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002245 void updateTelephonyCapable(boolean capable) {
2246 checkIsHandlerThread();
Bill Linef81cbd2018-07-05 17:48:49 +08002247 if (capable == mTelephonyCapable) {
2248 return;
2249 }
2250 mTelephonyCapable = capable;
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002251 for (int i = 0; i < mCallbacks.size(); i++) {
2252 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
Bill Linef81cbd2018-07-05 17:48:49 +08002253 if (cb != null) {
2254 cb.onTelephonyCapable(mTelephonyCapable);
2255 }
2256 }
2257 }
2258
2259 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002260 * Handle {@link #MSG_SIM_STATE_CHANGE}
2261 */
Lucas Dupin5e0f0d22018-02-26 13:32:16 -08002262 @VisibleForTesting
Adrian Roos30a2ae62018-04-25 19:09:50 +02002263 void handleSimStateChange(int subId, int slotId, State state) {
2264 checkIsHandlerThread();
Jim Miller52a61332014-11-12 19:29:51 -08002265 if (DEBUG_SIM_STATES) {
2266 Log.d(TAG, "handleSimStateChange(subId=" + subId + ", slotId="
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002267 + slotId + ", state=" + state + ")");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002268 }
2269
Lucas Dupin2e0d4952018-12-05 20:03:53 -08002270 boolean becameAbsent = false;
Wink Savillea54bf652014-12-11 13:37:50 -08002271 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Jim Miller52a61332014-11-12 19:29:51 -08002272 Log.w(TAG, "invalid subId in handleSimStateChange()");
andychou695a7602019-05-16 23:14:00 +08002273 /* Only handle No SIM(ABSENT) and Card Error(CARD_IO_ERROR) due to
2274 * handleServiceStateChange() handle other case */
Bill Linef81cbd2018-07-05 17:48:49 +08002275 if (state == State.ABSENT) {
2276 updateTelephonyCapable(true);
Lucas Dupin2e0d4952018-12-05 20:03:53 -08002277 // Even though the subscription is not valid anymore, we need to notify that the
2278 // SIM card was removed so we can update the UI.
2279 becameAbsent = true;
Brad Ebingere6c6f722018-12-20 21:11:44 -08002280 for (SimData data : mSimDatas.values()) {
2281 // Set the SIM state of all SimData associated with that slot to ABSENT se we
2282 // do not move back into PIN/PUK locked and not detect the change below.
2283 if (data.slotId == slotId) {
2284 data.simState = State.ABSENT;
2285 }
2286 }
andychou695a7602019-05-16 23:14:00 +08002287 } else if (state == State.CARD_IO_ERROR) {
2288 updateTelephonyCapable(true);
Lucas Dupin2e0d4952018-12-05 20:03:53 -08002289 } else {
2290 return;
Bill Linef81cbd2018-07-05 17:48:49 +08002291 }
Jim Miller52a61332014-11-12 19:29:51 -08002292 }
2293
2294 SimData data = mSimDatas.get(subId);
2295 final boolean changed;
2296 if (data == null) {
2297 data = new SimData(state, slotId, subId);
2298 mSimDatas.put(subId, data);
2299 changed = true; // no data yet; force update
2300 } else {
2301 changed = (data.simState != state || data.subId != subId || data.slotId != slotId);
2302 data.simState = state;
2303 data.subId = subId;
2304 data.slotId = slotId;
2305 }
Lucas Dupin2e0d4952018-12-05 20:03:53 -08002306 if ((changed || becameAbsent) && state != State.UNKNOWN) {
Jim Millerbbf1a742012-07-17 18:30:30 -07002307 for (int i = 0; i < mCallbacks.size(); i++) {
Jim Millerdcb3d842012-08-23 19:18:12 -07002308 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
2309 if (cb != null) {
Jim Miller52a61332014-11-12 19:29:51 -08002310 cb.onSimStateChanged(subId, slotId, state);
Jim Millerdcb3d842012-08-23 19:18:12 -07002311 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002312 }
2313 }
2314 }
2315
Jim Millerbbf1a742012-07-17 18:30:30 -07002316 /**
Etan Cohen47051d82015-07-06 16:19:04 -07002317 * Handle {@link #MSG_SERVICE_STATE_CHANGE}
2318 */
Bill Linef81cbd2018-07-05 17:48:49 +08002319 @VisibleForTesting
2320 void handleServiceStateChange(int subId, ServiceState serviceState) {
Etan Cohen47051d82015-07-06 16:19:04 -07002321 if (DEBUG) {
2322 Log.d(TAG,
2323 "handleServiceStateChange(subId=" + subId + ", serviceState=" + serviceState);
2324 }
2325
2326 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2327 Log.w(TAG, "invalid subId in handleServiceStateChange()");
2328 return;
Bill Linef81cbd2018-07-05 17:48:49 +08002329 } else {
2330 updateTelephonyCapable(true);
Etan Cohen47051d82015-07-06 16:19:04 -07002331 }
2332
2333 mServiceStates.put(subId, serviceState);
2334
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002335 callbacksRefreshCarrierInfo();
Etan Cohen47051d82015-07-06 16:19:04 -07002336 }
2337
Lucas Dupinf8463ee2018-06-11 16:18:15 -07002338 public boolean isKeyguardVisible() {
2339 return mKeyguardIsVisible;
2340 }
2341
Etan Cohen47051d82015-07-06 16:19:04 -07002342 /**
Jorim Jaggi6a15d522015-09-22 15:55:33 -07002343 * Notifies that the visibility state of Keyguard has changed.
2344 *
2345 * <p>Needs to be called from the main thread.
Danielle Millettf6d0fc12012-10-23 16:16:52 -04002346 */
Jorim Jaggi6a15d522015-09-22 15:55:33 -07002347 public void onKeyguardVisibilityChanged(boolean showing) {
Adrian Roos30a2ae62018-04-25 19:09:50 +02002348 checkIsHandlerThread();
Kevin Chynb4514d22019-04-15 13:47:25 -07002349 Log.d(TAG, "onKeyguardVisibilityChanged(" + showing + ")");
Jorim Jaggi6a15d522015-09-22 15:55:33 -07002350 mKeyguardIsVisible = showing;
Kevin Chyn6951d3d2019-06-10 14:07:13 -07002351
2352 if (showing) {
2353 mSecureCameraLaunched = false;
2354 }
2355
Danielle Millettf6d0fc12012-10-23 16:16:52 -04002356 for (int i = 0; i < mCallbacks.size(); i++) {
2357 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
2358 if (cb != null) {
Jorim Jaggi6a15d522015-09-22 15:55:33 -07002359 cb.onKeyguardVisibilityChangedRaw(showing);
Danielle Millettf6d0fc12012-10-23 16:16:52 -04002360 }
2361 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +02002362 updateBiometricListeningState();
Danielle Millettf6d0fc12012-10-23 16:16:52 -04002363 }
2364
Brian Colonna7fce3802013-09-17 15:51:32 -04002365 /**
Selim Cinek1fcafc42015-07-20 14:39:25 -07002366 * Handle {@link #MSG_KEYGUARD_RESET}
2367 */
2368 private void handleKeyguardReset() {
2369 if (DEBUG) Log.d(TAG, "handleKeyguardReset");
Gilad Brettercb51b8b2018-03-22 17:04:51 +02002370 updateBiometricListeningState();
Jorim Jaggi031f7952016-09-01 16:39:26 -07002371 mNeedsSlowUnlockTransition = resolveNeedsSlowUnlockTransition();
2372 }
2373
2374 private boolean resolveNeedsSlowUnlockTransition() {
Lucas Dupin6c6d5732019-08-27 17:36:05 -07002375 if (isUserUnlocked(getCurrentUser())) {
Jorim Jaggi031f7952016-09-01 16:39:26 -07002376 return false;
2377 }
2378 Intent homeIntent = new Intent(Intent.ACTION_MAIN)
2379 .addCategory(Intent.CATEGORY_HOME);
2380 ResolveInfo resolveInfo = mContext.getPackageManager().resolveActivity(homeIntent,
2381 0 /* flags */);
2382 return FALLBACK_HOME_COMPONENT.equals(resolveInfo.getComponentInfo().getComponentName());
Selim Cinek1fcafc42015-07-20 14:39:25 -07002383 }
2384
2385 /**
Adrian Roosb6011622014-05-14 15:52:53 +02002386 * Handle {@link #MSG_KEYGUARD_BOUNCER_CHANGED}
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002387 *
Adrian Roosb6011622014-05-14 15:52:53 +02002388 * @see #sendKeyguardBouncerChanged(boolean)
2389 */
2390 private void handleKeyguardBouncerChanged(int bouncer) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002391 checkIsHandlerThread();
Adrian Roosb6011622014-05-14 15:52:53 +02002392 if (DEBUG) Log.d(TAG, "handleKeyguardBouncerChanged(" + bouncer + ")");
2393 boolean isBouncer = (bouncer == 1);
2394 mBouncer = isBouncer;
Kevin Chynd0381892019-07-11 16:25:36 -07002395
2396 if (isBouncer) {
2397 // If the bouncer is shown, always clear this flag. This can happen in the following
2398 // situations: 1) Default camera with SHOW_WHEN_LOCKED is not chosen yet. 2) Secure
2399 // camera requests dismiss keyguard (tapping on photos for example). When these happen,
2400 // face auth should resume.
2401 mSecureCameraLaunched = false;
2402 }
2403
Adrian Roosb6011622014-05-14 15:52:53 +02002404 for (int i = 0; i < mCallbacks.size(); i++) {
2405 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
2406 if (cb != null) {
2407 cb.onKeyguardBouncerChanged(isBouncer);
2408 }
2409 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +02002410 updateBiometricListeningState();
Adrian Roosb6011622014-05-14 15:52:53 +02002411 }
2412
2413 /**
Brian Colonna7fce3802013-09-17 15:51:32 -04002414 * Handle {@link #MSG_REPORT_EMERGENCY_CALL_ACTION}
2415 */
2416 private void handleReportEmergencyCallAction() {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002417 checkIsHandlerThread();
Brian Colonna7fce3802013-09-17 15:51:32 -04002418 for (int i = 0; i < mCallbacks.size(); i++) {
2419 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
2420 if (cb != null) {
2421 cb.onEmergencyCallAction();
2422 }
2423 }
2424 }
2425
Lucas Dupin4272f442018-01-13 22:00:35 -08002426 private boolean isBatteryUpdateInteresting(BatteryStatus old, BatteryStatus current) {
Jim Millerbbf1a742012-07-17 18:30:30 -07002427 final boolean nowPluggedIn = current.isPluggedIn();
2428 final boolean wasPluggedIn = old.isPluggedIn();
Lucas Dupin4272f442018-01-13 22:00:35 -08002429 final boolean stateChangedWhilePluggedIn = wasPluggedIn && nowPluggedIn
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002430 && (old.status != current.status);
Jim Miller16464b82011-10-20 21:10:13 -07002431
2432 // change in plug state is always interesting
2433 if (wasPluggedIn != nowPluggedIn || stateChangedWhilePluggedIn) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002434 return true;
2435 }
2436
Lucas Dupin3fcdd472018-01-19 19:06:45 -08002437 // change in battery level
2438 if (old.level != current.level) {
Jim Miller16464b82011-10-20 21:10:13 -07002439 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002440 }
Adrian Roos76dc5a52015-07-21 16:20:36 -07002441
2442 // change in charging current while plugged in
Adrian Roos0c859ae2015-11-23 16:47:50 -08002443 if (nowPluggedIn && current.maxChargingWattage != old.maxChargingWattage) {
Adrian Roos76dc5a52015-07-21 16:20:36 -07002444 return true;
2445 }
2446
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002447 return false;
2448 }
2449
2450 /**
Jim Millerbbf1a742012-07-17 18:30:30 -07002451 * Remove the given observer's callback.
2452 *
Jim Miller6212cc02012-09-05 17:35:31 -07002453 * @param callback The callback to remove
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002454 */
Jim Miller6212cc02012-09-05 17:35:31 -07002455 public void removeCallback(KeyguardUpdateMonitorCallback callback) {
Adrian Roos30a2ae62018-04-25 19:09:50 +02002456 checkIsHandlerThread();
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002457 if (DEBUG) {
2458 Log.v(TAG, "*** unregister callback for " + callback);
Jim Miller6212cc02012-09-05 17:35:31 -07002459 }
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002460
2461 mCallbacks.removeIf(el -> el.get() == callback);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002462 }
2463
2464 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002465 * Register to receive notifications about general keyguard information
2466 * (see {@link InfoCallback}.
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002467 *
Jim Miller6212cc02012-09-05 17:35:31 -07002468 * @param callback The callback to register
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002469 */
Jim Millerbbf1a742012-07-17 18:30:30 -07002470 public void registerCallback(KeyguardUpdateMonitorCallback callback) {
Adrian Roos30a2ae62018-04-25 19:09:50 +02002471 checkIsHandlerThread();
Jim Miller6212cc02012-09-05 17:35:31 -07002472 if (DEBUG) Log.v(TAG, "*** register callback for " + callback);
2473 // Prevent adding duplicate callbacks
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002474
Jim Miller6212cc02012-09-05 17:35:31 -07002475 for (int i = 0; i < mCallbacks.size(); i++) {
2476 if (mCallbacks.get(i).get() == callback) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002477 if (DEBUG) {
2478 Log.e(TAG, "Object tried to add another callback",
2479 new Exception("Called by"));
2480 }
Jim Miller6212cc02012-09-05 17:35:31 -07002481 return;
Jim Millerdcb3d842012-08-23 19:18:12 -07002482 }
2483 }
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002484 mCallbacks.add(new WeakReference<>(callback));
Jim Miller6212cc02012-09-05 17:35:31 -07002485 removeCallback(null); // remove unused references
2486 sendUpdates(callback);
2487 }
2488
Lucas Dupin9e484aa2019-06-24 13:38:00 -07002489 public void setKeyguardBypassController(KeyguardBypassController keyguardBypassController) {
2490 mKeyguardBypassController = keyguardBypassController;
2491 }
2492
Lucas Dupinc12fad32019-05-14 20:59:17 +00002493 public boolean isSwitchingUser() {
2494 return mSwitchingUser;
2495 }
2496
Adrian Roos30a2ae62018-04-25 19:09:50 +02002497 @AnyThread
Evan Rosky18396452016-07-27 15:19:37 -07002498 public void setSwitchingUser(boolean switching) {
Lucas Dupinc12fad32019-05-14 20:59:17 +00002499 mSwitchingUser = switching;
Selim Cinekbbe19242017-12-08 15:42:08 -08002500 // Since this comes in on a binder thread, we need to post if first
Gilad Brettercb51b8b2018-03-22 17:04:51 +02002501 mHandler.post(mUpdateBiometricListeningState);
Evan Rosky18396452016-07-27 15:19:37 -07002502 }
2503
Jim Miller6212cc02012-09-05 17:35:31 -07002504 private void sendUpdates(KeyguardUpdateMonitorCallback callback) {
2505 // Notify listener of the current state
2506 callback.onRefreshBatteryInfo(mBatteryStatus);
2507 callback.onTimeChanged();
2508 callback.onRingerModeChanged(mRingMode);
2509 callback.onPhoneStateChanged(mPhoneState);
Jason Monk9ff69bd2014-12-02 16:43:17 -05002510 callback.onRefreshCarrierInfo();
Jim Miller6212cc02012-09-05 17:35:31 -07002511 callback.onClockVisibilityChanged();
Lucas Dupin16cfe452018-02-08 13:14:50 -08002512 callback.onKeyguardVisibilityChangedRaw(mKeyguardIsVisible);
Bill Linef81cbd2018-07-05 17:48:49 +08002513 callback.onTelephonyCapable(mTelephonyCapable);
Jim Miller52a61332014-11-12 19:29:51 -08002514 for (Entry<Integer, SimData> data : mSimDatas.entrySet()) {
2515 final SimData state = data.getValue();
2516 callback.onSimStateChanged(state.subId, state.slotId, state.simState);
2517 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002518 }
2519
Selim Cinek1fcafc42015-07-20 14:39:25 -07002520 public void sendKeyguardReset() {
2521 mHandler.obtainMessage(MSG_KEYGUARD_RESET).sendToTarget();
2522 }
2523
Adrian Roosb6011622014-05-14 15:52:53 +02002524 /**
2525 * @see #handleKeyguardBouncerChanged(int)
2526 */
2527 public void sendKeyguardBouncerChanged(boolean showingBouncer) {
2528 if (DEBUG) Log.d(TAG, "sendKeyguardBouncerChanged(" + showingBouncer + ")");
2529 Message message = mHandler.obtainMessage(MSG_KEYGUARD_BOUNCER_CHANGED);
2530 message.arg1 = showingBouncer ? 1 : 0;
2531 message.sendToTarget();
2532 }
2533
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002534 /**
Jim Miller90d5d462011-11-17 16:57:01 -08002535 * Report that the user successfully entered the SIM PIN or PUK/SIM PIN so we
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002536 * have the information earlier than waiting for the intent
2537 * broadcast from the telephony code.
Jim Miller90d5d462011-11-17 16:57:01 -08002538 *
2539 * NOTE: Because handleSimStateChange() invokes callbacks immediately without going
2540 * through mHandler, this *must* be called from the UI thread.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002541 */
Adrian Roos30a2ae62018-04-25 19:09:50 +02002542 @MainThread
Jim Miller52a61332014-11-12 19:29:51 -08002543 public void reportSimUnlocked(int subId) {
2544 if (DEBUG_SIM_STATES) Log.v(TAG, "reportSimUnlocked(subId=" + subId + ")");
Lucas Dupin10960bd2019-09-27 16:08:32 -07002545 handleSimStateChange(subId, getSlotId(subId), State.READY);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002546 }
2547
Brian Colonna7fce3802013-09-17 15:51:32 -04002548 /**
2549 * Report that the emergency call button has been pressed and the emergency dialer is
2550 * about to be displayed.
2551 *
2552 * @param bypassHandler runs immediately.
2553 *
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002554 * NOTE: Must be called from UI thread if bypassHandler == true.
Brian Colonna7fce3802013-09-17 15:51:32 -04002555 */
2556 public void reportEmergencyCallAction(boolean bypassHandler) {
2557 if (!bypassHandler) {
2558 mHandler.obtainMessage(MSG_REPORT_EMERGENCY_CALL_ACTION).sendToTarget();
2559 } else {
Adrian Roos30a2ae62018-04-25 19:09:50 +02002560 checkIsHandlerThread();
Brian Colonna7fce3802013-09-17 15:51:32 -04002561 handleReportEmergencyCallAction();
2562 }
2563 }
2564
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002565 /**
2566 * @return Whether the device is provisioned (whether they have gone through
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002567 * the setup wizard)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002568 */
2569 public boolean isDeviceProvisioned() {
2570 return mDeviceProvisioned;
2571 }
2572
Kensuke Matsui21d1bf12017-03-14 13:27:20 +09002573 public ServiceState getServiceState(int subId) {
2574 return mServiceStates.get(subId);
2575 }
2576
Gilad Brettercb51b8b2018-03-22 17:04:51 +02002577 public void clearBiometricRecognized() {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002578 checkIsHandlerThread();
Jim Miller9f0753f2015-03-23 23:59:22 -07002579 mUserFingerprintAuthenticated.clear();
Gilad Brettercb51b8b2018-03-22 17:04:51 +02002580 mUserFaceAuthenticated.clear();
2581 mTrustManager.clearAllBiometricRecognized(BiometricSourceType.FINGERPRINT);
2582 mTrustManager.clearAllBiometricRecognized(BiometricSourceType.FACE);
Aran Ink4c0d5602019-06-21 14:27:32 -04002583
2584 for (int i = 0; i < mCallbacks.size(); i++) {
2585 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
2586 if (cb != null) {
2587 cb.onBiometricsCleared();
2588 }
2589 }
Jim Millerf41fc962014-06-18 16:33:51 -07002590 }
2591
Jim Miller52a61332014-11-12 19:29:51 -08002592 public boolean isSimPinVoiceSecure() {
2593 // TODO: only count SIMs that handle voice
2594 return isSimPinSecure();
Jim Millerdcb3d842012-08-23 19:18:12 -07002595 }
2596
Lucas Dupin7156bc72019-05-03 19:37:39 -07002597 /**
2598 * If any SIM cards are currently secure.
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002599 *
Lucas Dupin7156bc72019-05-03 19:37:39 -07002600 * @see #isSimPinSecure(State)
2601 */
Jim Millerdcb3d842012-08-23 19:18:12 -07002602 public boolean isSimPinSecure() {
Jim Miller52a61332014-11-12 19:29:51 -08002603 // True if any SIM is pin secure
2604 for (SubscriptionInfo info : getSubscriptionInfo(false /* forceReload */)) {
2605 if (isSimPinSecure(getSimState(info.getSubscriptionId()))) return true;
2606 }
2607 return false;
2608 }
2609
Jason Monk9ff69bd2014-12-02 16:43:17 -05002610 public State getSimState(int subId) {
Jim Miller52a61332014-11-12 19:29:51 -08002611 if (mSimDatas.containsKey(subId)) {
2612 return mSimDatas.get(subId).simState;
2613 } else {
2614 return State.UNKNOWN;
2615 }
2616 }
2617
Lucas Dupin10960bd2019-09-27 16:08:32 -07002618 private int getSlotId(int subId) {
2619 if (!mSimDatas.containsKey(subId)) {
2620 refreshSimState(subId, SubscriptionManager.getSlotIndex(subId));
2621 }
2622 return mSimDatas.get(subId).slotId;
2623 }
2624
Winson Chung67f5c8b2018-09-24 12:09:19 -07002625 private final TaskStackChangeListener
2626 mTaskStackListener = new TaskStackChangeListener() {
Kevin Chyn2fefd462017-04-28 12:18:19 -07002627 @Override
2628 public void onTaskStackChangedBackground() {
2629 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07002630 ActivityManager.StackInfo info = ActivityTaskManager.getService().getStackInfo(
Wale Ogunwale68278562017-09-23 17:13:55 -07002631 WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_ASSISTANT);
Kevin Chyn2fefd462017-04-28 12:18:19 -07002632 if (info == null) {
2633 return;
2634 }
2635 mHandler.sendMessage(mHandler.obtainMessage(MSG_ASSISTANT_STACK_CHANGED,
2636 info.visible));
2637 } catch (RemoteException e) {
2638 Log.e(TAG, "unable to check task stack", e);
2639 }
2640 }
2641 };
2642
Jorim Jaggi01ba98b2015-01-13 21:33:45 +01002643 /**
Richard Choue0381b82018-04-24 03:48:59 +00002644 * @return true if and only if the state has changed for the specified {@code slotId}
Jorim Jaggi01ba98b2015-01-13 21:33:45 +01002645 */
Richard Choue0381b82018-04-24 03:48:59 +00002646 private boolean refreshSimState(int subId, int slotId) {
Jim Miller52a61332014-11-12 19:29:51 -08002647
2648 // This is awful. It exists because there are two APIs for getting the SIM status
2649 // that don't return the complete set of values and have different types. In Keyguard we
2650 // need IccCardConstants, but TelephonyManager would only give us
2651 // TelephonyManager.SIM_STATE*, so we retrieve it manually.
xinhe18b9c3c2014-12-02 15:03:20 -08002652 final TelephonyManager tele = TelephonyManager.from(mContext);
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002653 int simState = tele.getSimState(slotId);
Richard Choue0381b82018-04-24 03:48:59 +00002654 State state;
2655 try {
2656 state = State.intToState(simState);
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002657 } catch (IllegalArgumentException ex) {
Richard Choue0381b82018-04-24 03:48:59 +00002658 Log.w(TAG, "Unknown sim state: " + simState);
2659 state = State.UNKNOWN;
John Spurlock5b13e922015-01-07 11:04:58 -05002660 }
Richard Choue0381b82018-04-24 03:48:59 +00002661 SimData data = mSimDatas.get(subId);
2662 final boolean changed;
2663 if (data == null) {
2664 data = new SimData(state, slotId, subId);
2665 mSimDatas.put(subId, data);
2666 changed = true; // no data yet; force update
2667 } else {
2668 changed = data.simState != state;
2669 data.simState = state;
Jorim Jaggi01ba98b2015-01-13 21:33:45 +01002670 }
Richard Choue0381b82018-04-24 03:48:59 +00002671 return changed;
Jim Millerdcb3d842012-08-23 19:18:12 -07002672 }
2673
Lucas Dupin7156bc72019-05-03 19:37:39 -07002674 /**
2675 * If the {@code state} is currently requiring a SIM PIN, PUK, or is disabled.
2676 */
Jim Millerdcb3d842012-08-23 19:18:12 -07002677 public static boolean isSimPinSecure(IccCardConstants.State state) {
Lucas Dupin7156bc72019-05-03 19:37:39 -07002678 return (state == IccCardConstants.State.PIN_REQUIRED
2679 || state == IccCardConstants.State.PUK_REQUIRED
2680 || state == IccCardConstants.State.PERM_DISABLED);
Jim Millerb0304762012-03-13 20:01:25 -07002681 }
Jim Miller8f09fd22013-03-14 19:04:28 -07002682
2683 public DisplayClientState getCachedDisplayClientState() {
2684 return mDisplayClientState;
2685 }
Jim Miller20daffd2013-10-07 14:59:53 -07002686
2687 // TODO: use these callbacks elsewhere in place of the existing notifyScreen*()
2688 // (KeyguardViewMediator, KeyguardHostView)
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002689 public void dispatchStartedWakingUp() {
2690 synchronized (this) {
2691 mDeviceInteractive = true;
2692 }
2693 mHandler.sendEmptyMessage(MSG_STARTED_WAKING_UP);
2694 }
2695
Jorim Jaggi95e40382015-09-16 15:53:42 -07002696 public void dispatchStartedGoingToSleep(int why) {
2697 mHandler.sendMessage(mHandler.obtainMessage(MSG_STARTED_GOING_TO_SLEEP, why, 0));
2698 }
2699
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002700 public void dispatchFinishedGoingToSleep(int why) {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002701 synchronized (this) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002702 mDeviceInteractive = false;
2703 }
2704 mHandler.sendMessage(mHandler.obtainMessage(MSG_FINISHED_GOING_TO_SLEEP, why, 0));
2705 }
2706
Jim Miller20daffd2013-10-07 14:59:53 -07002707 public void dispatchScreenTurnedOn() {
2708 synchronized (this) {
2709 mScreenOn = true;
2710 }
Jorim Jaggif1518da2015-07-30 11:56:36 -07002711 mHandler.sendEmptyMessage(MSG_SCREEN_TURNED_ON);
Jim Miller20daffd2013-10-07 14:59:53 -07002712 }
2713
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002714 public void dispatchScreenTurnedOff() {
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002715 synchronized (this) {
Jim Miller20daffd2013-10-07 14:59:53 -07002716 mScreenOn = false;
2717 }
Jorim Jaggif1518da2015-07-30 11:56:36 -07002718 mHandler.sendEmptyMessage(MSG_SCREEN_TURNED_OFF);
Jim Miller20daffd2013-10-07 14:59:53 -07002719 }
2720
Selim Cinek99415392016-09-09 14:58:41 -07002721 public void dispatchDreamingStarted() {
2722 mHandler.sendMessage(mHandler.obtainMessage(MSG_DREAMING_STATE_CHANGED, 1, 0));
2723 }
2724
2725 public void dispatchDreamingStopped() {
2726 mHandler.sendMessage(mHandler.obtainMessage(MSG_DREAMING_STATE_CHANGED, 0, 0));
2727 }
2728
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002729 public boolean isDeviceInteractive() {
2730 return mDeviceInteractive;
Jim Miller20daffd2013-10-07 14:59:53 -07002731 }
Jim Miller52a61332014-11-12 19:29:51 -08002732
Jorim Jaggi95e40382015-09-16 15:53:42 -07002733 public boolean isGoingToSleep() {
2734 return mGoingToSleep;
2735 }
2736
Jim Miller52a61332014-11-12 19:29:51 -08002737 /**
2738 * Find the next SubscriptionId for a SIM in the given state, favoring lower slot numbers first.
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002739 *
Wink Savilled09c4ca2014-11-22 10:08:16 -08002740 * @return subid or {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} if none found
Jim Miller52a61332014-11-12 19:29:51 -08002741 */
2742 public int getNextSubIdForState(State state) {
2743 List<SubscriptionInfo> list = getSubscriptionInfo(false /* forceReload */);
Wink Savilled09c4ca2014-11-22 10:08:16 -08002744 int resultId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Jim Miller52a61332014-11-12 19:29:51 -08002745 int bestSlotId = Integer.MAX_VALUE; // Favor lowest slot first
2746 for (int i = 0; i < list.size(); i++) {
2747 final SubscriptionInfo info = list.get(i);
2748 final int id = info.getSubscriptionId();
Lucas Dupin10960bd2019-09-27 16:08:32 -07002749 int slotId = getSlotId(id);
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002750 if (state == getSimState(id) && bestSlotId > slotId) {
Jim Miller52a61332014-11-12 19:29:51 -08002751 resultId = id;
2752 bestSlotId = slotId;
2753 }
2754 }
2755 return resultId;
2756 }
2757
2758 public SubscriptionInfo getSubscriptionInfoForSubId(int subId) {
2759 List<SubscriptionInfo> list = getSubscriptionInfo(false /* forceReload */);
2760 for (int i = 0; i < list.size(); i++) {
2761 SubscriptionInfo info = list.get(i);
2762 if (subId == info.getSubscriptionId()) return info;
2763 }
2764 return null; // not found
2765 }
Jason Monkab525272015-07-13 17:02:49 -04002766
Alex Chauff7653d2018-02-01 17:18:08 +00002767 /**
2768 * @return a cached version of DevicePolicyManager.isLogoutEnabled()
2769 */
2770 public boolean isLogoutEnabled() {
2771 return mLogoutEnabled;
2772 }
2773
2774 private void updateLogoutEnabled() {
Adrian Roos30a2ae62018-04-25 19:09:50 +02002775 checkIsHandlerThread();
Alex Chauff7653d2018-02-01 17:18:08 +00002776 boolean logoutEnabled = mDevicePolicyManager.isLogoutEnabled();
2777 if (mLogoutEnabled != logoutEnabled) {
2778 mLogoutEnabled = logoutEnabled;
Dave Mankoff4b0ab652019-08-07 09:49:20 -04002779
Alex Chauff7653d2018-02-01 17:18:08 +00002780 for (int i = 0; i < mCallbacks.size(); i++) {
2781 KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
2782 if (cb != null) {
2783 cb.onLogoutEnabledChanged();
2784 }
2785 }
2786 }
2787 }
2788
Adrian Roos30a2ae62018-04-25 19:09:50 +02002789 private void checkIsHandlerThread() {
Adrian Roos30a2ae62018-04-25 19:09:50 +02002790 if (!mHandler.getLooper().isCurrentThread()) {
Dave Mankoff898e1bb2019-09-25 17:54:19 -04002791 Log.wtfStack(TAG, "must call on mHandler's thread "
Adrian Roos30a2ae62018-04-25 19:09:50 +02002792 + mHandler.getLooper().getThread() + ", not " + Thread.currentThread());
2793 }
2794 }
2795
Lucas Dupin64171fe2019-10-30 14:28:29 -07002796 @Override
Jason Monkab525272015-07-13 17:02:49 -04002797 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
2798 pw.println("KeyguardUpdateMonitor state:");
2799 pw.println(" SIM States:");
2800 for (SimData data : mSimDatas.values()) {
2801 pw.println(" " + data.toString());
2802 }
2803 pw.println(" Subs:");
2804 if (mSubscriptionInfo != null) {
2805 for (int i = 0; i < mSubscriptionInfo.size(); i++) {
2806 pw.println(" " + mSubscriptionInfo.get(i));
2807 }
2808 }
Malcolm Chen5c63b512019-08-13 13:24:07 -07002809 pw.println(" Current active data subId=" + mActiveMobileDataSubscription);
Jason Monkab525272015-07-13 17:02:49 -04002810 pw.println(" Service states:");
2811 for (int subId : mServiceStates.keySet()) {
2812 pw.println(" " + subId + "=" + mServiceStates.get(subId));
2813 }
Jim Millerd72d5ac2015-09-29 18:55:32 -07002814 if (mFpm != null && mFpm.isHardwareDetected()) {
2815 final int userId = ActivityManager.getCurrentUser();
2816 final int strongAuthFlags = mStrongAuthTracker.getStrongAuthForUser(userId);
2817 pw.println(" Fingerprint state (user=" + userId + ")");
Gilad Brettercb51b8b2018-03-22 17:04:51 +02002818 pw.println(" allowed=" + isUnlockingWithBiometricAllowed());
Jim Millerd72d5ac2015-09-29 18:55:32 -07002819 pw.println(" auth'd=" + mUserFingerprintAuthenticated.get(userId));
2820 pw.println(" authSinceBoot="
2821 + getStrongAuthTracker().hasUserAuthenticatedSinceBoot());
2822 pw.println(" disabled(DPM)=" + isFingerprintDisabled(userId));
2823 pw.println(" possible=" + isUnlockWithFingerprintPossible(userId));
Adrian Roos2aaf9442018-11-20 16:57:33 +01002824 pw.println(" listening: actual=" + mFingerprintRunningState
2825 + " expected=" + (shouldListenForFingerprint() ? 1 : 0));
Jim Millerd72d5ac2015-09-29 18:55:32 -07002826 pw.println(" strongAuthFlags=" + Integer.toHexString(strongAuthFlags));
Jim Millerd72d5ac2015-09-29 18:55:32 -07002827 pw.println(" trustManaged=" + getUserTrustIsManaged(userId));
2828 }
Kevin Chynb7b54a62018-09-28 18:48:12 -07002829 if (mFaceManager != null && mFaceManager.isHardwareDetected()) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +02002830 final int userId = ActivityManager.getCurrentUser();
2831 final int strongAuthFlags = mStrongAuthTracker.getStrongAuthForUser(userId);
2832 pw.println(" Face authentication state (user=" + userId + ")");
2833 pw.println(" allowed=" + isUnlockingWithBiometricAllowed());
2834 pw.println(" auth'd=" + mUserFaceAuthenticated.get(userId));
2835 pw.println(" authSinceBoot="
2836 + getStrongAuthTracker().hasUserAuthenticatedSinceBoot());
2837 pw.println(" disabled(DPM)=" + isFaceDisabled(userId));
2838 pw.println(" possible=" + isUnlockWithFacePossible(userId));
2839 pw.println(" strongAuthFlags=" + Integer.toHexString(strongAuthFlags));
2840 pw.println(" trustManaged=" + getUserTrustIsManaged(userId));
Lucas Dupin7d95f152019-07-17 16:25:54 -07002841 pw.println(" enabledByUser=" + mFaceSettingEnabledForUser.get(userId));
Kevin Chynd0381892019-07-11 16:25:36 -07002842 pw.println(" mSecureCameraLaunched=" + mSecureCameraLaunched);
Gilad Brettercb51b8b2018-03-22 17:04:51 +02002843 }
Jason Monkab525272015-07-13 17:02:49 -04002844 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002845}