Make biometric setting toggles show dynamic auth types

Updates the preference toggles shown on the combined biometric settings
screen to indicate which types of biometric sensor (e.g. face and/or
fingerprint) each setting applies to. This is done by checking the
maximum registered strength for each type of sensor.

Test: Manual

Bug: 193714498
Bug: 201306569
Change-Id: I1f27bbe1fdd172ebc899c3c5f1daef9095b338bd
This commit is contained in:
Curtis Belmonte
2021-09-27 13:27:20 -07:00
parent 61e7977aaa
commit a9c582262e
6 changed files with 114 additions and 27 deletions

View File

@@ -997,12 +997,16 @@
<string name="biometric_settings_intro">When you set up Face Unlock and Fingerprint Unlock, your phone will ask for your fingerprint when you wear a mask or are in a dark area</string>
<!-- Biometric category title - biometric options for unlocking the device. [CHAR LIMIT=50] -->
<string name="biometric_settings_category_ways_to_unlock">Ways to unlock</string>
<!-- Biometric category title - configuration options for using biometric to unlock the device or authenticate in apps. [CHAR LIMIT=50] -->
<string name="biometric_settings_category_ways_to_use">Use face and fingerprint for</string>
<!-- Text shown on a toggle which allows or disallows the device to use biometric for unlocking the device. [CHAR LIMIT=50] -->
<string name="biometric_settings_use_biometric_unlock_phone">Unlocking your phone</string>
<string name="biometric_settings_use_biometric_unlock_phone">Unlock your phone</string>
<!-- Text shown on a toggle which allows or disallows the device to use biometric for authentication. [CHAR LIMIT=50] -->
<string name="biometric_settings_use_biometric_for_apps">Authentication in apps</string>
<string name="biometric_settings_use_biometric_for_apps">Verify it\u2019s you in apps</string>
<!-- Message for a biometric preference toggle, indicating that an action can only be performed by using Face Unlock. [CHAR LIMIT=50] -->
<string name="biometric_settings_use_face_preference_summary">Using face</string>
<!-- Message for a biometric preference toggle, indicating that an action can only be performed by using Fingerprint Unlock. [CHAR LIMIT=50] -->
<string name="biometric_settings_use_fingerprint_preference_summary">Using fingerprint</string>
<!-- Message for a biometric preference toggle, indicating that an action can be performed by using either Face Unlock or Fingerprint Unlock. [CHAR LIMIT=50] -->
<string name="biometric_settings_use_face_or_fingerprint_preference_summary">Using face or fingerprint</string>
<!-- Message shown during enrollment to prompt a child to give the device to a parent or guardian. [CHAR LIMIT=NONE]-->
<string name="biometric_settings_hand_back_to_guardian">Hand the phone back to your parent</string>
<!-- Button text shown during enrollment to proceed after a child user has handed the device to a parent or guardian. [CHAR LIMIT=22] -->
@@ -1242,25 +1246,6 @@
<!-- Button to confirm the last removing the last fingerprint. [CHAR LIMIT=20]-->
<string name="fingerprint_last_delete_confirm">Yes, remove</string>
<!-- Title of the combined biometrics settings screen. [CHAR LIMIT=40] -->
<string name="security_settings_biometrics_title">Face \u0026 fingerprint unlock</string>
<!-- Summary of the current biometrics setting when no biometrics have been enrolled. [CHAR LIMIT=50] -->
<string name="security_settings_biometrics_summary_none">Tap to set up</string>
<!-- Summary of the current biometrics setting when the user has enrolled a face but no fingerprint. [CHAR LIMIT=50] -->
<string name="security_settings_biometrics_summary_face">Face only</string>
<!-- Summary of the current biometrics setting when the user has enrolled a fingerprint but no face. [CHAR LIMIT=50] -->
<string name="security_settings_biometrics_summary_fingerprint">Fingerprint only</string>
<!-- Summary of the current biometrics setting when the user has enrolled both a face and a fingerprint. [CHAR LIMIT=50] -->
<string name="security_settings_biometrics_summary_both">Face and fingerprint</string>
<!-- Description shown on the combined biometrics settings screen. [CHAR LIMIT=NONE] -->
<string name="security_settings_biometrics_description">When you set up face and fingerprint unlock, your phone will ask for your fingerprint when you wear a mask or are in a dark area</string>
<!-- Title of a section on the biometrics settings screen for setting up different types of authentication. [CHAR LIMIT=50] -->
<string name="security_settings_biometrics_types_category">Ways to unlock</string>
<!-- Title of a section on the biometrics settings screen for adjusting authentication preferences. [CHAR LIMIT=50] -->
<string name="security_settings_biometrics_preferences_category">Use face or fingerprint for</string>
<!-- Title of a section on the biometrics settings screen for adjusting authentication preferences. [CHAR LIMIT=50] -->
<string name="security_settings_biometrics_preference_use_with_apps">Authentication in apps</string>
<!-- Title of the preferences category for preference items to control encryption -->
<string name="crypt_keeper_settings_title">Encryption</string>

