Merge changes from topic "ExtractBackupDataFromSettings"
* changes: Move the list of settings to backup out of the Settings class Move the validators out of the settings class
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -24,6 +24,8 @@ android_test {
|
||||
// because this test is not an instrumentation test. (because the target runs in the system process.)
|
||||
srcs: [
|
||||
"test/**/*.java",
|
||||
"src/android/provider/settings/backup/*",
|
||||
"src/android/provider/settings/validators/*",
|
||||
"src/com/android/providers/settings/SettingsBackupAgent.java",
|
||||
"src/com/android/providers/settings/SettingsState.java",
|
||||
"src/com/android/providers/settings/SettingsHelper.java",
|
||||
@@ -31,6 +33,8 @@ android_test {
|
||||
static_libs: [
|
||||
"androidx.test.rules",
|
||||
"SettingsLibDisplayDensityUtils",
|
||||
"platform-test-annotations",
|
||||
"truth-prebuilt",
|
||||
],
|
||||
libs: [
|
||||
"android.test.base",
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.backup;
|
||||
|
||||
import android.provider.Settings;
|
||||
|
||||
/** Information related to the backup of Global settings */
|
||||
public class GlobalSettings {
|
||||
|
||||
/**
|
||||
* These keys may be mentioned in the SETTINGS_TO_BACKUP arrays in SystemSettings
|
||||
* and SecureSettings as well. This is because those tables drive both backup and
|
||||
* restore, and restore needs to properly whitelist keys that used to live
|
||||
* in those namespaces.
|
||||
*
|
||||
* NOTE: Settings are backed up and restored in the order they appear
|
||||
* in this array. If you have one setting depending on another,
|
||||
* make sure that they are ordered appropriately.
|
||||
*
|
||||
* NOTE: This table should only be used for settings which should be restored
|
||||
* between different types of devices
|
||||
* {@see #Settings.Secure.DEVICE_SPECIFIC_SETTINGS_TO_BACKUP}
|
||||
*
|
||||
* NOTE: All settings which are backed up should have a corresponding validator.
|
||||
*/
|
||||
public static final String[] SETTINGS_TO_BACKUP = {
|
||||
Settings.Global.APPLY_RAMPING_RINGER,
|
||||
Settings.Global.BUGREPORT_IN_POWER_MENU,
|
||||
Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
|
||||
Settings.Global.APP_AUTO_RESTRICTION_ENABLED,
|
||||
Settings.Global.AUTO_TIME,
|
||||
Settings.Global.AUTO_TIME_ZONE,
|
||||
Settings.Global.POWER_SOUNDS_ENABLED,
|
||||
Settings.Global.DOCK_SOUNDS_ENABLED,
|
||||
Settings.Global.CHARGING_SOUNDS_ENABLED,
|
||||
Settings.Global.USB_MASS_STORAGE_ENABLED,
|
||||
Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED,
|
||||
Settings.Global.WIFI_WAKEUP_ENABLED,
|
||||
Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
|
||||
Settings.Global.USE_OPEN_WIFI_PACKAGE,
|
||||
Settings.Global.WIFI_WATCHDOG_POOR_NETWORK_TEST_ENABLED,
|
||||
Settings.Global.EMERGENCY_TONE,
|
||||
Settings.Global.CALL_AUTO_RETRY,
|
||||
Settings.Global.DOCK_AUDIO_MEDIA_ENABLED,
|
||||
Settings.Global.ENABLE_AUTOMATIC_SYSTEM_SERVER_HEAP_DUMPS,
|
||||
Settings.Global.ENCODED_SURROUND_OUTPUT,
|
||||
Settings.Global.ENCODED_SURROUND_OUTPUT_ENABLED_FORMATS,
|
||||
Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL,
|
||||
Settings.Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_ENABLED,
|
||||
Settings.Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_LEVEL,
|
||||
Settings.Global.BLUETOOTH_ON,
|
||||
Settings.Global.PRIVATE_DNS_MODE,
|
||||
Settings.Global.PRIVATE_DNS_SPECIFIER,
|
||||
Settings.Global.SOFT_AP_TIMEOUT_ENABLED,
|
||||
Settings.Global.ZEN_DURATION,
|
||||
Settings.Global.CHARGING_VIBRATION_ENABLED,
|
||||
Settings.Global.AWARE_ALLOWED,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* 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.backup;
|
||||
|
||||
import android.annotation.UnsupportedAppUsage;
|
||||
import android.provider.Settings;
|
||||
|
||||
/** Information relating to the Secure settings which should be backed up */
|
||||
public class SecureSettings {
|
||||
|
||||
/**
|
||||
* NOTE: Settings are backed up and restored in the order they appear
|
||||
* in this array. If you have one setting depending on another,
|
||||
* make sure that they are ordered appropriately.
|
||||
*/
|
||||
@UnsupportedAppUsage
|
||||
public static final String[] SETTINGS_TO_BACKUP = {
|
||||
Settings.Secure.BUGREPORT_IN_POWER_MENU, // moved to global
|
||||
Settings.Secure.ALLOW_MOCK_LOCATION,
|
||||
Settings.Secure.USB_MASS_STORAGE_ENABLED, // moved to global
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED,
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER,
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED,
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
|
||||
Settings.Secure.AUTOFILL_SERVICE,
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
|
||||
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
|
||||
Settings.Secure.ENABLED_VR_LISTENERS,
|
||||
Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES,
|
||||
Settings.Secure.TOUCH_EXPLORATION_ENABLED,
|
||||
Settings.Secure.ACCESSIBILITY_ENABLED,
|
||||
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE,
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT,
|
||||
Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN,
|
||||
Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED,
|
||||
Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN,
|
||||
Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED,
|
||||
Settings.Secure.ACCESSIBILITY_CAPTIONING_PRESET,
|
||||
Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED,
|
||||
Settings.Secure.ACCESSIBILITY_CAPTIONING_LOCALE,
|
||||
Settings.Secure.ACCESSIBILITY_CAPTIONING_BACKGROUND_COLOR,
|
||||
Settings.Secure.ACCESSIBILITY_CAPTIONING_FOREGROUND_COLOR,
|
||||
Settings.Secure.ACCESSIBILITY_CAPTIONING_EDGE_TYPE,
|
||||
Settings.Secure.ACCESSIBILITY_CAPTIONING_EDGE_COLOR,
|
||||
Settings.Secure.ACCESSIBILITY_CAPTIONING_TYPEFACE,
|
||||
Settings.Secure.ACCESSIBILITY_CAPTIONING_FONT_SCALE,
|
||||
Settings.Secure.ACCESSIBILITY_CAPTIONING_WINDOW_COLOR,
|
||||
Settings.Secure.TTS_DEFAULT_RATE,
|
||||
Settings.Secure.TTS_DEFAULT_PITCH,
|
||||
Settings.Secure.TTS_DEFAULT_SYNTH,
|
||||
Settings.Secure.TTS_ENABLED_PLUGINS,
|
||||
Settings.Secure.TTS_DEFAULT_LOCALE,
|
||||
Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD,
|
||||
Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, // moved to global
|
||||
Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY, // moved to global
|
||||
Settings.Secure.WIFI_NUM_OPEN_NETWORKS_KEPT, // moved to global
|
||||
Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND,
|
||||
Settings.Secure.MOUNT_UMS_AUTOSTART,
|
||||
Settings.Secure.MOUNT_UMS_PROMPT,
|
||||
Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED,
|
||||
Settings.Secure.DOUBLE_TAP_TO_WAKE,
|
||||
Settings.Secure.WAKE_GESTURE_ENABLED,
|
||||
Settings.Secure.LONG_PRESS_TIMEOUT,
|
||||
Settings.Secure.CAMERA_GESTURE_DISABLED,
|
||||
Settings.Secure.ACCESSIBILITY_AUTOCLICK_ENABLED,
|
||||
Settings.Secure.ACCESSIBILITY_AUTOCLICK_DELAY,
|
||||
Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON,
|
||||
Settings.Secure.PREFERRED_TTY_MODE,
|
||||
Settings.Secure.ENHANCED_VOICE_PRIVACY_ENABLED,
|
||||
Settings.Secure.TTY_MODE_ENABLED,
|
||||
Settings.Secure.RTT_CALLING_MODE,
|
||||
Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
|
||||
Settings.Secure.NIGHT_DISPLAY_CUSTOM_START_TIME,
|
||||
Settings.Secure.NIGHT_DISPLAY_CUSTOM_END_TIME,
|
||||
Settings.Secure.NIGHT_DISPLAY_COLOR_TEMPERATURE,
|
||||
Settings.Secure.NIGHT_DISPLAY_AUTO_MODE,
|
||||
Settings.Secure.DISPLAY_WHITE_BALANCE_ENABLED,
|
||||
Settings.Secure.SYNC_PARENT_SOUNDS,
|
||||
Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED,
|
||||
Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED,
|
||||
Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED,
|
||||
Settings.Secure.QS_TILES,
|
||||
Settings.Secure.DOZE_ENABLED,
|
||||
Settings.Secure.DOZE_ALWAYS_ON,
|
||||
Settings.Secure.DOZE_PICK_UP_GESTURE,
|
||||
Settings.Secure.DOZE_DOUBLE_TAP_GESTURE,
|
||||
Settings.Secure.DOZE_TAP_SCREEN_GESTURE,
|
||||
Settings.Secure.DOZE_WAKE_LOCK_SCREEN_GESTURE,
|
||||
Settings.Secure.DOZE_WAKE_DISPLAY_GESTURE,
|
||||
Settings.Secure.NFC_PAYMENT_DEFAULT_COMPONENT,
|
||||
Settings.Secure.AUTOMATIC_STORAGE_MANAGER_DAYS_TO_RETAIN,
|
||||
Settings.Secure.FACE_UNLOCK_KEYGUARD_ENABLED,
|
||||
Settings.Secure.SHOW_MEDIA_WHEN_BYPASSING,
|
||||
Settings.Secure.FACE_UNLOCK_DISMISSES_KEYGUARD,
|
||||
Settings.Secure.FACE_UNLOCK_APP_ENABLED,
|
||||
Settings.Secure.FACE_UNLOCK_ALWAYS_REQUIRE_CONFIRMATION,
|
||||
Settings.Secure.ASSIST_GESTURE_ENABLED,
|
||||
Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED,
|
||||
Settings.Secure.ASSIST_GESTURE_WAKE_ENABLED,
|
||||
Settings.Secure.VR_DISPLAY_MODE,
|
||||
Settings.Secure.NOTIFICATION_BADGING,
|
||||
Settings.Secure.NOTIFICATION_BUBBLES,
|
||||
Settings.Secure.NOTIFICATION_DISMISS_RTL,
|
||||
Settings.Secure.QS_AUTO_ADDED_TILES,
|
||||
Settings.Secure.SCREENSAVER_ENABLED,
|
||||
Settings.Secure.SCREENSAVER_COMPONENTS,
|
||||
Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
|
||||
Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
|
||||
Settings.Secure.LOCKDOWN_IN_POWER_MENU,
|
||||
Settings.Secure.SHOW_FIRST_CRASH_DIALOG_DEV_OPTION,
|
||||
Settings.Secure.VOLUME_HUSH_GESTURE,
|
||||
Settings.Secure.MANUAL_RINGER_TOGGLE_COUNT,
|
||||
Settings.Secure.HUSH_GESTURE_USED,
|
||||
Settings.Secure.IN_CALL_NOTIFICATION_ENABLED,
|
||||
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
|
||||
Settings.Secure.LOCK_SCREEN_CUSTOM_CLOCK_FACE,
|
||||
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
|
||||
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS,
|
||||
Settings.Secure.SHOW_NOTIFICATION_SNOOZE,
|
||||
Settings.Secure.ZEN_DURATION,
|
||||
Settings.Secure.SHOW_ZEN_UPGRADE_NOTIFICATION,
|
||||
Settings.Secure.SHOW_ZEN_SETTINGS_SUGGESTION,
|
||||
Settings.Secure.ZEN_SETTINGS_UPDATED,
|
||||
Settings.Secure.ZEN_SETTINGS_SUGGESTION_VIEWED,
|
||||
Settings.Secure.CHARGING_SOUNDS_ENABLED,
|
||||
Settings.Secure.CHARGING_VIBRATION_ENABLED,
|
||||
Settings.Secure.ACCESSIBILITY_NON_INTERACTIVE_UI_TIMEOUT_MS,
|
||||
Settings.Secure.ACCESSIBILITY_INTERACTIVE_UI_TIMEOUT_MS,
|
||||
Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL,
|
||||
Settings.Secure.TRUST_AGENTS_EXTEND_UNLOCK,
|
||||
Settings.Secure.UI_NIGHT_MODE,
|
||||
Settings.Secure.LOCK_SCREEN_WHEN_TRUST_LOST,
|
||||
Settings.Secure.SKIP_GESTURE,
|
||||
Settings.Secure.SKIP_DIRECTION,
|
||||
Settings.Secure.SILENCE_GESTURE,
|
||||
Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES,
|
||||
Settings.Secure.NAVIGATION_MODE,
|
||||
Settings.Secure.AWARE_ENABLED,
|
||||
Settings.Secure.SKIP_GESTURE_COUNT,
|
||||
Settings.Secure.SKIP_TOUCH_COUNT,
|
||||
Settings.Secure.SILENCE_ALARMS_GESTURE_COUNT,
|
||||
Settings.Secure.SILENCE_CALL_GESTURE_COUNT,
|
||||
Settings.Secure.SILENCE_TIMER_GESTURE_COUNT,
|
||||
Settings.Secure.SILENCE_ALARMS_TOUCH_COUNT,
|
||||
Settings.Secure.SILENCE_CALL_TOUCH_COUNT,
|
||||
Settings.Secure.SILENCE_TIMER_TOUCH_COUNT,
|
||||
Settings.Secure.DARK_MODE_DIALOG_SEEN,
|
||||
Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED,
|
||||
Settings.Secure.AWARE_LOCK_ENABLED
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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.backup;
|
||||
|
||||
import android.annotation.UnsupportedAppUsage;
|
||||
import android.provider.Settings;
|
||||
|
||||
/** Information about the system settings to back up */
|
||||
public class SystemSettings {
|
||||
|
||||
/**
|
||||
* Settings to backup.
|
||||
*
|
||||
* NOTE: Settings are backed up and restored in the order they appear
|
||||
* in this array. If you have one setting depending on another,
|
||||
* make sure that they are ordered appropriately.
|
||||
*/
|
||||
@UnsupportedAppUsage
|
||||
public static final String[] SETTINGS_TO_BACKUP = {
|
||||
Settings.System.STAY_ON_WHILE_PLUGGED_IN, // moved to global
|
||||
Settings.System.WIFI_USE_STATIC_IP,
|
||||
Settings.System.WIFI_STATIC_IP,
|
||||
Settings.System.WIFI_STATIC_GATEWAY,
|
||||
Settings.System.WIFI_STATIC_NETMASK,
|
||||
Settings.System.WIFI_STATIC_DNS1,
|
||||
Settings.System.WIFI_STATIC_DNS2,
|
||||
Settings.System.BLUETOOTH_DISCOVERABILITY,
|
||||
Settings.System.BLUETOOTH_DISCOVERABILITY_TIMEOUT,
|
||||
Settings.System.FONT_SCALE,
|
||||
Settings.System.DIM_SCREEN,
|
||||
Settings.System.SCREEN_OFF_TIMEOUT,
|
||||
Settings.System.SCREEN_BRIGHTNESS_MODE,
|
||||
Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ,
|
||||
Settings.System.SCREEN_BRIGHTNESS_FOR_VR,
|
||||
Settings.System.ADAPTIVE_SLEEP,
|
||||
Settings.System.VIBRATE_INPUT_DEVICES,
|
||||
Settings.System.MODE_RINGER_STREAMS_AFFECTED,
|
||||
Settings.System.TEXT_AUTO_REPLACE,
|
||||
Settings.System.TEXT_AUTO_CAPS,
|
||||
Settings.System.TEXT_AUTO_PUNCTUATE,
|
||||
Settings.System.TEXT_SHOW_PASSWORD,
|
||||
Settings.System.AUTO_TIME, // moved to global
|
||||
Settings.System.AUTO_TIME_ZONE, // moved to global
|
||||
Settings.System.TIME_12_24,
|
||||
Settings.System.DATE_FORMAT,
|
||||
Settings.System.DTMF_TONE_WHEN_DIALING,
|
||||
Settings.System.DTMF_TONE_TYPE_WHEN_DIALING,
|
||||
Settings.System.HEARING_AID,
|
||||
Settings.System.TTY_MODE,
|
||||
Settings.System.MASTER_MONO,
|
||||
Settings.System.MASTER_BALANCE,
|
||||
Settings.System.SOUND_EFFECTS_ENABLED,
|
||||
Settings.System.HAPTIC_FEEDBACK_ENABLED,
|
||||
Settings.System.POWER_SOUNDS_ENABLED, // moved to global
|
||||
Settings.System.DOCK_SOUNDS_ENABLED, // moved to global
|
||||
Settings.System.LOCKSCREEN_SOUNDS_ENABLED,
|
||||
Settings.System.SHOW_WEB_SUGGESTIONS,
|
||||
Settings.System.SIP_CALL_OPTIONS,
|
||||
Settings.System.SIP_RECEIVE_CALLS,
|
||||
Settings.System.POINTER_SPEED,
|
||||
Settings.System.VIBRATE_WHEN_RINGING,
|
||||
Settings.System.RINGTONE,
|
||||
Settings.System.LOCK_TO_APP_ENABLED,
|
||||
Settings.System.NOTIFICATION_SOUND,
|
||||
Settings.System.ACCELEROMETER_ROTATION,
|
||||
Settings.System.SHOW_BATTERY_PERCENT,
|
||||
Settings.System.NOTIFICATION_VIBRATION_INTENSITY,
|
||||
Settings.System.RING_VIBRATION_INTENSITY,
|
||||
Settings.System.HAPTIC_FEEDBACK_INTENSITY,
|
||||
Settings.System.DISPLAY_COLOR_MODE,
|
||||
Settings.System.ALARM_ALERT,
|
||||
Settings.System.NOTIFICATION_LIGHT_PULSE,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* 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.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.PACKAGE_NAME_VALIDATOR;
|
||||
import static android.provider.settings.validators.SettingsValidators.PERCENTAGE_INTEGER_VALIDATOR;
|
||||
|
||||
import android.media.AudioFormat;
|
||||
import android.os.BatteryManager;
|
||||
import android.provider.Settings.Global;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Validators for Global settings
|
||||
*/
|
||||
public class GlobalSettingsValidators {
|
||||
/**
|
||||
* All settings in {@link Global.SETTINGS_TO_BACKUP} array *must* have a non-null validator,
|
||||
* otherwise they won't be restored.
|
||||
*/
|
||||
public static final Map<String, Validator> VALIDATORS = new ArrayMap<>();
|
||||
|
||||
static {
|
||||
VALIDATORS.put(Global.APPLY_RAMPING_RINGER, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.BUGREPORT_IN_POWER_MENU, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Global.STAY_ON_WHILE_PLUGGED_IN,
|
||||
value -> {
|
||||
try {
|
||||
int val = Integer.parseInt(value);
|
||||
return (val == 0)
|
||||
|| (val == BatteryManager.BATTERY_PLUGGED_AC)
|
||||
|| (val == BatteryManager.BATTERY_PLUGGED_USB)
|
||||
|| (val == BatteryManager.BATTERY_PLUGGED_WIRELESS)
|
||||
|| (val
|
||||
== (BatteryManager.BATTERY_PLUGGED_AC
|
||||
| BatteryManager.BATTERY_PLUGGED_USB))
|
||||
|| (val
|
||||
== (BatteryManager.BATTERY_PLUGGED_AC
|
||||
| BatteryManager.BATTERY_PLUGGED_WIRELESS))
|
||||
|| (val
|
||||
== (BatteryManager.BATTERY_PLUGGED_USB
|
||||
| BatteryManager.BATTERY_PLUGGED_WIRELESS))
|
||||
|| (val
|
||||
== (BatteryManager.BATTERY_PLUGGED_AC
|
||||
| BatteryManager.BATTERY_PLUGGED_USB
|
||||
| BatteryManager.BATTERY_PLUGGED_WIRELESS));
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
VALIDATORS.put(Global.AUTO_TIME, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.AUTO_TIME_ZONE, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.POWER_SOUNDS_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.DOCK_SOUNDS_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.CHARGING_SOUNDS_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.USB_MASS_STORAGE_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Global.NETWORK_RECOMMENDATIONS_ENABLED,
|
||||
new DiscreteValueValidator(new String[] {"-1", "0", "1"}));
|
||||
VALIDATORS.put(Global.WIFI_WAKEUP_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Global.USE_OPEN_WIFI_PACKAGE,
|
||||
value -> (value == null) || PACKAGE_NAME_VALIDATOR.validate(value));
|
||||
VALIDATORS.put(Global.WIFI_WATCHDOG_POOR_NETWORK_TEST_ENABLED, ANY_STRING_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Global.EMERGENCY_TONE, new DiscreteValueValidator(new String[] {"0", "1", "2"}));
|
||||
VALIDATORS.put(Global.CALL_AUTO_RETRY, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.DOCK_AUDIO_MEDIA_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Global.ENABLE_AUTOMATIC_SYSTEM_SERVER_HEAP_DUMPS,
|
||||
new DiscreteValueValidator(new String[] {"0", "1"}));
|
||||
VALIDATORS.put(
|
||||
Global.ENCODED_SURROUND_OUTPUT,
|
||||
new DiscreteValueValidator(new String[] {"0", "1", "2", "3"}));
|
||||
VALIDATORS.put(
|
||||
Global.ENCODED_SURROUND_OUTPUT_ENABLED_FORMATS,
|
||||
value -> {
|
||||
try {
|
||||
String[] surroundFormats = TextUtils.split(value, ",");
|
||||
for (String format : surroundFormats) {
|
||||
int audioFormat = Integer.valueOf(format);
|
||||
boolean isSurroundFormat = false;
|
||||
for (int sf : AudioFormat.SURROUND_SOUND_ENCODING) {
|
||||
if (sf == audioFormat) {
|
||||
isSurroundFormat = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isSurroundFormat) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
VALIDATORS.put(
|
||||
Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_LEVEL,
|
||||
new InclusiveIntegerRangeValidator(0, 100));
|
||||
VALIDATORS.put(
|
||||
Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_ENABLED,
|
||||
new DiscreteValueValidator(new String[] {"0", "1"}));
|
||||
VALIDATORS.put(Global.LOW_POWER_MODE_TRIGGER_LEVEL, PERCENTAGE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Global.LOW_POWER_MODE_TRIGGER_LEVEL_MAX, PERCENTAGE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Global.AUTOMATIC_POWER_SAVE_MODE,
|
||||
new DiscreteValueValidator(new String[] {"0", "1"}));
|
||||
VALIDATORS.put(
|
||||
Global.DYNAMIC_POWER_SAVINGS_DISABLE_THRESHOLD, PERCENTAGE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Global.BLUETOOTH_ON, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.PRIVATE_DNS_MODE, ANY_STRING_VALIDATOR);
|
||||
VALIDATORS.put(Global.PRIVATE_DNS_SPECIFIER, ANY_STRING_VALIDATOR);
|
||||
VALIDATORS.put(Global.SOFT_AP_TIMEOUT_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.WIFI_SCAN_THROTTLE_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.APP_AUTO_RESTRICTION_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.ZEN_DURATION, ANY_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Global.CHARGING_VIBRATION_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.DEVICE_PROVISIONING_MOBILE_DATA_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.REQUIRE_PASSWORD_TO_DECRYPT, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.DEVICE_DEMO_MODE, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.WIFI_PNO_FREQUENCY_CULLING_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.WIFI_PNO_RECENCY_SORTING_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.WIFI_LINK_PROBING_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.AWARE_ALLOWED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Global.POWER_BUTTON_LONG_PRESS, new InclusiveIntegerRangeValidator(0, 5));
|
||||
VALIDATORS.put(
|
||||
Global.POWER_BUTTON_VERY_LONG_PRESS, new InclusiveIntegerRangeValidator(0, 1));
|
||||
}
|
||||
}
|
||||
@@ -23,11 +23,11 @@ import android.annotation.Nullable;
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public final class InclusiveFloatRangeValidator implements Validator {
|
||||
final class InclusiveFloatRangeValidator implements Validator {
|
||||
private final float mMin;
|
||||
private final float mMax;
|
||||
|
||||
public InclusiveFloatRangeValidator(float min, float max) {
|
||||
InclusiveFloatRangeValidator(float min, float max) {
|
||||
mMin = min;
|
||||
mMax = max;
|
||||
}
|
||||
@@ -23,11 +23,11 @@ import android.annotation.Nullable;
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public final class InclusiveIntegerRangeValidator implements Validator {
|
||||
final class InclusiveIntegerRangeValidator implements Validator {
|
||||
private final int mMin;
|
||||
private final int mMax;
|
||||
|
||||
public InclusiveIntegerRangeValidator(int min, int max) {
|
||||
InclusiveIntegerRangeValidator(int min, int max) {
|
||||
mMin = min;
|
||||
mMax = max;
|
||||
}
|
||||
@@ -23,8 +23,8 @@ import static android.provider.settings.validators.SettingsValidators.PACKAGE_NA
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public final class PackageNameListValidator extends ListValidator {
|
||||
public PackageNameListValidator(String separator) {
|
||||
final class PackageNameListValidator extends ListValidator {
|
||||
PackageNameListValidator(String separator) {
|
||||
super(separator);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* 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.ANY_INTEGER_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.JSON_OBJECT_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 android.provider.Settings.Secure;
|
||||
import android.util.ArrayMap;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Validators for the Secure Settings.
|
||||
*/
|
||||
public class SecureSettingsValidators {
|
||||
/**
|
||||
* All settings in {@link Secure.SETTINGS_TO_BACKUP} and {@link
|
||||
* Secure.DEVICE_SPECIFIC_SETTINGS_TO_BACKUP} array *must* have a non-null validator, otherwise
|
||||
* they won't be restored.
|
||||
*/
|
||||
public static final Map<String, Validator> VALIDATORS = new ArrayMap<>();
|
||||
|
||||
static {
|
||||
VALIDATORS.put(Secure.BUGREPORT_IN_POWER_MENU, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ALLOW_MOCK_LOCATION, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.USB_MASS_STORAGE_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Secure.ACCESSIBILITY_DISPLAY_DALTONIZER,
|
||||
new DiscreteValueValidator(new String[] {"-1", "0", "11", "12", "13"}));
|
||||
VALIDATORS.put(Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, 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));
|
||||
VALIDATORS.put(
|
||||
Secure.ENABLED_ACCESSIBILITY_SERVICES, COLON_SEPARATED_COMPONENT_LIST_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ENABLED_VR_LISTENERS, COLON_SEPARATED_COMPONENT_LIST_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES,
|
||||
COLON_SEPARATED_COMPONENT_LIST_VALIDATOR);
|
||||
VALIDATORS.put(Secure.TOUCH_EXPLORATION_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ACCESSIBILITY_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, NULLABLE_COMPONENT_NAME_VALIDATOR);
|
||||
// technically either ComponentName or class name, but there's proper value
|
||||
// validation at callsites, so allow any non-null string
|
||||
VALIDATORS.put(Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT, value -> value != null);
|
||||
VALIDATORS.put(Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ACCESSIBILITY_SHORTCUT_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Secure.ACCESSIBILITY_CAPTIONING_PRESET,
|
||||
new DiscreteValueValidator(new String[] {"-1", "0", "1", "2", "3", "4"}));
|
||||
VALIDATORS.put(Secure.ACCESSIBILITY_CAPTIONING_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ACCESSIBILITY_CAPTIONING_LOCALE, LOCALE_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ACCESSIBILITY_CAPTIONING_BACKGROUND_COLOR, ANY_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ACCESSIBILITY_CAPTIONING_FOREGROUND_COLOR, ANY_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Secure.ACCESSIBILITY_CAPTIONING_EDGE_TYPE,
|
||||
new DiscreteValueValidator(new String[] {"0", "1", "2"}));
|
||||
VALIDATORS.put(Secure.ACCESSIBILITY_CAPTIONING_EDGE_COLOR, ANY_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Secure.ACCESSIBILITY_CAPTIONING_TYPEFACE,
|
||||
new DiscreteValueValidator(
|
||||
new String[] {"DEFAULT", "MONOSPACE", "SANS_SERIF", "SERIF"}));
|
||||
VALIDATORS.put(
|
||||
Secure.ACCESSIBILITY_CAPTIONING_FONT_SCALE,
|
||||
new InclusiveFloatRangeValidator(0.5f, 2.0f));
|
||||
VALIDATORS.put(Secure.ACCESSIBILITY_CAPTIONING_WINDOW_COLOR, ANY_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.TTS_DEFAULT_RATE, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.TTS_DEFAULT_PITCH, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.TTS_DEFAULT_SYNTH, PACKAGE_NAME_VALIDATOR);
|
||||
VALIDATORS.put(Secure.TTS_ENABLED_PLUGINS, new PackageNameListValidator(" "));
|
||||
VALIDATORS.put(Secure.TTS_DEFAULT_LOCALE, TTS_LIST_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SHOW_IME_WITH_HARD_KEYBOARD, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.WIFI_NUM_OPEN_NETWORKS_KEPT, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.MOUNT_PLAY_NOTIFICATION_SND, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.MOUNT_UMS_AUTOSTART, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.MOUNT_UMS_PROMPT, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.MOUNT_UMS_NOTIFY_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.DOUBLE_TAP_TO_WAKE, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.WAKE_GESTURE_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.LONG_PRESS_TIMEOUT, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.CAMERA_GESTURE_DISABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ACCESSIBILITY_AUTOCLICK_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ACCESSIBILITY_AUTOCLICK_DELAY, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ACCESSIBILITY_LARGE_POINTER_ICON, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Secure.PREFERRED_TTY_MODE,
|
||||
new DiscreteValueValidator(new String[] {"0", "1", "2", "3"}));
|
||||
VALIDATORS.put(Secure.ENHANCED_VOICE_PRIVACY_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.TTY_MODE_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.RTT_CALLING_MODE, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Secure.INCALL_POWER_BUTTON_BEHAVIOR,
|
||||
new DiscreteValueValidator(new String[] {"1", "2"}));
|
||||
VALIDATORS.put(Secure.NIGHT_DISPLAY_CUSTOM_START_TIME, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.NIGHT_DISPLAY_CUSTOM_END_TIME, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.NIGHT_DISPLAY_COLOR_TEMPERATURE, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.NIGHT_DISPLAY_AUTO_MODE, new InclusiveIntegerRangeValidator(0, 2));
|
||||
VALIDATORS.put(Secure.DISPLAY_WHITE_BALANCE_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SYNC_PARENT_SOUNDS, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.QS_TILES, TILE_LIST_VALIDATOR);
|
||||
VALIDATORS.put(Secure.DOZE_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.DOZE_ALWAYS_ON, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.DOZE_PICK_UP_GESTURE, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.DOZE_DOUBLE_TAP_GESTURE, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.DOZE_TAP_SCREEN_GESTURE, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.DOZE_WAKE_LOCK_SCREEN_GESTURE, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.DOZE_WAKE_DISPLAY_GESTURE, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.NFC_PAYMENT_DEFAULT_COMPONENT, COMPONENT_NAME_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Secure.AUTOMATIC_STORAGE_MANAGER_DAYS_TO_RETAIN, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.FACE_UNLOCK_KEYGUARD_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.FACE_UNLOCK_DISMISSES_KEYGUARD, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SHOW_MEDIA_WHEN_BYPASSING, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.FACE_UNLOCK_APP_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.FACE_UNLOCK_ALWAYS_REQUIRE_CONFIRMATION, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ASSIST_GESTURE_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ASSIST_GESTURE_WAKE_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.VR_DISPLAY_MODE, new DiscreteValueValidator(new String[] {"0", "1"}));
|
||||
VALIDATORS.put(Secure.NOTIFICATION_BADGING, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.NOTIFICATION_BUBBLES, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.NOTIFICATION_DISMISS_RTL, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.QS_AUTO_ADDED_TILES, TILE_LIST_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SCREENSAVER_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SCREENSAVER_COMPONENTS, COMMA_SEPARATED_COMPONENT_LIST_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SCREENSAVER_ACTIVATE_ON_DOCK, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SCREENSAVER_ACTIVATE_ON_SLEEP, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.LOCKDOWN_IN_POWER_MENU, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SHOW_FIRST_CRASH_DIALOG_DEV_OPTION, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.VOLUME_HUSH_GESTURE, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Secure.ENABLED_NOTIFICATION_LISTENERS,
|
||||
COLON_SEPARATED_COMPONENT_LIST_VALIDATOR); // legacy restore setting
|
||||
VALIDATORS.put(
|
||||
Secure.ENABLED_NOTIFICATION_ASSISTANT,
|
||||
COLON_SEPARATED_COMPONENT_LIST_VALIDATOR); // legacy restore setting
|
||||
VALIDATORS.put(
|
||||
Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES,
|
||||
COLON_SEPARATED_PACKAGE_LIST_VALIDATOR); // legacy restore setting
|
||||
VALIDATORS.put(Secure.HUSH_GESTURE_USED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.MANUAL_RINGER_TOGGLE_COUNT, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.IN_CALL_NOTIFICATION_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SHOW_NOTIFICATION_SNOOZE, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ZEN_DURATION, ANY_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SHOW_ZEN_UPGRADE_NOTIFICATION, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SHOW_ZEN_SETTINGS_SUGGESTION, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ZEN_SETTINGS_UPDATED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ZEN_SETTINGS_SUGGESTION_VIEWED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.CHARGING_SOUNDS_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.CHARGING_VIBRATION_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Secure.ACCESSIBILITY_NON_INTERACTIVE_UI_TIMEOUT_MS, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Secure.ACCESSIBILITY_INTERACTIVE_UI_TIMEOUT_MS, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.USER_SETUP_COMPLETE, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ASSIST_GESTURE_SETUP_COMPLETE, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.TRUST_AGENTS_EXTEND_UNLOCK, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.LOCK_SCREEN_CUSTOM_CLOCK_FACE, JSON_OBJECT_VALIDATOR);
|
||||
VALIDATORS.put(Secure.LOCK_SCREEN_WHEN_TRUST_LOST, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SKIP_GESTURE, BOOLEAN_VALIDATOR);
|
||||
/*
|
||||
* Only used if FeatureFlag "settings_skip_direction_mutable" is enabled.
|
||||
* If feature flag is disabled, should assume SKIP_DIRECTION = 0.
|
||||
* 0 / false = right to left to advance to next
|
||||
* 1 / true = left to right to advance to next
|
||||
*/
|
||||
VALIDATORS.put(Secure.SKIP_DIRECTION, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SILENCE_GESTURE, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES, JSON_OBJECT_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
Secure.NAVIGATION_MODE, new DiscreteValueValidator(new String[] {"0", "1", "2"}));
|
||||
VALIDATORS.put(Secure.AWARE_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SKIP_GESTURE_COUNT, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SKIP_TOUCH_COUNT, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SILENCE_ALARMS_GESTURE_COUNT, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SILENCE_TIMER_GESTURE_COUNT, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SILENCE_CALL_GESTURE_COUNT, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SILENCE_ALARMS_TOUCH_COUNT, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SILENCE_TIMER_TOUCH_COUNT, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.SILENCE_CALL_TOUCH_COUNT, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(Secure.ODI_CAPTIONS_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.DARK_MODE_DIALOG_SEEN, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.UI_NIGHT_MODE, new InclusiveIntegerRangeValidator(0, 2));
|
||||
VALIDATORS.put(Secure.GLOBAL_ACTIONS_PANEL_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.AWARE_LOCK_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(Secure.DISPLAY_DENSITY_FORCED, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import android.text.TextUtils;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
@@ -180,4 +181,27 @@ public class SettingsValidators {
|
||||
public static final Validator TTS_LIST_VALIDATOR = new TTSListValidator();
|
||||
|
||||
public static final Validator TILE_LIST_VALIDATOR = new TileListValidator();
|
||||
|
||||
static final Validator DATE_FORMAT_VALIDATOR = value -> {
|
||||
try {
|
||||
new SimpleDateFormat(value);
|
||||
return true;
|
||||
} catch (IllegalArgumentException | NullPointerException e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
static final Validator COLON_SEPARATED_COMPONENT_LIST_VALIDATOR =
|
||||
new ComponentNameListValidator(":");
|
||||
|
||||
static final Validator COLON_SEPARATED_PACKAGE_LIST_VALIDATOR =
|
||||
new PackageNameListValidator(":");
|
||||
|
||||
static final Validator COMMA_SEPARATED_COMPONENT_LIST_VALIDATOR =
|
||||
new ComponentNameListValidator(",");
|
||||
|
||||
static final Validator PERCENTAGE_INTEGER_VALIDATOR =
|
||||
new InclusiveIntegerRangeValidator(0, 100);
|
||||
|
||||
static final Validator VIBRATION_INTENSITY_VALIDATOR = new InclusiveIntegerRangeValidator(0, 3);
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* 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.BOOLEAN_VALIDATOR;
|
||||
import static android.provider.settings.validators.SettingsValidators.COMPONENT_NAME_VALIDATOR;
|
||||
import static android.provider.settings.validators.SettingsValidators.DATE_FORMAT_VALIDATOR;
|
||||
import static android.provider.settings.validators.SettingsValidators.LENIENT_IP_ADDRESS_VALIDATOR;
|
||||
import static android.provider.settings.validators.SettingsValidators.NON_NEGATIVE_INTEGER_VALIDATOR;
|
||||
import static android.provider.settings.validators.SettingsValidators.URI_VALIDATOR;
|
||||
import static android.provider.settings.validators.SettingsValidators.VIBRATION_INTENSITY_VALIDATOR;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UnsupportedAppUsage;
|
||||
import android.content.ComponentName;
|
||||
import android.hardware.display.ColorDisplayManager;
|
||||
import android.os.BatteryManager;
|
||||
import android.provider.Settings.System;
|
||||
import android.util.ArrayMap;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Validators for System settings
|
||||
*/
|
||||
public class SystemSettingsValidators {
|
||||
/**
|
||||
* These are all public system settings
|
||||
*
|
||||
* <p>All settings in {@link System.SETTINGS_TO_BACKUP} array *must* have a non-null validator,
|
||||
* otherwise they won't be restored.
|
||||
*/
|
||||
@UnsupportedAppUsage
|
||||
public static final Map<String, Validator> VALIDATORS = new ArrayMap<>();
|
||||
|
||||
static {
|
||||
VALIDATORS.put(
|
||||
System.STAY_ON_WHILE_PLUGGED_IN,
|
||||
value -> {
|
||||
try {
|
||||
int val = Integer.parseInt(value);
|
||||
return (val == 0)
|
||||
|| (val == BatteryManager.BATTERY_PLUGGED_AC)
|
||||
|| (val == BatteryManager.BATTERY_PLUGGED_USB)
|
||||
|| (val == BatteryManager.BATTERY_PLUGGED_WIRELESS)
|
||||
|| (val
|
||||
== (BatteryManager.BATTERY_PLUGGED_AC
|
||||
| BatteryManager.BATTERY_PLUGGED_USB))
|
||||
|| (val
|
||||
== (BatteryManager.BATTERY_PLUGGED_AC
|
||||
| BatteryManager.BATTERY_PLUGGED_WIRELESS))
|
||||
|| (val
|
||||
== (BatteryManager.BATTERY_PLUGGED_USB
|
||||
| BatteryManager.BATTERY_PLUGGED_WIRELESS))
|
||||
|| (val
|
||||
== (BatteryManager.BATTERY_PLUGGED_AC
|
||||
| BatteryManager.BATTERY_PLUGGED_USB
|
||||
| BatteryManager.BATTERY_PLUGGED_WIRELESS));
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
VALIDATORS.put(System.END_BUTTON_BEHAVIOR, new InclusiveIntegerRangeValidator(0, 3));
|
||||
VALIDATORS.put(System.WIFI_USE_STATIC_IP, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.BLUETOOTH_DISCOVERABILITY, new InclusiveIntegerRangeValidator(0, 2));
|
||||
VALIDATORS.put(System.BLUETOOTH_DISCOVERABILITY_TIMEOUT, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
System.NEXT_ALARM_FORMATTED,
|
||||
new Validator() {
|
||||
private static final int MAX_LENGTH = 1000;
|
||||
|
||||
@Override
|
||||
public boolean validate(String value) {
|
||||
// TODO: No idea what the correct format is.
|
||||
return value == null || value.length() < MAX_LENGTH;
|
||||
}
|
||||
});
|
||||
VALIDATORS.put(
|
||||
System.FONT_SCALE,
|
||||
value -> {
|
||||
try {
|
||||
return Float.parseFloat(value) >= 0;
|
||||
} catch (NumberFormatException | NullPointerException e) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
VALIDATORS.put(System.DIM_SCREEN, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
System.DISPLAY_COLOR_MODE,
|
||||
new Validator() {
|
||||
@Override
|
||||
public boolean validate(@Nullable String value) {
|
||||
// Assume the actual validation that this device can properly handle this
|
||||
// kind of
|
||||
// color mode further down in ColorDisplayManager / ColorDisplayService.
|
||||
try {
|
||||
final int setting = Integer.parseInt(value);
|
||||
final boolean isInFrameworkRange =
|
||||
setting >= ColorDisplayManager.COLOR_MODE_NATURAL
|
||||
&& setting <= ColorDisplayManager.COLOR_MODE_AUTOMATIC;
|
||||
final boolean isInVendorRange =
|
||||
setting >= ColorDisplayManager.VENDOR_COLOR_MODE_RANGE_MIN
|
||||
&& setting
|
||||
<= ColorDisplayManager
|
||||
.VENDOR_COLOR_MODE_RANGE_MAX;
|
||||
return isInFrameworkRange || isInVendorRange;
|
||||
} catch (NumberFormatException | NullPointerException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
VALIDATORS.put(System.SCREEN_OFF_TIMEOUT, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(System.SCREEN_BRIGHTNESS_FOR_VR, new InclusiveIntegerRangeValidator(0, 255));
|
||||
VALIDATORS.put(System.SCREEN_BRIGHTNESS_MODE, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.ADAPTIVE_SLEEP, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.MODE_RINGER_STREAMS_AFFECTED, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(System.MUTE_STREAMS_AFFECTED, NON_NEGATIVE_INTEGER_VALIDATOR);
|
||||
VALIDATORS.put(System.VIBRATE_ON, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.NOTIFICATION_VIBRATION_INTENSITY, VIBRATION_INTENSITY_VALIDATOR);
|
||||
VALIDATORS.put(System.RING_VIBRATION_INTENSITY, VIBRATION_INTENSITY_VALIDATOR);
|
||||
VALIDATORS.put(System.HAPTIC_FEEDBACK_INTENSITY, VIBRATION_INTENSITY_VALIDATOR);
|
||||
VALIDATORS.put(System.RINGTONE, URI_VALIDATOR);
|
||||
VALIDATORS.put(System.NOTIFICATION_SOUND, URI_VALIDATOR);
|
||||
VALIDATORS.put(System.ALARM_ALERT, URI_VALIDATOR);
|
||||
VALIDATORS.put(System.TEXT_AUTO_REPLACE, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.TEXT_AUTO_CAPS, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.TEXT_AUTO_PUNCTUATE, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.TEXT_SHOW_PASSWORD, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.AUTO_TIME, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.AUTO_TIME_ZONE, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.SHOW_GTALK_SERVICE_STATUS, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
System.WALLPAPER_ACTIVITY,
|
||||
new Validator() {
|
||||
private static final int MAX_LENGTH = 1000;
|
||||
|
||||
@Override
|
||||
public boolean validate(String value) {
|
||||
if (value != null && value.length() > MAX_LENGTH) {
|
||||
return false;
|
||||
}
|
||||
return ComponentName.unflattenFromString(value) != null;
|
||||
}
|
||||
});
|
||||
VALIDATORS.put(
|
||||
System.TIME_12_24, new DiscreteValueValidator(new String[] {"12", "24", null}));
|
||||
VALIDATORS.put(System.DATE_FORMAT, DATE_FORMAT_VALIDATOR);
|
||||
VALIDATORS.put(System.SETUP_WIZARD_HAS_RUN, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.ACCELEROMETER_ROTATION, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.USER_ROTATION, new InclusiveIntegerRangeValidator(0, 3));
|
||||
VALIDATORS.put(System.DTMF_TONE_WHEN_DIALING, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.SOUND_EFFECTS_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.HAPTIC_FEEDBACK_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.POWER_SOUNDS_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.DOCK_SOUNDS_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.SHOW_WEB_SUGGESTIONS, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.WIFI_USE_STATIC_IP, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.ADVANCED_SETTINGS, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.SCREEN_AUTO_BRIGHTNESS_ADJ, new InclusiveFloatRangeValidator(-1, 1));
|
||||
VALIDATORS.put(System.VIBRATE_INPUT_DEVICES, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.MASTER_MONO, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.MASTER_BALANCE, new InclusiveFloatRangeValidator(-1.f, 1.f));
|
||||
VALIDATORS.put(System.NOTIFICATIONS_USE_RING_VOLUME, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.VIBRATE_IN_SILENT, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.MEDIA_BUTTON_RECEIVER, COMPONENT_NAME_VALIDATOR);
|
||||
VALIDATORS.put(System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.VIBRATE_WHEN_RINGING, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.DTMF_TONE_TYPE_WHEN_DIALING, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.HEARING_AID, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.TTY_MODE, new InclusiveIntegerRangeValidator(0, 3));
|
||||
VALIDATORS.put(System.NOTIFICATION_LIGHT_PULSE, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.POINTER_LOCATION, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.SHOW_TOUCHES, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.WINDOW_ORIENTATION_LISTENER_LOG, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.LOCKSCREEN_SOUNDS_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.LOCKSCREEN_DISABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.SIP_RECEIVE_CALLS, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
System.SIP_CALL_OPTIONS,
|
||||
new DiscreteValueValidator(new String[] {"SIP_ALWAYS", "SIP_ADDRESS_ONLY"}));
|
||||
VALIDATORS.put(System.SIP_ALWAYS, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.SIP_ADDRESS_ONLY, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.SIP_ASK_ME_EACH_TIME, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.POINTER_SPEED, new InclusiveFloatRangeValidator(-7, 7));
|
||||
VALIDATORS.put(System.LOCK_TO_APP_ENABLED, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(
|
||||
System.EGG_MODE,
|
||||
new Validator() {
|
||||
@Override
|
||||
public boolean validate(@Nullable String value) {
|
||||
try {
|
||||
return Long.parseLong(value) >= 0;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
VALIDATORS.put(System.WIFI_STATIC_IP, LENIENT_IP_ADDRESS_VALIDATOR);
|
||||
VALIDATORS.put(System.WIFI_STATIC_GATEWAY, LENIENT_IP_ADDRESS_VALIDATOR);
|
||||
VALIDATORS.put(System.WIFI_STATIC_NETMASK, LENIENT_IP_ADDRESS_VALIDATOR);
|
||||
VALIDATORS.put(System.WIFI_STATIC_DNS1, LENIENT_IP_ADDRESS_VALIDATOR);
|
||||
VALIDATORS.put(System.WIFI_STATIC_DNS2, LENIENT_IP_ADDRESS_VALIDATOR);
|
||||
VALIDATORS.put(System.SHOW_BATTERY_PERCENT, BOOLEAN_VALIDATOR);
|
||||
VALIDATORS.put(System.NOTIFICATION_LIGHT_PULSE, BOOLEAN_VALIDATOR);
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,12 @@ import android.os.Build;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.provider.settings.backup.GlobalSettings;
|
||||
import android.provider.settings.backup.SecureSettings;
|
||||
import android.provider.settings.backup.SystemSettings;
|
||||
import android.provider.settings.validators.GlobalSettingsValidators;
|
||||
import android.provider.settings.validators.SecureSettingsValidators;
|
||||
import android.provider.settings.validators.SystemSettingsValidators;
|
||||
import android.provider.settings.validators.Validator;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
@@ -542,7 +548,7 @@ public class SettingsBackupAgent extends BackupAgentHelper {
|
||||
Cursor cursor = getContentResolver().query(Settings.System.CONTENT_URI, PROJECTION, null,
|
||||
null, null);
|
||||
try {
|
||||
return extractRelevantValues(cursor, Settings.System.SETTINGS_TO_BACKUP);
|
||||
return extractRelevantValues(cursor, SystemSettings.SETTINGS_TO_BACKUP);
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
@@ -552,7 +558,7 @@ public class SettingsBackupAgent extends BackupAgentHelper {
|
||||
Cursor cursor = getContentResolver().query(Settings.Secure.CONTENT_URI, PROJECTION, null,
|
||||
null, null);
|
||||
try {
|
||||
return extractRelevantValues(cursor, Settings.Secure.SETTINGS_TO_BACKUP);
|
||||
return extractRelevantValues(cursor, SecureSettings.SETTINGS_TO_BACKUP);
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
@@ -562,7 +568,7 @@ public class SettingsBackupAgent extends BackupAgentHelper {
|
||||
Cursor cursor = getContentResolver().query(Settings.Global.CONTENT_URI, PROJECTION, null,
|
||||
null, null);
|
||||
try {
|
||||
return extractRelevantValues(cursor, Settings.Global.SETTINGS_TO_BACKUP);
|
||||
return extractRelevantValues(cursor, GlobalSettings.SETTINGS_TO_BACKUP);
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
@@ -633,18 +639,18 @@ public class SettingsBackupAgent extends BackupAgentHelper {
|
||||
final String[] whitelist;
|
||||
Map<String, Validator> validators = null;
|
||||
if (contentUri.equals(Settings.Secure.CONTENT_URI)) {
|
||||
whitelist = ArrayUtils.concatElements(String.class, Settings.Secure.SETTINGS_TO_BACKUP,
|
||||
whitelist = ArrayUtils.concatElements(String.class, SecureSettings.SETTINGS_TO_BACKUP,
|
||||
Settings.Secure.LEGACY_RESTORE_SETTINGS,
|
||||
Settings.Secure.DEVICE_SPECIFIC_SETTINGS_TO_BACKUP);
|
||||
validators = Settings.Secure.VALIDATORS;
|
||||
validators = SecureSettingsValidators.VALIDATORS;
|
||||
} else if (contentUri.equals(Settings.System.CONTENT_URI)) {
|
||||
whitelist = ArrayUtils.concatElements(String.class, Settings.System.SETTINGS_TO_BACKUP,
|
||||
whitelist = ArrayUtils.concatElements(String.class, SystemSettings.SETTINGS_TO_BACKUP,
|
||||
Settings.System.LEGACY_RESTORE_SETTINGS);
|
||||
validators = Settings.System.VALIDATORS;
|
||||
validators = SystemSettingsValidators.VALIDATORS;
|
||||
} else if (contentUri.equals(Settings.Global.CONTENT_URI)) {
|
||||
whitelist = ArrayUtils.concatElements(String.class, Settings.Global.SETTINGS_TO_BACKUP,
|
||||
whitelist = ArrayUtils.concatElements(String.class, GlobalSettings.SETTINGS_TO_BACKUP,
|
||||
Settings.Global.LEGACY_RESTORE_SETTINGS);
|
||||
validators = Settings.Global.VALIDATORS;
|
||||
validators = GlobalSettingsValidators.VALIDATORS;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown URI: " + contentUri);
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ import android.provider.DeviceConfig;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.Global;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.provider.settings.validators.SystemSettingsValidators;
|
||||
import android.provider.settings.validators.Validator;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
@@ -1717,7 +1718,7 @@ public class SettingsProvider extends ContentProvider {
|
||||
}
|
||||
|
||||
private void validateSystemSettingValue(String name, String value) {
|
||||
Validator validator = Settings.System.VALIDATORS.get(name);
|
||||
Validator validator = SystemSettingsValidators.VALIDATORS.get(name);
|
||||
if (validator != null && !validator.validate(value)) {
|
||||
throw new IllegalArgumentException("Invalid value: " + value
|
||||
+ " for setting: " + name);
|
||||
|
||||
@@ -18,15 +18,16 @@ package android.provider;
|
||||
|
||||
import static com.google.android.collect.Sets.newHashSet;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import static java.lang.reflect.Modifier.isFinal;
|
||||
import static java.lang.reflect.Modifier.isPublic;
|
||||
import static java.lang.reflect.Modifier.isStatic;
|
||||
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
import android.provider.settings.backup.GlobalSettings;
|
||||
import android.provider.settings.backup.SecureSettings;
|
||||
import android.provider.settings.backup.SystemSettings;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
@@ -727,45 +728,43 @@ public class SettingsBackupTest {
|
||||
public void systemSettingsBackedUpOrBlacklisted() {
|
||||
checkSettingsBackedUpOrBlacklisted(
|
||||
getCandidateSettings(Settings.System.class),
|
||||
newHashSet(Settings.System.SETTINGS_TO_BACKUP),
|
||||
newHashSet(SystemSettings.SETTINGS_TO_BACKUP),
|
||||
BACKUP_BLACKLISTED_SYSTEM_SETTINGS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void globalSettingsBackedUpOrBlacklisted() {
|
||||
checkSettingsBackedUpOrBlacklisted(
|
||||
getCandidateSettings(Settings.Global.class),
|
||||
newHashSet(Settings.Global.SETTINGS_TO_BACKUP),
|
||||
BACKUP_BLACKLISTED_GLOBAL_SETTINGS);
|
||||
getCandidateSettings(Settings.Global.class),
|
||||
newHashSet(GlobalSettings.SETTINGS_TO_BACKUP),
|
||||
BACKUP_BLACKLISTED_GLOBAL_SETTINGS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void secureSettingsBackedUpOrBlacklisted() {
|
||||
HashSet<String> keys = new HashSet<String>();
|
||||
Collections.addAll(keys, Settings.Secure.SETTINGS_TO_BACKUP);
|
||||
Collections.addAll(keys, SecureSettings.SETTINGS_TO_BACKUP);
|
||||
Collections.addAll(keys, Settings.Secure.DEVICE_SPECIFIC_SETTINGS_TO_BACKUP);
|
||||
checkSettingsBackedUpOrBlacklisted(
|
||||
getCandidateSettings(Settings.Secure.class),
|
||||
keys,
|
||||
BACKUP_BLACKLISTED_SECURE_SETTINGS);
|
||||
BACKUP_BLACKLISTED_SECURE_SETTINGS);
|
||||
}
|
||||
|
||||
private static void checkSettingsBackedUpOrBlacklisted(
|
||||
Set<String> settings, Set<String> settingsToBackup, Set<String> blacklist) {
|
||||
Set<String> settingsNotBackedUp = difference(settings, settingsToBackup);
|
||||
Set<String> settingsNotBackedUpOrBlacklisted = difference(settingsNotBackedUp, blacklist);
|
||||
assertThat(
|
||||
assertTrue(
|
||||
"Settings not backed up or blacklisted",
|
||||
settingsNotBackedUpOrBlacklisted,
|
||||
is(empty()));
|
||||
settingsNotBackedUpOrBlacklisted.isEmpty());
|
||||
|
||||
assertThat(
|
||||
"blacklisted settings backed up",
|
||||
intersect(settingsToBackup, blacklist),
|
||||
is(empty()));
|
||||
assertTrue(
|
||||
"blacklisted settings backed up", intersect(settingsToBackup, blacklist).isEmpty());
|
||||
}
|
||||
|
||||
private static Set<String> getCandidateSettings(Class<? extends Settings.NameValueTable> clazz) {
|
||||
private static Set<String> getCandidateSettings(
|
||||
Class<? extends Settings.NameValueTable> clazz) {
|
||||
HashSet<String> result = new HashSet<String>();
|
||||
for (Field field : clazz.getDeclaredFields()) {
|
||||
if (looksLikeValidSetting(field)) {
|
||||
@@ -24,6 +24,9 @@ import static org.junit.Assert.fail;
|
||||
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
import android.provider.Settings;
|
||||
import android.provider.settings.backup.GlobalSettings;
|
||||
import android.provider.settings.backup.SecureSettings;
|
||||
import android.provider.settings.backup.SystemSettings;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
@@ -218,7 +221,7 @@ public class SettingsValidatorsTest {
|
||||
|
||||
@Test
|
||||
public void dateFormatValidator_onNullValue_returnsFalse() {
|
||||
assertFalse(Settings.System.DATE_FORMAT_VALIDATOR.validate(null));
|
||||
assertFalse(SettingsValidators.DATE_FORMAT_VALIDATOR.validate(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -238,18 +241,18 @@ public class SettingsValidatorsTest {
|
||||
|
||||
@Test
|
||||
public void testJSONObjectValidator_onNullValue_returnsFalse() {
|
||||
assertThat(SettingsValidators.JSON_OBJECT_VALIDATOR.validate(null)).isFalse();
|
||||
assertFalse(SettingsValidators.JSON_OBJECT_VALIDATOR.validate(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJSONObjectValidator_onEmptyString_returnsFalse() {
|
||||
assertThat(SettingsValidators.JSON_OBJECT_VALIDATOR.validate("")).isFalse();
|
||||
assertFalse(SettingsValidators.JSON_OBJECT_VALIDATOR.validate(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ensureAllBackedUpSystemSettingsHaveValidators() {
|
||||
String offenders = getOffenders(concat(Settings.System.SETTINGS_TO_BACKUP,
|
||||
Settings.System.LEGACY_RESTORE_SETTINGS), Settings.System.VALIDATORS);
|
||||
String offenders = getOffenders(concat(SystemSettings.SETTINGS_TO_BACKUP,
|
||||
Settings.System.LEGACY_RESTORE_SETTINGS), SystemSettingsValidators.VALIDATORS);
|
||||
|
||||
failIfOffendersPresent(offenders, "Settings.System");
|
||||
}
|
||||
@@ -295,16 +298,16 @@ public class SettingsValidatorsTest {
|
||||
|
||||
@Test
|
||||
public void ensureAllBackedUpGlobalSettingsHaveValidators() {
|
||||
String offenders = getOffenders(concat(Settings.Global.SETTINGS_TO_BACKUP,
|
||||
Settings.Global.LEGACY_RESTORE_SETTINGS), Settings.Global.VALIDATORS);
|
||||
String offenders = getOffenders(concat(GlobalSettings.SETTINGS_TO_BACKUP,
|
||||
Settings.Global.LEGACY_RESTORE_SETTINGS), GlobalSettingsValidators.VALIDATORS);
|
||||
|
||||
failIfOffendersPresent(offenders, "Settings.Global");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ensureAllBackedUpSecureSettingsHaveValidators() {
|
||||
String offenders = getOffenders(concat(Settings.Secure.SETTINGS_TO_BACKUP,
|
||||
Settings.Secure.LEGACY_RESTORE_SETTINGS), Settings.Secure.VALIDATORS);
|
||||
String offenders = getOffenders(concat(SecureSettings.SETTINGS_TO_BACKUP,
|
||||
Settings.Secure.LEGACY_RESTORE_SETTINGS), SecureSettingsValidators.VALIDATORS);
|
||||
|
||||
failIfOffendersPresent(offenders, "Settings.Secure");
|
||||
}
|
||||
Reference in New Issue
Block a user