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

Commit a0758358 authored by Joshua McCloskey's avatar Joshua McCloskey Committed by Joshua Mccloskey
Browse files

Use vendor extension for fp auth.

Test: Manually verified extension blob can be passed through the
framework.
Fixes: 286585912

Change-Id: Ie865b172f878aa5c8efb60029fca1a6fc4916621
parent 13073aed
Loading
Loading
Loading
Loading
+68 −8
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.hardware.fingerprint.FingerprintManager.SENSOR_ID_ANY;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.hardware.biometrics.AuthenticateOptions;
import android.hardware.biometrics.common.AuthenticateReason;
import android.os.Parcelable;

import com.android.internal.util.DataClass;
@@ -85,7 +86,16 @@ public final class FingerprintAuthenticateOptions implements AuthenticateOptions
        return null;
    }


    /**
     * The Vendor extension, if any.
     *
     * This option may be present when a vendor would like to send additional information for each
     * auth attempt.
     */
    @Nullable private AuthenticateReason.Vendor mVendorReason;
    private static AuthenticateReason.Vendor defaultVendorReason() {
        return null;
    }

    // Code below generated by codegen v1.0.23.
    //
@@ -107,7 +117,8 @@ public final class FingerprintAuthenticateOptions implements AuthenticateOptions
            boolean ignoreEnrollmentState,
            @AuthenticateOptions.DisplayState int displayState,
            @NonNull String opPackageName,
            @Nullable String attributionTag) {
            @Nullable String attributionTag,
            @Nullable AuthenticateReason.Vendor vendorReason) {
        this.mUserId = userId;
        this.mSensorId = sensorId;
        this.mIgnoreEnrollmentState = ignoreEnrollmentState;
@@ -118,6 +129,7 @@ public final class FingerprintAuthenticateOptions implements AuthenticateOptions
        com.android.internal.util.AnnotationValidations.validate(
                NonNull.class, null, mOpPackageName);
        this.mAttributionTag = attributionTag;
        this.mVendorReason = vendorReason;

        // onConstructed(); // You can define this method to get a callback
    }
@@ -175,6 +187,17 @@ public final class FingerprintAuthenticateOptions implements AuthenticateOptions
        return mAttributionTag;
    }

    /**
     * The Vendor extension, if any.
     *
     * This option may be present when a vendor would like to send additional information for each
     * auth attempt.
     */
    @DataClass.Generated.Member
    public @Nullable AuthenticateReason.Vendor getVendorReason() {
        return mVendorReason;
    }

    /**
     * The sensor id for this operation.
     */
@@ -209,6 +232,18 @@ public final class FingerprintAuthenticateOptions implements AuthenticateOptions
        return this;
    }

    /**
     * The Vendor extension, if any.
     *
     * This option may be present when a vendor would like to send additional information for each
     * auth attempt.
     */
    @DataClass.Generated.Member
    public @NonNull FingerprintAuthenticateOptions setVendorReason(@NonNull AuthenticateReason.Vendor value) {
        mVendorReason = value;
        return this;
    }

    @Override
    @DataClass.Generated.Member
    public boolean equals(@Nullable Object o) {
@@ -227,7 +262,8 @@ public final class FingerprintAuthenticateOptions implements AuthenticateOptions
                && mIgnoreEnrollmentState == that.mIgnoreEnrollmentState
                && mDisplayState == that.mDisplayState
                && java.util.Objects.equals(mOpPackageName, that.mOpPackageName)
                && java.util.Objects.equals(mAttributionTag, that.mAttributionTag);
                && java.util.Objects.equals(mAttributionTag, that.mAttributionTag)
                && java.util.Objects.equals(mVendorReason, that.mVendorReason);
    }

    @Override
@@ -243,6 +279,7 @@ public final class FingerprintAuthenticateOptions implements AuthenticateOptions
        _hash = 31 * _hash + mDisplayState;
        _hash = 31 * _hash + java.util.Objects.hashCode(mOpPackageName);
        _hash = 31 * _hash + java.util.Objects.hashCode(mAttributionTag);
        _hash = 31 * _hash + java.util.Objects.hashCode(mVendorReason);
        return _hash;
    }

@@ -255,12 +292,14 @@ public final class FingerprintAuthenticateOptions implements AuthenticateOptions
        byte flg = 0;
        if (mIgnoreEnrollmentState) flg |= 0x4;
        if (mAttributionTag != null) flg |= 0x20;
        if (mVendorReason != null) flg |= 0x40;
        dest.writeByte(flg);
        dest.writeInt(mUserId);
        dest.writeInt(mSensorId);
        dest.writeInt(mDisplayState);
        dest.writeString(mOpPackageName);
        if (mAttributionTag != null) dest.writeString(mAttributionTag);
        if (mVendorReason != null) dest.writeTypedObject(mVendorReason, flags);
    }

    @Override
