由于本比较菜,源码的理解不到位,无法精准对症下药,找了三种方案一个一个试把。
1:先修改res/values/arrays.xml
该文件中保存的是数组资源,哪种方案都是需要改的。
30 minutes
//增加改选项,为页面上看的到的数组选项
Never
1800000
//增加选项2147483647为int最大值
2147483647
2:修改 src/com/android/settings/display/TimeoutListPreference.java
最后修改src/com/android/settings/display/TimeoutPreferenceController.java
1:packages/apps/Settings/res/values/arrays.xml
30 minutes
//下面为新增
Never
1800000
-1 //如果-1编译会报错则看另一种方案
2:然后在Settings.java文件中修改设置的休眠时间
//putInt最终调用的是putIntForUser
public static boolean putInt(ContentResolver cr, String name, int value) {
return putIntForUser(cr, name, value, cr.getUserId());
}
//putIntForUser中根据传入的name和value特殊值-1进行修改设置
/** @hide */
@UnsupportedAppUsage
public static boolean putIntForUser(ContentResolver cr, String name, int value,int userHandle) {
///ADD START
if(name.equals(SCREEN_OFF_TIMEOUT))
{
//-1说明是我们在设置中添加的永不休眠的值
if(value==-1)
{
//
Log.d(“Settings”,“change screen timeout for:”+Integer.toString(Integer.MAX_VALUE-1000));
return putStringForUser(cr, name, Integer.toString(Integer.MAX_VALUE-1000), userHandle);
}
}
///ADD END
return putStringForUser(cr, name, Integer.toString(value), userHandle);
}
1:packages/apps/Settings/res/values/arrays.xml
30 minutes
never
1800000
2147483647
2:packages/apps/Settings/src/com/android/settings/display/TimeoutPreferenceController.java
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
try {
long value = Long.parseLong((String) newValue); //int修改成long
Settings.System.putLong(mContext.getContentResolver(), SCREEN_OFF_TIMEOUT, value);
updateTimeoutPreferenceDescription((TimeoutListPreference) preference, value);
} catch (NumberFormatException e) {
Log.e(TAG, “could not persist screen timeout setting”, e);
}
return true;
}
…
private void updateTimeoutPreferenceDescription(TimeoutListPreference preference,
long currentTimeout) {
final CharSequence[] entries = preference.getEntries();
final CharSequence[] values = preference.getEntryValues();
final String summary;
if (preference.isDisabledByAdmin()) {
summary = mContext.getString(com.android.settings.R.string.disabled_by_policy_title);
} else {
final CharSequence timeoutDescription = getTimeoutDescription(
currentTimeout, entries, values);
// add code start
//if( currentTimeoutjava.lang.Integer.MAX_VALUE){
// summary = entries[best].toString();
// }
if(currentTimeout2147483647){
summary=timeoutDescription.toString();
}else{ //add code
summary = timeoutDescription == null
? “”
: mContext.getString(R.string.screen_timeout_summary, timeoutDescription);
}//add code
}
preference.setSummary(summary);
}
本小白实习时搞过小段时间的java后端,对操作数据库的方式比较容易理解和认可
1:frameworks/base/packages/SettingsProvider/res/values/defaults.xml
true
2:frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java
private int getScreenOffTimeoutLocked(int sleepTimeout) {
int timeout = mScreenOffTimeoutSetting;
if(timeout == 0){
//rk3288 7.1比较特殊,这是是timeout为0代表不灭屏,一般android此值为-1,具体为多少需要查看Setting的DisplaySettings.java源码,比如我的是