Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
| 17 | package com.android.systemui.statusbar; |
| 18 | |
Beverly | 8c78589 | 2018-01-31 17:25:52 -0500 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 21 | import android.app.admin.DevicePolicyManager; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 22 | import android.content.Context; |
Jason Chang | 2386a37 | 2018-04-24 16:05:30 +0800 | [diff] [blame] | 23 | import android.content.res.ColorStateList; |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 24 | import android.content.res.Resources; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 25 | import android.graphics.Color; |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 26 | import android.hardware.biometrics.BiometricSourceType; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 27 | import android.hardware.face.FaceManager; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 28 | import android.hardware.fingerprint.FingerprintManager; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 29 | import android.os.BatteryManager; |
| 30 | import android.os.BatteryStats; |
| 31 | import android.os.Handler; |
| 32 | import android.os.Message; |
| 33 | import android.os.RemoteException; |
| 34 | import android.os.ServiceManager; |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 35 | import android.os.UserManager; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 36 | import android.text.TextUtils; |
| 37 | import android.text.format.Formatter; |
| 38 | import android.util.Log; |
| 39 | import android.view.View; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 40 | import android.view.ViewGroup; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 41 | |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 42 | import com.android.internal.annotations.VisibleForTesting; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 43 | import com.android.internal.app.IBatteryStats; |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 44 | import com.android.internal.logging.nano.MetricsProto; |
| 45 | import com.android.internal.widget.LockPatternUtils; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 46 | import com.android.keyguard.KeyguardUpdateMonitor; |
| 47 | import com.android.keyguard.KeyguardUpdateMonitorCallback; |
Jason Monk | 58be7a6 | 2017-02-01 20:17:51 -0500 | [diff] [blame] | 48 | import com.android.settingslib.Utils; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 49 | import com.android.systemui.Dependency; |
Beverly | 8c78589 | 2018-01-31 17:25:52 -0500 | [diff] [blame] | 50 | import com.android.systemui.Interpolators; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 51 | import com.android.systemui.R; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 52 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
| 53 | import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 54 | import com.android.systemui.statusbar.phone.KeyguardIndicationTextView; |
| 55 | import com.android.systemui.statusbar.phone.LockIcon; |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 56 | import com.android.systemui.statusbar.phone.LockscreenGestureLogger; |
Lucas Dupin | 0df60fe | 2019-04-23 10:19:27 -0700 | [diff] [blame] | 57 | import com.android.systemui.statusbar.phone.ShadeController; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 58 | import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 59 | import com.android.systemui.statusbar.phone.UnlockMethodCache; |
Lucas Dupin | 0df60fe | 2019-04-23 10:19:27 -0700 | [diff] [blame] | 60 | import com.android.systemui.statusbar.policy.AccessibilityController; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 61 | import com.android.systemui.statusbar.policy.UserInfoController; |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 62 | import com.android.systemui.util.wakelock.SettableWakeLock; |
| 63 | import com.android.systemui.util.wakelock.WakeLock; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 64 | |
Lucas Dupin | 3fcdd47 | 2018-01-19 19:06:45 -0800 | [diff] [blame] | 65 | import java.io.FileDescriptor; |
| 66 | import java.io.PrintWriter; |
Lucas Dupin | 4272f44 | 2018-01-13 22:00:35 -0800 | [diff] [blame] | 67 | import java.text.NumberFormat; |
Lucas Dupin | 8d595d2 | 2018-03-08 10:34:58 -0800 | [diff] [blame] | 68 | import java.util.IllegalFormatConversionException; |
Lucas Dupin | 4272f44 | 2018-01-13 22:00:35 -0800 | [diff] [blame] | 69 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 70 | /** |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 71 | * Controls the indications and error messages shown on the Keyguard |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 72 | */ |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 73 | public class KeyguardIndicationController implements StateListener, |
| 74 | UnlockMethodCache.OnUnlockMethodChangedListener { |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 75 | |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 76 | private static final String TAG = "KeyguardIndication"; |
| 77 | private static final boolean DEBUG_CHARGING_SPEED = false; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 78 | |
| 79 | private static final int MSG_HIDE_TRANSIENT = 1; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 80 | private static final int MSG_CLEAR_BIOMETRIC_MSG = 2; |
| 81 | private static final long TRANSIENT_BIOMETRIC_ERROR_TIMEOUT = 1300; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 82 | |
| 83 | private final Context mContext; |
Lucas Dupin | 0df60fe | 2019-04-23 10:19:27 -0700 | [diff] [blame] | 84 | private final ShadeController mShadeController; |
| 85 | private final AccessibilityController mAccessibilityController; |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 86 | private final UnlockMethodCache mUnlockMethodCache; |
| 87 | private final StatusBarStateController mStatusBarStateController; |
| 88 | private final KeyguardUpdateMonitor mKeyguardUpdateMonitor; |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 89 | private ViewGroup mIndicationArea; |
| 90 | private KeyguardIndicationTextView mTextView; |
| 91 | private KeyguardIndicationTextView mDisclosure; |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 92 | private final UserManager mUserManager; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 93 | private final IBatteryStats mBatteryInfo; |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 94 | private final SettableWakeLock mWakeLock; |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 95 | private final LockPatternUtils mLockPatternUtils; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 96 | |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 97 | private final int mSlowThreshold; |
| 98 | private final int mFastThreshold; |
Lucas Dupin | 0590465 | 2019-04-09 16:16:15 -0700 | [diff] [blame] | 99 | private final LockIcon mLockIcon; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 100 | private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 101 | private LockscreenGestureLogger mLockscreenGestureLogger = new LockscreenGestureLogger(); |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 102 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 103 | private String mRestingIndication; |
Lucas Dupin | ef88654 | 2018-01-03 16:03:07 -0800 | [diff] [blame] | 104 | private CharSequence mTransientIndication; |
Jason Chang | 2386a37 | 2018-04-24 16:05:30 +0800 | [diff] [blame] | 105 | private ColorStateList mTransientTextColorState; |
| 106 | private ColorStateList mInitialTextColorState; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 107 | private boolean mVisible; |
| 108 | |
| 109 | private boolean mPowerPluggedIn; |
Beverly | 2034c83 | 2018-03-19 11:18:51 -0400 | [diff] [blame] | 110 | private boolean mPowerPluggedInWired; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 111 | private boolean mPowerCharged; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 112 | private int mChargingSpeed; |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 113 | private int mChargingWattage; |
Lucas Dupin | 4272f44 | 2018-01-13 22:00:35 -0800 | [diff] [blame] | 114 | private int mBatteryLevel; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 115 | private String mMessageToShowOnScreenOn; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 116 | |
Zachary Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 117 | private KeyguardUpdateMonitorCallback mUpdateMonitorCallback; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 118 | |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 119 | private final DevicePolicyManager mDevicePolicyManager; |
Adrian Roos | 91ba307 | 2017-02-14 16:50:46 +0100 | [diff] [blame] | 120 | private boolean mDozing; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 121 | |
Adrian Roos | af45b60 | 2017-03-14 13:10:25 -0700 | [diff] [blame] | 122 | /** |
| 123 | * Creates a new KeyguardIndicationController and registers callbacks. |
| 124 | */ |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 125 | public KeyguardIndicationController(Context context, ViewGroup indicationArea, |
| 126 | LockIcon lockIcon) { |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 127 | this(context, indicationArea, lockIcon, new LockPatternUtils(context), |
Lucas Dupin | 0df60fe | 2019-04-23 10:19:27 -0700 | [diff] [blame] | 128 | WakeLock.createPartial(context, "Doze:KeyguardIndication"), |
| 129 | Dependency.get(ShadeController.class), |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 130 | Dependency.get(AccessibilityController.class), |
| 131 | UnlockMethodCache.getInstance(context), |
| 132 | Dependency.get(StatusBarStateController.class), |
| 133 | KeyguardUpdateMonitor.getInstance(context)); |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 134 | } |
| 135 | |
Adrian Roos | af45b60 | 2017-03-14 13:10:25 -0700 | [diff] [blame] | 136 | /** |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 137 | * Creates a new KeyguardIndicationController for testing. |
Adrian Roos | af45b60 | 2017-03-14 13:10:25 -0700 | [diff] [blame] | 138 | */ |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 139 | @VisibleForTesting |
| 140 | KeyguardIndicationController(Context context, ViewGroup indicationArea, LockIcon lockIcon, |
Lucas Dupin | 0df60fe | 2019-04-23 10:19:27 -0700 | [diff] [blame] | 141 | LockPatternUtils lockPatternUtils, WakeLock wakeLock, ShadeController shadeController, |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 142 | AccessibilityController accessibilityController, UnlockMethodCache unlockMethodCache, |
| 143 | StatusBarStateController statusBarStateController, |
| 144 | KeyguardUpdateMonitor keyguardUpdateMonitor) { |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 145 | mContext = context; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 146 | mLockIcon = lockIcon; |
Lucas Dupin | 0df60fe | 2019-04-23 10:19:27 -0700 | [diff] [blame] | 147 | mShadeController = shadeController; |
| 148 | mAccessibilityController = accessibilityController; |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 149 | mUnlockMethodCache = unlockMethodCache; |
| 150 | mStatusBarStateController = statusBarStateController; |
| 151 | mKeyguardUpdateMonitor = keyguardUpdateMonitor; |
Brad Stenning | 691c274 | 2019-04-19 11:48:00 -0700 | [diff] [blame] | 152 | // lock icon is not used on all form factors. |
| 153 | if (mLockIcon != null) { |
Lucas Dupin | 0df60fe | 2019-04-23 10:19:27 -0700 | [diff] [blame] | 154 | mLockIcon.setOnLongClickListener(this::handleLockLongClick); |
| 155 | mLockIcon.setOnClickListener(this::handleLockClick); |
Brad Stenning | 691c274 | 2019-04-19 11:48:00 -0700 | [diff] [blame] | 156 | } |
Lucas Dupin | ee4c9b7 | 2019-02-18 17:04:58 -0800 | [diff] [blame] | 157 | mWakeLock = new SettableWakeLock(wakeLock, TAG); |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 158 | mLockPatternUtils = lockPatternUtils; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 159 | |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 160 | Resources res = context.getResources(); |
| 161 | mSlowThreshold = res.getInteger(R.integer.config_chargingSlowlyThreshold); |
| 162 | mFastThreshold = res.getInteger(R.integer.config_chargingFastThreshold); |
| 163 | |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 164 | mUserManager = context.getSystemService(UserManager.class); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 165 | mBatteryInfo = IBatteryStats.Stub.asInterface( |
| 166 | ServiceManager.getService(BatteryStats.SERVICE_NAME)); |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 167 | |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 168 | mDevicePolicyManager = (DevicePolicyManager) context.getSystemService( |
| 169 | Context.DEVICE_POLICY_SERVICE); |
Lucas Dupin | 00ebe13 | 2019-04-26 16:17:56 -0700 | [diff] [blame] | 170 | setIndicationArea(indicationArea); |
Adrian Roos | af45b60 | 2017-03-14 13:10:25 -0700 | [diff] [blame] | 171 | updateDisclosure(); |
Adrian Roos | af45b60 | 2017-03-14 13:10:25 -0700 | [diff] [blame] | 172 | |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 173 | mKeyguardUpdateMonitor.registerCallback(getKeyguardCallback()); |
| 174 | mKeyguardUpdateMonitor.registerCallback(mTickReceiver); |
| 175 | mStatusBarStateController.addCallback(this); |
| 176 | mUnlockMethodCache.addListener(this); |
Evan Laird | 878c853 | 2018-10-15 15:54:29 -0400 | [diff] [blame] | 177 | } |
| 178 | |
Lucas Dupin | 00ebe13 | 2019-04-26 16:17:56 -0700 | [diff] [blame] | 179 | public void setIndicationArea(ViewGroup indicationArea) { |
| 180 | mIndicationArea = indicationArea; |
| 181 | mTextView = indicationArea.findViewById(R.id.keyguard_indication_text); |
| 182 | mInitialTextColorState = mTextView != null ? |
| 183 | mTextView.getTextColors() : ColorStateList.valueOf(Color.WHITE); |
| 184 | mDisclosure = indicationArea.findViewById(R.id.keyguard_indication_enterprise_disclosure); |
| 185 | updateIndication(false /* animate */); |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 186 | } |
| 187 | |
Lucas Dupin | 0df60fe | 2019-04-23 10:19:27 -0700 | [diff] [blame] | 188 | private boolean handleLockLongClick(View view) { |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 189 | mLockscreenGestureLogger.write(MetricsProto.MetricsEvent.ACTION_LS_LOCK, |
| 190 | 0 /* lengthDp - N/A */, 0 /* velocityDp - N/A */); |
| 191 | showTransientIndication(R.string.keyguard_indication_trust_disabled); |
Lucas Dupin | ca88e5f | 2019-05-14 16:11:08 -0700 | [diff] [blame^] | 192 | mKeyguardUpdateMonitor.onLockIconPressed(); |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 193 | mLockPatternUtils.requireCredentialEntry(KeyguardUpdateMonitor.getCurrentUser()); |
| 194 | |
| 195 | return true; |
| 196 | } |
| 197 | |
Lucas Dupin | 0df60fe | 2019-04-23 10:19:27 -0700 | [diff] [blame] | 198 | private void handleLockClick(View view) { |
| 199 | if (!mAccessibilityController.isAccessibilityEnabled()) { |
| 200 | return; |
| 201 | } |
Lucas Dupin | d54f00e | 2019-05-06 17:44:03 -0700 | [diff] [blame] | 202 | mShadeController.animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE, true /* force */); |
Lucas Dupin | 0df60fe | 2019-04-23 10:19:27 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 205 | /** |
| 206 | * Gets the {@link KeyguardUpdateMonitorCallback} instance associated with this |
| 207 | * {@link KeyguardIndicationController}. |
| 208 | * |
| 209 | * <p>Subclasses may override this method to extend or change the callback behavior by extending |
| 210 | * the {@link BaseKeyguardCallback}. |
| 211 | * |
| 212 | * @return A KeyguardUpdateMonitorCallback. Multiple calls to this method <b>must</b> return the |
| 213 | * same instance. |
| 214 | */ |
| 215 | protected KeyguardUpdateMonitorCallback getKeyguardCallback() { |
Zachary Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 216 | if (mUpdateMonitorCallback == null) { |
| 217 | mUpdateMonitorCallback = new BaseKeyguardCallback(); |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 218 | } |
Zachary Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 219 | return mUpdateMonitorCallback; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 220 | } |
| 221 | |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 222 | private void updateDisclosure() { |
| 223 | if (mDevicePolicyManager == null) { |
| 224 | return; |
| 225 | } |
| 226 | |
Adrian Roos | 91ba307 | 2017-02-14 16:50:46 +0100 | [diff] [blame] | 227 | if (!mDozing && mDevicePolicyManager.isDeviceManaged()) { |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 228 | final CharSequence organizationName = |
| 229 | mDevicePolicyManager.getDeviceOwnerOrganizationName(); |
| 230 | if (organizationName != null) { |
| 231 | mDisclosure.switchIndication(mContext.getResources().getString( |
| 232 | R.string.do_disclosure_with_name, organizationName)); |
| 233 | } else { |
| 234 | mDisclosure.switchIndication(R.string.do_disclosure_generic); |
| 235 | } |
| 236 | mDisclosure.setVisibility(View.VISIBLE); |
| 237 | } else { |
| 238 | mDisclosure.setVisibility(View.GONE); |
| 239 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | public void setVisible(boolean visible) { |
| 243 | mVisible = visible; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 244 | mIndicationArea.setVisibility(visible ? View.VISIBLE : View.GONE); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 245 | if (visible) { |
Kevin Chyn | 4c4001c | 2017-08-25 14:23:36 -0700 | [diff] [blame] | 246 | // If this is called after an error message was already shown, we should not clear it. |
| 247 | // Otherwise the error message won't be shown |
| 248 | if (!mHandler.hasMessages(MSG_HIDE_TRANSIENT)) { |
| 249 | hideTransientIndication(); |
| 250 | } |
Beverly | 8c78589 | 2018-01-31 17:25:52 -0500 | [diff] [blame] | 251 | updateIndication(false); |
Kevin Chyn | 4c4001c | 2017-08-25 14:23:36 -0700 | [diff] [blame] | 252 | } else if (!visible) { |
| 253 | // If we unlock and return to keyguard quickly, previous error should not be shown |
| 254 | hideTransientIndication(); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Sets the indication that is shown if nothing else is showing. |
| 260 | */ |
| 261 | public void setRestingIndication(String restingIndication) { |
| 262 | mRestingIndication = restingIndication; |
Beverly | 8c78589 | 2018-01-31 17:25:52 -0500 | [diff] [blame] | 263 | updateIndication(false); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | /** |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 267 | * Sets the active controller managing changes and callbacks to user information. |
| 268 | */ |
| 269 | public void setUserInfoController(UserInfoController userInfoController) { |
| 270 | } |
| 271 | |
| 272 | /** |
Zachary Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 273 | * Returns the indication text indicating that trust has been granted. |
| 274 | * |
| 275 | * @return {@code null} or an empty string if a trust indication text should not be shown. |
| 276 | */ |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 277 | @VisibleForTesting |
| 278 | String getTrustGrantedIndication() { |
Lucas Dupin | 859f2c8 | 2019-04-17 18:30:00 -0700 | [diff] [blame] | 279 | return mContext.getString(R.string.keyguard_indication_trust_unlocked); |
Zachary Iqbal | dc05aa0 | 2017-05-17 18:52:49 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Returns the indication text indicating that trust is currently being managed. |
| 284 | * |
| 285 | * @return {@code null} or an empty string if a trust managed text should not be shown. |
| 286 | */ |
Lucas Dupin | 859f2c8 | 2019-04-17 18:30:00 -0700 | [diff] [blame] | 287 | private String getTrustManagedIndication() { |
Zachary Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 288 | return null; |
| 289 | } |
| 290 | |
| 291 | /** |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 292 | * Hides transient indication in {@param delayMs}. |
| 293 | */ |
| 294 | public void hideTransientIndicationDelayed(long delayMs) { |
| 295 | mHandler.sendMessageDelayed( |
| 296 | mHandler.obtainMessage(MSG_HIDE_TRANSIENT), delayMs); |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}. |
| 301 | */ |
| 302 | public void showTransientIndication(int transientIndication) { |
| 303 | showTransientIndication(mContext.getResources().getString(transientIndication)); |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}. |
| 308 | */ |
Lucas Dupin | ef88654 | 2018-01-03 16:03:07 -0800 | [diff] [blame] | 309 | public void showTransientIndication(CharSequence transientIndication) { |
Jason Chang | 2386a37 | 2018-04-24 16:05:30 +0800 | [diff] [blame] | 310 | showTransientIndication(transientIndication, mInitialTextColorState); |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | /** |
| 314 | * Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}. |
| 315 | */ |
Jason Chang | 2386a37 | 2018-04-24 16:05:30 +0800 | [diff] [blame] | 316 | public void showTransientIndication(CharSequence transientIndication, |
| 317 | ColorStateList textColorState) { |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 318 | mTransientIndication = transientIndication; |
Jason Chang | 2386a37 | 2018-04-24 16:05:30 +0800 | [diff] [blame] | 319 | mTransientTextColorState = textColorState; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 320 | mHandler.removeMessages(MSG_HIDE_TRANSIENT); |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 321 | if (mDozing && !TextUtils.isEmpty(mTransientIndication)) { |
| 322 | // Make sure this doesn't get stuck and burns in. Acquire wakelock until its cleared. |
| 323 | mWakeLock.setAcquired(true); |
| 324 | hideTransientIndicationDelayed(BaseKeyguardCallback.HIDE_DELAY_MS); |
| 325 | } |
Beverly | 8c78589 | 2018-01-31 17:25:52 -0500 | [diff] [blame] | 326 | |
| 327 | updateIndication(false); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | /** |
| 331 | * Hides transient indication. |
| 332 | */ |
| 333 | public void hideTransientIndication() { |
| 334 | if (mTransientIndication != null) { |
| 335 | mTransientIndication = null; |
| 336 | mHandler.removeMessages(MSG_HIDE_TRANSIENT); |
Beverly | 8c78589 | 2018-01-31 17:25:52 -0500 | [diff] [blame] | 337 | updateIndication(false); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | |
Beverly | 8c78589 | 2018-01-31 17:25:52 -0500 | [diff] [blame] | 341 | protected final void updateIndication(boolean animate) { |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 342 | if (TextUtils.isEmpty(mTransientIndication)) { |
| 343 | mWakeLock.setAcquired(false); |
| 344 | } |
| 345 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 346 | if (mVisible) { |
Lucas Dupin | 53d5062 | 2017-05-13 15:54:14 -0700 | [diff] [blame] | 347 | // Walk down a precedence-ordered list of what indication |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 348 | // should be shown based on user or device state |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 349 | if (mDozing) { |
Lucas Dupin | 07ed3df | 2019-03-26 21:23:59 -0700 | [diff] [blame] | 350 | // When dozing we ignore any text color and use white instead, because |
| 351 | // colors can be hard to read in low brightness. |
| 352 | mTextView.setTextColor(Color.WHITE); |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 353 | if (!TextUtils.isEmpty(mTransientIndication)) { |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 354 | mTextView.switchIndication(mTransientIndication); |
Lucas Dupin | 07ed3df | 2019-03-26 21:23:59 -0700 | [diff] [blame] | 355 | } else if (mPowerPluggedIn) { |
| 356 | String indication = computePowerIndication(); |
| 357 | if (animate) { |
| 358 | animateText(mTextView, indication); |
| 359 | } else { |
| 360 | mTextView.switchIndication(indication); |
| 361 | } |
| 362 | } else { |
| 363 | String percentage = NumberFormat.getPercentInstance() |
| 364 | .format(mBatteryLevel / 100f); |
| 365 | mTextView.switchIndication(percentage); |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 366 | } |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 367 | return; |
| 368 | } |
| 369 | |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 370 | int userId = KeyguardUpdateMonitor.getCurrentUser(); |
Zachary Iqbal | dc05aa0 | 2017-05-17 18:52:49 -0700 | [diff] [blame] | 371 | String trustGrantedIndication = getTrustGrantedIndication(); |
| 372 | String trustManagedIndication = getTrustManagedIndication(); |
Zachary Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 373 | if (!mUserManager.isUserUnlocked(userId)) { |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 374 | mTextView.switchIndication(com.android.internal.R.string.lockscreen_storage_locked); |
Jason Chang | 2386a37 | 2018-04-24 16:05:30 +0800 | [diff] [blame] | 375 | mTextView.setTextColor(mInitialTextColorState); |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 376 | } else if (!TextUtils.isEmpty(mTransientIndication)) { |
| 377 | mTextView.switchIndication(mTransientIndication); |
Jason Chang | 2386a37 | 2018-04-24 16:05:30 +0800 | [diff] [blame] | 378 | mTextView.setTextColor(mTransientTextColorState); |
Zachary Iqbal | dc05aa0 | 2017-05-17 18:52:49 -0700 | [diff] [blame] | 379 | } else if (!TextUtils.isEmpty(trustGrantedIndication) |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 380 | && mKeyguardUpdateMonitor.getUserHasTrust(userId)) { |
Zachary Iqbal | dc05aa0 | 2017-05-17 18:52:49 -0700 | [diff] [blame] | 381 | mTextView.switchIndication(trustGrantedIndication); |
Jason Chang | 2386a37 | 2018-04-24 16:05:30 +0800 | [diff] [blame] | 382 | mTextView.setTextColor(mInitialTextColorState); |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 383 | } else if (mPowerPluggedIn) { |
| 384 | String indication = computePowerIndication(); |
| 385 | if (DEBUG_CHARGING_SPEED) { |
| 386 | indication += ", " + (mChargingWattage / 1000) + " mW"; |
| 387 | } |
Jason Chang | 2386a37 | 2018-04-24 16:05:30 +0800 | [diff] [blame] | 388 | mTextView.setTextColor(mInitialTextColorState); |
Beverly | 85499d9 | 2018-02-14 15:55:16 -0500 | [diff] [blame] | 389 | if (animate) { |
| 390 | animateText(mTextView, indication); |
| 391 | } else { |
| 392 | mTextView.switchIndication(indication); |
| 393 | } |
Zachary Iqbal | dc05aa0 | 2017-05-17 18:52:49 -0700 | [diff] [blame] | 394 | } else if (!TextUtils.isEmpty(trustManagedIndication) |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 395 | && mKeyguardUpdateMonitor.getUserTrustIsManaged(userId) |
| 396 | && !mKeyguardUpdateMonitor.getUserHasTrust(userId)) { |
Zachary Iqbal | dc05aa0 | 2017-05-17 18:52:49 -0700 | [diff] [blame] | 397 | mTextView.switchIndication(trustManagedIndication); |
Jason Chang | 2386a37 | 2018-04-24 16:05:30 +0800 | [diff] [blame] | 398 | mTextView.setTextColor(mInitialTextColorState); |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 399 | } else { |
| 400 | mTextView.switchIndication(mRestingIndication); |
Jason Chang | 2386a37 | 2018-04-24 16:05:30 +0800 | [diff] [blame] | 401 | mTextView.setTextColor(mInitialTextColorState); |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 402 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 403 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 404 | } |
| 405 | |
Beverly | 85499d9 | 2018-02-14 15:55:16 -0500 | [diff] [blame] | 406 | // animates textView - textView moves up and bounces down |
| 407 | private void animateText(KeyguardIndicationTextView textView, String indication) { |
| 408 | int yTranslation = mContext.getResources().getInteger( |
| 409 | R.integer.wired_charging_keyguard_text_animation_distance); |
| 410 | int animateUpDuration = mContext.getResources().getInteger( |
| 411 | R.integer.wired_charging_keyguard_text_animation_duration_up); |
| 412 | int animateDownDuration = mContext.getResources().getInteger( |
| 413 | R.integer.wired_charging_keyguard_text_animation_duration_down); |
Lucas Dupin | def4369 | 2018-07-02 15:22:58 -0700 | [diff] [blame] | 414 | textView.animate().cancel(); |
| 415 | float translation = textView.getTranslationY(); |
Beverly | 85499d9 | 2018-02-14 15:55:16 -0500 | [diff] [blame] | 416 | textView.animate() |
| 417 | .translationYBy(yTranslation) |
| 418 | .setInterpolator(Interpolators.LINEAR) |
| 419 | .setDuration(animateUpDuration) |
| 420 | .setListener(new AnimatorListenerAdapter() { |
Lucas Dupin | def4369 | 2018-07-02 15:22:58 -0700 | [diff] [blame] | 421 | private boolean mCancelled; |
| 422 | |
Beverly | 85499d9 | 2018-02-14 15:55:16 -0500 | [diff] [blame] | 423 | @Override |
| 424 | public void onAnimationStart(Animator animation) { |
| 425 | textView.switchIndication(indication); |
| 426 | } |
Lucas Dupin | def4369 | 2018-07-02 15:22:58 -0700 | [diff] [blame] | 427 | |
| 428 | @Override |
| 429 | public void onAnimationCancel(Animator animation) { |
| 430 | textView.setTranslationY(translation); |
| 431 | mCancelled = true; |
| 432 | } |
| 433 | |
Beverly | 85499d9 | 2018-02-14 15:55:16 -0500 | [diff] [blame] | 434 | @Override |
| 435 | public void onAnimationEnd(Animator animation) { |
Lucas Dupin | def4369 | 2018-07-02 15:22:58 -0700 | [diff] [blame] | 436 | if (mCancelled) { |
| 437 | return; |
| 438 | } |
Beverly | 85499d9 | 2018-02-14 15:55:16 -0500 | [diff] [blame] | 439 | textView.animate() |
| 440 | .setDuration(animateDownDuration) |
| 441 | .setInterpolator(Interpolators.BOUNCE) |
Lucas Dupin | def4369 | 2018-07-02 15:22:58 -0700 | [diff] [blame] | 442 | .translationY(translation) |
| 443 | .setListener(new AnimatorListenerAdapter() { |
| 444 | @Override |
| 445 | public void onAnimationCancel(Animator animation) { |
| 446 | textView.setTranslationY(translation); |
| 447 | } |
| 448 | }); |
Beverly | 85499d9 | 2018-02-14 15:55:16 -0500 | [diff] [blame] | 449 | } |
| 450 | }); |
| 451 | } |
| 452 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 453 | private String computePowerIndication() { |
| 454 | if (mPowerCharged) { |
| 455 | return mContext.getResources().getString(R.string.keyguard_charged); |
| 456 | } |
| 457 | |
| 458 | // Try fetching charging time from battery stats. |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 459 | long chargingTimeRemaining = 0; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 460 | try { |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 461 | chargingTimeRemaining = mBatteryInfo.computeChargeTimeRemaining(); |
| 462 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 463 | } catch (RemoteException e) { |
| 464 | Log.e(TAG, "Error calling IBatteryStats: ", e); |
| 465 | } |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 466 | final boolean hasChargingTime = chargingTimeRemaining > 0; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 467 | |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 468 | int chargingId; |
Beverly | 7d7f699 | 2019-02-11 13:58:27 -0500 | [diff] [blame] | 469 | if (mPowerPluggedInWired) { |
| 470 | switch (mChargingSpeed) { |
| 471 | case KeyguardUpdateMonitor.BatteryStatus.CHARGING_FAST: |
| 472 | chargingId = hasChargingTime |
| 473 | ? R.string.keyguard_indication_charging_time_fast |
| 474 | : R.string.keyguard_plugged_in_charging_fast; |
| 475 | break; |
| 476 | case KeyguardUpdateMonitor.BatteryStatus.CHARGING_SLOWLY: |
| 477 | chargingId = hasChargingTime |
| 478 | ? R.string.keyguard_indication_charging_time_slowly |
| 479 | : R.string.keyguard_plugged_in_charging_slowly; |
| 480 | break; |
| 481 | default: |
| 482 | chargingId = hasChargingTime |
| 483 | ? R.string.keyguard_indication_charging_time |
| 484 | : R.string.keyguard_plugged_in; |
| 485 | break; |
| 486 | } |
| 487 | } else { |
| 488 | chargingId = hasChargingTime |
| 489 | ? R.string.keyguard_indication_charging_time_wireless |
| 490 | : R.string.keyguard_plugged_in_wireless; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 491 | } |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 492 | |
Lucas Dupin | 8d595d2 | 2018-03-08 10:34:58 -0800 | [diff] [blame] | 493 | String percentage = NumberFormat.getPercentInstance() |
| 494 | .format(mBatteryLevel / 100f); |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 495 | if (hasChargingTime) { |
Lucas Dupin | 8d595d2 | 2018-03-08 10:34:58 -0800 | [diff] [blame] | 496 | // We now have battery percentage in these strings and it's expected that all |
| 497 | // locales will also have it in the future. For now, we still have to support the old |
| 498 | // format until all languages get the new translations. |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 499 | String chargingTimeFormatted = Formatter.formatShortElapsedTimeRoundingUpToMinutes( |
| 500 | mContext, chargingTimeRemaining); |
Lucas Dupin | 8d595d2 | 2018-03-08 10:34:58 -0800 | [diff] [blame] | 501 | try { |
| 502 | return mContext.getResources().getString(chargingId, chargingTimeFormatted, |
| 503 | percentage); |
| 504 | } catch (IllegalFormatConversionException e) { |
| 505 | return mContext.getResources().getString(chargingId, chargingTimeFormatted); |
| 506 | } |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 507 | } else { |
Lucas Dupin | 8d595d2 | 2018-03-08 10:34:58 -0800 | [diff] [blame] | 508 | // Same as above |
| 509 | try { |
| 510 | return mContext.getResources().getString(chargingId, percentage); |
| 511 | } catch (IllegalFormatConversionException e) { |
| 512 | return mContext.getResources().getString(chargingId); |
| 513 | } |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 514 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 515 | } |
| 516 | |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 517 | public void setStatusBarKeyguardViewManager( |
| 518 | StatusBarKeyguardViewManager statusBarKeyguardViewManager) { |
| 519 | mStatusBarKeyguardViewManager = statusBarKeyguardViewManager; |
| 520 | } |
| 521 | |
Lucas Dupin | 7e171e2 | 2018-12-20 11:29:35 -0800 | [diff] [blame] | 522 | private final KeyguardUpdateMonitorCallback mTickReceiver = |
| 523 | new KeyguardUpdateMonitorCallback() { |
| 524 | @Override |
| 525 | public void onTimeChanged() { |
| 526 | if (mVisible) { |
| 527 | updateIndication(false /* animate */); |
| 528 | } |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 529 | } |
Lucas Dupin | 7e171e2 | 2018-12-20 11:29:35 -0800 | [diff] [blame] | 530 | }; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 531 | |
| 532 | private final Handler mHandler = new Handler() { |
| 533 | @Override |
| 534 | public void handleMessage(Message msg) { |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 535 | if (msg.what == MSG_HIDE_TRANSIENT) { |
| 536 | hideTransientIndication(); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 537 | } else if (msg.what == MSG_CLEAR_BIOMETRIC_MSG) { |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 538 | mLockIcon.setTransientBiometricsError(false); |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | }; |
| 542 | |
Adrian Roos | 91ba307 | 2017-02-14 16:50:46 +0100 | [diff] [blame] | 543 | public void setDozing(boolean dozing) { |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 544 | if (mDozing == dozing) { |
| 545 | return; |
| 546 | } |
Adrian Roos | 91ba307 | 2017-02-14 16:50:46 +0100 | [diff] [blame] | 547 | mDozing = dozing; |
Beverly | 8c78589 | 2018-01-31 17:25:52 -0500 | [diff] [blame] | 548 | updateIndication(false); |
Adrian Roos | 91ba307 | 2017-02-14 16:50:46 +0100 | [diff] [blame] | 549 | updateDisclosure(); |
| 550 | } |
| 551 | |
Lucas Dupin | 3fcdd47 | 2018-01-19 19:06:45 -0800 | [diff] [blame] | 552 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 553 | pw.println("KeyguardIndicationController:"); |
Jason Chang | 2386a37 | 2018-04-24 16:05:30 +0800 | [diff] [blame] | 554 | pw.println(" mTransientTextColorState: " + mTransientTextColorState); |
| 555 | pw.println(" mInitialTextColorState: " + mInitialTextColorState); |
Beverly | 2034c83 | 2018-03-19 11:18:51 -0400 | [diff] [blame] | 556 | pw.println(" mPowerPluggedInWired: " + mPowerPluggedInWired); |
Lucas Dupin | 3fcdd47 | 2018-01-19 19:06:45 -0800 | [diff] [blame] | 557 | pw.println(" mPowerPluggedIn: " + mPowerPluggedIn); |
| 558 | pw.println(" mPowerCharged: " + mPowerCharged); |
| 559 | pw.println(" mChargingSpeed: " + mChargingSpeed); |
| 560 | pw.println(" mChargingWattage: " + mChargingWattage); |
| 561 | pw.println(" mMessageToShowOnScreenOn: " + mMessageToShowOnScreenOn); |
| 562 | pw.println(" mDozing: " + mDozing); |
| 563 | pw.println(" mBatteryLevel: " + mBatteryLevel); |
| 564 | pw.println(" mTextView.getText(): " + (mTextView == null ? null : mTextView.getText())); |
| 565 | pw.println(" computePowerIndication(): " + computePowerIndication()); |
| 566 | } |
| 567 | |
Evan Laird | 878c853 | 2018-10-15 15:54:29 -0400 | [diff] [blame] | 568 | @Override |
| 569 | public void onStateChanged(int newState) { |
| 570 | // don't care |
| 571 | } |
| 572 | |
| 573 | @Override |
| 574 | public void onDozingChanged(boolean isDozing) { |
| 575 | setDozing(isDozing); |
| 576 | } |
| 577 | |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 578 | @Override |
| 579 | public void onUnlockMethodStateChanged() { |
| 580 | updateIndication(!mDozing); |
| 581 | } |
| 582 | |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 583 | protected class BaseKeyguardCallback extends KeyguardUpdateMonitorCallback { |
Adrian Roos | 5602189 | 2017-02-27 20:25:09 +0100 | [diff] [blame] | 584 | public static final int HIDE_DELAY_MS = 5000; |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 585 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 586 | @Override |
| 587 | public void onRefreshBatteryInfo(KeyguardUpdateMonitor.BatteryStatus status) { |
Adrian Roos | ad3bc7f | 2014-10-30 18:29:38 +0100 | [diff] [blame] | 588 | boolean isChargingOrFull = status.status == BatteryManager.BATTERY_STATUS_CHARGING |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 589 | || status.status == BatteryManager.BATTERY_STATUS_FULL; |
Adrian Roos | 5602189 | 2017-02-27 20:25:09 +0100 | [diff] [blame] | 590 | boolean wasPluggedIn = mPowerPluggedIn; |
Beverly | 2034c83 | 2018-03-19 11:18:51 -0400 | [diff] [blame] | 591 | mPowerPluggedInWired = status.isPluggedInWired() && isChargingOrFull; |
Adrian Roos | ad3bc7f | 2014-10-30 18:29:38 +0100 | [diff] [blame] | 592 | mPowerPluggedIn = status.isPluggedIn() && isChargingOrFull; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 593 | mPowerCharged = status.isCharged(); |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 594 | mChargingWattage = status.maxChargingWattage; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 595 | mChargingSpeed = status.getChargingSpeed(mSlowThreshold, mFastThreshold); |
Lucas Dupin | 4272f44 | 2018-01-13 22:00:35 -0800 | [diff] [blame] | 596 | mBatteryLevel = status.level; |
Beverly | 2034c83 | 2018-03-19 11:18:51 -0400 | [diff] [blame] | 597 | updateIndication(!wasPluggedIn && mPowerPluggedInWired); |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 598 | if (mDozing) { |
| 599 | if (!wasPluggedIn && mPowerPluggedIn) { |
| 600 | showTransientIndication(computePowerIndication()); |
| 601 | hideTransientIndicationDelayed(HIDE_DELAY_MS); |
| 602 | } else if (wasPluggedIn && !mPowerPluggedIn) { |
| 603 | hideTransientIndication(); |
| 604 | } |
Adrian Roos | 5602189 | 2017-02-27 20:25:09 +0100 | [diff] [blame] | 605 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 606 | } |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 607 | |
| 608 | @Override |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 609 | public void onKeyguardVisibilityChanged(boolean showing) { |
| 610 | if (showing) { |
| 611 | updateDisclosure(); |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | @Override |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 616 | public void onBiometricHelp(int msgId, String helpString, |
| 617 | BiometricSourceType biometricSourceType) { |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 618 | KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 619 | if (!updateMonitor.isUnlockingWithBiometricAllowed()) { |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 620 | return; |
| 621 | } |
Lucas Dupin | e54ad1d | 2019-04-09 17:08:46 -0700 | [diff] [blame] | 622 | animatePadlockError(); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 623 | if (mStatusBarKeyguardViewManager.isBouncerShowing()) { |
Jason Chang | 2386a37 | 2018-04-24 16:05:30 +0800 | [diff] [blame] | 624 | mStatusBarKeyguardViewManager.showBouncerMessage(helpString, |
Lucas Dupin | c2d11b3 | 2019-03-06 16:02:18 -0800 | [diff] [blame] | 625 | mInitialTextColorState); |
Kevin Chyn | 4c4001c | 2017-08-25 14:23:36 -0700 | [diff] [blame] | 626 | } else if (updateMonitor.isScreenOn()) { |
Lucas Dupin | c2d11b3 | 2019-03-06 16:02:18 -0800 | [diff] [blame] | 627 | showTransientIndication(helpString); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 628 | hideTransientIndicationDelayed(TRANSIENT_BIOMETRIC_ERROR_TIMEOUT); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | |
| 632 | @Override |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 633 | public void onBiometricError(int msgId, String errString, |
| 634 | BiometricSourceType biometricSourceType) { |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 635 | KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 636 | if (shouldSuppressBiometricError(msgId, biometricSourceType, updateMonitor)) { |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 637 | return; |
| 638 | } |
Lucas Dupin | e54ad1d | 2019-04-09 17:08:46 -0700 | [diff] [blame] | 639 | animatePadlockError(); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 640 | if (mStatusBarKeyguardViewManager.isBouncerShowing()) { |
Lucas Dupin | e54ad1d | 2019-04-09 17:08:46 -0700 | [diff] [blame] | 641 | mStatusBarKeyguardViewManager.showBouncerMessage(errString, mInitialTextColorState); |
Kevin Chyn | 4c4001c | 2017-08-25 14:23:36 -0700 | [diff] [blame] | 642 | } else if (updateMonitor.isScreenOn()) { |
Lucas Dupin | c2d11b3 | 2019-03-06 16:02:18 -0800 | [diff] [blame] | 643 | showTransientIndication(errString); |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 644 | // We want to keep this message around in case the screen was off |
Adrian Roos | 5602189 | 2017-02-27 20:25:09 +0100 | [diff] [blame] | 645 | hideTransientIndicationDelayed(HIDE_DELAY_MS); |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 646 | } else { |
| 647 | mMessageToShowOnScreenOn = errString; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 648 | } |
Lucas Dupin | e54ad1d | 2019-04-09 17:08:46 -0700 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | private void animatePadlockError() { |
| 652 | mLockIcon.setTransientBiometricsError(true); |
| 653 | mHandler.removeMessages(MSG_CLEAR_BIOMETRIC_MSG); |
| 654 | mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_CLEAR_BIOMETRIC_MSG), |
| 655 | TRANSIENT_BIOMETRIC_ERROR_TIMEOUT); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 658 | private boolean shouldSuppressBiometricError(int msgId, |
| 659 | BiometricSourceType biometricSourceType, KeyguardUpdateMonitor updateMonitor) { |
| 660 | if (biometricSourceType == BiometricSourceType.FINGERPRINT) |
| 661 | return shouldSuppressFingerprintError(msgId, updateMonitor); |
| 662 | if (biometricSourceType == BiometricSourceType.FACE) |
| 663 | return shouldSuppressFaceError(msgId, updateMonitor); |
| 664 | return false; |
| 665 | } |
| 666 | |
| 667 | private boolean shouldSuppressFingerprintError(int msgId, |
| 668 | KeyguardUpdateMonitor updateMonitor) { |
| 669 | return ((!updateMonitor.isUnlockingWithBiometricAllowed() |
| 670 | && msgId != FingerprintManager.FINGERPRINT_ERROR_LOCKOUT_PERMANENT) |
| 671 | || msgId == FingerprintManager.FINGERPRINT_ERROR_CANCELED); |
| 672 | } |
| 673 | |
| 674 | private boolean shouldSuppressFaceError(int msgId, KeyguardUpdateMonitor updateMonitor) { |
| 675 | return ((!updateMonitor.isUnlockingWithBiometricAllowed() |
| 676 | && msgId != FaceManager.FACE_ERROR_LOCKOUT_PERMANENT) |
| 677 | || msgId == FaceManager.FACE_ERROR_CANCELED); |
| 678 | } |
| 679 | |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 680 | @Override |
Lucas Dupin | ef88654 | 2018-01-03 16:03:07 -0800 | [diff] [blame] | 681 | public void onTrustAgentErrorMessage(CharSequence message) { |
Jason Chang | 2386a37 | 2018-04-24 16:05:30 +0800 | [diff] [blame] | 682 | showTransientIndication(message, Utils.getColorError(mContext)); |
Lucas Dupin | ef88654 | 2018-01-03 16:03:07 -0800 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | @Override |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 686 | public void onScreenTurnedOn() { |
| 687 | if (mMessageToShowOnScreenOn != null) { |
Jason Chang | 2386a37 | 2018-04-24 16:05:30 +0800 | [diff] [blame] | 688 | showTransientIndication(mMessageToShowOnScreenOn, Utils.getColorError(mContext)); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 689 | // We want to keep this message around in case the screen was off |
Adrian Roos | 5602189 | 2017-02-27 20:25:09 +0100 | [diff] [blame] | 690 | hideTransientIndicationDelayed(HIDE_DELAY_MS); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 691 | mMessageToShowOnScreenOn = null; |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | @Override |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 696 | public void onBiometricRunningStateChanged(boolean running, |
| 697 | BiometricSourceType biometricSourceType) { |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 698 | if (running) { |
Lucas Dupin | 8f3faac | 2019-03-12 15:28:49 -0700 | [diff] [blame] | 699 | // Let's hide any previous messages when authentication starts, otherwise |
| 700 | // multiple auth attempts would overlap. |
| 701 | hideTransientIndication(); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 702 | mMessageToShowOnScreenOn = null; |
| 703 | } |
| 704 | } |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 705 | |
| 706 | @Override |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 707 | public void onBiometricAuthenticated(int userId, BiometricSourceType biometricSourceType) { |
| 708 | super.onBiometricAuthenticated(userId, biometricSourceType); |
Kevin Chyn | 6d793bd | 2019-03-27 15:36:13 -0700 | [diff] [blame] | 709 | mHandler.sendEmptyMessage(MSG_HIDE_TRANSIENT); |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | @Override |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 713 | public void onUserUnlocked() { |
| 714 | if (mVisible) { |
Beverly | 8c78589 | 2018-01-31 17:25:52 -0500 | [diff] [blame] | 715 | updateIndication(false); |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 716 | } |
| 717 | } |
Lucas Dupin | 0590465 | 2019-04-09 16:16:15 -0700 | [diff] [blame] | 718 | |
| 719 | @Override |
| 720 | public void onKeyguardBouncerChanged(boolean bouncer) { |
Brad Stenning | 8fcd8b4 | 2019-04-22 09:30:20 -0700 | [diff] [blame] | 721 | if (mLockIcon == null) { |
| 722 | return; |
| 723 | } |
Lucas Dupin | 0590465 | 2019-04-09 16:16:15 -0700 | [diff] [blame] | 724 | mLockIcon.setBouncerVisible(bouncer); |
| 725 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 726 | }; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 727 | } |