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

Commit e1c05111 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove manager dependency from biometric services"

parents 0a5d59ff 8b7a037e
Loading
Loading
Loading
Loading
+0 −25
Original line number Diff line number Diff line
@@ -201,31 +201,6 @@ public interface BiometricAuthenticator {
        throw new UnsupportedOperationException("Stub!");
    }

    /**
     * @param error
     * @param vendorCode
     * @return the error string associated with this error
     */
    default String getErrorString(int error, int vendorCode) {
        throw new UnsupportedOperationException("Stub!");
    }

    /**
     * @param acquireInfo
     * @param vendorCode
     * @return the help string associated with this code
     */
    default String getAcquiredString(int acquireInfo, int vendorCode) {
        throw new UnsupportedOperationException("Stub!");
    }

    /**
     * @return one of {@link #TYPE_FINGERPRINT} {@link #TYPE_IRIS} or {@link #TYPE_FACE}
     */
    default int getType() {
        throw new UnsupportedOperationException("Stub!");
    }

    /**
     * This call warms up the hardware and starts scanning for valid biometrics. It terminates
     * when {@link AuthenticationCallback#onAuthenticationError(int,
+42 −46
Original line number Diff line number Diff line
@@ -168,10 +168,11 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
            } catch (RemoteException e) {
                Log.w(TAG, "Remote exception while authenticating: ", e);
                if (callback != null) {
                    // Though this may not be a hardware issue, it will cause apps to give up or try
                    // again later.
                    // Though this may not be a hardware issue, it will cause apps to give up or
                    // try again later.
                    callback.onAuthenticationError(FACE_ERROR_HW_UNAVAILABLE,
                            getErrorString(FACE_ERROR_HW_UNAVAILABLE, 0 /* vendorCode */));
                            getErrorString(mContext, FACE_ERROR_HW_UNAVAILABLE,
                                0 /* vendorCode */));
                }
            }
        }
@@ -232,10 +233,11 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
            } catch (RemoteException e) {
                Log.w(TAG, "Remote exception in enroll: ", e);
                if (callback != null) {
                    // Though this may not be a hardware issue, it will cause apps to give up or try
                    // again later.
                    // Though this may not be a hardware issue, it will cause apps to give up or
                    // try again later.
                    callback.onEnrollmentError(FACE_ERROR_HW_UNAVAILABLE,
                            getErrorString(FACE_ERROR_HW_UNAVAILABLE, 0 /* vendorCode */));
                            getErrorString(mContext, FACE_ERROR_HW_UNAVAILABLE,
                                0 /* vendorCode */));
                }
            }
        }
@@ -315,7 +317,8 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
                Log.w(TAG, "Remote exception in remove: ", e);
                if (callback != null) {
                    callback.onRemovalError(face, FACE_ERROR_HW_UNAVAILABLE,
                            getErrorString(FACE_ERROR_HW_UNAVAILABLE, 0 /* vendorCode */));
                            getErrorString(mContext, FACE_ERROR_HW_UNAVAILABLE,
                                0 /* vendorCode */));
                }
            }
        }