@@ -281,6 +320,7 @@ public final class FingerprintAuthenticateOptions implements AuthenticateOptions
        int displayState = in.readInt();
        String opPackageName = in.readString();
        String attributionTag = (flg & 0x20) == 0 ? null : in.readString();
        AuthenticateReason.Vendor vendorReason = (flg & 0x40) == 0 ? null : (AuthenticateReason.Vendor) in.readTypedObject(AuthenticateReason.Vendor.CREATOR);

        this.mUserId = userId;
        this.mSensorId = sensorId;
@@ -292,6 +332,7 @@ public final class FingerprintAuthenticateOptions implements AuthenticateOptions
        com.android.internal.util.AnnotationValidations.validate(
                NonNull.class, null, mOpPackageName);
        this.mAttributionTag = attributionTag;
        this.mVendorReason = vendorReason;

        // onConstructed(); // You can define this method to get a callback
    }
@@ -323,6 +364,7 @@ public final class FingerprintAuthenticateOptions implements AuthenticateOptions
        private @AuthenticateOptions.DisplayState int mDisplayState;
        private @NonNull String mOpPackageName;
        private @Nullable String mAttributionTag;
        private @Nullable AuthenticateReason.Vendor mVendorReason;

        private long mBuilderFieldsSet = 0L;

@@ -400,10 +442,24 @@ public final class FingerprintAuthenticateOptions implements AuthenticateOptions
            return this;
        }

        /**
         * The Vendor extension, if any.
         *
         * This option may be present when a vendor would like to send additional information for each
         * auth attempt.
         */
        @DataClass.Generated.Member
        public @NonNull Builder setVendorReason(@NonNull AuthenticateReason.Vendor value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x40;
            mVendorReason = value;
            return this;
        }

        /** Builds the instance. This builder should not be touched after calling this! */
        public @NonNull FingerprintAuthenticateOptions build() {
            checkNotUsed();
            mBuilderFieldsSet |= 0x40; // Mark builder used
            mBuilderFieldsSet |= 0x80; // Mark builder used

            if ((mBuilderFieldsSet & 0x1) == 0) {
                mUserId = defaultUserId();
@@ -423,18 +479,22 @@ public final class FingerprintAuthenticateOptions implements AuthenticateOptions
            if ((mBuilderFieldsSet & 0x20) == 0) {
                mAttributionTag = defaultAttributionTag();
            }
            if ((mBuilderFieldsSet & 0x40) == 0) {
                mVendorReason = defaultVendorReason();
            }
            FingerprintAuthenticateOptions o = new FingerprintAuthenticateOptions(
                    mUserId,
                    mSensorId,
                    mIgnoreEnrollmentState,
                    mDisplayState,
                    mOpPackageName,
                    mAttributionTag);
                    mAttributionTag,
                    mVendorReason);
            return o;
        }

        private void checkNotUsed() {
            if ((mBuilderFieldsSet & 0x40) != 0) {
            if ((mBuilderFieldsSet & 0x80) != 0) {
                throw new IllegalStateException(
                        "This Builder should not be reused. Use a new Builder instance instead");
            }
@@ -442,10 +502,10 @@ public final class FingerprintAuthenticateOptions implements AuthenticateOptions
    }

    @DataClass.Generated(
            time = 1677119626721L,
            time = 1689703591032L,
            codegenVersion = "1.0.23",
            sourceFile = "frameworks/base/core/java/android/hardware/fingerprint/FingerprintAuthenticateOptions.java",
            inputSignatures = "private final  int mUserId\nprivate  int mSensorId\nprivate final  boolean mIgnoreEnrollmentState\nprivate final @android.hardware.biometrics.AuthenticateOptions.DisplayState int mDisplayState\nprivate @android.annotation.NonNull java.lang.String mOpPackageName\nprivate @android.annotation.Nullable java.lang.String mAttributionTag\nprivate static  int defaultUserId()\nprivate static  int defaultSensorId()\nprivate static  boolean defaultIgnoreEnrollmentState()\nprivate static  int defaultDisplayState()\nprivate static  java.lang.String defaultOpPackageName()\nprivate static  java.lang.String defaultAttributionTag()\nclass FingerprintAuthenticateOptions extends java.lang.Object implements [android.hardware.biometrics.AuthenticateOptions, android.os.Parcelable]\n@com.android.internal.util.DataClass(genParcelable=true, genAidl=true, genBuilder=true, genSetters=true, genEqualsHashCode=true)")
            inputSignatures = "private final  int mUserId\nprivate  int mSensorId\nprivate final  boolean mIgnoreEnrollmentState\nprivate final @android.hardware.biometrics.AuthenticateOptions.DisplayState int mDisplayState\nprivate @android.annotation.NonNull java.lang.String mOpPackageName\nprivate @android.annotation.Nullable java.lang.String mAttributionTag\nprivate @android.annotation.Nullable android.hardware.biometrics.common.AuthenticateReason.Vendor mVendorReason\nprivate static  int defaultUserId()\nprivate static  int defaultSensorId()\nprivate static  boolean defaultIgnoreEnrollmentState()\nprivate static  int defaultDisplayState()\nprivate static  java.lang.String defaultOpPackageName()\nprivate static  java.lang.String defaultAttributionTag()\nprivate static  android.hardware.biometrics.common.AuthenticateReason.Vendor defaultVendorReason()\nclass FingerprintAuthenticateOptions extends java.lang.Object implements [android.hardware.biometrics.AuthenticateOptions, android.os.Parcelable]\n@com.android.internal.util.DataClass(genParcelable=true, genAidl=true, genBuilder=true, genSetters=true, genEqualsHashCode=true)")
    @Deprecated
    private void __metadata() {}

