Change preference title if Active Unlock enabled
Change the title of the preference to reflect that Active Unlock can
also be used to unlock the device.
Test: make RunSettingsRoboTests
Bug: b/271782800
Change-Id: Ie227e6dddfc024235fc3568899ef151f14f17696
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b38552f..6e47dcc 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -815,6 +815,10 @@
<string name="biometric_settings_intro_with_fingerprint">You can unlock with your watch when your fingerprint isn\u2019t recognized.</string>
<!-- Introduction shown in face page to explain that watch unlock can be used if face isn't recognized. [CHAR LIMIT=NONE]-->
<string name="biometric_settings_intro_with_face">You can unlock with your watch when your face isn\u2019t recognized.</string>
+ <string name="biometric_settings_use_fingerprint_or_watch_for"> Use fingerprint or watch to</string>
+ <string name="biometric_settings_use_face_or_watch_for"> Use face or watch to</string>
+ <string name="biometric_settings_use_face_fingerprint_or_watch_for"> Use face, fingerprint, or watch to</string>
+ <string name="biometric_settings_use_watch_for"> Use watch to</string>
<!-- Message for a biometric preference toggle, indicating that an action can only be performed by using Face Unlock or Watch Unlock. [CHAR LIMIT=50] -->
<string name="biometric_settings_use_face_or_watch_preference_summary">Using face or watch</string>
<!-- Message for a biometric preference toggle, indicating that an action can only be performed by using Fingerprint Unlock or Watch Unlock. [CHAR LIMIT=50] -->
diff --git a/src/com/android/settings/biometrics/activeunlock/ActiveUnlockStatusUtils.java b/src/com/android/settings/biometrics/activeunlock/ActiveUnlockStatusUtils.java
index 4ff2b87..8f9da54 100644
--- a/src/com/android/settings/biometrics/activeunlock/ActiveUnlockStatusUtils.java
+++ b/src/com/android/settings/biometrics/activeunlock/ActiveUnlockStatusUtils.java
@@ -268,6 +268,30 @@
}
}
+ /**
+ * Returns the preference title of how to use biometrics when active unlock is enabled.
+ */
+ public String getUseBiometricTitleForActiveUnlock() {
+ final boolean faceAllowed = Utils.hasFaceHardware(mContext);
+ final boolean fingerprintAllowed = Utils.hasFingerprintHardware(mContext);
+
+ return mContext.getString(getUseBiometricTitleRes(faceAllowed, fingerprintAllowed));
+ }
+
+ @StringRes
+ private static int getUseBiometricTitleRes(
+ boolean isFaceAllowed, boolean isFingerprintAllowed) {
+ if (isFaceAllowed && isFingerprintAllowed) {
+ return R.string.biometric_settings_use_face_fingerprint_or_watch_for;
+ } else if (isFaceAllowed) {
+ return R.string.biometric_settings_use_face_or_watch_for;
+ } else if (isFingerprintAllowed) {
+ return R.string.biometric_settings_use_fingerprint_or_watch_for;
+ } else {
+ return R.string.biometric_settings_use_watch_for;
+ }
+ }
+
private static String getFlagState() {
return DeviceConfig.getProperty(DeviceConfig.NAMESPACE_REMOTE_AUTH, CONFIG_FLAG_NAME);
}
diff --git a/src/com/android/settings/biometrics/combination/CombinedBiometricSettings.java b/src/com/android/settings/biometrics/combination/CombinedBiometricSettings.java
index d0e986f..671a5b6 100644
--- a/src/com/android/settings/biometrics/combination/CombinedBiometricSettings.java
+++ b/src/com/android/settings/biometrics/combination/CombinedBiometricSettings.java
@@ -46,6 +46,7 @@
private static final String KEY_UNLOCK_PHONE = "biometric_settings_biometric_keyguard";
private static final String KEY_USE_IN_APPS = "biometric_settings_biometric_app";
private static final String KEY_INTRO_PREFERENCE = "biometric_intro";
+ private static final String KEY_USE_BIOMETRIC_PREFERENCE = "biometric_ways_to_use";
private ActiveUnlockStatusUtils mActiveUnlockStatusUtils;
private CombinedBiometricStatusUtils mCombinedBiometricStatusUtils;
@@ -83,6 +84,11 @@
if (introPreference != null) {
introPreference.setTitle(mActiveUnlockStatusUtils.getIntroForActiveUnlock());
}
+ final Preference useBiometricPreference = findPreference(KEY_USE_BIOMETRIC_PREFERENCE);
+ if (useBiometricPreference != null) {
+ useBiometricPreference.setTitle(
+ mActiveUnlockStatusUtils.getUseBiometricTitleForActiveUnlock());
+ }
getActivity().setTitle(mActiveUnlockStatusUtils.getTitleForActiveUnlock());
}
diff --git a/tests/robotests/src/com/android/settings/biometrics/activeunlock/ActiveUnlockStatusUtilsTest.java b/tests/robotests/src/com/android/settings/biometrics/activeunlock/ActiveUnlockStatusUtilsTest.java
index d420f78..e5eac12 100644
--- a/tests/robotests/src/com/android/settings/biometrics/activeunlock/ActiveUnlockStatusUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/biometrics/activeunlock/ActiveUnlockStatusUtilsTest.java
@@ -222,4 +222,44 @@
.isEqualTo(mApplicationContext.getString(
R.string.biometric_settings_use_face_or_watch_preference_summary));
}
+
+ @Test
+ public void getUseBiometricTitle_faceAndFingerprintEnabled_returnsFaceFingerprintOrWatch() {
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+ when(mFaceManager.isHardwareDetected()).thenReturn(true);
+
+ assertThat(mActiveUnlockStatusUtils.getUseBiometricTitleForActiveUnlock())
+ .isEqualTo(mApplicationContext.getString(
+ R.string.biometric_settings_use_face_fingerprint_or_watch_for));
+ }
+
+ @Test
+ public void getUseBiometricTitle_fingerprintEnabled_returnsFingerprintOrWatch() {
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+ when(mFaceManager.isHardwareDetected()).thenReturn(false);
+
+ assertThat(mActiveUnlockStatusUtils.getUseBiometricTitleForActiveUnlock())
+ .isEqualTo(mApplicationContext.getString(
+ R.string.biometric_settings_use_fingerprint_or_watch_for));
+ }
+
+ @Test
+ public void getUseBiometricTitle_faceEnabled_returnsFaceOrWatch() {
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
+ when(mFaceManager.isHardwareDetected()).thenReturn(true);
+
+ assertThat(mActiveUnlockStatusUtils.getUseBiometricTitleForActiveUnlock())
+ .isEqualTo(mApplicationContext.getString(
+ R.string.biometric_settings_use_face_or_watch_for));
+ }
+
+ @Test
+ public void getUseBiometricTitle_withoutFaceOrFingerprint_returnsWatch() {
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
+ when(mFaceManager.isHardwareDetected()).thenReturn(false);
+
+ assertThat(mActiveUnlockStatusUtils.getUseBiometricTitleForActiveUnlock())
+ .isEqualTo(mApplicationContext.getString(
+ R.string.biometric_settings_use_watch_for));
+ }
}