KeyguardFaceUnlockView.java revision dcb3d84b82cc2448d04e73359a716581bfb657db
1/* 2 * Copyright (C) 2012 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 */ 16package com.android.internal.policy.impl.keyguard; 17 18import android.content.Context; 19import android.util.AttributeSet; 20import android.widget.LinearLayout; 21 22import com.android.internal.widget.LockPatternUtils; 23 24public class KeyguardFaceUnlockView extends LinearLayout implements KeyguardSecurityView { 25 26 // Long enough to stay visible while dialer comes up 27 // Short enough to not be visible if the user goes back immediately 28 private static final int BIOMETRIC_AREA_EMERGENCY_DIALER_TIMEOUT = 1000; 29 private KeyguardSecurityCallback mKeyguardSecurityCallback; 30 private LockPatternUtils mLockPatternUtils; 31 32 public KeyguardFaceUnlockView(Context context) { 33 this(context, null); 34 } 35 36 public KeyguardFaceUnlockView(Context context, AttributeSet attrs) { 37 super(context, attrs); 38 } 39 40 @Override 41 public void setKeyguardCallback(KeyguardSecurityCallback callback) { 42 mKeyguardSecurityCallback = callback; 43 } 44 45 @Override 46 public void setLockPatternUtils(LockPatternUtils utils) { 47 mLockPatternUtils = utils; 48 } 49 50 @Override 51 public void reset() { 52 53 } 54 55 @Override 56 public void onPause() { 57 58 } 59 60 @Override 61 public void onResume() { 62 63 } 64 65 @Override 66 public boolean needsInput() { 67 return false; 68 } 69 70 @Override 71 public KeyguardSecurityCallback getCallback() { 72 return mKeyguardSecurityCallback; 73 } 74 75 // TODO 76 // public void onRefreshBatteryInfo(BatteryStatus status) { 77 // // When someone plugs in or unplugs the device, we hide the biometric sensor area and 78 // // suppress its startup for the next onScreenTurnedOn(). Since plugging/unplugging 79 // // causes the screen to turn on, the biometric unlock would start if it wasn't 80 // // suppressed. 81 // // 82 // // However, if the biometric unlock is already running, we do not want to interrupt it. 83 // final boolean pluggedIn = status.isPluggedIn(); 84 // if (mBiometricUnlock != null && mPluggedIn != pluggedIn 85 // && !mBiometricUnlock.isRunning()) { 86 // mBiometricUnlock.stop(); 87 // mBiometricUnlock.hide(); 88 // mSuppressBiometricUnlock = true; 89 // } 90 // mPluggedIn = pluggedIn; 91 // } 92 93 // We need to stop the biometric unlock when a phone call comes in 94 // @Override 95 // public void onPhoneStateChanged(int phoneState) { 96 // if (DEBUG) Log.d(TAG, "phone state: " + phoneState); 97 // if (phoneState == TelephonyManager.CALL_STATE_RINGING) { 98 // mSuppressBiometricUnlock = true; 99 // mBiometricUnlock.stop(); 100 // mBiometricUnlock.hide(); 101 // } 102 // } 103 104 // @Override 105 // public void onUserSwitched(int userId) { 106 // if (mBiometricUnlock != null) { 107 // mBiometricUnlock.stop(); 108 // } 109 // mLockPatternUtils.setCurrentUser(userId); 110 // updateScreen(getInitialMode(), true); 111 // } 112 113 // /** 114 // * This returns false if there is any condition that indicates that the biometric unlock should 115 // * not be used before the next time the unlock screen is recreated. In other words, if this 116 // * returns false there is no need to even construct the biometric unlock. 117 // */ 118 // private boolean useBiometricUnlock() { 119 // final ShowingMode unlockMode = getUnlockMode(); 120 // final boolean backupIsTimedOut = (mUpdateMonitor.getFailedAttempts() >= 121 // LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT); 122 // return (mLockPatternUtils.usingBiometricWeak() && 123 // mLockPatternUtils.isBiometricWeakInstalled() && 124 // !mUpdateMonitor.getMaxBiometricUnlockAttemptsReached() && 125 // !backupIsTimedOut && 126 // (unlockMode == ShowingMode.Pattern || unlockMode == ShowingMode.Password)); 127 // } 128 129 // private void initializeBiometricUnlockView(View view) { 130 // boolean restartBiometricUnlock = false; 131 // 132 // if (mBiometricUnlock != null) { 133 // restartBiometricUnlock = mBiometricUnlock.stop(); 134 // } 135 // 136 // // Prevents biometric unlock from coming up immediately after a phone call or if there 137 // // is a dialog on top of lockscreen. It is only updated if the screen is off because if the 138 // // screen is on it's either because of an orientation change, or when it first boots. 139 // // In both those cases, we don't want to override the current value of 140 // // mSuppressBiometricUnlock and instead want to use the previous value. 141 // if (!mScreenOn) { 142 // mSuppressBiometricUnlock = 143 // mUpdateMonitor.getPhoneState() != TelephonyManager.CALL_STATE_IDLE 144 // || mHasDialog; 145 // } 146 // 147 // // If the biometric unlock is not being used, we don't bother constructing it. Then we can 148 // // simply check if it is null when deciding whether we should make calls to it. 149 // mBiometricUnlock = null; 150 // if (useBiometricUnlock()) { 151 // // TODO: make faceLockAreaView a more general biometricUnlockView 152 // // We will need to add our Face Unlock specific child views programmatically in 153 // // initializeView rather than having them in the XML files. 154 // View biometricUnlockView = view.findViewById( 155 // com.android.internal.R.id.faceLockAreaView); 156 // if (biometricUnlockView != null) { 157 // mBiometricUnlock = new FaceUnlock(mContext, mUpdateMonitor, mLockPatternUtils, 158 // mKeyguardScreenCallback); 159 // mBiometricUnlock.initializeView(biometricUnlockView); 160 // 161 // // If this is being called because the screen turned off, we want to cover the 162 // // backup lock so it is covered when the screen turns back on. 163 // if (!mScreenOn) mBiometricUnlock.show(0); 164 // } else { 165 // Log.w(TAG, "Couldn't find biometric unlock view"); 166 // } 167 // } 168 // 169 // if (mBiometricUnlock != null && restartBiometricUnlock) { 170 // maybeStartBiometricUnlock(); 171 // } 172 // } 173 174 // /** 175 // * Starts the biometric unlock if it should be started based on a number of factors including 176 // * the mSuppressBiometricUnlock flag. If it should not be started, it hides the biometric 177 // * unlock area. 178 // */ 179 // private void maybeStartBiometricUnlock() { 180 // if (mBiometricUnlock != null) { 181 // final boolean backupIsTimedOut = (mUpdateMonitor.getFailedAttempts() >= 182 // LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT); 183 // if (!mSuppressBiometricUnlock 184 // && mUpdateMonitor.getPhoneState() == TelephonyManager.CALL_STATE_IDLE 185 // && !mUpdateMonitor.getMaxBiometricUnlockAttemptsReached() 186 // && !backupIsTimedOut) { 187 // mBiometricUnlock.start(); 188 // } else { 189 // mBiometricUnlock.hide(); 190 // } 191 // } 192 //} 193 194} 195