1. 程式人生 > >Android4.4螢幕不休眠&不鎖屏

Android4.4螢幕不休眠&不鎖屏



首先還是要修改defaults.xml檔案裡def_screen_off_timeout的值。

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

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

      修改def_screen_off_timeout為-1

2.修改frameworks/base/services/java/com/android/server/power/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); 
  }

不鎖屏:frameworks/base/packages/Keyguard/src/com/android/keyguard/KeyguardViewMediator.java檔案中
192行:private boolean mExternallyEnabled = true  改為false