android4.2以上版本比android4.2以前的版本framework层框架部分有了很大的改变,androd4.2以前版本framework层给上的接口函数与android4.2以上版本的接口函数也有了些变化,以前让机器永不休眠的方法用在android4.2以上版本已经不起作用了。现将android4.2以上版本修改永不休眠的方法记录下来。
首先还是要修改defaults.xml文件里def_screen_off_timeout的值。
1. 修改default值,不自动休眠
/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
修改def_screen_off_timeout为-1
2.修改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);
- }
- 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);