Android 6.0 默认关闭定位和GPS,开启后默认选省电,永不休眠
发布日期:2021-06-29 13:08:01 浏览次数:2 分类:技术文章

本文共 3631 字,大约阅读时间需要 12 分钟。

默认关闭定位和GPS 修改位置

frameworks/base/packages/SettingsProvider/res/values/defaults.xml

network,gps
修改为

默认省电 修改位置

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

15 seconds
30 seconds
1 minute
2 minutes
5 minutes
10 minutes
30 minutes
never
15000
30000
60000
120000
300000
600000
1800000
2147483647
"15秒"
"30秒"
"1分钟"
"2分钟"
"5分钟"
"10分钟"
"30分钟"
"永不"

方法二

frameworks/base/core/res/res/values/config.xml

-1

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);}

转载地址:https://cczheng.blog.csdn.net/article/details/89002193 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Android6.0 源码修改之 仿IOS添加全屏可拖拽浮窗返回按钮
下一篇:Android6.0 源码修改之 Contacts应用

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年04月27日 01时42分48秒