Loading wifi/java/android/net/wifi/WifiStateTracker.java +31 −23 Original line number Diff line number Diff line Loading @@ -2524,23 +2524,10 @@ public class WifiStateTracker extends NetworkStateTracker { } if (msg.what == EVENT_DHCP_START) { Log.d(TAG, "DHCP request started"); if (NetworkUtils.runDhcp(mInterfaceName, mDhcpInfo)) { if (runDhcp(false)) { 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 //Don't do it if we're on an infinite lease if (mDhcpInfo.leaseDuration >= 0) { mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + mDhcpInfo.leaseDuration * 480, //in milliseconds mDhcpRenewalIntent); } } else { event = EVENT_INTERFACE_CONFIGURATION_FAILED; Log.e(TAG, "DHCP request failed: " + NetworkUtils.getDhcpError()); } synchronized (this) { if (!mCancelCallback) { Loading @@ -2549,16 +2536,13 @@ public class WifiStateTracker extends NetworkStateTracker { } } else if (msg.what == EVENT_DHCP_RENEW) { Log.d(TAG, "DHCP renewal started"); int oIp = mDhcpInfo.ipAddress; int oGw = mDhcpInfo.gateway; int oMsk = mDhcpInfo.netmask; int oDns1 = mDhcpInfo.dns1; int oDns2 = mDhcpInfo.dns2; if (NetworkUtils.runDhcpRenew(mInterfaceName, mDhcpInfo)) { Log.d(TAG, "DHCP renewal with lease: " + mDhcpInfo.leaseDuration); if (runDhcp(true)) { boolean changed = (oIp != mDhcpInfo.ipAddress || oGw != mDhcpInfo.gateway || Loading @@ -2574,11 +2558,6 @@ public class WifiStateTracker extends NetworkStateTracker { mNetworkInfo); msg.sendToTarget(); } mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + mDhcpInfo.leaseDuration * 480, mDhcpRenewalIntent); } else { event = EVENT_INTERFACE_CONFIGURATION_FAILED; Log.d(TAG, "DHCP renewal failed: " + NetworkUtils.getDhcpError()); Loading @@ -2605,6 +2584,35 @@ public class WifiStateTracker extends NetworkStateTracker { } } private boolean runDhcp(boolean renew) { final String action = renew ? "DHCP request" : "DHCP renewal"; Log.d(TAG, action + " started"); boolean result = renew ? NetworkUtils.runDhcpRenew(mInterfaceName, mDhcpInfo) : NetworkUtils.runDhcp(mInterfaceName, mDhcpInfo); if (!result) { Log.e(TAG, action + " failed: " + NetworkUtils.getDhcpError()); return false; } Log.d(TAG, action + " succeeded with lease: " + mDhcpInfo.leaseDuration); //Don't schedule renewal if we're on an infinite lease if (mDhcpInfo.leaseDuration >= 0) { //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 long nextRenewal = (long) mDhcpInfo.leaseDuration * 480; // in milliseconds; nextRenewal += SystemClock.elapsedRealtime(); mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextRenewal, mDhcpRenewalIntent); } return true; } public synchronized void setCancelCallback(boolean cancelCallback) { mCancelCallback = cancelCallback; if (cancelCallback) { Loading Loading
wifi/java/android/net/wifi/WifiStateTracker.java +31 −23 Original line number Diff line number Diff line Loading @@ -2524,23 +2524,10 @@ public class WifiStateTracker extends NetworkStateTracker { } if (msg.what == EVENT_DHCP_START) { Log.d(TAG, "DHCP request started"); if (NetworkUtils.runDhcp(mInterfaceName, mDhcpInfo)) { if (runDhcp(false)) { 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 //Don't do it if we're on an infinite lease if (mDhcpInfo.leaseDuration >= 0) { mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + mDhcpInfo.leaseDuration * 480, //in milliseconds mDhcpRenewalIntent); } } else { event = EVENT_INTERFACE_CONFIGURATION_FAILED; Log.e(TAG, "DHCP request failed: " + NetworkUtils.getDhcpError()); } synchronized (this) { if (!mCancelCallback) { Loading @@ -2549,16 +2536,13 @@ public class WifiStateTracker extends NetworkStateTracker { } } else if (msg.what == EVENT_DHCP_RENEW) { Log.d(TAG, "DHCP renewal started"); int oIp = mDhcpInfo.ipAddress; int oGw = mDhcpInfo.gateway; int oMsk = mDhcpInfo.netmask; int oDns1 = mDhcpInfo.dns1; int oDns2 = mDhcpInfo.dns2; if (NetworkUtils.runDhcpRenew(mInterfaceName, mDhcpInfo)) { Log.d(TAG, "DHCP renewal with lease: " + mDhcpInfo.leaseDuration); if (runDhcp(true)) { boolean changed = (oIp != mDhcpInfo.ipAddress || oGw != mDhcpInfo.gateway || Loading @@ -2574,11 +2558,6 @@ public class WifiStateTracker extends NetworkStateTracker { mNetworkInfo); msg.sendToTarget(); } mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + mDhcpInfo.leaseDuration * 480, mDhcpRenewalIntent); } else { event = EVENT_INTERFACE_CONFIGURATION_FAILED; Log.d(TAG, "DHCP renewal failed: " + NetworkUtils.getDhcpError()); Loading @@ -2605,6 +2584,35 @@ public class WifiStateTracker extends NetworkStateTracker { } } private boolean runDhcp(boolean renew) { final String action = renew ? "DHCP request" : "DHCP renewal"; Log.d(TAG, action + " started"); boolean result = renew ? NetworkUtils.runDhcpRenew(mInterfaceName, mDhcpInfo) : NetworkUtils.runDhcp(mInterfaceName, mDhcpInfo); if (!result) { Log.e(TAG, action + " failed: " + NetworkUtils.getDhcpError()); return false; } Log.d(TAG, action + " succeeded with lease: " + mDhcpInfo.leaseDuration); //Don't schedule renewal if we're on an infinite lease if (mDhcpInfo.leaseDuration >= 0) { //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 long nextRenewal = (long) mDhcpInfo.leaseDuration * 480; // in milliseconds; nextRenewal += SystemClock.elapsedRealtime(); mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextRenewal, mDhcpRenewalIntent); } return true; } public synchronized void setCancelCallback(boolean cancelCallback) { mCancelCallback = cancelCallback; if (cancelCallback) { Loading