+0 −3
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ data class KeyguardFingerprintListenModel(
    var keyguardIsVisible: Boolean = false,
    var keyguardOccluded: Boolean = false,
    var occludingAppRequestingFp: Boolean = false,
    var shouldListenSfpsState: Boolean = false,
    var shouldListenForFingerprintAssistant: Boolean = false,
    var strongerAuthRequired: Boolean = false,
    var switchingUser: Boolean = false,
@@ -74,7 +73,6 @@ data class KeyguardFingerprintListenModel(
            keyguardIsVisible.toString(),
            keyguardOccluded.toString(),
            occludingAppRequestingFp.toString(),
            shouldListenSfpsState.toString(),
            shouldListenForFingerprintAssistant.toString(),
            strongerAuthRequired.toString(),
            switchingUser.toString(),
@@ -115,7 +113,6 @@ data class KeyguardFingerprintListenModel(
                keyguardIsVisible = model.keyguardIsVisible
                keyguardOccluded = model.keyguardOccluded
                occludingAppRequestingFp = model.occludingAppRequestingFp
                shouldListenSfpsState = model.shouldListenSfpsState
                shouldListenForFingerprintAssistant = model.shouldListenForFingerprintAssistant
                strongerAuthRequired = model.strongerAuthRequired
                switchingUser = model.switchingUser
+7 −19
Original line number Diff line number Diff line
@@ -3128,18 +3128,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                && !strongerAuthRequired
                && userDoesNotHaveTrust);

        boolean shouldListenSideFpsState = true;
        if (isSideFps) {
            final boolean interactiveToAuthEnabled =
                    mFingerprintInteractiveToAuthProvider != null &&
                            mFingerprintInteractiveToAuthProvider.isEnabled(getCurrentUser());
            shouldListenSideFpsState =
                    interactiveToAuthEnabled ? isDeviceInteractive() && !mGoingToSleep : true;
        }

        boolean shouldListen = shouldListenKeyguardState && shouldListenUserState
                && shouldListenBouncerState && shouldListenUdfpsState
                && shouldListenSideFpsState;
                && shouldListenBouncerState && shouldListenUdfpsState;
        logListenerModelData(
                new KeyguardFingerprintListenModel(
                    System.currentTimeMillis(),
@@ -3160,7 +3151,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                    isKeyguardVisible(),
                    mKeyguardOccluded,
                    mOccludingAppRequestingFp,
                    shouldListenSideFpsState,
                    shouldListenForFingerprintAssistant,
                    strongerAuthRequired,
                    mSwitchingUser,
@@ -3314,6 +3304,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                        mFingerprintDetectionCallback,
                        new FingerprintAuthenticateOptions.Builder()
                                .setUserId(userId)
                                .setVendorReason(
                                        mFingerprintInteractiveToAuthProvider.getVendorExtension(
                                                getCurrentUser()))
                                .build());
            } else {
                mLogger.v("startListeningForFingerprint");
@@ -3322,6 +3315,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                        null /* handler */,
                        new FingerprintAuthenticateOptions.Builder()
                                .setUserId(userId)
                                .setVendorReason(
                                        mFingerprintInteractiveToAuthProvider.getVendorExtension(
                                                getCurrentUser()))
                                .build()
                );
            }
@@ -4497,14 +4493,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
            } else if (isSfpsSupported()) {
                pw.println("        sfpsEnrolled=" + isSfpsEnrolled());
                pw.println("        shouldListenForSfps=" + shouldListenForFingerprint(false));
                if (isSfpsEnrolled()) {
                    final boolean interactiveToAuthEnabled =
                                    mFingerprintInteractiveToAuthProvider != null &&
                                            mFingerprintInteractiveToAuthProvider
                                            .isEnabled(getCurrentUser());
                    pw.println("        interactiveToAuthEnabled="
                            + interactiveToAuthEnabled);
                }
            }
            new DumpsysTableLogger(
                    "KeyguardFingerprintListen",
+9 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.biometrics;

import android.hardware.biometrics.common.AuthenticateReason;

/** Provides the status of the interactive to auth feature. */
public interface FingerprintInteractiveToAuthProvider {
    /**
@@ -24,4 +26,11 @@ public interface FingerprintInteractiveToAuthProvider {
     * @return true if the InteractiveToAuthFeature is enabled, false if disabled.
     */
    boolean isEnabled(int userId);

    /**
     *
     * @param userId the user Id.
     * @return Vendor extension if needed for authentication.
     */
    AuthenticateReason.Vendor getVendorExtension(int userId);
}
+0 −65
Original line number Diff line number Diff line
@@ -1693,71 +1693,6 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
        assertThat(mKeyguardUpdateMonitor.shouldListenForFingerprint(true)).isEqualTo(true);
    }

    @Test
    public void startsListeningForSfps_whenKeyguardIsVisible_ifRequireInteractiveToAuthEnabled()
            throws RemoteException {
        // SFPS supported and enrolled
        when(mAuthController.isSfpsSupported()).thenReturn(true);
        when(mAuthController.isSfpsEnrolled(anyInt())).thenReturn(true);

        // WHEN require interactive to auth is disabled, and keyguard is not awake
        when(mInteractiveToAuthProvider.isEnabled(anyInt())).thenReturn(false);

        // Preconditions for sfps auth to run
        keyguardNotGoingAway();
        currentUserIsSystem();
        currentUserDoesNotHaveTrust();
        biometricsNotDisabledThroughDevicePolicyManager();
        biometricsEnabledForCurrentUser();
        userNotCurrentlySwitching();

        statusBarShadeIsLocked();
        mTestableLooper.processAllMessages();

        // THEN we should listen for sfps when screen off, because require screen on is disabled
        assertThat(mKeyguardUpdateMonitor.shouldListenForFingerprint(false)).isTrue();

        // WHEN require interactive to auth is enabled, and keyguard is not awake
        when(mInteractiveToAuthProvider.isEnabled(anyInt())).thenReturn(true);

        // THEN we shouldn't listen for sfps when screen off, because require screen on is enabled
        assertThat(mKeyguardUpdateMonitor.shouldListenForFingerprint(false)).isFalse();

        // Device now awake & keyguard is now interactive
        deviceNotGoingToSleep();
        deviceIsInteractive();
        keyguardIsVisible();

        // THEN we should listen for sfps when screen on, and require screen on is enabled
        assertThat(mKeyguardUpdateMonitor.shouldListenForFingerprint(false)).isTrue();
    }

    @Test
    public void notListeningForSfps_whenGoingToSleep_ifRequireInteractiveToAuthEnabled()
            throws RemoteException {
        // GIVEN SFPS supported and enrolled
        when(mAuthController.isSfpsSupported()).thenReturn(true);
        when(mAuthController.isSfpsEnrolled(anyInt())).thenReturn(true);

        // GIVEN Preconditions for sfps auth to run
        keyguardNotGoingAway();
        currentUserIsSystem();
        currentUserDoesNotHaveTrust();
        biometricsNotDisabledThroughDevicePolicyManager();
        biometricsEnabledForCurrentUser();
        userNotCurrentlySwitching();
        statusBarShadeIsLocked();

        // WHEN require interactive to auth is enabled & keyguard is going to sleep
        when(mInteractiveToAuthProvider.isEnabled(anyInt())).thenReturn(true);
        deviceGoingToSleep();

        mTestableLooper.processAllMessages();

        // THEN we should NOT listen for sfps because device is going to sleep
        assertThat(mKeyguardUpdateMonitor.shouldListenForFingerprint(false)).isFalse();
    }

    @Test
    public void listeningForSfps_whenGoingToSleep_ifRequireInteractiveToAuthDisabled()
            throws RemoteException {
Loading