blob: 2094362db5430b31740bbfa643a678fb696ca5b3 [file] [log] [blame]
Adrian Roos12c1ef52014-06-04 13:54:08 +02001/*
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
17package com.android.systemui.statusbar;
18
Jeff Sharkeyb6edaa92016-07-27 15:51:31 -060019import android.app.ActivityManager;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +010020import android.app.admin.DevicePolicyManager;
Adrian Roos12c1ef52014-06-04 13:54:08 +020021import android.content.BroadcastReceiver;
22import android.content.Context;
23import android.content.Intent;
24import android.content.IntentFilter;
Adrian Roos7b043112015-07-10 13:00:33 -070025import android.content.res.Resources;
Jorim Jaggi27c9b742015-04-09 10:34:49 -070026import android.graphics.Color;
Selim Cinekcfafe4e2015-08-11 14:58:44 -070027import android.hardware.fingerprint.FingerprintManager;
Adrian Roos12c1ef52014-06-04 13:54:08 +020028import android.os.BatteryManager;
29import android.os.BatteryStats;
30import android.os.Handler;
31import android.os.Message;
32import android.os.RemoteException;
33import android.os.ServiceManager;
34import android.os.UserHandle;
Jeff Sharkeyb6edaa92016-07-27 15:51:31 -060035import android.os.UserManager;
Adrian Roos12c1ef52014-06-04 13:54:08 +020036import android.text.TextUtils;
37import android.text.format.Formatter;
38import android.util.Log;
39import android.view.View;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +010040import android.view.ViewGroup;
Adrian Roos12c1ef52014-06-04 13:54:08 +020041
Adrian Roosc1b50322017-02-27 21:07:58 +010042import com.android.internal.annotations.VisibleForTesting;
Selim Cinekcfafe4e2015-08-11 14:58:44 -070043import com.android.internal.app.IBatteryStats;
44import com.android.keyguard.KeyguardUpdateMonitor;
45import com.android.keyguard.KeyguardUpdateMonitorCallback;
Jason Monk58be7a62017-02-01 20:17:51 -050046import com.android.settingslib.Utils;
Jason Monk9c7844c2017-01-18 15:21:53 -050047import com.android.systemui.Dependency;
Selim Cinekcfafe4e2015-08-11 14:58:44 -070048import com.android.systemui.R;
49import com.android.systemui.statusbar.phone.KeyguardIndicationTextView;
50import com.android.systemui.statusbar.phone.LockIcon;
51import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
Zachary Iqbalf50284c2017-01-22 18:54:46 -080052import com.android.systemui.statusbar.policy.UserInfoController;
Adrian Roosc1b50322017-02-27 21:07:58 +010053import com.android.systemui.util.wakelock.SettableWakeLock;
54import com.android.systemui.util.wakelock.WakeLock;
Selim Cinekcfafe4e2015-08-11 14:58:44 -070055
Adrian Roos12c1ef52014-06-04 13:54:08 +020056/**
Selim Cinekcfafe4e2015-08-11 14:58:44 -070057 * Controls the indications and error messages shown on the Keyguard
Adrian Roos12c1ef52014-06-04 13:54:08 +020058 */
59public class KeyguardIndicationController {
60
Adrian Roos0c859ae2015-11-23 16:47:50 -080061 private static final String TAG = "KeyguardIndication";
62 private static final boolean DEBUG_CHARGING_SPEED = false;
Adrian Roos12c1ef52014-06-04 13:54:08 +020063
64 private static final int MSG_HIDE_TRANSIENT = 1;
Selim Cinekcfafe4e2015-08-11 14:58:44 -070065 private static final int MSG_CLEAR_FP_MSG = 2;
66 private static final long TRANSIENT_FP_ERROR_TIMEOUT = 1300;
Adrian Roos12c1ef52014-06-04 13:54:08 +020067
68 private final Context mContext;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +010069 private final ViewGroup mIndicationArea;
Adrian Roos12c1ef52014-06-04 13:54:08 +020070 private final KeyguardIndicationTextView mTextView;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +010071 private final KeyguardIndicationTextView mDisclosure;
Jeff Sharkeyb6edaa92016-07-27 15:51:31 -060072 private final UserManager mUserManager;
Adrian Roos12c1ef52014-06-04 13:54:08 +020073 private final IBatteryStats mBatteryInfo;
Adrian Roosc1b50322017-02-27 21:07:58 +010074 private final SettableWakeLock mWakeLock;
Adrian Roos12c1ef52014-06-04 13:54:08 +020075
Adrian Roos7b043112015-07-10 13:00:33 -070076 private final int mSlowThreshold;
77 private final int mFastThreshold;
Selim Cinekcfafe4e2015-08-11 14:58:44 -070078 private final LockIcon mLockIcon;
79 private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
Adrian Roos7b043112015-07-10 13:00:33 -070080
Adrian Roos12c1ef52014-06-04 13:54:08 +020081 private String mRestingIndication;
82 private String mTransientIndication;
Jorim Jaggi27c9b742015-04-09 10:34:49 -070083 private int mTransientTextColor;
Adrian Roos12c1ef52014-06-04 13:54:08 +020084 private boolean mVisible;
85
86 private boolean mPowerPluggedIn;
87 private boolean mPowerCharged;
Adrian Roos7b043112015-07-10 13:00:33 -070088 private int mChargingSpeed;
Adrian Roos0c859ae2015-11-23 16:47:50 -080089 private int mChargingWattage;
Selim Cinekcfafe4e2015-08-11 14:58:44 -070090 private String mMessageToShowOnScreenOn;
Adrian Roos12c1ef52014-06-04 13:54:08 +020091
Zachary Iqbal8f4c2422017-04-20 17:56:42 -070092 private KeyguardUpdateMonitorCallback mUpdateMonitorCallback;
Zachary Iqbalf50284c2017-01-22 18:54:46 -080093
Bartosz Fabianowski5f045002016-12-01 10:36:18 +010094 private final DevicePolicyManager mDevicePolicyManager;
Adrian Roos91ba3072017-02-14 16:50:46 +010095 private boolean mDozing;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +010096
Adrian Roosaf45b602017-03-14 13:10:25 -070097 /**
98 * Creates a new KeyguardIndicationController and registers callbacks.
99 */
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100100 public KeyguardIndicationController(Context context, ViewGroup indicationArea,
101 LockIcon lockIcon) {
Adrian Roosc1b50322017-02-27 21:07:58 +0100102 this(context, indicationArea, lockIcon,
103 WakeLock.createPartial(context, "Doze:KeyguardIndication"));
Adrian Roosaf45b602017-03-14 13:10:25 -0700104
105 registerCallbacks(KeyguardUpdateMonitor.getInstance(context));
Adrian Roosc1b50322017-02-27 21:07:58 +0100106 }
107
Adrian Roosaf45b602017-03-14 13:10:25 -0700108 /**
109 * Creates a new KeyguardIndicationController for testing. Does *not* register callbacks.
110 */
Adrian Roosc1b50322017-02-27 21:07:58 +0100111 @VisibleForTesting
112 KeyguardIndicationController(Context context, ViewGroup indicationArea, LockIcon lockIcon,
113 WakeLock wakeLock) {
Adrian Roos12c1ef52014-06-04 13:54:08 +0200114 mContext = context;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100115 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 Cinekcfafe4e2015-08-11 14:58:44 -0700120 mLockIcon = lockIcon;
Adrian Roosc1b50322017-02-27 21:07:58 +0100121 mWakeLock = new SettableWakeLock(wakeLock);
Adrian Roos12c1ef52014-06-04 13:54:08 +0200122
Adrian Roos7b043112015-07-10 13:00:33 -0700123 Resources res = context.getResources();
124 mSlowThreshold = res.getInteger(R.integer.config_chargingSlowlyThreshold);
125 mFastThreshold = res.getInteger(R.integer.config_chargingFastThreshold);
126
Jeff Sharkeyb6edaa92016-07-27 15:51:31 -0600127 mUserManager = context.getSystemService(UserManager.class);
Adrian Roos12c1ef52014-06-04 13:54:08 +0200128 mBatteryInfo = IBatteryStats.Stub.asInterface(
129 ServiceManager.getService(BatteryStats.SERVICE_NAME));
Jeff Sharkeyb6edaa92016-07-27 15:51:31 -0600130
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100131 mDevicePolicyManager = (DevicePolicyManager) context.getSystemService(
132 Context.DEVICE_POLICY_SERVICE);
133
Adrian Roosaf45b602017-03-14 13:10:25 -0700134 updateDisclosure();
135 }
136
137 private void registerCallbacks(KeyguardUpdateMonitor monitor) {
138 monitor.registerCallback(getKeyguardCallback());
139
140 mContext.registerReceiverAsUser(mTickReceiver, UserHandle.SYSTEM,
Jason Monkcd26af72017-01-11 14:32:58 -0500141 new IntentFilter(Intent.ACTION_TIME_TICK), null,
Jason Monk9c7844c2017-01-18 15:21:53 -0500142 Dependency.get(Dependency.TIME_TICK_HANDLER));
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100143 }
144
Zachary Iqbalf50284c2017-01-22 18:54:46 -0800145 /**
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 Iqbal8f4c2422017-04-20 17:56:42 -0700156 if (mUpdateMonitorCallback == null) {
157 mUpdateMonitorCallback = new BaseKeyguardCallback();
Zachary Iqbalf50284c2017-01-22 18:54:46 -0800158 }
Zachary Iqbal8f4c2422017-04-20 17:56:42 -0700159 return mUpdateMonitorCallback;
Zachary Iqbalf50284c2017-01-22 18:54:46 -0800160 }
161
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100162 private void updateDisclosure() {
163 if (mDevicePolicyManager == null) {
164 return;
165 }
166
Adrian Roos91ba3072017-02-14 16:50:46 +0100167 if (!mDozing && mDevicePolicyManager.isDeviceManaged()) {
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100168 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 Roos12c1ef52014-06-04 13:54:08 +0200180 }
181
182 public void setVisible(boolean visible) {
183 mVisible = visible;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100184 mIndicationArea.setVisibility(visible ? View.VISIBLE : View.GONE);
Adrian Roos12c1ef52014-06-04 13:54:08 +0200185 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 Iqbalf50284c2017-01-22 18:54:46 -0800200 * Sets the active controller managing changes and callbacks to user information.
201 */
202 public void setUserInfoController(UserInfoController userInfoController) {
203 }
204
205 /**
Zachary Iqbal8f4c2422017-04-20 17:56:42 -0700206 * 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 Roos12c1ef52014-06-04 13:54:08 +0200215 * 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 Jaggi27c9b742015-04-09 10:34:49 -0700233 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 Roos12c1ef52014-06-04 13:54:08 +0200240 mTransientIndication = transientIndication;
Jorim Jaggi27c9b742015-04-09 10:34:49 -0700241 mTransientTextColor = textColor;
Adrian Roos12c1ef52014-06-04 13:54:08 +0200242 mHandler.removeMessages(MSG_HIDE_TRANSIENT);
Adrian Roosc1b50322017-02-27 21:07:58 +0100243 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 Roos12c1ef52014-06-04 13:54:08 +0200248 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 Iqbal8f4c2422017-04-20 17:56:42 -0700262 protected final void updateIndication() {
Adrian Roosc1b50322017-02-27 21:07:58 +0100263 if (TextUtils.isEmpty(mTransientIndication)) {
264 mWakeLock.setAcquired(false);
265 }
266
Adrian Roos12c1ef52014-06-04 13:54:08 +0200267 if (mVisible) {
Jeff Sharkeyb6edaa92016-07-27 15:51:31 -0600268 // Walk down a precedence-ordered list of what should indication
269 // should be shown based on user or device state
Adrian Roos91ba3072017-02-14 16:50:46 +0100270 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 Iqbal8f4c2422017-04-20 17:56:42 -0700282 KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
Jorim Jaggifabc7432017-05-15 02:40:05 +0200283 int userId = KeyguardUpdateMonitor.getCurrentUser();
Zachary Iqbal8f4c2422017-04-20 17:56:42 -0700284 String trustIndication = getTrustIndication();
285 if (!mUserManager.isUserUnlocked(userId)) {
Jeff Sharkeyb6edaa92016-07-27 15:51:31 -0600286 mTextView.switchIndication(com.android.internal.R.string.lockscreen_storage_locked);
287 mTextView.setTextColor(Color.WHITE);
Jeff Sharkeyb6edaa92016-07-27 15:51:31 -0600288 } else if (!TextUtils.isEmpty(mTransientIndication)) {
289 mTextView.switchIndication(mTransientIndication);
290 mTextView.setTextColor(mTransientTextColor);
Zachary Iqbal8f4c2422017-04-20 17:56:42 -0700291 } else if (!TextUtils.isEmpty(trustIndication)
292 && updateMonitor.getUserHasTrust(userId)) {
293 mTextView.switchIndication(trustIndication);
294 mTextView.setTextColor(Color.WHITE);
Jeff Sharkeyb6edaa92016-07-27 15:51:31 -0600295 } 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 Roos7b043112015-07-10 13:00:33 -0700306 }
Adrian Roos12c1ef52014-06-04 13:54:08 +0200307 }
Adrian Roos12c1ef52014-06-04 13:54:08 +0200308 }
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 Roos7e39e592015-09-23 17:03:47 -0700316 long chargingTimeRemaining = 0;
Adrian Roos12c1ef52014-06-04 13:54:08 +0200317 try {
Adrian Roos7e39e592015-09-23 17:03:47 -0700318 chargingTimeRemaining = mBatteryInfo.computeChargeTimeRemaining();
319
Adrian Roos12c1ef52014-06-04 13:54:08 +0200320 } catch (RemoteException e) {
321 Log.e(TAG, "Error calling IBatteryStats: ", e);
322 }
Adrian Roos7e39e592015-09-23 17:03:47 -0700323 final boolean hasChargingTime = chargingTimeRemaining > 0;
Adrian Roos12c1ef52014-06-04 13:54:08 +0200324
Adrian Roos7b043112015-07-10 13:00:33 -0700325 int chargingId;
326 switch (mChargingSpeed) {
327 case KeyguardUpdateMonitor.BatteryStatus.CHARGING_FAST:
Adrian Roos7e39e592015-09-23 17:03:47 -0700328 chargingId = hasChargingTime
Adrian Roosf142cac2015-09-25 15:15:17 -0700329 ? R.string.keyguard_indication_charging_time_fast
Adrian Roos7e39e592015-09-23 17:03:47 -0700330 : R.string.keyguard_plugged_in_charging_fast;
Adrian Roos7b043112015-07-10 13:00:33 -0700331 break;
332 case KeyguardUpdateMonitor.BatteryStatus.CHARGING_SLOWLY:
Adrian Roos7e39e592015-09-23 17:03:47 -0700333 chargingId = hasChargingTime
Adrian Roosf142cac2015-09-25 15:15:17 -0700334 ? R.string.keyguard_indication_charging_time_slowly
Adrian Roos7e39e592015-09-23 17:03:47 -0700335 : R.string.keyguard_plugged_in_charging_slowly;
Adrian Roos7b043112015-07-10 13:00:33 -0700336 break;
337 default:
Adrian Roos7e39e592015-09-23 17:03:47 -0700338 chargingId = hasChargingTime
339 ? R.string.keyguard_indication_charging_time
340 : R.string.keyguard_plugged_in;
Adrian Roos7b043112015-07-10 13:00:33 -0700341 break;
342 }
Adrian Roos7e39e592015-09-23 17:03:47 -0700343
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 Roos12c1ef52014-06-04 13:54:08 +0200351 }
352
Zachary Iqbalf50284c2017-01-22 18:54:46 -0800353 public void setStatusBarKeyguardViewManager(
354 StatusBarKeyguardViewManager statusBarKeyguardViewManager) {
355 mStatusBarKeyguardViewManager = statusBarKeyguardViewManager;
356 }
357
Adrian Roosaf45b602017-03-14 13:10:25 -0700358 private final BroadcastReceiver mTickReceiver = new BroadcastReceiver() {
Zachary Iqbalf50284c2017-01-22 18:54:46 -0800359 @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 Roosc1b50322017-02-27 21:07:58 +0100372 if (msg.what == MSG_HIDE_TRANSIENT) {
373 hideTransientIndication();
Zachary Iqbalf50284c2017-01-22 18:54:46 -0800374 } else if (msg.what == MSG_CLEAR_FP_MSG) {
375 mLockIcon.setTransientFpError(false);
376 hideTransientIndication();
377 }
378 }
379 };
380
Adrian Roos91ba3072017-02-14 16:50:46 +0100381 public void setDozing(boolean dozing) {
Jorim Jaggifabc7432017-05-15 02:40:05 +0200382 if (mDozing == dozing) {
383 return;
384 }
Adrian Roos91ba3072017-02-14 16:50:46 +0100385 mDozing = dozing;
386 updateIndication();
387 updateDisclosure();
388 }
389
Zachary Iqbalf50284c2017-01-22 18:54:46 -0800390 protected class BaseKeyguardCallback extends KeyguardUpdateMonitorCallback {
Adrian Roos56021892017-02-27 20:25:09 +0100391 public static final int HIDE_DELAY_MS = 5000;
Zachary Iqbalf50284c2017-01-22 18:54:46 -0800392 private int mLastSuccessiveErrorMessage = -1;
Selim Cinek3e451942016-07-14 18:07:53 -0700393
Adrian Roos12c1ef52014-06-04 13:54:08 +0200394 @Override
395 public void onRefreshBatteryInfo(KeyguardUpdateMonitor.BatteryStatus status) {
Adrian Roosad3bc7f2014-10-30 18:29:38 +0100396 boolean isChargingOrFull = status.status == BatteryManager.BATTERY_STATUS_CHARGING
Adrian Roos12c1ef52014-06-04 13:54:08 +0200397 || status.status == BatteryManager.BATTERY_STATUS_FULL;
Adrian Roos56021892017-02-27 20:25:09 +0100398 boolean wasPluggedIn = mPowerPluggedIn;
Adrian Roosad3bc7f2014-10-30 18:29:38 +0100399 mPowerPluggedIn = status.isPluggedIn() && isChargingOrFull;
Adrian Roos12c1ef52014-06-04 13:54:08 +0200400 mPowerCharged = status.isCharged();
Adrian Roos0c859ae2015-11-23 16:47:50 -0800401 mChargingWattage = status.maxChargingWattage;
Adrian Roos7b043112015-07-10 13:00:33 -0700402 mChargingSpeed = status.getChargingSpeed(mSlowThreshold, mFastThreshold);
Adrian Roos12c1ef52014-06-04 13:54:08 +0200403 updateIndication();
Adrian Roosc1b50322017-02-27 21:07:58 +0100404 if (mDozing) {
405 if (!wasPluggedIn && mPowerPluggedIn) {
406 showTransientIndication(computePowerIndication());
407 hideTransientIndicationDelayed(HIDE_DELAY_MS);
408 } else if (wasPluggedIn && !mPowerPluggedIn) {
409 hideTransientIndication();
410 }
Adrian Roos56021892017-02-27 20:25:09 +0100411 }
Adrian Roos12c1ef52014-06-04 13:54:08 +0200412 }
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700413
414 @Override
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100415 public void onKeyguardVisibilityChanged(boolean showing) {
416 if (showing) {
417 updateDisclosure();
418 }
419 }
420
421 @Override
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700422 public void onFingerprintHelp(int msgId, String helpString) {
423 KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
424 if (!updateMonitor.isUnlockingWithFingerprintAllowed()) {
425 return;
426 }
Jason Monk58be7a62017-02-01 20:17:51 -0500427 int errorColor = Utils.getColorError(mContext);
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700428 if (mStatusBarKeyguardViewManager.isBouncerShowing()) {
429 mStatusBarKeyguardViewManager.showBouncerMessage(helpString, errorColor);
Adrian Roos91ba3072017-02-14 16:50:46 +0100430 } else if (updateMonitor.isDeviceInteractive()
431 || mDozing && updateMonitor.isScreenOn()) {
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700432 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 Cinek3e451942016-07-14 18:07:53 -0700438 // 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 Cinekcfafe4e2015-08-11 14:58:44 -0700441 }
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 Monk58be7a62017-02-01 20:17:51 -0500450 int errorColor = Utils.getColorError(mContext);
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700451 if (mStatusBarKeyguardViewManager.isBouncerShowing()) {
Selim Cinek3e451942016-07-14 18:07:53 -0700452 // 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 Cinekcfafe4e2015-08-11 14:58:44 -0700459 } else if (updateMonitor.isDeviceInteractive()) {
Selim Cinek3e451942016-07-14 18:07:53 -0700460 showTransientIndication(errString, errorColor);
461 // We want to keep this message around in case the screen was off
Adrian Roos56021892017-02-27 20:25:09 +0100462 hideTransientIndicationDelayed(HIDE_DELAY_MS);
Selim Cinek3e451942016-07-14 18:07:53 -0700463 } else {
464 mMessageToShowOnScreenOn = errString;
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700465 }
Selim Cinek3e451942016-07-14 18:07:53 -0700466 mLastSuccessiveErrorMessage = msgId;
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700467 }
468
469 @Override
470 public void onScreenTurnedOn() {
471 if (mMessageToShowOnScreenOn != null) {
Jason Monk58be7a62017-02-01 20:17:51 -0500472 int errorColor = Utils.getColorError(mContext);
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700473 showTransientIndication(mMessageToShowOnScreenOn, errorColor);
474 // We want to keep this message around in case the screen was off
Adrian Roos56021892017-02-27 20:25:09 +0100475 hideTransientIndicationDelayed(HIDE_DELAY_MS);
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700476 mMessageToShowOnScreenOn = null;
477 }
478 }
479
480 @Override
481 public void onFingerprintRunningStateChanged(boolean running) {
482 if (running) {
483 mMessageToShowOnScreenOn = null;
484 }
485 }
Selim Cinek3e451942016-07-14 18:07:53 -0700486
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 Jaggidadafd42016-09-30 07:20:25 -0700498
499 @Override
500 public void onUserUnlocked() {
501 if (mVisible) {
502 updateIndication();
503 }
504 }
Adrian Roos12c1ef52014-06-04 13:54:08 +0200505 };
Adrian Roos12c1ef52014-06-04 13:54:08 +0200506}