如果想第一次烧录系统开机就是永不休眠。这个需要修改def_screen_off_timeout = -1,在android 第一次开机的时候会去读取这个值,
在文件SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
R.integer.def_screen_off_timeout);
中将def_screen_off_timeout 保存在数据库中SCREEN_OFF_TIMEOUT = def_screen_off_timeout,
当启动设置应用时,路径(package/apps/Settings)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
........
final long currentTimeout = getTimoutValue();
.......
updateTimeoutPreferenceDescription(currentTimeout);
private int getTimoutValue() {
int currentValue = Settings.System.getInt(getActivity()
.getContentResolver(), SCREEN_OFF_TIMEOUT,
FALLBACK_SCREEN_TIMEOUT_VALUE);
Xlog.d(TAG, "getTimoutValue()---currentValue=" + currentValue);
int bestMatch = 0;
int timeout = 0;
final CharSequence[] valuesTimeout = mScreenTimeoutPreference
.getEntryValues();
for (int i = 0; i < valuesTimeout.length; i++) {
timeout = Integer.parseInt(valuesTimeout[i].toString());
if (currentValue == timeout) {
return currentValue;
} else {
if (currentValue > timeout) {
bestMatch = i;
}
}
}
Xlog.d(TAG, "getTimoutValue()---bestMatch=" + bestMatch);
return Integer.parseInt(valuesTimeout[bestMatch].toString()); }
读取数据中SCREEN_OFF_TIMEOUT 的值并更新到设置应用中。
在文件 PowerManagerService.java的函数 getScreenOffTimeoutLocked 修改前:
private int getScreenOffTimeoutLocked() {
int timeout = mScreenOffTimeoutSetting;
if (isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()) {
timeout = Math.min(timeout, mMaximumScreenOffTimeoutFromDeviceAdmin);
}
if (mUserActivityTimeoutOverrideFromWindowManager >= 0) {
timeout = (int)Math.min(timeout, mUserActivityTimeoutOverrideFromWindowManager);
}
return Math.max(timeout, MINIMUM_SCREEN_OFF_TIMEOUT);
}
修改后
private int getScreenOffTimeoutLocked() {
int nosleep;
int timeout = mScreenOffTimeoutSetting;
if (isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()) {
timeout = Math.min(timeout, mMaximumScreenOffTimeoutFromDeviceAdmin);
}
if (mUserActivityTimeoutOverrideFromWindowManager >= 0) {
timeout = (int)Math.min(timeout, mUserActivityTimeoutOverrideFromWindowManager);
}
nosleep = mScreenOffTimeoutSetting;
if(nosleep < 0) {
nosleep = mMaximumScreenOffTimeoutFromDeviceAdmin ;
return Math.max(nosleep, mMaximumScreenOffTimeoutFromDeviceAdmin);
}
return Math.max(timeout, MINIMUM_SCREEN_OFF_TIMEOUT);
}
这个函数会在设置时间有改动的时候被调用,
mMaximumScreenOffTimeoutFromDeviceAdmin 为系统支持最大不休眠的时间 大概为2147483647 ,大概200小时 。远远超过我们的电池电量的时间。
修改设置应用的代码 Settings/res/values/arrays.xml
<string-array name="screen_timeout_entries">
<item>never</item>
<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>
</string-array>
第一行添加 never
<string-array name="screen_timeout_values" translatable="false">
<item>-1</item>
<!-- 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>
</string-array>
第一行添加 -1
res/values-zh-rCN/arrays.xml 中 添加第一行
<string-array name="screen_timeout_entries">
<item msgid="6868686868686868688">"永不 休眠"</item>
<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>
</string-array>
在函数 updateTimeoutPreferenceDescription 中修改
if (currentTimeout < 0) {
// Unsupported value
summary = "";
}
改为
if (currentTimeout < -1)
在下面代码中添加
if (entries.length != 0) {
summary = preference.getContext().getString(
R.string.screen_timeout_summary, entries[best]);
//add new code
if(currentTimeout < 0)
summary =entries[best].toString();
//end new code
} else {