@@ -300,7 +300,18 @@ void handleHideFaceUnlockView() {
300300 * onServiceConnected() callback is received.
301301 */
302302 void handleServiceConnected () {
303- if (DEBUG ) Log .d (TAG , "handleServiceConnected()" );
303+ Log .d (TAG , "handleServiceConnected()" );
304+
305+ // It is possible that an unbind has occurred in the time between the bind and when this
306+ // function is reached. If an unbind has already occurred, proceeding on to call startUi()
307+ // can result in a fatal error. Note that the onServiceConnected() callback is
308+ // asynchronous, so this possibility would still exist if we executed this directly in
309+ // onServiceConnected() rather than using a handler.
310+ if (!mBoundToService ) {
311+ Log .d (TAG , "Dropping startUi() in handleServiceConnected() because no longer bound" );
312+ return ;
313+ }
314+
304315 try {
305316 mService .registerCallback (mFaceUnlockCallback );
306317 } catch (RemoteException e ) {
@@ -452,25 +463,12 @@ public void onServiceDisconnected(ComponentName className) {
452463 * Tells the Face Unlock service to start displaying its UI and start processing.
453464 */
454465 private void startUi (IBinder windowToken , int x , int y , int w , int h ) {
455- Log .d (TAG , "startUi()" );
466+ if ( DEBUG ) Log .d (TAG , "startUi()" );
456467 synchronized (mServiceRunningLock ) {
457468 if (!mServiceRunning ) {
458- if ( DEBUG ) Log .d (TAG , "Starting Face Unlock" );
469+ Log .d (TAG , "Starting Face Unlock" );
459470 try {
460- // TODO: these checks and logs are for tracking down bug 6409767 and can be
461- // removed when that bug is fixed.
462- if (mService == null ) {
463- Log .d (TAG , "mService is null" );
464- }
465- if (windowToken == null ) {
466- Log .d (TAG , "windowToken is null" );
467- }
468- if (mLockPatternUtils == null ) {
469- Log .d (TAG , "mLockPatternUtils is null" );
470- }
471- Log .d (TAG , "x,y,w,h,live: " + x + "," + y + "," + w + "," + h + ", no" );
472471 mService .startUi (windowToken , x , y , w , h , false );
473- Log .d (TAG , "mService.startUi() called" );
474472 } catch (RemoteException e ) {
475473 Log .e (TAG , "Caught exception starting Face Unlock: " + e .toString ());
476474 return ;
@@ -492,7 +490,7 @@ private void stopUi() {
492490 // screen is turned off. That's why we check.
493491 synchronized (mServiceRunningLock ) {
494492 if (mServiceRunning ) {
495- if ( DEBUG ) Log .d (TAG , "Stopping Face Unlock" );
493+ Log .d (TAG , "Stopping Face Unlock" );
496494 try {
497495 mService .stopUi ();
498496 } catch (RemoteException e ) {
0 commit comments