View File

@@ -43,8 +43,7 @@
</PreferenceCategory>
<PreferenceCategory
android:key="biometric_ways_to_use"
android:title="@string/biometric_settings_category_ways_to_use">
android:key="biometric_ways_to_use">
<com.android.settingslib.RestrictedSwitchPreference
android:key="biometric_settings_biometric_keyguard"

View File

@@ -43,8 +43,7 @@
</PreferenceCategory>
<PreferenceCategory
android:key="biometric_ways_to_use"
android:title="@string/biometric_settings_category_ways_to_use">
android:key="biometric_ways_to_use">
<SwitchPreference
android:key="biometric_settings_biometric_app_profile"

View File

@@ -21,13 +21,18 @@ import static com.android.settings.password.ChooseLockPattern.RESULT_FINISHED;
import android.content.Context;
import android.content.Intent;
import android.hardware.biometrics.SensorProperties;
import android.hardware.face.FaceManager;
import android.hardware.face.FaceSensorPropertiesInternal;
import android.hardware.fingerprint.FingerprintManager;
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
import android.os.Bundle;
import android.os.UserHandle;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.preference.Preference;
import com.android.settings.R;
@@ -90,6 +95,16 @@ public abstract class BiometricsSettingsBase extends DashboardFragment {
mConfirmCredential = true;
launchChooseOrConfirmLock();
}
final Preference unlockPhonePreference = findPreference(getUnlockPhonePreferenceKey());
if (unlockPhonePreference != null) {
unlockPhonePreference.setSummary(getUseAnyBiometricSummary());
}
final Preference useInAppsPreference = findPreference(getUseInAppsPreferenceKey());
if (useInAppsPreference != null) {
useInAppsPreference.setSummary(getUseClass2BiometricSummary());
}
}
@Override
@@ -185,6 +200,16 @@ public abstract class BiometricsSettingsBase extends DashboardFragment {
*/
public abstract String getFingerprintPreferenceKey();
/**
* @return The preference key of the "Unlock your phone" setting toggle.
*/
public abstract String getUnlockPhonePreferenceKey();
/**
* @return The preference key of the "Verify it's you in apps" setting toggle.
*/
public abstract String getUseInAppsPreferenceKey();
private void launchChooseOrConfirmLock() {
final ChooseLockSettingsHelper.Builder builder =
new ChooseLockSettingsHelper.Builder(getActivity(), this)
@@ -214,4 +239,59 @@ public abstract class BiometricsSettingsBase extends DashboardFragment {
startActivityForResult(intent, CHOOSE_LOCK_REQUEST);
}
}
@NonNull
private String getUseAnyBiometricSummary() {
boolean isFaceAllowed = mFaceManager != null && mFaceManager.isHardwareDetected();
boolean isFingerprintAllowed =
mFingerprintManager != null && mFingerprintManager.isHardwareDetected();
@StringRes final int resId = getUseBiometricSummaryRes(isFaceAllowed, isFingerprintAllowed);
return resId == 0 ? "" : getString(resId);
}
@NonNull
private String getUseClass2BiometricSummary() {
boolean isFaceAllowed = false;
if (mFaceManager != null) {
for (final FaceSensorPropertiesInternal sensorProps
: mFaceManager.getSensorPropertiesInternal()) {
if (sensorProps.sensorStrength == SensorProperties.STRENGTH_WEAK
|| sensorProps.sensorStrength == SensorProperties.STRENGTH_STRONG) {
isFaceAllowed = true;
break;
}
}
}
boolean isFingerprintAllowed = false;
if (mFingerprintManager != null) {
for (final FingerprintSensorPropertiesInternal sensorProps
: mFingerprintManager.getSensorPropertiesInternal()) {
if (sensorProps.sensorStrength == SensorProperties.STRENGTH_WEAK
|| sensorProps.sensorStrength == SensorProperties.STRENGTH_STRONG) {
isFingerprintAllowed = true;
break;
}
}
}
@StringRes final int resId = getUseBiometricSummaryRes(isFaceAllowed, isFingerprintAllowed);
return resId == 0 ? "" : getString(resId);
}
@StringRes
private static int getUseBiometricSummaryRes(boolean isFaceAllowed,
boolean isFingerprintAllowed) {
if (isFaceAllowed && isFingerprintAllowed) {
return R.string.biometric_settings_use_face_or_fingerprint_preference_summary;
} else if (isFaceAllowed) {
return R.string.biometric_settings_use_face_preference_summary;
} else if (isFingerprintAllowed) {
return R.string.biometric_settings_use_fingerprint_preference_summary;
} else {
return 0;
}
}
}

