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
This commit is contained in:
Curtis Belmonte
2021-04-20 16:48:54 -07:00
parent 8b7253d316
commit 7f60baaadb
3 changed files with 65 additions and 6 deletions

View File

@@ -21,6 +21,8 @@ import static android.Manifest.permission.USE_BIOMETRIC;
import static android.Manifest.permission.USE_BIOMETRIC_INTERNAL;
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.NonNull;
import android.annotation.Nullable;
@@ -34,6 +36,8 @@ import android.os.RemoteException;
import android.security.keystore.KeyProperties;
import android.util.Slog;
import com.android.internal.util.FrameworkStatsLog;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
@@ -271,7 +275,17 @@ public class BiometricManager {
@RequiresPermission(USE_BIOMETRIC)
@BiometricError
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)
@BiometricError
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)
@BiometricError
public int canAuthenticate(
int userId, @Authenticators.Types int authenticators) {
public int canAuthenticate(int userId, @Authenticators.Types int authenticators) {
if (mService != null) {
try {
final String opPackageName = mContext.getOpPackageName();

View File

@@ -43,6 +43,7 @@ import android.text.TextUtils;
import android.util.Log;
import com.android.internal.R;
import com.android.internal.util.FrameworkStatsLog;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -422,7 +423,7 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
final boolean deviceCredentialAllowed = mPromptInfo.isDeviceCredentialAllowed();
final @Authenticators.Types int authenticators = mPromptInfo.getAuthenticators();
final boolean willShowDeviceCredentialButton = deviceCredentialAllowed
|| (authenticators & Authenticators.DEVICE_CREDENTIAL) != 0;
|| isCredentialAllowed(authenticators);
if (TextUtils.isEmpty(title) && !useDefaultTitle) {
throw new IllegalArgumentException("Title must be set and non-empty");
@@ -916,6 +917,14 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
@NonNull CancellationSignal cancel,
@NonNull @CallbackExecutor Executor executor,
@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) {
throw new IllegalArgumentException("Must supply a crypto object");
}
@@ -973,6 +982,14 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
public void authenticate(@NonNull CancellationSignal cancel,
@NonNull @CallbackExecutor Executor executor,
@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) {
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)));
}
}
private static boolean isCredentialAllowed(@Authenticators.Types int allowedAuthenticators) {
return (allowedAuthenticators & Authenticators.DEVICE_CREDENTIAL) != 0;
}
}

View File

@@ -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_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.NonNull;
import android.annotation.Nullable;
@@ -56,6 +60,8 @@ import android.security.identity.IdentityCredential;
import android.util.Slog;
import android.view.Surface;
import com.android.internal.util.FrameworkStatsLog;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.security.Signature;
@@ -534,6 +540,11 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
public void authenticate(@Nullable CryptoObject crypto, @Nullable CancellationSignal cancel,
@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) {
throw new IllegalArgumentException("Must supply an authentication callback");
}
@@ -910,6 +921,11 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
@Deprecated
@RequiresPermission(USE_FINGERPRINT)
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());
}
@@ -938,6 +954,11 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
@Deprecated
@RequiresPermission(USE_FINGERPRINT)
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) {
try {
return mService.isHardwareDetectedDeprecated(mContext.getOpPackageName());