@@ -513,32 +516,34 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
        }
    }

    @Override
    public String getErrorString(int errMsg, int vendorCode) {
    /**
     * @hide
     */
    public static String getErrorString(Context context, int errMsg, int vendorCode) {
        switch (errMsg) {
            case FACE_ERROR_HW_UNAVAILABLE:
                return mContext.getString(
                return context.getString(
                        com.android.internal.R.string.face_error_hw_not_available);
            case FACE_ERROR_UNABLE_TO_PROCESS:
                return mContext.getString(
                return context.getString(
                        com.android.internal.R.string.face_error_unable_to_process);
            case FACE_ERROR_TIMEOUT:
                return mContext.getString(com.android.internal.R.string.face_error_timeout);
                return context.getString(com.android.internal.R.string.face_error_timeout);
            case FACE_ERROR_NO_SPACE:
                return mContext.getString(com.android.internal.R.string.face_error_no_space);
                return context.getString(com.android.internal.R.string.face_error_no_space);
            case FACE_ERROR_CANCELED:
                return mContext.getString(com.android.internal.R.string.face_error_canceled);
                return context.getString(com.android.internal.R.string.face_error_canceled);
            case FACE_ERROR_LOCKOUT:
                return mContext.getString(com.android.internal.R.string.face_error_lockout);
                return context.getString(com.android.internal.R.string.face_error_lockout);
            case FACE_ERROR_LOCKOUT_PERMANENT:
                return mContext.getString(
                return context.getString(
                        com.android.internal.R.string.face_error_lockout_permanent);
            case FACE_ERROR_NOT_ENROLLED:
                return mContext.getString(com.android.internal.R.string.face_error_not_enrolled);
                return context.getString(com.android.internal.R.string.face_error_not_enrolled);
            case FACE_ERROR_HW_NOT_PRESENT:
                return mContext.getString(com.android.internal.R.string.face_error_hw_not_present);
                return context.getString(com.android.internal.R.string.face_error_hw_not_present);
            case FACE_ERROR_VENDOR: {
                String[] msgArray = mContext.getResources().getStringArray(
                String[] msgArray = context.getResources().getStringArray(
                        com.android.internal.R.array.face_error_vendor);
                if (vendorCode < msgArray.length) {
                    return msgArray[vendorCode];
@@ -552,35 +557,34 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
    /**
     * @hide
     */
    @Override
    public String getAcquiredString(int acquireInfo, int vendorCode) {
    public static String getAcquiredString(Context context, int acquireInfo, int vendorCode) {
        switch (acquireInfo) {
            case FACE_ACQUIRED_GOOD:
                return null;
            case FACE_ACQUIRED_INSUFFICIENT:
                return mContext.getString(R.string.face_acquired_insufficient);
                return context.getString(R.string.face_acquired_insufficient);
            case FACE_ACQUIRED_TOO_BRIGHT:
                return mContext.getString(R.string.face_acquired_too_bright);
                return context.getString(R.string.face_acquired_too_bright);
            case FACE_ACQUIRED_TOO_DARK:
                return mContext.getString(R.string.face_acquired_too_dark);
                return context.getString(R.string.face_acquired_too_dark);
            case FACE_ACQUIRED_TOO_CLOSE:
                return mContext.getString(R.string.face_acquired_too_close);
                return context.getString(R.string.face_acquired_too_close);
            case FACE_ACQUIRED_TOO_FAR:
                return mContext.getString(R.string.face_acquired_too_far);
                return context.getString(R.string.face_acquired_too_far);
            case FACE_ACQUIRED_TOO_HIGH:
                return mContext.getString(R.string.face_acquired_too_high);
                return context.getString(R.string.face_acquired_too_high);
            case FACE_ACQUIRED_TOO_LOW:
                return mContext.getString(R.string.face_acquired_too_low);
                return context.getString(R.string.face_acquired_too_low);
            case FACE_ACQUIRED_TOO_RIGHT:
                return mContext.getString(R.string.face_acquired_too_right);
                return context.getString(R.string.face_acquired_too_right);
            case FACE_ACQUIRED_TOO_LEFT:
                return mContext.getString(R.string.face_acquired_too_left);
                return context.getString(R.string.face_acquired_too_left);
            case FACE_ACQUIRED_POOR_GAZE:
                return mContext.getString(R.string.face_acquired_poor_gaze);
                return context.getString(R.string.face_acquired_poor_gaze);
            case FACE_ACQUIRED_NOT_DETECTED:
                return mContext.getString(R.string.face_acquired_not_detected);
                return context.getString(R.string.face_acquired_not_detected);
            case FACE_ACQUIRED_VENDOR: {
                String[] msgArray = mContext.getResources().getStringArray(
                String[] msgArray = context.getResources().getStringArray(
                        R.array.face_acquired_vendor);
                if (vendorCode < msgArray.length) {
                    return msgArray[vendorCode];
@@ -591,19 +595,11 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
        return null;
    }

    /**
     * @hide
     */
    @Override
    public int getType() {
        return TYPE_FACE;
    }

    /**
     * Used so BiometricPrompt can map the face ones onto existing public constants.
     * @hide
     */
    public int getMappedAcquiredInfo(int acquireInfo, int vendorCode) {
    public static int getMappedAcquiredInfo(int acquireInfo, int vendorCode) {
        switch (acquireInfo) {
            case FACE_ACQUIRED_GOOD:
                return BiometricConstants.BIOMETRIC_ACQUIRED_GOOD;
@@ -898,13 +894,13 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
                ? (vendorCode + FACE_ERROR_VENDOR_BASE) : errMsgId;
        if (mEnrollmentCallback != null) {
            mEnrollmentCallback.onEnrollmentError(clientErrMsgId,
                    getErrorString(errMsgId, vendorCode));
                    getErrorString(mContext, errMsgId, vendorCode));
        } else if (mAuthenticationCallback != null) {
            mAuthenticationCallback.onAuthenticationError(clientErrMsgId,
                    getErrorString(errMsgId, vendorCode));
                    getErrorString(mContext, errMsgId, vendorCode));
        } else if (mRemovalCallback != null) {
            mRemovalCallback.onRemovalError(mRemovalFace, clientErrMsgId,
                    getErrorString(errMsgId, vendorCode));
                    getErrorString(mContext, errMsgId, vendorCode));
        }
    }

@@ -932,7 +928,7 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
        if (mAuthenticationCallback != null) {
            mAuthenticationCallback.onAuthenticationAcquired(acquireInfo);
        }
        final String msg = getAcquiredString(acquireInfo, vendorCode);
        final String msg = getAcquiredString(mContext, acquireInfo, vendorCode);
        if (msg == null) {
            return;
        }
+32 −38
Original line number Diff line number Diff line
@@ -426,7 +426,8 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
                // Though this may not be a hardware issue, it will cause apps to give up or try
                // again later.
                callback.onAuthenticationError(FINGERPRINT_ERROR_HW_UNAVAILABLE,
                        getErrorString(FINGERPRINT_ERROR_HW_UNAVAILABLE, 0 /* vendorCode */));
                        getErrorString(mContext, FINGERPRINT_ERROR_HW_UNAVAILABLE,
                            0 /* vendorCode */));
            }
        }
    }
@@ -476,7 +477,8 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
                // Though this may not be a hardware issue, it will cause apps to give up or try
                // again later.
                callback.onEnrollmentError(FINGERPRINT_ERROR_HW_UNAVAILABLE,
                        getErrorString(FINGERPRINT_ERROR_HW_UNAVAILABLE, 0 /* vendorCode */));
                        getErrorString(mContext, FINGERPRINT_ERROR_HW_UNAVAILABLE,
                            0 /* vendorCode */));
            }
        }
    }
@@ -546,7 +548,8 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
            Slog.w(TAG, "Remote exception in remove: ", e);
            if (callback != null) {
                callback.onRemovalError(fp, FINGERPRINT_ERROR_HW_UNAVAILABLE,
                        getErrorString(FINGERPRINT_ERROR_HW_UNAVAILABLE, 0 /* vendorCode */));
                        getErrorString(mContext, FINGERPRINT_ERROR_HW_UNAVAILABLE,
                            0 /* vendorCode */));
            }
        }
    }
@@ -568,7 +571,8 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
            Slog.w(TAG, "Remote exception in enumerate: ", e);
            if (callback != null) {
                callback.onEnumerateError(FINGERPRINT_ERROR_HW_UNAVAILABLE,
                        getErrorString(FINGERPRINT_ERROR_HW_UNAVAILABLE, 0 /* vendorCode */));
                        getErrorString(mContext, FINGERPRINT_ERROR_HW_UNAVAILABLE,
                            0 /* vendorCode */));
            }
        }
    }
