Skip to content

Instantly share code, notes, and snippets.

@chenyiping1995
Last active June 21, 2023 08:54
Show Gist options
  • Save chenyiping1995/c43da1570f1c101d78c49c095d6f2a49 to your computer and use it in GitHub Desktop.
Save chenyiping1995/c43da1570f1c101d78c49c095d6f2a49 to your computer and use it in GitHub Desktop.
This script snippet attempts to modify a few settings in SettingsProvider (that is normally not accessible to end user) for easier use of stock Android OS.
# Android Debug Bridge (adb) interactive shell should be used to change these settings.
# Since the 'settings' shell command only exists on Android 4.2 or newer versions of Android, even if the SettingsProvider has the key/value pairs, there is no way for legacy OS prior to Android 4.2 to change these with the command specified in this shell snippet.
# See https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/provider/Settings.java for latest SettingsProvider key/value pairs.
# See https://android.googlesource.com/platform/frameworks/base/+/refs/tags/android-$(Android_Version_Code)_r$(Android_Version_Revision_Code)/core/java/android/provider/Settings.java for SettingsProvider key/value pairs for a specific version of Android. Android Version Code and Android Version Revision Code could be found at https://android.googlesource.com/platform/frameworks/base/+refs .
# Specifies the device's UTC system clock and date should be set automatically from sources like NITZ, GNSS or NTP. Prior to Android 4.0.1_r1, this setting also enables network-based automatic time zone configuration.
# Valid since Android 1.6_r1. Not deprecated in latest Android release.
adb shell settings put global auto_time 1
# Sets the date format to YYYY/MM/DD.
# Valid since Android 1.6_r1. Not deprecated in latest Android release.
adb shell settings put system date_format yyyy/mm/dd
# Sets the time format to 24 hours.
# Valid since Android 1.6_r1. Not deprecated in latest Android release.
adb shell settings put system time_12_24 24
# Enables network-based automatic time zone configuration.
# Valid since Android 4.0.1_r1. Not deprecated in latest Android release.
adb shell settings put global auto_time_zone 1
# Sets default NTP server for time synchronization.
# Valid since Android 4.0.1_r1. Not deprecated in latest Android release.
adb shell settings put global ntp_server ntp.aliyun.com
# Sets default DNS server for domain name resolution. Only appliable to networks that do not have DNS specified.
# Valid since Android 4.0.1_r1. Not deprecated in latest Android release.
adb shell settings put global default_dns_server 223.5.5.5
# Enables active connection probing using captive server.
# Valid since Android 4.2_r1. Deprecated since Android 7.1.2_r1, by <code>captive_portal_mode</code> varible. Not removed in latest Android release.
adb shell settings put global captive_portal_detection_enabled 1
# Sets the captive server used for active connection probing.
# Valid since Android 4.2_r1. Deprecated since Android Android 7.1.1_r1, by <code>captive_portal_https_url</code>, <code>captive_portal_http_url</code>, <code>captive_portal_fallback_url</code> and <code>captive_portal_other_fallback_urls</code> varibles. Not removed in latest Android release.
adb shell settings put global captive_portal_server conn1.oppomobile.com
# Sets the preference whether to use HTTPS for network validation.
# Valid since Android 7.0.0_r1. Not deprecated in latest Android release.
adb shell settings put global captive_portal_use_https 1
# Sets the exact URLs used for active connection probing. These settings override the deprecated <code>captive_portal_server</code> varible.
# Valid since Android 7.1.1_r1. Not deprecated in latest Android release.
adb shell settings put global captive_portal_https_url https://conn1.oppomobile.com/generate_204
adb shell settings put global captive_portal_http_url http://conn1.oppomobile.com/generate_204
adb shell settings put global captive_portal_fallback_url https://conn2.oppomobile.com/generate_204
# Sets other fallback URLs used for active connection probing. The URLs are seperated using comma. These URLs are never used but were defined nonetheless.
# Valid since Android 7.1.1_r31. Not deprecated in latest Android release.
adb shell settings put global captive_portal_other_fallback_urls https://connect.rom.miui.com/generate_204,https://connectivitycheck.platform.hicloud.com/generate_204,https://www.google.cn/generate_204,https://services.googleapis.cn/generate_204,https://www.gstatic.cn/generate_204,https://developer.android.google.cn/generate_204,https://source.android.google.cn/generate_204,https://www.google-analytics.com/generate_204,https://connectivitycheck.gstatic.com/generate_204,https://www.gstatic.com/generate_204,https://cp.cloudflare.com/generate_204,https://wifi.vivo.com.cn/generate_204,https://www.qualcomm.cn/generate_204,https://captive.v2ex.co/generate_204,https://204.io/generate_204,https://204.ustclug.org/generate_204,https://gen204.applinzi.com/generate_204,https://www.noisyfox.io/generate_204
# Sets active connection probing preference to display a notification that prompts the user to sign in when detecting a captive portal. This setting overrides the deprecated <code>captive_portal_detection_enabled</code> variable.
# Valid since Android 7.1.2_r1. Not deprecated in latest Android release.
adb shell settings put global captive_portal_mode 1
# Sets other fallback URLs used for active connection probing, that do not follow the traditional HTTP 204 way but instead use other HTTP codes and/or content. This setting follows <code>url@@/@@statusCodeRegex@@/@@contentRegex</code> format, and different specs are seperated by <code>@@,@@</code>. These URLs are never used but were defined nonetheless.
# Valid since Android 9.0.0_r1. Not deprecated in latest Android release.
adb shell settings put global captive_portal_fallback_probe_specs https://captive.apple.com/hotspot-detect.html@@/@@200@@/@@/Success/@@,@@https://fedoraproject.org/static/hotspot.txt@@/@@200@@/@@/^OK$/@@,@@http://www.msftncsi.com/ncsi.txt@@/@@200@@/@@/^Microsoft\x20NCSI$/@@,@@http://www.msftconnecttest.com/connecttest.txt@@/@@200@@/@@/^Microsoft\x20Connect\x20Test$/
# Enables location-based automatic time zone detection.
# Valid since Android 12.0.0_r1. Not deprecated in latest Android release.
adb shell settings put secure location_time_zone_detection_enabled 1
# Enables automatic time on Android Wearable devices.
# Valid since Android 13.0.0_r1. Not deprecated in latest Android release.
adb shell settings put global clockwork_auto_time 1
# Enables automatic time zone on Android Wearable devices.
# Valid since Android 13.0.0_r1. Not deprecated in latest Android release.
adb shell settings put global clockwork_auto_time_zone 1
# Sets the time format on Android Wearable devices to 24 hours.
# Valid since Android 13.0.0_r1. Not deprecated in latest Android release.
adb shell settings put global clockwork_24hr_time 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment