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

Commit 42deb763 authored by Derek Jedral's avatar Derek Jedral Committed by Android (Google) Code Review
Browse files

Merge "Change preference title if Active Unlock enabled" into udc-dev

parents 2f970a1a 5a75cd54
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -818,6 +818,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] -->
+24 −0
Original line number Diff line number Diff line
@@ -268,6 +268,30 @@ public class ActiveUnlockStatusUtils {
        }
    }

    /**
     * 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);
    }
+6 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ public class CombinedBiometricSettings extends BiometricsSettingsBase {
    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 @@ public class CombinedBiometricSettings extends BiometricsSettingsBase {
        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());
    }

+40 −0
Original line number Diff line number Diff line
@@ -222,4 +222,44 @@ public class ActiveUnlockStatusUtilsTest {
                .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));
    }
}