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