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