summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Irfan Sheriff <isheriff@google.com> 2011-06-21 12:23:17 -0700
committer Irfan Sheriff <isheriff@google.com> 2011-06-21 15:42:48 -0700
commitcd672ebf2963e4c448115bac4c80a6659a5904be (patch)
tree71056210747144a86fb3d2cf914d0db8e5fcef32
parent41b35884ff68a62f5fc8f65dcc26342d0889113d (diff)
Release wakelock after use
DHCP renewal can finish pretty quick most times and holding a timed wakelock wastes battery. Hold a non-reference counted lock and release it immediate while having the safety of a 40s release Bug: 4575773 Change-Id: I49d2e8c27b2723690aef26417c4b9a145843a401
-rw-r--r--core/java/android/net/DhcpStateMachine.java10
1 files changed, 9 insertions, 1 deletions
diff --git a/core/java/android/net/DhcpStateMachine.java b/core/java/android/net/DhcpStateMachine.java
index e2230c98aed2..ca9583294cdd 100644
--- a/core/java/android/net/DhcpStateMachine.java
+++ b/core/java/android/net/DhcpStateMachine.java
@@ -117,13 +117,14 @@ public class DhcpStateMachine extends HierarchicalStateMachine {
PowerManager powerManager = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
mDhcpRenewWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_TAG);
+ mDhcpRenewWakeLock.setReferenceCounted(false);
mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//DHCP renew
if (DBG) Log.d(TAG, "Sending a DHCP renewal " + this);
- //acquire a 40s wakelock to finish DHCP renewal
+ //Lock released after 40s in worst case scenario
mDhcpRenewWakeLock.acquire(40000);
sendMessage(CMD_RENEW_DHCP);
}
@@ -166,6 +167,7 @@ public class DhcpStateMachine extends HierarchicalStateMachine {
switch (message.what) {
case CMD_RENEW_DHCP:
Log.e(TAG, "Error! Failed to handle a DHCP renewal on " + mInterfaceName);
+ mDhcpRenewWakeLock.release();
break;
case HSM_QUIT_CMD:
mContext.unregisterReceiver(mBroadcastReceiver);
@@ -268,10 +270,12 @@ public class DhcpStateMachine extends HierarchicalStateMachine {
/* Notify controller before starting DHCP */
mController.sendMessage(CMD_PRE_DHCP_ACTION);
transitionTo(mWaitBeforeRenewalState);
+ //mDhcpRenewWakeLock is released in WaitBeforeRenewalState
} else {
if (!runDhcp(DhcpAction.RENEW)) {
transitionTo(mStoppedState);
}
+ mDhcpRenewWakeLock.release();
}
break;
case CMD_START_DHCP:
@@ -318,6 +322,10 @@ public class DhcpStateMachine extends HierarchicalStateMachine {
}
return retValue;
}
+ @Override
+ public void exit() {
+ mDhcpRenewWakeLock.release();
+ }
}
private boolean runDhcp(DhcpAction dhcpAction) {