@@ -862,7 +866,7 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
        if (mAuthenticationCallback != null) {
            mAuthenticationCallback.onAuthenticationAcquired(acquireInfo);
        }
        final String msg = getAcquiredString(acquireInfo, vendorCode);
        final String msg = getAcquiredString(mContext, acquireInfo, vendorCode);
        if (msg == null) {
            return;
        }
@@ -882,16 +886,16 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
                ? (vendorCode + FINGERPRINT_ERROR_VENDOR_BASE) : errMsgId;
        if (mEnrollmentCallback != null) {
            mEnrollmentCallback.onEnrollmentError(clientErrMsgId,
                    getErrorString(errMsgId, vendorCode));
                    getErrorString(mContext, errMsgId, vendorCode));
        } else if (mAuthenticationCallback != null) {
            mAuthenticationCallback.onAuthenticationError(clientErrMsgId,
                    getErrorString(errMsgId, vendorCode));
                    getErrorString(mContext, errMsgId, vendorCode));
        } else if (mRemovalCallback != null) {
            mRemovalCallback.onRemovalError(mRemovalFingerprint, clientErrMsgId,
                    getErrorString(errMsgId, vendorCode));
                    getErrorString(mContext, errMsgId, vendorCode));
        } else if (mEnumerateCallback != null) {
            mEnumerateCallback.onEnumerateError(clientErrMsgId,
                    getErrorString(errMsgId, vendorCode));
                    getErrorString(mContext, errMsgId, vendorCode));
        }
    }

