Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 855bdf65 authored by Danielle Millett's avatar Danielle Millett Committed by Android Git Automerger
Browse files

am 85a4ac92: am 8f89e6f8: Merge "Face Unlock is shown correctly during a phone...

am 85a4ac92: am 8f89e6f8: Merge "Face Unlock is shown correctly during a phone call - fix b/7271718" into jb-mr1-dev

* commit '85a4ac92':
  Face Unlock is shown correctly during a phone call - fix b/7271718
parents bfd97573 85a4ac92
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -46,13 +46,14 @@
            android:background="@color/facelock_spotlight_mask"
            android:background="@color/facelock_spotlight_mask"
        />
        />


        <ImageView
        <ImageButton
            android:id="@+id/cancel_button"
            android:id="@+id/face_unlock_cancel_button"
            android:layout_width="wrap_content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_height="wrap_content"
            android:padding="5dip"
            android:padding="5dip"
            android:layout_alignParentTop="true"
            android:layout_alignParentTop="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentEnd="true"
            android:background="#00000000"
            android:src="@drawable/ic_facial_backup"
            android:src="@drawable/ic_facial_backup"
        />
        />


+1 −0
Original line number Original line Diff line number Diff line
@@ -1233,6 +1233,7 @@
  <java-symbol type="id" name="eight" />
  <java-symbol type="id" name="eight" />
  <java-symbol type="id" name="emergencyCallButton" />
  <java-symbol type="id" name="emergencyCallButton" />
  <java-symbol type="id" name="face_unlock_area_view" />
  <java-symbol type="id" name="face_unlock_area_view" />
  <java-symbol type="id" name="face_unlock_cancel_button" />
  <java-symbol type="id" name="five" />
  <java-symbol type="id" name="five" />
  <java-symbol type="id" name="forgotPatternButton" />
  <java-symbol type="id" name="forgotPatternButton" />
  <java-symbol type="id" name="four" />
  <java-symbol type="id" name="four" />
