Add mandatory biometric prompt to platform surfaces (1/N)
1. Face settings 2. Fingerprint settings 3. Change device credential Flag: android.hardware.biometrics.Flags.MANDATORY_BIOMETRICS Bug: 339910718 Test: atest UtilsTest Change-Id: I69778d1733ea9fb312e7c26ae0fa23b6008dde5d
This commit is contained in:
@@ -24,6 +24,9 @@ import static android.os.UserManager.USER_TYPE_PROFILE_PRIVATE;
|
||||
import static android.text.format.DateUtils.FORMAT_ABBREV_MONTH;
|
||||
import static android.text.format.DateUtils.FORMAT_SHOW_DATE;
|
||||
|
||||
import static com.android.settings.password.ConfirmDeviceCredentialActivity.BIOMETRIC_PROMPT_AUTHENTICATORS;
|
||||
import static com.android.settings.password.ConfirmDeviceCredentialActivity.BIOMETRIC_PROMPT_NEGATIVE_BUTTON_TEXT;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
@@ -54,6 +57,7 @@ import android.graphics.drawable.AdaptiveIconDrawable;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.VectorDrawable;
|
||||
import android.hardware.biometrics.BiometricManager;
|
||||
import android.hardware.biometrics.SensorProperties;
|
||||
import android.hardware.face.Face;
|
||||
import android.hardware.face.FaceManager;
|
||||
@@ -122,6 +126,7 @@ import com.android.settings.dashboard.profileselector.ProfileFragmentBridge;
|
||||
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||
import com.android.settings.dashboard.profileselector.ProfileSelectFragment.ProfileType;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
import com.android.settings.password.ConfirmDeviceCredentialActivity;
|
||||
import com.android.settingslib.widget.ActionBarShadowController;
|
||||
import com.android.settingslib.widget.AdaptiveIcon;
|
||||
|
||||
@@ -1478,6 +1483,55 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
disableComponent(pm, new ComponentName(context, Settings.CreateShortcutActivity.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Request biometric authentication if all requirements for mandatory biometrics is satisfied.
|
||||
* @param context of the corresponding activity/fragment
|
||||
* @param biometricsSuccessfullyAuthenticated if the user has already authenticated using
|
||||
* biometrics
|
||||
* @param biometricsAuthenticationRequested if the activity/fragment has already requested for
|
||||
* biometric prompt
|
||||
* @return true if all requirements for mandatory biometrics is satisfied
|
||||
*/
|
||||
public static boolean requestBiometricAuthenticationForMandatoryBiometrics(
|
||||
@NonNull Context context,
|
||||
boolean biometricsSuccessfullyAuthenticated,
|
||||
boolean biometricsAuthenticationRequested) {
|
||||
final BiometricManager biometricManager = context.getSystemService(BiometricManager.class);
|
||||
if (biometricManager == null) {
|
||||
Log.e(TAG, "Biometric Manager is null.");
|
||||
return false;
|
||||
}
|
||||
final int status = biometricManager.canAuthenticate(
|
||||
BiometricManager.Authenticators.MANDATORY_BIOMETRICS);
|
||||
return android.hardware.biometrics.Flags.mandatoryBiometrics()
|
||||
&& status == BiometricManager.BIOMETRIC_SUCCESS
|
||||
&& !biometricsSuccessfullyAuthenticated
|
||||
&& !biometricsAuthenticationRequested;
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch biometric prompt for mandatory biometrics. Call
|
||||
* {@link #requestBiometricAuthenticationForMandatoryBiometrics(Context, boolean, boolean)}
|
||||
* to check if all requirements for mandatory biometrics is satisfied
|
||||
* before launching biometric prompt.
|
||||
*
|
||||
* @param fragment corresponding fragment of the surface
|
||||
* @param requestCode for starting the new activity
|
||||
*/
|
||||
public static void launchBiometricPromptForMandatoryBiometrics(@NonNull Fragment fragment,
|
||||
int requestCode) {
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(BIOMETRIC_PROMPT_AUTHENTICATORS,
|
||||
BiometricManager.Authenticators.MANDATORY_BIOMETRICS);
|
||||
intent.putExtra(BIOMETRIC_PROMPT_NEGATIVE_BUTTON_TEXT,
|
||||
fragment.getString(R.string.cancel));
|
||||
intent.putExtra(KeyguardManager.EXTRA_DESCRIPTION,
|
||||
fragment.getString(R.string.mandatory_biometrics_prompt_description));
|
||||
intent.setClassName(SETTINGS_PACKAGE_NAME,
|
||||
ConfirmDeviceCredentialActivity.class.getName());
|
||||
fragment.startActivityForResult(intent, requestCode);
|
||||
}
|
||||
|
||||
private static void disableComponent(PackageManager pm, ComponentName componentName) {
|
||||
pm.setComponentEnabledSetting(componentName,
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
|
||||
|
Reference in New Issue
Block a user