Android6.0 禁止自动同步网络时间
扫描二维码
随时随地手机看文章
配置文件在:frameworks/base/packages/SettingsProvider/res/values/defaults.xml
falsefalse
直接将def_auto_time 和 def_auto_time_zone设置成false,就不会同步网络时间了。
如果用户去设置中去勾选,还是可以同步时间的,下面将把设置中的自动同步选项移除,
移除packages/apps/Settings/res/xml/date_time_prefs.xml
-->
在packages/apps/Settings/src/com/android/settings/DateTimeSettings.java删除有关获取auto_time的ID的代码。
--- a/packages/apps/Settings/src/com/android/settings/DateTimeSettings.java +++ b/packages/apps/Settings/src/com/android/settings/DateTimeSettings.java @@ -93,12 +93,12 @@ public class DateTimeSettings extends SettingsPreferenceFragment boolean autoTimeEnabled = getAutoState(Settings.Global.AUTO_TIME); boolean autoTimeZoneEnabled = getAutoState(Settings.Global.AUTO_TIME_ZONE); - mAutoTimePref = (SwitchPreference) findPreference(KEY_AUTO_TIME); + // mAutoTimePref = (SwitchPreference) findPreference(KEY_AUTO_TIME); DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context .DEVICE_POLICY_SERVICE); if (dpm.getAutoTimeRequired()) { - mAutoTimePref.setEnabled(false); + // mAutoTimePref.setEnabled(false); // If Settings.Global.AUTO_TIME is false it will be set to true // by the device policy manager very soon. @@ -110,7 +110,7 @@ public class DateTimeSettings extends SettingsPreferenceFragment mDummyDate = Calendar.getInstance(); - mAutoTimePref.setChecked(autoTimeEnabled); + //mAutoTimePref.setChecked(autoTimeEnabled);
如果觉得还是不放心,可以直接禁止同步时间的服务
frameworks/base/services/java/com/android/server/SystemServer.java
在这里找到NetworkTimeUpdateService把相关代码注释掉就可以。