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