Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.provider; |
| 18 | |
| 19 | import static com.google.android.collect.Sets.newHashSet; |
| 20 | import static org.hamcrest.MatcherAssert.assertThat; |
| 21 | import static org.hamcrest.Matchers.empty; |
| 22 | import static org.hamcrest.Matchers.is; |
| 23 | import static java.lang.reflect.Modifier.isFinal; |
| 24 | import static java.lang.reflect.Modifier.isPublic; |
| 25 | import static java.lang.reflect.Modifier.isStatic; |
| 26 | |
Bryan Mawhinney | 2c5f95a | 2017-02-21 10:58:23 +0000 | [diff] [blame] | 27 | import android.platform.test.annotations.Presubmit; |
Bryan Mawhinney | 24a2ae5 | 2017-01-31 11:18:50 +0000 | [diff] [blame] | 28 | import android.support.test.filters.SmallTest; |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 29 | import android.support.test.runner.AndroidJUnit4; |
| 30 | |
| 31 | import java.lang.reflect.Field; |
| 32 | import java.util.HashSet; |
| 33 | import java.util.Set; |
| 34 | |
| 35 | import org.junit.Test; |
| 36 | import org.junit.runner.RunWith; |
| 37 | |
Bryan Mawhinney | 2c5f95a | 2017-02-21 10:58:23 +0000 | [diff] [blame] | 38 | /** Tests that ensure appropriate settings are backed up. */ |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 39 | @RunWith(AndroidJUnit4.class) |
Bryan Mawhinney | 24a2ae5 | 2017-01-31 11:18:50 +0000 | [diff] [blame] | 40 | @SmallTest |
Bryan Mawhinney | 2c5f95a | 2017-02-21 10:58:23 +0000 | [diff] [blame] | 41 | public class SettingsBackupTest { |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * The following blacklists contain settings that should *not* be backed up and restored to |
| 45 | * another device. As a general rule, anything that is not user configurable should be |
| 46 | * blacklisted (and conversely, things that *are* user configurable *should* be backed up) |
| 47 | */ |
| 48 | private static final Set<String> BACKUP_BLACKLISTED_SYSTEM_SETTINGS = |
| 49 | newHashSet( |
| 50 | Settings.System.ADVANCED_SETTINGS, // candidate for backup? |
| 51 | Settings.System.ALARM_ALERT, // backup candidate? |
| 52 | Settings.System.ALARM_ALERT_CACHE, // internal cache |
| 53 | Settings.System.APPEND_FOR_LAST_AUDIBLE, // suffix deprecated since API 2 |
| 54 | Settings.System.EGG_MODE, // I am the lolrus |
| 55 | Settings.System.END_BUTTON_BEHAVIOR, // bug? |
| 56 | Settings.System |
| 57 | .HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, // candidate for backup? |
| 58 | Settings.System.LOCKSCREEN_DISABLED, // ? |
| 59 | Settings.System.MEDIA_BUTTON_RECEIVER, // candidate for backup? |
| 60 | Settings.System.MUTE_STREAMS_AFFECTED, // candidate for backup? |
| 61 | Settings.System.NOTIFICATION_LIGHT_PULSE, // candidate for backup? |
| 62 | Settings.System.NOTIFICATION_SOUND_CACHE, // internal cache |
| 63 | Settings.System.POINTER_LOCATION, // backup candidate? |
| 64 | Settings.System.RINGTONE_CACHE, // internal cache |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 65 | Settings.System.SETUP_WIZARD_HAS_RUN, // Only used by SuW |
| 66 | Settings.System.SHOW_GTALK_SERVICE_STATUS, // candidate for backup? |
| 67 | Settings.System.SHOW_TOUCHES, // bug? |
| 68 | Settings.System.SIP_ADDRESS_ONLY, // value, not a setting |
| 69 | Settings.System.SIP_ALWAYS, // value, not a setting |
| 70 | Settings.System.SYSTEM_LOCALES, // bug? |
| 71 | Settings.System.USER_ROTATION, // backup candidate? |
| 72 | Settings.System.VIBRATE_IN_SILENT, // deprecated? |
| 73 | Settings.System.VIBRATE_ON, // candidate for backup? |
Michal Karpinski | 034a83f | 2017-04-26 19:25:25 +0100 | [diff] [blame] | 74 | Settings.System.VOLUME_ACCESSIBILITY, // used internally, changing value will |
| 75 | // not change volume |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 76 | Settings.System.VOLUME_ALARM, // deprecated since API 2? |
| 77 | Settings.System.VOLUME_BLUETOOTH_SCO, // deprecated since API 2? |
| 78 | Settings.System.VOLUME_MASTER, // candidate for backup? |
| 79 | Settings.System.VOLUME_MUSIC, // deprecated since API 2? |
| 80 | Settings.System.VOLUME_NOTIFICATION, // deprecated since API 2? |
| 81 | Settings.System.VOLUME_RING, // deprecated since API 2? |
| 82 | Settings.System.VOLUME_SYSTEM, // deprecated since API 2? |
| 83 | Settings.System.VOLUME_VOICE, // deprecated since API 2? |
| 84 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, // bug? |
| 85 | Settings.System.WINDOW_ORIENTATION_LISTENER_LOG // used for debugging only |
| 86 | ); |
| 87 | |
| 88 | private static final Set<String> BACKUP_BLACKLISTED_GLOBAL_SETTINGS = |
| 89 | newHashSet( |
Bryan Mawhinney | 24a2ae5 | 2017-01-31 11:18:50 +0000 | [diff] [blame] | 90 | Settings.Global.ACTIVITY_MANAGER_CONSTANTS, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 91 | Settings.Global.ADB_ENABLED, |
| 92 | Settings.Global.ADD_USERS_WHEN_LOCKED, |
| 93 | Settings.Global.AIRPLANE_MODE_ON, |
| 94 | Settings.Global.AIRPLANE_MODE_RADIOS, |
| 95 | Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS, |
| 96 | Settings.Global.ALARM_MANAGER_CONSTANTS, |
| 97 | Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, |
| 98 | Settings.Global.ALWAYS_FINISH_ACTIVITIES, |
| 99 | Settings.Global.ANIMATOR_DURATION_SCALE, |
| 100 | Settings.Global.APN_DB_UPDATE_CONTENT_URL, |
| 101 | Settings.Global.APN_DB_UPDATE_METADATA_URL, |
| 102 | Settings.Global.APP_IDLE_CONSTANTS, |
| 103 | Settings.Global.ASSISTED_GPS_ENABLED, |
| 104 | Settings.Global.AUDIO_SAFE_VOLUME_STATE, |
| 105 | Settings.Global.BATTERY_DISCHARGE_DURATION_THRESHOLD, |
| 106 | Settings.Global.BATTERY_DISCHARGE_THRESHOLD, |
| 107 | Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, |
| 108 | Settings.Global.BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX, |
| 109 | Settings.Global.BLUETOOTH_A2DP_SRC_PRIORITY_PREFIX, |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 110 | Settings.Global.BLUETOOTH_A2DP_SUPPORTS_OPTIONAL_CODECS_PREFIX, |
| 111 | Settings.Global.BLUETOOTH_A2DP_OPTIONAL_CODECS_ENABLED_PREFIX, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 112 | Settings.Global.BLUETOOTH_DISABLED_PROFILES, |
| 113 | Settings.Global.BLUETOOTH_HEADSET_PRIORITY_PREFIX, |
| 114 | Settings.Global.BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX, |
| 115 | Settings.Global.BLUETOOTH_INTEROPERABILITY_LIST, |
| 116 | Settings.Global.BLUETOOTH_MAP_CLIENT_PRIORITY_PREFIX, |
| 117 | Settings.Global.BLUETOOTH_MAP_PRIORITY_PREFIX, |
| 118 | Settings.Global.BLUETOOTH_ON, // Candidate for backup? |
| 119 | Settings.Global.BLUETOOTH_PAN_PRIORITY_PREFIX, |
| 120 | Settings.Global.BLUETOOTH_PBAP_CLIENT_PRIORITY_PREFIX, |
| 121 | Settings.Global.BLUETOOTH_SAP_PRIORITY_PREFIX, |
| 122 | Settings.Global.BOOT_COUNT, |
| 123 | Settings.Global.CAPTIVE_PORTAL_FALLBACK_URL, |
| 124 | Settings.Global.CAPTIVE_PORTAL_HTTPS_URL, |
| 125 | Settings.Global.CAPTIVE_PORTAL_HTTP_URL, |
| 126 | Settings.Global.CAPTIVE_PORTAL_MODE, |
Michal Karpinski | 034a83f | 2017-04-26 19:25:25 +0100 | [diff] [blame] | 127 | Settings.Global.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 128 | Settings.Global.CAPTIVE_PORTAL_SERVER, |
| 129 | Settings.Global.CAPTIVE_PORTAL_USE_HTTPS, |
| 130 | Settings.Global.CAPTIVE_PORTAL_USER_AGENT, |
| 131 | Settings.Global.CAR_DOCK_SOUND, |
| 132 | Settings.Global.CARRIER_APP_WHITELIST, |
| 133 | Settings.Global.CAR_UNDOCK_SOUND, |
| 134 | Settings.Global.CDMA_CELL_BROADCAST_SMS, |
| 135 | Settings.Global.CDMA_ROAMING_MODE, |
| 136 | Settings.Global.CDMA_SUBSCRIPTION_MODE, |
| 137 | Settings.Global.CELL_ON, |
| 138 | Settings.Global.CERT_PIN_UPDATE_CONTENT_URL, |
| 139 | Settings.Global.CERT_PIN_UPDATE_METADATA_URL, |
| 140 | Settings.Global.COMPATIBILITY_MODE, |
| 141 | Settings.Global.CONNECTIVITY_CHANGE_DELAY, |
| 142 | Settings.Global.CONNECTIVITY_METRICS_BUFFER_SIZE, |
| 143 | Settings.Global.CONNECTIVITY_SAMPLING_INTERVAL_IN_SECONDS, |
| 144 | Settings.Global.CONTACT_METADATA_SYNC_ENABLED, |
| 145 | Settings.Global.CONTACTS_DATABASE_WAL_ENABLED, |
| 146 | Settings.Global.DATA_ACTIVITY_TIMEOUT_MOBILE, |
| 147 | Settings.Global.DATA_ACTIVITY_TIMEOUT_WIFI, |
Amith Yamasani | 3945202 | 2017-03-21 15:23:47 -0700 | [diff] [blame] | 148 | Settings.Global.DATABASE_CREATION_BUILDID, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 149 | Settings.Global.DATABASE_DOWNGRADE_REASON, |
| 150 | Settings.Global.DATA_ROAMING, |
| 151 | Settings.Global.DATA_STALL_ALARM_AGGRESSIVE_DELAY_IN_MS, |
| 152 | Settings.Global.DATA_STALL_ALARM_NON_AGGRESSIVE_DELAY_IN_MS, |
| 153 | Settings.Global.DEBUG_APP, |
| 154 | Settings.Global.DEBUG_VIEW_ATTRIBUTES, |
| 155 | Settings.Global.DEFAULT_DNS_SERVER, |
| 156 | Settings.Global.DEFAULT_INSTALL_LOCATION, |
| 157 | Settings.Global.DESK_DOCK_SOUND, |
| 158 | Settings.Global.DESK_UNDOCK_SOUND, |
| 159 | Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, |
| 160 | Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, |
| 161 | Settings.Global.DEVELOPMENT_FORCE_RTL, |
| 162 | Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, |
| 163 | Settings.Global.DEVICE_DEMO_MODE, |
| 164 | Settings.Global.DEVICE_IDLE_CONSTANTS, |
| 165 | Settings.Global.DEVICE_IDLE_CONSTANTS_WATCH, |
jackqdyulei | 455e90a | 2017-02-09 15:29:16 -0800 | [diff] [blame] | 166 | Settings.Global.BATTERY_SAVER_CONSTANTS, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 167 | Settings.Global.DEVICE_NAME, |
Bryan Mawhinney | 2092484 | 2017-05-11 12:50:14 +0100 | [diff] [blame] | 168 | Settings.Global.DEVICE_POLICY_CONSTANTS, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 169 | Settings.Global.DEVICE_PROVISIONED, |
| 170 | Settings.Global.DEVICE_PROVISIONING_MOBILE_DATA_ENABLED, |
| 171 | Settings.Global.DISK_FREE_CHANGE_REPORTING_THRESHOLD, |
| 172 | Settings.Global.DISPLAY_SCALING_FORCE, |
| 173 | Settings.Global.DISPLAY_SIZE_FORCED, |
| 174 | Settings.Global.DNS_RESOLVER_MAX_SAMPLES, |
| 175 | Settings.Global.DNS_RESOLVER_MIN_SAMPLES, |
| 176 | Settings.Global.DNS_RESOLVER_SAMPLE_VALIDITY_SECONDS, |
| 177 | Settings.Global.DNS_RESOLVER_SUCCESS_THRESHOLD_PERCENT, |
| 178 | Settings.Global.DOCK_SOUNDS_ENABLED_WHEN_ACCESSIBILITY, |
| 179 | Settings.Global.DOWNLOAD_MAX_BYTES_OVER_MOBILE, |
| 180 | Settings.Global.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE, |
| 181 | Settings.Global.DROPBOX_AGE_SECONDS, |
| 182 | Settings.Global.DROPBOX_MAX_FILES, |
| 183 | Settings.Global.DROPBOX_QUOTA_KB, |
| 184 | Settings.Global.DROPBOX_QUOTA_PERCENT, |
| 185 | Settings.Global.DROPBOX_RESERVE_PERCENT, |
| 186 | Settings.Global.DROPBOX_TAG_PREFIX, |
| 187 | Settings.Global.EMERGENCY_AFFORDANCE_NEEDED, |
| 188 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, |
Daniel Nishi | 0f703e6 | 2017-02-21 15:19:27 -0800 | [diff] [blame] | 189 | Settings.Global.ENABLE_CACHE_QUOTA_CALCULATION, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 190 | Settings.Global.ENABLE_CELLULAR_ON_BOOT, |
Bryan Mawhinney | 24a2ae5 | 2017-01-31 11:18:50 +0000 | [diff] [blame] | 191 | Settings.Global.ENABLE_DISKSTATS_LOGGING, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 192 | Settings.Global.ENABLE_EPHEMERAL_FEATURE, |
| 193 | Settings.Global.ENHANCED_4G_MODE_ENABLED, |
| 194 | Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES, |
| 195 | Settings.Global.ERROR_LOGCAT_PREFIX, |
| 196 | Settings.Global.FANCY_IME_ANIMATIONS, |
| 197 | Settings.Global.FORCE_ALLOW_ON_EXTERNAL, |
| 198 | Settings.Global.FSTRIM_MANDATORY_INTERVAL, |
| 199 | Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST, |
| 200 | Settings.Global.GLOBAL_HTTP_PROXY_HOST, |
| 201 | Settings.Global.GLOBAL_HTTP_PROXY_PAC, |
| 202 | Settings.Global.GLOBAL_HTTP_PROXY_PORT, |
| 203 | Settings.Global.GPRS_REGISTER_CHECK_PERIOD_MS, |
| 204 | Settings.Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED, |
| 205 | Settings.Global.HDMI_CONTROL_AUTO_WAKEUP_ENABLED, |
| 206 | Settings.Global.HDMI_CONTROL_ENABLED, |
Donghyun Cho | c1fa9af | 2016-12-27 18:31:09 +0900 | [diff] [blame] | 207 | Settings.Global.HDMI_SYSTEM_AUDIO_CONTROL_ENABLED, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 208 | Settings.Global.HEADS_UP_NOTIFICATIONS_ENABLED, |
| 209 | Settings.Global.HTTP_PROXY, |
| 210 | Settings.Global.INET_CONDITION_DEBOUNCE_DOWN_DELAY, |
| 211 | Settings.Global.INET_CONDITION_DEBOUNCE_UP_DELAY, |
| 212 | Settings.Global.INTENT_FIREWALL_UPDATE_CONTENT_URL, |
| 213 | Settings.Global.INTENT_FIREWALL_UPDATE_METADATA_URL, |
| 214 | Settings.Global.JOB_SCHEDULER_CONSTANTS, |
Michal Karpinski | 034a83f | 2017-04-26 19:25:25 +0100 | [diff] [blame] | 215 | Settings.Global.LANG_ID_UPDATE_CONTENT_URL, |
| 216 | Settings.Global.LANG_ID_UPDATE_METADATA_URL, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 217 | Settings.Global.LOCATION_BACKGROUND_THROTTLE_INTERVAL_MS, |
Lifu Tang | c94ef4d | 2017-03-23 23:48:00 -0700 | [diff] [blame] | 218 | Settings.Global.LOCATION_BACKGROUND_THROTTLE_PROXIMITY_ALERT_INTERVAL_MS, |
Bryan Mawhinney | 24a2ae5 | 2017-01-31 11:18:50 +0000 | [diff] [blame] | 219 | Settings.Global.LOCATION_BACKGROUND_THROTTLE_PACKAGE_WHITELIST, |
| 220 | Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 221 | Settings.Global.LOCK_SOUND, |
| 222 | Settings.Global.LOW_BATTERY_SOUND, |
| 223 | Settings.Global.LOW_BATTERY_SOUND_TIMEOUT, |
| 224 | Settings.Global.LOW_POWER_MODE, |
| 225 | Settings.Global.LTE_SERVICE_FORCED, |
| 226 | Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE, |
| 227 | Settings.Global.MDC_INITIAL_MAX_RETRY, |
| 228 | Settings.Global.MHL_INPUT_SWITCHING_ENABLED, |
| 229 | Settings.Global.MHL_POWER_CHARGE_ENABLED, |
| 230 | Settings.Global.MOBILE_DATA, // Candidate for backup? |
| 231 | Settings.Global.MOBILE_DATA_ALWAYS_ON, |
| 232 | Settings.Global.MODE_RINGER, |
| 233 | Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION, |
| 234 | Settings.Global.MULTI_SIM_SMS_PROMPT, |
| 235 | Settings.Global.MULTI_SIM_SMS_SUBSCRIPTION, |
| 236 | Settings.Global.MULTI_SIM_VOICE_CALL_SUBSCRIPTION, |
| 237 | Settings.Global.MULTI_SIM_VOICE_PROMPT, |
| 238 | Settings.Global.NETSTATS_DEV_BUCKET_DURATION, |
| 239 | Settings.Global.NETSTATS_DEV_DELETE_AGE, |
| 240 | Settings.Global.NETSTATS_DEV_PERSIST_BYTES, |
| 241 | Settings.Global.NETSTATS_DEV_ROTATE_AGE, |
| 242 | Settings.Global.NETSTATS_ENABLED, |
| 243 | Settings.Global.NETSTATS_GLOBAL_ALERT_BYTES, |
| 244 | Settings.Global.NETSTATS_POLL_INTERVAL, |
| 245 | Settings.Global.NETSTATS_SAMPLE_ENABLED, |
| 246 | Settings.Global.NETSTATS_TIME_CACHE_MAX_AGE, |
| 247 | Settings.Global.NETSTATS_UID_BUCKET_DURATION, |
| 248 | Settings.Global.NETSTATS_UID_DELETE_AGE, |
| 249 | Settings.Global.NETSTATS_UID_PERSIST_BYTES, |
| 250 | Settings.Global.NETSTATS_UID_ROTATE_AGE, |
| 251 | Settings.Global.NETSTATS_UID_TAG_BUCKET_DURATION, |
| 252 | Settings.Global.NETSTATS_UID_TAG_DELETE_AGE, |
| 253 | Settings.Global.NETSTATS_UID_TAG_PERSIST_BYTES, |
| 254 | Settings.Global.NETSTATS_UID_TAG_ROTATE_AGE, |
| 255 | Settings.Global.NETWORK_AVOID_BAD_WIFI, |
Bryan Mawhinney | 9a471b94 | 2017-02-01 13:18:07 +0000 | [diff] [blame] | 256 | Settings.Global.NETWORK_METERED_MULTIPATH_PREFERENCE, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 257 | Settings.Global.NETWORK_PREFERENCE, |
Bryan Mawhinney | 2c5f95a | 2017-02-21 10:58:23 +0000 | [diff] [blame] | 258 | Settings.Global.NETWORK_RECOMMENDATIONS_PACKAGE, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 259 | Settings.Global.NETWORK_RECOMMENDATION_REQUEST_TIMEOUT_MS, |
| 260 | Settings.Global.NETWORK_SCORER_APP, |
| 261 | Settings.Global.NETWORK_SCORING_PROVISIONED, |
Bryan Mawhinney | 24a2ae5 | 2017-01-31 11:18:50 +0000 | [diff] [blame] | 262 | Settings.Global.NETWORK_SCORING_UI_ENABLED, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 263 | Settings.Global.NETWORK_SWITCH_NOTIFICATION_DAILY_LIMIT, |
| 264 | Settings.Global.NETWORK_SWITCH_NOTIFICATION_RATE_LIMIT_MILLIS, |
| 265 | Settings.Global.NEW_CONTACT_AGGREGATOR, |
| 266 | Settings.Global.NITZ_UPDATE_DIFF, |
| 267 | Settings.Global.NITZ_UPDATE_SPACING, |
| 268 | Settings.Global.NSD_ON, |
| 269 | Settings.Global.NTP_SERVER, |
| 270 | Settings.Global.NTP_TIMEOUT, |
| 271 | Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, |
| 272 | Settings.Global.OVERLAY_DISPLAY_DEVICES, |
| 273 | Settings.Global.PAC_CHANGE_DELAY, |
| 274 | Settings.Global.PACKAGE_VERIFIER_DEFAULT_RESPONSE, |
| 275 | Settings.Global.PACKAGE_VERIFIER_ENABLE, |
| 276 | Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, |
| 277 | Settings.Global.PACKAGE_VERIFIER_SETTING_VISIBLE, |
| 278 | Settings.Global.PACKAGE_VERIFIER_TIMEOUT, |
| 279 | Settings.Global.PDP_WATCHDOG_ERROR_POLL_COUNT, |
| 280 | Settings.Global.PDP_WATCHDOG_ERROR_POLL_INTERVAL_MS, |
| 281 | Settings.Global.PDP_WATCHDOG_LONG_POLL_INTERVAL_MS, |
| 282 | Settings.Global.PDP_WATCHDOG_MAX_PDP_RESET_FAIL_COUNT, |
| 283 | Settings.Global.PDP_WATCHDOG_POLL_INTERVAL_MS, |
| 284 | Settings.Global.PDP_WATCHDOG_TRIGGER_PACKET_COUNT, |
| 285 | Settings.Global.POLICY_CONTROL, |
Bryan Mawhinney | 24a2ae5 | 2017-01-31 11:18:50 +0000 | [diff] [blame] | 286 | Settings.Global.POWER_MANAGER_CONSTANTS, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 287 | Settings.Global.PREFERRED_NETWORK_MODE, |
| 288 | Settings.Global.PROVISIONING_APN_ALARM_DELAY_IN_MS, |
| 289 | Settings.Global.RADIO_BLUETOOTH, |
| 290 | Settings.Global.RADIO_CELL, |
| 291 | Settings.Global.RADIO_NFC, |
| 292 | Settings.Global.RADIO_WIFI, |
| 293 | Settings.Global.RADIO_WIMAX, |
Amin Shaikh | d3c8193 | 2017-02-06 16:22:42 -0800 | [diff] [blame] | 294 | Settings.Global.RECOMMENDED_NETWORK_EVALUATOR_CACHE_EXPIRY_MS, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 295 | Settings.Global.READ_EXTERNAL_STORAGE_ENFORCED_DEFAULT, |
| 296 | Settings.Global.REQUIRE_PASSWORD_TO_DECRYPT, |
| 297 | Settings.Global.RETAIL_DEMO_MODE_CONSTANTS, |
| 298 | Settings.Global.SAFE_BOOT_DISALLOWED, |
| 299 | Settings.Global.SAMPLING_PROFILER_MS, |
| 300 | Settings.Global.SELINUX_STATUS, |
| 301 | Settings.Global.SELINUX_UPDATE_CONTENT_URL, |
| 302 | Settings.Global.SELINUX_UPDATE_METADATA_URL, |
| 303 | Settings.Global.SEND_ACTION_APP_ERROR, |
| 304 | Settings.Global.SET_GLOBAL_HTTP_PROXY, |
| 305 | Settings.Global.SET_INSTALL_LOCATION, |
| 306 | Settings.Global.SETUP_PREPAID_DATA_SERVICE_URL, |
| 307 | Settings.Global.SETUP_PREPAID_DETECTION_REDIR_HOST, |
| 308 | Settings.Global.SETUP_PREPAID_DETECTION_TARGET_URL, |
| 309 | Settings.Global.SHORTCUT_MANAGER_CONSTANTS, |
Geoffrey Pitsch | bd3ec6a | 2017-05-04 14:56:33 -0400 | [diff] [blame] | 310 | Settings.Global.SHOW_NOTIFICATION_CHANNEL_WARNINGS, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 311 | Settings.Global.SHOW_TEMPERATURE_WARNING, |
Michal Karpinski | 034a83f | 2017-04-26 19:25:25 +0100 | [diff] [blame] | 312 | Settings.Global.SMART_SELECTION_UPDATE_CONTENT_URL, |
| 313 | Settings.Global.SMART_SELECTION_UPDATE_METADATA_URL, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 314 | Settings.Global.SMS_OUTGOING_CHECK_INTERVAL_MS, |
| 315 | Settings.Global.SMS_OUTGOING_CHECK_MAX_COUNT, |
| 316 | Settings.Global.SMS_SHORT_CODE_CONFIRMATION, |
| 317 | Settings.Global.SMS_SHORT_CODE_RULE, |
| 318 | Settings.Global.SMS_SHORT_CODES_UPDATE_CONTENT_URL, |
| 319 | Settings.Global.SMS_SHORT_CODES_UPDATE_METADATA_URL, |
| 320 | Settings.Global.STORAGE_BENCHMARK_INTERVAL, |
| 321 | Settings.Global.SYNC_MAX_RETRY_DELAY_IN_SECONDS, |
| 322 | Settings.Global.SYS_FREE_STORAGE_LOG_INTERVAL, |
Jeff Sharkey | 78f6f7f | 2017-02-21 13:57:31 -0700 | [diff] [blame] | 323 | Settings.Global.SYS_STORAGE_CACHE_MAX_BYTES, |
| 324 | Settings.Global.SYS_STORAGE_CACHE_PERCENTAGE, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 325 | Settings.Global.SYS_STORAGE_FULL_THRESHOLD_BYTES, |
| 326 | Settings.Global.SYS_STORAGE_THRESHOLD_MAX_BYTES, |
| 327 | Settings.Global.SYS_STORAGE_THRESHOLD_PERCENTAGE, |
| 328 | Settings.Global.TCP_DEFAULT_INIT_RWND, |
| 329 | Settings.Global.TETHER_DUN_APN, |
| 330 | Settings.Global.TETHER_DUN_REQUIRED, |
| 331 | Settings.Global.TETHER_SUPPORTED, |
| 332 | Settings.Global.THEATER_MODE_ON, |
| 333 | Settings.Global.TRANSITION_ANIMATION_SCALE, |
| 334 | Settings.Global.TRUSTED_SOUND, |
| 335 | Settings.Global.TZINFO_UPDATE_CONTENT_URL, |
| 336 | Settings.Global.TZINFO_UPDATE_METADATA_URL, |
Svet Ganov | f36d53c | 2017-05-24 00:27:21 -0700 | [diff] [blame] | 337 | Settings.Global.INSTALLED_INSTANT_APP_MIN_CACHE_PERIOD, |
| 338 | Settings.Global.INSTALLED_INSTANT_APP_MAX_CACHE_PERIOD, |
| 339 | Settings.Global.UNINSTALLED_INSTANT_APP_MIN_CACHE_PERIOD, |
| 340 | Settings.Global.UNINSTALLED_INSTANT_APP_MAX_CACHE_PERIOD, |
| 341 | Settings.Global.UNUSED_STATIC_SHARED_LIB_MIN_CACHE_PERIOD, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 342 | Settings.Global.UNLOCK_SOUND, |
| 343 | Settings.Global.USE_GOOGLE_MAIL, |
| 344 | Settings.Global.VT_IMS_ENABLED, |
| 345 | Settings.Global.WAIT_FOR_DEBUGGER, |
Sudheer Shanka | 5918c67 | 2017-03-21 19:31:37 -0700 | [diff] [blame] | 346 | Settings.Global.NETWORK_ACCESS_TIMEOUT_MS, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 347 | Settings.Global.WARNING_TEMPERATURE, |
| 348 | Settings.Global.WEBVIEW_DATA_REDUCTION_PROXY_KEY, |
| 349 | Settings.Global.WEBVIEW_FALLBACK_LOGIC_ENABLED, |
| 350 | Settings.Global.WEBVIEW_MULTIPROCESS, |
| 351 | Settings.Global.WEBVIEW_PROVIDER, |
| 352 | Settings.Global.WFC_IMS_ENABLED, |
| 353 | Settings.Global.WFC_IMS_MODE, |
| 354 | Settings.Global.WFC_IMS_ROAMING_ENABLED, |
| 355 | Settings.Global.WFC_IMS_ROAMING_MODE, |
Bryan Mawhinney | 9a471b94 | 2017-02-01 13:18:07 +0000 | [diff] [blame] | 356 | Settings.Global.WIFI_BADGING_THRESHOLDS, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 357 | Settings.Global.WIFI_BOUNCE_DELAY_OVERRIDE_MS, |
| 358 | Settings.Global.WIFI_COUNTRY_CODE, |
| 359 | Settings.Global.WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN, |
| 360 | Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON, |
| 361 | Settings.Global.WIFI_DISPLAY_ON, |
| 362 | Settings.Global.WIFI_DISPLAY_WPS_CONFIG, |
| 363 | Settings.Global.WIFI_ENHANCED_AUTO_JOIN, |
| 364 | Settings.Global.WIFI_EPHEMERAL_OUT_OF_RANGE_TIMEOUT_MS, |
| 365 | Settings.Global.WIFI_FRAMEWORK_SCAN_INTERVAL_MS, |
| 366 | Settings.Global.WIFI_FREQUENCY_BAND, |
| 367 | Settings.Global.WIFI_IDLE_MS, |
| 368 | Settings.Global.WIFI_MAX_DHCP_RETRY_COUNT, |
| 369 | Settings.Global.WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS, |
| 370 | Settings.Global.WIFI_NETWORK_SHOW_RSSI, |
| 371 | Settings.Global.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY, |
| 372 | Settings.Global.WIFI_NUM_OPEN_NETWORKS_KEPT, |
| 373 | Settings.Global.WIFI_ON, |
| 374 | Settings.Global.WIFI_P2P_DEVICE_NAME, |
| 375 | Settings.Global.WIFI_REENABLE_DELAY_MS, |
| 376 | Settings.Global.WIFI_SAVED_STATE, |
| 377 | Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, |
Wei Wang | 3b7528b | 2017-05-04 13:16:32 -0700 | [diff] [blame] | 378 | Settings.Global.WIFI_SCAN_BACKGROUND_THROTTLE_INTERVAL_MS, |
| 379 | Settings.Global.WIFI_SCAN_BACKGROUND_THROTTLE_PACKAGE_WHITELIST, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 380 | Settings.Global.WIFI_SCAN_INTERVAL_WHEN_P2P_CONNECTED_MS, |
| 381 | Settings.Global.WIFI_SLEEP_POLICY, |
| 382 | Settings.Global.WIFI_SUPPLICANT_SCAN_INTERVAL_MS, |
| 383 | Settings.Global.WIFI_SUSPEND_OPTIMIZATIONS_ENABLED, |
| 384 | Settings.Global.WIFI_VERBOSE_LOGGING_ENABLED, |
Bryan Mawhinney | 2092484 | 2017-05-11 12:50:14 +0100 | [diff] [blame] | 385 | Settings.Global.WIFI_WAKEUP_AVAILABLE, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 386 | Settings.Global.WIFI_WATCHDOG_ON, |
| 387 | Settings.Global.WIMAX_NETWORKS_AVAILABLE_NOTIFICATION_ON, |
| 388 | Settings.Global.WINDOW_ANIMATION_SCALE, |
| 389 | Settings.Global.WIRELESS_CHARGING_STARTED_SOUND, |
| 390 | Settings.Global.WTF_IS_FATAL, |
| 391 | Settings.Global.ZEN_MODE, |
| 392 | Settings.Global.ZEN_MODE_CONFIG_ETAG, |
| 393 | Settings.Global.ZEN_MODE_RINGER_LEVEL); |
| 394 | |
| 395 | private static final Set<String> BACKUP_BLACKLISTED_SECURE_SETTINGS = |
| 396 | newHashSet( |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 397 | Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE, |
| 398 | Settings.Secure.ALLOWED_GEOLOCATION_ORIGINS, |
| 399 | Settings.Secure.ALWAYS_ON_VPN_APP, |
| 400 | Settings.Secure.ALWAYS_ON_VPN_LOCKDOWN, |
| 401 | Settings.Secure.ANDROID_ID, |
| 402 | Settings.Secure.ANR_SHOW_BACKGROUND, |
| 403 | Settings.Secure.ASSISTANT, |
| 404 | Settings.Secure.ASSIST_DISCLOSURE_ENABLED, |
| 405 | Settings.Secure.ASSIST_SCREENSHOT_ENABLED, |
| 406 | Settings.Secure.ASSIST_STRUCTURE_ENABLED, |
Philip P. Moltmann | e287a15 | 2017-05-04 11:07:05 -0700 | [diff] [blame] | 407 | Settings.Secure.AUTOFILL_SERVICE_SEARCH_URI, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 408 | Settings.Secure.AUTOMATIC_STORAGE_MANAGER_BYTES_CLEARED, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 409 | Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, |
| 410 | Settings.Secure.AUTOMATIC_STORAGE_MANAGER_LAST_RUN, |
| 411 | Settings.Secure.BACKUP_AUTO_RESTORE, |
| 412 | Settings.Secure.BACKUP_ENABLED, |
| 413 | Settings.Secure.BACKUP_PROVISIONED, |
| 414 | Settings.Secure.BACKUP_TRANSPORT, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 415 | Settings.Secure.CARRIER_APPS_HANDLED, |
Jack Yu | 3902857 | 2017-02-23 09:49:25 -0800 | [diff] [blame] | 416 | Settings.Secure.CMAS_ADDITIONAL_BROADCAST_PKG, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 417 | Settings.Secure.COMPLETED_CATEGORY_PREFIX, |
| 418 | Settings.Secure.CONNECTIVITY_RELEASE_PENDING_INTENT_DELAY_MS, |
| 419 | Settings.Secure.DEFAULT_INPUT_METHOD, |
| 420 | Settings.Secure.DEMO_USER_SETUP_COMPLETE, |
| 421 | Settings.Secure.DEVICE_PAIRED, |
| 422 | Settings.Secure.DIALER_DEFAULT_APPLICATION, |
| 423 | Settings.Secure.DISABLED_PRINT_SERVICES, |
| 424 | Settings.Secure.DISABLED_SYSTEM_INPUT_METHODS, |
| 425 | Settings.Secure.DISPLAY_DENSITY_FORCED, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 426 | Settings.Secure.DOZE_ALWAYS_ON, |
| 427 | Settings.Secure.EMERGENCY_ASSISTANCE_APPLICATION, |
| 428 | Settings.Secure.ENABLED_NOTIFICATION_ASSISTANT, |
| 429 | Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES, |
| 430 | Settings.Secure.ENABLED_PRINT_SERVICES, |
| 431 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS, |
| 432 | Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR, |
| 433 | Settings.Secure.INPUT_METHOD_SELECTOR_VISIBILITY, |
| 434 | Settings.Secure.INPUT_METHODS_SUBTYPE_HISTORY, |
| 435 | Settings.Secure.INSTALL_NON_MARKET_APPS, |
| 436 | Settings.Secure.LAST_SETUP_SHOWN, |
| 437 | Settings.Secure.LOCATION_MODE, |
| 438 | Settings.Secure.LOCATION_PREVIOUS_MODE, |
| 439 | Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, // Candidate? |
| 440 | Settings.Secure.LOCK_SCREEN_ALLOW_REMOTE_INPUT, // Candidate? |
| 441 | Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, |
| 442 | Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, // Candidate? |
| 443 | Settings.Secure.LOCK_TO_APP_EXIT_LOCKED, |
| 444 | Settings.Secure.MANAGED_PROFILE_CONTACT_REMOTE_SEARCH, |
| 445 | Settings.Secure.MULTI_PRESS_TIMEOUT, |
| 446 | Settings.Secure.NFC_PAYMENT_FOREGROUND, |
Bryan Mawhinney | 2c5f95a | 2017-02-21 10:58:23 +0000 | [diff] [blame] | 447 | Settings.Secure.OVERVIEW_LAST_STACK_ACTIVE_TIME, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 448 | Settings.Secure.PACKAGE_VERIFIER_STATE, |
| 449 | Settings.Secure.PACKAGE_VERIFIER_USER_CONSENT, |
| 450 | Settings.Secure.PARENTAL_CONTROL_LAST_UPDATE, |
| 451 | Settings.Secure.PAYMENT_SERVICE_SEARCH_URI, |
| 452 | Settings.Secure.PRINT_SERVICE_SEARCH_URI, |
| 453 | Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK, // Candidate? |
| 454 | Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP, // Candidate? |
| 455 | Settings.Secure.SCREENSAVER_COMPONENTS, |
| 456 | Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT, // Candidate? |
| 457 | Settings.Secure.SCREENSAVER_ENABLED, // Candidate? |
| 458 | Settings.Secure.SEARCH_GLOBAL_SEARCH_ACTIVITY, |
| 459 | Settings.Secure.SEARCH_MAX_RESULTS_PER_SOURCE, |
| 460 | Settings.Secure.SEARCH_MAX_RESULTS_TO_DISPLAY, |
| 461 | Settings.Secure.SEARCH_MAX_SHORTCUTS_RETURNED, |
| 462 | Settings.Secure.SEARCH_MAX_SOURCE_EVENT_AGE_MILLIS, |
| 463 | Settings.Secure.SEARCH_MAX_STAT_AGE_MILLIS, |
| 464 | Settings.Secure.SEARCH_MIN_CLICKS_FOR_SOURCE_RANKING, |
| 465 | Settings.Secure.SEARCH_MIN_IMPRESSIONS_FOR_SOURCE_RANKING, |
| 466 | Settings.Secure.SEARCH_NUM_PROMOTED_SOURCES, |
| 467 | Settings.Secure.SEARCH_PER_SOURCE_CONCURRENT_QUERY_LIMIT, |
| 468 | Settings.Secure.SEARCH_PREFILL_MILLIS, |
| 469 | Settings.Secure.SEARCH_PROMOTED_SOURCE_DEADLINE_MILLIS, |
| 470 | Settings.Secure.SEARCH_QUERY_THREAD_CORE_POOL_SIZE, |
| 471 | Settings.Secure.SEARCH_QUERY_THREAD_MAX_POOL_SIZE, |
| 472 | Settings.Secure.SEARCH_SHORTCUT_REFRESH_CORE_POOL_SIZE, |
| 473 | Settings.Secure.SEARCH_SHORTCUT_REFRESH_MAX_POOL_SIZE, |
| 474 | Settings.Secure.SEARCH_SOURCE_TIMEOUT_MILLIS, |
| 475 | Settings.Secure.SEARCH_THREAD_KEEPALIVE_SECONDS, |
| 476 | Settings.Secure.SEARCH_WEB_RESULTS_OVERRIDE_LIMIT, |
| 477 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, |
| 478 | Settings.Secure.SETTINGS_CLASSNAME, |
| 479 | Settings.Secure.SHOW_NOTE_ABOUT_NOTIFICATION_HIDING, // candidate? |
| 480 | Settings.Secure.SKIP_FIRST_USE_HINTS, // candidate? |
| 481 | Settings.Secure.SMS_DEFAULT_APPLICATION, |
| 482 | Settings.Secure.TRUST_AGENTS_INITIALIZED, |
| 483 | Settings.Secure.TV_INPUT_CUSTOM_LABELS, |
| 484 | Settings.Secure.TV_INPUT_HIDDEN_INPUTS, |
| 485 | Settings.Secure.UI_NIGHT_MODE, // candidate? |
Suprabh Shukla | 0b1356f | 2017-02-21 14:33:50 -0800 | [diff] [blame] | 486 | Settings.Secure.UNKNOWN_SOURCES_DEFAULT_REVERSED, |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 487 | Settings.Secure.UNSAFE_VOLUME_MUSIC_ACTIVE_MS, |
| 488 | Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED, |
| 489 | Settings.Secure.USER_SETUP_COMPLETE, |
| 490 | Settings.Secure.VOICE_INTERACTION_SERVICE, |
| 491 | Settings.Secure.VOICE_RECOGNITION_SERVICE, |
Jesse Evans | fc1bfc4 | 2017-04-07 16:11:26 -0700 | [diff] [blame] | 492 | Settings.Secure.INSTANT_APPS_ENABLED); |
Bryan Mawhinney | 87b1aac | 2017-01-16 18:06:07 +0000 | [diff] [blame] | 493 | |
| 494 | @Test |
| 495 | public void systemSettingsBackedUpOrBlacklisted() { |
| 496 | checkSettingsBackedUpOrBlacklisted( |
| 497 | getCandidateSettings(Settings.System.class), |
| 498 | newHashSet(Settings.System.SETTINGS_TO_BACKUP), |
| 499 | BACKUP_BLACKLISTED_SYSTEM_SETTINGS); |
| 500 | } |
| 501 | |
| 502 | @Test |
| 503 | public void globalSettingsBackedUpOrBlacklisted() { |
| 504 | checkSettingsBackedUpOrBlacklisted( |
| 505 | getCandidateSettings(Settings.Global.class), |
| 506 | newHashSet(Settings.Global.SETTINGS_TO_BACKUP), |
| 507 | BACKUP_BLACKLISTED_GLOBAL_SETTINGS); |
| 508 | } |
| 509 | |
| 510 | @Test |
| 511 | public void secureSettingsBackedUpOrBlacklisted() { |
| 512 | checkSettingsBackedUpOrBlacklisted( |
| 513 | getCandidateSettings(Settings.Secure.class), |
| 514 | newHashSet(Settings.Secure.SETTINGS_TO_BACKUP), |
| 515 | BACKUP_BLACKLISTED_SECURE_SETTINGS); |
| 516 | } |
| 517 | |
| 518 | private static void checkSettingsBackedUpOrBlacklisted( |
| 519 | Set<String> settings, Set<String> settingsToBackup, Set<String> blacklist) { |
| 520 | Set<String> settingsNotBackedUp = difference(settings, settingsToBackup); |
| 521 | Set<String> settingsNotBackedUpOrBlacklisted = difference(settingsNotBackedUp, blacklist); |
| 522 | assertThat( |
| 523 | "Settings not backed up or blacklisted", |
| 524 | settingsNotBackedUpOrBlacklisted, |
| 525 | is(empty())); |
| 526 | |
| 527 | assertThat( |
| 528 | "blacklisted settings backed up", |
| 529 | intersect(settingsToBackup, blacklist), |
| 530 | is(empty())); |
| 531 | } |
| 532 | |
| 533 | private static Set<String> getCandidateSettings(Class<? extends Settings.NameValueTable> clazz) { |
| 534 | HashSet<String> result = new HashSet<String>(); |
| 535 | for (Field field : clazz.getDeclaredFields()) { |
| 536 | if (looksLikeValidSetting(field)) { |
| 537 | try { |
| 538 | result.add((String) field.get(null)); |
| 539 | } catch (IllegalAccessException e) { |
| 540 | // Impossible for public fields |
| 541 | throw new RuntimeException(e); |
| 542 | } |
| 543 | } |
| 544 | } |
| 545 | return result; |
| 546 | } |
| 547 | |
| 548 | private static boolean looksLikeValidSetting(Field field) { |
| 549 | int modifiers = field.getModifiers(); |
| 550 | return isPublic(modifiers) |
| 551 | && isStatic(modifiers) |
| 552 | && isFinal(modifiers) |
| 553 | && field.getType() == String.class |
| 554 | && field.getAnnotation(Deprecated.class) == null; |
| 555 | } |
| 556 | |
| 557 | private static <T> Set<T> difference(Set<T> s1, Set<T> s2) { |
| 558 | HashSet<T> result = new HashSet<T>(s1); |
| 559 | result.removeAll(s2); |
| 560 | return result; |
| 561 | } |
| 562 | |
| 563 | private static <T> Set<T> intersect(Set<T> s1, Set<T> s2) { |
| 564 | HashSet<T> result = new HashSet<T>(s1); |
| 565 | result.retainAll(s2); |
| 566 | return result; |
| 567 | } |
| 568 | |
| 569 | } |