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