禁止Android系统进入深休眠的方法

在PowerManagerService中,mWakeLockSuspendBlocker是控制CPU休眠的锁;
,mDisplaySuspendBlocker是控制显示开关的锁。

通过查看文件,亮屏时看到的也是这两个锁:

# cat /sys/power/wake_lock                                          
PowerManagerService.Display PowerManagerService.WakeLocks

当按下电源键,会调用goToSleep—>goToSleepInternal —>goToSleepNoUpdateLocked—>updatePowerStateLocked;

当Activity用户无操作活动超时,会调用handleUserActivityTimeout—>updatePowerStateLocked—>;

最终走的都是updatePowerStateLocked

如果想实现按power键不关闭屏幕,则不让mDisplaySuspendBlocker进行release操作即可。

frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java
         @Override // Binder call  
         public void goToSleep(long eventTime, int reason, int flags) {  
+            if(true){  
+                return;  
+            }  
             if (eventTime > SystemClock.uptimeMillis()) {  
                 throw new IllegalArgumentException("event time must not be in the future");  
             }  

如果想实现关闭屏幕后系统不进入休眠,,则让mDisplaySuspendBlocker进行release操作,mWakeLockSuspendBlocker不进行release操作。

frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java
    /**
     * Updates the suspend blocker that keeps the CPU alive.
     *
     * This function must have no other side-effects.
     */
    private void updateSuspendBlockerLocked() {
 
+        if (SystemProperties.getBoolean("sys.pms.holding_wake_lock", false)){
+            Slog.d(TAG, "Holding wake lock suspend blocker");
+            return;
+        }
+
         // Then release suspend blockers if needed.
         if (!needWakeLockSuspendBlocker && mHoldingWakeLockSuspendBlocker) {
             mWakeLockSuspendBlocker.release();
 

你可能感兴趣的:(android,Rockchip)