Fix lease duration handling
We need to convert lease duration from int to long before converting into milliseconds Also add basic sanity check Bug: 4561231 Change-Id: I9bcafaa798a04c8de3f2c1897dc5b3c4ae245672
This commit is contained in:
@@ -166,6 +166,9 @@ public class WifiStateTracker extends NetworkStateTracker {
|
|||||||
*/
|
*/
|
||||||
private static final int DEFAULT_MAX_DHCP_RETRIES = 9;
|
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_AUTO = 0;
|
||||||
private static final int DRIVER_POWER_MODE_ACTIVE = 1;
|
private static final int DRIVER_POWER_MODE_ACTIVE = 1;
|
||||||
|
|
||||||
@@ -2506,13 +2509,7 @@ public class WifiStateTracker extends NetworkStateTracker {
|
|||||||
if (NetworkUtils.runDhcp(mInterfaceName, mDhcpInfo)) {
|
if (NetworkUtils.runDhcp(mInterfaceName, mDhcpInfo)) {
|
||||||
event = EVENT_INTERFACE_CONFIGURATION_SUCCEEDED;
|
event = EVENT_INTERFACE_CONFIGURATION_SUCCEEDED;
|
||||||
Log.d(TAG, "DHCP succeeded with lease: " + mDhcpInfo.leaseDuration);
|
Log.d(TAG, "DHCP succeeded with lease: " + mDhcpInfo.leaseDuration);
|
||||||
//Do it a bit earlier than half the lease duration time
|
setDhcpRenewalAlarm(mDhcpInfo.leaseDuration);
|
||||||
//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 {
|
} else {
|
||||||
event = EVENT_INTERFACE_CONFIGURATION_FAILED;
|
event = EVENT_INTERFACE_CONFIGURATION_FAILED;
|
||||||
Log.e(TAG, "DHCP request failed: " + NetworkUtils.getDhcpError());
|
Log.e(TAG, "DHCP request failed: " + NetworkUtils.getDhcpError());
|
||||||
@@ -2550,10 +2547,7 @@ public class WifiStateTracker extends NetworkStateTracker {
|
|||||||
msg.sendToTarget();
|
msg.sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
setDhcpRenewalAlarm(mDhcpInfo.leaseDuration);
|
||||||
SystemClock.elapsedRealtime() +
|
|
||||||
mDhcpInfo.leaseDuration * 480,
|
|
||||||
mDhcpRenewalIntent);
|
|
||||||
} else {
|
} else {
|
||||||
event = EVENT_INTERFACE_CONFIGURATION_FAILED;
|
event = EVENT_INTERFACE_CONFIGURATION_FAILED;
|
||||||
Log.d(TAG, "DHCP renewal failed: " + NetworkUtils.getDhcpError());
|
Log.d(TAG, "DHCP renewal failed: " + NetworkUtils.getDhcpError());
|
||||||
@@ -2601,6 +2595,19 @@ public class WifiStateTracker extends NetworkStateTracker {
|
|||||||
return state == BluetoothHeadset.STATE_DISCONNECTED;
|
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() {
|
private void checkUseStaticIp() {
|
||||||
|
|||||||
Reference in New Issue
Block a user