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