@@ -934,38 +938,37 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
    /**
     * @hide
     */
    @Override
    public String getErrorString(int errMsg, int vendorCode) {
    public static String getErrorString(Context context, int errMsg, int vendorCode) {
        switch (errMsg) {
            case FINGERPRINT_ERROR_UNABLE_TO_PROCESS:
                return mContext.getString(
                return context.getString(
                    com.android.internal.R.string.fingerprint_error_unable_to_process);
            case FINGERPRINT_ERROR_HW_UNAVAILABLE:
                return mContext.getString(
                return context.getString(
                    com.android.internal.R.string.fingerprint_error_hw_not_available);
            case FINGERPRINT_ERROR_NO_SPACE:
                return mContext.getString(
                return context.getString(
                    com.android.internal.R.string.fingerprint_error_no_space);
            case FINGERPRINT_ERROR_TIMEOUT:
                return mContext.getString(com.android.internal.R.string.fingerprint_error_timeout);
                return context.getString(com.android.internal.R.string.fingerprint_error_timeout);
            case FINGERPRINT_ERROR_CANCELED:
                return mContext.getString(com.android.internal.R.string.fingerprint_error_canceled);
                return context.getString(com.android.internal.R.string.fingerprint_error_canceled);
            case FINGERPRINT_ERROR_LOCKOUT:
                return mContext.getString(com.android.internal.R.string.fingerprint_error_lockout);
                return context.getString(com.android.internal.R.string.fingerprint_error_lockout);
            case FINGERPRINT_ERROR_LOCKOUT_PERMANENT:
                return mContext.getString(
                return context.getString(
                        com.android.internal.R.string.fingerprint_error_lockout_permanent);
            case FINGERPRINT_ERROR_USER_CANCELED:
                return mContext.getString(
                return context.getString(
                        com.android.internal.R.string.fingerprint_error_user_canceled);
            case FINGERPRINT_ERROR_NO_FINGERPRINTS:
                return mContext.getString(
                return context.getString(
                        com.android.internal.R.string.fingerprint_error_no_fingerprints);
            case FINGERPRINT_ERROR_HW_NOT_PRESENT:
                return mContext.getString(
                return context.getString(
                        com.android.internal.R.string.fingerprint_error_hw_not_present);
            case FINGERPRINT_ERROR_VENDOR: {
                    String[] msgArray = mContext.getResources().getStringArray(
                    String[] msgArray = context.getResources().getStringArray(
                            com.android.internal.R.array.fingerprint_error_vendor);
                    if (vendorCode < msgArray.length) {
                        return msgArray[vendorCode];
@@ -979,28 +982,27 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
    /**
     * @hide
     */
    @Override
    public String getAcquiredString(int acquireInfo, int vendorCode) {
    public static String getAcquiredString(Context context, int acquireInfo, int vendorCode) {
        switch (acquireInfo) {
            case FINGERPRINT_ACQUIRED_GOOD:
                return null;
            case FINGERPRINT_ACQUIRED_PARTIAL:
                return mContext.getString(
                return context.getString(
                    com.android.internal.R.string.fingerprint_acquired_partial);
            case FINGERPRINT_ACQUIRED_INSUFFICIENT:
                return mContext.getString(
                return context.getString(
                    com.android.internal.R.string.fingerprint_acquired_insufficient);
            case FINGERPRINT_ACQUIRED_IMAGER_DIRTY:
                return mContext.getString(
                return context.getString(
                    com.android.internal.R.string.fingerprint_acquired_imager_dirty);
            case FINGERPRINT_ACQUIRED_TOO_SLOW:
                return mContext.getString(
                return context.getString(
                    com.android.internal.R.string.fingerprint_acquired_too_slow);
            case FINGERPRINT_ACQUIRED_TOO_FAST:
                return mContext.getString(
                return context.getString(
                    com.android.internal.R.string.fingerprint_acquired_too_fast);
            case FINGERPRINT_ACQUIRED_VENDOR: {
                    String[] msgArray = mContext.getResources().getStringArray(
                    String[] msgArray = context.getResources().getStringArray(
                            com.android.internal.R.array.fingerprint_acquired_vendor);
                    if (vendorCode < msgArray.length) {
                        return msgArray[vendorCode];
@@ -1011,14 +1013,6 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
        return null;
    }

    /**
     * @hide
     */
    @Override
    public int getType() {
        return TYPE_FINGERPRINT;
    }

    private IFingerprintServiceReceiver mServiceReceiver = new IFingerprintServiceReceiver.Stub() {

        @Override // binder call
+11 −10
Original line number Diff line number Diff line
@@ -39,12 +39,17 @@ public abstract class AuthenticationClient extends ClientMonitor {

    public abstract int handleFailedAttempt();
    public abstract void resetFailedAttempts();
    public abstract String getErrorString(int error, int vendorCode);
    public abstract String getAcquiredString(int acquireInfo, int vendorCode);
    /**
      * @return one of {@link #TYPE_FINGERPRINT} {@link #TYPE_IRIS} or {@link #TYPE_FACE}
      */
    public abstract int getBiometricType();

    public static final int LOCKOUT_NONE = 0;
    public static final int LOCKOUT_TIMED = 1;
    public static final int LOCKOUT_PERMANENT = 2;

    private final BiometricAuthenticator mAuthenticator;
    // Callback mechanism received from the client
    // (BiometricPrompt -> BiometricPromptService -> <Biometric>Service -> AuthenticationClient)
    private IBiometricPromptReceiver mDialogReceiverFromClient;
@@ -88,15 +93,13 @@ public abstract class AuthenticationClient extends ClientMonitor {
            BiometricService.DaemonWrapper daemon, long halDeviceId, IBinder token,
            BiometricService.ServiceListener listener, int targetUserId, int groupId, long opId,
            boolean restricted, String owner, Bundle bundle,
            IBiometricPromptReceiver dialogReceiver, IStatusBarService statusBarService,
            BiometricAuthenticator authenticator) {
            IBiometricPromptReceiver dialogReceiver, IStatusBarService statusBarService) {
        super(context, metrics, daemon, halDeviceId, token, listener, targetUserId, groupId,
                restricted, owner);
        mOpId = opId;
        mBundle = bundle;
        mDialogReceiverFromClient = dialogReceiver;
        mStatusBarService = statusBarService;
        mAuthenticator = authenticator;
        mHandler = new Handler(Looper.getMainLooper());
    }

@@ -115,8 +118,7 @@ public abstract class AuthenticationClient extends ClientMonitor {
        if (mBundle != null) {
            try {
                if (acquiredInfo != BiometricConstants.BIOMETRIC_ACQUIRED_GOOD) {
                    mStatusBarService.onBiometricHelp(
                            mAuthenticator.getAcquiredString(acquiredInfo, vendorCode));
                    mStatusBarService.onBiometricHelp(getAcquiredString(acquiredInfo, vendorCode));
                }
                return false; // acquisition continues
            } catch (RemoteException e) {
@@ -144,8 +146,7 @@ public abstract class AuthenticationClient extends ClientMonitor {
        }
        if (mBundle != null) {
            try {
                mStatusBarService.onBiometricError(
                        mAuthenticator.getErrorString(error, vendorCode));
                mStatusBarService.onBiometricError(getErrorString(error, vendorCode));
            } catch (RemoteException e) {
                Slog.e(getLogTag(), "Remote exception when sending error", e);
            }
@@ -220,7 +221,7 @@ public abstract class AuthenticationClient extends ClientMonitor {
                    // Send the lockout message to the system dialog
                    if (mBundle != null) {
                        mStatusBarService.onBiometricError(
                                mAuthenticator.getErrorString(errorCode, 0 /* vendorCode */));
                                getErrorString(errorCode, 0 /* vendorCode */));
                        mHandler.postDelayed(() -> {
                            try {
                                listener.onError(getHalDeviceId(), errorCode, 0 /* vendorCode */);
@@ -268,7 +269,7 @@ public abstract class AuthenticationClient extends ClientMonitor {
            if (mBundle != null) {
                try {
                    mStatusBarService.showBiometricDialog(mBundle, mDialogReceiver,
                            mAuthenticator.getType());
                            getBiometricType());
                } catch (RemoteException e) {
                    Slog.e(getLogTag(), "Unable to show biometric dialog", e);
                }
+4 −4
Original line number Diff line number Diff line
@@ -219,16 +219,16 @@ public abstract class BiometricService extends SystemService implements IHwBinde
     */
    protected void notifyClientActiveCallbacks(boolean isActive) {}

    protected class AuthenticationClientImpl extends AuthenticationClient {
    protected abstract class AuthenticationClientImpl extends AuthenticationClient {

        public AuthenticationClientImpl(Context context, DaemonWrapper daemon, long halDeviceId,
                IBinder token, ServiceListener listener, int targetUserId, int groupId, long opId,
                boolean restricted, String owner, Bundle bundle,
                IBiometricPromptReceiver dialogReceiver,
                IStatusBarService statusBarService, BiometricAuthenticator authenticator) {
                IStatusBarService statusBarService) {
            super(context, getMetrics(), daemon, halDeviceId, token, listener,
                    targetUserId, groupId, opId, restricted, owner, bundle, dialogReceiver,
                    statusBarService, authenticator);
                    statusBarService);
        }

        @Override
Loading