1dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller/* 2dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller * Copyright (C) 2012 The Android Open Source Project 3dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller * 4dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller * Licensed under the Apache License, Version 2.0 (the "License"); 5dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller * you may not use this file except in compliance with the License. 6dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller * You may obtain a copy of the License at 7dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller * 8dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller * http://www.apache.org/licenses/LICENSE-2.0 9dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller * 10dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller * Unless required by applicable law or agreed to in writing, software 11dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller * distributed under the License is distributed on an "AS IS" BASIS, 12dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller * See the License for the specific language governing permissions and 14dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller * limitations under the License. 15dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller */ 165ecd81154fa039961f65bb4e36d18ac555b0d1d6Jim Millerpackage com.android.keyguard; 17dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller 18dcb3d84b82cc2448d04e73359a716581bfb657dbJim Millerimport android.content.Context; 19c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wrenimport android.graphics.drawable.Drawable; 2094c7b14b1a4f53157997939505b70ef056ca90d8Uriel Rodriguezimport android.os.PowerManager; 21b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonnaimport android.os.RemoteException; 22b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonnaimport android.os.ServiceManager; 23000464ac012471d301c6e48a8228291519915e17Jim Millerimport android.telephony.TelephonyManager; 24dcb3d84b82cc2448d04e73359a716581bfb657dbJim Millerimport android.util.AttributeSet; 25000464ac012471d301c6e48a8228291519915e17Jim Millerimport android.util.Log; 26b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonnaimport android.view.IRotationWatcher; 27b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonnaimport android.view.IWindowManager; 28000464ac012471d301c6e48a8228291519915e17Jim Millerimport android.view.View; 2961413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millettimport android.widget.ImageButton; 30dcb3d84b82cc2448d04e73359a716581bfb657dbJim Millerimport android.widget.LinearLayout; 31dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller 32dcb3d84b82cc2448d04e73359a716581bfb657dbJim Millerimport com.android.internal.widget.LockPatternUtils; 33dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller 34b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonnaimport java.lang.Math; 35b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna 36dcb3d84b82cc2448d04e73359a716581bfb657dbJim Millerpublic class KeyguardFaceUnlockView extends LinearLayout implements KeyguardSecurityView { 37dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller 3894c7b14b1a4f53157997939505b70ef056ca90d8Uriel Rodriguez private static final String TAG = "FULKeyguardFaceUnlockView"; 3961413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett private static final boolean DEBUG = false; 40dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller private KeyguardSecurityCallback mKeyguardSecurityCallback; 41dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller private LockPatternUtils mLockPatternUtils; 42000464ac012471d301c6e48a8228291519915e17Jim Miller private BiometricSensorUnlock mBiometricUnlock; 43000464ac012471d301c6e48a8228291519915e17Jim Miller private View mFaceUnlockAreaView; 4461413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett private ImageButton mCancelButton; 45c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren private SecurityMessageDisplay mSecurityMessageDisplay; 46c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren private View mEcaView; 47c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren private Drawable mBouncerFrame; 48dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller 49f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett private boolean mIsShowing = false; 50f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett private final Object mIsShowingLock = new Object(); 51f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett 52b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna private int mLastRotation; 53b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna private boolean mWatchingRotation; 54b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna private final IWindowManager mWindowManager = 55b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna IWindowManager.Stub.asInterface(ServiceManager.getService("window")); 56b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna 57b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna private final IRotationWatcher mRotationWatcher = new IRotationWatcher.Stub() { 58b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna public void onRotationChanged(int rotation) { 59b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna if (DEBUG) Log.d(TAG, "onRotationChanged(): " + mLastRotation + "->" + rotation); 60b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna 61b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna // If the difference between the new rotation value and the previous rotation value is 62b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna // equal to 2, the rotation change was 180 degrees. This stops the biometric unlock 63b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna // and starts it in the new position. This is not performed for 90 degree rotations 64b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna // since a 90 degree rotation is a configuration change, which takes care of this for 65b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna // us. 66b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna if (Math.abs(rotation - mLastRotation) == 2) { 67b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna if (mBiometricUnlock != null) { 68b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna mBiometricUnlock.stop(); 69b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna maybeStartBiometricUnlock(); 70b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna } 71b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna } 72b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna mLastRotation = rotation; 73b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna } 74b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna }; 75b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna 76dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller public KeyguardFaceUnlockView(Context context) { 77dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller this(context, null); 78dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller } 79dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller 80dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller public KeyguardFaceUnlockView(Context context, AttributeSet attrs) { 81dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller super(context, attrs); 82dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller } 83dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller 84dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller @Override 85000464ac012471d301c6e48a8228291519915e17Jim Miller protected void onFinishInflate() { 86000464ac012471d301c6e48a8228291519915e17Jim Miller super.onFinishInflate(); 87000464ac012471d301c6e48a8228291519915e17Jim Miller 88000464ac012471d301c6e48a8228291519915e17Jim Miller initializeBiometricUnlockView(); 89c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren 90c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren mSecurityMessageDisplay = new KeyguardMessageArea.Helper(this); 91c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren mEcaView = findViewById(R.id.keyguard_selector_fade_container); 92c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren View bouncerFrameView = findViewById(R.id.keyguard_bouncer_frame); 93c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren if (bouncerFrameView != null) { 94c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren mBouncerFrame = bouncerFrameView.getBackground(); 95c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren } 96000464ac012471d301c6e48a8228291519915e17Jim Miller } 97000464ac012471d301c6e48a8228291519915e17Jim Miller 98000464ac012471d301c6e48a8228291519915e17Jim Miller @Override 99dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller public void setKeyguardCallback(KeyguardSecurityCallback callback) { 100dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller mKeyguardSecurityCallback = callback; 101000464ac012471d301c6e48a8228291519915e17Jim Miller // TODO: formalize this in the interface or factor it out 102000464ac012471d301c6e48a8228291519915e17Jim Miller ((FaceUnlock)mBiometricUnlock).setKeyguardCallback(callback); 103dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller } 104dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller 105dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller @Override 106dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller public void setLockPatternUtils(LockPatternUtils utils) { 107dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller mLockPatternUtils = utils; 108dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller } 109dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller 110dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller @Override 111dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller public void reset() { 112dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller 113dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller } 114dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller 115dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller @Override 116fbb9c6197f4c9dd2583590559502e3b0600867d8Steven Ross public void onDetachedFromWindow() { 11761413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett if (DEBUG) Log.d(TAG, "onDetachedFromWindow()"); 118fbb9c6197f4c9dd2583590559502e3b0600867d8Steven Ross if (mBiometricUnlock != null) { 1199a9f4ce1e2522f020b72a08161c1c3d244dd5c68Steven Ross mBiometricUnlock.stop(); 120fbb9c6197f4c9dd2583590559502e3b0600867d8Steven Ross } 121cade0049a729ac63832f45befa91cec3b7ce88f5Danielle Millett KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateCallback); 122b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna if (mWatchingRotation) { 123b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna try { 124b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna mWindowManager.removeRotationWatcher(mRotationWatcher); 125b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna mWatchingRotation = false; 126b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna } catch (RemoteException e) { 127b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna Log.e(TAG, "Remote exception when removing rotation watcher"); 128b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna } 129b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna } 130fbb9c6197f4c9dd2583590559502e3b0600867d8Steven Ross } 131fbb9c6197f4c9dd2583590559502e3b0600867d8Steven Ross 132fbb9c6197f4c9dd2583590559502e3b0600867d8Steven Ross @Override 133dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller public void onPause() { 13461413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett if (DEBUG) Log.d(TAG, "onPause()"); 135000464ac012471d301c6e48a8228291519915e17Jim Miller if (mBiometricUnlock != null) { 1361108a2cb412b054cc9e4acc48182c46c45180c0cDanielle Millett mBiometricUnlock.stop(); 137000464ac012471d301c6e48a8228291519915e17Jim Miller } 138000464ac012471d301c6e48a8228291519915e17Jim Miller KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateCallback); 139b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna if (mWatchingRotation) { 140b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna try { 141b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna mWindowManager.removeRotationWatcher(mRotationWatcher); 142b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna mWatchingRotation = false; 143b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna } catch (RemoteException e) { 144b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna Log.e(TAG, "Remote exception when removing rotation watcher"); 145b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna } 146b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna } 147dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller } 148dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller 149dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller @Override 150a042ac90640c0c3fd3c5349083b86bbfd6319b64Chris Wren public void onResume(int reason) { 15161413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett if (DEBUG) Log.d(TAG, "onResume()"); 1525d2404da57926736317c1a08d989cd55784ef8a1Danielle Millett mIsShowing = KeyguardUpdateMonitor.getInstance(mContext).isKeyguardVisible(); 153a5239891dc324db21beb87535f90ea76fba803b9Brian Colonna if (!KeyguardUpdateMonitor.getInstance(mContext).isSwitchingUser()) { 154a5239891dc324db21beb87535f90ea76fba803b9Brian Colonna maybeStartBiometricUnlock(); 155a5239891dc324db21beb87535f90ea76fba803b9Brian Colonna } 156000464ac012471d301c6e48a8228291519915e17Jim Miller KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateCallback); 157b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna 158b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna // Registers a callback which handles stopping the biometric unlock and restarting it in 159b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna // the new position for a 180 degree rotation change. 160b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna if (!mWatchingRotation) { 161b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna try { 162b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna mLastRotation = mWindowManager.watchRotation(mRotationWatcher); 163b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna mWatchingRotation = true; 164b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna } catch (RemoteException e) { 165b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna Log.e(TAG, "Remote exception when adding rotation watcher"); 166b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna } 167b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna } 168dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller } 169dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller 170dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller @Override 171dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller public boolean needsInput() { 172dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller return false; 173dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller } 174dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller 175dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller @Override 176dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller public KeyguardSecurityCallback getCallback() { 177dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller return mKeyguardSecurityCallback; 178dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller } 179dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller 180000464ac012471d301c6e48a8228291519915e17Jim Miller @Override 181000464ac012471d301c6e48a8228291519915e17Jim Miller protected void onLayout(boolean changed, int l, int t, int r, int b) { 182000464ac012471d301c6e48a8228291519915e17Jim Miller super.onLayout(changed, l, t, r, b); 183000464ac012471d301c6e48a8228291519915e17Jim Miller mBiometricUnlock.initializeView(mFaceUnlockAreaView); 184000464ac012471d301c6e48a8228291519915e17Jim Miller } 185000464ac012471d301c6e48a8228291519915e17Jim Miller 186000464ac012471d301c6e48a8228291519915e17Jim Miller private void initializeBiometricUnlockView() { 187f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett if (DEBUG) Log.d(TAG, "initializeBiometricUnlockView()"); 188000464ac012471d301c6e48a8228291519915e17Jim Miller mFaceUnlockAreaView = findViewById(R.id.face_unlock_area_view); 189000464ac012471d301c6e48a8228291519915e17Jim Miller if (mFaceUnlockAreaView != null) { 190000464ac012471d301c6e48a8228291519915e17Jim Miller mBiometricUnlock = new FaceUnlock(mContext); 19161413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett 19261413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett mCancelButton = (ImageButton) findViewById(R.id.face_unlock_cancel_button); 19361413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett mCancelButton.setOnClickListener(new OnClickListener() { 19461413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett @Override 19561413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett public void onClick(View v) { 19661413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett mBiometricUnlock.stopAndShowBackup(); 19761413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett } 19861413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett }); 199000464ac012471d301c6e48a8228291519915e17Jim Miller } else { 200000464ac012471d301c6e48a8228291519915e17Jim Miller Log.w(TAG, "Couldn't find biometric unlock view"); 201000464ac012471d301c6e48a8228291519915e17Jim Miller } 202000464ac012471d301c6e48a8228291519915e17Jim Miller } 203000464ac012471d301c6e48a8228291519915e17Jim Miller 204000464ac012471d301c6e48a8228291519915e17Jim Miller /** 205f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett * Starts the biometric unlock if it should be started based on a number of factors. If it 206f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett * should not be started, it either goes to the back up, or remains showing to prepare for 207f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett * it being started later. 208000464ac012471d301c6e48a8228291519915e17Jim Miller */ 209000464ac012471d301c6e48a8228291519915e17Jim Miller private void maybeStartBiometricUnlock() { 21061413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett if (DEBUG) Log.d(TAG, "maybeStartBiometricUnlock()"); 211000464ac012471d301c6e48a8228291519915e17Jim Miller if (mBiometricUnlock != null) { 212000464ac012471d301c6e48a8228291519915e17Jim Miller KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext); 213000464ac012471d301c6e48a8228291519915e17Jim Miller final boolean backupIsTimedOut = ( 214000464ac012471d301c6e48a8228291519915e17Jim Miller monitor.getFailedUnlockAttempts() >= 215000464ac012471d301c6e48a8228291519915e17Jim Miller LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT); 21694c7b14b1a4f53157997939505b70ef056ca90d8Uriel Rodriguez PowerManager powerManager = (PowerManager) mContext.getSystemService( 21794c7b14b1a4f53157997939505b70ef056ca90d8Uriel Rodriguez Context.POWER_SERVICE); 218f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett 219f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett boolean isShowing; 220f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett synchronized(mIsShowingLock) { 221f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett isShowing = mIsShowing; 222f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett } 223f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett 224f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett // Don't start it if the screen is off or if it's not showing, but keep this view up 225f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett // because we want it here and ready for when the screen turns on or when it does start 226f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett // showing. 227f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett if (!powerManager.isScreenOn() || !isShowing) { 228f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett mBiometricUnlock.stop(); // It shouldn't be running but calling this can't hurt. 229f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett return; 230f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett } 231f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett 232b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna // Although these same conditions are handled in KeyguardSecurityModel, they are still 233b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna // necessary here. When a tablet is rotated 90 degrees, a configuration change is 234b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna // triggered and everything is torn down and reconstructed. That means 235b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna // KeyguardSecurityModel gets a chance to take care of the logic and doesn't even 236b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna // reconstruct KeyguardFaceUnlockView if the biometric unlock should be suppressed. 237b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna // However, for a 180 degree rotation, no configuration change is triggered, so only 238b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna // the logic here is capable of suppressing Face Unlock. 239d95c659a1d621dfbdd892759419ffc089e248672Danielle Millett if (monitor.getPhoneState() == TelephonyManager.CALL_STATE_IDLE 240b1b9a8ac07ea7d438eda613f4c798dd8b10a66ceBrian Colonna && monitor.isAlternateUnlockEnabled() 241000464ac012471d301c6e48a8228291519915e17Jim Miller && !monitor.getMaxBiometricUnlockAttemptsReached() 242f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett && !backupIsTimedOut) { 243000464ac012471d301c6e48a8228291519915e17Jim Miller mBiometricUnlock.start(); 244000464ac012471d301c6e48a8228291519915e17Jim Miller } else { 24561413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett mBiometricUnlock.stopAndShowBackup(); 246000464ac012471d301c6e48a8228291519915e17Jim Miller } 247000464ac012471d301c6e48a8228291519915e17Jim Miller } 248000464ac012471d301c6e48a8228291519915e17Jim Miller } 249000464ac012471d301c6e48a8228291519915e17Jim Miller 250000464ac012471d301c6e48a8228291519915e17Jim Miller KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() { 251000464ac012471d301c6e48a8228291519915e17Jim Miller // We need to stop the biometric unlock when a phone call comes in 252000464ac012471d301c6e48a8228291519915e17Jim Miller @Override 253000464ac012471d301c6e48a8228291519915e17Jim Miller public void onPhoneStateChanged(int phoneState) { 25461413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett if (DEBUG) Log.d(TAG, "onPhoneStateChanged(" + phoneState + ")"); 255000464ac012471d301c6e48a8228291519915e17Jim Miller if (phoneState == TelephonyManager.CALL_STATE_RINGING) { 256f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett if (mBiometricUnlock != null) { 257f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett mBiometricUnlock.stopAndShowBackup(); 258f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett } 259000464ac012471d301c6e48a8228291519915e17Jim Miller } 260000464ac012471d301c6e48a8228291519915e17Jim Miller } 261000464ac012471d301c6e48a8228291519915e17Jim Miller 262000464ac012471d301c6e48a8228291519915e17Jim Miller @Override 263f41c61bc1551c98c681fe3e6ae197fefed2bc856Chris Wren public void onUserSwitching(int userId) { 26461413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett if (DEBUG) Log.d(TAG, "onUserSwitched(" + userId + ")"); 265000464ac012471d301c6e48a8228291519915e17Jim Miller if (mBiometricUnlock != null) { 266000464ac012471d301c6e48a8228291519915e17Jim Miller mBiometricUnlock.stop(); 267000464ac012471d301c6e48a8228291519915e17Jim Miller } 268ee82f8fa2d47fc1dbfc29582ae348b3c45ff8fe0Jim Miller // No longer required; static value set by KeyguardViewMediator 269ee82f8fa2d47fc1dbfc29582ae348b3c45ff8fe0Jim Miller // mLockPatternUtils.setCurrentUser(userId); 270000464ac012471d301c6e48a8228291519915e17Jim Miller } 271f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett 272f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett @Override 273a5239891dc324db21beb87535f90ea76fba803b9Brian Colonna public void onUserSwitchComplete(int userId) { 274a5239891dc324db21beb87535f90ea76fba803b9Brian Colonna if (DEBUG) Log.d(TAG, "onUserSwitchComplete(" + userId + ")"); 275a5239891dc324db21beb87535f90ea76fba803b9Brian Colonna if (mBiometricUnlock != null) { 276a5239891dc324db21beb87535f90ea76fba803b9Brian Colonna maybeStartBiometricUnlock(); 277a5239891dc324db21beb87535f90ea76fba803b9Brian Colonna } 278a5239891dc324db21beb87535f90ea76fba803b9Brian Colonna } 279a5239891dc324db21beb87535f90ea76fba803b9Brian Colonna 280a5239891dc324db21beb87535f90ea76fba803b9Brian Colonna @Override 281f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett public void onKeyguardVisibilityChanged(boolean showing) { 282f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett if (DEBUG) Log.d(TAG, "onKeyguardVisibilityChanged(" + showing + ")"); 283f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett boolean wasShowing = false; 284f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett synchronized(mIsShowingLock) { 285f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett wasShowing = mIsShowing; 286f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett mIsShowing = showing; 287f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett } 288f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett PowerManager powerManager = (PowerManager) mContext.getSystemService( 289f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett Context.POWER_SERVICE); 290f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett if (mBiometricUnlock != null) { 291f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett if (!showing && wasShowing) { 292f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett mBiometricUnlock.stop(); 293f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett } else if (showing && powerManager.isScreenOn() && !wasShowing) { 294f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett maybeStartBiometricUnlock(); 295f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett } 296f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett } 297f6d0fc190c4b257ee4f2f1ae8a59519d3a21ce6dDanielle Millett } 2987fce38021694925295f5d14bfba71f28cba19404Brian Colonna 2997fce38021694925295f5d14bfba71f28cba19404Brian Colonna @Override 3007fce38021694925295f5d14bfba71f28cba19404Brian Colonna public void onEmergencyCallAction() { 3017fce38021694925295f5d14bfba71f28cba19404Brian Colonna if (mBiometricUnlock != null) { 3027fce38021694925295f5d14bfba71f28cba19404Brian Colonna mBiometricUnlock.stop(); 3037fce38021694925295f5d14bfba71f28cba19404Brian Colonna } 3047fce38021694925295f5d14bfba71f28cba19404Brian Colonna } 305000464ac012471d301c6e48a8228291519915e17Jim Miller }; 306dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller 3070ff7f010f8bfd011f0915031b02739ae3bee401eJim Miller @Override 3086fb841fa219eaae3e87f2fdc05e105d7a1813c42Adam Cohen public void showUsabilityHint() { 3096fb841fa219eaae3e87f2fdc05e105d7a1813c42Adam Cohen } 310c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren 311c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren @Override 312c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren public void showBouncer(int duration) { 313c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren KeyguardSecurityViewHelper. 314c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren showBouncer(mSecurityMessageDisplay, mEcaView, mBouncerFrame, duration); 315c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren } 316c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren 317c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren @Override 318c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren public void hideBouncer(int duration) { 319c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren KeyguardSecurityViewHelper. 320c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren hideBouncer(mSecurityMessageDisplay, mEcaView, mBouncerFrame, duration); 321c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren } 322c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren 323dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller} 324