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

Commit 7f60baaa authored by Curtis Belmonte's avatar Curtis Belmonte
Browse files

Log new auth-related framework atoms for Android 12

Adds logging to the framework for new authentication and biometric atoms
introduced as part of ag/13856328.

Test: Manually trigger each case and verify log statements are called.

Bug: 185136248
Change-Id: I2783e4738eac36f34b073107afbd67ce1df4b0fb
parent 8b7253d3
Loading
Loading
Loading
Loading
+22 −5
Original line number Original line Diff line number Diff line
@@ -21,6 +21,8 @@ import static android.Manifest.permission.USE_BIOMETRIC;
import static android.Manifest.permission.USE_BIOMETRIC_INTERNAL;
import static android.Manifest.permission.USE_BIOMETRIC_INTERNAL;
import static android.Manifest.permission.WRITE_DEVICE_CONFIG;
import static android.Manifest.permission.WRITE_DEVICE_CONFIG;


import static com.android.internal.util.FrameworkStatsLog.AUTH_DEPRECATED_APIUSED__DEPRECATED_API__API_BIOMETRIC_MANAGER_CAN_AUTHENTICATE;

import android.annotation.IntDef;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
@@ -34,6 +36,8 @@ import android.os.RemoteException;
import android.security.keystore.KeyProperties;
import android.security.keystore.KeyProperties;
import android.util.Slog;
import android.util.Slog;


import com.android.internal.util.FrameworkStatsLog;

