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