+2 −14
Original line number Original line Diff line number Diff line
@@ -37,21 +37,9 @@ interface BiometricSensorUnlock {
    public boolean isRunning();
    public boolean isRunning();


    /**
    /**
     * Covers the backup unlock mechanism by showing the contents of the view initialized in
     * Stops and removes the biometric unlock and shows the backup unlock
     * {@link BiometricSensorUnlock#initializeView(View)}.  The view should disappear after the
     * specified timeout.  If the timeout is 0, the interface shows until another event, such as
     * calling {@link BiometricSensorUnlock#hide()}, causes it to disappear.  Called on the UI
     * thread.
     * @param timeoutMilliseconds Amount of time in milliseconds to display the view before
     * disappearing.  A value of 0 means the view should remain visible.
     */
    public void show(long timeoutMilliseconds);

    /**
     * Uncovers the backup unlock mechanism by hiding the contents of the view initialized in
     * {@link BiometricSensorUnlock#initializeView(View)}.
     */
     */
    public void hide();
    public void stopAndShowBackup();


    /**
    /**
     * Binds to the biometric unlock service and starts the unlock procedure.  Called on the UI
     * Binds to the biometric unlock service and starts the unlock procedure.  Called on the UI
+15 −78
Original line number Original line Diff line number Diff line
@@ -52,26 +52,19 @@ public class FaceUnlock implements BiometricSensorUnlock, Handler.Callback {
    private View mFaceUnlockView;
    private View mFaceUnlockView;


    private Handler mHandler;
    private Handler mHandler;
    private final int MSG_SHOW_FACE_UNLOCK_VIEW = 0;
    private final int MSG_SERVICE_CONNECTED = 0;
    private final int MSG_HIDE_FACE_UNLOCK_VIEW = 1;
    private final int MSG_SERVICE_DISCONNECTED = 1;
    private final int MSG_SERVICE_CONNECTED = 2;
    private final int MSG_UNLOCK = 2;
    private final int MSG_SERVICE_DISCONNECTED = 3;
    private final int MSG_CANCEL = 3;
    private final int MSG_UNLOCK = 4;
    private final int MSG_REPORT_FAILED_ATTEMPT = 4;
    private final int MSG_CANCEL = 5;
    private final int MSG_EXPOSE_FALLBACK = 5;
    private final int MSG_REPORT_FAILED_ATTEMPT = 6;
    private final int MSG_POKE_WAKELOCK = 6;
    private final int MSG_EXPOSE_FALLBACK = 7;
    private final int MSG_POKE_WAKELOCK = 8;


    // TODO: This was added for the purpose of adhering to what the biometric interface expects
    // TODO: This was added for the purpose of adhering to what the biometric interface expects
    // the isRunning() function to return.  However, it is probably not necessary to have both
    // the isRunning() function to return.  However, it is probably not necessary to have both
    // mRunning and mServiceRunning.  I'd just rather wait to change that logic.
    // mRunning and mServiceRunning.  I'd just rather wait to change that logic.
    private volatile boolean mIsRunning = false;
    private volatile boolean mIsRunning = false;


    // Long enough to stay visible while the service starts
    // Short enough to not have to wait long for backup if service fails to start or crashes
    // The service can take a couple of seconds to start on the first try after boot
    private final int SERVICE_STARTUP_VIEW_TIMEOUT = 3000;

    // So the user has a consistent amount of time when brought to the backup method from Face
    // So the user has a consistent amount of time when brought to the backup method from Face
    // Unlock
    // Unlock
    private final int BACKUP_LOCK_TIMEOUT = 5000;
    private final int BACKUP_LOCK_TIMEOUT = 5000;
@@ -110,30 +103,11 @@ public class FaceUnlock implements BiometricSensorUnlock, Handler.Callback {
    }
    }


    /**
    /**
     * Sets the Face Unlock view to visible, hiding it after the specified amount of time.  If
     * Dismisses face unlock and goes to the backup lock
     * timeoutMillis is 0, no hide is performed.  Called on the UI thread.
     */
     */
    public void show(long timeoutMillis) {
    public void stopAndShowBackup() {
        if (DEBUG) Log.d(TAG, "show()");
        if (DEBUG) Log.d(TAG, "stopAndShowBackup()");
        if (mHandler.getLooper() != Looper.myLooper()) {
        mHandler.sendEmptyMessage(MSG_CANCEL);
            Log.e(TAG, "show() called off of the UI thread");
        }
        removeDisplayMessages();
        if (timeoutMillis > 0) {
            mHandler.sendEmptyMessageDelayed(MSG_HIDE_FACE_UNLOCK_VIEW, timeoutMillis);
        }
    }

    /**
     * Hides the Face Unlock view.
     */
    public void hide() {
        if (DEBUG) Log.d(TAG, "hide()");
        // Removes any wakelock messages to make sure they don't cause the screen to turn back on.
        mHandler.removeMessages(MSG_POKE_WAKELOCK);
        // Remove messages to prevent a delayed show message from undo-ing the hide
        removeDisplayMessages();
        mHandler.sendEmptyMessage(MSG_HIDE_FACE_UNLOCK_VIEW);
    }
    }


    /**
    /**
@@ -151,10 +125,6 @@ public class FaceUnlock implements BiometricSensorUnlock, Handler.Callback {
            Log.w(TAG, "start() called when already running");
            Log.w(TAG, "start() called when already running");
        }
        }


        // Show Face Unlock view, but only for a little bit so lockpattern will become visible if
        // Face Unlock fails to start or crashes
        // This must show before bind to guarantee that Face Unlock has a place to display
        show(SERVICE_STARTUP_VIEW_TIMEOUT);
        if (!mBoundToService) {
        if (!mBoundToService) {
            Log.d(TAG, "Binding to Face Unlock service for user="
            Log.d(TAG, "Binding to Face Unlock service for user="
                    + mLockPatternUtils.getCurrentUser());
                    + mLockPatternUtils.getCurrentUser());
@@ -234,12 +204,6 @@ public class FaceUnlock implements BiometricSensorUnlock, Handler.Callback {
     */
     */
    public boolean handleMessage(Message msg) {
    public boolean handleMessage(Message msg) {
        switch (msg.what) {
        switch (msg.what) {
            case MSG_SHOW_FACE_UNLOCK_VIEW:
                handleShowFaceUnlockView();
                break;
            case MSG_HIDE_FACE_UNLOCK_VIEW:
                handleHideFaceUnlockView();
                break;
            case MSG_SERVICE_CONNECTED:
            case MSG_SERVICE_CONNECTED:
                handleServiceConnected();
                handleServiceConnected();
                break;
                break;
@@ -268,22 +232,6 @@ public class FaceUnlock implements BiometricSensorUnlock, Handler.Callback {
        return true;
        return true;
    }
    }


    /**
     * Sets the Face Unlock view to visible, thus covering the backup lock.
     */
    void handleShowFaceUnlockView() {
        if (DEBUG) Log.d(TAG, "handleShowFaceUnlockView()");
        // Not required
    }

    /**
     * Hide face unlock and show backup
     */
    void handleHideFaceUnlockView() {
        if (DEBUG) Log.d(TAG, "handleHideFaceUnlockView()");
        mKeyguardScreenCallback.showBackupSecurity();
    }

    /**
    /**
     * Tells the service to start its UI via an AIDL interface.  Called when the
     * Tells the service to start its UI via an AIDL interface.  Called when the
     * onServiceConnected() callback is received.
     * onServiceConnected() callback is received.
@@ -347,23 +295,21 @@ public class FaceUnlock implements BiometricSensorUnlock, Handler.Callback {
    }
    }


    /**
    /**
     * Stops the Face Unlock service and tells the device to grant access to the user.  Shows the
     * Stops the Face Unlock service and tells the device to grant access to the user.
     * Face Unlock view to keep the backup lock covered while the device unlocks.
     */
     */
    void handleUnlock() {
    void handleUnlock() {
        if (DEBUG) Log.d(TAG, "handleUnlock()");
        if (DEBUG) Log.d(TAG, "handleUnlock()");
        removeDisplayMessages();
        stop();
        stop();
        mKeyguardScreenCallback.reportSuccessfulUnlockAttempt();
        mKeyguardScreenCallback.reportSuccessfulUnlockAttempt();
        mKeyguardScreenCallback.dismiss(true);
        mKeyguardScreenCallback.dismiss(true);
    }
    }


    /**
    /**
     * Stops the Face Unlock service and exposes the backup lock.
     * Stops the Face Unlock service and goes to the backup lock.
     */
     */
    void handleCancel() {
    void handleCancel() {
        if (DEBUG) Log.d(TAG, "handleCancel()");
        if (DEBUG) Log.d(TAG, "handleCancel()");
        mKeyguardScreenCallback.dismiss(false);
        mKeyguardScreenCallback.showBackupSecurity();
        stop();
        stop();
        mKeyguardScreenCallback.userActivity(BACKUP_LOCK_TIMEOUT);
        mKeyguardScreenCallback.userActivity(BACKUP_LOCK_TIMEOUT);
    }
    }
@@ -397,15 +343,6 @@ public class FaceUnlock implements BiometricSensorUnlock, Handler.Callback {
      }
      }
    }
    }


    /**
     * Removes show and hide messages from the message queue.  Called to prevent delayed show/hide
     * messages from undoing a new message.
     */
    private void removeDisplayMessages() {
        mHandler.removeMessages(MSG_SHOW_FACE_UNLOCK_VIEW);
        mHandler.removeMessages(MSG_HIDE_FACE_UNLOCK_VIEW);
    }

    /**
    /**
     * Implements service connection methods.
     * Implements service connection methods.
     */
     */
@@ -508,7 +445,7 @@ public class FaceUnlock implements BiometricSensorUnlock, Handler.Callback {
         * Called when the Face Unlock service starts displaying the UI, indicating that the backup
         * Called when the Face Unlock service starts displaying the UI, indicating that the backup
         * unlock can be exposed because the Face Unlock service is now covering the backup with its
         * unlock can be exposed because the Face Unlock service is now covering the backup with its
         * UI.
         * UI.
         **/
         */
        public void exposeFallback() {
        public void exposeFallback() {
            if (DEBUG) Log.d(TAG, "exposeFallback()");
            if (DEBUG) Log.d(TAG, "exposeFallback()");
            mHandler.sendEmptyMessage(MSG_EXPOSE_FALLBACK);
            mHandler.sendEmptyMessage(MSG_EXPOSE_FALLBACK);
+24 −9
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import android.telephony.TelephonyManager;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Log;
import android.view.View;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.LinearLayout;


import com.android.internal.R;
import com.android.internal.R;
@@ -29,11 +30,13 @@ import com.android.internal.widget.LockPatternUtils;
public class KeyguardFaceUnlockView extends LinearLayout implements KeyguardSecurityView {
public class KeyguardFaceUnlockView extends LinearLayout implements KeyguardSecurityView {


    private static final String TAG = "KeyguardFaceUnlockView";
    private static final String TAG = "KeyguardFaceUnlockView";
    private static final boolean DEBUG = false;
    private KeyguardSecurityCallback mKeyguardSecurityCallback;
    private KeyguardSecurityCallback mKeyguardSecurityCallback;
    private LockPatternUtils mLockPatternUtils;
    private LockPatternUtils mLockPatternUtils;
    private BiometricSensorUnlock mBiometricUnlock;
    private BiometricSensorUnlock mBiometricUnlock;
    private KeyguardNavigationManager mNavigationManager;
    private KeyguardNavigationManager mNavigationManager;
    private View mFaceUnlockAreaView;
    private View mFaceUnlockAreaView;
    private ImageButton mCancelButton;


    public KeyguardFaceUnlockView(Context context) {
    public KeyguardFaceUnlockView(Context context) {
        this(context, null);
        this(context, null);
@@ -70,25 +73,25 @@ public class KeyguardFaceUnlockView extends LinearLayout implements KeyguardSecu


    @Override
    @Override
    public void onDetachedFromWindow() {
    public void onDetachedFromWindow() {
        if (DEBUG) Log.d(TAG, "onDetachedFromWindow()");
        if (mBiometricUnlock != null) {
        if (mBiometricUnlock != null) {
            mBiometricUnlock.hide();
            mBiometricUnlock.stopAndShowBackup();
            mBiometricUnlock.stop();
        }
        }
    }
    }


    @Override
    @Override
    public void onPause() {
    public void onPause() {
        if (DEBUG) Log.d(TAG, "onPause()");
        if (mBiometricUnlock != null) {
        if (mBiometricUnlock != null) {
            mBiometricUnlock.hide();
            mBiometricUnlock.stopAndShowBackup();
            mBiometricUnlock.stop();
        }
        }
        KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateCallback);
        KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateCallback);
    }
    }


    @Override
    @Override
    public void onResume() {
    public void onResume() {
        if (DEBUG) Log.d(TAG, "onResume()");
        maybeStartBiometricUnlock();
        maybeStartBiometricUnlock();
        mBiometricUnlock.show(0);
        KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateCallback);
        KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateCallback);
    }
    }


@@ -112,6 +115,14 @@ public class KeyguardFaceUnlockView extends LinearLayout implements KeyguardSecu
        mFaceUnlockAreaView = findViewById(R.id.face_unlock_area_view);
        mFaceUnlockAreaView = findViewById(R.id.face_unlock_area_view);
        if (mFaceUnlockAreaView != null) {
        if (mFaceUnlockAreaView != null) {
            mBiometricUnlock = new FaceUnlock(mContext);
            mBiometricUnlock = new FaceUnlock(mContext);

            mCancelButton = (ImageButton) findViewById(R.id.face_unlock_cancel_button);
            mCancelButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    mBiometricUnlock.stopAndShowBackup();
                }
            });
        } else {
        } else {
            Log.w(TAG, "Couldn't find biometric unlock view");
            Log.w(TAG, "Couldn't find biometric unlock view");
        }
        }
@@ -123,17 +134,20 @@ public class KeyguardFaceUnlockView extends LinearLayout implements KeyguardSecu
     * unlock area.
     * unlock area.
     */
     */
    private void maybeStartBiometricUnlock() {
    private void maybeStartBiometricUnlock() {
        if (DEBUG) Log.d(TAG, "maybeStartBiometricUnlock()");
        if (mBiometricUnlock != null) {
        if (mBiometricUnlock != null) {
            KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext);
            KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext);
            final boolean backupIsTimedOut = (
            final boolean backupIsTimedOut = (
                    monitor.getFailedUnlockAttempts() >=
                    monitor.getFailedUnlockAttempts() >=
                    LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT);
                    LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT);
            if (monitor.getPhoneState() == TelephonyManager.CALL_STATE_IDLE
            // TODO: These max attempts checks are also checked in KeyguardSecurityModel so they
            // might not be necessary here anymore.
            if (monitor.getPhoneState() != TelephonyManager.CALL_STATE_RINGING
                    && !monitor.getMaxBiometricUnlockAttemptsReached()
                    && !monitor.getMaxBiometricUnlockAttemptsReached()
                    && !backupIsTimedOut) {
                    && !backupIsTimedOut) {
                mBiometricUnlock.start();
                mBiometricUnlock.start();
            } else {
            } else {
                mBiometricUnlock.hide();
                mBiometricUnlock.stopAndShowBackup();
            }
            }
        }
        }
    }
    }
@@ -142,14 +156,15 @@ public class KeyguardFaceUnlockView extends LinearLayout implements KeyguardSecu
        // We need to stop the biometric unlock when a phone call comes in
        // We need to stop the biometric unlock when a phone call comes in
        @Override
        @Override
        public void onPhoneStateChanged(int phoneState) {
        public void onPhoneStateChanged(int phoneState) {
            if (DEBUG) Log.d(TAG, "onPhoneStateChanged(" + phoneState + ")");
            if (phoneState == TelephonyManager.CALL_STATE_RINGING) {
            if (phoneState == TelephonyManager.CALL_STATE_RINGING) {
                mBiometricUnlock.stop();
                mBiometricUnlock.stopAndShowBackup();
                mBiometricUnlock.hide();
            }
            }
        }
        }


        @Override
        @Override
        public void onUserSwitched(int userId) {
        public void onUserSwitched(int userId) {
            if (DEBUG) Log.d(TAG, "onUserSwitched(" + userId + ")");
            if (mBiometricUnlock != null) {
            if (mBiometricUnlock != null) {
                mBiometricUnlock.stop();
                mBiometricUnlock.stop();
            }
            }
Loading