blob: 74737c4c2948101b4ba693c46d2b232716ba2b13 [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
Bartosz Fabianowski5f045002016-12-01 10:36:18 +010019import android.app.admin.DevicePolicyManager;
Adrian Roos12c1ef52014-06-04 13:54:08 +020020import android.content.BroadcastReceiver;
21import android.content.Context;
22import android.content.Intent;
23import android.content.IntentFilter;
Adrian Roos7b043112015-07-10 13:00:33 -070024import android.content.res.Resources;
Jorim Jaggi27c9b742015-04-09 10:34:49 -070025import android.graphics.Color;
Selim Cinekcfafe4e2015-08-11 14:58:44 -070026import android.hardware.fingerprint.FingerprintManager;
Adrian Roos12c1ef52014-06-04 13:54:08 +020027import android.os.BatteryManager;
28import android.os.BatteryStats;
29import android.os.Handler;
30import android.os.Message;
31import android.os.RemoteException;
32import android.os.ServiceManager;
33import android.os.UserHandle;
Jeff Sharkeyb6edaa92016-07-27 15:51:31 -060034import android.os.UserManager;
Adrian Roos12c1ef52014-06-04 13:54:08 +020035import android.text.TextUtils;
36import android.text.format.Formatter;
37import android.util.Log;
38import android.view.View;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +010039import android.view.ViewGroup;
Adrian Roos12c1ef52014-06-04 13:54:08 +020040
Adrian Roosc1b50322017-02-27 21:07:58 +010041import com.android.internal.annotations.VisibleForTesting;
Selim Cinekcfafe4e2015-08-11 14:58:44 -070042import com.android.internal.app.IBatteryStats;
43import com.android.keyguard.KeyguardUpdateMonitor;
44import com.android.keyguard.KeyguardUpdateMonitorCallback;
Jason Monk58be7a62017-02-01 20:17:51 -050045import com.android.settingslib.Utils;
Jason Monk9c7844c2017-01-18 15:21:53 -050046import com.android.systemui.Dependency;
Selim Cinekcfafe4e2015-08-11 14:58:44 -070047import com.android.systemui.R;
48import com.android.systemui.statusbar.phone.KeyguardIndicationTextView;
49import com.android.systemui.statusbar.phone.LockIcon;
50import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
Zachary Iqbalf50284c2017-01-22 18:54:46 -080051import com.android.systemui.statusbar.policy.UserInfoController;
Adrian Roosc1b50322017-02-27 21:07:58 +010052import com.android.systemui.util.wakelock.SettableWakeLock;
53import com.android.systemui.util.wakelock.WakeLock;
Selim Cinekcfafe4e2015-08-11 14:58:44 -070054
Adrian Roos12c1ef52014-06-04 13:54:08 +020055/**
Selim Cinekcfafe4e2015-08-11 14:58:44 -070056 * Controls the indications and error messages shown on the Keyguard
Adrian Roos12c1ef52014-06-04 13:54:08 +020057 */
58public class KeyguardIndicationController {
59
Adrian Roos0c859ae2015-11-23 16:47:50 -080060 private static final String TAG = "KeyguardIndication";
61 private static final boolean DEBUG_CHARGING_SPEED = false;
Adrian Roos12c1ef52014-06-04 13:54:08 +020062
63 private static final int MSG_HIDE_TRANSIENT = 1;
Selim Cinekcfafe4e2015-08-11 14:58:44 -070064 private static final int MSG_CLEAR_FP_MSG = 2;
65 private static final long TRANSIENT_FP_ERROR_TIMEOUT = 1300;
Adrian Roos12c1ef52014-06-04 13:54:08 +020066
67 private final Context mContext;
Lucas Dupin987f1932017-05-13 21:02:52 -070068 private ViewGroup mIndicationArea;
69 private KeyguardIndicationTextView mTextView;
70 private KeyguardIndicationTextView mDisclosure;
Jeff Sharkeyb6edaa92016-07-27 15:51:31 -060071 private final UserManager mUserManager;
Adrian Roos12c1ef52014-06-04 13:54:08 +020072 private final IBatteryStats mBatteryInfo;
Adrian Roosc1b50322017-02-27 21:07:58 +010073 private final SettableWakeLock mWakeLock;
Adrian Roos12c1ef52014-06-04 13:54:08 +020074
Adrian Roos7b043112015-07-10 13:00:33 -070075 private final int mSlowThreshold;
76 private final int mFastThreshold;
Lucas Dupin987f1932017-05-13 21:02:52 -070077 private LockIcon mLockIcon;
Selim Cinekcfafe4e2015-08-11 14:58:44 -070078 private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
Adrian Roos7b043112015-07-10 13:00:33 -070079
Adrian Roos12c1ef52014-06-04 13:54:08 +020080 private String mRestingIndication;
81 private String mTransientIndication;
Jorim Jaggi27c9b742015-04-09 10:34:49 -070082 private int mTransientTextColor;
Lucas Dupin53d50622017-05-13 15:54:14 -070083 private int mInitialTextColor;
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);
Lucas Dupin987f1932017-05-13 21:02:52 -0700118 mInitialTextColor = mTextView != null ? mTextView.getCurrentTextColor() : Color.WHITE;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100119 mDisclosure = (KeyguardIndicationTextView) indicationArea.findViewById(
120 R.id.keyguard_indication_enterprise_disclosure);
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700121 mLockIcon = lockIcon;
Adrian Roosc1b50322017-02-27 21:07:58 +0100122 mWakeLock = new SettableWakeLock(wakeLock);
Adrian Roos12c1ef52014-06-04 13:54:08 +0200123
Adrian Roos7b043112015-07-10 13:00:33 -0700124 Resources res = context.getResources();
125 mSlowThreshold = res.getInteger(R.integer.config_chargingSlowlyThreshold);
126 mFastThreshold = res.getInteger(R.integer.config_chargingFastThreshold);
127
Jeff Sharkeyb6edaa92016-07-27 15:51:31 -0600128 mUserManager = context.getSystemService(UserManager.class);
Adrian Roos12c1ef52014-06-04 13:54:08 +0200129 mBatteryInfo = IBatteryStats.Stub.asInterface(
130 ServiceManager.getService(BatteryStats.SERVICE_NAME));
Jeff Sharkeyb6edaa92016-07-27 15:51:31 -0600131
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100132 mDevicePolicyManager = (DevicePolicyManager) context.getSystemService(
133 Context.DEVICE_POLICY_SERVICE);
134
Adrian Roosaf45b602017-03-14 13:10:25 -0700135 updateDisclosure();
136 }
137
138 private void registerCallbacks(KeyguardUpdateMonitor monitor) {
139 monitor.registerCallback(getKeyguardCallback());
140
141 mContext.registerReceiverAsUser(mTickReceiver, UserHandle.SYSTEM,
Jason Monkcd26af72017-01-11 14:32:58 -0500142 new IntentFilter(Intent.ACTION_TIME_TICK), null,
Jason Monk9c7844c2017-01-18 15:21:53 -0500143 Dependency.get(Dependency.TIME_TICK_HANDLER));
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100144 }
145
Zachary Iqbalf50284c2017-01-22 18:54:46 -0800146 /**
147 * Gets the {@link KeyguardUpdateMonitorCallback} instance associated with this
148 * {@link KeyguardIndicationController}.
149 *
150 * <p>Subclasses may override this method to extend or change the callback behavior by extending
151 * the {@link BaseKeyguardCallback}.
152 *
153 * @return A KeyguardUpdateMonitorCallback. Multiple calls to this method <b>must</b> return the
154 * same instance.
155 */
156 protected KeyguardUpdateMonitorCallback getKeyguardCallback() {
Zachary Iqbal8f4c2422017-04-20 17:56:42 -0700157 if (mUpdateMonitorCallback == null) {
158 mUpdateMonitorCallback = new BaseKeyguardCallback();
Zachary Iqbalf50284c2017-01-22 18:54:46 -0800159 }
Zachary Iqbal8f4c2422017-04-20 17:56:42 -0700160 return mUpdateMonitorCallback;
Zachary Iqbalf50284c2017-01-22 18:54:46 -0800161 }
162
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100163 private void updateDisclosure() {
164 if (mDevicePolicyManager == null) {
165 return;
166 }
167
Adrian Roos91ba3072017-02-14 16:50:46 +0100168 if (!mDozing && mDevicePolicyManager.isDeviceManaged()) {
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100169 final CharSequence organizationName =
170 mDevicePolicyManager.getDeviceOwnerOrganizationName();
171 if (organizationName != null) {
172 mDisclosure.switchIndication(mContext.getResources().getString(
173 R.string.do_disclosure_with_name, organizationName));
174 } else {
175 mDisclosure.switchIndication(R.string.do_disclosure_generic);
176 }
177 mDisclosure.setVisibility(View.VISIBLE);
178 } else {
179 mDisclosure.setVisibility(View.GONE);
180 }
Adrian Roos12c1ef52014-06-04 13:54:08 +0200181 }
182
183 public void setVisible(boolean visible) {
184 mVisible = visible;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100185 mIndicationArea.setVisibility(visible ? View.VISIBLE : View.GONE);
Adrian Roos12c1ef52014-06-04 13:54:08 +0200186 if (visible) {
187 hideTransientIndication();
188 updateIndication();
189 }
190 }
191
192 /**
193 * Sets the indication that is shown if nothing else is showing.
194 */
195 public void setRestingIndication(String restingIndication) {
196 mRestingIndication = restingIndication;
197 updateIndication();
198 }
199
200 /**
Zachary Iqbalf50284c2017-01-22 18:54:46 -0800201 * Sets the active controller managing changes and callbacks to user information.
202 */
203 public void setUserInfoController(UserInfoController userInfoController) {
204 }
205
206 /**
Zachary Iqbal8f4c2422017-04-20 17:56:42 -0700207 * Returns the indication text indicating that trust has been granted.
208 *
209 * @return {@code null} or an empty string if a trust indication text should not be shown.
210 */
Zachary Iqbaldc05aa02017-05-17 18:52:49 -0700211 protected String getTrustGrantedIndication() {
212 return null;
213 }
214
215 /**
216 * Returns the indication text indicating that trust is currently being managed.
217 *
218 * @return {@code null} or an empty string if a trust managed text should not be shown.
219 */
220 protected String getTrustManagedIndication() {
Zachary Iqbal8f4c2422017-04-20 17:56:42 -0700221 return null;
222 }
223
224 /**
Adrian Roos12c1ef52014-06-04 13:54:08 +0200225 * Hides transient indication in {@param delayMs}.
226 */
227 public void hideTransientIndicationDelayed(long delayMs) {
228 mHandler.sendMessageDelayed(
229 mHandler.obtainMessage(MSG_HIDE_TRANSIENT), delayMs);
230 }
231
232 /**
233 * Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}.
234 */
235 public void showTransientIndication(int transientIndication) {
236 showTransientIndication(mContext.getResources().getString(transientIndication));
237 }
238
239 /**
240 * Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}.
241 */
242 public void showTransientIndication(String transientIndication) {
Lucas Dupin53d50622017-05-13 15:54:14 -0700243 showTransientIndication(transientIndication, mInitialTextColor);
Jorim Jaggi27c9b742015-04-09 10:34:49 -0700244 }
245
246 /**
247 * Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}.
248 */
249 public void showTransientIndication(String transientIndication, int textColor) {
Adrian Roos12c1ef52014-06-04 13:54:08 +0200250 mTransientIndication = transientIndication;
Jorim Jaggi27c9b742015-04-09 10:34:49 -0700251 mTransientTextColor = textColor;
Adrian Roos12c1ef52014-06-04 13:54:08 +0200252 mHandler.removeMessages(MSG_HIDE_TRANSIENT);
Adrian Roosc1b50322017-02-27 21:07:58 +0100253 if (mDozing && !TextUtils.isEmpty(mTransientIndication)) {
254 // Make sure this doesn't get stuck and burns in. Acquire wakelock until its cleared.
255 mWakeLock.setAcquired(true);
256 hideTransientIndicationDelayed(BaseKeyguardCallback.HIDE_DELAY_MS);
257 }
Adrian Roos12c1ef52014-06-04 13:54:08 +0200258 updateIndication();
259 }
260
261 /**
262 * Hides transient indication.
263 */
264 public void hideTransientIndication() {
265 if (mTransientIndication != null) {
266 mTransientIndication = null;
267 mHandler.removeMessages(MSG_HIDE_TRANSIENT);
268 updateIndication();
269 }
270 }
271
Zachary Iqbal8f4c2422017-04-20 17:56:42 -0700272 protected final void updateIndication() {
Adrian Roosc1b50322017-02-27 21:07:58 +0100273 if (TextUtils.isEmpty(mTransientIndication)) {
274 mWakeLock.setAcquired(false);
275 }
276
Adrian Roos12c1ef52014-06-04 13:54:08 +0200277 if (mVisible) {
Lucas Dupin53d50622017-05-13 15:54:14 -0700278 // Walk down a precedence-ordered list of what indication
Jeff Sharkeyb6edaa92016-07-27 15:51:31 -0600279 // should be shown based on user or device state
Adrian Roos91ba3072017-02-14 16:50:46 +0100280 if (mDozing) {
281 // If we're dozing, never show a persistent indication.
282 if (!TextUtils.isEmpty(mTransientIndication)) {
Adrian Roos12e112d2017-07-25 16:46:23 +0200283 // When dozing we ignore any text color and use white instead, because
284 // colors can be hard to read in low brightness.
285 mTextView.setTextColor(Color.WHITE);
Adrian Roos91ba3072017-02-14 16:50:46 +0100286 mTextView.switchIndication(mTransientIndication);
Adrian Roos91ba3072017-02-14 16:50:46 +0100287 } else {
288 mTextView.switchIndication(null);
289 }
290 return;
291 }
292
Zachary Iqbal8f4c2422017-04-20 17:56:42 -0700293 KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
Jorim Jaggifabc7432017-05-15 02:40:05 +0200294 int userId = KeyguardUpdateMonitor.getCurrentUser();
Zachary Iqbaldc05aa02017-05-17 18:52:49 -0700295 String trustGrantedIndication = getTrustGrantedIndication();
296 String trustManagedIndication = getTrustManagedIndication();
Zachary Iqbal8f4c2422017-04-20 17:56:42 -0700297 if (!mUserManager.isUserUnlocked(userId)) {
Jeff Sharkeyb6edaa92016-07-27 15:51:31 -0600298 mTextView.switchIndication(com.android.internal.R.string.lockscreen_storage_locked);
Lucas Dupin53d50622017-05-13 15:54:14 -0700299 mTextView.setTextColor(mInitialTextColor);
Jeff Sharkeyb6edaa92016-07-27 15:51:31 -0600300 } else if (!TextUtils.isEmpty(mTransientIndication)) {
301 mTextView.switchIndication(mTransientIndication);
302 mTextView.setTextColor(mTransientTextColor);
Zachary Iqbaldc05aa02017-05-17 18:52:49 -0700303 } else if (!TextUtils.isEmpty(trustGrantedIndication)
Zachary Iqbal8f4c2422017-04-20 17:56:42 -0700304 && updateMonitor.getUserHasTrust(userId)) {
Zachary Iqbaldc05aa02017-05-17 18:52:49 -0700305 mTextView.switchIndication(trustGrantedIndication);
Lucas Dupin53d50622017-05-13 15:54:14 -0700306 mTextView.setTextColor(mInitialTextColor);
Jeff Sharkeyb6edaa92016-07-27 15:51:31 -0600307 } else if (mPowerPluggedIn) {
308 String indication = computePowerIndication();
309 if (DEBUG_CHARGING_SPEED) {
310 indication += ", " + (mChargingWattage / 1000) + " mW";
311 }
312 mTextView.switchIndication(indication);
Lucas Dupin53d50622017-05-13 15:54:14 -0700313 mTextView.setTextColor(mInitialTextColor);
Zachary Iqbaldc05aa02017-05-17 18:52:49 -0700314 } else if (!TextUtils.isEmpty(trustManagedIndication)
315 && updateMonitor.getUserTrustIsManaged(userId)
316 && !updateMonitor.getUserHasTrust(userId)) {
317 mTextView.switchIndication(trustManagedIndication);
Lucas Dupin53d50622017-05-13 15:54:14 -0700318 mTextView.setTextColor(mInitialTextColor);
Jeff Sharkeyb6edaa92016-07-27 15:51:31 -0600319 } else {
320 mTextView.switchIndication(mRestingIndication);
Lucas Dupin53d50622017-05-13 15:54:14 -0700321 mTextView.setTextColor(mInitialTextColor);
Adrian Roos7b043112015-07-10 13:00:33 -0700322 }
Adrian Roos12c1ef52014-06-04 13:54:08 +0200323 }
Adrian Roos12c1ef52014-06-04 13:54:08 +0200324 }
325
326 private String computePowerIndication() {
327 if (mPowerCharged) {
328 return mContext.getResources().getString(R.string.keyguard_charged);
329 }
330
331 // Try fetching charging time from battery stats.
Adrian Roos7e39e592015-09-23 17:03:47 -0700332 long chargingTimeRemaining = 0;
Adrian Roos12c1ef52014-06-04 13:54:08 +0200333 try {
Adrian Roos7e39e592015-09-23 17:03:47 -0700334 chargingTimeRemaining = mBatteryInfo.computeChargeTimeRemaining();
335
Adrian Roos12c1ef52014-06-04 13:54:08 +0200336 } catch (RemoteException e) {
337 Log.e(TAG, "Error calling IBatteryStats: ", e);
338 }
Adrian Roos7e39e592015-09-23 17:03:47 -0700339 final boolean hasChargingTime = chargingTimeRemaining > 0;
Adrian Roos12c1ef52014-06-04 13:54:08 +0200340
Adrian Roos7b043112015-07-10 13:00:33 -0700341 int chargingId;
342 switch (mChargingSpeed) {
343 case KeyguardUpdateMonitor.BatteryStatus.CHARGING_FAST:
Adrian Roos7e39e592015-09-23 17:03:47 -0700344 chargingId = hasChargingTime
Adrian Roosf142cac2015-09-25 15:15:17 -0700345 ? R.string.keyguard_indication_charging_time_fast
Adrian Roos7e39e592015-09-23 17:03:47 -0700346 : R.string.keyguard_plugged_in_charging_fast;
Adrian Roos7b043112015-07-10 13:00:33 -0700347 break;
348 case KeyguardUpdateMonitor.BatteryStatus.CHARGING_SLOWLY:
Adrian Roos7e39e592015-09-23 17:03:47 -0700349 chargingId = hasChargingTime
Adrian Roosf142cac2015-09-25 15:15:17 -0700350 ? R.string.keyguard_indication_charging_time_slowly
Adrian Roos7e39e592015-09-23 17:03:47 -0700351 : R.string.keyguard_plugged_in_charging_slowly;
Adrian Roos7b043112015-07-10 13:00:33 -0700352 break;
353 default:
Adrian Roos7e39e592015-09-23 17:03:47 -0700354 chargingId = hasChargingTime
355 ? R.string.keyguard_indication_charging_time
356 : R.string.keyguard_plugged_in;
Adrian Roos7b043112015-07-10 13:00:33 -0700357 break;
358 }
Adrian Roos7e39e592015-09-23 17:03:47 -0700359
360 if (hasChargingTime) {
361 String chargingTimeFormatted = Formatter.formatShortElapsedTimeRoundingUpToMinutes(
362 mContext, chargingTimeRemaining);
363 return mContext.getResources().getString(chargingId, chargingTimeFormatted);
364 } else {
365 return mContext.getResources().getString(chargingId);
366 }
Adrian Roos12c1ef52014-06-04 13:54:08 +0200367 }
368
Zachary Iqbalf50284c2017-01-22 18:54:46 -0800369 public void setStatusBarKeyguardViewManager(
370 StatusBarKeyguardViewManager statusBarKeyguardViewManager) {
371 mStatusBarKeyguardViewManager = statusBarKeyguardViewManager;
372 }
373
Adrian Roosaf45b602017-03-14 13:10:25 -0700374 private final BroadcastReceiver mTickReceiver = new BroadcastReceiver() {
Zachary Iqbalf50284c2017-01-22 18:54:46 -0800375 @Override
376 public void onReceive(Context context, Intent intent) {
377 mHandler.post(() -> {
378 if (mVisible) {
379 updateIndication();
380 }
381 });
382 }
383 };
384
385 private final Handler mHandler = new Handler() {
386 @Override
387 public void handleMessage(Message msg) {
Adrian Roosc1b50322017-02-27 21:07:58 +0100388 if (msg.what == MSG_HIDE_TRANSIENT) {
389 hideTransientIndication();
Zachary Iqbalf50284c2017-01-22 18:54:46 -0800390 } else if (msg.what == MSG_CLEAR_FP_MSG) {
391 mLockIcon.setTransientFpError(false);
392 hideTransientIndication();
393 }
394 }
395 };
396
Adrian Roos91ba3072017-02-14 16:50:46 +0100397 public void setDozing(boolean dozing) {
Jorim Jaggifabc7432017-05-15 02:40:05 +0200398 if (mDozing == dozing) {
399 return;
400 }
Adrian Roos91ba3072017-02-14 16:50:46 +0100401 mDozing = dozing;
402 updateIndication();
403 updateDisclosure();
404 }
405
Zachary Iqbalf50284c2017-01-22 18:54:46 -0800406 protected class BaseKeyguardCallback extends KeyguardUpdateMonitorCallback {
Adrian Roos56021892017-02-27 20:25:09 +0100407 public static final int HIDE_DELAY_MS = 5000;
Zachary Iqbalf50284c2017-01-22 18:54:46 -0800408 private int mLastSuccessiveErrorMessage = -1;
Selim Cinek3e451942016-07-14 18:07:53 -0700409
Adrian Roos12c1ef52014-06-04 13:54:08 +0200410 @Override
411 public void onRefreshBatteryInfo(KeyguardUpdateMonitor.BatteryStatus status) {
Adrian Roosad3bc7f2014-10-30 18:29:38 +0100412 boolean isChargingOrFull = status.status == BatteryManager.BATTERY_STATUS_CHARGING
Adrian Roos12c1ef52014-06-04 13:54:08 +0200413 || status.status == BatteryManager.BATTERY_STATUS_FULL;
Adrian Roos56021892017-02-27 20:25:09 +0100414 boolean wasPluggedIn = mPowerPluggedIn;
Adrian Roosad3bc7f2014-10-30 18:29:38 +0100415 mPowerPluggedIn = status.isPluggedIn() && isChargingOrFull;
Adrian Roos12c1ef52014-06-04 13:54:08 +0200416 mPowerCharged = status.isCharged();
Adrian Roos0c859ae2015-11-23 16:47:50 -0800417 mChargingWattage = status.maxChargingWattage;
Adrian Roos7b043112015-07-10 13:00:33 -0700418 mChargingSpeed = status.getChargingSpeed(mSlowThreshold, mFastThreshold);
Adrian Roos12c1ef52014-06-04 13:54:08 +0200419 updateIndication();
Adrian Roosc1b50322017-02-27 21:07:58 +0100420 if (mDozing) {
421 if (!wasPluggedIn && mPowerPluggedIn) {
422 showTransientIndication(computePowerIndication());
423 hideTransientIndicationDelayed(HIDE_DELAY_MS);
424 } else if (wasPluggedIn && !mPowerPluggedIn) {
425 hideTransientIndication();
426 }
Adrian Roos56021892017-02-27 20:25:09 +0100427 }
Adrian Roos12c1ef52014-06-04 13:54:08 +0200428 }
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700429
430 @Override
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100431 public void onKeyguardVisibilityChanged(boolean showing) {
432 if (showing) {
433 updateDisclosure();
434 }
435 }
436
437 @Override
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700438 public void onFingerprintHelp(int msgId, String helpString) {
439 KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
440 if (!updateMonitor.isUnlockingWithFingerprintAllowed()) {
441 return;
442 }
Jason Monk58be7a62017-02-01 20:17:51 -0500443 int errorColor = Utils.getColorError(mContext);
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700444 if (mStatusBarKeyguardViewManager.isBouncerShowing()) {
445 mStatusBarKeyguardViewManager.showBouncerMessage(helpString, errorColor);
Adrian Roos91ba3072017-02-14 16:50:46 +0100446 } else if (updateMonitor.isDeviceInteractive()
447 || mDozing && updateMonitor.isScreenOn()) {
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700448 mLockIcon.setTransientFpError(true);
449 showTransientIndication(helpString, errorColor);
450 mHandler.removeMessages(MSG_CLEAR_FP_MSG);
451 mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_CLEAR_FP_MSG),
452 TRANSIENT_FP_ERROR_TIMEOUT);
453 }
Selim Cinek3e451942016-07-14 18:07:53 -0700454 // Help messages indicate that there was actually a try since the last error, so those
455 // are not two successive error messages anymore.
456 mLastSuccessiveErrorMessage = -1;
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700457 }
458
459 @Override
460 public void onFingerprintError(int msgId, String errString) {
461 KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
462 if (!updateMonitor.isUnlockingWithFingerprintAllowed()
463 || msgId == FingerprintManager.FINGERPRINT_ERROR_CANCELED) {
464 return;
465 }
Jason Monk58be7a62017-02-01 20:17:51 -0500466 int errorColor = Utils.getColorError(mContext);
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700467 if (mStatusBarKeyguardViewManager.isBouncerShowing()) {
Selim Cinek3e451942016-07-14 18:07:53 -0700468 // When swiping up right after receiving a fingerprint error, the bouncer calls
469 // authenticate leading to the same message being shown again on the bouncer.
470 // We want to avoid this, as it may confuse the user when the message is too
471 // generic.
472 if (mLastSuccessiveErrorMessage != msgId) {
473 mStatusBarKeyguardViewManager.showBouncerMessage(errString, errorColor);
474 }
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700475 } else if (updateMonitor.isDeviceInteractive()) {
Selim Cinek3e451942016-07-14 18:07:53 -0700476 showTransientIndication(errString, errorColor);
477 // We want to keep this message around in case the screen was off
Adrian Roos56021892017-02-27 20:25:09 +0100478 hideTransientIndicationDelayed(HIDE_DELAY_MS);
Selim Cinek3e451942016-07-14 18:07:53 -0700479 } else {
480 mMessageToShowOnScreenOn = errString;
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700481 }
Selim Cinek3e451942016-07-14 18:07:53 -0700482 mLastSuccessiveErrorMessage = msgId;
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700483 }
484
485 @Override
486 public void onScreenTurnedOn() {
487 if (mMessageToShowOnScreenOn != null) {
Jason Monk58be7a62017-02-01 20:17:51 -0500488 int errorColor = Utils.getColorError(mContext);
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700489 showTransientIndication(mMessageToShowOnScreenOn, errorColor);
490 // We want to keep this message around in case the screen was off
Adrian Roos56021892017-02-27 20:25:09 +0100491 hideTransientIndicationDelayed(HIDE_DELAY_MS);
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700492 mMessageToShowOnScreenOn = null;
493 }
494 }
495
496 @Override
497 public void onFingerprintRunningStateChanged(boolean running) {
498 if (running) {
499 mMessageToShowOnScreenOn = null;
500 }
501 }
Selim Cinek3e451942016-07-14 18:07:53 -0700502
503 @Override
504 public void onFingerprintAuthenticated(int userId) {
505 super.onFingerprintAuthenticated(userId);
506 mLastSuccessiveErrorMessage = -1;
507 }
508
509 @Override
510 public void onFingerprintAuthFailed() {
511 super.onFingerprintAuthFailed();
512 mLastSuccessiveErrorMessage = -1;
513 }
Jorim Jaggidadafd42016-09-30 07:20:25 -0700514
515 @Override
516 public void onUserUnlocked() {
517 if (mVisible) {
518 updateIndication();
519 }
520 }
Adrian Roos12c1ef52014-06-04 13:54:08 +0200521 };
Adrian Roos12c1ef52014-06-04 13:54:08 +0200522}