import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.ArrayList;
@@ -271,7 +275,17 @@ public class BiometricManager {
    @RequiresPermission(USE_BIOMETRIC)
    @RequiresPermission(USE_BIOMETRIC)
    @BiometricError
    @BiometricError
    public int canAuthenticate() {
    public int canAuthenticate() {
        return canAuthenticate(Authenticators.BIOMETRIC_WEAK);
        @BiometricError final int result = canAuthenticate(mContext.getUserId(),
                Authenticators.BIOMETRIC_WEAK);

        FrameworkStatsLog.write(FrameworkStatsLog.AUTH_MANAGER_CAN_AUTHENTICATE_INVOKED,
                false /* isAllowedAuthenticatorsSet */, Authenticators.EMPTY_SET, result);
        FrameworkStatsLog.write(FrameworkStatsLog.AUTH_DEPRECATED_API_USED,
                AUTH_DEPRECATED_APIUSED__DEPRECATED_API__API_BIOMETRIC_MANAGER_CAN_AUTHENTICATE,
                mContext.getApplicationInfo().uid,
                mContext.getApplicationInfo().targetSdkVersion);

        return result;
    }
    }


    /**
    /**
@@ -302,7 +316,12 @@ public class BiometricManager {
    @RequiresPermission(USE_BIOMETRIC)
    @RequiresPermission(USE_BIOMETRIC)
    @BiometricError
    @BiometricError
    public int canAuthenticate(@Authenticators.Types int authenticators) {
    public int canAuthenticate(@Authenticators.Types int authenticators) {
        return canAuthenticate(mContext.getUserId(), authenticators);
        @BiometricError final int result = canAuthenticate(mContext.getUserId(), authenticators);

        FrameworkStatsLog.write(FrameworkStatsLog.AUTH_MANAGER_CAN_AUTHENTICATE_INVOKED,
                true /* isAllowedAuthenticatorsSet */, authenticators, result);

        return result;
    }
    }


    /**
    /**
@@ -310,9 +329,7 @@ public class BiometricManager {
     */
     */
    @RequiresPermission(USE_BIOMETRIC_INTERNAL)
    @RequiresPermission(USE_BIOMETRIC_INTERNAL)
    @BiometricError
    @BiometricError
    public int canAuthenticate(
    public int canAuthenticate(int userId, @Authenticators.Types int authenticators) {
            int userId, @Authenticators.Types int authenticators) {

        if (mService != null) {
        if (mService != null) {
            try {
            try {
                final String opPackageName = mContext.getOpPackageName();
                final String opPackageName = mContext.getOpPackageName();
+22 −1
Original line number Original line Diff line number Diff line
@@ -43,6 +43,7 @@ import android.text.TextUtils;
import android.util.Log;
import android.util.Log;


import com.android.internal.R;
import com.android.internal.R;
import com.android.internal.util.FrameworkStatsLog;


import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
@@ -422,7 +423,7 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
            final boolean deviceCredentialAllowed = mPromptInfo.isDeviceCredentialAllowed();
            final boolean deviceCredentialAllowed = mPromptInfo.isDeviceCredentialAllowed();
            final @Authenticators.Types int authenticators = mPromptInfo.getAuthenticators();
            final @Authenticators.Types int authenticators = mPromptInfo.getAuthenticators();
            final boolean willShowDeviceCredentialButton = deviceCredentialAllowed
            final boolean willShowDeviceCredentialButton = deviceCredentialAllowed
                    || (authenticators & Authenticators.DEVICE_CREDENTIAL) != 0;
                    || isCredentialAllowed(authenticators);


            if (TextUtils.isEmpty(title) && !useDefaultTitle) {
            if (TextUtils.isEmpty(title) && !useDefaultTitle) {
                throw new IllegalArgumentException("Title must be set and non-empty");
                throw new IllegalArgumentException("Title must be set and non-empty");
@@ -916,6 +917,14 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
            @NonNull CancellationSignal cancel,
            @NonNull CancellationSignal cancel,
            @NonNull @CallbackExecutor Executor executor,
            @NonNull @CallbackExecutor Executor executor,
            @NonNull AuthenticationCallback callback) {
            @NonNull AuthenticationCallback callback) {

        FrameworkStatsLog.write(FrameworkStatsLog.AUTH_PROMPT_AUTHENTICATE_INVOKED,
                true /* isCrypto */,
                mPromptInfo.isConfirmationRequested(),
                mPromptInfo.isDeviceCredentialAllowed(),
                mPromptInfo.getAuthenticators() != Authenticators.EMPTY_SET,
                mPromptInfo.getAuthenticators());

        if (crypto == null) {
        if (crypto == null) {
            throw new IllegalArgumentException("Must supply a crypto object");
            throw new IllegalArgumentException("Must supply a crypto object");
        }
        }
@@ -973,6 +982,14 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
    public void authenticate(@NonNull CancellationSignal cancel,
    public void authenticate(@NonNull CancellationSignal cancel,
            @NonNull @CallbackExecutor Executor executor,
            @NonNull @CallbackExecutor Executor executor,
            @NonNull AuthenticationCallback callback) {
            @NonNull AuthenticationCallback callback) {

        FrameworkStatsLog.write(FrameworkStatsLog.AUTH_PROMPT_AUTHENTICATE_INVOKED,
                false /* isCrypto */,
                mPromptInfo.isConfirmationRequested(),
                mPromptInfo.isDeviceCredentialAllowed(),
                mPromptInfo.getAuthenticators() != Authenticators.EMPTY_SET,
                mPromptInfo.getAuthenticators());

        if (cancel == null) {
        if (cancel == null) {
            throw new IllegalArgumentException("Must supply a cancellation signal");
            throw new IllegalArgumentException("Must supply a cancellation signal");
        }
        }
@@ -1058,4 +1075,8 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
                    mContext.getString(R.string.biometric_error_hw_unavailable)));
                    mContext.getString(R.string.biometric_error_hw_unavailable)));
        }
        }
    }
    }

    private static boolean isCredentialAllowed(@Authenticators.Types int allowedAuthenticators) {
        return (allowedAuthenticators & Authenticators.DEVICE_CREDENTIAL) != 0;
    }
}
}
+21 −0
Original line number Original line Diff line number Diff line
@@ -24,6 +24,10 @@ import static android.Manifest.permission.USE_BIOMETRIC;
import static android.Manifest.permission.USE_BIOMETRIC_INTERNAL;
import static android.Manifest.permission.USE_BIOMETRIC_INTERNAL;
import static android.Manifest.permission.USE_FINGERPRINT;
import static android.Manifest.permission.USE_FINGERPRINT;


