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 | |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 19 | import android.content.Context; |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 20 | import android.content.res.Configuration; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 21 | import android.graphics.drawable.AnimatedVectorDrawable; |
| 22 | import android.graphics.drawable.Drawable; |
| 23 | import android.graphics.drawable.InsetDrawable; |
| 24 | import android.util.AttributeSet; |
| 25 | import android.view.View; |
Selim Cinek | c99d9a95 | 2015-06-19 18:44:50 -0700 | [diff] [blame] | 26 | import android.view.accessibility.AccessibilityNodeInfo; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 27 | |
| 28 | import com.android.keyguard.KeyguardUpdateMonitor; |
| 29 | import com.android.systemui.R; |
| 30 | import com.android.systemui.statusbar.KeyguardAffordanceView; |
| 31 | import com.android.systemui.statusbar.policy.AccessibilityController; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 32 | import com.android.systemui.statusbar.policy.UserInfoController.OnUserInfoChangedListener; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Manages the different states and animations of the unlock icon. |
| 36 | */ |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 37 | public class LockIcon extends KeyguardAffordanceView implements OnUserInfoChangedListener { |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 38 | |
Jorim Jaggi | 8dea48c | 2016-11-28 14:47:45 +0100 | [diff] [blame] | 39 | private static final int FP_DRAW_OFF_TIMEOUT = 800; |
| 40 | |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 41 | private static final int STATE_LOCKED = 0; |
| 42 | private static final int STATE_LOCK_OPEN = 1; |
| 43 | private static final int STATE_FACE_UNLOCK = 2; |
| 44 | private static final int STATE_FINGERPRINT = 3; |
| 45 | private static final int STATE_FINGERPRINT_ERROR = 4; |
| 46 | |
| 47 | private int mLastState = 0; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 48 | private boolean mLastDeviceInteractive; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 49 | private boolean mTransientFpError; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 50 | private boolean mDeviceInteractive; |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 51 | private boolean mScreenOn; |
| 52 | private boolean mLastScreenOn; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 53 | private Drawable mUserAvatarIcon; |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 54 | private TrustDrawable mTrustDrawable; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 55 | private final UnlockMethodCache mUnlockMethodCache; |
| 56 | private AccessibilityController mAccessibilityController; |
Selim Cinek | c99d9a95 | 2015-06-19 18:44:50 -0700 | [diff] [blame] | 57 | private boolean mHasFingerPrintIcon; |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 58 | private int mDensity; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 59 | |
Jorim Jaggi | 8dea48c | 2016-11-28 14:47:45 +0100 | [diff] [blame] | 60 | private final Runnable mDrawOffTimeout = () -> update(true /* forceUpdate */); |
| 61 | |
Jorim Jaggi | 582b57f | 2015-04-28 16:28:26 -0700 | [diff] [blame] | 62 | public LockIcon(Context context, AttributeSet attrs) { |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 63 | super(context, attrs); |
| 64 | mTrustDrawable = new TrustDrawable(context); |
| 65 | setBackground(mTrustDrawable); |
| 66 | mUnlockMethodCache = UnlockMethodCache.getInstance(context); |
| 67 | } |
| 68 | |
| 69 | @Override |
Jorim Jaggi | 582b57f | 2015-04-28 16:28:26 -0700 | [diff] [blame] | 70 | protected void onVisibilityChanged(View changedView, int visibility) { |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 71 | super.onVisibilityChanged(changedView, visibility); |
| 72 | if (isShown()) { |
| 73 | mTrustDrawable.start(); |
| 74 | } else { |
| 75 | mTrustDrawable.stop(); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | protected void onDetachedFromWindow() { |
| 81 | super.onDetachedFromWindow(); |
| 82 | mTrustDrawable.stop(); |
| 83 | } |
| 84 | |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 85 | @Override |
| 86 | public void onUserInfoChanged(String name, Drawable picture, String userAccount) { |
| 87 | mUserAvatarIcon = picture; |
| 88 | update(); |
| 89 | } |
| 90 | |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 91 | public void setTransientFpError(boolean transientFpError) { |
| 92 | mTransientFpError = transientFpError; |
| 93 | update(); |
| 94 | } |
| 95 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 96 | public void setDeviceInteractive(boolean deviceInteractive) { |
| 97 | mDeviceInteractive = deviceInteractive; |
Jorim Jaggi | 864e64b | 2015-05-20 14:13:23 -0700 | [diff] [blame] | 98 | update(); |
| 99 | } |
| 100 | |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 101 | public void setScreenOn(boolean screenOn) { |
| 102 | mScreenOn = screenOn; |
| 103 | update(); |
| 104 | } |
| 105 | |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 106 | @Override |
| 107 | protected void onConfigurationChanged(Configuration newConfig) { |
| 108 | super.onConfigurationChanged(newConfig); |
| 109 | final int density = newConfig.densityDpi; |
| 110 | if (density != mDensity) { |
| 111 | mDensity = density; |
| 112 | mTrustDrawable.stop(); |
| 113 | mTrustDrawable = new TrustDrawable(getContext()); |
| 114 | setBackground(mTrustDrawable); |
| 115 | update(); |
| 116 | } |
| 117 | } |
| 118 | |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 119 | public void update() { |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 120 | update(false /* force */); |
| 121 | } |
| 122 | |
| 123 | public void update(boolean force) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 124 | boolean visible = isShown() |
| 125 | && KeyguardUpdateMonitor.getInstance(mContext).isDeviceInteractive(); |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 126 | if (visible) { |
| 127 | mTrustDrawable.start(); |
| 128 | } else { |
| 129 | mTrustDrawable.stop(); |
| 130 | } |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 131 | int state = getState(); |
| 132 | boolean anyFingerprintIcon = state == STATE_FINGERPRINT || state == STATE_FINGERPRINT_ERROR; |
Selim Cinek | c384198 | 2015-08-25 18:34:29 -0700 | [diff] [blame] | 133 | boolean useAdditionalPadding = anyFingerprintIcon; |
| 134 | boolean trustHidden = anyFingerprintIcon; |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 135 | if (state != mLastState || mDeviceInteractive != mLastDeviceInteractive |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 136 | || mScreenOn != mLastScreenOn || force) { |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 137 | int iconAnimRes = |
| 138 | getAnimationResForTransition(mLastState, state, mLastDeviceInteractive, |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 139 | mDeviceInteractive, mLastScreenOn, mScreenOn); |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 140 | boolean isAnim = iconAnimRes != -1; |
| 141 | if (iconAnimRes == R.drawable.lockscreen_fingerprint_draw_off_animation) { |
Jorim Jaggi | 864e64b | 2015-05-20 14:13:23 -0700 | [diff] [blame] | 142 | anyFingerprintIcon = true; |
Selim Cinek | c384198 | 2015-08-25 18:34:29 -0700 | [diff] [blame] | 143 | useAdditionalPadding = true; |
| 144 | trustHidden = true; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 145 | } else if (iconAnimRes == R.drawable.trusted_state_to_error_animation) { |
Selim Cinek | c384198 | 2015-08-25 18:34:29 -0700 | [diff] [blame] | 146 | anyFingerprintIcon = true; |
| 147 | useAdditionalPadding = false; |
| 148 | trustHidden = true; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 149 | } else if (iconAnimRes == R.drawable.error_to_trustedstate_animation) { |
Selim Cinek | c384198 | 2015-08-25 18:34:29 -0700 | [diff] [blame] | 150 | anyFingerprintIcon = true; |
| 151 | useAdditionalPadding = false; |
| 152 | trustHidden = false; |
Jorim Jaggi | 864e64b | 2015-05-20 14:13:23 -0700 | [diff] [blame] | 153 | } |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 154 | |
| 155 | Drawable icon; |
| 156 | if (isAnim) { |
| 157 | // Load the animation resource. |
| 158 | icon = mContext.getDrawable(iconAnimRes); |
| 159 | } else { |
| 160 | // Load the static icon resource based on the current state. |
| 161 | icon = getIconForState(state, mScreenOn, mDeviceInteractive); |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 162 | } |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 163 | |
Jorim Jaggi | 864e64b | 2015-05-20 14:13:23 -0700 | [diff] [blame] | 164 | final AnimatedVectorDrawable animation = icon instanceof AnimatedVectorDrawable |
| 165 | ? (AnimatedVectorDrawable) icon |
| 166 | : null; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 167 | int iconHeight = getResources().getDimensionPixelSize( |
| 168 | R.dimen.keyguard_affordance_icon_height); |
| 169 | int iconWidth = getResources().getDimensionPixelSize( |
| 170 | R.dimen.keyguard_affordance_icon_width); |
| 171 | if (!anyFingerprintIcon && (icon.getIntrinsicHeight() != iconHeight |
| 172 | || icon.getIntrinsicWidth() != iconWidth)) { |
| 173 | icon = new IntrinsicSizeDrawable(icon, iconWidth, iconHeight); |
| 174 | } |
Selim Cinek | c384198 | 2015-08-25 18:34:29 -0700 | [diff] [blame] | 175 | setPaddingRelative(0, 0, 0, useAdditionalPadding |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 176 | ? getResources().getDimensionPixelSize( |
| 177 | R.dimen.fingerprint_icon_additional_padding) |
| 178 | : 0); |
| 179 | setRestingAlpha( |
| 180 | anyFingerprintIcon ? 1f : KeyguardAffordanceHelper.SWIPE_RESTING_ALPHA_AMOUNT); |
Evan Laird | b0ddf87 | 2017-07-24 15:52:59 -0400 | [diff] [blame] | 181 | setImageDrawable(icon, false); |
Selim Cinek | c99d9a95 | 2015-06-19 18:44:50 -0700 | [diff] [blame] | 182 | mHasFingerPrintIcon = anyFingerprintIcon; |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 183 | if (animation != null && isAnim) { |
Jorim Jaggi | 23bb84b | 2016-06-30 19:11:38 -0700 | [diff] [blame] | 184 | animation.forceAnimationOnUI(); |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 185 | animation.start(); |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 186 | } |
Jorim Jaggi | 8dea48c | 2016-11-28 14:47:45 +0100 | [diff] [blame] | 187 | |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 188 | if (iconAnimRes == R.drawable.lockscreen_fingerprint_draw_off_animation) { |
Jorim Jaggi | 8dea48c | 2016-11-28 14:47:45 +0100 | [diff] [blame] | 189 | removeCallbacks(mDrawOffTimeout); |
| 190 | postDelayed(mDrawOffTimeout, FP_DRAW_OFF_TIMEOUT); |
| 191 | } else { |
| 192 | removeCallbacks(mDrawOffTimeout); |
| 193 | } |
| 194 | |
Jorim Jaggi | 864e64b | 2015-05-20 14:13:23 -0700 | [diff] [blame] | 195 | mLastState = state; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 196 | mLastDeviceInteractive = mDeviceInteractive; |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 197 | mLastScreenOn = mScreenOn; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | // Hide trust circle when fingerprint is running. |
Selim Cinek | c384198 | 2015-08-25 18:34:29 -0700 | [diff] [blame] | 201 | boolean trustManaged = mUnlockMethodCache.isTrustManaged() && !trustHidden; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 202 | mTrustDrawable.setTrustManaged(trustManaged); |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 203 | updateClickability(); |
| 204 | } |
| 205 | |
| 206 | private void updateClickability() { |
| 207 | if (mAccessibilityController == null) { |
| 208 | return; |
| 209 | } |
Adrian Roos | a94e964 | 2017-08-17 17:29:19 +0200 | [diff] [blame] | 210 | boolean clickToUnlock = mAccessibilityController.isAccessibilityEnabled(); |
Jorim Jaggi | 16093fe3 | 2015-09-09 23:29:17 +0000 | [diff] [blame] | 211 | boolean clickToForceLock = mUnlockMethodCache.isTrustManaged() |
Adrian Roos | a94e964 | 2017-08-17 17:29:19 +0200 | [diff] [blame] | 212 | && !clickToUnlock; |
Jorim Jaggi | 16093fe3 | 2015-09-09 23:29:17 +0000 | [diff] [blame] | 213 | boolean longClickToForceLock = mUnlockMethodCache.isTrustManaged() |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 214 | && !clickToForceLock; |
| 215 | setClickable(clickToForceLock || clickToUnlock); |
| 216 | setLongClickable(longClickToForceLock); |
| 217 | setFocusable(mAccessibilityController.isAccessibilityEnabled()); |
| 218 | } |
| 219 | |
Selim Cinek | c99d9a95 | 2015-06-19 18:44:50 -0700 | [diff] [blame] | 220 | @Override |
| 221 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
| 222 | super.onInitializeAccessibilityNodeInfo(info); |
| 223 | if (mHasFingerPrintIcon) { |
Selim Cinek | c99d9a95 | 2015-06-19 18:44:50 -0700 | [diff] [blame] | 224 | AccessibilityNodeInfo.AccessibilityAction unlock |
| 225 | = new AccessibilityNodeInfo.AccessibilityAction( |
| 226 | AccessibilityNodeInfo.ACTION_CLICK, |
| 227 | getContext().getString(R.string.accessibility_unlock_without_fingerprint)); |
| 228 | info.addAction(unlock); |
Selim Cinek | 947c77c | 2017-03-23 14:20:32 -0700 | [diff] [blame] | 229 | info.setHintText(getContext().getString( |
| 230 | R.string.accessibility_waiting_for_fingerprint)); |
Selim Cinek | c99d9a95 | 2015-06-19 18:44:50 -0700 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 234 | public void setAccessibilityController(AccessibilityController accessibilityController) { |
| 235 | mAccessibilityController = accessibilityController; |
| 236 | } |
| 237 | |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 238 | private Drawable getIconForState(int state, boolean screenOn, boolean deviceInteractive) { |
| 239 | int iconRes; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 240 | switch (state) { |
| 241 | case STATE_LOCKED: |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 242 | iconRes = R.drawable.ic_lock_24dp; |
| 243 | break; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 244 | case STATE_LOCK_OPEN: |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 245 | if (mUnlockMethodCache.isTrustManaged() && mUnlockMethodCache.isTrusted() |
| 246 | && mUserAvatarIcon != null) { |
| 247 | return mUserAvatarIcon; |
| 248 | } else { |
| 249 | iconRes = R.drawable.ic_lock_open_24dp; |
| 250 | } |
| 251 | break; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 252 | case STATE_FACE_UNLOCK: |
Lucas Dupin | 334f954 | 2018-01-16 11:24:46 -0800 | [diff] [blame] | 253 | iconRes = R.drawable.ic_face_unlock; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 254 | break; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 255 | case STATE_FINGERPRINT: |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 256 | // If screen is off and device asleep, use the draw on animation so the first frame |
| 257 | // gets drawn. |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 258 | iconRes = screenOn && deviceInteractive |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 259 | ? R.drawable.ic_fingerprint |
| 260 | : R.drawable.lockscreen_fingerprint_draw_on_animation; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 261 | break; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 262 | case STATE_FINGERPRINT_ERROR: |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 263 | iconRes = R.drawable.ic_fingerprint_error; |
| 264 | break; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 265 | default: |
| 266 | throw new IllegalArgumentException(); |
| 267 | } |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 268 | |
| 269 | return mContext.getDrawable(iconRes); |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 272 | private int getAnimationResForTransition(int oldState, int newState, |
| 273 | boolean oldDeviceInteractive, boolean deviceInteractive, |
| 274 | boolean oldScreenOn, boolean screenOn) { |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 275 | if (oldState == STATE_FINGERPRINT && newState == STATE_FINGERPRINT_ERROR) { |
Jorim Jaggi | 864e64b | 2015-05-20 14:13:23 -0700 | [diff] [blame] | 276 | return R.drawable.lockscreen_fingerprint_fp_to_error_state_animation; |
Selim Cinek | c384198 | 2015-08-25 18:34:29 -0700 | [diff] [blame] | 277 | } else if (oldState == STATE_LOCK_OPEN && newState == STATE_FINGERPRINT_ERROR) { |
| 278 | return R.drawable.trusted_state_to_error_animation; |
| 279 | } else if (oldState == STATE_FINGERPRINT_ERROR && newState == STATE_LOCK_OPEN) { |
| 280 | return R.drawable.error_to_trustedstate_animation; |
Jorim Jaggi | 864e64b | 2015-05-20 14:13:23 -0700 | [diff] [blame] | 281 | } else if (oldState == STATE_FINGERPRINT_ERROR && newState == STATE_FINGERPRINT) { |
| 282 | return R.drawable.lockscreen_fingerprint_error_state_to_fp_animation; |
Selim Cinek | 2a46d68 | 2015-06-25 19:44:05 -0400 | [diff] [blame] | 283 | } else if (oldState == STATE_FINGERPRINT && newState == STATE_LOCK_OPEN |
Selim Cinek | e8bae62 | 2015-07-15 13:24:06 -0700 | [diff] [blame] | 284 | && !mUnlockMethodCache.isTrusted()) { |
Jorim Jaggi | 864e64b | 2015-05-20 14:13:23 -0700 | [diff] [blame] | 285 | return R.drawable.lockscreen_fingerprint_draw_off_animation; |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 286 | } else if (newState == STATE_FINGERPRINT && (!oldScreenOn && screenOn && deviceInteractive |
| 287 | || screenOn && !oldDeviceInteractive && deviceInteractive)) { |
Jorim Jaggi | 864e64b | 2015-05-20 14:13:23 -0700 | [diff] [blame] | 288 | return R.drawable.lockscreen_fingerprint_draw_on_animation; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 289 | } else { |
| 290 | return -1; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | private int getState() { |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 295 | KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext); |
| 296 | boolean fingerprintRunning = updateMonitor.isFingerprintDetectionRunning(); |
| 297 | boolean unlockingAllowed = updateMonitor.isUnlockingWithFingerprintAllowed(); |
Selim Cinek | c384198 | 2015-08-25 18:34:29 -0700 | [diff] [blame] | 298 | if (mTransientFpError) { |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 299 | return STATE_FINGERPRINT_ERROR; |
Selim Cinek | c384198 | 2015-08-25 18:34:29 -0700 | [diff] [blame] | 300 | } else if (mUnlockMethodCache.canSkipBouncer()) { |
| 301 | return STATE_LOCK_OPEN; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 302 | } else if (mUnlockMethodCache.isFaceUnlockRunning()) { |
| 303 | return STATE_FACE_UNLOCK; |
Adrian Roos | e07cbaf | 2015-09-02 13:29:42 -0700 | [diff] [blame] | 304 | } else if (fingerprintRunning && unlockingAllowed) { |
| 305 | return STATE_FINGERPRINT; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 306 | } else { |
| 307 | return STATE_LOCKED; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * A wrapper around another Drawable that overrides the intrinsic size. |
| 313 | */ |
| 314 | private static class IntrinsicSizeDrawable extends InsetDrawable { |
| 315 | |
| 316 | private final int mIntrinsicWidth; |
| 317 | private final int mIntrinsicHeight; |
| 318 | |
| 319 | public IntrinsicSizeDrawable(Drawable drawable, int intrinsicWidth, int intrinsicHeight) { |
| 320 | super(drawable, 0); |
| 321 | mIntrinsicWidth = intrinsicWidth; |
| 322 | mIntrinsicHeight = intrinsicHeight; |
| 323 | } |
| 324 | |
| 325 | @Override |
| 326 | public int getIntrinsicWidth() { |
| 327 | return mIntrinsicWidth; |
| 328 | } |
| 329 | |
| 330 | @Override |
| 331 | public int getIntrinsicHeight() { |
| 332 | return mIntrinsicHeight; |
| 333 | } |
| 334 | } |
| 335 | } |