Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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.phone; |
| 18 | |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 19 | import static com.android.systemui.Dependency.MAIN_HANDLER_NAME; |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 20 | import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT; |
| 21 | |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 22 | import android.content.Context; |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 23 | import android.content.res.ColorStateList; |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 24 | import android.content.res.Configuration; |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 25 | import android.content.res.TypedArray; |
Lucas Dupin | c90a6bf | 2018-10-10 13:53:20 -0700 | [diff] [blame] | 26 | import android.graphics.Color; |
Lucas Dupin | f3b2629 | 2019-03-14 16:06:22 -0700 | [diff] [blame] | 27 | import android.graphics.drawable.Animatable2; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 28 | import android.graphics.drawable.AnimatedVectorDrawable; |
| 29 | import android.graphics.drawable.Drawable; |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 30 | import android.hardware.biometrics.BiometricSourceType; |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 31 | import android.os.Handler; |
Ian | aee1b2a | 2019-05-10 16:48:22 -0700 | [diff] [blame] | 32 | import android.os.Trace; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 33 | import android.util.AttributeSet; |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 34 | import android.view.ViewGroup; |
Selim Cinek | c99d9a95 | 2015-06-19 18:44:50 -0700 | [diff] [blame] | 35 | import android.view.accessibility.AccessibilityNodeInfo; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 36 | |
Lucas Dupin | d722135 | 2019-04-29 19:43:11 -0700 | [diff] [blame] | 37 | import androidx.annotation.Nullable; |
| 38 | |
Lucas Dupin | c90a6bf | 2018-10-10 13:53:20 -0700 | [diff] [blame] | 39 | import com.android.internal.graphics.ColorUtils; |
Lucas Dupin | da069d7 | 2019-05-04 11:29:47 -0700 | [diff] [blame] | 40 | import com.android.internal.telephony.IccCardConstants; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 41 | import com.android.keyguard.KeyguardUpdateMonitor; |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 42 | import com.android.keyguard.KeyguardUpdateMonitorCallback; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 43 | import com.android.systemui.R; |
Lucas Dupin | d722135 | 2019-04-29 19:43:11 -0700 | [diff] [blame] | 44 | import com.android.systemui.dock.DockManager; |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 45 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 46 | import com.android.systemui.statusbar.KeyguardAffordanceView; |
Lucas Dupin | cdbb1cb | 2019-05-16 19:48:30 -0700 | [diff] [blame] | 47 | import com.android.systemui.statusbar.phone.ScrimController.ScrimVisibility; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 48 | import com.android.systemui.statusbar.policy.AccessibilityController; |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 49 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Lucas Dupin | 1cad65e | 2019-05-15 13:47:05 -0700 | [diff] [blame] | 50 | import com.android.systemui.statusbar.policy.KeyguardMonitor; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 51 | import com.android.systemui.statusbar.policy.UserInfoController.OnUserInfoChangedListener; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 52 | |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 53 | import javax.inject.Inject; |
| 54 | import javax.inject.Named; |
| 55 | |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 56 | /** |
| 57 | * Manages the different states and animations of the unlock icon. |
| 58 | */ |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 59 | public class LockIcon extends KeyguardAffordanceView implements OnUserInfoChangedListener, |
| 60 | StatusBarStateController.StateListener, ConfigurationController.ConfigurationListener, |
| 61 | UnlockMethodCache.OnUnlockMethodChangedListener { |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 62 | |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 63 | private static final int STATE_LOCKED = 0; |
| 64 | private static final int STATE_LOCK_OPEN = 1; |
Lucas Dupin | c2d11b3 | 2019-03-06 16:02:18 -0800 | [diff] [blame] | 65 | private static final int STATE_SCANNING_FACE = 2; |
| 66 | private static final int STATE_BIOMETRICS_ERROR = 3; |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 67 | private final ConfigurationController mConfigurationController; |
| 68 | private final StatusBarStateController mStatusBarStateController; |
| 69 | private final UnlockMethodCache mUnlockMethodCache; |
| 70 | private final KeyguardUpdateMonitor mKeyguardUpdateMonitor; |
| 71 | private final AccessibilityController mAccessibilityController; |
Lucas Dupin | d722135 | 2019-04-29 19:43:11 -0700 | [diff] [blame] | 72 | private final DockManager mDockManager; |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 73 | private final Handler mMainHandler; |
Lucas Dupin | 1cad65e | 2019-05-15 13:47:05 -0700 | [diff] [blame] | 74 | private final KeyguardMonitor mKeyguardMonitor; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 75 | |
| 76 | private int mLastState = 0; |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 77 | private boolean mTransientBiometricsError; |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 78 | private boolean mIsFaceUnlockState; |
Lucas Dupin | da069d7 | 2019-05-04 11:29:47 -0700 | [diff] [blame] | 79 | private boolean mSimLocked; |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 80 | private int mDensity; |
Lucas Dupin | f22194f | 2018-12-26 11:43:57 -0800 | [diff] [blame] | 81 | private boolean mPulsing; |
| 82 | private boolean mDozing; |
Lucas Dupin | 0590465 | 2019-04-09 16:16:15 -0700 | [diff] [blame] | 83 | private boolean mBouncerVisible; |
Lucas Dupin | d722135 | 2019-04-29 19:43:11 -0700 | [diff] [blame] | 84 | private boolean mDocked; |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 85 | private boolean mLastDozing; |
| 86 | private boolean mLastPulsing; |
Lucas Dupin | 0590465 | 2019-04-09 16:16:15 -0700 | [diff] [blame] | 87 | private boolean mLastBouncerVisible; |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 88 | private int mIconColor; |
Lucas Dupin | d722135 | 2019-04-29 19:43:11 -0700 | [diff] [blame] | 89 | private float mDozeAmount; |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 90 | private int mIconRes; |
| 91 | private boolean mWasPulsingOnThisFrame; |
Lucas Dupin | 71f3804 | 2019-05-10 16:23:04 -0700 | [diff] [blame] | 92 | private boolean mWakeAndUnlockRunning; |
Lucas Dupin | 1cad65e | 2019-05-15 13:47:05 -0700 | [diff] [blame] | 93 | private boolean mKeyguardShowing; |
Lucas Dupin | 23964c7 | 2019-05-21 16:12:45 -0700 | [diff] [blame] | 94 | private boolean mShowingLaunchAffordance; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 95 | |
Lucas Dupin | 1cad65e | 2019-05-15 13:47:05 -0700 | [diff] [blame] | 96 | private final KeyguardMonitor.Callback mKeyguardMonitorCallback = |
| 97 | new KeyguardMonitor.Callback() { |
| 98 | @Override |
| 99 | public void onKeyguardShowingChanged() { |
| 100 | mKeyguardShowing = mKeyguardMonitor.isShowing(); |
| 101 | update(false /* force */); |
| 102 | } |
| 103 | }; |
Lucas Dupin | d722135 | 2019-04-29 19:43:11 -0700 | [diff] [blame] | 104 | private final DockManager.DockEventListener mDockEventListener = |
| 105 | new DockManager.DockEventListener() { |
| 106 | @Override |
| 107 | public void onEvent(int event) { |
| 108 | boolean docked = event == DockManager.STATE_DOCKED |
| 109 | || event == DockManager.STATE_DOCKED_HIDE; |
| 110 | if (docked != mDocked) { |
| 111 | mDocked = docked; |
| 112 | update(true /* force */); |
| 113 | } |
| 114 | } |
| 115 | }; |
Jorim Jaggi | 8dea48c | 2016-11-28 14:47:45 +0100 | [diff] [blame] | 116 | |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 117 | private final KeyguardUpdateMonitorCallback mUpdateMonitorCallback = |
| 118 | new KeyguardUpdateMonitorCallback() { |
| 119 | @Override |
Lucas Dupin | da069d7 | 2019-05-04 11:29:47 -0700 | [diff] [blame] | 120 | public void onSimStateChanged(int subId, int slotId, |
| 121 | IccCardConstants.State simState) { |
| 122 | boolean oldSimLocked = mSimLocked; |
| 123 | mSimLocked = mKeyguardUpdateMonitor.isSimPinSecure(); |
| 124 | update(oldSimLocked != mSimLocked); |
| 125 | } |
| 126 | |
| 127 | @Override |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 128 | public void onKeyguardVisibilityChanged(boolean showing) { |
| 129 | update(); |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public void onBiometricRunningStateChanged(boolean running, |
| 134 | BiometricSourceType biometricSourceType) { |
| 135 | update(); |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public void onStrongAuthStateChanged(int userId) { |
| 140 | update(); |
| 141 | } |
| 142 | }; |
| 143 | |
| 144 | @Inject |
| 145 | public LockIcon(@Named(VIEW_CONTEXT) Context context, AttributeSet attrs, |
| 146 | StatusBarStateController statusBarStateController, |
| 147 | ConfigurationController configurationController, |
Lucas Dupin | d722135 | 2019-04-29 19:43:11 -0700 | [diff] [blame] | 148 | AccessibilityController accessibilityController, |
Lucas Dupin | 1cad65e | 2019-05-15 13:47:05 -0700 | [diff] [blame] | 149 | KeyguardMonitor keyguardMonitor, |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 150 | @Nullable DockManager dockManager, |
| 151 | @Named(MAIN_HANDLER_NAME) Handler mainHandler) { |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 152 | super(context, attrs); |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 153 | mContext = context; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 154 | mUnlockMethodCache = UnlockMethodCache.getInstance(context); |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 155 | mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext); |
| 156 | mAccessibilityController = accessibilityController; |
| 157 | mConfigurationController = configurationController; |
| 158 | mStatusBarStateController = statusBarStateController; |
Lucas Dupin | 1cad65e | 2019-05-15 13:47:05 -0700 | [diff] [blame] | 159 | mKeyguardMonitor = keyguardMonitor; |
Lucas Dupin | d722135 | 2019-04-29 19:43:11 -0700 | [diff] [blame] | 160 | mDockManager = dockManager; |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 161 | mMainHandler = mainHandler; |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | @Override |
| 165 | protected void onAttachedToWindow() { |
| 166 | super.onAttachedToWindow(); |
| 167 | mStatusBarStateController.addCallback(this); |
| 168 | mConfigurationController.addCallback(this); |
Lucas Dupin | 1cad65e | 2019-05-15 13:47:05 -0700 | [diff] [blame] | 169 | mKeyguardMonitor.addCallback(mKeyguardMonitorCallback); |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 170 | mKeyguardUpdateMonitor.registerCallback(mUpdateMonitorCallback); |
| 171 | mUnlockMethodCache.addListener(this); |
Lucas Dupin | da069d7 | 2019-05-04 11:29:47 -0700 | [diff] [blame] | 172 | mSimLocked = mKeyguardUpdateMonitor.isSimPinSecure(); |
Lucas Dupin | d722135 | 2019-04-29 19:43:11 -0700 | [diff] [blame] | 173 | if (mDockManager != null) { |
| 174 | mDockManager.addListener(mDockEventListener); |
| 175 | } |
Lucas Dupin | 12dab90 | 2019-04-19 11:10:48 -0700 | [diff] [blame] | 176 | onThemeChanged(); |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | @Override |
| 180 | protected void onDetachedFromWindow() { |
| 181 | super.onDetachedFromWindow(); |
| 182 | mStatusBarStateController.removeCallback(this); |
| 183 | mConfigurationController.removeCallback(this); |
| 184 | mKeyguardUpdateMonitor.removeCallback(mUpdateMonitorCallback); |
Lucas Dupin | 1cad65e | 2019-05-15 13:47:05 -0700 | [diff] [blame] | 185 | mKeyguardMonitor.removeCallback(mKeyguardMonitorCallback); |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 186 | mUnlockMethodCache.removeListener(this); |
Lucas Dupin | d722135 | 2019-04-29 19:43:11 -0700 | [diff] [blame] | 187 | if (mDockManager != null) { |
| 188 | mDockManager.removeListener(mDockEventListener); |
| 189 | } |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | @Override |
| 193 | public void onThemeChanged() { |
| 194 | TypedArray typedArray = mContext.getTheme().obtainStyledAttributes( |
| 195 | null, new int[]{ R.attr.wallpaperTextColor }, 0, 0); |
| 196 | mIconColor = typedArray.getColor(0, Color.WHITE); |
| 197 | typedArray.recycle(); |
| 198 | updateDarkTint(); |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | @Override |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 202 | public void onUserInfoChanged(String name, Drawable picture, String userAccount) { |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 203 | update(); |
| 204 | } |
| 205 | |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 206 | /** |
| 207 | * If we're currently presenting an authentication error message. |
| 208 | */ |
| 209 | public void setTransientBiometricsError(boolean transientBiometricsError) { |
| 210 | mTransientBiometricsError = transientBiometricsError; |
Jorim Jaggi | 864e64b | 2015-05-20 14:13:23 -0700 | [diff] [blame] | 211 | update(); |
| 212 | } |
| 213 | |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 214 | @Override |
| 215 | protected void onConfigurationChanged(Configuration newConfig) { |
| 216 | super.onConfigurationChanged(newConfig); |
| 217 | final int density = newConfig.densityDpi; |
| 218 | if (density != mDensity) { |
| 219 | mDensity = density; |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 220 | update(); |
| 221 | } |
| 222 | } |
| 223 | |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 224 | public void update() { |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 225 | update(false /* force */); |
| 226 | } |
| 227 | |
| 228 | public void update(boolean force) { |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 229 | int state = getState(); |
Lucas Dupin | c2d11b3 | 2019-03-06 16:02:18 -0800 | [diff] [blame] | 230 | mIsFaceUnlockState = state == STATE_SCANNING_FACE; |
| 231 | if (state != mLastState || mLastDozing != mDozing || mLastPulsing != mPulsing |
Lucas Dupin | e24c0bf | 2019-06-07 11:44:28 -0700 | [diff] [blame] | 232 | || mLastBouncerVisible != mBouncerVisible || force) { |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 233 | int iconAnimRes = getAnimationResForTransition(mLastState, state, mLastPulsing, |
Lucas Dupin | 0590465 | 2019-04-09 16:16:15 -0700 | [diff] [blame] | 234 | mPulsing, mLastDozing, mDozing, mBouncerVisible); |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 235 | boolean isAnim = iconAnimRes != -1; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 236 | |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 237 | int iconRes = isAnim ? iconAnimRes : getIconForState(state); |
| 238 | if (iconRes != mIconRes) { |
| 239 | mIconRes = iconRes; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 240 | |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 241 | Drawable icon = mContext.getDrawable(iconRes); |
| 242 | final AnimatedVectorDrawable animation = icon instanceof AnimatedVectorDrawable |
| 243 | ? (AnimatedVectorDrawable) icon |
| 244 | : null; |
| 245 | setImageDrawable(icon, false); |
| 246 | if (mIsFaceUnlockState) { |
| 247 | announceForAccessibility(getContext().getString( |
| 248 | R.string.accessibility_scanning_face)); |
| 249 | } |
Bingyu Zhang | bfe6dcf | 2018-04-25 10:20:36 -0700 | [diff] [blame] | 250 | |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 251 | if (animation != null && isAnim) { |
| 252 | animation.forceAnimationOnUI(); |
| 253 | animation.clearAnimationCallbacks(); |
| 254 | animation.registerAnimationCallback(new Animatable2.AnimationCallback() { |
| 255 | @Override |
| 256 | public void onAnimationEnd(Drawable drawable) { |
| 257 | if (getDrawable() == animation && state == getState() |
| 258 | && doesAnimationLoop(iconAnimRes)) { |
| 259 | animation.start(); |
Ian | aee1b2a | 2019-05-10 16:48:22 -0700 | [diff] [blame] | 260 | } else { |
| 261 | Trace.endAsyncSection("LockIcon#Animation", state); |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 262 | } |
Lucas Dupin | f3b2629 | 2019-03-14 16:06:22 -0700 | [diff] [blame] | 263 | } |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 264 | }); |
Ian | aee1b2a | 2019-05-10 16:48:22 -0700 | [diff] [blame] | 265 | Trace.beginAsyncSection("LockIcon#Animation", state); |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 266 | animation.start(); |
| 267 | } |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 268 | } |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 269 | updateDarkTint(); |
Jorim Jaggi | 8dea48c | 2016-11-28 14:47:45 +0100 | [diff] [blame] | 270 | |
Jorim Jaggi | 864e64b | 2015-05-20 14:13:23 -0700 | [diff] [blame] | 271 | mLastState = state; |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 272 | mLastDozing = mDozing; |
| 273 | mLastPulsing = mPulsing; |
Lucas Dupin | 0590465 | 2019-04-09 16:16:15 -0700 | [diff] [blame] | 274 | mLastBouncerVisible = mBouncerVisible; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Lucas Dupin | 71f3804 | 2019-05-10 16:23:04 -0700 | [diff] [blame] | 277 | boolean onAodNotPulsingOrDocked = mDozing && (!mPulsing || mDocked); |
Lucas Dupin | 23964c7 | 2019-05-21 16:12:45 -0700 | [diff] [blame] | 278 | boolean invisible = onAodNotPulsingOrDocked || mWakeAndUnlockRunning |
| 279 | || mShowingLaunchAffordance; |
Lucas Dupin | d722135 | 2019-04-29 19:43:11 -0700 | [diff] [blame] | 280 | setVisibility(invisible ? INVISIBLE : VISIBLE); |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 281 | updateClickability(); |
| 282 | } |
| 283 | |
| 284 | private void updateClickability() { |
| 285 | if (mAccessibilityController == null) { |
| 286 | return; |
| 287 | } |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 288 | boolean canLock = mUnlockMethodCache.isMethodSecure() |
| 289 | && mUnlockMethodCache.canSkipBouncer(); |
Adrian Roos | a94e964 | 2017-08-17 17:29:19 +0200 | [diff] [blame] | 290 | boolean clickToUnlock = mAccessibilityController.isAccessibilityEnabled(); |
Lucas Dupin | 0df60fe | 2019-04-23 10:19:27 -0700 | [diff] [blame] | 291 | setClickable(clickToUnlock); |
| 292 | setLongClickable(canLock && !clickToUnlock); |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 293 | setFocusable(mAccessibilityController.isAccessibilityEnabled()); |
| 294 | } |
| 295 | |
Selim Cinek | c99d9a95 | 2015-06-19 18:44:50 -0700 | [diff] [blame] | 296 | @Override |
| 297 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
| 298 | super.onInitializeAccessibilityNodeInfo(info); |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 299 | boolean fingerprintRunning = mKeyguardUpdateMonitor.isFingerprintDetectionRunning(); |
| 300 | boolean unlockingAllowed = mKeyguardUpdateMonitor.isUnlockingWithBiometricAllowed(); |
Lucas Dupin | c2d11b3 | 2019-03-06 16:02:18 -0800 | [diff] [blame] | 301 | if (fingerprintRunning && unlockingAllowed) { |
Selim Cinek | c99d9a95 | 2015-06-19 18:44:50 -0700 | [diff] [blame] | 302 | AccessibilityNodeInfo.AccessibilityAction unlock |
| 303 | = new AccessibilityNodeInfo.AccessibilityAction( |
| 304 | AccessibilityNodeInfo.ACTION_CLICK, |
| 305 | getContext().getString(R.string.accessibility_unlock_without_fingerprint)); |
| 306 | info.addAction(unlock); |
Selim Cinek | 947c77c | 2017-03-23 14:20:32 -0700 | [diff] [blame] | 307 | info.setHintText(getContext().getString( |
| 308 | R.string.accessibility_waiting_for_fingerprint)); |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 309 | } else if (mIsFaceUnlockState) { |
Bingyu Zhang | bfe6dcf | 2018-04-25 10:20:36 -0700 | [diff] [blame] | 310 | //Avoid 'button' to be spoken for scanning face |
| 311 | info.setClassName(LockIcon.class.getName()); |
| 312 | info.setContentDescription(getContext().getString( |
| 313 | R.string.accessibility_scanning_face)); |
Selim Cinek | c99d9a95 | 2015-06-19 18:44:50 -0700 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 317 | private int getIconForState(int state) { |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 318 | int iconRes; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 319 | switch (state) { |
| 320 | case STATE_LOCKED: |
Lucas Dupin | c2d11b3 | 2019-03-06 16:02:18 -0800 | [diff] [blame] | 321 | // Scanning animation is a pulsing padlock. This means that the resting state is |
| 322 | // just a padlock. |
| 323 | case STATE_SCANNING_FACE: |
| 324 | // Error animation also starts and ands on the padlock. |
| 325 | case STATE_BIOMETRICS_ERROR: |
Lucas Dupin | ce56d3b | 2019-03-07 13:02:25 -0800 | [diff] [blame] | 326 | iconRes = com.android.internal.R.drawable.ic_lock; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 327 | break; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 328 | case STATE_LOCK_OPEN: |
Lucas Dupin | ce56d3b | 2019-03-07 13:02:25 -0800 | [diff] [blame] | 329 | iconRes = com.android.internal.R.drawable.ic_lock_open; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 330 | break; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 331 | default: |
| 332 | throw new IllegalArgumentException(); |
| 333 | } |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 334 | |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 335 | return iconRes; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Lucas Dupin | f3b2629 | 2019-03-14 16:06:22 -0700 | [diff] [blame] | 338 | private boolean doesAnimationLoop(int resourceId) { |
| 339 | return resourceId == com.android.internal.R.anim.lock_scanning; |
| 340 | } |
| 341 | |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 342 | private int getAnimationResForTransition(int oldState, int newState, |
Lucas Dupin | 0590465 | 2019-04-09 16:16:15 -0700 | [diff] [blame] | 343 | boolean wasPulsing, boolean pulsing, boolean wasDozing, boolean dozing, |
| 344 | boolean bouncerVisible) { |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 345 | |
Lucas Dupin | c2d11b3 | 2019-03-06 16:02:18 -0800 | [diff] [blame] | 346 | // Never animate when screen is off |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 347 | if (dozing && !pulsing && !mWasPulsingOnThisFrame) { |
Lucas Dupin | c2d11b3 | 2019-03-06 16:02:18 -0800 | [diff] [blame] | 348 | return -1; |
| 349 | } |
| 350 | |
| 351 | boolean isError = oldState != STATE_BIOMETRICS_ERROR && newState == STATE_BIOMETRICS_ERROR; |
| 352 | boolean justUnlocked = oldState != STATE_LOCK_OPEN && newState == STATE_LOCK_OPEN; |
| 353 | boolean justLocked = oldState == STATE_LOCK_OPEN && newState == STATE_LOCKED; |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 354 | boolean nowPulsing = !wasPulsing && pulsing; |
| 355 | boolean turningOn = wasDozing && !dozing && !mWasPulsingOnThisFrame; |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 356 | |
| 357 | if (isError) { |
| 358 | return com.android.internal.R.anim.lock_to_error; |
Lucas Dupin | c2d11b3 | 2019-03-06 16:02:18 -0800 | [diff] [blame] | 359 | } else if (justUnlocked) { |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 360 | return com.android.internal.R.anim.lock_unlock; |
Lucas Dupin | c2d11b3 | 2019-03-06 16:02:18 -0800 | [diff] [blame] | 361 | } else if (justLocked) { |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 362 | return com.android.internal.R.anim.lock_lock; |
Lucas Dupin | 0590465 | 2019-04-09 16:16:15 -0700 | [diff] [blame] | 363 | } else if (newState == STATE_SCANNING_FACE && bouncerVisible) { |
Lucas Dupin | c2d11b3 | 2019-03-06 16:02:18 -0800 | [diff] [blame] | 364 | return com.android.internal.R.anim.lock_scanning; |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 365 | } else if ((nowPulsing || turningOn) && newState != STATE_LOCK_OPEN) { |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 366 | return com.android.internal.R.anim.lock_in; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 367 | } |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 368 | return -1; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | private int getState() { |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 372 | KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext); |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 373 | if (mTransientBiometricsError) { |
| 374 | return STATE_BIOMETRICS_ERROR; |
Lucas Dupin | 1cad65e | 2019-05-15 13:47:05 -0700 | [diff] [blame] | 375 | } else if ((mUnlockMethodCache.canSkipBouncer() || !mKeyguardShowing) && !mSimLocked) { |
Selim Cinek | c384198 | 2015-08-25 18:34:29 -0700 | [diff] [blame] | 376 | return STATE_LOCK_OPEN; |
Lucas Dupin | 61de0cb | 2019-04-03 10:20:46 -0700 | [diff] [blame] | 377 | } else if (updateMonitor.isFaceDetectionRunning()) { |
Lucas Dupin | c2d11b3 | 2019-03-06 16:02:18 -0800 | [diff] [blame] | 378 | return STATE_SCANNING_FACE; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 379 | } else { |
| 380 | return STATE_LOCKED; |
| 381 | } |
| 382 | } |
Lucas Dupin | c90a6bf | 2018-10-10 13:53:20 -0700 | [diff] [blame] | 383 | |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 384 | @Override |
| 385 | public void onDozeAmountChanged(float linear, float eased) { |
| 386 | mDozeAmount = eased; |
Lucas Dupin | c90a6bf | 2018-10-10 13:53:20 -0700 | [diff] [blame] | 387 | updateDarkTint(); |
| 388 | } |
| 389 | |
Lucas Dupin | f22194f | 2018-12-26 11:43:57 -0800 | [diff] [blame] | 390 | /** |
| 391 | * When keyguard is in pulsing (AOD2) state. |
| 392 | * @param pulsing {@code true} when pulsing. |
Lucas Dupin | f22194f | 2018-12-26 11:43:57 -0800 | [diff] [blame] | 393 | */ |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 394 | public void setPulsing(boolean pulsing) { |
Lucas Dupin | f22194f | 2018-12-26 11:43:57 -0800 | [diff] [blame] | 395 | mPulsing = pulsing; |
Lucas Dupin | 1aec88f | 2019-05-01 22:25:22 -0700 | [diff] [blame] | 396 | if (!mPulsing) { |
| 397 | mWasPulsingOnThisFrame = true; |
| 398 | mMainHandler.post(() -> { |
| 399 | mWasPulsingOnThisFrame = false; |
| 400 | }); |
| 401 | } |
Lucas Dupin | f22194f | 2018-12-26 11:43:57 -0800 | [diff] [blame] | 402 | update(); |
| 403 | } |
| 404 | |
| 405 | /** |
| 406 | * Sets the dozing state of the keyguard. |
| 407 | */ |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 408 | @Override |
| 409 | public void onDozingChanged(boolean dozing) { |
Lucas Dupin | f22194f | 2018-12-26 11:43:57 -0800 | [diff] [blame] | 410 | mDozing = dozing; |
| 411 | update(); |
| 412 | } |
| 413 | |
Lucas Dupin | c90a6bf | 2018-10-10 13:53:20 -0700 | [diff] [blame] | 414 | private void updateDarkTint() { |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 415 | int color = ColorUtils.blendARGB(mIconColor, Color.WHITE, mDozeAmount); |
| 416 | setImageTintList(ColorStateList.valueOf(color)); |
Lucas Dupin | c90a6bf | 2018-10-10 13:53:20 -0700 | [diff] [blame] | 417 | } |
Lucas Dupin | 0590465 | 2019-04-09 16:16:15 -0700 | [diff] [blame] | 418 | |
| 419 | /** |
| 420 | * If bouncer is visible or not. |
| 421 | */ |
| 422 | public void setBouncerVisible(boolean bouncerVisible) { |
| 423 | if (mBouncerVisible == bouncerVisible) { |
| 424 | return; |
| 425 | } |
| 426 | mBouncerVisible = bouncerVisible; |
| 427 | update(); |
| 428 | } |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 429 | |
| 430 | @Override |
| 431 | public void onDensityOrFontScaleChanged() { |
| 432 | ViewGroup.LayoutParams lp = getLayoutParams(); |
| 433 | if (lp == null) { |
| 434 | return; |
| 435 | } |
| 436 | lp.width = getResources().getDimensionPixelSize(R.dimen.keyguard_lock_width); |
| 437 | lp.height = getResources().getDimensionPixelSize(R.dimen.keyguard_lock_height); |
| 438 | setLayoutParams(lp); |
| 439 | update(true /* force */); |
| 440 | } |
| 441 | |
| 442 | @Override |
| 443 | public void onLocaleListChanged() { |
| 444 | setContentDescription(getContext().getText(R.string.accessibility_unlock_button)); |
| 445 | update(true /* force */); |
| 446 | } |
| 447 | |
| 448 | @Override |
| 449 | public void onUnlockMethodStateChanged() { |
| 450 | update(); |
| 451 | } |
Lucas Dupin | 71f3804 | 2019-05-10 16:23:04 -0700 | [diff] [blame] | 452 | |
| 453 | /** |
| 454 | * We need to hide the lock whenever there's a fingerprint unlock, otherwise you'll see the |
| 455 | * icon on top of the black front scrim. |
| 456 | */ |
| 457 | public void onBiometricAuthModeChanged(boolean wakeAndUnlock) { |
| 458 | if (wakeAndUnlock) { |
| 459 | mWakeAndUnlockRunning = true; |
| 460 | } |
| 461 | update(); |
| 462 | } |
| 463 | |
| 464 | /** |
Lucas Dupin | 23964c7 | 2019-05-21 16:12:45 -0700 | [diff] [blame] | 465 | * When we're launching an affordance, like double pressing power to open camera. |
| 466 | */ |
| 467 | public void onShowingLaunchAffordanceChanged(boolean showing) { |
| 468 | mShowingLaunchAffordance = showing; |
| 469 | update(); |
| 470 | } |
| 471 | |
| 472 | /** |
Lucas Dupin | cdbb1cb | 2019-05-16 19:48:30 -0700 | [diff] [blame] | 473 | * Called whenever the scrims become opaque, transparent or semi-transparent. |
Lucas Dupin | 71f3804 | 2019-05-10 16:23:04 -0700 | [diff] [blame] | 474 | */ |
Lucas Dupin | cdbb1cb | 2019-05-16 19:48:30 -0700 | [diff] [blame] | 475 | public void onScrimVisibilityChanged(@ScrimVisibility int scrimsVisible) { |
| 476 | if (mWakeAndUnlockRunning |
| 477 | && scrimsVisible == ScrimController.VISIBILITY_FULLY_TRANSPARENT) { |
| 478 | mWakeAndUnlockRunning = false; |
| 479 | update(); |
| 480 | } |
Lucas Dupin | 71f3804 | 2019-05-10 16:23:04 -0700 | [diff] [blame] | 481 | } |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 482 | } |