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