Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +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.phone; |
| 18 | |
| 19 | import android.app.ActivityManagerNative; |
| 20 | import android.app.admin.DevicePolicyManager; |
| 21 | import android.content.BroadcastReceiver; |
| 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
| 24 | import android.content.IntentFilter; |
Jorim Jaggi | 97b63c4 | 2014-05-02 23:03:34 +0200 | [diff] [blame] | 25 | import android.content.pm.PackageManager; |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 26 | import android.content.pm.ResolveInfo; |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 27 | import android.content.res.Configuration; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 28 | import android.content.res.Resources; |
Adrian Roos | 72cc370 | 2014-09-18 17:25:09 +0200 | [diff] [blame] | 29 | import android.graphics.drawable.Drawable; |
| 30 | import android.graphics.drawable.InsetDrawable; |
Jim Miller | fe6439f | 2015-04-11 18:07:57 -0700 | [diff] [blame] | 31 | import android.hardware.fingerprint.FingerprintManager; |
Yorke Lee | 583a2024 | 2014-08-12 18:47:08 -0700 | [diff] [blame] | 32 | import android.os.AsyncTask; |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 33 | import android.os.Bundle; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 34 | import android.os.RemoteException; |
| 35 | import android.os.UserHandle; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 36 | import android.os.Vibrator; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 37 | import android.provider.MediaStore; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 38 | import android.provider.Settings; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 39 | import android.telecom.TelecomManager; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 40 | import android.util.AttributeSet; |
| 41 | import android.util.Log; |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 42 | import android.util.TypedValue; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 43 | import android.view.View; |
Jorim Jaggi | b6cdcbc | 2014-07-25 21:58:29 +0200 | [diff] [blame] | 44 | import android.view.ViewGroup; |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 45 | import android.view.accessibility.AccessibilityNodeInfo; |
Jorim Jaggi | 16423aa | 2014-10-28 11:42:58 +0100 | [diff] [blame] | 46 | import android.view.animation.AnimationUtils; |
| 47 | import android.view.animation.Interpolator; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 48 | import android.widget.FrameLayout; |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 49 | import android.widget.TextView; |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 50 | |
| 51 | import com.android.internal.widget.LockPatternUtils; |
| 52 | import com.android.keyguard.KeyguardUpdateMonitor; |
| 53 | import com.android.keyguard.KeyguardUpdateMonitorCallback; |
Christoph Studer | b018399 | 2014-12-22 21:02:26 +0100 | [diff] [blame] | 54 | import com.android.systemui.EventLogConstants; |
| 55 | import com.android.systemui.EventLogTags; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 56 | import com.android.systemui.R; |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 57 | import com.android.systemui.statusbar.CommandQueue; |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 58 | import com.android.systemui.statusbar.KeyguardAffordanceView; |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 59 | import com.android.systemui.statusbar.KeyguardIndicationController; |
| 60 | import com.android.systemui.statusbar.policy.AccessibilityController; |
| 61 | import com.android.systemui.statusbar.policy.FlashlightController; |
Jorim Jaggi | b6cdcbc | 2014-07-25 21:58:29 +0200 | [diff] [blame] | 62 | import com.android.systemui.statusbar.policy.PreviewInflater; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 63 | |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 64 | import static android.view.accessibility.AccessibilityNodeInfo.ACTION_CLICK; |
| 65 | import static android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; |
| 66 | |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 67 | /** |
| 68 | * Implementation for the bottom area of the Keyguard, including camera/phone affordance and status |
| 69 | * text. |
| 70 | */ |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 71 | public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickListener, |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 72 | UnlockMethodCache.OnUnlockMethodChangedListener, |
| 73 | AccessibilityController.AccessibilityStateChangedCallback, View.OnLongClickListener { |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 74 | |
| 75 | final static String TAG = "PhoneStatusBar/KeyguardBottomAreaView"; |
| 76 | |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 77 | private static final Intent SECURE_CAMERA_INTENT = |
| 78 | new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE) |
| 79 | .addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 80 | private static final Intent INSECURE_CAMERA_INTENT = |
| 81 | new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); |
Jorim Jaggi | 97b63c4 | 2014-05-02 23:03:34 +0200 | [diff] [blame] | 82 | private static final Intent PHONE_INTENT = new Intent(Intent.ACTION_DIAL); |
Jorim Jaggi | 16423aa | 2014-10-28 11:42:58 +0100 | [diff] [blame] | 83 | private static final int DOZE_ANIMATION_STAGGER_DELAY = 48; |
| 84 | private static final int DOZE_ANIMATION_ELEMENT_DURATION = 250; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 85 | private static final long TRANSIENT_FP_ERROR_TIMEOUT = 1300; |
| 86 | private static final long[] FP_ERROR_VIBRATE_PATTERN = new long[] {0, 30, 100, 30}; |
| 87 | private static final long[] FP_SUCCESS_VIBRATE_PATTERN = new long[] {0, 30}; |
Jorim Jaggi | 97b63c4 | 2014-05-02 23:03:34 +0200 | [diff] [blame] | 88 | |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 89 | private KeyguardAffordanceView mCameraImageView; |
| 90 | private KeyguardAffordanceView mPhoneImageView; |
| 91 | private KeyguardAffordanceView mLockIcon; |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 92 | private TextView mIndicationText; |
Jorim Jaggi | b6cdcbc | 2014-07-25 21:58:29 +0200 | [diff] [blame] | 93 | private ViewGroup mPreviewContainer; |
| 94 | |
| 95 | private View mPhonePreview; |
| 96 | private View mCameraPreview; |
Jorim Jaggi | 97b63c4 | 2014-05-02 23:03:34 +0200 | [diff] [blame] | 97 | |
Jorim Jaggi | 97b63c4 | 2014-05-02 23:03:34 +0200 | [diff] [blame] | 98 | private ActivityStarter mActivityStarter; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 99 | private UnlockMethodCache mUnlockMethodCache; |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 100 | private LockPatternUtils mLockPatternUtils; |
Adrian Roos | 1e1d6ac | 2014-07-22 17:18:55 +0200 | [diff] [blame] | 101 | private FlashlightController mFlashlightController; |
Jorim Jaggi | 781c29c | 2014-08-05 20:39:15 +0200 | [diff] [blame] | 102 | private PreviewInflater mPreviewInflater; |
Adrian Roos | 4ebcdfd | 2014-08-12 23:33:49 +0200 | [diff] [blame] | 103 | private KeyguardIndicationController mIndicationController; |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 104 | private AccessibilityController mAccessibilityController; |
| 105 | private PhoneStatusBar mPhoneStatusBar; |
Adrian Roos | 2fe592d | 2014-05-17 03:11:59 +0200 | [diff] [blame] | 106 | |
Adrian Roos | 2e3ccbb | 2014-08-19 22:23:37 +0200 | [diff] [blame] | 107 | private final TrustDrawable mTrustDrawable; |
Jorim Jaggi | 16423aa | 2014-10-28 11:42:58 +0100 | [diff] [blame] | 108 | private final Interpolator mLinearOutSlowInInterpolator; |
Adrian Roos | 72cc370 | 2014-09-18 17:25:09 +0200 | [diff] [blame] | 109 | private int mLastUnlockIconRes = 0; |
Jorim Jaggi | a86790b | 2015-04-02 16:32:29 -0700 | [diff] [blame] | 110 | private boolean mPrewarmSent; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 111 | private boolean mTransientFpError; |
Adrian Roos | 72cc370 | 2014-09-18 17:25:09 +0200 | [diff] [blame] | 112 | |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 113 | public KeyguardBottomAreaView(Context context) { |
Adrian Roos | 2e3ccbb | 2014-08-19 22:23:37 +0200 | [diff] [blame] | 114 | this(context, null); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | public KeyguardBottomAreaView(Context context, AttributeSet attrs) { |
Adrian Roos | 2e3ccbb | 2014-08-19 22:23:37 +0200 | [diff] [blame] | 118 | this(context, attrs, 0); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | public KeyguardBottomAreaView(Context context, AttributeSet attrs, int defStyleAttr) { |
Adrian Roos | 2e3ccbb | 2014-08-19 22:23:37 +0200 | [diff] [blame] | 122 | this(context, attrs, defStyleAttr, 0); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | public KeyguardBottomAreaView(Context context, AttributeSet attrs, int defStyleAttr, |
| 126 | int defStyleRes) { |
| 127 | super(context, attrs, defStyleAttr, defStyleRes); |
Adrian Roos | 2e3ccbb | 2014-08-19 22:23:37 +0200 | [diff] [blame] | 128 | mTrustDrawable = new TrustDrawable(mContext); |
Jorim Jaggi | 16423aa | 2014-10-28 11:42:58 +0100 | [diff] [blame] | 129 | mLinearOutSlowInInterpolator = |
| 130 | AnimationUtils.loadInterpolator(context, android.R.interpolator.linear_out_slow_in); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 131 | } |
| 132 | |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 133 | private AccessibilityDelegate mAccessibilityDelegate = new AccessibilityDelegate() { |
| 134 | @Override |
| 135 | public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { |
| 136 | super.onInitializeAccessibilityNodeInfo(host, info); |
| 137 | String label = null; |
| 138 | if (host == mLockIcon) { |
| 139 | label = getResources().getString(R.string.unlock_label); |
| 140 | } else if (host == mCameraImageView) { |
| 141 | label = getResources().getString(R.string.camera_label); |
| 142 | } else if (host == mPhoneImageView) { |
| 143 | label = getResources().getString(R.string.phone_label); |
| 144 | } |
| 145 | info.addAction(new AccessibilityAction(ACTION_CLICK, label)); |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public boolean performAccessibilityAction(View host, int action, Bundle args) { |
| 150 | if (action == ACTION_CLICK) { |
| 151 | if (host == mLockIcon) { |
| 152 | mPhoneStatusBar.animateCollapsePanels( |
Jorim Jaggi | 4eedc1d | 2014-10-27 13:45:56 +0100 | [diff] [blame] | 153 | CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, true /* force */); |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 154 | return true; |
| 155 | } else if (host == mCameraImageView) { |
| 156 | launchCamera(); |
| 157 | return true; |
| 158 | } else if (host == mPhoneImageView) { |
| 159 | launchPhone(); |
| 160 | return true; |
| 161 | } |
| 162 | } |
| 163 | return super.performAccessibilityAction(host, action, args); |
| 164 | } |
| 165 | }; |
| 166 | |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 167 | @Override |
| 168 | protected void onFinishInflate() { |
| 169 | super.onFinishInflate(); |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 170 | mLockPatternUtils = new LockPatternUtils(mContext); |
Jorim Jaggi | b6cdcbc | 2014-07-25 21:58:29 +0200 | [diff] [blame] | 171 | mPreviewContainer = (ViewGroup) findViewById(R.id.preview_container); |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 172 | mCameraImageView = (KeyguardAffordanceView) findViewById(R.id.camera_button); |
| 173 | mPhoneImageView = (KeyguardAffordanceView) findViewById(R.id.phone_button); |
| 174 | mLockIcon = (KeyguardAffordanceView) findViewById(R.id.lock_icon); |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 175 | mIndicationText = (TextView) findViewById(R.id.keyguard_indication_text); |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 176 | watchForCameraPolicyChanges(); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 177 | updateCameraVisibility(); |
Jorim Jaggi | 97b63c4 | 2014-05-02 23:03:34 +0200 | [diff] [blame] | 178 | updatePhoneVisibility(); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 179 | mUnlockMethodCache = UnlockMethodCache.getInstance(getContext()); |
| 180 | mUnlockMethodCache.addListener(this); |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 181 | updateLockIcon(); |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 182 | setClipChildren(false); |
| 183 | setClipToPadding(false); |
Jorim Jaggi | 781c29c | 2014-08-05 20:39:15 +0200 | [diff] [blame] | 184 | mPreviewInflater = new PreviewInflater(mContext, new LockPatternUtils(mContext)); |
Jorim Jaggi | b6cdcbc | 2014-07-25 21:58:29 +0200 | [diff] [blame] | 185 | inflatePreviews(); |
Adrian Roos | 4ebcdfd | 2014-08-12 23:33:49 +0200 | [diff] [blame] | 186 | mLockIcon.setOnClickListener(this); |
Adrian Roos | 2e3ccbb | 2014-08-19 22:23:37 +0200 | [diff] [blame] | 187 | mLockIcon.setBackground(mTrustDrawable); |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 188 | mLockIcon.setOnLongClickListener(this); |
| 189 | mCameraImageView.setOnClickListener(this); |
| 190 | mPhoneImageView.setOnClickListener(this); |
| 191 | initAccessibility(); |
| 192 | } |
| 193 | |
| 194 | private void initAccessibility() { |
| 195 | mLockIcon.setAccessibilityDelegate(mAccessibilityDelegate); |
| 196 | mPhoneImageView.setAccessibilityDelegate(mAccessibilityDelegate); |
| 197 | mCameraImageView.setAccessibilityDelegate(mAccessibilityDelegate); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 198 | } |
| 199 | |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 200 | @Override |
| 201 | protected void onConfigurationChanged(Configuration newConfig) { |
| 202 | super.onConfigurationChanged(newConfig); |
| 203 | int indicationBottomMargin = getResources().getDimensionPixelSize( |
| 204 | R.dimen.keyguard_indication_margin_bottom); |
| 205 | MarginLayoutParams mlp = (MarginLayoutParams) mIndicationText.getLayoutParams(); |
| 206 | if (mlp.bottomMargin != indicationBottomMargin) { |
| 207 | mlp.bottomMargin = indicationBottomMargin; |
| 208 | mIndicationText.setLayoutParams(mlp); |
| 209 | } |
| 210 | |
| 211 | // Respect font size setting. |
| 212 | mIndicationText.setTextSize(TypedValue.COMPLEX_UNIT_PX, |
| 213 | getResources().getDimensionPixelSize( |
| 214 | com.android.internal.R.dimen.text_size_small_material)); |
| 215 | } |
| 216 | |
Jorim Jaggi | 97b63c4 | 2014-05-02 23:03:34 +0200 | [diff] [blame] | 217 | public void setActivityStarter(ActivityStarter activityStarter) { |
| 218 | mActivityStarter = activityStarter; |
| 219 | } |
| 220 | |
Adrian Roos | 1e1d6ac | 2014-07-22 17:18:55 +0200 | [diff] [blame] | 221 | public void setFlashlightController(FlashlightController flashlightController) { |
| 222 | mFlashlightController = flashlightController; |
| 223 | } |
| 224 | |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 225 | public void setAccessibilityController(AccessibilityController accessibilityController) { |
| 226 | mAccessibilityController = accessibilityController; |
| 227 | accessibilityController.addStateChangedCallback(this); |
| 228 | } |
| 229 | |
| 230 | public void setPhoneStatusBar(PhoneStatusBar phoneStatusBar) { |
| 231 | mPhoneStatusBar = phoneStatusBar; |
Dan Sandler | e163a64 | 2015-03-01 22:58:32 -0500 | [diff] [blame] | 232 | updateCameraVisibility(); // in case onFinishInflate() was called too early |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 233 | } |
| 234 | |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 235 | private Intent getCameraIntent() { |
| 236 | KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext); |
| 237 | boolean currentUserHasTrust = updateMonitor.getUserHasTrust( |
| 238 | mLockPatternUtils.getCurrentUser()); |
| 239 | return mLockPatternUtils.isSecure() && !currentUserHasTrust |
| 240 | ? SECURE_CAMERA_INTENT : INSECURE_CAMERA_INTENT; |
| 241 | } |
| 242 | |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 243 | private void updateCameraVisibility() { |
Dan Sandler | e163a64 | 2015-03-01 22:58:32 -0500 | [diff] [blame] | 244 | if (mCameraImageView == null) { |
| 245 | // Things are not set up yet; reply hazy, ask again later |
| 246 | return; |
| 247 | } |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 248 | ResolveInfo resolved = mContext.getPackageManager().resolveActivityAsUser(getCameraIntent(), |
| 249 | PackageManager.MATCH_DEFAULT_ONLY, |
| 250 | mLockPatternUtils.getCurrentUser()); |
Jorim Jaggi | 15dac5f | 2014-08-27 19:08:26 +0200 | [diff] [blame] | 251 | boolean visible = !isCameraDisabledByDpm() && resolved != null |
| 252 | && getResources().getBoolean(R.bool.config_keyguardShowCameraAffordance); |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 253 | mCameraImageView.setVisibility(visible ? View.VISIBLE : View.GONE); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 254 | } |
| 255 | |
Jorim Jaggi | 97b63c4 | 2014-05-02 23:03:34 +0200 | [diff] [blame] | 256 | private void updatePhoneVisibility() { |
| 257 | boolean visible = isPhoneVisible(); |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 258 | mPhoneImageView.setVisibility(visible ? View.VISIBLE : View.GONE); |
Jorim Jaggi | 97b63c4 | 2014-05-02 23:03:34 +0200 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | private boolean isPhoneVisible() { |
| 262 | PackageManager pm = mContext.getPackageManager(); |
| 263 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY) |
| 264 | && pm.resolveActivity(PHONE_INTENT, 0) != null; |
| 265 | } |
| 266 | |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 267 | private boolean isCameraDisabledByDpm() { |
| 268 | final DevicePolicyManager dpm = |
| 269 | (DevicePolicyManager) getContext().getSystemService(Context.DEVICE_POLICY_SERVICE); |
Dan Sandler | e163a64 | 2015-03-01 22:58:32 -0500 | [diff] [blame] | 270 | if (dpm != null && mPhoneStatusBar != null) { |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 271 | try { |
| 272 | final int userId = ActivityManagerNative.getDefault().getCurrentUser().id; |
| 273 | final int disabledFlags = dpm.getKeyguardDisabledFeatures(null, userId); |
| 274 | final boolean disabledBecauseKeyguardSecure = |
| 275 | (disabledFlags & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA) != 0 |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 276 | && mPhoneStatusBar.isKeyguardSecure(); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 277 | return dpm.getCameraDisabled(null) || disabledBecauseKeyguardSecure; |
| 278 | } catch (RemoteException e) { |
| 279 | Log.e(TAG, "Can't get userId", e); |
| 280 | } |
| 281 | } |
| 282 | return false; |
| 283 | } |
| 284 | |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 285 | private void watchForCameraPolicyChanges() { |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 286 | final IntentFilter filter = new IntentFilter(); |
| 287 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 288 | getContext().registerReceiverAsUser(mDevicePolicyReceiver, |
| 289 | UserHandle.ALL, filter, null, null); |
| 290 | KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallback); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 291 | } |
| 292 | |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 293 | @Override |
| 294 | public void onStateChanged(boolean accessibilityEnabled, boolean touchExplorationEnabled) { |
| 295 | mCameraImageView.setClickable(touchExplorationEnabled); |
| 296 | mPhoneImageView.setClickable(touchExplorationEnabled); |
| 297 | mCameraImageView.setFocusable(accessibilityEnabled); |
| 298 | mPhoneImageView.setFocusable(accessibilityEnabled); |
| 299 | updateLockIconClickability(); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 300 | } |
| 301 | |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 302 | private void updateLockIconClickability() { |
| 303 | if (mAccessibilityController == null) { |
| 304 | return; |
| 305 | } |
Adrian Roos | 38fc7606 | 2014-09-22 17:34:56 +0200 | [diff] [blame] | 306 | boolean clickToUnlock = mAccessibilityController.isTouchExplorationEnabled(); |
| 307 | boolean clickToForceLock = mUnlockMethodCache.isTrustManaged() |
| 308 | && !mAccessibilityController.isAccessibilityEnabled(); |
| 309 | boolean longClickToForceLock = mUnlockMethodCache.isTrustManaged() |
| 310 | && !clickToForceLock; |
| 311 | mLockIcon.setClickable(clickToForceLock || clickToUnlock); |
| 312 | mLockIcon.setLongClickable(longClickToForceLock); |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 313 | mLockIcon.setFocusable(mAccessibilityController.isAccessibilityEnabled()); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 314 | } |
| 315 | |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 316 | @Override |
| 317 | public void onClick(View v) { |
| 318 | if (v == mCameraImageView) { |
| 319 | launchCamera(); |
| 320 | } else if (v == mPhoneImageView) { |
| 321 | launchPhone(); |
Adrian Roos | 4ebcdfd | 2014-08-12 23:33:49 +0200 | [diff] [blame] | 322 | } if (v == mLockIcon) { |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 323 | if (!mAccessibilityController.isAccessibilityEnabled()) { |
| 324 | handleTrustCircleClick(); |
| 325 | } else { |
| 326 | mPhoneStatusBar.animateCollapsePanels( |
| 327 | CommandQueue.FLAG_EXCLUDE_NONE, true /* force */); |
| 328 | } |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 332 | @Override |
| 333 | public boolean onLongClick(View v) { |
| 334 | handleTrustCircleClick(); |
| 335 | return true; |
| 336 | } |
| 337 | |
| 338 | private void handleTrustCircleClick() { |
Christoph Studer | b018399 | 2014-12-22 21:02:26 +0100 | [diff] [blame] | 339 | EventLogTags.writeSysuiLockscreenGesture( |
| 340 | EventLogConstants.SYSUI_LOCKSCREEN_GESTURE_TAP_LOCK, 0 /* lengthDp - N/A */, |
| 341 | 0 /* velocityDp - N/A */); |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 342 | mIndicationController.showTransientIndication( |
| 343 | R.string.keyguard_indication_trust_disabled); |
| 344 | mLockPatternUtils.requireCredentialEntry(mLockPatternUtils.getCurrentUser()); |
| 345 | } |
| 346 | |
Jorim Jaggi | a86790b | 2015-04-02 16:32:29 -0700 | [diff] [blame] | 347 | public void prewarmCamera() { |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 348 | Intent intent = getCameraIntent(); |
Jorim Jaggi | a86790b | 2015-04-02 16:32:29 -0700 | [diff] [blame] | 349 | String targetPackage = PreviewInflater.getTargetPackage(mContext, intent, |
| 350 | mLockPatternUtils.getCurrentUser()); |
| 351 | if (targetPackage != null) { |
| 352 | Intent prewarm = new Intent(MediaStore.ACTION_STILL_IMAGE_CAMERA_PREWARM); |
| 353 | prewarm.setPackage(targetPackage); |
| 354 | mPrewarmSent = true; |
| 355 | mContext.sendBroadcast(prewarm); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | public void maybeCooldownCamera() { |
| 360 | if (!mPrewarmSent) { |
| 361 | return; |
| 362 | } |
| 363 | mPrewarmSent = false; |
| 364 | Intent intent = getCameraIntent(); |
| 365 | String targetPackage = PreviewInflater.getTargetPackage(mContext, intent, |
| 366 | mLockPatternUtils.getCurrentUser()); |
| 367 | if (targetPackage != null) { |
| 368 | Intent prewarm = new Intent(MediaStore.ACTION_STILL_IMAGE_CAMERA_COOLDOWN); |
| 369 | prewarm.setPackage(targetPackage); |
| 370 | mContext.sendBroadcast(prewarm); |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | public void launchCamera() { |
| 375 | |
| 376 | // Reset prewarm state. |
| 377 | mPrewarmSent = false; |
| 378 | final Intent intent = getCameraIntent(); |
Jorim Jaggi | 85dc23c | 2014-09-08 14:42:29 +0200 | [diff] [blame] | 379 | boolean wouldLaunchResolverActivity = PreviewInflater.wouldLaunchResolverActivity( |
| 380 | mContext, intent, mLockPatternUtils.getCurrentUser()); |
Jorim Jaggi | 746f7fa | 2014-08-27 17:52:46 +0200 | [diff] [blame] | 381 | if (intent == SECURE_CAMERA_INTENT && !wouldLaunchResolverActivity) { |
Jorim Jaggi | a86790b | 2015-04-02 16:32:29 -0700 | [diff] [blame] | 382 | AsyncTask.execute(new Runnable() { |
| 383 | @Override |
| 384 | public void run() { |
| 385 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
| 386 | } |
| 387 | }); |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 388 | } else { |
Jorim Jaggi | 746f7fa | 2014-08-27 17:52:46 +0200 | [diff] [blame] | 389 | |
| 390 | // We need to delay starting the activity because ResolverActivity finishes itself if |
| 391 | // launched behind lockscreen. |
Jorim Jaggi | 85dc23c | 2014-09-08 14:42:29 +0200 | [diff] [blame] | 392 | mActivityStarter.startActivity(intent, false /* dismissShade */); |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 393 | } |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 394 | } |
| 395 | |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 396 | public void launchPhone() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 397 | final TelecomManager tm = TelecomManager.from(mContext); |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 398 | if (tm.isInCall()) { |
Yorke Lee | 583a2024 | 2014-08-12 18:47:08 -0700 | [diff] [blame] | 399 | AsyncTask.execute(new Runnable() { |
| 400 | @Override |
| 401 | public void run() { |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 402 | tm.showInCallScreen(false /* showDialpad */); |
Yorke Lee | 583a2024 | 2014-08-12 18:47:08 -0700 | [diff] [blame] | 403 | } |
| 404 | }); |
| 405 | } else { |
Jorim Jaggi | 85dc23c | 2014-09-08 14:42:29 +0200 | [diff] [blame] | 406 | mActivityStarter.startActivity(PHONE_INTENT, false /* dismissShade */); |
Yorke Lee | 583a2024 | 2014-08-12 18:47:08 -0700 | [diff] [blame] | 407 | } |
Jorim Jaggi | 97b63c4 | 2014-05-02 23:03:34 +0200 | [diff] [blame] | 408 | } |
| 409 | |
Adrian Roos | 2fe592d | 2014-05-17 03:11:59 +0200 | [diff] [blame] | 410 | |
| 411 | @Override |
| 412 | protected void onVisibilityChanged(View changedView, int visibility) { |
| 413 | super.onVisibilityChanged(changedView, visibility); |
Adrian Roos | 2e3ccbb | 2014-08-19 22:23:37 +0200 | [diff] [blame] | 414 | if (isShown()) { |
| 415 | mTrustDrawable.start(); |
| 416 | } else { |
| 417 | mTrustDrawable.stop(); |
| 418 | } |
Adrian Roos | 2fe592d | 2014-05-17 03:11:59 +0200 | [diff] [blame] | 419 | if (changedView == this && visibility == VISIBLE) { |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 420 | updateLockIcon(); |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 421 | updateCameraVisibility(); |
Adrian Roos | 2fe592d | 2014-05-17 03:11:59 +0200 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | |
Adrian Roos | 2e3ccbb | 2014-08-19 22:23:37 +0200 | [diff] [blame] | 425 | @Override |
| 426 | protected void onDetachedFromWindow() { |
| 427 | super.onDetachedFromWindow(); |
| 428 | mTrustDrawable.stop(); |
| 429 | } |
| 430 | |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 431 | private void updateLockIcon() { |
Adrian Roos | 2e3ccbb | 2014-08-19 22:23:37 +0200 | [diff] [blame] | 432 | boolean visible = isShown() && KeyguardUpdateMonitor.getInstance(mContext).isScreenOn(); |
| 433 | if (visible) { |
| 434 | mTrustDrawable.start(); |
| 435 | } else { |
| 436 | mTrustDrawable.stop(); |
| 437 | } |
| 438 | if (!visible) { |
Adrian Roos | 2fe592d | 2014-05-17 03:11:59 +0200 | [diff] [blame] | 439 | return; |
| 440 | } |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 441 | // TODO: Real icon for facelock. |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 442 | boolean isFingerprintIcon = |
| 443 | KeyguardUpdateMonitor.getInstance(mContext).isFingerprintDetectionRunning(); |
| 444 | boolean anyFingerprintIcon = isFingerprintIcon || mTransientFpError; |
| 445 | int iconRes = mTransientFpError ? R.drawable.ic_fingerprint_error |
| 446 | : isFingerprintIcon ? R.drawable.ic_fingerprint |
| 447 | : mUnlockMethodCache.isFaceUnlockRunning() |
| 448 | ? com.android.internal.R.drawable.ic_account_circle |
Christoph Studer | 2231c6e | 2014-12-19 12:40:13 +0100 | [diff] [blame] | 449 | : mUnlockMethodCache.isCurrentlyInsecure() ? R.drawable.ic_lock_open_24dp |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 450 | : R.drawable.ic_lock_24dp; |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 451 | |
Adrian Roos | 72cc370 | 2014-09-18 17:25:09 +0200 | [diff] [blame] | 452 | if (mLastUnlockIconRes != iconRes) { |
| 453 | Drawable icon = mContext.getDrawable(iconRes); |
| 454 | int iconHeight = getResources().getDimensionPixelSize( |
| 455 | R.dimen.keyguard_affordance_icon_height); |
| 456 | int iconWidth = getResources().getDimensionPixelSize( |
| 457 | R.dimen.keyguard_affordance_icon_width); |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 458 | if (!anyFingerprintIcon && (icon.getIntrinsicHeight() != iconHeight |
| 459 | || icon.getIntrinsicWidth() != iconWidth)) { |
Adrian Roos | 72cc370 | 2014-09-18 17:25:09 +0200 | [diff] [blame] | 460 | icon = new IntrinsicSizeDrawable(icon, iconWidth, iconHeight); |
| 461 | } |
| 462 | mLockIcon.setImageDrawable(icon); |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 463 | mLockIcon.setPaddingRelative(0, 0, 0, anyFingerprintIcon |
| 464 | ? getResources().getDimensionPixelSize( |
| 465 | R.dimen.fingerprint_icon_additional_padding) |
| 466 | : 0); |
| 467 | mLockIcon.setRestingAlpha( |
| 468 | anyFingerprintIcon ? 1f : KeyguardAffordanceHelper.SWIPE_RESTING_ALPHA_AMOUNT); |
Adrian Roos | 72cc370 | 2014-09-18 17:25:09 +0200 | [diff] [blame] | 469 | } |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 470 | |
| 471 | // Hide trust circle when fingerprint is running. |
| 472 | boolean trustManaged = mUnlockMethodCache.isTrustManaged() && !anyFingerprintIcon; |
Adrian Roos | 2e3ccbb | 2014-08-19 22:23:37 +0200 | [diff] [blame] | 473 | mTrustDrawable.setTrustManaged(trustManaged); |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 474 | updateLockIconClickability(); |
Adrian Roos | 2fe592d | 2014-05-17 03:11:59 +0200 | [diff] [blame] | 475 | } |
| 476 | |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 477 | public KeyguardAffordanceView getPhoneView() { |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 478 | return mPhoneImageView; |
| 479 | } |
| 480 | |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 481 | public KeyguardAffordanceView getCameraView() { |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 482 | return mCameraImageView; |
| 483 | } |
| 484 | |
Jorim Jaggi | b6cdcbc | 2014-07-25 21:58:29 +0200 | [diff] [blame] | 485 | public View getPhonePreview() { |
| 486 | return mPhonePreview; |
| 487 | } |
| 488 | |
| 489 | public View getCameraPreview() { |
| 490 | return mCameraPreview; |
| 491 | } |
| 492 | |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 493 | public KeyguardAffordanceView getLockIcon() { |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 494 | return mLockIcon; |
| 495 | } |
| 496 | |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 497 | public View getIndicationView() { |
| 498 | return mIndicationText; |
| 499 | } |
| 500 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 501 | @Override |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 502 | public boolean hasOverlappingRendering() { |
| 503 | return false; |
| 504 | } |
| 505 | |
| 506 | @Override |
Christoph Studer | 2231c6e | 2014-12-19 12:40:13 +0100 | [diff] [blame] | 507 | public void onUnlockMethodStateChanged() { |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 508 | updateLockIcon(); |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 509 | updateCameraVisibility(); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 510 | } |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 511 | |
Jorim Jaggi | b6cdcbc | 2014-07-25 21:58:29 +0200 | [diff] [blame] | 512 | private void inflatePreviews() { |
Jorim Jaggi | 781c29c | 2014-08-05 20:39:15 +0200 | [diff] [blame] | 513 | mPhonePreview = mPreviewInflater.inflatePreview(PHONE_INTENT); |
| 514 | mCameraPreview = mPreviewInflater.inflatePreview(getCameraIntent()); |
Jorim Jaggi | b6cdcbc | 2014-07-25 21:58:29 +0200 | [diff] [blame] | 515 | if (mPhonePreview != null) { |
| 516 | mPreviewContainer.addView(mPhonePreview); |
| 517 | mPhonePreview.setVisibility(View.INVISIBLE); |
| 518 | } |
| 519 | if (mCameraPreview != null) { |
| 520 | mPreviewContainer.addView(mCameraPreview); |
| 521 | mCameraPreview.setVisibility(View.INVISIBLE); |
| 522 | } |
| 523 | } |
| 524 | |
Jorim Jaggi | 16423aa | 2014-10-28 11:42:58 +0100 | [diff] [blame] | 525 | public void startFinishDozeAnimation() { |
| 526 | long delay = 0; |
| 527 | if (mPhoneImageView.getVisibility() == View.VISIBLE) { |
| 528 | startFinishDozeAnimationElement(mPhoneImageView, delay); |
| 529 | delay += DOZE_ANIMATION_STAGGER_DELAY; |
| 530 | } |
| 531 | startFinishDozeAnimationElement(mLockIcon, delay); |
| 532 | delay += DOZE_ANIMATION_STAGGER_DELAY; |
| 533 | if (mCameraImageView.getVisibility() == View.VISIBLE) { |
| 534 | startFinishDozeAnimationElement(mCameraImageView, delay); |
| 535 | } |
| 536 | mIndicationText.setAlpha(0f); |
| 537 | mIndicationText.animate() |
| 538 | .alpha(1f) |
| 539 | .setInterpolator(mLinearOutSlowInInterpolator) |
| 540 | .setDuration(NotificationPanelView.DOZE_ANIMATION_DURATION); |
| 541 | } |
| 542 | |
| 543 | private void startFinishDozeAnimationElement(View element, long delay) { |
| 544 | element.setAlpha(0f); |
| 545 | element.setTranslationY(element.getHeight() / 2); |
| 546 | element.animate() |
| 547 | .alpha(1f) |
| 548 | .translationY(0f) |
| 549 | .setInterpolator(mLinearOutSlowInInterpolator) |
| 550 | .setStartDelay(delay) |
| 551 | .setDuration(DOZE_ANIMATION_ELEMENT_DURATION); |
| 552 | } |
| 553 | |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 554 | private void vibrateFingerprintError() { |
| 555 | mContext.getSystemService(Vibrator.class).vibrate(FP_ERROR_VIBRATE_PATTERN, -1); |
| 556 | } |
| 557 | |
| 558 | private void vibrateFingerprintSuccess() { |
| 559 | mContext.getSystemService(Vibrator.class).vibrate(FP_SUCCESS_VIBRATE_PATTERN, -1); |
| 560 | } |
| 561 | |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 562 | private final BroadcastReceiver mDevicePolicyReceiver = new BroadcastReceiver() { |
| 563 | public void onReceive(Context context, Intent intent) { |
| 564 | post(new Runnable() { |
| 565 | @Override |
| 566 | public void run() { |
| 567 | updateCameraVisibility(); |
| 568 | } |
| 569 | }); |
| 570 | } |
| 571 | }; |
| 572 | |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 573 | private final Runnable mTransientFpErrorClearRunnable = new Runnable() { |
| 574 | @Override |
| 575 | public void run() { |
| 576 | mTransientFpError = false; |
| 577 | mIndicationController.hideTransientIndication(); |
| 578 | updateLockIcon(); |
| 579 | } |
| 580 | }; |
| 581 | |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 582 | private final KeyguardUpdateMonitorCallback mUpdateMonitorCallback = |
| 583 | new KeyguardUpdateMonitorCallback() { |
| 584 | @Override |
| 585 | public void onUserSwitchComplete(int userId) { |
| 586 | updateCameraVisibility(); |
| 587 | } |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 588 | |
| 589 | @Override |
Adrian Roos | 2e3ccbb | 2014-08-19 22:23:37 +0200 | [diff] [blame] | 590 | public void onScreenTurnedOn() { |
| 591 | updateLockIcon(); |
| 592 | } |
| 593 | |
| 594 | @Override |
| 595 | public void onScreenTurnedOff(int why) { |
| 596 | updateLockIcon(); |
| 597 | } |
Adrian Roos | b9ae090 | 2014-10-27 14:20:30 +0100 | [diff] [blame] | 598 | |
| 599 | @Override |
| 600 | public void onKeyguardVisibilityChanged(boolean showing) { |
| 601 | updateLockIcon(); |
| 602 | } |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 603 | |
| 604 | @Override |
| 605 | public void onFingerprintAuthenticated(int userId) { |
| 606 | vibrateFingerprintSuccess(); |
| 607 | } |
| 608 | |
| 609 | @Override |
| 610 | public void onFingerprintRunningStateChanged(boolean running) { |
| 611 | updateLockIcon(); |
| 612 | } |
| 613 | |
| 614 | @Override |
| 615 | public void onFingerprintHelp(int msgId, String helpString) { |
| 616 | vibrateFingerprintError(); |
| 617 | mTransientFpError = true; |
| 618 | mIndicationController.showTransientIndication(helpString, |
| 619 | getResources().getColor(R.color.system_warning_color, null)); |
| 620 | removeCallbacks(mTransientFpErrorClearRunnable); |
| 621 | postDelayed(mTransientFpErrorClearRunnable, TRANSIENT_FP_ERROR_TIMEOUT); |
| 622 | updateLockIcon(); |
| 623 | } |
| 624 | |
| 625 | @Override |
| 626 | public void onFingerprintError(int msgId, String errString) { |
| 627 | // TODO: Go to bouncer if this is "too many attempts" (lockout) error. |
| 628 | Log.i(TAG, "FP Error: " + errString); |
Jim Miller | fe6439f | 2015-04-11 18:07:57 -0700 | [diff] [blame] | 629 | updateLockIcon(); |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 630 | } |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 631 | }; |
Adrian Roos | 4ebcdfd | 2014-08-12 23:33:49 +0200 | [diff] [blame] | 632 | |
| 633 | public void setKeyguardIndicationController( |
| 634 | KeyguardIndicationController keyguardIndicationController) { |
| 635 | mIndicationController = keyguardIndicationController; |
| 636 | } |
Adrian Roos | 72cc370 | 2014-09-18 17:25:09 +0200 | [diff] [blame] | 637 | |
Adrian Roos | 72cc370 | 2014-09-18 17:25:09 +0200 | [diff] [blame] | 638 | /** |
| 639 | * A wrapper around another Drawable that overrides the intrinsic size. |
| 640 | */ |
| 641 | private static class IntrinsicSizeDrawable extends InsetDrawable { |
| 642 | |
| 643 | private final int mIntrinsicWidth; |
| 644 | private final int mIntrinsicHeight; |
| 645 | |
| 646 | public IntrinsicSizeDrawable(Drawable drawable, int intrinsicWidth, int intrinsicHeight) { |
| 647 | super(drawable, 0); |
| 648 | mIntrinsicWidth = intrinsicWidth; |
| 649 | mIntrinsicHeight = intrinsicHeight; |
| 650 | } |
| 651 | |
| 652 | @Override |
| 653 | public int getIntrinsicWidth() { |
| 654 | return mIntrinsicWidth; |
| 655 | } |
| 656 | |
| 657 | @Override |
| 658 | public int getIntrinsicHeight() { |
| 659 | return mIntrinsicHeight; |
| 660 | } |
| 661 | } |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 662 | } |