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