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 | |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 19 | import android.app.admin.DevicePolicyManager; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 20 | import android.content.BroadcastReceiver; |
| 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
| 23 | import android.content.IntentFilter; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 24 | import android.content.res.Resources; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 25 | import android.graphics.Color; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 26 | import android.hardware.fingerprint.FingerprintManager; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 27 | import android.os.BatteryManager; |
| 28 | import android.os.BatteryStats; |
| 29 | import android.os.Handler; |
| 30 | import android.os.Message; |
| 31 | import android.os.RemoteException; |
| 32 | import android.os.ServiceManager; |
| 33 | import android.os.UserHandle; |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 34 | import android.os.UserManager; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 35 | import android.text.TextUtils; |
| 36 | import android.text.format.Formatter; |
| 37 | import android.util.Log; |
| 38 | import android.view.View; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 39 | import android.view.ViewGroup; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 40 | |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 41 | import com.android.internal.annotations.VisibleForTesting; |
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; |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 52 | import com.android.systemui.util.wakelock.SettableWakeLock; |
| 53 | import com.android.systemui.util.wakelock.WakeLock; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 54 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 55 | /** |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 56 | * Controls the indications and error messages shown on the Keyguard |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 57 | */ |
| 58 | public class KeyguardIndicationController { |
| 59 | |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 60 | private static final String TAG = "KeyguardIndication"; |
| 61 | private static final boolean DEBUG_CHARGING_SPEED = false; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 62 | |
| 63 | private static final int MSG_HIDE_TRANSIENT = 1; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 64 | private static final int MSG_CLEAR_FP_MSG = 2; |
| 65 | private static final long TRANSIENT_FP_ERROR_TIMEOUT = 1300; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 66 | |
| 67 | private final Context mContext; |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 68 | private ViewGroup mIndicationArea; |
| 69 | private KeyguardIndicationTextView mTextView; |
| 70 | private KeyguardIndicationTextView mDisclosure; |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 71 | private final UserManager mUserManager; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 72 | private final IBatteryStats mBatteryInfo; |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 73 | private final SettableWakeLock mWakeLock; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 74 | |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 75 | private final int mSlowThreshold; |
| 76 | private final int mFastThreshold; |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 77 | private LockIcon mLockIcon; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 78 | private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 79 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 80 | private String mRestingIndication; |
| 81 | private String mTransientIndication; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 82 | private int mTransientTextColor; |
Lucas Dupin | 53d5062 | 2017-05-13 15:54:14 -0700 | [diff] [blame] | 83 | private int mInitialTextColor; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 84 | private boolean mVisible; |
| 85 | |
| 86 | private boolean mPowerPluggedIn; |
| 87 | private boolean mPowerCharged; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 88 | private int mChargingSpeed; |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 89 | private int mChargingWattage; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 90 | private String mMessageToShowOnScreenOn; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 91 | |
Zachary Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 92 | private KeyguardUpdateMonitorCallback mUpdateMonitorCallback; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 93 | |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 94 | private final DevicePolicyManager mDevicePolicyManager; |
Adrian Roos | 91ba307 | 2017-02-14 16:50:46 +0100 | [diff] [blame] | 95 | private boolean mDozing; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 96 | |
Adrian Roos | af45b60 | 2017-03-14 13:10:25 -0700 | [diff] [blame] | 97 | /** |
| 98 | * Creates a new KeyguardIndicationController and registers callbacks. |
| 99 | */ |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 100 | public KeyguardIndicationController(Context context, ViewGroup indicationArea, |
| 101 | LockIcon lockIcon) { |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 102 | this(context, indicationArea, lockIcon, |
| 103 | WakeLock.createPartial(context, "Doze:KeyguardIndication")); |
Adrian Roos | af45b60 | 2017-03-14 13:10:25 -0700 | [diff] [blame] | 104 | |
| 105 | registerCallbacks(KeyguardUpdateMonitor.getInstance(context)); |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 106 | } |
| 107 | |
Adrian Roos | af45b60 | 2017-03-14 13:10:25 -0700 | [diff] [blame] | 108 | /** |
| 109 | * Creates a new KeyguardIndicationController for testing. Does *not* register callbacks. |
| 110 | */ |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 111 | @VisibleForTesting |
| 112 | KeyguardIndicationController(Context context, ViewGroup indicationArea, LockIcon lockIcon, |
| 113 | WakeLock wakeLock) { |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 114 | mContext = context; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 115 | mIndicationArea = indicationArea; |
| 116 | mTextView = (KeyguardIndicationTextView) indicationArea.findViewById( |
| 117 | R.id.keyguard_indication_text); |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 118 | mInitialTextColor = mTextView != null ? mTextView.getCurrentTextColor() : Color.WHITE; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 119 | mDisclosure = (KeyguardIndicationTextView) indicationArea.findViewById( |
| 120 | R.id.keyguard_indication_enterprise_disclosure); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 121 | mLockIcon = lockIcon; |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 122 | mWakeLock = new SettableWakeLock(wakeLock); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 123 | |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 124 | Resources res = context.getResources(); |
| 125 | mSlowThreshold = res.getInteger(R.integer.config_chargingSlowlyThreshold); |
| 126 | mFastThreshold = res.getInteger(R.integer.config_chargingFastThreshold); |
| 127 | |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 128 | mUserManager = context.getSystemService(UserManager.class); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 129 | mBatteryInfo = IBatteryStats.Stub.asInterface( |
| 130 | ServiceManager.getService(BatteryStats.SERVICE_NAME)); |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 131 | |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 132 | mDevicePolicyManager = (DevicePolicyManager) context.getSystemService( |
| 133 | Context.DEVICE_POLICY_SERVICE); |
| 134 | |
Adrian Roos | af45b60 | 2017-03-14 13:10:25 -0700 | [diff] [blame] | 135 | updateDisclosure(); |
| 136 | } |
| 137 | |
| 138 | private void registerCallbacks(KeyguardUpdateMonitor monitor) { |
| 139 | monitor.registerCallback(getKeyguardCallback()); |
| 140 | |
| 141 | mContext.registerReceiverAsUser(mTickReceiver, UserHandle.SYSTEM, |
Jason Monk | cd26af7 | 2017-01-11 14:32:58 -0500 | [diff] [blame] | 142 | new IntentFilter(Intent.ACTION_TIME_TICK), null, |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 143 | Dependency.get(Dependency.TIME_TICK_HANDLER)); |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 144 | } |
| 145 | |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 146 | /** |
| 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 Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 157 | if (mUpdateMonitorCallback == null) { |
| 158 | mUpdateMonitorCallback = new BaseKeyguardCallback(); |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 159 | } |
Zachary Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 160 | return mUpdateMonitorCallback; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 161 | } |
| 162 | |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 163 | private void updateDisclosure() { |
| 164 | if (mDevicePolicyManager == null) { |
| 165 | return; |
| 166 | } |
| 167 | |
Adrian Roos | 91ba307 | 2017-02-14 16:50:46 +0100 | [diff] [blame] | 168 | if (!mDozing && mDevicePolicyManager.isDeviceManaged()) { |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 169 | 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 Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | public void setVisible(boolean visible) { |
| 184 | mVisible = visible; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 185 | mIndicationArea.setVisibility(visible ? View.VISIBLE : View.GONE); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 186 | 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 Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 201 | * Sets the active controller managing changes and callbacks to user information. |
| 202 | */ |
| 203 | public void setUserInfoController(UserInfoController userInfoController) { |
| 204 | } |
| 205 | |
| 206 | /** |
Zachary Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 207 | * 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 Iqbal | dc05aa0 | 2017-05-17 18:52:49 -0700 | [diff] [blame] | 211 | 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 Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 221 | return null; |
| 222 | } |
| 223 | |
| 224 | /** |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 225 | * 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 Dupin | 53d5062 | 2017-05-13 15:54:14 -0700 | [diff] [blame] | 243 | showTransientIndication(transientIndication, mInitialTextColor); |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}. |
| 248 | */ |
| 249 | public void showTransientIndication(String transientIndication, int textColor) { |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 250 | mTransientIndication = transientIndication; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 251 | mTransientTextColor = textColor; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 252 | mHandler.removeMessages(MSG_HIDE_TRANSIENT); |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 253 | 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 Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 258 | 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 Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 272 | protected final void updateIndication() { |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 273 | if (TextUtils.isEmpty(mTransientIndication)) { |
| 274 | mWakeLock.setAcquired(false); |
| 275 | } |
| 276 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 277 | if (mVisible) { |
Lucas Dupin | 53d5062 | 2017-05-13 15:54:14 -0700 | [diff] [blame] | 278 | // Walk down a precedence-ordered list of what indication |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 279 | // should be shown based on user or device state |
Adrian Roos | 91ba307 | 2017-02-14 16:50:46 +0100 | [diff] [blame] | 280 | if (mDozing) { |
| 281 | // If we're dozing, never show a persistent indication. |
| 282 | if (!TextUtils.isEmpty(mTransientIndication)) { |
Adrian Roos | 12e112d | 2017-07-25 16:46:23 +0200 | [diff] [blame] | 283 | // 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 Roos | 91ba307 | 2017-02-14 16:50:46 +0100 | [diff] [blame] | 286 | mTextView.switchIndication(mTransientIndication); |
Adrian Roos | 91ba307 | 2017-02-14 16:50:46 +0100 | [diff] [blame] | 287 | } else { |
| 288 | mTextView.switchIndication(null); |
| 289 | } |
| 290 | return; |
| 291 | } |
| 292 | |
Zachary Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 293 | KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext); |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 294 | int userId = KeyguardUpdateMonitor.getCurrentUser(); |
Zachary Iqbal | dc05aa0 | 2017-05-17 18:52:49 -0700 | [diff] [blame] | 295 | String trustGrantedIndication = getTrustGrantedIndication(); |
| 296 | String trustManagedIndication = getTrustManagedIndication(); |
Zachary Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 297 | if (!mUserManager.isUserUnlocked(userId)) { |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 298 | mTextView.switchIndication(com.android.internal.R.string.lockscreen_storage_locked); |
Lucas Dupin | 53d5062 | 2017-05-13 15:54:14 -0700 | [diff] [blame] | 299 | mTextView.setTextColor(mInitialTextColor); |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 300 | } else if (!TextUtils.isEmpty(mTransientIndication)) { |
| 301 | mTextView.switchIndication(mTransientIndication); |
| 302 | mTextView.setTextColor(mTransientTextColor); |
Zachary Iqbal | dc05aa0 | 2017-05-17 18:52:49 -0700 | [diff] [blame] | 303 | } else if (!TextUtils.isEmpty(trustGrantedIndication) |
Zachary Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 304 | && updateMonitor.getUserHasTrust(userId)) { |
Zachary Iqbal | dc05aa0 | 2017-05-17 18:52:49 -0700 | [diff] [blame] | 305 | mTextView.switchIndication(trustGrantedIndication); |
Lucas Dupin | 53d5062 | 2017-05-13 15:54:14 -0700 | [diff] [blame] | 306 | mTextView.setTextColor(mInitialTextColor); |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 307 | } else if (mPowerPluggedIn) { |
| 308 | String indication = computePowerIndication(); |
| 309 | if (DEBUG_CHARGING_SPEED) { |
| 310 | indication += ", " + (mChargingWattage / 1000) + " mW"; |
| 311 | } |
| 312 | mTextView.switchIndication(indication); |
Lucas Dupin | 53d5062 | 2017-05-13 15:54:14 -0700 | [diff] [blame] | 313 | mTextView.setTextColor(mInitialTextColor); |
Zachary Iqbal | dc05aa0 | 2017-05-17 18:52:49 -0700 | [diff] [blame] | 314 | } else if (!TextUtils.isEmpty(trustManagedIndication) |
| 315 | && updateMonitor.getUserTrustIsManaged(userId) |
| 316 | && !updateMonitor.getUserHasTrust(userId)) { |
| 317 | mTextView.switchIndication(trustManagedIndication); |
Lucas Dupin | 53d5062 | 2017-05-13 15:54:14 -0700 | [diff] [blame] | 318 | mTextView.setTextColor(mInitialTextColor); |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 319 | } else { |
| 320 | mTextView.switchIndication(mRestingIndication); |
Lucas Dupin | 53d5062 | 2017-05-13 15:54:14 -0700 | [diff] [blame] | 321 | mTextView.setTextColor(mInitialTextColor); |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 322 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 323 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 324 | } |
| 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 Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 332 | long chargingTimeRemaining = 0; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 333 | try { |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 334 | chargingTimeRemaining = mBatteryInfo.computeChargeTimeRemaining(); |
| 335 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 336 | } catch (RemoteException e) { |
| 337 | Log.e(TAG, "Error calling IBatteryStats: ", e); |
| 338 | } |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 339 | final boolean hasChargingTime = chargingTimeRemaining > 0; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 340 | |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 341 | int chargingId; |
| 342 | switch (mChargingSpeed) { |
| 343 | case KeyguardUpdateMonitor.BatteryStatus.CHARGING_FAST: |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 344 | chargingId = hasChargingTime |
Adrian Roos | f142cac | 2015-09-25 15:15:17 -0700 | [diff] [blame] | 345 | ? R.string.keyguard_indication_charging_time_fast |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 346 | : R.string.keyguard_plugged_in_charging_fast; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 347 | break; |
| 348 | case KeyguardUpdateMonitor.BatteryStatus.CHARGING_SLOWLY: |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 349 | chargingId = hasChargingTime |
Adrian Roos | f142cac | 2015-09-25 15:15:17 -0700 | [diff] [blame] | 350 | ? R.string.keyguard_indication_charging_time_slowly |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 351 | : R.string.keyguard_plugged_in_charging_slowly; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 352 | break; |
| 353 | default: |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 354 | chargingId = hasChargingTime |
| 355 | ? R.string.keyguard_indication_charging_time |
| 356 | : R.string.keyguard_plugged_in; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 357 | break; |
| 358 | } |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 359 | |
| 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 Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 367 | } |
| 368 | |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 369 | public void setStatusBarKeyguardViewManager( |
| 370 | StatusBarKeyguardViewManager statusBarKeyguardViewManager) { |
| 371 | mStatusBarKeyguardViewManager = statusBarKeyguardViewManager; |
| 372 | } |
| 373 | |
Adrian Roos | af45b60 | 2017-03-14 13:10:25 -0700 | [diff] [blame] | 374 | private final BroadcastReceiver mTickReceiver = new BroadcastReceiver() { |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 375 | @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 Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 388 | if (msg.what == MSG_HIDE_TRANSIENT) { |
| 389 | hideTransientIndication(); |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 390 | } else if (msg.what == MSG_CLEAR_FP_MSG) { |
| 391 | mLockIcon.setTransientFpError(false); |
| 392 | hideTransientIndication(); |
| 393 | } |
| 394 | } |
| 395 | }; |
| 396 | |
Adrian Roos | 91ba307 | 2017-02-14 16:50:46 +0100 | [diff] [blame] | 397 | public void setDozing(boolean dozing) { |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 398 | if (mDozing == dozing) { |
| 399 | return; |
| 400 | } |
Adrian Roos | 91ba307 | 2017-02-14 16:50:46 +0100 | [diff] [blame] | 401 | mDozing = dozing; |
| 402 | updateIndication(); |
| 403 | updateDisclosure(); |
| 404 | } |
| 405 | |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 406 | protected class BaseKeyguardCallback extends KeyguardUpdateMonitorCallback { |
Adrian Roos | 5602189 | 2017-02-27 20:25:09 +0100 | [diff] [blame] | 407 | public static final int HIDE_DELAY_MS = 5000; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 408 | private int mLastSuccessiveErrorMessage = -1; |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 409 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 410 | @Override |
| 411 | public void onRefreshBatteryInfo(KeyguardUpdateMonitor.BatteryStatus status) { |
Adrian Roos | ad3bc7f | 2014-10-30 18:29:38 +0100 | [diff] [blame] | 412 | boolean isChargingOrFull = status.status == BatteryManager.BATTERY_STATUS_CHARGING |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 413 | || status.status == BatteryManager.BATTERY_STATUS_FULL; |
Adrian Roos | 5602189 | 2017-02-27 20:25:09 +0100 | [diff] [blame] | 414 | boolean wasPluggedIn = mPowerPluggedIn; |
Adrian Roos | ad3bc7f | 2014-10-30 18:29:38 +0100 | [diff] [blame] | 415 | mPowerPluggedIn = status.isPluggedIn() && isChargingOrFull; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 416 | mPowerCharged = status.isCharged(); |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 417 | mChargingWattage = status.maxChargingWattage; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 418 | mChargingSpeed = status.getChargingSpeed(mSlowThreshold, mFastThreshold); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 419 | updateIndication(); |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 420 | if (mDozing) { |
| 421 | if (!wasPluggedIn && mPowerPluggedIn) { |
| 422 | showTransientIndication(computePowerIndication()); |
| 423 | hideTransientIndicationDelayed(HIDE_DELAY_MS); |
| 424 | } else if (wasPluggedIn && !mPowerPluggedIn) { |
| 425 | hideTransientIndication(); |
| 426 | } |
Adrian Roos | 5602189 | 2017-02-27 20:25:09 +0100 | [diff] [blame] | 427 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 428 | } |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 429 | |
| 430 | @Override |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 431 | public void onKeyguardVisibilityChanged(boolean showing) { |
| 432 | if (showing) { |
| 433 | updateDisclosure(); |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | @Override |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 438 | public void onFingerprintHelp(int msgId, String helpString) { |
| 439 | KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext); |
| 440 | if (!updateMonitor.isUnlockingWithFingerprintAllowed()) { |
| 441 | return; |
| 442 | } |
Jason Monk | 58be7a6 | 2017-02-01 20:17:51 -0500 | [diff] [blame] | 443 | int errorColor = Utils.getColorError(mContext); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 444 | if (mStatusBarKeyguardViewManager.isBouncerShowing()) { |
| 445 | mStatusBarKeyguardViewManager.showBouncerMessage(helpString, errorColor); |
Adrian Roos | 91ba307 | 2017-02-14 16:50:46 +0100 | [diff] [blame] | 446 | } else if (updateMonitor.isDeviceInteractive() |
| 447 | || mDozing && updateMonitor.isScreenOn()) { |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 448 | 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 Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 454 | // 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 Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 457 | } |
| 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 Monk | 58be7a6 | 2017-02-01 20:17:51 -0500 | [diff] [blame] | 466 | int errorColor = Utils.getColorError(mContext); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 467 | if (mStatusBarKeyguardViewManager.isBouncerShowing()) { |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 468 | // 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 Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 475 | } else if (updateMonitor.isDeviceInteractive()) { |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 476 | showTransientIndication(errString, errorColor); |
| 477 | // We want to keep this message around in case the screen was off |
Adrian Roos | 5602189 | 2017-02-27 20:25:09 +0100 | [diff] [blame] | 478 | hideTransientIndicationDelayed(HIDE_DELAY_MS); |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 479 | } else { |
| 480 | mMessageToShowOnScreenOn = errString; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 481 | } |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 482 | mLastSuccessiveErrorMessage = msgId; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | @Override |
| 486 | public void onScreenTurnedOn() { |
| 487 | if (mMessageToShowOnScreenOn != null) { |
Jason Monk | 58be7a6 | 2017-02-01 20:17:51 -0500 | [diff] [blame] | 488 | int errorColor = Utils.getColorError(mContext); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 489 | showTransientIndication(mMessageToShowOnScreenOn, errorColor); |
| 490 | // We want to keep this message around in case the screen was off |
Adrian Roos | 5602189 | 2017-02-27 20:25:09 +0100 | [diff] [blame] | 491 | hideTransientIndicationDelayed(HIDE_DELAY_MS); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 492 | mMessageToShowOnScreenOn = null; |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | @Override |
| 497 | public void onFingerprintRunningStateChanged(boolean running) { |
| 498 | if (running) { |
| 499 | mMessageToShowOnScreenOn = null; |
| 500 | } |
| 501 | } |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 502 | |
| 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 Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 514 | |
| 515 | @Override |
| 516 | public void onUserUnlocked() { |
| 517 | if (mVisible) { |
| 518 | updateIndication(); |
| 519 | } |
| 520 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 521 | }; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 522 | } |