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