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