AndroidQ increases the screen never timeout
Due to the lack of understanding of the source code in this book, it is impossible to accurately prescribe the right medicine, so I found three solutions and tried them one by one.
The first plan
1: First modify res/values/arrays.xml.
The file saved in this file is array resources, whichever scheme needs to be changed.
30 minutes
//Add the change option, which is the array option
Never seen on the page
1800000
//Add option 2147483647 to int maximum value
2147483647
2: Modify src/com/android/settings/display/TimeoutListPreference.java and
finally modify src/com/android/settings/display/TimeoutPreferenceController.java
The second method
1: packages/apps/Settings/res/values/arrays.xml
30 minutes
//The following is the new
Never
1800000 -1 //If compiling with -1 will report an error, look at another solution 2: Then modify the set sleep time in the Settings.java file
//putInt finally calls putIntForUser
public static boolean putInt(ContentResolver cr, String name, int value) { return putIntForUser(cr, name, value, cr.getUserId()); }
//PutIntForUser is modified and set according to the incoming name and value special 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 description is the never-sleep value we added in the settings 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); }
Another option for Android8
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);
}
Never turn off the screen according to the database setting
Ben Xiaobai has worked on the java backend for a short period of time during his internship. It is easier to understand and recognize the way of operating the database
1: frameworks/base/packages/SettingsProvider/res/values/defaults.xml
true
- 1800000
- 0
-1
false
false
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源码,比如我的是