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 | |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 42 | import com.android.internal.app.IBatteryStats; |
| 43 | import com.android.keyguard.KeyguardUpdateMonitor; |
| 44 | import com.android.keyguard.KeyguardUpdateMonitorCallback; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame^] | 45 | import com.android.systemui.Dependency; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 46 | import com.android.systemui.R; |
| 47 | import com.android.systemui.statusbar.phone.KeyguardIndicationTextView; |
| 48 | import com.android.systemui.statusbar.phone.LockIcon; |
| 49 | import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; |
| 50 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 51 | /** |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 52 | * Controls the indications and error messages shown on the Keyguard |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 53 | */ |
| 54 | public class KeyguardIndicationController { |
| 55 | |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 56 | private static final String TAG = "KeyguardIndication"; |
| 57 | private static final boolean DEBUG_CHARGING_SPEED = false; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 58 | |
| 59 | private static final int MSG_HIDE_TRANSIENT = 1; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 60 | private static final int MSG_CLEAR_FP_MSG = 2; |
| 61 | private static final long TRANSIENT_FP_ERROR_TIMEOUT = 1300; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 62 | |
| 63 | private final Context mContext; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 64 | private final ViewGroup mIndicationArea; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 65 | private final KeyguardIndicationTextView mTextView; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 66 | private final KeyguardIndicationTextView mDisclosure; |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 67 | private final UserManager mUserManager; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 68 | private final IBatteryStats mBatteryInfo; |
| 69 | |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 70 | private final int mSlowThreshold; |
| 71 | private final int mFastThreshold; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 72 | private final LockIcon mLockIcon; |
| 73 | private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 74 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 75 | private String mRestingIndication; |
| 76 | private String mTransientIndication; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 77 | private int mTransientTextColor; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 78 | private boolean mVisible; |
| 79 | |
| 80 | private boolean mPowerPluggedIn; |
| 81 | private boolean mPowerCharged; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 82 | private int mChargingSpeed; |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 83 | private int mChargingWattage; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 84 | private String mMessageToShowOnScreenOn; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 85 | |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 86 | private final DevicePolicyManager mDevicePolicyManager; |
| 87 | |
| 88 | public KeyguardIndicationController(Context context, ViewGroup indicationArea, |
| 89 | LockIcon lockIcon) { |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 90 | mContext = context; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 91 | mIndicationArea = indicationArea; |
| 92 | mTextView = (KeyguardIndicationTextView) indicationArea.findViewById( |
| 93 | R.id.keyguard_indication_text); |
| 94 | mDisclosure = (KeyguardIndicationTextView) indicationArea.findViewById( |
| 95 | R.id.keyguard_indication_enterprise_disclosure); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 96 | mLockIcon = lockIcon; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 97 | |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 98 | Resources res = context.getResources(); |
| 99 | mSlowThreshold = res.getInteger(R.integer.config_chargingSlowlyThreshold); |
| 100 | mFastThreshold = res.getInteger(R.integer.config_chargingFastThreshold); |
| 101 | |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 102 | mUserManager = context.getSystemService(UserManager.class); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 103 | mBatteryInfo = IBatteryStats.Stub.asInterface( |
| 104 | ServiceManager.getService(BatteryStats.SERVICE_NAME)); |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 105 | |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 106 | mDevicePolicyManager = (DevicePolicyManager) context.getSystemService( |
| 107 | Context.DEVICE_POLICY_SERVICE); |
| 108 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 109 | KeyguardUpdateMonitor.getInstance(context).registerCallback(mUpdateMonitor); |
Jeff Sharkey | 99e1bca | 2016-08-23 16:32:03 -0600 | [diff] [blame] | 110 | context.registerReceiverAsUser(mTickReceiver, UserHandle.SYSTEM, |
Jason Monk | cd26af7 | 2017-01-11 14:32:58 -0500 | [diff] [blame] | 111 | new IntentFilter(Intent.ACTION_TIME_TICK), null, |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame^] | 112 | Dependency.get(Dependency.TIME_TICK_HANDLER)); |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 113 | |
| 114 | updateDisclosure(); |
| 115 | } |
| 116 | |
| 117 | private void updateDisclosure() { |
| 118 | if (mDevicePolicyManager == null) { |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | if (mDevicePolicyManager.isDeviceManaged()) { |
| 123 | final CharSequence organizationName = |
| 124 | mDevicePolicyManager.getDeviceOwnerOrganizationName(); |
| 125 | if (organizationName != null) { |
| 126 | mDisclosure.switchIndication(mContext.getResources().getString( |
| 127 | R.string.do_disclosure_with_name, organizationName)); |
| 128 | } else { |
| 129 | mDisclosure.switchIndication(R.string.do_disclosure_generic); |
| 130 | } |
| 131 | mDisclosure.setVisibility(View.VISIBLE); |
| 132 | } else { |
| 133 | mDisclosure.setVisibility(View.GONE); |
| 134 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | public void setVisible(boolean visible) { |
| 138 | mVisible = visible; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 139 | mIndicationArea.setVisibility(visible ? View.VISIBLE : View.GONE); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 140 | if (visible) { |
| 141 | hideTransientIndication(); |
| 142 | updateIndication(); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Sets the indication that is shown if nothing else is showing. |
| 148 | */ |
| 149 | public void setRestingIndication(String restingIndication) { |
| 150 | mRestingIndication = restingIndication; |
| 151 | updateIndication(); |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Hides transient indication in {@param delayMs}. |
| 156 | */ |
| 157 | public void hideTransientIndicationDelayed(long delayMs) { |
| 158 | mHandler.sendMessageDelayed( |
| 159 | mHandler.obtainMessage(MSG_HIDE_TRANSIENT), delayMs); |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}. |
| 164 | */ |
| 165 | public void showTransientIndication(int transientIndication) { |
| 166 | showTransientIndication(mContext.getResources().getString(transientIndication)); |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}. |
| 171 | */ |
| 172 | public void showTransientIndication(String transientIndication) { |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 173 | showTransientIndication(transientIndication, Color.WHITE); |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}. |
| 178 | */ |
| 179 | public void showTransientIndication(String transientIndication, int textColor) { |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 180 | mTransientIndication = transientIndication; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 181 | mTransientTextColor = textColor; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 182 | mHandler.removeMessages(MSG_HIDE_TRANSIENT); |
| 183 | updateIndication(); |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Hides transient indication. |
| 188 | */ |
| 189 | public void hideTransientIndication() { |
| 190 | if (mTransientIndication != null) { |
| 191 | mTransientIndication = null; |
| 192 | mHandler.removeMessages(MSG_HIDE_TRANSIENT); |
| 193 | updateIndication(); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | private void updateIndication() { |
| 198 | if (mVisible) { |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 199 | // Walk down a precedence-ordered list of what should indication |
| 200 | // should be shown based on user or device state |
| 201 | if (!mUserManager.isUserUnlocked(ActivityManager.getCurrentUser())) { |
| 202 | mTextView.switchIndication(com.android.internal.R.string.lockscreen_storage_locked); |
| 203 | mTextView.setTextColor(Color.WHITE); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 204 | |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 205 | } else if (!TextUtils.isEmpty(mTransientIndication)) { |
| 206 | mTextView.switchIndication(mTransientIndication); |
| 207 | mTextView.setTextColor(mTransientTextColor); |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 208 | |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 209 | } else if (mPowerPluggedIn) { |
| 210 | String indication = computePowerIndication(); |
| 211 | if (DEBUG_CHARGING_SPEED) { |
| 212 | indication += ", " + (mChargingWattage / 1000) + " mW"; |
| 213 | } |
| 214 | mTextView.switchIndication(indication); |
| 215 | mTextView.setTextColor(Color.WHITE); |
| 216 | |
| 217 | } else { |
| 218 | mTextView.switchIndication(mRestingIndication); |
| 219 | mTextView.setTextColor(Color.WHITE); |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 220 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 221 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | private String computePowerIndication() { |
| 225 | if (mPowerCharged) { |
| 226 | return mContext.getResources().getString(R.string.keyguard_charged); |
| 227 | } |
| 228 | |
| 229 | // Try fetching charging time from battery stats. |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 230 | long chargingTimeRemaining = 0; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 231 | try { |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 232 | chargingTimeRemaining = mBatteryInfo.computeChargeTimeRemaining(); |
| 233 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 234 | } catch (RemoteException e) { |
| 235 | Log.e(TAG, "Error calling IBatteryStats: ", e); |
| 236 | } |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 237 | final boolean hasChargingTime = chargingTimeRemaining > 0; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 238 | |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 239 | int chargingId; |
| 240 | switch (mChargingSpeed) { |
| 241 | case KeyguardUpdateMonitor.BatteryStatus.CHARGING_FAST: |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 242 | chargingId = hasChargingTime |
Adrian Roos | f142cac | 2015-09-25 15:15:17 -0700 | [diff] [blame] | 243 | ? R.string.keyguard_indication_charging_time_fast |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 244 | : R.string.keyguard_plugged_in_charging_fast; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 245 | break; |
| 246 | case KeyguardUpdateMonitor.BatteryStatus.CHARGING_SLOWLY: |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 247 | chargingId = hasChargingTime |
Adrian Roos | f142cac | 2015-09-25 15:15:17 -0700 | [diff] [blame] | 248 | ? R.string.keyguard_indication_charging_time_slowly |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 249 | : R.string.keyguard_plugged_in_charging_slowly; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 250 | break; |
| 251 | default: |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 252 | chargingId = hasChargingTime |
| 253 | ? R.string.keyguard_indication_charging_time |
| 254 | : R.string.keyguard_plugged_in; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 255 | break; |
| 256 | } |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 257 | |
| 258 | if (hasChargingTime) { |
| 259 | String chargingTimeFormatted = Formatter.formatShortElapsedTimeRoundingUpToMinutes( |
| 260 | mContext, chargingTimeRemaining); |
| 261 | return mContext.getResources().getString(chargingId, chargingTimeFormatted); |
| 262 | } else { |
| 263 | return mContext.getResources().getString(chargingId); |
| 264 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | KeyguardUpdateMonitorCallback mUpdateMonitor = new KeyguardUpdateMonitorCallback() { |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 268 | public int mLastSuccessiveErrorMessage = -1; |
| 269 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 270 | @Override |
| 271 | public void onRefreshBatteryInfo(KeyguardUpdateMonitor.BatteryStatus status) { |
Adrian Roos | ad3bc7f | 2014-10-30 18:29:38 +0100 | [diff] [blame] | 272 | boolean isChargingOrFull = status.status == BatteryManager.BATTERY_STATUS_CHARGING |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 273 | || status.status == BatteryManager.BATTERY_STATUS_FULL; |
Adrian Roos | ad3bc7f | 2014-10-30 18:29:38 +0100 | [diff] [blame] | 274 | mPowerPluggedIn = status.isPluggedIn() && isChargingOrFull; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 275 | mPowerCharged = status.isCharged(); |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 276 | mChargingWattage = status.maxChargingWattage; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 277 | mChargingSpeed = status.getChargingSpeed(mSlowThreshold, mFastThreshold); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 278 | updateIndication(); |
| 279 | } |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 280 | |
| 281 | @Override |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 282 | public void onKeyguardVisibilityChanged(boolean showing) { |
| 283 | if (showing) { |
| 284 | updateDisclosure(); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | @Override |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 289 | public void onFingerprintHelp(int msgId, String helpString) { |
| 290 | KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext); |
| 291 | if (!updateMonitor.isUnlockingWithFingerprintAllowed()) { |
| 292 | return; |
| 293 | } |
| 294 | int errorColor = mContext.getResources().getColor(R.color.system_warning_color, null); |
| 295 | if (mStatusBarKeyguardViewManager.isBouncerShowing()) { |
| 296 | mStatusBarKeyguardViewManager.showBouncerMessage(helpString, errorColor); |
| 297 | } else if (updateMonitor.isDeviceInteractive()) { |
| 298 | mLockIcon.setTransientFpError(true); |
| 299 | showTransientIndication(helpString, errorColor); |
| 300 | mHandler.removeMessages(MSG_CLEAR_FP_MSG); |
| 301 | mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_CLEAR_FP_MSG), |
| 302 | TRANSIENT_FP_ERROR_TIMEOUT); |
| 303 | } |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 304 | // Help messages indicate that there was actually a try since the last error, so those |
| 305 | // are not two successive error messages anymore. |
| 306 | mLastSuccessiveErrorMessage = -1; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | @Override |
| 310 | public void onFingerprintError(int msgId, String errString) { |
| 311 | KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext); |
| 312 | if (!updateMonitor.isUnlockingWithFingerprintAllowed() |
| 313 | || msgId == FingerprintManager.FINGERPRINT_ERROR_CANCELED) { |
| 314 | return; |
| 315 | } |
| 316 | int errorColor = mContext.getResources().getColor(R.color.system_warning_color, null); |
| 317 | if (mStatusBarKeyguardViewManager.isBouncerShowing()) { |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 318 | // When swiping up right after receiving a fingerprint error, the bouncer calls |
| 319 | // authenticate leading to the same message being shown again on the bouncer. |
| 320 | // We want to avoid this, as it may confuse the user when the message is too |
| 321 | // generic. |
| 322 | if (mLastSuccessiveErrorMessage != msgId) { |
| 323 | mStatusBarKeyguardViewManager.showBouncerMessage(errString, errorColor); |
| 324 | } |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 325 | } else if (updateMonitor.isDeviceInteractive()) { |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 326 | showTransientIndication(errString, errorColor); |
| 327 | // We want to keep this message around in case the screen was off |
| 328 | mHandler.removeMessages(MSG_HIDE_TRANSIENT); |
| 329 | hideTransientIndicationDelayed(5000); |
| 330 | } else { |
| 331 | mMessageToShowOnScreenOn = errString; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 332 | } |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 333 | mLastSuccessiveErrorMessage = msgId; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | @Override |
| 337 | public void onScreenTurnedOn() { |
| 338 | if (mMessageToShowOnScreenOn != null) { |
| 339 | int errorColor = mContext.getResources().getColor(R.color.system_warning_color, |
| 340 | null); |
| 341 | showTransientIndication(mMessageToShowOnScreenOn, errorColor); |
| 342 | // We want to keep this message around in case the screen was off |
| 343 | mHandler.removeMessages(MSG_HIDE_TRANSIENT); |
| 344 | hideTransientIndicationDelayed(5000); |
| 345 | mMessageToShowOnScreenOn = null; |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | @Override |
| 350 | public void onFingerprintRunningStateChanged(boolean running) { |
| 351 | if (running) { |
| 352 | mMessageToShowOnScreenOn = null; |
| 353 | } |
| 354 | } |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 355 | |
| 356 | @Override |
| 357 | public void onFingerprintAuthenticated(int userId) { |
| 358 | super.onFingerprintAuthenticated(userId); |
| 359 | mLastSuccessiveErrorMessage = -1; |
| 360 | } |
| 361 | |
| 362 | @Override |
| 363 | public void onFingerprintAuthFailed() { |
| 364 | super.onFingerprintAuthFailed(); |
| 365 | mLastSuccessiveErrorMessage = -1; |
| 366 | } |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 367 | |
| 368 | @Override |
| 369 | public void onUserUnlocked() { |
| 370 | if (mVisible) { |
| 371 | updateIndication(); |
| 372 | } |
| 373 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 374 | }; |
| 375 | |
Jeff Sharkey | 99e1bca | 2016-08-23 16:32:03 -0600 | [diff] [blame] | 376 | BroadcastReceiver mTickReceiver = new BroadcastReceiver() { |
| 377 | @Override |
| 378 | public void onReceive(Context context, Intent intent) { |
Jason Monk | cd26af7 | 2017-01-11 14:32:58 -0500 | [diff] [blame] | 379 | mHandler.post(() -> { |
| 380 | if (mVisible) { |
| 381 | updateIndication(); |
| 382 | } |
| 383 | }); |
Jeff Sharkey | 99e1bca | 2016-08-23 16:32:03 -0600 | [diff] [blame] | 384 | } |
| 385 | }; |
| 386 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 387 | |
| 388 | private final Handler mHandler = new Handler() { |
| 389 | @Override |
| 390 | public void handleMessage(Message msg) { |
| 391 | if (msg.what == MSG_HIDE_TRANSIENT && mTransientIndication != null) { |
| 392 | mTransientIndication = null; |
| 393 | updateIndication(); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 394 | } else if (msg.what == MSG_CLEAR_FP_MSG) { |
| 395 | mLockIcon.setTransientFpError(false); |
| 396 | hideTransientIndication(); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | }; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 400 | |
| 401 | public void setStatusBarKeyguardViewManager( |
| 402 | StatusBarKeyguardViewManager statusBarKeyguardViewManager) { |
| 403 | mStatusBarKeyguardViewManager = statusBarKeyguardViewManager; |
| 404 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 405 | } |