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

Commit d1de9470 authored by Becca Hughes's avatar Becca Hughes
Browse files

Enable credential manager for backup/restore

This CL adds support for credman provider
preferences to be backed up / restored as
part of the device backup.

Test: manual ondevice test + unit tests
Bug: 254351562
Change-Id: I6ca4076e95006a9652ea50020980761cc14d8fc1
parent cba298bb
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -249,6 +249,8 @@ public class SecureSettings {
        Settings.Secure.HUB_MODE_TUTORIAL_STATE,
        Settings.Secure.STYLUS_BUTTONS_ENABLED,
        Settings.Secure.STYLUS_HANDWRITING_ENABLED,
        Settings.Secure.DEFAULT_NOTE_TASK_PROFILE
        Settings.Secure.DEFAULT_NOTE_TASK_PROFILE,
        Settings.Secure.CREDENTIAL_SERVICE,
        Settings.Secure.CREDENTIAL_SERVICE_PRIMARY
    };
}
+5 −1
Original line number Diff line number Diff line
@@ -19,11 +19,13 @@ package android.provider.settings.validators;
import static android.provider.settings.validators.SettingsValidators.ACCESSIBILITY_SHORTCUT_TARGET_LIST_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.ANY_INTEGER_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.ANY_STRING_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.AUTOFILL_SERVICE_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.BOOLEAN_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.COLON_SEPARATED_COMPONENT_LIST_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.COLON_SEPARATED_PACKAGE_LIST_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.COMMA_SEPARATED_COMPONENT_LIST_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.COMPONENT_NAME_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.CREDENTIAL_SERVICE_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.JSON_OBJECT_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.LOCALE_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.NONE_NEGATIVE_LONG_VALIDATOR;
@@ -62,7 +64,6 @@ public class SecureSettingsValidators {
        VALIDATORS.put(Secure.ADAPTIVE_CHARGING_ENABLED, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.ADAPTIVE_SLEEP, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.CAMERA_AUTOROTATE, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.AUTOFILL_SERVICE, NULLABLE_COMPONENT_NAME_VALIDATOR);
        VALIDATORS.put(
                Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
                new InclusiveFloatRangeValidator(1.0f, Float.MAX_VALUE));
@@ -398,5 +399,8 @@ public class SecureSettingsValidators {
        VALIDATORS.put(Secure.STYLUS_HANDWRITING_ENABLED,
                new DiscreteValueValidator(new String[] {"-1", "0", "1"}));
        VALIDATORS.put(Secure.DEFAULT_NOTE_TASK_PROFILE, NON_NEGATIVE_INTEGER_VALIDATOR);
        VALIDATORS.put(Secure.CREDENTIAL_SERVICE, CREDENTIAL_SERVICE_VALIDATOR);
        VALIDATORS.put(Secure.CREDENTIAL_SERVICE_PRIMARY, NULLABLE_COMPONENT_NAME_VALIDATOR);
        VALIDATORS.put(Secure.AUTOFILL_SERVICE, AUTOFILL_SERVICE_VALIDATOR);
    }
}
+26 −0
Original line number Diff line number Diff line
@@ -235,4 +235,30 @@ public class SettingsValidators {
            }
        }
    };

    static final Validator CREDENTIAL_SERVICE_VALIDATOR = new Validator() {
        @Override
        public boolean validate(String value) {
            if (value == null || value.equals("")) {
                return true;
            }

            return COLON_SEPARATED_COMPONENT_LIST_VALIDATOR.validate(value);
        }
    };

    static final Validator AUTOFILL_SERVICE_VALIDATOR = new Validator() {
        @Override
        public boolean validate(String value) {
            if (value == null || value.equals("")) {
                return true;
            }

            if (value.equals("credential-provider")) {
               return true;
            }

            return NULLABLE_COMPONENT_NAME_VALIDATOR.validate(value);
        }
    };
}
+0 −2
Original line number Diff line number Diff line
@@ -851,8 +851,6 @@ public class SettingsBackupTest {
                 Settings.Secure.ACCESSIBILITY_SHOW_WINDOW_MAGNIFICATION_PROMPT,
                 Settings.Secure.ACCESSIBILITY_FLOATING_MENU_MIGRATION_TOOLTIP_PROMPT,
                 Settings.Secure.UI_TRANSLATION_ENABLED,
                 Settings.Secure.CREDENTIAL_SERVICE,
                 Settings.Secure.CREDENTIAL_SERVICE_PRIMARY,
                 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_EDGE_HAPTIC_ENABLED,
                 Settings.Secure.DND_CONFIGS_MIGRATED,
                 Settings.Secure.NAVIGATION_MODE_RESTORE);
+54 −0
Original line number Diff line number Diff line
@@ -340,6 +340,60 @@ public class SettingsValidatorsTest {
        failIfOffendersPresent(offenders, "Settings.Secure");
    }

    @Test
    public void testCredentialServiceValidator_returnsTrueIfNull() {
        assertTrue(SettingsValidators.CREDENTIAL_SERVICE_VALIDATOR.validate(null));
    }

    @Test
    public void testCredentialServiceValidator_returnsTrueIfEmpty() {
        assertTrue(SettingsValidators.CREDENTIAL_SERVICE_VALIDATOR.validate(""));
    }

    @Test
    public void testCredentialServiceValidator_returnsTrueIfSingleComponentName() {
        assertTrue(SettingsValidators.CREDENTIAL_SERVICE_VALIDATOR.validate(
            "android.credentials/android.credentials.Test"));
    }

    @Test
    public void testCredentialServiceValidator_returnsTrueIfMultipleComponentName() {
        assertTrue(SettingsValidators.CREDENTIAL_SERVICE_VALIDATOR.validate(
            "android.credentials/android.credentials.Test"
            + ":android.credentials/.Test2"));
    }

    @Test
    public void testCredentialServiceValidator_returnsFalseIfInvalidComponentName() {
        assertFalse(SettingsValidators.CREDENTIAL_SERVICE_VALIDATOR.validate("test"));
    }

    @Test
    public void testAutofillServiceValidator_returnsTrueIfNull() {
        assertTrue(SettingsValidators.AUTOFILL_SERVICE_VALIDATOR.validate(null));
    }

    @Test
    public void testAutofillServiceValidator_returnsTrueIfEmpty() {
        assertTrue(SettingsValidators.AUTOFILL_SERVICE_VALIDATOR.validate(""));
    }

    @Test
    public void testAutofillServiceValidator_returnsTrueIfPlaceholder() {
        assertTrue(SettingsValidators.AUTOFILL_SERVICE_VALIDATOR.validate("credential-provider"));
    }

    @Test
    public void testAutofillServiceValidator_returnsTrueIfSingleComponentName() {
        assertTrue(SettingsValidators.AUTOFILL_SERVICE_VALIDATOR.validate(
            "android.credentials/android.credentials.Test"));
    }

    @Test
    public void testAutofillServiceValidator_returnsFalseIfInvalidComponentName() {
        assertFalse(SettingsValidators.AUTOFILL_SERVICE_VALIDATOR.validate("test"));
    }

    private void failIfOffendersPresent(String offenders, String settingsType) {
        if (offenders.length() > 0) {
            fail("All " + settingsType + " settings that are backed up have to have a non-null"