默认关闭定位和GPS 修改位置
frameworks/base/packages/SettingsProvider/res/values/defaults.xml
<string name="def_location_providers_allowed" translatable="false">network,gps</string> 修改为 <string name="def_location_providers_allowed" translatable="false"></string>
默认省电 修改位置
com/android/settings/location/LocationSettings.java
public class LocationSettings extends LocationSettingsBase @Override public void onSwitchChanged(Switch switchView, boolean isChecked) { if (isChecked) { //setLocationMode(android.provider.Settings.Secure.LOCATION_MODE_HIGH_ACCURACY); setLocationMode(android.provider.Settings.Secure.LOCATION_MODE_BATTERY_SAVING); } else { setLocationMode(android.provider.Settings.Secure.LOCATION_MODE_OFF); }
查看当前模式
adb shell settings get secure location_providers_allowed
1.关闭location:
结果空
2.开location,high_accuracy模式
network,gps
3.开location,battery_saving模式
network
4.开location,sensors_only模式
gps
永不休眠
方法一
packages/apps/Provision/src/com/android/provision/DefaultActivity.java
增加配置
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, Integer.MAX_VALUE);
packages/apps/Settings/src/com/android/settings/DisplaySettings.java
修改 updateTimeoutPreferenceDescription 显示的值
private void updateTimeoutPreferenceDescription(long currentTimeout) { ListPreference preference = mScreenTimeoutPreference; String summary=""; if (currentTimeout < 0) { // Unsupported value summary = ""; } else { final CharSequence[] entries = preference.getEntries(); final CharSequence[] values = preference.getEntryValues(); if (entries == null || entries.length == 0) { summary = ""; } else { int best = 0; for (int i = 0; i < values.length; i++) { long timeout = Long.parseLong(values[i].toString()); if (currentTimeout >= timeout) { best = i; } } //cczheng add if if(currentTimeout == Integer.MAX_VALUE) summary = entries[best].toString(); else summary = preference.getContext().getString(R.string.screen_timeout_summary, entries[best]); } } preference.setSummary(summary); }
修改对应的资源文件值
packages/apps/Settings/res/values-zh-rCN/arrays.xml
packages/apps/Settings/res/values/arrays.xml
<string-array name="screen_timeout_entries"> <item>15 seconds</item> <item>30 seconds</item> <item>1 minute</item> <item>2 minutes</item> <item>5 minutes</item> <item>10 minutes</item> <item>30 minutes</item> <item>never</item> </string-array> <!-- Do not translate. --> <string-array name="screen_timeout_values" translatable="false"> <!-- Do not translate. --> <item>15000</item> <!-- Do not translate. --> <item>30000</item> <!-- Do not translate. --> <item>60000</item> <!-- Do not translate. --> <item>120000</item> <!-- Do not translate. --> <item>300000</item> <!-- Do not translate. --> <item>600000</item> <!-- Do not translate. --> <item>1800000</item> <!--Interger.MAX--> <item>2147483647</item> </string-array> <string-array name="screen_timeout_entries"> <item msgid="3342301044271143016">"15秒"</item> <item msgid="8881760709354815449">"30秒"</item> <item msgid="7589406073232279088">"1分钟"</item> <item msgid="7001195990902244174">"2分钟"</item> <item msgid="7489864775127957179">"5分钟"</item> <item msgid="2314124409517439288">"10分钟"</item> <item msgid="6864027152847611413">"30分钟"</item> <item msgid="6864027152847611485">"永不"</item> </string-array>
方法二
frameworks/base/core/res/res/values/config.xml
<integer name="config_minimumScreenOffTimeout">-1</integer>
frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java
private int getScreenOffTimeoutLocked(int sleepTimeout) { .... if (sleepTimeout >= 0) { timeout = Math.min(timeout, sleepTimeout); } if (mMinimumScreenOffTimeoutConfig < 0 ) { return mMaximumScreenOffTimeoutFromDeviceAdmin; } return Math.max(timeout, mMinimumScreenOffTimeoutConfig); }