android 5.1禁止休眠

1.  修改default值,不自动休眠

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

      修改def_screen_off_timeout为-1

2.frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java

修改PowerManagerService.java文件getScreenOffTimeoutLocked()函数

[html]  view plain copy
  1. private int getScreenOffTimeoutLocked() {  
  2.         int timeout = mScreenOffTimeoutSetting;  
  3.         if (isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()) {  
  4.             timeout = Math.min(timeout, mMaximumScreenOffTimeoutFromDeviceAdmin);  
  5.         }  
  6.         if (mUserActivityTimeoutOverrideFromWindowManager >= 0) {  
  7.             timeout = (int)Math.min(timeout, mUserActivityTimeoutOverrideFromWindowManager);  
  8.         }  
  9.          
  10.         return Math.max(timeout, MINIMUM_SCREEN_OFF_TIMEOUT);  
  11.     }  
修改后:

[html]  view plain copy
  1. int nosleep;  
  2. int timeout = mScreenOffTimeoutSetting;  
  3. if (isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()) {  
  4.     timeout = Math.min(timeout, mMaximumScreenOffTimeoutFromDeviceAdmin);  
  5. }  
  6. if (mUserActivityTimeoutOverrideFromWindowManager >= 0) {  
  7.     timeout = (int)Math.min(timeout, mUserActivityTimeoutOverrideFromWindowManager);  
  8. }  
  9. nosleep = mScreenOffTimeoutSetting;  
  10. if(nosleep  < 0)  
  11. {  
  12.     nosleep = mMaximumScreenOffTimeoutFromDeviceAdmin ;  
  13.     return Math.max(nosleep, mMaximumScreenOffTimeoutFromDeviceAdmin);  
  14. }  
  15. return Math.max(timeout, MINIMUM_SCREEN_OFF_TIMEOUT);

你可能感兴趣的:(Android,framework之积累)