View File

@@ -28,6 +28,8 @@ public class CombinedBiometricProfileSettings extends BiometricsSettingsBase {
private static final String TAG = "BiometricProfileSetting";
private static final String KEY_FACE_SETTINGS = "biometric_face_settings_profile";
private static final String KEY_FINGERPRINT_SETTINGS = "biometric_fingerprint_settings_profile";
private static final String KEY_UNLOCK_PHONE = "biometric_settings_biometric_keyguard_profile";
private static final String KEY_USE_IN_APPS = "biometric_settings_biometric_app_profile";
@Override
public void onAttach(Context context) {
@@ -50,6 +52,16 @@ public class CombinedBiometricProfileSettings extends BiometricsSettingsBase {
return KEY_FINGERPRINT_SETTINGS;
}
@Override
public String getUnlockPhonePreferenceKey() {
return KEY_UNLOCK_PHONE;
}
@Override
public String getUseInAppsPreferenceKey() {
return KEY_USE_IN_APPS;
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -30,6 +30,8 @@ public class CombinedBiometricSettings extends BiometricsSettingsBase {
private static final String TAG = "BiometricSettings";
private static final String KEY_FACE_SETTINGS = "biometric_face_settings";
private static final String KEY_FINGERPRINT_SETTINGS = "biometric_fingerprint_settings";
private static final String KEY_UNLOCK_PHONE = "biometric_settings_biometric_keyguard";
private static final String KEY_USE_IN_APPS = "biometric_settings_biometric_app";
@Override
public void onAttach(Context context) {
@@ -53,6 +55,16 @@ public class CombinedBiometricSettings extends BiometricsSettingsBase {
return KEY_FINGERPRINT_SETTINGS;
}
@Override
public String getUnlockPhonePreferenceKey() {
return KEY_UNLOCK_PHONE;
}
@Override
public String getUseInAppsPreferenceKey() {
return KEY_USE_IN_APPS;
}
@Override
protected String getLogTag() {
return TAG;