@@ -117,9 +117,14 @@ public class LockPatternKeyguardView extends KeyguardViewBase implements Handler
117117 private final int MSG_SHOW_FACELOCK_AREA_VIEW = 0 ;
118118 private final int MSG_HIDE_FACELOCK_AREA_VIEW = 1 ;
119119
120- // Long enough to stay black while dialer comes up
121- // Short enough to not be black if the user goes back immediately
122- private final int FACELOCK_VIEW_AREA_EMERGENCY_HIDE_TIMEOUT = 1000 ;
120+ // Long enough to stay visible while dialer comes up
121+ // Short enough to not be visible if the user goes back immediately
122+ private final int FACELOCK_VIEW_AREA_EMERGENCY_DIALER_TIMEOUT = 1000 ;
123+
124+ // Long enough to stay visible while the service starts
125+ // Short enough to not have to wait long for backup if service fails to start or crashes
126+ // The service can take a couple of seconds to start on the first try after boot
127+ private final int FACELOCK_VIEW_AREA_SERVICE_TIMEOUT = 3000 ;
123128
124129 /**
125130 * The current {@link KeyguardScreen} will use this to communicate back to us.
@@ -328,9 +333,8 @@ public void takeEmergencyCallAction() {
328333 // FaceLock must be stopped if it is running when emergency call is pressed
329334 stopAndUnbindFromFaceLock ();
330335
331- // Delay hiding FaceLock area so unlock doesn't display while dialer is coming up
332- mHandler .sendEmptyMessageDelayed (MSG_HIDE_FACELOCK_AREA_VIEW ,
333- FACELOCK_VIEW_AREA_EMERGENCY_HIDE_TIMEOUT );
336+ // Continue showing FaceLock area until dialer comes up
337+ showFaceLockAreaWithTimeout (FACELOCK_VIEW_AREA_EMERGENCY_DIALER_TIMEOUT );
334338
335339 pokeWakelock (EMERGENCY_CALL_TIMEOUT );
336340 if (TelephonyManager .getDefault ().getCallState ()
@@ -529,11 +533,11 @@ private void activateFaceLockIfAble() {
529533 if (mUpdateMonitor .getPhoneState () == TelephonyManager .CALL_STATE_IDLE
530534 && transportInvisible ) {
531535 bindToFaceLock ();
532- //Eliminate the black background so that the lockpattern will be visible
533- //If FaceUnlock is cancelled
534- mHandler . sendEmptyMessageDelayed ( MSG_HIDE_FACELOCK_AREA_VIEW , 4000 );
536+ // Show FaceLock area, but only for a little bit so lockpattern will become visible if
537+ // FaceLock fails to start or crashes
538+ showFaceLockAreaWithTimeout ( FACELOCK_VIEW_AREA_SERVICE_TIMEOUT );
535539 } else {
536- mHandler . sendEmptyMessage ( MSG_HIDE_FACELOCK_AREA_VIEW );
540+ hideFaceLockArea ( );
537541 }
538542 }
539543
@@ -563,7 +567,7 @@ public void onWindowFocusChanged (boolean hasWindowFocus) {
563567 }
564568 if (!hasWindowFocus ) {
565569 stopAndUnbindFromFaceLock ();
566- mHandler . sendEmptyMessage ( MSG_HIDE_FACELOCK_AREA_VIEW );
570+ hideFaceLockArea ( );
567571 } else if (runFaceLock ) {
568572 //Don't activate facelock while the user is calling 911!
569573 if (mEmergencyCall ) mEmergencyCall = false ;
@@ -583,9 +587,9 @@ public void show() {
583587
584588 if (mLockPatternUtils .usingBiometricWeak () &&
585589 mLockPatternUtils .isBiometricWeakInstalled ()) {
586- mHandler . sendEmptyMessage ( MSG_SHOW_FACELOCK_AREA_VIEW );
590+ showFaceLockArea ( );
587591 } else {
588- mHandler . sendEmptyMessage ( MSG_HIDE_FACELOCK_AREA_VIEW );
592+ hideFaceLockArea ( );
589593 }
590594 }
591595
@@ -652,7 +656,7 @@ public void onPhoneStateChanged(int phoneState) {
652656 if (DEBUG ) Log .d (TAG , "phone state: " + phoneState );
653657 if (phoneState == TelephonyManager .CALL_STATE_RINGING ) {
654658 stopAndUnbindFromFaceLock ();
655- mHandler . sendEmptyMessage ( MSG_HIDE_FACELOCK_AREA_VIEW );
659+ hideFaceLockArea ( );
656660 }
657661 }
658662
@@ -1085,6 +1089,32 @@ public boolean handleMessage(Message msg) {
10851089 return true ;
10861090 }
10871091
1092+ // Removes show and hide messages from the message queue
1093+ private void removeFaceLockAreaDisplayMessages () {
1094+ mHandler .removeMessages (MSG_SHOW_FACELOCK_AREA_VIEW );
1095+ mHandler .removeMessages (MSG_HIDE_FACELOCK_AREA_VIEW );
1096+ }
1097+
1098+ // Shows the FaceLock area immediately
1099+ private void showFaceLockArea () {
1100+ // Remove messages to prevent a delayed hide message from undo-ing the show
1101+ removeFaceLockAreaDisplayMessages ();
1102+ mHandler .sendEmptyMessage (MSG_SHOW_FACELOCK_AREA_VIEW );
1103+ }
1104+
1105+ // Hides the FaceLock area immediately
1106+ private void hideFaceLockArea () {
1107+ // Remove messages to prevent a delayed show message from undo-ing the hide
1108+ removeFaceLockAreaDisplayMessages ();
1109+ mHandler .sendEmptyMessage (MSG_HIDE_FACELOCK_AREA_VIEW );
1110+ }
1111+
1112+ // Shows the FaceLock area for a period of time
1113+ private void showFaceLockAreaWithTimeout (long timeoutMillis ) {
1114+ showFaceLockArea ();
1115+ mHandler .sendEmptyMessageDelayed (MSG_HIDE_FACELOCK_AREA_VIEW , timeoutMillis );
1116+ }
1117+
10881118 // Binds to FaceLock service, but does not tell it to start
10891119 public void bindToFaceLock () {
10901120 if (mLockPatternUtils .usingBiometricWeak () &&
@@ -1130,7 +1160,10 @@ public void onServiceConnected(ComponentName className, IBinder iservice) {
11301160 try {
11311161 mFaceLockService .registerCallback (mFaceLockCallback );
11321162 } catch (RemoteException e ) {
1133- throw new RuntimeException ("Remote exception" );
1163+ Log .e (TAG , "Caught exception connecting to FaceLock: " + e .toString ());
1164+ mFaceLockService = null ;
1165+ mBoundToFaceLockService = false ;
1166+ return ;
11341167 }
11351168
11361169 if (mFaceLockAreaView != null ) {
@@ -1147,6 +1180,7 @@ public void onServiceDisconnected(ComponentName className) {
11471180 mFaceLockService = null ;
11481181 mFaceLockServiceRunning = false ;
11491182 }
1183+ mBoundToFaceLockService = false ;
11501184 Log .w (TAG , "Unexpected disconnect from FaceLock service" );
11511185 }
11521186 };
@@ -1162,7 +1196,8 @@ public void startFaceLock(IBinder windowToken, int x, int y, int h, int w)
11621196 try {
11631197 mFaceLockService .startUi (windowToken , x , y , h , w );
11641198 } catch (RemoteException e ) {
1165- throw new RuntimeException ("Remote exception" );
1199+ Log .e (TAG , "Caught exception starting FaceLock: " + e .toString ());
1200+ return ;
11661201 }
11671202 mFaceLockServiceRunning = true ;
11681203 } else {
@@ -1186,7 +1221,7 @@ public void stopFaceLock()
11861221 if (DEBUG ) Log .d (TAG , "Stopping FaceLock" );
11871222 mFaceLockService .stopUi ();
11881223 } catch (RemoteException e ) {
1189- throw new RuntimeException ( "Remote exception" );
1224+ Log . e ( TAG , "Caught exception stopping FaceLock: " + e . toString () );
11901225 }
11911226 mFaceLockServiceRunning = false ;
11921227 }
@@ -1201,7 +1236,7 @@ public void stopFaceLock()
12011236 @ Override
12021237 public void unlock () {
12031238 if (DEBUG ) Log .d (TAG , "FaceLock unlock()" );
1204- mHandler . sendEmptyMessage ( MSG_SHOW_FACELOCK_AREA_VIEW ); // Keep fallback covered
1239+ showFaceLockArea ( ); // Keep fallback covered
12051240 stopFaceLock ();
12061241
12071242 mKeyguardScreenCallback .keyguardDone (true );
@@ -1213,7 +1248,7 @@ public void unlock() {
12131248 @ Override
12141249 public void cancel () {
12151250 if (DEBUG ) Log .d (TAG , "FaceLock cancel()" );
1216- mHandler . sendEmptyMessage ( MSG_HIDE_FACELOCK_AREA_VIEW ); // Expose fallback
1251+ hideFaceLockArea ( ); // Expose fallback
12171252 stopFaceLock ();
12181253 }
12191254
0 commit comments