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

Commit a9b6a2d4 authored by Diya Bera's avatar Diya Bera
Browse files

Add Identity Check Test API

The API is BiometricManager#setIsIdentityCheckActive(IdentityCheckStatus)
and is hidden. It is for testing purpose ONLY.

Flag: android.hardware.biometrics.identity_check_test_api
Test: atest BiometricSimpleTests
Bug: 347123256

Change-Id: I5f5d321656116c47fa0ae820029cfa3d31ddb62a
parent 219b071f
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -1570,6 +1570,7 @@ package android.hardware.biometrics {
    method @NonNull @RequiresPermission(android.Manifest.permission.TEST_BIOMETRIC) public android.hardware.biometrics.BiometricTestSession createTestSession(int);
    method @NonNull @RequiresPermission(android.Manifest.permission.TEST_BIOMETRIC) public java.util.List<android.hardware.biometrics.SensorProperties> getSensorProperties();
    method @NonNull @RequiresPermission(android.Manifest.permission.TEST_BIOMETRIC) public String getUiPackage();
    method @FlaggedApi("android.hardware.biometrics.identity_check_test_api") @RequiresPermission(android.Manifest.permission.TEST_BIOMETRIC) public void setIdentityCheckTestStatus(@NonNull android.hardware.biometrics.IdentityCheckStatus);
  }

  public class BiometricPrompt {
@@ -1594,6 +1595,21 @@ package android.hardware.biometrics {
    method @RequiresPermission(android.Manifest.permission.TEST_BIOMETRIC) public void startEnroll(int);
  }

  @FlaggedApi("android.hardware.biometrics.identity_check_test_api") public final class IdentityCheckStatus implements android.os.Parcelable {
    method public int describeContents();
    method public boolean isIdentityCheckActive();
    method public boolean isIdentityCheckValueForTestAvailable();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.hardware.biometrics.IdentityCheckStatus> CREATOR;
  }

  public static final class IdentityCheckStatus.Builder {
    ctor public IdentityCheckStatus.Builder();
    method @NonNull public android.hardware.biometrics.IdentityCheckStatus build();
    method @NonNull public android.hardware.biometrics.IdentityCheckStatus.Builder setIdentityCheckActive(boolean);
    method @NonNull public android.hardware.biometrics.IdentityCheckStatus.Builder setIdentityCheckValueForTestAvailable(boolean);
  }

  public class SensorProperties {
    method @NonNull public java.util.List<android.hardware.biometrics.SensorProperties.ComponentInfo> getComponentInfo();
    method public int getSensorId();
+18 −0
Original line number Diff line number Diff line
@@ -485,6 +485,24 @@ public class BiometricManager {
        }
    }

    /**
     * Sets Identity Check status for testing purpose.
     * @hide
     */
    @TestApi
    @RequiresPermission(TEST_BIOMETRIC)
    @FlaggedApi(Flags.FLAG_IDENTITY_CHECK_TEST_API)
    public void setIdentityCheckTestStatus(@NonNull IdentityCheckStatus identityCheckStatus) {
        try {
            Slog.d(TAG, "Identity Check status being set to "
                    + identityCheckStatus.isIdentityCheckActive()
                    + ". For test: " + identityCheckStatus.isIdentityCheckValueForTestAvailable());
            mService.setIdentityCheckTestStatus(identityCheckStatus);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Retrieves the package where BiometricPrompt's UI is implemented.
     * @hide
+7 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ public class BiometricTestSession implements AutoCloseable {
    }

    private final int mSensorId;
    private final BiometricManager mBiometricManager;
    private final List<ITestSession> mTestSessionsForAllSensors = new ArrayList<>();
    private ITestSession mTestSession;

@@ -99,6 +100,7 @@ public class BiometricTestSession implements AutoCloseable {
    public BiometricTestSession(@NonNull Context context, List<SensorProperties> sensors,
            int sensorId, @NonNull TestSessionProvider testSessionProvider) throws RemoteException {
        mSensorId = sensorId;
        mBiometricManager = context.getSystemService(BiometricManager.class);
        // When any of the sensors should create the test session, all the other sensors should
        // set test hal enabled too.
        for (SensorProperties sensor : sensors) {
@@ -286,6 +288,11 @@ public class BiometricTestSession implements AutoCloseable {
                    + mUsersCleaningUp.size());
        }

        //Reset Identity Check values when the session is closed.
        mBiometricManager.setIdentityCheckTestStatus(new IdentityCheckStatus.Builder()
                .setIdentityCheckActive(false)
                .setIdentityCheckValueForTestAvailable(false)
                .build());
        // Disable the test HAL after the sensor becomes idle.
        setTestHalEnabled(false);
    }
+5 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.hardware.biometrics;
import android.hardware.biometrics.AuthenticationStateListener;
import android.hardware.biometrics.IBiometricEnabledOnKeyguardCallback;
import android.hardware.biometrics.IBiometricServiceReceiver;
import android.hardware.biometrics.IdentityCheckStatus;
import android.hardware.biometrics.IInvalidationCallback;
import android.hardware.biometrics.ITestSession;
import android.hardware.biometrics.ITestSessionCallback;
@@ -38,6 +39,10 @@ interface IAuthService {
    @EnforcePermission("TEST_BIOMETRIC")
    ITestSession createTestSession(int sensorId, ITestSessionCallback callback, String opPackageName);

    //Sets Identity Check status for testing purpose
    @EnforcePermission("TEST_BIOMETRIC")
    void setIdentityCheckTestStatus(in IdentityCheckStatus identityCheckStatus);

    // Retrieve static sensor properties for all biometric sensors
    @EnforcePermission("TEST_BIOMETRIC")
    List<SensorPropertiesInternal> getSensorProperties(String opPackageName);
+5 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.hardware.biometrics;
import android.hardware.biometrics.IBiometricEnabledOnKeyguardCallback;
import android.hardware.biometrics.IBiometricServiceReceiver;
import android.hardware.biometrics.IBiometricAuthenticator;
import android.hardware.biometrics.IdentityCheckStatus;
import android.hardware.biometrics.IInvalidationCallback;
import android.hardware.biometrics.ITestSession;
import android.hardware.biometrics.ITestSessionCallback;
@@ -34,6 +35,10 @@ interface IBiometricService {
    @EnforcePermission("USE_BIOMETRIC_INTERNAL")
    ITestSession createTestSession(int sensorId, ITestSessionCallback callback, String opPackageName);

    //Sets Identity Check status for testing purpose
    @EnforcePermission("USE_BIOMETRIC_INTERNAL")
    void setIdentityCheckTestStatus(in IdentityCheckStatus identityCheckStatus);

    // Retrieve static sensor properties for all biometric sensors
    @EnforcePermission("USE_BIOMETRIC_INTERNAL")
    List<SensorPropertiesInternal> getSensorProperties(String opPackageName);
Loading