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 DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 19 | import static com.android.systemui.DejankUtils.whitelistIpcs; |
| 20 | |
Beverly | 8c78589 | 2018-01-31 17:25:52 -0500 | [diff] [blame] | 21 | import android.animation.Animator; |
| 22 | import android.animation.AnimatorListenerAdapter; |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 23 | import android.app.admin.DevicePolicyManager; |
| 24 | import android.content.BroadcastReceiver; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 25 | import android.content.Context; |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 26 | import android.content.Intent; |
| 27 | import android.content.IntentFilter; |
arangelov | c00bd0c | 2020-06-19 17:13:59 +0100 | [diff] [blame] | 28 | import android.content.pm.UserInfo; |
Jason Chang | 2386a37 | 2018-04-24 16:05:30 +0800 | [diff] [blame] | 29 | import android.content.res.ColorStateList; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 30 | import android.graphics.Color; |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 31 | import android.hardware.biometrics.BiometricSourceType; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 32 | import android.hardware.face.FaceManager; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 33 | import android.hardware.fingerprint.FingerprintManager; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 34 | import android.os.BatteryManager; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 35 | import android.os.Handler; |
| 36 | import android.os.Message; |
| 37 | import android.os.RemoteException; |
arangelov | c00bd0c | 2020-06-19 17:13:59 +0100 | [diff] [blame] | 38 | import android.os.UserHandle; |
| 39 | import android.os.UserManager; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 40 | import android.text.TextUtils; |
| 41 | import android.text.format.Formatter; |
| 42 | import android.util.Log; |
| 43 | import android.view.View; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 44 | import android.view.ViewGroup; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 45 | |
arangelov | c00bd0c | 2020-06-19 17:13:59 +0100 | [diff] [blame] | 46 | import androidx.annotation.Nullable; |
| 47 | |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 48 | import com.android.internal.annotations.VisibleForTesting; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 49 | import com.android.internal.app.IBatteryStats; |
Lucas Dupin | eff8ef0 | 2019-06-06 11:14:01 -0700 | [diff] [blame] | 50 | import com.android.internal.widget.ViewClippingUtil; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 51 | import com.android.keyguard.KeyguardUpdateMonitor; |
| 52 | import com.android.keyguard.KeyguardUpdateMonitorCallback; |
Jason Monk | 58be7a6 | 2017-02-01 20:17:51 -0500 | [diff] [blame] | 53 | import com.android.settingslib.Utils; |
Raff Tsai | f4ea562 | 2019-06-26 16:15:21 +0800 | [diff] [blame] | 54 | import com.android.settingslib.fuelgauge.BatteryStatus; |
Beverly | 8c78589 | 2018-01-31 17:25:52 -0500 | [diff] [blame] | 55 | import com.android.systemui.Interpolators; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 56 | import com.android.systemui.R; |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 57 | import com.android.systemui.broadcast.BroadcastDispatcher; |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 58 | import com.android.systemui.dock.DockManager; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 59 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
| 60 | import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 61 | import com.android.systemui.statusbar.phone.KeyguardIndicationTextView; |
Dave Mankoff | c0d9a7d | 2020-02-27 17:15:52 -0500 | [diff] [blame] | 62 | import com.android.systemui.statusbar.phone.LockscreenLockIconController; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 63 | import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 64 | import com.android.systemui.statusbar.policy.KeyguardStateController; |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 65 | import com.android.systemui.util.wakelock.SettableWakeLock; |
| 66 | import com.android.systemui.util.wakelock.WakeLock; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 67 | |
Lucas Dupin | 3fcdd47 | 2018-01-19 19:06:45 -0800 | [diff] [blame] | 68 | import java.io.FileDescriptor; |
| 69 | import java.io.PrintWriter; |
Lucas Dupin | 4272f44 | 2018-01-13 22:00:35 -0800 | [diff] [blame] | 70 | import java.text.NumberFormat; |
Lucas Dupin | 8d595d2 | 2018-03-08 10:34:58 -0800 | [diff] [blame] | 71 | import java.util.IllegalFormatConversionException; |
Lucas Dupin | 4272f44 | 2018-01-13 22:00:35 -0800 | [diff] [blame] | 72 | |
Dave Mankoff | c0d9a7d | 2020-02-27 17:15:52 -0500 | [diff] [blame] | 73 | import javax.inject.Inject; |
| 74 | import javax.inject.Singleton; |
| 75 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 76 | /** |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 77 | * Controls the indications and error messages shown on the Keyguard |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 78 | */ |
Dave Mankoff | c0d9a7d | 2020-02-27 17:15:52 -0500 | [diff] [blame] | 79 | @Singleton |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 80 | public class KeyguardIndicationController implements StateListener, |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 81 | KeyguardStateController.Callback { |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 82 | |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 83 | private static final String TAG = "KeyguardIndication"; |
| 84 | private static final boolean DEBUG_CHARGING_SPEED = false; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 85 | |
| 86 | private static final int MSG_HIDE_TRANSIENT = 1; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 87 | private static final int MSG_CLEAR_BIOMETRIC_MSG = 2; |
Lucas Dupin | 51996bb | 2019-05-16 17:56:43 -0700 | [diff] [blame] | 88 | private static final int MSG_SWIPE_UP_TO_UNLOCK = 3; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 89 | private static final long TRANSIENT_BIOMETRIC_ERROR_TIMEOUT = 1300; |
Robert Snoeberger | ddfb065 | 2019-06-21 16:41:46 -0400 | [diff] [blame] | 90 | private static final float BOUNCE_ANIMATION_FINAL_Y = 0f; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 91 | |
| 92 | private final Context mContext; |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 93 | private final BroadcastDispatcher mBroadcastDispatcher; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 94 | private final KeyguardStateController mKeyguardStateController; |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 95 | private final StatusBarStateController mStatusBarStateController; |
| 96 | private final KeyguardUpdateMonitor mKeyguardUpdateMonitor; |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 97 | private ViewGroup mIndicationArea; |
| 98 | private KeyguardIndicationTextView mTextView; |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 99 | private KeyguardIndicationTextView mDisclosure; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 100 | private final IBatteryStats mBatteryInfo; |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 101 | private final SettableWakeLock mWakeLock; |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 102 | private final DockManager mDockManager; |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 103 | private final DevicePolicyManager mDevicePolicyManager; |
arangelov | c00bd0c | 2020-06-19 17:13:59 +0100 | [diff] [blame] | 104 | private final UserManager mUserManager; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 105 | |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 106 | private BroadcastReceiver mBroadcastReceiver; |
Dave Mankoff | c0d9a7d | 2020-02-27 17:15:52 -0500 | [diff] [blame] | 107 | private LockscreenLockIconController mLockIconController; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 108 | private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 109 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 110 | private String mRestingIndication; |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 111 | private String mAlignmentIndication; |
Lucas Dupin | ef88654 | 2018-01-03 16:03:07 -0800 | [diff] [blame] | 112 | private CharSequence mTransientIndication; |
Lucas Dupin | aff4236 | 2020-03-27 16:28:20 -0700 | [diff] [blame] | 113 | private boolean mTransientTextIsError; |
Jason Chang | 2386a37 | 2018-04-24 16:05:30 +0800 | [diff] [blame] | 114 | private ColorStateList mInitialTextColorState; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 115 | private boolean mVisible; |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 116 | private boolean mHideTransientMessageOnScreenOff; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 117 | |
| 118 | private boolean mPowerPluggedIn; |
Beverly | 2034c83 | 2018-03-19 11:18:51 -0400 | [diff] [blame] | 119 | private boolean mPowerPluggedInWired; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 120 | private boolean mPowerCharged; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 121 | private int mChargingSpeed; |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 122 | private int mChargingWattage; |
Lucas Dupin | 4272f44 | 2018-01-13 22:00:35 -0800 | [diff] [blame] | 123 | private int mBatteryLevel; |
Lucas Dupin | 9131b28 | 2019-11-19 16:25:03 -0800 | [diff] [blame] | 124 | private long mChargingTimeRemaining; |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 125 | private float mDisclosureMaxAlpha; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 126 | private String mMessageToShowOnScreenOn; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 127 | |
Zachary Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 128 | private KeyguardUpdateMonitorCallback mUpdateMonitorCallback; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 129 | |
Adrian Roos | 91ba307 | 2017-02-14 16:50:46 +0100 | [diff] [blame] | 130 | private boolean mDozing; |
Lucas Dupin | eff8ef0 | 2019-06-06 11:14:01 -0700 | [diff] [blame] | 131 | private final ViewClippingUtil.ClippingParameters mClippingParams = |
| 132 | new ViewClippingUtil.ClippingParameters() { |
| 133 | @Override |
| 134 | public boolean shouldFinish(View view) { |
| 135 | return view == mIndicationArea; |
| 136 | } |
| 137 | }; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 138 | |
Adrian Roos | af45b60 | 2017-03-14 13:10:25 -0700 | [diff] [blame] | 139 | /** |
| 140 | * Creates a new KeyguardIndicationController and registers callbacks. |
| 141 | */ |
Dave Mankoff | c0d9a7d | 2020-02-27 17:15:52 -0500 | [diff] [blame] | 142 | @Inject |
| 143 | KeyguardIndicationController(Context context, |
| 144 | WakeLock.Builder wakeLockBuilder, |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 145 | KeyguardStateController keyguardStateController, |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 146 | StatusBarStateController statusBarStateController, |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 147 | KeyguardUpdateMonitor keyguardUpdateMonitor, |
Lucas Dupin | 9131b28 | 2019-11-19 16:25:03 -0800 | [diff] [blame] | 148 | DockManager dockManager, |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 149 | BroadcastDispatcher broadcastDispatcher, |
| 150 | DevicePolicyManager devicePolicyManager, |
arangelov | c00bd0c | 2020-06-19 17:13:59 +0100 | [diff] [blame] | 151 | IBatteryStats iBatteryStats, |
| 152 | UserManager userManager) { |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 153 | mContext = context; |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 154 | mBroadcastDispatcher = broadcastDispatcher; |
| 155 | mDevicePolicyManager = devicePolicyManager; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 156 | mKeyguardStateController = keyguardStateController; |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 157 | mStatusBarStateController = statusBarStateController; |
| 158 | mKeyguardUpdateMonitor = keyguardUpdateMonitor; |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 159 | mDockManager = dockManager; |
Wilson Wu | 0e72713 | 2019-12-26 16:17:56 +0800 | [diff] [blame] | 160 | mDockManager.addAlignmentStateListener( |
| 161 | alignState -> mHandler.post(() -> handleAlignStateChanged(alignState))); |
Dave Mankoff | c0d9a7d | 2020-02-27 17:15:52 -0500 | [diff] [blame] | 162 | mWakeLock = new SettableWakeLock( |
| 163 | wakeLockBuilder.setTag("Doze:KeyguardIndication").build(), TAG); |
Lucas Dupin | 9131b28 | 2019-11-19 16:25:03 -0800 | [diff] [blame] | 164 | mBatteryInfo = iBatteryStats; |
arangelov | c00bd0c | 2020-06-19 17:13:59 +0100 | [diff] [blame] | 165 | mUserManager = userManager; |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 166 | |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 167 | mKeyguardUpdateMonitor.registerCallback(getKeyguardCallback()); |
| 168 | mKeyguardUpdateMonitor.registerCallback(mTickReceiver); |
| 169 | mStatusBarStateController.addCallback(this); |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 170 | mKeyguardStateController.addCallback(this); |
Evan Laird | 878c853 | 2018-10-15 15:54:29 -0400 | [diff] [blame] | 171 | } |
| 172 | |
Lucas Dupin | 00ebe13 | 2019-04-26 16:17:56 -0700 | [diff] [blame] | 173 | public void setIndicationArea(ViewGroup indicationArea) { |
| 174 | mIndicationArea = indicationArea; |
| 175 | mTextView = indicationArea.findViewById(R.id.keyguard_indication_text); |
| 176 | mInitialTextColorState = mTextView != null ? |
| 177 | mTextView.getTextColors() : ColorStateList.valueOf(Color.WHITE); |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 178 | mDisclosure = indicationArea.findViewById(R.id.keyguard_indication_enterprise_disclosure); |
| 179 | mDisclosureMaxAlpha = mDisclosure.getAlpha(); |
Lucas Dupin | 00ebe13 | 2019-04-26 16:17:56 -0700 | [diff] [blame] | 180 | updateIndication(false /* animate */); |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 181 | updateDisclosure(); |
| 182 | |
| 183 | if (mBroadcastReceiver == null) { |
| 184 | // Update the disclosure proactively to avoid IPC on the critical path. |
| 185 | mBroadcastReceiver = new BroadcastReceiver() { |
| 186 | @Override |
| 187 | public void onReceive(Context context, Intent intent) { |
| 188 | updateDisclosure(); |
| 189 | } |
| 190 | }; |
arangelov | c00bd0c | 2020-06-19 17:13:59 +0100 | [diff] [blame] | 191 | IntentFilter intentFilter = new IntentFilter(); |
| 192 | intentFilter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 193 | intentFilter.addAction(Intent.ACTION_USER_REMOVED); |
| 194 | mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, intentFilter); |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 195 | } |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 196 | } |
| 197 | |
Dave Mankoff | c0d9a7d | 2020-02-27 17:15:52 -0500 | [diff] [blame] | 198 | public void setLockIconController(LockscreenLockIconController lockIconController) { |
| 199 | mLockIconController = lockIconController; |
Lucas Dupin | 0df60fe | 2019-04-23 10:19:27 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 202 | private void handleAlignStateChanged(int alignState) { |
| 203 | String alignmentIndication = ""; |
| 204 | if (alignState == DockManager.ALIGN_STATE_POOR) { |
| 205 | alignmentIndication = |
| 206 | mContext.getResources().getString(R.string.dock_alignment_slow_charging); |
| 207 | } else if (alignState == DockManager.ALIGN_STATE_TERRIBLE) { |
| 208 | alignmentIndication = |
| 209 | mContext.getResources().getString(R.string.dock_alignment_not_charging); |
| 210 | } |
| 211 | if (!alignmentIndication.equals(mAlignmentIndication)) { |
| 212 | mAlignmentIndication = alignmentIndication; |
| 213 | updateIndication(false); |
| 214 | } |
| 215 | } |
| 216 | |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 217 | /** |
| 218 | * Gets the {@link KeyguardUpdateMonitorCallback} instance associated with this |
| 219 | * {@link KeyguardIndicationController}. |
| 220 | * |
| 221 | * <p>Subclasses may override this method to extend or change the callback behavior by extending |
| 222 | * the {@link BaseKeyguardCallback}. |
| 223 | * |
| 224 | * @return A KeyguardUpdateMonitorCallback. Multiple calls to this method <b>must</b> return the |
| 225 | * same instance. |
| 226 | */ |
| 227 | protected KeyguardUpdateMonitorCallback getKeyguardCallback() { |
Zachary Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 228 | if (mUpdateMonitorCallback == null) { |
| 229 | mUpdateMonitorCallback = new BaseKeyguardCallback(); |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 230 | } |
Zachary Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 231 | return mUpdateMonitorCallback; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 232 | } |
| 233 | |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 234 | private void updateDisclosure() { |
| 235 | // NOTE: Because this uses IPC, avoid calling updateDisclosure() on a critical path. |
arangelov | c00bd0c | 2020-06-19 17:13:59 +0100 | [diff] [blame] | 236 | if (whitelistIpcs(this::isOrganizationOwnedDevice)) { |
| 237 | CharSequence organizationName = getOrganizationOwnedDeviceOrganizationName(); |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 238 | if (organizationName != null) { |
| 239 | mDisclosure.switchIndication(mContext.getResources().getString( |
| 240 | R.string.do_disclosure_with_name, organizationName)); |
| 241 | } else { |
| 242 | mDisclosure.switchIndication(R.string.do_disclosure_generic); |
| 243 | } |
| 244 | mDisclosure.setVisibility(View.VISIBLE); |
| 245 | } else { |
| 246 | mDisclosure.setVisibility(View.GONE); |
| 247 | } |
| 248 | } |
| 249 | |
arangelov | c00bd0c | 2020-06-19 17:13:59 +0100 | [diff] [blame] | 250 | private boolean isOrganizationOwnedDevice() { |
| 251 | return mDevicePolicyManager.isDeviceManaged() |
| 252 | || mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile(); |
| 253 | } |
| 254 | |
| 255 | @Nullable |
| 256 | private CharSequence getOrganizationOwnedDeviceOrganizationName() { |
| 257 | if (mDevicePolicyManager.isDeviceManaged()) { |
| 258 | return mDevicePolicyManager.getDeviceOwnerOrganizationName(); |
| 259 | } else if (mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()) { |
| 260 | return getWorkProfileOrganizationName(); |
| 261 | } |
| 262 | return null; |
| 263 | } |
| 264 | |
| 265 | private CharSequence getWorkProfileOrganizationName() { |
| 266 | final int profileId = getWorkProfileUserId(UserHandle.myUserId()); |
| 267 | if (profileId == UserHandle.USER_NULL) { |
| 268 | return null; |
| 269 | } |
| 270 | return mDevicePolicyManager.getOrganizationNameForUser(profileId); |
| 271 | } |
| 272 | |
| 273 | private int getWorkProfileUserId(int userId) { |
| 274 | for (final UserInfo userInfo : mUserManager.getProfiles(userId)) { |
| 275 | if (userInfo.isManagedProfile()) { |
| 276 | return userInfo.id; |
| 277 | } |
| 278 | } |
| 279 | return UserHandle.USER_NULL; |
| 280 | } |
| 281 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 282 | public void setVisible(boolean visible) { |
| 283 | mVisible = visible; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 284 | mIndicationArea.setVisibility(visible ? View.VISIBLE : View.GONE); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 285 | if (visible) { |
Kevin Chyn | 4c4001c | 2017-08-25 14:23:36 -0700 | [diff] [blame] | 286 | // If this is called after an error message was already shown, we should not clear it. |
| 287 | // Otherwise the error message won't be shown |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 288 | if (!mHandler.hasMessages(MSG_HIDE_TRANSIENT)) { |
Kevin Chyn | 4c4001c | 2017-08-25 14:23:36 -0700 | [diff] [blame] | 289 | hideTransientIndication(); |
| 290 | } |
Beverly | 8c78589 | 2018-01-31 17:25:52 -0500 | [diff] [blame] | 291 | updateIndication(false); |
Kevin Chyn | 4c4001c | 2017-08-25 14:23:36 -0700 | [diff] [blame] | 292 | } else if (!visible) { |
| 293 | // If we unlock and return to keyguard quickly, previous error should not be shown |
| 294 | hideTransientIndication(); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Sets the indication that is shown if nothing else is showing. |
| 300 | */ |
| 301 | public void setRestingIndication(String restingIndication) { |
| 302 | mRestingIndication = restingIndication; |
Beverly | 8c78589 | 2018-01-31 17:25:52 -0500 | [diff] [blame] | 303 | updateIndication(false); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /** |
Zachary Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 307 | * Returns the indication text indicating that trust has been granted. |
| 308 | * |
| 309 | * @return {@code null} or an empty string if a trust indication text should not be shown. |
| 310 | */ |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 311 | @VisibleForTesting |
| 312 | String getTrustGrantedIndication() { |
Lucas Dupin | 859f2c8 | 2019-04-17 18:30:00 -0700 | [diff] [blame] | 313 | return mContext.getString(R.string.keyguard_indication_trust_unlocked); |
Zachary Iqbal | dc05aa0 | 2017-05-17 18:52:49 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | /** |
Scott Warner | 778db33 | 2020-01-21 09:45:56 -0500 | [diff] [blame] | 317 | * Sets if the device is plugged in |
| 318 | */ |
| 319 | @VisibleForTesting |
| 320 | void setPowerPluggedIn(boolean plugged) { |
| 321 | mPowerPluggedIn = plugged; |
| 322 | } |
| 323 | |
| 324 | /** |
Zachary Iqbal | dc05aa0 | 2017-05-17 18:52:49 -0700 | [diff] [blame] | 325 | * Returns the indication text indicating that trust is currently being managed. |
| 326 | * |
| 327 | * @return {@code null} or an empty string if a trust managed text should not be shown. |
| 328 | */ |
Lucas Dupin | 859f2c8 | 2019-04-17 18:30:00 -0700 | [diff] [blame] | 329 | private String getTrustManagedIndication() { |
Zachary Iqbal | 8f4c242 | 2017-04-20 17:56:42 -0700 | [diff] [blame] | 330 | return null; |
| 331 | } |
| 332 | |
| 333 | /** |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 334 | * Hides transient indication in {@param delayMs}. |
| 335 | */ |
| 336 | public void hideTransientIndicationDelayed(long delayMs) { |
| 337 | mHandler.sendMessageDelayed( |
| 338 | mHandler.obtainMessage(MSG_HIDE_TRANSIENT), delayMs); |
| 339 | } |
| 340 | |
| 341 | /** |
| 342 | * Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}. |
| 343 | */ |
| 344 | public void showTransientIndication(int transientIndication) { |
| 345 | showTransientIndication(mContext.getResources().getString(transientIndication)); |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}. |
| 350 | */ |
Lucas Dupin | ef88654 | 2018-01-03 16:03:07 -0800 | [diff] [blame] | 351 | public void showTransientIndication(CharSequence transientIndication) { |
Lucas Dupin | aff4236 | 2020-03-27 16:28:20 -0700 | [diff] [blame] | 352 | showTransientIndication(transientIndication, false /* isError */, |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 353 | false /* hideOnScreenOff */); |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | /** |
| 357 | * Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}. |
| 358 | */ |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 359 | private void showTransientIndication(CharSequence transientIndication, |
Lucas Dupin | aff4236 | 2020-03-27 16:28:20 -0700 | [diff] [blame] | 360 | boolean isError, boolean hideOnScreenOff) { |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 361 | mTransientIndication = transientIndication; |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 362 | mHideTransientMessageOnScreenOff = hideOnScreenOff && transientIndication != null; |
Lucas Dupin | aff4236 | 2020-03-27 16:28:20 -0700 | [diff] [blame] | 363 | mTransientTextIsError = isError; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 364 | mHandler.removeMessages(MSG_HIDE_TRANSIENT); |
Lucas Dupin | 51996bb | 2019-05-16 17:56:43 -0700 | [diff] [blame] | 365 | mHandler.removeMessages(MSG_SWIPE_UP_TO_UNLOCK); |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 366 | if (mDozing && !TextUtils.isEmpty(mTransientIndication)) { |
| 367 | // Make sure this doesn't get stuck and burns in. Acquire wakelock until its cleared. |
| 368 | mWakeLock.setAcquired(true); |
| 369 | hideTransientIndicationDelayed(BaseKeyguardCallback.HIDE_DELAY_MS); |
| 370 | } |
Beverly | 8c78589 | 2018-01-31 17:25:52 -0500 | [diff] [blame] | 371 | |
| 372 | updateIndication(false); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | /** |
| 376 | * Hides transient indication. |
| 377 | */ |
| 378 | public void hideTransientIndication() { |
| 379 | if (mTransientIndication != null) { |
| 380 | mTransientIndication = null; |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 381 | mHideTransientMessageOnScreenOff = false; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 382 | mHandler.removeMessages(MSG_HIDE_TRANSIENT); |
Beverly | 8c78589 | 2018-01-31 17:25:52 -0500 | [diff] [blame] | 383 | updateIndication(false); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | |
Beverly | 8c78589 | 2018-01-31 17:25:52 -0500 | [diff] [blame] | 387 | protected final void updateIndication(boolean animate) { |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 388 | if (TextUtils.isEmpty(mTransientIndication)) { |
| 389 | mWakeLock.setAcquired(false); |
| 390 | } |
| 391 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 392 | if (mVisible) { |
Lucas Dupin | 53d5062 | 2017-05-13 15:54:14 -0700 | [diff] [blame] | 393 | // Walk down a precedence-ordered list of what indication |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 394 | // should be shown based on user or device state |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 395 | if (mDozing) { |
Lucas Dupin | 07ed3df | 2019-03-26 21:23:59 -0700 | [diff] [blame] | 396 | // When dozing we ignore any text color and use white instead, because |
| 397 | // colors can be hard to read in low brightness. |
| 398 | mTextView.setTextColor(Color.WHITE); |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 399 | if (!TextUtils.isEmpty(mTransientIndication)) { |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 400 | mTextView.switchIndication(mTransientIndication); |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 401 | } else if (!TextUtils.isEmpty(mAlignmentIndication)) { |
| 402 | mTextView.switchIndication(mAlignmentIndication); |
Wilson Wu | bb51d09 | 2020-04-21 16:00:59 +0800 | [diff] [blame] | 403 | mTextView.setTextColor(mContext.getColor(R.color.misalignment_text_color)); |
Lucas Dupin | 07ed3df | 2019-03-26 21:23:59 -0700 | [diff] [blame] | 404 | } else if (mPowerPluggedIn) { |
| 405 | String indication = computePowerIndication(); |
| 406 | if (animate) { |
| 407 | animateText(mTextView, indication); |
| 408 | } else { |
| 409 | mTextView.switchIndication(indication); |
| 410 | } |
| 411 | } else { |
| 412 | String percentage = NumberFormat.getPercentInstance() |
| 413 | .format(mBatteryLevel / 100f); |
| 414 | mTextView.switchIndication(percentage); |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 415 | } |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 416 | return; |
| 417 | } |
| 418 | |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 419 | int userId = KeyguardUpdateMonitor.getCurrentUser(); |
Zachary Iqbal | dc05aa0 | 2017-05-17 18:52:49 -0700 | [diff] [blame] | 420 | String trustGrantedIndication = getTrustGrantedIndication(); |
| 421 | String trustManagedIndication = getTrustManagedIndication(); |
Scott Warner | 778db33 | 2020-01-21 09:45:56 -0500 | [diff] [blame] | 422 | |
| 423 | String powerIndication = null; |
| 424 | if (mPowerPluggedIn) { |
| 425 | powerIndication = computePowerIndication(); |
| 426 | } |
| 427 | |
Lucas Dupin | aff4236 | 2020-03-27 16:28:20 -0700 | [diff] [blame] | 428 | boolean isError = false; |
Lucas Dupin | 6c6d573 | 2019-08-27 17:36:05 -0700 | [diff] [blame] | 429 | if (!mKeyguardUpdateMonitor.isUserUnlocked(userId)) { |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 430 | mTextView.switchIndication(com.android.internal.R.string.lockscreen_storage_locked); |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 431 | } else if (!TextUtils.isEmpty(mTransientIndication)) { |
Lucas Dupin | d9af631 | 2020-03-23 17:30:15 -0700 | [diff] [blame] | 432 | if (powerIndication != null && !mTransientIndication.equals(powerIndication)) { |
Scott Warner | 778db33 | 2020-01-21 09:45:56 -0500 | [diff] [blame] | 433 | String indication = mContext.getResources().getString( |
| 434 | R.string.keyguard_indication_trust_unlocked_plugged_in, |
| 435 | mTransientIndication, powerIndication); |
| 436 | mTextView.switchIndication(indication); |
| 437 | } else { |
| 438 | mTextView.switchIndication(mTransientIndication); |
| 439 | } |
Lucas Dupin | aff4236 | 2020-03-27 16:28:20 -0700 | [diff] [blame] | 440 | isError = mTransientTextIsError; |
Zachary Iqbal | dc05aa0 | 2017-05-17 18:52:49 -0700 | [diff] [blame] | 441 | } else if (!TextUtils.isEmpty(trustGrantedIndication) |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 442 | && mKeyguardUpdateMonitor.getUserHasTrust(userId)) { |
Scott Warner | 778db33 | 2020-01-21 09:45:56 -0500 | [diff] [blame] | 443 | if (powerIndication != null) { |
| 444 | String indication = mContext.getResources().getString( |
| 445 | R.string.keyguard_indication_trust_unlocked_plugged_in, |
| 446 | trustGrantedIndication, powerIndication); |
| 447 | mTextView.switchIndication(indication); |
| 448 | } else { |
| 449 | mTextView.switchIndication(trustGrantedIndication); |
| 450 | } |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 451 | } else if (!TextUtils.isEmpty(mAlignmentIndication)) { |
| 452 | mTextView.switchIndication(mAlignmentIndication); |
Lucas Dupin | aff4236 | 2020-03-27 16:28:20 -0700 | [diff] [blame] | 453 | isError = true; |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 454 | } else if (mPowerPluggedIn) { |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 455 | if (DEBUG_CHARGING_SPEED) { |
Scott Warner | 778db33 | 2020-01-21 09:45:56 -0500 | [diff] [blame] | 456 | powerIndication += ", " + (mChargingWattage / 1000) + " mW"; |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 457 | } |
Beverly | 85499d9 | 2018-02-14 15:55:16 -0500 | [diff] [blame] | 458 | if (animate) { |
Scott Warner | 778db33 | 2020-01-21 09:45:56 -0500 | [diff] [blame] | 459 | animateText(mTextView, powerIndication); |
Beverly | 85499d9 | 2018-02-14 15:55:16 -0500 | [diff] [blame] | 460 | } else { |
Scott Warner | 778db33 | 2020-01-21 09:45:56 -0500 | [diff] [blame] | 461 | mTextView.switchIndication(powerIndication); |
Beverly | 85499d9 | 2018-02-14 15:55:16 -0500 | [diff] [blame] | 462 | } |
Zachary Iqbal | dc05aa0 | 2017-05-17 18:52:49 -0700 | [diff] [blame] | 463 | } else if (!TextUtils.isEmpty(trustManagedIndication) |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 464 | && mKeyguardUpdateMonitor.getUserTrustIsManaged(userId) |
| 465 | && !mKeyguardUpdateMonitor.getUserHasTrust(userId)) { |
Zachary Iqbal | dc05aa0 | 2017-05-17 18:52:49 -0700 | [diff] [blame] | 466 | mTextView.switchIndication(trustManagedIndication); |
Jeff Sharkey | b6edaa9 | 2016-07-27 15:51:31 -0600 | [diff] [blame] | 467 | } else { |
| 468 | mTextView.switchIndication(mRestingIndication); |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 469 | } |
Lucas Dupin | aff4236 | 2020-03-27 16:28:20 -0700 | [diff] [blame] | 470 | mTextView.setTextColor(isError ? Utils.getColorError(mContext) |
| 471 | : mInitialTextColorState); |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 472 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 473 | } |
| 474 | |
Beverly | 85499d9 | 2018-02-14 15:55:16 -0500 | [diff] [blame] | 475 | // animates textView - textView moves up and bounces down |
| 476 | private void animateText(KeyguardIndicationTextView textView, String indication) { |
| 477 | int yTranslation = mContext.getResources().getInteger( |
| 478 | R.integer.wired_charging_keyguard_text_animation_distance); |
| 479 | int animateUpDuration = mContext.getResources().getInteger( |
| 480 | R.integer.wired_charging_keyguard_text_animation_duration_up); |
| 481 | int animateDownDuration = mContext.getResources().getInteger( |
| 482 | R.integer.wired_charging_keyguard_text_animation_duration_down); |
Lucas Dupin | def4369 | 2018-07-02 15:22:58 -0700 | [diff] [blame] | 483 | textView.animate().cancel(); |
Lucas Dupin | eff8ef0 | 2019-06-06 11:14:01 -0700 | [diff] [blame] | 484 | ViewClippingUtil.setClippingDeactivated(textView, true, mClippingParams); |
Beverly | 85499d9 | 2018-02-14 15:55:16 -0500 | [diff] [blame] | 485 | textView.animate() |
| 486 | .translationYBy(yTranslation) |
| 487 | .setInterpolator(Interpolators.LINEAR) |
| 488 | .setDuration(animateUpDuration) |
| 489 | .setListener(new AnimatorListenerAdapter() { |
Lucas Dupin | def4369 | 2018-07-02 15:22:58 -0700 | [diff] [blame] | 490 | private boolean mCancelled; |
| 491 | |
Beverly | 85499d9 | 2018-02-14 15:55:16 -0500 | [diff] [blame] | 492 | @Override |
| 493 | public void onAnimationStart(Animator animation) { |
| 494 | textView.switchIndication(indication); |
| 495 | } |
Lucas Dupin | def4369 | 2018-07-02 15:22:58 -0700 | [diff] [blame] | 496 | |
| 497 | @Override |
| 498 | public void onAnimationCancel(Animator animation) { |
Robert Snoeberger | ddfb065 | 2019-06-21 16:41:46 -0400 | [diff] [blame] | 499 | textView.setTranslationY(BOUNCE_ANIMATION_FINAL_Y); |
Lucas Dupin | def4369 | 2018-07-02 15:22:58 -0700 | [diff] [blame] | 500 | mCancelled = true; |
| 501 | } |
| 502 | |
Beverly | 85499d9 | 2018-02-14 15:55:16 -0500 | [diff] [blame] | 503 | @Override |
| 504 | public void onAnimationEnd(Animator animation) { |
Lucas Dupin | def4369 | 2018-07-02 15:22:58 -0700 | [diff] [blame] | 505 | if (mCancelled) { |
Lucas Dupin | eff8ef0 | 2019-06-06 11:14:01 -0700 | [diff] [blame] | 506 | ViewClippingUtil.setClippingDeactivated(textView, false, |
| 507 | mClippingParams); |
Lucas Dupin | def4369 | 2018-07-02 15:22:58 -0700 | [diff] [blame] | 508 | return; |
| 509 | } |
Beverly | 85499d9 | 2018-02-14 15:55:16 -0500 | [diff] [blame] | 510 | textView.animate() |
| 511 | .setDuration(animateDownDuration) |
| 512 | .setInterpolator(Interpolators.BOUNCE) |
Robert Snoeberger | ddfb065 | 2019-06-21 16:41:46 -0400 | [diff] [blame] | 513 | .translationY(BOUNCE_ANIMATION_FINAL_Y) |
Lucas Dupin | def4369 | 2018-07-02 15:22:58 -0700 | [diff] [blame] | 514 | .setListener(new AnimatorListenerAdapter() { |
| 515 | @Override |
Lucas Dupin | eff8ef0 | 2019-06-06 11:14:01 -0700 | [diff] [blame] | 516 | public void onAnimationEnd(Animator animation) { |
Robert Snoeberger | ddfb065 | 2019-06-21 16:41:46 -0400 | [diff] [blame] | 517 | textView.setTranslationY(BOUNCE_ANIMATION_FINAL_Y); |
Lucas Dupin | eff8ef0 | 2019-06-06 11:14:01 -0700 | [diff] [blame] | 518 | ViewClippingUtil.setClippingDeactivated(textView, false, |
| 519 | mClippingParams); |
| 520 | } |
Lucas Dupin | def4369 | 2018-07-02 15:22:58 -0700 | [diff] [blame] | 521 | }); |
Beverly | 85499d9 | 2018-02-14 15:55:16 -0500 | [diff] [blame] | 522 | } |
| 523 | }); |
| 524 | } |
| 525 | |
Scott Warner | 778db33 | 2020-01-21 09:45:56 -0500 | [diff] [blame] | 526 | @VisibleForTesting |
| 527 | String computePowerIndication() { |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 528 | if (mPowerCharged) { |
| 529 | return mContext.getResources().getString(R.string.keyguard_charged); |
| 530 | } |
| 531 | |
Lucas Dupin | 9131b28 | 2019-11-19 16:25:03 -0800 | [diff] [blame] | 532 | final boolean hasChargingTime = mChargingTimeRemaining > 0; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 533 | int chargingId; |
Beverly | 7d7f699 | 2019-02-11 13:58:27 -0500 | [diff] [blame] | 534 | if (mPowerPluggedInWired) { |
| 535 | switch (mChargingSpeed) { |
Raff Tsai | f4ea562 | 2019-06-26 16:15:21 +0800 | [diff] [blame] | 536 | case BatteryStatus.CHARGING_FAST: |
Beverly | 7d7f699 | 2019-02-11 13:58:27 -0500 | [diff] [blame] | 537 | chargingId = hasChargingTime |
| 538 | ? R.string.keyguard_indication_charging_time_fast |
| 539 | : R.string.keyguard_plugged_in_charging_fast; |
| 540 | break; |
Raff Tsai | f4ea562 | 2019-06-26 16:15:21 +0800 | [diff] [blame] | 541 | case BatteryStatus.CHARGING_SLOWLY: |
Beverly | 7d7f699 | 2019-02-11 13:58:27 -0500 | [diff] [blame] | 542 | chargingId = hasChargingTime |
| 543 | ? R.string.keyguard_indication_charging_time_slowly |
| 544 | : R.string.keyguard_plugged_in_charging_slowly; |
| 545 | break; |
| 546 | default: |
| 547 | chargingId = hasChargingTime |
| 548 | ? R.string.keyguard_indication_charging_time |
| 549 | : R.string.keyguard_plugged_in; |
| 550 | break; |
| 551 | } |
| 552 | } else { |
| 553 | chargingId = hasChargingTime |
| 554 | ? R.string.keyguard_indication_charging_time_wireless |
| 555 | : R.string.keyguard_plugged_in_wireless; |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 556 | } |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 557 | |
Lucas Dupin | 8d595d2 | 2018-03-08 10:34:58 -0800 | [diff] [blame] | 558 | String percentage = NumberFormat.getPercentInstance() |
| 559 | .format(mBatteryLevel / 100f); |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 560 | if (hasChargingTime) { |
Lucas Dupin | 8d595d2 | 2018-03-08 10:34:58 -0800 | [diff] [blame] | 561 | // We now have battery percentage in these strings and it's expected that all |
| 562 | // locales will also have it in the future. For now, we still have to support the old |
| 563 | // format until all languages get the new translations. |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 564 | String chargingTimeFormatted = Formatter.formatShortElapsedTimeRoundingUpToMinutes( |
Lucas Dupin | 9131b28 | 2019-11-19 16:25:03 -0800 | [diff] [blame] | 565 | mContext, mChargingTimeRemaining); |
Lucas Dupin | 8d595d2 | 2018-03-08 10:34:58 -0800 | [diff] [blame] | 566 | try { |
| 567 | return mContext.getResources().getString(chargingId, chargingTimeFormatted, |
| 568 | percentage); |
| 569 | } catch (IllegalFormatConversionException e) { |
| 570 | return mContext.getResources().getString(chargingId, chargingTimeFormatted); |
| 571 | } |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 572 | } else { |
Lucas Dupin | 8d595d2 | 2018-03-08 10:34:58 -0800 | [diff] [blame] | 573 | // Same as above |
| 574 | try { |
| 575 | return mContext.getResources().getString(chargingId, percentage); |
| 576 | } catch (IllegalFormatConversionException e) { |
| 577 | return mContext.getResources().getString(chargingId); |
| 578 | } |
Adrian Roos | 7e39e59 | 2015-09-23 17:03:47 -0700 | [diff] [blame] | 579 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 580 | } |
| 581 | |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 582 | public void setStatusBarKeyguardViewManager( |
| 583 | StatusBarKeyguardViewManager statusBarKeyguardViewManager) { |
| 584 | mStatusBarKeyguardViewManager = statusBarKeyguardViewManager; |
| 585 | } |
| 586 | |
Lucas Dupin | 7e171e2 | 2018-12-20 11:29:35 -0800 | [diff] [blame] | 587 | private final KeyguardUpdateMonitorCallback mTickReceiver = |
| 588 | new KeyguardUpdateMonitorCallback() { |
| 589 | @Override |
| 590 | public void onTimeChanged() { |
| 591 | if (mVisible) { |
| 592 | updateIndication(false /* animate */); |
| 593 | } |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 594 | } |
Lucas Dupin | 7e171e2 | 2018-12-20 11:29:35 -0800 | [diff] [blame] | 595 | }; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 596 | |
| 597 | private final Handler mHandler = new Handler() { |
| 598 | @Override |
| 599 | public void handleMessage(Message msg) { |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 600 | if (msg.what == MSG_HIDE_TRANSIENT) { |
| 601 | hideTransientIndication(); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 602 | } else if (msg.what == MSG_CLEAR_BIOMETRIC_MSG) { |
Dave Mankoff | c0d9a7d | 2020-02-27 17:15:52 -0500 | [diff] [blame] | 603 | if (mLockIconController != null) { |
| 604 | mLockIconController.setTransientBiometricsError(false); |
| 605 | } |
Lucas Dupin | 51996bb | 2019-05-16 17:56:43 -0700 | [diff] [blame] | 606 | } else if (msg.what == MSG_SWIPE_UP_TO_UNLOCK) { |
| 607 | showSwipeUpToUnlock(); |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | }; |
| 611 | |
Lucas Dupin | 51996bb | 2019-05-16 17:56:43 -0700 | [diff] [blame] | 612 | private void showSwipeUpToUnlock() { |
| 613 | if (mDozing) { |
| 614 | return; |
| 615 | } |
| 616 | |
Lucas Dupin | 51996bb | 2019-05-16 17:56:43 -0700 | [diff] [blame] | 617 | if (mStatusBarKeyguardViewManager.isBouncerShowing()) { |
Lucas Dupin | adce353 | 2019-08-02 11:17:39 -0700 | [diff] [blame] | 618 | String message = mContext.getString(R.string.keyguard_retry); |
Lucas Dupin | 51996bb | 2019-05-16 17:56:43 -0700 | [diff] [blame] | 619 | mStatusBarKeyguardViewManager.showBouncerMessage(message, mInitialTextColorState); |
| 620 | } else if (mKeyguardUpdateMonitor.isScreenOn()) { |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 621 | showTransientIndication(mContext.getString(R.string.keyguard_unlock), |
Lucas Dupin | aff4236 | 2020-03-27 16:28:20 -0700 | [diff] [blame] | 622 | false /* isError */, true /* hideOnScreenOff */); |
Lucas Dupin | 51996bb | 2019-05-16 17:56:43 -0700 | [diff] [blame] | 623 | hideTransientIndicationDelayed(BaseKeyguardCallback.HIDE_DELAY_MS); |
| 624 | } |
| 625 | } |
| 626 | |
Adrian Roos | 91ba307 | 2017-02-14 16:50:46 +0100 | [diff] [blame] | 627 | public void setDozing(boolean dozing) { |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 628 | if (mDozing == dozing) { |
| 629 | return; |
| 630 | } |
Adrian Roos | 91ba307 | 2017-02-14 16:50:46 +0100 | [diff] [blame] | 631 | mDozing = dozing; |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 632 | if (mHideTransientMessageOnScreenOff && mDozing) { |
| 633 | hideTransientIndication(); |
| 634 | } else { |
| 635 | updateIndication(false); |
| 636 | } |
Adrian Roos | 91ba307 | 2017-02-14 16:50:46 +0100 | [diff] [blame] | 637 | } |
| 638 | |
Lucas Dupin | 3fcdd47 | 2018-01-19 19:06:45 -0800 | [diff] [blame] | 639 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 640 | pw.println("KeyguardIndicationController:"); |
Lucas Dupin | aff4236 | 2020-03-27 16:28:20 -0700 | [diff] [blame] | 641 | pw.println(" mTransientTextIsError: " + mTransientTextIsError); |
Jason Chang | 2386a37 | 2018-04-24 16:05:30 +0800 | [diff] [blame] | 642 | pw.println(" mInitialTextColorState: " + mInitialTextColorState); |
Beverly | 2034c83 | 2018-03-19 11:18:51 -0400 | [diff] [blame] | 643 | pw.println(" mPowerPluggedInWired: " + mPowerPluggedInWired); |
Lucas Dupin | 3fcdd47 | 2018-01-19 19:06:45 -0800 | [diff] [blame] | 644 | pw.println(" mPowerPluggedIn: " + mPowerPluggedIn); |
| 645 | pw.println(" mPowerCharged: " + mPowerCharged); |
| 646 | pw.println(" mChargingSpeed: " + mChargingSpeed); |
| 647 | pw.println(" mChargingWattage: " + mChargingWattage); |
| 648 | pw.println(" mMessageToShowOnScreenOn: " + mMessageToShowOnScreenOn); |
| 649 | pw.println(" mDozing: " + mDozing); |
| 650 | pw.println(" mBatteryLevel: " + mBatteryLevel); |
| 651 | pw.println(" mTextView.getText(): " + (mTextView == null ? null : mTextView.getText())); |
| 652 | pw.println(" computePowerIndication(): " + computePowerIndication()); |
| 653 | } |
| 654 | |
Evan Laird | 878c853 | 2018-10-15 15:54:29 -0400 | [diff] [blame] | 655 | @Override |
| 656 | public void onStateChanged(int newState) { |
| 657 | // don't care |
| 658 | } |
| 659 | |
| 660 | @Override |
| 661 | public void onDozingChanged(boolean isDozing) { |
| 662 | setDozing(isDozing); |
| 663 | } |
| 664 | |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 665 | @Override |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 666 | public void onDozeAmountChanged(float linear, float eased) { |
| 667 | mDisclosure.setAlpha((1 - linear) * mDisclosureMaxAlpha); |
| 668 | } |
| 669 | |
| 670 | @Override |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 671 | public void onUnlockedChanged() { |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 672 | updateIndication(!mDozing); |
| 673 | } |
| 674 | |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 675 | protected class BaseKeyguardCallback extends KeyguardUpdateMonitorCallback { |
Adrian Roos | 5602189 | 2017-02-27 20:25:09 +0100 | [diff] [blame] | 676 | public static final int HIDE_DELAY_MS = 5000; |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 677 | |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 678 | @Override |
Raff Tsai | f4ea562 | 2019-06-26 16:15:21 +0800 | [diff] [blame] | 679 | public void onRefreshBatteryInfo(BatteryStatus status) { |
Adrian Roos | ad3bc7f | 2014-10-30 18:29:38 +0100 | [diff] [blame] | 680 | boolean isChargingOrFull = status.status == BatteryManager.BATTERY_STATUS_CHARGING |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 681 | || status.status == BatteryManager.BATTERY_STATUS_FULL; |
Adrian Roos | 5602189 | 2017-02-27 20:25:09 +0100 | [diff] [blame] | 682 | boolean wasPluggedIn = mPowerPluggedIn; |
Beverly | 2034c83 | 2018-03-19 11:18:51 -0400 | [diff] [blame] | 683 | mPowerPluggedInWired = status.isPluggedInWired() && isChargingOrFull; |
Adrian Roos | ad3bc7f | 2014-10-30 18:29:38 +0100 | [diff] [blame] | 684 | mPowerPluggedIn = status.isPluggedIn() && isChargingOrFull; |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 685 | mPowerCharged = status.isCharged(); |
Adrian Roos | 0c859ae | 2015-11-23 16:47:50 -0800 | [diff] [blame] | 686 | mChargingWattage = status.maxChargingWattage; |
Raff Tsai | f4ea562 | 2019-06-26 16:15:21 +0800 | [diff] [blame] | 687 | mChargingSpeed = status.getChargingSpeed(mContext); |
Lucas Dupin | 4272f44 | 2018-01-13 22:00:35 -0800 | [diff] [blame] | 688 | mBatteryLevel = status.level; |
Lucas Dupin | 9131b28 | 2019-11-19 16:25:03 -0800 | [diff] [blame] | 689 | try { |
| 690 | mChargingTimeRemaining = mPowerPluggedIn |
| 691 | ? mBatteryInfo.computeChargeTimeRemaining() : -1; |
| 692 | } catch (RemoteException e) { |
| 693 | Log.e(TAG, "Error calling IBatteryStats: ", e); |
| 694 | mChargingTimeRemaining = -1; |
| 695 | } |
Beverly | 2034c83 | 2018-03-19 11:18:51 -0400 | [diff] [blame] | 696 | updateIndication(!wasPluggedIn && mPowerPluggedInWired); |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 697 | if (mDozing) { |
| 698 | if (!wasPluggedIn && mPowerPluggedIn) { |
| 699 | showTransientIndication(computePowerIndication()); |
| 700 | hideTransientIndicationDelayed(HIDE_DELAY_MS); |
| 701 | } else if (wasPluggedIn && !mPowerPluggedIn) { |
| 702 | hideTransientIndication(); |
| 703 | } |
Adrian Roos | 5602189 | 2017-02-27 20:25:09 +0100 | [diff] [blame] | 704 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 705 | } |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 706 | |
| 707 | @Override |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 708 | public void onBiometricHelp(int msgId, String helpString, |
| 709 | BiometricSourceType biometricSourceType) { |
Haining Chen | c06c481 | 2020-01-13 20:38:53 -0800 | [diff] [blame] | 710 | // TODO(b/141025588): refactor to reduce repetition of code/comments |
| 711 | // Only checking if unlocking with Biometric is allowed (no matter strong or non-strong |
| 712 | // as long as primary auth, i.e. PIN/pattern/password, is not required), so it's ok to |
| 713 | // pass true for isStrongBiometric to isUnlockingWithBiometricAllowed() to bypass the |
| 714 | // check of whether non-strong biometric is allowed |
| 715 | if (!mKeyguardUpdateMonitor |
| 716 | .isUnlockingWithBiometricAllowed(true /* isStrongBiometric */)) { |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 717 | return; |
| 718 | } |
Lucas Dupin | 51996bb | 2019-05-16 17:56:43 -0700 | [diff] [blame] | 719 | boolean showSwipeToUnlock = |
| 720 | msgId == KeyguardUpdateMonitor.BIOMETRIC_HELP_FACE_NOT_RECOGNIZED; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 721 | if (mStatusBarKeyguardViewManager.isBouncerShowing()) { |
Jason Chang | 2386a37 | 2018-04-24 16:05:30 +0800 | [diff] [blame] | 722 | mStatusBarKeyguardViewManager.showBouncerMessage(helpString, |
Lucas Dupin | c2d11b3 | 2019-03-06 16:02:18 -0800 | [diff] [blame] | 723 | mInitialTextColorState); |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 724 | } else if (mKeyguardUpdateMonitor.isScreenOn()) { |
Lucas Dupin | aff4236 | 2020-03-27 16:28:20 -0700 | [diff] [blame] | 725 | showTransientIndication(helpString, false /* isError */, showSwipeToUnlock); |
Lucas Dupin | 51996bb | 2019-05-16 17:56:43 -0700 | [diff] [blame] | 726 | if (!showSwipeToUnlock) { |
| 727 | hideTransientIndicationDelayed(TRANSIENT_BIOMETRIC_ERROR_TIMEOUT); |
| 728 | } |
| 729 | } |
| 730 | if (showSwipeToUnlock) { |
| 731 | mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_SWIPE_UP_TO_UNLOCK), |
| 732 | TRANSIENT_BIOMETRIC_ERROR_TIMEOUT); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 733 | } |
| 734 | } |
| 735 | |
| 736 | @Override |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 737 | public void onBiometricError(int msgId, String errString, |
| 738 | BiometricSourceType biometricSourceType) { |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 739 | if (shouldSuppressBiometricError(msgId, biometricSourceType, mKeyguardUpdateMonitor)) { |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 740 | return; |
| 741 | } |
Lucas Dupin | e54ad1d | 2019-04-09 17:08:46 -0700 | [diff] [blame] | 742 | animatePadlockError(); |
Lucas Dupin | adce353 | 2019-08-02 11:17:39 -0700 | [diff] [blame] | 743 | if (msgId == FaceManager.FACE_ERROR_TIMEOUT) { |
| 744 | // The face timeout message is not very actionable, let's ask the user to |
| 745 | // manually retry. |
| 746 | showSwipeUpToUnlock(); |
| 747 | } else if (mStatusBarKeyguardViewManager.isBouncerShowing()) { |
Lucas Dupin | e54ad1d | 2019-04-09 17:08:46 -0700 | [diff] [blame] | 748 | mStatusBarKeyguardViewManager.showBouncerMessage(errString, mInitialTextColorState); |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 749 | } else if (mKeyguardUpdateMonitor.isScreenOn()) { |
Lucas Dupin | c2d11b3 | 2019-03-06 16:02:18 -0800 | [diff] [blame] | 750 | showTransientIndication(errString); |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 751 | // 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] | 752 | hideTransientIndicationDelayed(HIDE_DELAY_MS); |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 753 | } else { |
| 754 | mMessageToShowOnScreenOn = errString; |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 755 | } |
Lucas Dupin | e54ad1d | 2019-04-09 17:08:46 -0700 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | private void animatePadlockError() { |
Dave Mankoff | c0d9a7d | 2020-02-27 17:15:52 -0500 | [diff] [blame] | 759 | if (mLockIconController != null) { |
| 760 | mLockIconController.setTransientBiometricsError(true); |
| 761 | } |
Lucas Dupin | e54ad1d | 2019-04-09 17:08:46 -0700 | [diff] [blame] | 762 | mHandler.removeMessages(MSG_CLEAR_BIOMETRIC_MSG); |
| 763 | mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_CLEAR_BIOMETRIC_MSG), |
| 764 | TRANSIENT_BIOMETRIC_ERROR_TIMEOUT); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 767 | private boolean shouldSuppressBiometricError(int msgId, |
| 768 | BiometricSourceType biometricSourceType, KeyguardUpdateMonitor updateMonitor) { |
| 769 | if (biometricSourceType == BiometricSourceType.FINGERPRINT) |
| 770 | return shouldSuppressFingerprintError(msgId, updateMonitor); |
| 771 | if (biometricSourceType == BiometricSourceType.FACE) |
| 772 | return shouldSuppressFaceError(msgId, updateMonitor); |
| 773 | return false; |
| 774 | } |
| 775 | |
| 776 | private boolean shouldSuppressFingerprintError(int msgId, |
| 777 | KeyguardUpdateMonitor updateMonitor) { |
Haining Chen | c06c481 | 2020-01-13 20:38:53 -0800 | [diff] [blame] | 778 | // Only checking if unlocking with Biometric is allowed (no matter strong or non-strong |
| 779 | // as long as primary auth, i.e. PIN/pattern/password, is not required), so it's ok to |
| 780 | // pass true for isStrongBiometric to isUnlockingWithBiometricAllowed() to bypass the |
| 781 | // check of whether non-strong biometric is allowed |
| 782 | return ((!updateMonitor.isUnlockingWithBiometricAllowed(true /* isStrongBiometric */) |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 783 | && msgId != FingerprintManager.FINGERPRINT_ERROR_LOCKOUT_PERMANENT) |
| 784 | || msgId == FingerprintManager.FINGERPRINT_ERROR_CANCELED); |
| 785 | } |
| 786 | |
| 787 | private boolean shouldSuppressFaceError(int msgId, KeyguardUpdateMonitor updateMonitor) { |
Haining Chen | c06c481 | 2020-01-13 20:38:53 -0800 | [diff] [blame] | 788 | // Only checking if unlocking with Biometric is allowed (no matter strong or non-strong |
| 789 | // as long as primary auth, i.e. PIN/pattern/password, is not required), so it's ok to |
| 790 | // pass true for isStrongBiometric to isUnlockingWithBiometricAllowed() to bypass the |
| 791 | // check of whether non-strong biometric is allowed |
| 792 | return ((!updateMonitor.isUnlockingWithBiometricAllowed(true /* isStrongBiometric */) |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 793 | && msgId != FaceManager.FACE_ERROR_LOCKOUT_PERMANENT) |
| 794 | || msgId == FaceManager.FACE_ERROR_CANCELED); |
| 795 | } |
| 796 | |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 797 | @Override |
Lucas Dupin | ef88654 | 2018-01-03 16:03:07 -0800 | [diff] [blame] | 798 | public void onTrustAgentErrorMessage(CharSequence message) { |
Lucas Dupin | aff4236 | 2020-03-27 16:28:20 -0700 | [diff] [blame] | 799 | showTransientIndication(message, true /* isError */, false /* hideOnScreenOff */); |
Lucas Dupin | ef88654 | 2018-01-03 16:03:07 -0800 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | @Override |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 803 | public void onScreenTurnedOn() { |
| 804 | if (mMessageToShowOnScreenOn != null) { |
Lucas Dupin | aff4236 | 2020-03-27 16:28:20 -0700 | [diff] [blame] | 805 | showTransientIndication(mMessageToShowOnScreenOn, true /* isError */, |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 806 | false /* hideOnScreenOff */); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 807 | // 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] | 808 | hideTransientIndicationDelayed(HIDE_DELAY_MS); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 809 | mMessageToShowOnScreenOn = null; |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | @Override |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 814 | public void onBiometricRunningStateChanged(boolean running, |
| 815 | BiometricSourceType biometricSourceType) { |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 816 | if (running) { |
Lucas Dupin | 8f3faac | 2019-03-12 15:28:49 -0700 | [diff] [blame] | 817 | // Let's hide any previous messages when authentication starts, otherwise |
| 818 | // multiple auth attempts would overlap. |
| 819 | hideTransientIndication(); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 820 | mMessageToShowOnScreenOn = null; |
| 821 | } |
| 822 | } |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 823 | |
| 824 | @Override |
Haining Chen | c06c481 | 2020-01-13 20:38:53 -0800 | [diff] [blame] | 825 | public void onBiometricAuthenticated(int userId, BiometricSourceType biometricSourceType, |
| 826 | boolean isStrongBiometric) { |
| 827 | super.onBiometricAuthenticated(userId, biometricSourceType, isStrongBiometric); |
Kevin Chyn | 6d793bd | 2019-03-27 15:36:13 -0700 | [diff] [blame] | 828 | mHandler.sendEmptyMessage(MSG_HIDE_TRANSIENT); |
Selim Cinek | 3e45194 | 2016-07-14 18:07:53 -0700 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | @Override |
Lucas Dupin | 6c6d573 | 2019-08-27 17:36:05 -0700 | [diff] [blame] | 832 | public void onUserSwitchComplete(int userId) { |
| 833 | if (mVisible) { |
| 834 | updateIndication(false); |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | @Override |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 839 | public void onUserUnlocked() { |
| 840 | if (mVisible) { |
Beverly | 8c78589 | 2018-01-31 17:25:52 -0500 | [diff] [blame] | 841 | updateIndication(false); |
Jorim Jaggi | dadafd4 | 2016-09-30 07:20:25 -0700 | [diff] [blame] | 842 | } |
| 843 | } |
Lucas Dupin | 71d2fb2 | 2019-05-30 18:26:54 -0700 | [diff] [blame] | 844 | } |
Adrian Roos | 12c1ef5 | 2014-06-04 13:54:08 +0200 | [diff] [blame] | 845 | } |