import static com.android.internal.util.FrameworkStatsLog.AUTH_DEPRECATED_APIUSED__DEPRECATED_API__API_FINGERPRINT_MANAGER_AUTHENTICATE;
import static com.android.internal.util.FrameworkStatsLog.AUTH_DEPRECATED_APIUSED__DEPRECATED_API__API_FINGERPRINT_MANAGER_HAS_ENROLLED_FINGERPRINTS;
import static com.android.internal.util.FrameworkStatsLog.AUTH_DEPRECATED_APIUSED__DEPRECATED_API__API_FINGERPRINT_MANAGER_IS_HARDWARE_DETECTED;

import android.annotation.IntDef;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
@@ -56,6 +60,8 @@ import android.security.identity.IdentityCredential;
import android.util.Slog;
import android.util.Slog;
import android.view.Surface;
import android.view.Surface;


import com.android.internal.util.FrameworkStatsLog;

import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
import java.security.Signature;
import java.security.Signature;
@@ -534,6 +540,11 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
    public void authenticate(@Nullable CryptoObject crypto, @Nullable CancellationSignal cancel,
    public void authenticate(@Nullable CryptoObject crypto, @Nullable CancellationSignal cancel,
            @NonNull AuthenticationCallback callback, Handler handler, int sensorId, int userId) {
            @NonNull AuthenticationCallback callback, Handler handler, int sensorId, int userId) {


        FrameworkStatsLog.write(FrameworkStatsLog.AUTH_DEPRECATED_API_USED,
                AUTH_DEPRECATED_APIUSED__DEPRECATED_API__API_FINGERPRINT_MANAGER_AUTHENTICATE,
                mContext.getApplicationInfo().uid,
                mContext.getApplicationInfo().targetSdkVersion);

        if (callback == null) {
        if (callback == null) {
            throw new IllegalArgumentException("Must supply an authentication callback");
            throw new IllegalArgumentException("Must supply an authentication callback");
        }
        }
@@ -910,6 +921,11 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
    @Deprecated
    @Deprecated
    @RequiresPermission(USE_FINGERPRINT)
    @RequiresPermission(USE_FINGERPRINT)
    public boolean hasEnrolledFingerprints() {
    public boolean hasEnrolledFingerprints() {
        FrameworkStatsLog.write(FrameworkStatsLog.AUTH_DEPRECATED_API_USED,
                AUTH_DEPRECATED_APIUSED__DEPRECATED_API__API_FINGERPRINT_MANAGER_HAS_ENROLLED_FINGERPRINTS,
                mContext.getApplicationInfo().uid,
                mContext.getApplicationInfo().targetSdkVersion);

        return hasEnrolledFingerprints(UserHandle.myUserId());
        return hasEnrolledFingerprints(UserHandle.myUserId());
    }
    }


@@ -938,6 +954,11 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
    @Deprecated
    @Deprecated
    @RequiresPermission(USE_FINGERPRINT)
    @RequiresPermission(USE_FINGERPRINT)
    public boolean isHardwareDetected() {
    public boolean isHardwareDetected() {
        FrameworkStatsLog.write(FrameworkStatsLog.AUTH_DEPRECATED_API_USED,
                AUTH_DEPRECATED_APIUSED__DEPRECATED_API__API_FINGERPRINT_MANAGER_IS_HARDWARE_DETECTED,
                mContext.getApplicationInfo().uid,
                mContext.getApplicationInfo().targetSdkVersion);

        if (mService != null) {
        if (mService != null) {
            try {
            try {
                return mService.isHardwareDetectedDeprecated(mContext.getOpPackageName());
                return mService.isHardwareDetectedDeprecated(mContext.getOpPackageName());