Beispiel #1
0
  /** Stops Face Unlock and unbinds from the service. Called on the UI thread. */
  public boolean stop() {
    if (DEBUG) Log.d(TAG, "stop()");
    if (mHandler.getLooper() != Looper.myLooper()) {
      Log.e(TAG, "stop() called off of the UI thread");
    }

    boolean mWasRunning = mIsRunning;
    stopUi();

    if (mBoundToService) {
      if (mService != null) {
        try {
          mService.unregisterCallback(mFaceUnlockCallback);
        } catch (RemoteException e) {
          // Not much we can do
        }
      }
      Log.d(TAG, "Unbinding from Face Unlock service");
      mContext.unbindService(mConnection);
      mBoundToService = false;
    } else {
      // This is usually not an error when this happens.  Sometimes we will tell it to
      // unbind multiple times because it's called from both onWindowFocusChanged and
      // onDetachedFromWindow.
      if (DEBUG) Log.d(TAG, "Attempt to unbind from Face Unlock when not bound");
    }
    mIsRunning = false;
    return mWasRunning;
  }
Beispiel #2
0
 /** Frees up resources used by Face Unlock and stops it if it is still running. */
 public void cleanUp() {
   if (DEBUG) Log.d(TAG, "cleanUp()");
   if (mService != null) {
     try {
       mService.unregisterCallback(mFaceUnlockCallback);
     } catch (RemoteException e) {
       // Not much we can do
     }
     stopUi();
     mService = null;
   }
 }
Beispiel #3
0
  /**
   * Tells the service to start its UI via an AIDL interface. Called when the onServiceConnected()
   * callback is received.
   */
  void handleServiceConnected() {
    Log.d(TAG, "handleServiceConnected()");

    // It is possible that an unbind has occurred in the time between the bind and when this
    // function is reached.  If an unbind has already occurred, proceeding on to call startUi()
    // can result in a fatal error.  Note that the onServiceConnected() callback is
    // asynchronous, so this possibility would still exist if we executed this directly in
    // onServiceConnected() rather than using a handler.
    if (!mBoundToService) {
      Log.d(TAG, "Dropping startUi() in handleServiceConnected() because no longer bound");
      return;
    }

    try {
      mService.registerCallback(mFaceUnlockCallback);
    } catch (RemoteException e) {
      Log.e(TAG, "Caught exception connecting to Face Unlock: " + e.toString());
      mService = null;
      mBoundToService = false;
      mIsRunning = false;
      return;
    }

    if (mFaceUnlockView != null) {
      IBinder windowToken = mFaceUnlockView.getWindowToken();
      if (windowToken != null) {
        // When switching between portrait and landscape view while Face Unlock is running,
        // the screen will eventually go dark unless we poke the wakelock when Face Unlock
        // is restarted.
        mKeyguardScreenCallback.pokeWakelock();

        int[] position;
        position = new int[2];
        mFaceUnlockView.getLocationInWindow(position);
        startUi(
            windowToken,
            position[0],
            position[1],
            mFaceUnlockView.getWidth(),
            mFaceUnlockView.getHeight());
      } else {
        Log.e(TAG, "windowToken is null in handleServiceConnected()");
      }
    }
  }
Beispiel #4
0
 /** Tells the Face Unlock service to start displaying its UI and start processing. */
 private void startUi(IBinder windowToken, int x, int y, int w, int h) {
   if (DEBUG) Log.d(TAG, "startUi()");
   synchronized (mServiceRunningLock) {
     if (!mServiceRunning) {
       Log.d(TAG, "Starting Face Unlock");
       try {
         mService.startUi(
             windowToken, x, y, w, h, mLockPatternUtils.isBiometricWeakLivelinessEnabled());
       } catch (RemoteException e) {
         Log.e(TAG, "Caught exception starting Face Unlock: " + e.toString());
         return;
       }
       mServiceRunning = true;
     } else {
       Log.w(TAG, "startUi() attempted while running");
     }
   }
 }
Beispiel #5
0
 /** Tells the Face Unlock service to stop displaying its UI and stop processing. */
 private void stopUi() {
   if (DEBUG) Log.d(TAG, "stopUi()");
   // Note that attempting to stop Face Unlock when it's not running is not an issue.
   // Face Unlock can return, which stops it and then we try to stop it when the
   // screen is turned off.  That's why we check.
   synchronized (mServiceRunningLock) {
     if (mServiceRunning) {
       Log.d(TAG, "Stopping Face Unlock");
       try {
         mService.stopUi();
       } catch (RemoteException e) {
         Log.e(TAG, "Caught exception stopping Face Unlock: " + e.toString());
       }
       mServiceRunning = false;
     } else {
       // This is usually not an error when this happens.  Sometimes we will tell it to
       // stop multiple times because it's called from both onWindowFocusChanged and
       // onDetachedFromWindow.
       if (DEBUG) Log.d(TAG, "stopUi() attempted while not running");
     }
   }
 }