From 07a83d343adb6a5a2d4fce734b1dbec717126b6d Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Fri, 3 Jun 2016 10:37:52 -0700 Subject: Hold the wakelock for suspend optimaztion only when it matters. b/23106128 Change-Id: I367ffd43f84bb46276d30c12ffcd54d641a9bc4a --- .../com/android/server/wifi/WifiStateMachine.java | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index 2181311bc..6a28c0c83 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -2879,12 +2879,16 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss } enableRssiPolling(screenOn); if (mUserWantsSuspendOpt.get()) { + int shouldReleaseWakeLock = 0; if (screenOn) { - sendMessage(CMD_SET_SUSPEND_OPT_ENABLED, 0, 0); + sendMessage(CMD_SET_SUSPEND_OPT_ENABLED, 0, shouldReleaseWakeLock); } else { - // Allow 2s for suspend optimizations to be set - mSuspendWakeLock.acquire(2000); - sendMessage(CMD_SET_SUSPEND_OPT_ENABLED, 1, 0); + if (isConnected()) { + // Allow 2s for suspend optimizations to be set + mSuspendWakeLock.acquire(2000); + shouldReleaseWakeLock = 1; + } + sendMessage(CMD_SET_SUSPEND_OPT_ENABLED, 1, shouldReleaseWakeLock); } } mScreenBroadcastReceived.set(true); @@ -4070,7 +4074,9 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss break; case CMD_SET_SUSPEND_OPT_ENABLED: if (message.arg1 == 1) { - mSuspendWakeLock.release(); + if (message.arg2 == 1) { + mSuspendWakeLock.release(); + } setSuspendOptimizations(SUSPEND_DUE_TO_SCREEN, true); } else { setSuspendOptimizations(SUSPEND_DUE_TO_SCREEN, false); @@ -4789,7 +4795,9 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss case CMD_SET_SUSPEND_OPT_ENABLED: if (message.arg1 == 1) { setSuspendOptimizationsNative(SUSPEND_DUE_TO_SCREEN, true); - mSuspendWakeLock.release(); + if (message.arg2 == 1) { + mSuspendWakeLock.release(); + } } else { setSuspendOptimizationsNative(SUSPEND_DUE_TO_SCREEN, false); } -- cgit v1.2.3