Loading core/java/android/provider/Settings.java +4 −2 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import static android.provider.SettingsValidators.COMPONENT_NAME_VALIDATOR; import static android.provider.SettingsValidators.LENIENT_IP_ADDRESS_VALIDATOR; import static android.provider.SettingsValidators.LOCALE_VALIDATOR; import static android.provider.SettingsValidators.NON_NEGATIVE_INTEGER_VALIDATOR; import static android.provider.SettingsValidators.NULLABLE_COMPONENT_NAME_VALIDATOR; import static android.provider.SettingsValidators.PACKAGE_NAME_VALIDATOR; import static android.provider.SettingsValidators.URI_VALIDATOR; Loading Loading @@ -5461,7 +5462,8 @@ public final class Settings { @TestApi public static final String AUTOFILL_SERVICE = "autofill_service"; private static final Validator AUTOFILL_SERVICE_VALIDATOR = COMPONENT_NAME_VALIDATOR; private static final Validator AUTOFILL_SERVICE_VALIDATOR = NULLABLE_COMPONENT_NAME_VALIDATOR; /** * Boolean indicating if Autofill supports field classification. Loading Loading @@ -5959,7 +5961,7 @@ public final class Settings { "accessibility_shortcut_target_service"; private static final Validator ACCESSIBILITY_SHORTCUT_TARGET_SERVICE_VALIDATOR = COMPONENT_NAME_VALIDATOR; NULLABLE_COMPONENT_NAME_VALIDATOR; /** * Setting specifying the accessibility service or feature to be toggled via the Loading core/java/android/provider/SettingsValidators.java +15 −0 Original line number Diff line number Diff line Loading @@ -77,6 +77,11 @@ public class SettingsValidators { } }; /** * Does not allow a setting to have a null {@link ComponentName}. Use {@link * SettingsValidators#NULLABLE_COMPONENT_NAME_VALIDATOR} instead if a setting can have a * nullable {@link ComponentName}. */ public static final Validator COMPONENT_NAME_VALIDATOR = new Validator() { @Override public boolean validate(@Nullable String value) { Loading @@ -84,6 +89,16 @@ public class SettingsValidators { } }; /** * Allows a setting to have a null {@link ComponentName}. */ public static final Validator NULLABLE_COMPONENT_NAME_VALIDATOR = new Validator() { @Override public boolean validate(@Nullable String value) { return value == null || COMPONENT_NAME_VALIDATOR.validate(value); } }; public static final Validator PACKAGE_NAME_VALIDATOR = new Validator() { @Override public boolean validate(@Nullable String value) { Loading core/tests/coretests/src/android/provider/SettingsValidatorsTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,23 @@ public class SettingsValidatorsTest { assertFalse(SettingsValidators.LENIENT_IP_ADDRESS_VALIDATOR.validate(null)); } @Test public void testNullableComponentNameValidator_onValidComponentName_returnsTrue() { assertTrue(SettingsValidators.NULLABLE_COMPONENT_NAME_VALIDATOR.validate( "android/com.android.internal.backup.LocalTransport")); } @Test public void testNullableComponentNameValidator_onInvalidComponentName_returnsFalse() { assertFalse(SettingsValidators.NULLABLE_COMPONENT_NAME_VALIDATOR.validate( "rectangle")); } @Test public void testNullableComponentNameValidator_onNullValue_returnsTrue() { assertTrue(SettingsValidators.NULLABLE_COMPONENT_NAME_VALIDATOR.validate(null)); } @Test public void testLocaleValidator() { assertTrue(SettingsValidators.LOCALE_VALIDATOR.validate("en_US")); Loading Loading
core/java/android/provider/Settings.java +4 −2 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import static android.provider.SettingsValidators.COMPONENT_NAME_VALIDATOR; import static android.provider.SettingsValidators.LENIENT_IP_ADDRESS_VALIDATOR; import static android.provider.SettingsValidators.LOCALE_VALIDATOR; import static android.provider.SettingsValidators.NON_NEGATIVE_INTEGER_VALIDATOR; import static android.provider.SettingsValidators.NULLABLE_COMPONENT_NAME_VALIDATOR; import static android.provider.SettingsValidators.PACKAGE_NAME_VALIDATOR; import static android.provider.SettingsValidators.URI_VALIDATOR; Loading Loading @@ -5461,7 +5462,8 @@ public final class Settings { @TestApi public static final String AUTOFILL_SERVICE = "autofill_service"; private static final Validator AUTOFILL_SERVICE_VALIDATOR = COMPONENT_NAME_VALIDATOR; private static final Validator AUTOFILL_SERVICE_VALIDATOR = NULLABLE_COMPONENT_NAME_VALIDATOR; /** * Boolean indicating if Autofill supports field classification. Loading Loading @@ -5959,7 +5961,7 @@ public final class Settings { "accessibility_shortcut_target_service"; private static final Validator ACCESSIBILITY_SHORTCUT_TARGET_SERVICE_VALIDATOR = COMPONENT_NAME_VALIDATOR; NULLABLE_COMPONENT_NAME_VALIDATOR; /** * Setting specifying the accessibility service or feature to be toggled via the Loading
core/java/android/provider/SettingsValidators.java +15 −0 Original line number Diff line number Diff line Loading @@ -77,6 +77,11 @@ public class SettingsValidators { } }; /** * Does not allow a setting to have a null {@link ComponentName}. Use {@link * SettingsValidators#NULLABLE_COMPONENT_NAME_VALIDATOR} instead if a setting can have a * nullable {@link ComponentName}. */ public static final Validator COMPONENT_NAME_VALIDATOR = new Validator() { @Override public boolean validate(@Nullable String value) { Loading @@ -84,6 +89,16 @@ public class SettingsValidators { } }; /** * Allows a setting to have a null {@link ComponentName}. */ public static final Validator NULLABLE_COMPONENT_NAME_VALIDATOR = new Validator() { @Override public boolean validate(@Nullable String value) { return value == null || COMPONENT_NAME_VALIDATOR.validate(value); } }; public static final Validator PACKAGE_NAME_VALIDATOR = new Validator() { @Override public boolean validate(@Nullable String value) { Loading
core/tests/coretests/src/android/provider/SettingsValidatorsTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,23 @@ public class SettingsValidatorsTest { assertFalse(SettingsValidators.LENIENT_IP_ADDRESS_VALIDATOR.validate(null)); } @Test public void testNullableComponentNameValidator_onValidComponentName_returnsTrue() { assertTrue(SettingsValidators.NULLABLE_COMPONENT_NAME_VALIDATOR.validate( "android/com.android.internal.backup.LocalTransport")); } @Test public void testNullableComponentNameValidator_onInvalidComponentName_returnsFalse() { assertFalse(SettingsValidators.NULLABLE_COMPONENT_NAME_VALIDATOR.validate( "rectangle")); } @Test public void testNullableComponentNameValidator_onNullValue_returnsTrue() { assertTrue(SettingsValidators.NULLABLE_COMPONENT_NAME_VALIDATOR.validate(null)); } @Test public void testLocaleValidator() { assertTrue(SettingsValidators.LOCALE_VALIDATOR.validate("en_US")); Loading