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