diff options
author | Irfan Sheriff <isheriff@google.com> | 2011-06-15 16:29:02 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-06-15 16:29:02 -0700 |
commit | a464430762bad8039a598ce9af71f962d01f8eba (patch) | |
tree | 9e5fe139c835f8b7d9a8cc429501a9d1a4050878 | |
parent | 5137711109783dcbb20143d3e5cab2fa931218dd (diff) | |
parent | df1734e3f57646df1fa96275cbb65bb91ac9d2ac (diff) | |
download | frameworks_base-a464430762bad8039a598ce9af71f962d01f8eba.zip frameworks_base-a464430762bad8039a598ce9af71f962d01f8eba.tar.gz frameworks_base-a464430762bad8039a598ce9af71f962d01f8eba.tar.bz2 |
am df1734e3: Fix lease duration handling
* commit 'df1734e3f57646df1fa96275cbb65bb91ac9d2ac':
Fix lease duration handling
-rw-r--r-- | wifi/java/android/net/wifi/WifiStateTracker.java | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/wifi/java/android/net/wifi/WifiStateTracker.java b/wifi/java/android/net/wifi/WifiStateTracker.java index 90295e0..fedf3bb 100644 --- a/wifi/java/android/net/wifi/WifiStateTracker.java +++ b/wifi/java/android/net/wifi/WifiStateTracker.java @@ -166,6 +166,9 @@ public class WifiStateTracker extends NetworkStateTracker { */ private static final int DEFAULT_MAX_DHCP_RETRIES = 9; + //Minimum dhcp lease duration for renewal + private static final int MIN_RENEWAL_TIME_SECS = 5 * 60; //5 minutes + private static final int DRIVER_POWER_MODE_AUTO = 0; private static final int DRIVER_POWER_MODE_ACTIVE = 1; @@ -2507,14 +2510,8 @@ public class WifiStateTracker extends NetworkStateTracker { if (NetworkUtils.runDhcp(mInterfaceName, mDhcpInfo)) { event = EVENT_INTERFACE_CONFIGURATION_SUCCEEDED; Log.d(TAG, "DHCP succeeded with lease: " + mDhcpInfo.leaseDuration); - //Do it a bit earlier than half the lease duration time - //to beat the native DHCP client and avoid extra packets - //48% for one hour lease time = 29 minutes - mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, - SystemClock.elapsedRealtime() + - mDhcpInfo.leaseDuration * 480, //in milliseconds - mDhcpRenewalIntent); - } else { + setDhcpRenewalAlarm(mDhcpInfo.leaseDuration); + } else { event = EVENT_INTERFACE_CONFIGURATION_FAILED; Log.e(TAG, "DHCP request failed: " + NetworkUtils.getDhcpError()); } @@ -2551,10 +2548,7 @@ public class WifiStateTracker extends NetworkStateTracker { msg.sendToTarget(); } - mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, - SystemClock.elapsedRealtime() + - mDhcpInfo.leaseDuration * 480, - mDhcpRenewalIntent); + setDhcpRenewalAlarm(mDhcpInfo.leaseDuration); } else { event = EVENT_INTERFACE_CONFIGURATION_FAILED; Log.d(TAG, "DHCP renewal failed: " + NetworkUtils.getDhcpError()); @@ -2602,6 +2596,19 @@ public class WifiStateTracker extends NetworkStateTracker { return state == BluetoothHeadset.STATE_DISCONNECTED; } + private void setDhcpRenewalAlarm(long leaseDuration) { + //Do it a bit earlier than half the lease duration time + //to beat the native DHCP client and avoid extra packets + //48% for one hour lease time = 29 minutes + if (leaseDuration < MIN_RENEWAL_TIME_SECS) { + leaseDuration = MIN_RENEWAL_TIME_SECS; + } + mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, + SystemClock.elapsedRealtime() + + leaseDuration * 480, //in milliseconds + mDhcpRenewalIntent); + } + } private void checkUseStaticIp() { |