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

Commit 1f59d3c4 authored by Kevin Chyn's avatar Kevin Chyn Committed by Android (Google) Code Review
Browse files

Merge "Forward correct biometric in AuthenticationClient"

parents 9c5f04f9 b528d69a
Loading
Loading
Loading
Loading
+5 −39
Original line number Diff line number Diff line
@@ -26,47 +26,13 @@ import android.os.Parcelable;
 * @hide
 */
public final class Face extends BiometricAuthenticator.Identifier {
    private CharSequence mName;
    private int mFaceId;
    private long mDeviceId; // physical device this face is associated with

    public Face(CharSequence name, int faceId, long deviceId) {
        mName = name;
        mFaceId = faceId;
        mDeviceId = deviceId;
        super(name, faceId, deviceId);
    }

    private Face(Parcel in) {
        mName = in.readString();
        mFaceId = in.readInt();
        mDeviceId = in.readLong();
    }

    /**
     * Gets the human-readable name for the given fingerprint.
     * @return name given to finger
     */
    public CharSequence getName() {
        return mName;
    }

    /**
     * Gets the device-specific finger id.  Used by Settings to map a name to a specific
     * fingerprint template.
     * @return device-specific id for this finger
     * @hide
     */
    public int getFaceId() {
        return mFaceId;
    }

    /**
     * Device this face belongs to.
     *
     * @hide
     */
    public long getDeviceId() {
        return mDeviceId;
        super(in.readString(), in.readInt(), in.readLong());
    }

    /**
@@ -83,9 +49,9 @@ public final class Face extends BiometricAuthenticator.Identifier {
     * @param flags Additional flags about how the object should be written.
     */
    public void writeToParcel(Parcel out, int flags) {
        out.writeString(mName.toString());
        out.writeInt(mFaceId);
        out.writeLong(mDeviceId);
        out.writeString(getName().toString());
        out.writeInt(getBiometricId());
        out.writeLong(getDeviceId());
    }

    public static final Parcelable.Creator<Face> CREATOR = new Parcelable.Creator<Face>() {
+13 −1
Original line number Diff line number Diff line
@@ -418,7 +418,7 @@ public class FaceManager implements BiometricFaceConstants {
            try {
                mRemovalCallback = callback;
                mRemovalFace = face;
                mService.remove(mToken, face.getFaceId(), userId, mServiceReceiver);
                mService.remove(mToken, face.getBiometricId(), userId, mServiceReceiver);
            } catch (RemoteException e) {
                Log.w(TAG, "Remote exception in remove: ", e);
                if (callback != null) {
@@ -796,6 +796,18 @@ public class FaceManager implements BiometricFaceConstants {
         */
        public void onAuthenticationAcquired(int acquireInfo) {
        }

        /**
         * @hide
         * @param result
         */
        @Override
        public void onAuthenticationSucceeded(BiometricAuthenticator.AuthenticationResult result) {
            onAuthenticationSucceeded(new AuthenticationResult(
                    result.getCryptoObject(),
                    (Face) result.getId(), result.getUserId()));
        }

    }

    /**
+14 −7
Original line number Diff line number Diff line
@@ -153,11 +153,12 @@ public abstract class AuthenticationClient extends ClientMonitor {
    }

    @Override
    public boolean onAuthenticated(int fingerId, int groupId) {
    public boolean onAuthenticated(BiometricAuthenticator.Identifier identifier,
            boolean authenticated) {
        boolean result = false;
        boolean authenticated = fingerId != 0;

        // If the fingerprint dialog is showing, notify authentication succeeded
        // TODO: this goes to BiometricPrompt, split between biometric modalities
        if (mBundle != null) {
            try {
                if (authenticated) {
@@ -180,12 +181,18 @@ public abstract class AuthenticationClient extends ClientMonitor {
                } else {
                    if (DEBUG) {
                        Slog.v(getLogTag(), "onAuthenticated(owner=" + getOwnerString()
                                + ", id=" + fingerId + ", gp=" + groupId + ")");
                                + ", id=" + identifier.getBiometricId());
                    }

                    // Explicitly have if/else here to make it super obvious in case the code is
                    // touched in the future.
                    if (!getIsRestricted()) {
                        listener.onAuthenticationSucceeded(
                                getHalDeviceId(), identifier, getTargetUserId());
                    } else {
                        listener.onAuthenticationSucceeded(
                                getHalDeviceId(), null, getTargetUserId());
                    }
                    Fingerprint fp = !getIsRestricted()
                            ? new Fingerprint("" /* TODO */, groupId, fingerId, getHalDeviceId())
                            : null;
                    listener.onAuthenticationSucceeded(getHalDeviceId(), fp, getTargetUserId());
                }
            } catch (RemoteException e) {
                Slog.w(getLogTag(), "Failed to notify Authenticated:", e);
+6 −4
Original line number Diff line number Diff line
@@ -577,20 +577,22 @@ public abstract class BiometricService extends SystemService implements IHwBinde
        }
    }

    protected void handleAuthenticated(long deviceId, int biometricId, int groupId,
    protected void handleAuthenticated(BiometricAuthenticator.Identifier identifier,
            ArrayList<Byte> token) {
        ClientMonitor client = mCurrentClient;
        if (biometricId != 0) {
        final boolean authenticated = identifier.getBiometricId() != 0;

        if (authenticated) {
            final byte[] byteToken = new byte[token.size()];
            for (int i = 0; i < token.size(); i++) {
                byteToken[i] = token.get(i);
            }
            KeyStore.getInstance().addAuthToken(byteToken);
        }
        if (client != null && client.onAuthenticated(biometricId, groupId)) {
        if (client != null && client.onAuthenticated(identifier, authenticated)) {
            removeClient(client);
        }
        if (biometricId != 0) {
        if (authenticated) {
            mPerformanceStats.accept++;
        } else {
            mPerformanceStats.reject++;
+2 −1
Original line number Diff line number Diff line
@@ -127,7 +127,8 @@ public abstract class ClientMonitor implements IBinder.DeathRecipient {
    // to the next client (e.g. authentication accepts or rejects a biometric).
    public abstract boolean onEnrollResult(BiometricAuthenticator.Identifier identifier,
            int remaining);
    public abstract boolean onAuthenticated(int biometricId, int groupId);
    public abstract boolean onAuthenticated(BiometricAuthenticator.Identifier identifier,
            boolean authenticated);
    public abstract boolean onRemoved(BiometricAuthenticator.Identifier identifier,
            int remaining);
    public abstract boolean onEnumerationResult(
Loading