Loading core/java/android/provider/Settings.java +67 −62 Original line number Diff line number Diff line Loading @@ -16,16 +16,19 @@ package android.provider; import static android.provider.SettingsValidators.ANY_INTEGER_VALIDATOR; import static android.provider.SettingsValidators.ANY_STRING_VALIDATOR; import static android.provider.SettingsValidators.BOOLEAN_VALIDATOR; 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; 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.BOOLEAN_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.COMPONENT_NAME_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.JSON_OBJECT_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.LENIENT_IP_ADDRESS_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.LOCALE_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.NON_NEGATIVE_INTEGER_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.NULLABLE_COMPONENT_NAME_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.PACKAGE_NAME_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.TILE_LIST_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.TTS_LIST_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.URI_VALIDATOR; import android.Manifest; import android.annotation.IntDef; Loading Loading @@ -80,7 +83,12 @@ import android.os.RemoteException; import android.os.ResultReceiver; import android.os.ServiceManager; import android.os.UserHandle; import android.provider.SettingsValidators.Validator; import android.provider.settings.validators.ComponentNameListValidator; import android.provider.settings.validators.DiscreteValueValidator; import android.provider.settings.validators.InclusiveFloatRangeValidator; import android.provider.settings.validators.InclusiveIntegerRangeValidator; import android.provider.settings.validators.PackageNameListValidator; import android.provider.settings.validators.Validator; import android.speech.tts.TextToSpeech; import android.telephony.SubscriptionManager; import android.text.TextUtils; Loading Loading @@ -3149,7 +3157,7 @@ public final class Settings { public static final String END_BUTTON_BEHAVIOR = "end_button_behavior"; private static final Validator END_BUTTON_BEHAVIOR_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 3); new InclusiveIntegerRangeValidator(0, 3); /** * END_BUTTON_BEHAVIOR value for "go home". Loading Loading @@ -3351,7 +3359,7 @@ public final class Settings { "bluetooth_discoverability"; private static final Validator BLUETOOTH_DISCOVERABILITY_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 2); new InclusiveIntegerRangeValidator(0, 2); /** * Bluetooth discoverability timeout. If this value is nonzero, then Loading Loading @@ -3495,7 +3503,7 @@ public final class Settings { public static final String PEAK_REFRESH_RATE = "peak_refresh_rate"; private static final Validator PEAK_REFRESH_RATE_VALIDATOR = new SettingsValidators.InclusiveFloatRangeValidator(24f, Float.MAX_VALUE); new InclusiveFloatRangeValidator(24f, Float.MAX_VALUE); /** * The amount of time in milliseconds before the device goes to sleep or begins Loading Loading @@ -3524,7 +3532,7 @@ public final class Settings { public static final String SCREEN_BRIGHTNESS_FOR_VR = "screen_brightness_for_vr"; private static final Validator SCREEN_BRIGHTNESS_FOR_VR_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 255); new InclusiveIntegerRangeValidator(0, 255); /** * Control whether to enable automatic brightness mode. Loading @@ -3542,7 +3550,7 @@ public final class Settings { public static final String SCREEN_AUTO_BRIGHTNESS_ADJ = "screen_auto_brightness_adj"; private static final Validator SCREEN_AUTO_BRIGHTNESS_ADJ_VALIDATOR = new SettingsValidators.InclusiveFloatRangeValidator(-1, 1); new InclusiveFloatRangeValidator(-1, 1); /** * SCREEN_BRIGHTNESS_MODE value for manual mode. Loading Loading @@ -3676,7 +3684,7 @@ public final class Settings { "haptic_feedback_intensity"; private static final Validator VIBRATION_INTENSITY_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 3); new InclusiveIntegerRangeValidator(0, 3); /** * Ringer volume. This is used internally, changing this value will not Loading Loading @@ -3766,7 +3774,7 @@ public final class Settings { public static final String MASTER_BALANCE = "master_balance"; private static final Validator MASTER_BALANCE_VALIDATOR = new SettingsValidators.InclusiveFloatRangeValidator(-1.f, 1.f); new InclusiveFloatRangeValidator(-1.f, 1.f); /** * Whether the notifications should use the ring volume (value of 1) or Loading Loading @@ -4004,7 +4012,7 @@ public final class Settings { /** @hide */ public static final Validator TIME_12_24_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[] {"12", "24", null}); new DiscreteValueValidator(new String[] {"12", "24", null}); /** * Date format string Loading Loading @@ -4090,7 +4098,7 @@ public final class Settings { /** @hide */ public static final Validator USER_ROTATION_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 3); new InclusiveIntegerRangeValidator(0, 3); /** * Control whether the rotation lock toggle in the System UI should be hidden. Loading Loading @@ -4179,7 +4187,7 @@ public final class Settings { /** @hide */ public static final Validator TTY_MODE_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 3); new InclusiveIntegerRangeValidator(0, 3); /** * Whether the sounds effects (key clicks, lid open ...) are enabled. The value is Loading Loading @@ -4381,7 +4389,7 @@ public final class Settings { /** @hide */ public static final Validator SIP_CALL_OPTIONS_VALIDATOR = new SettingsValidators.DiscreteValueValidator( new DiscreteValueValidator( new String[] {"SIP_ALWAYS", "SIP_ADDRESS_ONLY"}); /** Loading Loading @@ -4428,7 +4436,7 @@ public final class Settings { /** @hide */ public static final Validator POINTER_SPEED_VALIDATOR = new SettingsValidators.InclusiveFloatRangeValidator(-7, 7); new InclusiveFloatRangeValidator(-7, 7); /** * Whether lock-to-app will be triggered by long-press on recents. Loading Loading @@ -6352,7 +6360,7 @@ public final class Settings { public static final String LOCK_SCREEN_CUSTOM_CLOCK_FACE = "lock_screen_custom_clock_face"; private static final Validator LOCK_SCREEN_CUSTOM_CLOCK_FACE_VALIDATOR = SettingsValidators.JSON_OBJECT_VALIDATOR; JSON_OBJECT_VALIDATOR; /** * Indicates which clock face to show on lock screen and AOD while docked. Loading Loading @@ -6509,7 +6517,7 @@ public final class Settings { "enabled_accessibility_services"; private static final Validator ENABLED_ACCESSIBILITY_SERVICES_VALIDATOR = new SettingsValidators.ComponentNameListValidator(":"); new ComponentNameListValidator(":"); /** * List of the accessibility services to which the user has granted Loading @@ -6521,7 +6529,7 @@ public final class Settings { "touch_exploration_granted_accessibility_services"; private static final Validator TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES_VALIDATOR = new SettingsValidators.ComponentNameListValidator(":"); new ComponentNameListValidator(":"); /** * Whether the Global Actions Panel is enabled. Loading Loading @@ -6696,7 +6704,7 @@ public final class Settings { "accessibility_display_magnification_scale"; private static final Validator ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE_VALIDATOR = new SettingsValidators.InclusiveFloatRangeValidator(1.0f, Float.MAX_VALUE); new InclusiveFloatRangeValidator(1.0f, Float.MAX_VALUE); /** * Unused mangnification setting Loading Loading @@ -6780,7 +6788,7 @@ public final class Settings { "accessibility_captioning_preset"; private static final Validator ACCESSIBILITY_CAPTIONING_PRESET_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[]{"-1", "0", "1", "2", new DiscreteValueValidator(new String[]{"-1", "0", "1", "2", "3", "4"}); /** Loading Loading @@ -6824,7 +6832,7 @@ public final class Settings { "accessibility_captioning_edge_type"; private static final Validator ACCESSIBILITY_CAPTIONING_EDGE_TYPE_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[]{"0", "1", "2"}); new DiscreteValueValidator(new String[]{"0", "1", "2"}); /** * Integer property that specifes the edge color for captions as a Loading Loading @@ -6870,7 +6878,7 @@ public final class Settings { "accessibility_captioning_typeface"; private static final Validator ACCESSIBILITY_CAPTIONING_TYPEFACE_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[]{"DEFAULT", new DiscreteValueValidator(new String[]{"DEFAULT", "MONOSPACE", "SANS_SERIF", "SERIF"}); /** Loading @@ -6882,7 +6890,7 @@ public final class Settings { "accessibility_captioning_font_scale"; private static final Validator ACCESSIBILITY_CAPTIONING_FONT_SCALE_VALIDATOR = new SettingsValidators.InclusiveFloatRangeValidator(0.5f, 2.0f); new InclusiveFloatRangeValidator(0.5f, 2.0f); /** * Setting that specifies whether display color inversion is enabled. Loading Loading @@ -6923,7 +6931,7 @@ public final class Settings { "accessibility_display_daltonizer"; private static final Validator ACCESSIBILITY_DISPLAY_DALTONIZER_VALIDATOR = new SettingsValidators.DiscreteValueValidator( new DiscreteValueValidator( new String[] {"-1", "0", "11", "12", "13"}); /** Loading Loading @@ -7112,8 +7120,7 @@ public final class Settings { */ public static final String TTS_DEFAULT_LOCALE = "tts_default_locale"; private static final Validator TTS_DEFAULT_LOCALE_VALIDATOR = new SettingsValidators.TTSListValidator(); private static final Validator TTS_DEFAULT_LOCALE_VALIDATOR = TTS_LIST_VALIDATOR; /** * Space delimited list of plugin packages that are enabled. Loading @@ -7121,7 +7128,7 @@ public final class Settings { public static final String TTS_ENABLED_PLUGINS = "tts_enabled_plugins"; private static final Validator TTS_ENABLED_PLUGINS_VALIDATOR = new SettingsValidators.PackageNameListValidator(" "); new PackageNameListValidator(" "); /** * @deprecated Use {@link android.provider.Settings.Global#WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON} Loading Loading @@ -7315,7 +7322,7 @@ public final class Settings { "preferred_tty_mode"; private static final Validator PREFERRED_TTY_MODE_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[]{"0", "1", "2", "3"}); new DiscreteValueValidator(new String[]{"0", "1", "2", "3"}); /** * Whether the enhanced voice privacy mode is enabled. Loading Loading @@ -7630,7 +7637,7 @@ public final class Settings { public static final String INCALL_POWER_BUTTON_BEHAVIOR = "incall_power_button_behavior"; private static final Validator INCALL_POWER_BUTTON_BEHAVIOR_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[]{"1", "2"}); new DiscreteValueValidator(new String[]{"1", "2"}); /** * INCALL_POWER_BUTTON_BEHAVIOR value for "turn off screen". Loading Loading @@ -7851,7 +7858,7 @@ public final class Settings { public static final String UI_NIGHT_MODE = "ui_night_mode"; private static final Validator UI_NIGHT_MODE_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 2); new InclusiveIntegerRangeValidator(0, 2); /** * Whether screensavers are enabled. Loading @@ -7871,7 +7878,7 @@ public final class Settings { public static final String SCREENSAVER_COMPONENTS = "screensaver_components"; private static final Validator SCREENSAVER_COMPONENTS_VALIDATOR = new SettingsValidators.ComponentNameListValidator(","); new ComponentNameListValidator(","); /** * If screensavers are enabled, whether the screensaver should be automatically launched Loading Loading @@ -8023,7 +8030,7 @@ public final class Settings { "enabled_notification_assistant"; private static final Validator ENABLED_NOTIFICATION_ASSISTANT_VALIDATOR = new SettingsValidators.ComponentNameListValidator(":"); new ComponentNameListValidator(":"); /** * Read only list of the service components that the current user has explicitly allowed to Loading @@ -8038,7 +8045,7 @@ public final class Settings { public static final String ENABLED_NOTIFICATION_LISTENERS = "enabled_notification_listeners"; private static final Validator ENABLED_NOTIFICATION_LISTENERS_VALIDATOR = new SettingsValidators.ComponentNameListValidator(":"); new ComponentNameListValidator(":"); /** * Read only list of the packages that the current user has explicitly allowed to Loading @@ -8053,7 +8060,7 @@ public final class Settings { "enabled_notification_policy_access_packages"; private static final Validator ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES_VALIDATOR = new SettingsValidators.PackageNameListValidator(":"); new PackageNameListValidator(":"); /** * Defines whether managed profile ringtones should be synced from it's parent profile Loading Loading @@ -8436,7 +8443,7 @@ public final class Settings { public static final String NIGHT_DISPLAY_AUTO_MODE = "night_display_auto_mode"; private static final Validator NIGHT_DISPLAY_AUTO_MODE_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 2); new InclusiveIntegerRangeValidator(0, 2); /** * Control the color temperature of Night Display, represented in Kelvin. Loading Loading @@ -8497,7 +8504,7 @@ public final class Settings { public static final String ENABLED_VR_LISTENERS = "enabled_vr_listeners"; private static final Validator ENABLED_VR_LISTENERS_VALIDATOR = new SettingsValidators.ComponentNameListValidator(":"); new ComponentNameListValidator(":"); /** * Behavior of the display while in VR mode. Loading @@ -8509,7 +8516,7 @@ public final class Settings { public static final String VR_DISPLAY_MODE = "vr_display_mode"; private static final Validator VR_DISPLAY_MODE_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[]{"0", "1"}); new DiscreteValueValidator(new String[]{"0", "1"}); /** * Lower the display persistence while the system is in VR mode. Loading Loading @@ -8628,8 +8635,7 @@ public final class Settings { */ public static final String QS_TILES = "sysui_qs_tiles"; private static final Validator QS_TILES_VALIDATOR = new SettingsValidators.TileListValidator(); private static final Validator QS_TILES_VALIDATOR = TILE_LIST_VALIDATOR; /** * Specifies whether the web action API is enabled. Loading Loading @@ -8695,8 +8701,7 @@ public final class Settings { */ public static final String QS_AUTO_ADDED_TILES = "qs_auto_tiles"; private static final Validator QS_AUTO_ADDED_TILES_VALIDATOR = new SettingsValidators.TileListValidator(); private static final Validator QS_AUTO_ADDED_TILES_VALIDATOR = TILE_LIST_VALIDATOR; /** * Whether the Lockdown button should be shown in the power menu. Loading Loading @@ -8857,7 +8862,7 @@ public final class Settings { "theme_customization_overlay_packages"; private static final Validator THEME_CUSTOMIZATION_OVERLAY_PACKAGES_VALIDATOR = SettingsValidators.JSON_OBJECT_VALIDATOR; JSON_OBJECT_VALIDATOR; /** * Navigation bar mode. Loading @@ -8869,7 +8874,7 @@ public final class Settings { public static final String NAVIGATION_MODE = "navigation_mode"; private static final Validator NAVIGATION_MODE_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[] {"0", "1", "2"}); new DiscreteValueValidator(new String[] {"0", "1", "2"}); /** * Controls whether aware is enabled. Loading Loading @@ -10721,7 +10726,7 @@ public final class Settings { "network_recommendations_enabled"; private static final Validator NETWORK_RECOMMENDATIONS_ENABLED_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[] {"-1", "0", "1"}); new DiscreteValueValidator(new String[] {"-1", "0", "1"}); /** * Which package name to use for network recommendations. If null, network recommendations Loading Loading @@ -12572,7 +12577,7 @@ public final class Settings { public static final String EMERGENCY_TONE = "emergency_tone"; private static final Validator EMERGENCY_TONE_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[] {"0", "1", "2"}); new DiscreteValueValidator(new String[] {"0", "1", "2"}); /** * CDMA only settings Loading Loading @@ -12602,7 +12607,7 @@ public final class Settings { "enable_automatic_system_server_heap_dumps"; private static final Validator ENABLE_AUTOMATIC_SYSTEM_SERVER_HEAP_DUMPS_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[] {"0", "1"}); new DiscreteValueValidator(new String[] {"0", "1"}); /** * See RIL_PreferredNetworkType in ril.h Loading Loading @@ -12796,7 +12801,7 @@ public final class Settings { "low_power_sticky_auto_disable_level"; private static final Validator LOW_POWER_MODE_STICKY_AUTO_DISABLE_LEVEL_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 100); new InclusiveIntegerRangeValidator(0, 100); /** * Whether sticky battery saver should be deactivated once the battery level has reached the Loading @@ -12808,7 +12813,7 @@ public final class Settings { "low_power_sticky_auto_disable_enabled"; private static final Validator LOW_POWER_MODE_STICKY_AUTO_DISABLE_ENABLED_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[] {"0", "1"}); new DiscreteValueValidator(new String[] {"0", "1"}); /** * Battery level [1-100] at which low power mode automatically turns on. Loading @@ -12823,7 +12828,7 @@ public final class Settings { public static final String LOW_POWER_MODE_TRIGGER_LEVEL = "low_power_trigger_level"; private static final Validator LOW_POWER_MODE_TRIGGER_LEVEL_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 100); new InclusiveIntegerRangeValidator(0, 100); /** * Whether battery saver is currently set to trigger based on percentage, dynamic power Loading @@ -12836,7 +12841,7 @@ public final class Settings { public static final String AUTOMATIC_POWER_SAVE_MODE = "automatic_power_save_mode"; private static final Validator AUTOMATIC_POWER_SAVE_MODE_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[] {"0", "1"}); new DiscreteValueValidator(new String[] {"0", "1"}); /** * The setting that backs the disable threshold for the setPowerSavingsWarning api in Loading @@ -12849,7 +12854,7 @@ public final class Settings { public static final String DYNAMIC_POWER_SAVINGS_DISABLE_THRESHOLD = "dynamic_power_savings_disable_threshold"; private static final Validator DYNAMIC_POWER_SAVINGS_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 100); new InclusiveIntegerRangeValidator(0, 100); /** * The setting which backs the setDynamicPowerSaveHint api in PowerManager. Loading Loading @@ -12999,7 +13004,7 @@ public final class Settings { public static final String ENCODED_SURROUND_OUTPUT = "encoded_surround_output"; private static final Validator ENCODED_SURROUND_OUTPUT_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[] {"0", "1", "2", "3"}); new DiscreteValueValidator(new String[] {"0", "1", "2", "3"}); /** * Surround sounds formats that are enabled when ENCODED_SURROUND_OUTPUT is set to Loading Loading @@ -13750,7 +13755,7 @@ public final class Settings { public static final String POWER_BUTTON_LONG_PRESS = "power_button_long_press"; private static final Validator POWER_BUTTON_LONG_PRESS_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 5); new InclusiveIntegerRangeValidator(0, 5); /** * Overrides internal R.integer.config_veryLongPressOnPowerBehavior. Loading @@ -13761,7 +13766,7 @@ public final class Settings { public static final String POWER_BUTTON_VERY_LONG_PRESS = "power_button_very_long_press"; private static final Validator POWER_BUTTON_VERY_LONG_PRESS_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 1); new InclusiveIntegerRangeValidator(0, 1); /** * Settings to backup. This is here so that it's in the same place as the settings core/java/android/provider/settings/validators/ComponentNameListValidator.java 0 → 100644 +40 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.provider.settings.validators; import static android.provider.settings.validators.SettingsValidators.COMPONENT_NAME_VALIDATOR; /** * Validate a list of compoments. * * @hide */ public final class ComponentNameListValidator extends ListValidator { public ComponentNameListValidator(String separator) { super(separator); } @Override protected boolean isEntryValid(String entry) { return entry != null; } @Override protected boolean isItemValid(String item) { return COMPONENT_NAME_VALIDATOR.validate(item); } } core/java/android/provider/settings/validators/DiscreteValueValidator.java 0 → 100644 +39 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.provider.settings.validators; import android.annotation.Nullable; import com.android.internal.util.ArrayUtils; /** * Validate a value exists in an array of known good values * * @hide */ public final class DiscreteValueValidator implements Validator { private final String[] mValues; public DiscreteValueValidator(String[] values) { mValues = values; } @Override public boolean validate(@Nullable String value) { return ArrayUtils.contains(mValues, value); } } core/java/android/provider/settings/validators/InclusiveFloatRangeValidator.java 0 → 100644 +44 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.provider.settings.validators; import android.annotation.Nullable; /** * Validate a float value lies within a given (boundary inclusive) range. * * @hide */ public final class InclusiveFloatRangeValidator implements Validator { private final float mMin; private final float mMax; public InclusiveFloatRangeValidator(float min, float max) { mMin = min; mMax = max; } @Override public boolean validate(@Nullable String value) { try { final float floatValue = Float.parseFloat(value); return floatValue >= mMin && floatValue <= mMax; } catch (NumberFormatException | NullPointerException e) { return false; } } } core/java/android/provider/settings/validators/InclusiveIntegerRangeValidator.java 0 → 100644 +44 −0 File added.Preview size limit exceeded, changes collapsed. Show changes Loading
core/java/android/provider/Settings.java +67 −62 Original line number Diff line number Diff line Loading @@ -16,16 +16,19 @@ package android.provider; import static android.provider.SettingsValidators.ANY_INTEGER_VALIDATOR; import static android.provider.SettingsValidators.ANY_STRING_VALIDATOR; import static android.provider.SettingsValidators.BOOLEAN_VALIDATOR; 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; 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.BOOLEAN_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.COMPONENT_NAME_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.JSON_OBJECT_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.LENIENT_IP_ADDRESS_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.LOCALE_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.NON_NEGATIVE_INTEGER_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.NULLABLE_COMPONENT_NAME_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.PACKAGE_NAME_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.TILE_LIST_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.TTS_LIST_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.URI_VALIDATOR; import android.Manifest; import android.annotation.IntDef; Loading Loading @@ -80,7 +83,12 @@ import android.os.RemoteException; import android.os.ResultReceiver; import android.os.ServiceManager; import android.os.UserHandle; import android.provider.SettingsValidators.Validator; import android.provider.settings.validators.ComponentNameListValidator; import android.provider.settings.validators.DiscreteValueValidator; import android.provider.settings.validators.InclusiveFloatRangeValidator; import android.provider.settings.validators.InclusiveIntegerRangeValidator; import android.provider.settings.validators.PackageNameListValidator; import android.provider.settings.validators.Validator; import android.speech.tts.TextToSpeech; import android.telephony.SubscriptionManager; import android.text.TextUtils; Loading Loading @@ -3149,7 +3157,7 @@ public final class Settings { public static final String END_BUTTON_BEHAVIOR = "end_button_behavior"; private static final Validator END_BUTTON_BEHAVIOR_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 3); new InclusiveIntegerRangeValidator(0, 3); /** * END_BUTTON_BEHAVIOR value for "go home". Loading Loading @@ -3351,7 +3359,7 @@ public final class Settings { "bluetooth_discoverability"; private static final Validator BLUETOOTH_DISCOVERABILITY_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 2); new InclusiveIntegerRangeValidator(0, 2); /** * Bluetooth discoverability timeout. If this value is nonzero, then Loading Loading @@ -3495,7 +3503,7 @@ public final class Settings { public static final String PEAK_REFRESH_RATE = "peak_refresh_rate"; private static final Validator PEAK_REFRESH_RATE_VALIDATOR = new SettingsValidators.InclusiveFloatRangeValidator(24f, Float.MAX_VALUE); new InclusiveFloatRangeValidator(24f, Float.MAX_VALUE); /** * The amount of time in milliseconds before the device goes to sleep or begins Loading Loading @@ -3524,7 +3532,7 @@ public final class Settings { public static final String SCREEN_BRIGHTNESS_FOR_VR = "screen_brightness_for_vr"; private static final Validator SCREEN_BRIGHTNESS_FOR_VR_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 255); new InclusiveIntegerRangeValidator(0, 255); /** * Control whether to enable automatic brightness mode. Loading @@ -3542,7 +3550,7 @@ public final class Settings { public static final String SCREEN_AUTO_BRIGHTNESS_ADJ = "screen_auto_brightness_adj"; private static final Validator SCREEN_AUTO_BRIGHTNESS_ADJ_VALIDATOR = new SettingsValidators.InclusiveFloatRangeValidator(-1, 1); new InclusiveFloatRangeValidator(-1, 1); /** * SCREEN_BRIGHTNESS_MODE value for manual mode. Loading Loading @@ -3676,7 +3684,7 @@ public final class Settings { "haptic_feedback_intensity"; private static final Validator VIBRATION_INTENSITY_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 3); new InclusiveIntegerRangeValidator(0, 3); /** * Ringer volume. This is used internally, changing this value will not Loading Loading @@ -3766,7 +3774,7 @@ public final class Settings { public static final String MASTER_BALANCE = "master_balance"; private static final Validator MASTER_BALANCE_VALIDATOR = new SettingsValidators.InclusiveFloatRangeValidator(-1.f, 1.f); new InclusiveFloatRangeValidator(-1.f, 1.f); /** * Whether the notifications should use the ring volume (value of 1) or Loading Loading @@ -4004,7 +4012,7 @@ public final class Settings { /** @hide */ public static final Validator TIME_12_24_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[] {"12", "24", null}); new DiscreteValueValidator(new String[] {"12", "24", null}); /** * Date format string Loading Loading @@ -4090,7 +4098,7 @@ public final class Settings { /** @hide */ public static final Validator USER_ROTATION_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 3); new InclusiveIntegerRangeValidator(0, 3); /** * Control whether the rotation lock toggle in the System UI should be hidden. Loading Loading @@ -4179,7 +4187,7 @@ public final class Settings { /** @hide */ public static final Validator TTY_MODE_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 3); new InclusiveIntegerRangeValidator(0, 3); /** * Whether the sounds effects (key clicks, lid open ...) are enabled. The value is Loading Loading @@ -4381,7 +4389,7 @@ public final class Settings { /** @hide */ public static final Validator SIP_CALL_OPTIONS_VALIDATOR = new SettingsValidators.DiscreteValueValidator( new DiscreteValueValidator( new String[] {"SIP_ALWAYS", "SIP_ADDRESS_ONLY"}); /** Loading Loading @@ -4428,7 +4436,7 @@ public final class Settings { /** @hide */ public static final Validator POINTER_SPEED_VALIDATOR = new SettingsValidators.InclusiveFloatRangeValidator(-7, 7); new InclusiveFloatRangeValidator(-7, 7); /** * Whether lock-to-app will be triggered by long-press on recents. Loading Loading @@ -6352,7 +6360,7 @@ public final class Settings { public static final String LOCK_SCREEN_CUSTOM_CLOCK_FACE = "lock_screen_custom_clock_face"; private static final Validator LOCK_SCREEN_CUSTOM_CLOCK_FACE_VALIDATOR = SettingsValidators.JSON_OBJECT_VALIDATOR; JSON_OBJECT_VALIDATOR; /** * Indicates which clock face to show on lock screen and AOD while docked. Loading Loading @@ -6509,7 +6517,7 @@ public final class Settings { "enabled_accessibility_services"; private static final Validator ENABLED_ACCESSIBILITY_SERVICES_VALIDATOR = new SettingsValidators.ComponentNameListValidator(":"); new ComponentNameListValidator(":"); /** * List of the accessibility services to which the user has granted Loading @@ -6521,7 +6529,7 @@ public final class Settings { "touch_exploration_granted_accessibility_services"; private static final Validator TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES_VALIDATOR = new SettingsValidators.ComponentNameListValidator(":"); new ComponentNameListValidator(":"); /** * Whether the Global Actions Panel is enabled. Loading Loading @@ -6696,7 +6704,7 @@ public final class Settings { "accessibility_display_magnification_scale"; private static final Validator ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE_VALIDATOR = new SettingsValidators.InclusiveFloatRangeValidator(1.0f, Float.MAX_VALUE); new InclusiveFloatRangeValidator(1.0f, Float.MAX_VALUE); /** * Unused mangnification setting Loading Loading @@ -6780,7 +6788,7 @@ public final class Settings { "accessibility_captioning_preset"; private static final Validator ACCESSIBILITY_CAPTIONING_PRESET_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[]{"-1", "0", "1", "2", new DiscreteValueValidator(new String[]{"-1", "0", "1", "2", "3", "4"}); /** Loading Loading @@ -6824,7 +6832,7 @@ public final class Settings { "accessibility_captioning_edge_type"; private static final Validator ACCESSIBILITY_CAPTIONING_EDGE_TYPE_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[]{"0", "1", "2"}); new DiscreteValueValidator(new String[]{"0", "1", "2"}); /** * Integer property that specifes the edge color for captions as a Loading Loading @@ -6870,7 +6878,7 @@ public final class Settings { "accessibility_captioning_typeface"; private static final Validator ACCESSIBILITY_CAPTIONING_TYPEFACE_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[]{"DEFAULT", new DiscreteValueValidator(new String[]{"DEFAULT", "MONOSPACE", "SANS_SERIF", "SERIF"}); /** Loading @@ -6882,7 +6890,7 @@ public final class Settings { "accessibility_captioning_font_scale"; private static final Validator ACCESSIBILITY_CAPTIONING_FONT_SCALE_VALIDATOR = new SettingsValidators.InclusiveFloatRangeValidator(0.5f, 2.0f); new InclusiveFloatRangeValidator(0.5f, 2.0f); /** * Setting that specifies whether display color inversion is enabled. Loading Loading @@ -6923,7 +6931,7 @@ public final class Settings { "accessibility_display_daltonizer"; private static final Validator ACCESSIBILITY_DISPLAY_DALTONIZER_VALIDATOR = new SettingsValidators.DiscreteValueValidator( new DiscreteValueValidator( new String[] {"-1", "0", "11", "12", "13"}); /** Loading Loading @@ -7112,8 +7120,7 @@ public final class Settings { */ public static final String TTS_DEFAULT_LOCALE = "tts_default_locale"; private static final Validator TTS_DEFAULT_LOCALE_VALIDATOR = new SettingsValidators.TTSListValidator(); private static final Validator TTS_DEFAULT_LOCALE_VALIDATOR = TTS_LIST_VALIDATOR; /** * Space delimited list of plugin packages that are enabled. Loading @@ -7121,7 +7128,7 @@ public final class Settings { public static final String TTS_ENABLED_PLUGINS = "tts_enabled_plugins"; private static final Validator TTS_ENABLED_PLUGINS_VALIDATOR = new SettingsValidators.PackageNameListValidator(" "); new PackageNameListValidator(" "); /** * @deprecated Use {@link android.provider.Settings.Global#WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON} Loading Loading @@ -7315,7 +7322,7 @@ public final class Settings { "preferred_tty_mode"; private static final Validator PREFERRED_TTY_MODE_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[]{"0", "1", "2", "3"}); new DiscreteValueValidator(new String[]{"0", "1", "2", "3"}); /** * Whether the enhanced voice privacy mode is enabled. Loading Loading @@ -7630,7 +7637,7 @@ public final class Settings { public static final String INCALL_POWER_BUTTON_BEHAVIOR = "incall_power_button_behavior"; private static final Validator INCALL_POWER_BUTTON_BEHAVIOR_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[]{"1", "2"}); new DiscreteValueValidator(new String[]{"1", "2"}); /** * INCALL_POWER_BUTTON_BEHAVIOR value for "turn off screen". Loading Loading @@ -7851,7 +7858,7 @@ public final class Settings { public static final String UI_NIGHT_MODE = "ui_night_mode"; private static final Validator UI_NIGHT_MODE_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 2); new InclusiveIntegerRangeValidator(0, 2); /** * Whether screensavers are enabled. Loading @@ -7871,7 +7878,7 @@ public final class Settings { public static final String SCREENSAVER_COMPONENTS = "screensaver_components"; private static final Validator SCREENSAVER_COMPONENTS_VALIDATOR = new SettingsValidators.ComponentNameListValidator(","); new ComponentNameListValidator(","); /** * If screensavers are enabled, whether the screensaver should be automatically launched Loading Loading @@ -8023,7 +8030,7 @@ public final class Settings { "enabled_notification_assistant"; private static final Validator ENABLED_NOTIFICATION_ASSISTANT_VALIDATOR = new SettingsValidators.ComponentNameListValidator(":"); new ComponentNameListValidator(":"); /** * Read only list of the service components that the current user has explicitly allowed to Loading @@ -8038,7 +8045,7 @@ public final class Settings { public static final String ENABLED_NOTIFICATION_LISTENERS = "enabled_notification_listeners"; private static final Validator ENABLED_NOTIFICATION_LISTENERS_VALIDATOR = new SettingsValidators.ComponentNameListValidator(":"); new ComponentNameListValidator(":"); /** * Read only list of the packages that the current user has explicitly allowed to Loading @@ -8053,7 +8060,7 @@ public final class Settings { "enabled_notification_policy_access_packages"; private static final Validator ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES_VALIDATOR = new SettingsValidators.PackageNameListValidator(":"); new PackageNameListValidator(":"); /** * Defines whether managed profile ringtones should be synced from it's parent profile Loading Loading @@ -8436,7 +8443,7 @@ public final class Settings { public static final String NIGHT_DISPLAY_AUTO_MODE = "night_display_auto_mode"; private static final Validator NIGHT_DISPLAY_AUTO_MODE_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 2); new InclusiveIntegerRangeValidator(0, 2); /** * Control the color temperature of Night Display, represented in Kelvin. Loading Loading @@ -8497,7 +8504,7 @@ public final class Settings { public static final String ENABLED_VR_LISTENERS = "enabled_vr_listeners"; private static final Validator ENABLED_VR_LISTENERS_VALIDATOR = new SettingsValidators.ComponentNameListValidator(":"); new ComponentNameListValidator(":"); /** * Behavior of the display while in VR mode. Loading @@ -8509,7 +8516,7 @@ public final class Settings { public static final String VR_DISPLAY_MODE = "vr_display_mode"; private static final Validator VR_DISPLAY_MODE_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[]{"0", "1"}); new DiscreteValueValidator(new String[]{"0", "1"}); /** * Lower the display persistence while the system is in VR mode. Loading Loading @@ -8628,8 +8635,7 @@ public final class Settings { */ public static final String QS_TILES = "sysui_qs_tiles"; private static final Validator QS_TILES_VALIDATOR = new SettingsValidators.TileListValidator(); private static final Validator QS_TILES_VALIDATOR = TILE_LIST_VALIDATOR; /** * Specifies whether the web action API is enabled. Loading Loading @@ -8695,8 +8701,7 @@ public final class Settings { */ public static final String QS_AUTO_ADDED_TILES = "qs_auto_tiles"; private static final Validator QS_AUTO_ADDED_TILES_VALIDATOR = new SettingsValidators.TileListValidator(); private static final Validator QS_AUTO_ADDED_TILES_VALIDATOR = TILE_LIST_VALIDATOR; /** * Whether the Lockdown button should be shown in the power menu. Loading Loading @@ -8857,7 +8862,7 @@ public final class Settings { "theme_customization_overlay_packages"; private static final Validator THEME_CUSTOMIZATION_OVERLAY_PACKAGES_VALIDATOR = SettingsValidators.JSON_OBJECT_VALIDATOR; JSON_OBJECT_VALIDATOR; /** * Navigation bar mode. Loading @@ -8869,7 +8874,7 @@ public final class Settings { public static final String NAVIGATION_MODE = "navigation_mode"; private static final Validator NAVIGATION_MODE_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[] {"0", "1", "2"}); new DiscreteValueValidator(new String[] {"0", "1", "2"}); /** * Controls whether aware is enabled. Loading Loading @@ -10721,7 +10726,7 @@ public final class Settings { "network_recommendations_enabled"; private static final Validator NETWORK_RECOMMENDATIONS_ENABLED_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[] {"-1", "0", "1"}); new DiscreteValueValidator(new String[] {"-1", "0", "1"}); /** * Which package name to use for network recommendations. If null, network recommendations Loading Loading @@ -12572,7 +12577,7 @@ public final class Settings { public static final String EMERGENCY_TONE = "emergency_tone"; private static final Validator EMERGENCY_TONE_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[] {"0", "1", "2"}); new DiscreteValueValidator(new String[] {"0", "1", "2"}); /** * CDMA only settings Loading Loading @@ -12602,7 +12607,7 @@ public final class Settings { "enable_automatic_system_server_heap_dumps"; private static final Validator ENABLE_AUTOMATIC_SYSTEM_SERVER_HEAP_DUMPS_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[] {"0", "1"}); new DiscreteValueValidator(new String[] {"0", "1"}); /** * See RIL_PreferredNetworkType in ril.h Loading Loading @@ -12796,7 +12801,7 @@ public final class Settings { "low_power_sticky_auto_disable_level"; private static final Validator LOW_POWER_MODE_STICKY_AUTO_DISABLE_LEVEL_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 100); new InclusiveIntegerRangeValidator(0, 100); /** * Whether sticky battery saver should be deactivated once the battery level has reached the Loading @@ -12808,7 +12813,7 @@ public final class Settings { "low_power_sticky_auto_disable_enabled"; private static final Validator LOW_POWER_MODE_STICKY_AUTO_DISABLE_ENABLED_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[] {"0", "1"}); new DiscreteValueValidator(new String[] {"0", "1"}); /** * Battery level [1-100] at which low power mode automatically turns on. Loading @@ -12823,7 +12828,7 @@ public final class Settings { public static final String LOW_POWER_MODE_TRIGGER_LEVEL = "low_power_trigger_level"; private static final Validator LOW_POWER_MODE_TRIGGER_LEVEL_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 100); new InclusiveIntegerRangeValidator(0, 100); /** * Whether battery saver is currently set to trigger based on percentage, dynamic power Loading @@ -12836,7 +12841,7 @@ public final class Settings { public static final String AUTOMATIC_POWER_SAVE_MODE = "automatic_power_save_mode"; private static final Validator AUTOMATIC_POWER_SAVE_MODE_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[] {"0", "1"}); new DiscreteValueValidator(new String[] {"0", "1"}); /** * The setting that backs the disable threshold for the setPowerSavingsWarning api in Loading @@ -12849,7 +12854,7 @@ public final class Settings { public static final String DYNAMIC_POWER_SAVINGS_DISABLE_THRESHOLD = "dynamic_power_savings_disable_threshold"; private static final Validator DYNAMIC_POWER_SAVINGS_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 100); new InclusiveIntegerRangeValidator(0, 100); /** * The setting which backs the setDynamicPowerSaveHint api in PowerManager. Loading Loading @@ -12999,7 +13004,7 @@ public final class Settings { public static final String ENCODED_SURROUND_OUTPUT = "encoded_surround_output"; private static final Validator ENCODED_SURROUND_OUTPUT_VALIDATOR = new SettingsValidators.DiscreteValueValidator(new String[] {"0", "1", "2", "3"}); new DiscreteValueValidator(new String[] {"0", "1", "2", "3"}); /** * Surround sounds formats that are enabled when ENCODED_SURROUND_OUTPUT is set to Loading Loading @@ -13750,7 +13755,7 @@ public final class Settings { public static final String POWER_BUTTON_LONG_PRESS = "power_button_long_press"; private static final Validator POWER_BUTTON_LONG_PRESS_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 5); new InclusiveIntegerRangeValidator(0, 5); /** * Overrides internal R.integer.config_veryLongPressOnPowerBehavior. Loading @@ -13761,7 +13766,7 @@ public final class Settings { public static final String POWER_BUTTON_VERY_LONG_PRESS = "power_button_very_long_press"; private static final Validator POWER_BUTTON_VERY_LONG_PRESS_VALIDATOR = new SettingsValidators.InclusiveIntegerRangeValidator(0, 1); new InclusiveIntegerRangeValidator(0, 1); /** * Settings to backup. This is here so that it's in the same place as the settings
core/java/android/provider/settings/validators/ComponentNameListValidator.java 0 → 100644 +40 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.provider.settings.validators; import static android.provider.settings.validators.SettingsValidators.COMPONENT_NAME_VALIDATOR; /** * Validate a list of compoments. * * @hide */ public final class ComponentNameListValidator extends ListValidator { public ComponentNameListValidator(String separator) { super(separator); } @Override protected boolean isEntryValid(String entry) { return entry != null; } @Override protected boolean isItemValid(String item) { return COMPONENT_NAME_VALIDATOR.validate(item); } }
core/java/android/provider/settings/validators/DiscreteValueValidator.java 0 → 100644 +39 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.provider.settings.validators; import android.annotation.Nullable; import com.android.internal.util.ArrayUtils; /** * Validate a value exists in an array of known good values * * @hide */ public final class DiscreteValueValidator implements Validator { private final String[] mValues; public DiscreteValueValidator(String[] values) { mValues = values; } @Override public boolean validate(@Nullable String value) { return ArrayUtils.contains(mValues, value); } }
core/java/android/provider/settings/validators/InclusiveFloatRangeValidator.java 0 → 100644 +44 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.provider.settings.validators; import android.annotation.Nullable; /** * Validate a float value lies within a given (boundary inclusive) range. * * @hide */ public final class InclusiveFloatRangeValidator implements Validator { private final float mMin; private final float mMax; public InclusiveFloatRangeValidator(float min, float max) { mMin = min; mMax = max; } @Override public boolean validate(@Nullable String value) { try { final float floatValue = Float.parseFloat(value); return floatValue >= mMin && floatValue <= mMax; } catch (NumberFormatException | NullPointerException e) { return false; } } }
core/java/android/provider/settings/validators/InclusiveIntegerRangeValidator.java 0 → 100644 +44 −0 File added.Preview size limit exceeded, changes collapsed. Show changes