Skip to content

Commit 511d534

Browse files
committed
Stop supplicant and dhcp before start
Bug: 7227463 Change-Id: Iaa0df7522edc38d25fae2bbda8d24490e997e733
1 parent bbe5caf commit 511d534

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

core/java/android/net/DhcpStateMachine.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ private boolean runDhcp(DhcpAction dhcpAction) {
351351
DhcpInfoInternal dhcpInfoInternal = new DhcpInfoInternal();
352352

353353
if (dhcpAction == DhcpAction.START) {
354+
/* Stop any existing DHCP daemon before starting new */
355+
NetworkUtils.stopDhcp(mInterfaceName);
354356
if (DBG) Log.d(TAG, "DHCP request on " + mInterfaceName);
355357
success = NetworkUtils.runDhcp(mInterfaceName, dhcpInfoInternal);
356358
mDhcpInfo = dhcpInfoInternal;

core/jni/android_net_wifi_Wifi.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ static jboolean android_net_wifi_startSupplicant(JNIEnv* env, jobject, jboolean
122122
return (jboolean)(::wifi_start_supplicant(p2pSupported) == 0);
123123
}
124124

125-
static jboolean android_net_wifi_killSupplicant(JNIEnv* env, jobject)
125+
static jboolean android_net_wifi_killSupplicant(JNIEnv* env, jobject, jboolean p2pSupported)
126126
{
127-
return (jboolean)(::wifi_stop_supplicant() == 0);
127+
return (jboolean)(::wifi_stop_supplicant(p2pSupported) == 0);
128128
}
129129

130130
static jboolean android_net_wifi_connectToSupplicant(JNIEnv* env, jobject, jstring jIface)
@@ -204,7 +204,7 @@ static JNINativeMethod gWifiMethods[] = {
204204
{ "isDriverLoaded", "()Z", (void *)android_net_wifi_isDriverLoaded },
205205
{ "unloadDriver", "()Z", (void *)android_net_wifi_unloadDriver },
206206
{ "startSupplicant", "(Z)Z", (void *)android_net_wifi_startSupplicant },
207-
{ "killSupplicant", "()Z", (void *)android_net_wifi_killSupplicant },
207+
{ "killSupplicant", "(Z)Z", (void *)android_net_wifi_killSupplicant },
208208
{ "connectToSupplicant", "(Ljava/lang/String;)Z",
209209
(void *)android_net_wifi_connectToSupplicant },
210210
{ "closeSupplicantConnection", "(Ljava/lang/String;)V",

wifi/java/android/net/wifi/WifiNative.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class WifiNative {
6161

6262
/* Sends a kill signal to supplicant. To be used when we have lost connection
6363
or when the supplicant is hung */
64-
public native static boolean killSupplicant();
64+
public native static boolean killSupplicant(boolean p2pSupported);
6565

6666
private native boolean connectToSupplicant(String iface);
6767

wifi/java/android/net/wifi/WifiStateMachine.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,6 +1944,7 @@ public boolean processMessage(Message message) {
19441944
case CMD_STOP_DRIVER:
19451945
case CMD_DELAYED_STOP_DRIVER:
19461946
case CMD_DRIVER_START_TIMED_OUT:
1947+
case CMD_CAPTIVE_CHECK_COMPLETE:
19471948
case CMD_START_AP:
19481949
case CMD_START_AP_SUCCESS:
19491950
case CMD_START_AP_FAILURE:
@@ -2189,6 +2190,13 @@ public boolean processMessage(Message message) {
21892190
loge("Unable to change interface settings: " + ie);
21902191
}
21912192

2193+
/* Stop a running supplicant after a runtime restart
2194+
* Avoids issues with drivers that do not handle interface down
2195+
* on a running supplicant properly.
2196+
*/
2197+
if (DBG) log("Kill any running supplicant");
2198+
mWifiNative.killSupplicant(mP2pSupported);
2199+
21922200
if(mWifiNative.startSupplicant(mP2pSupported)) {
21932201
if (DBG) log("Supplicant start successful");
21942202
mWifiMonitor.startMonitoring();
@@ -2384,7 +2392,7 @@ public boolean processMessage(Message message) {
23842392
case WifiMonitor.SUP_DISCONNECTION_EVENT:
23852393
if (++mSupplicantRestartCount <= SUPPLICANT_RESTART_TRIES) {
23862394
loge("Failed to setup control channel, restart supplicant");
2387-
mWifiNative.killSupplicant();
2395+
mWifiNative.killSupplicant(mP2pSupported);
23882396
transitionTo(mDriverLoadedState);
23892397
sendMessageDelayed(CMD_START_SUPPLICANT, SUPPLICANT_RESTART_INTERVAL_MSECS);
23902398
} else {
@@ -2451,7 +2459,7 @@ public boolean processMessage(Message message) {
24512459
break;
24522460
case WifiMonitor.SUP_DISCONNECTION_EVENT: /* Supplicant connection lost */
24532461
loge("Connection lost, restart supplicant");
2454-
mWifiNative.killSupplicant();
2462+
mWifiNative.killSupplicant(mP2pSupported);
24552463
mWifiNative.closeSupplicantConnection();
24562464
mNetworkInfo.setIsAvailable(false);
24572465
handleNetworkDisconnect();
@@ -2605,14 +2613,14 @@ public boolean processMessage(Message message) {
26052613
/* Socket connection can be lost when we do a graceful shutdown
26062614
* or when the driver is hung. Ensure supplicant is stopped here.
26072615
*/
2608-
mWifiNative.killSupplicant();
2616+
mWifiNative.killSupplicant(mP2pSupported);
26092617
mWifiNative.closeSupplicantConnection();
26102618
transitionTo(mDriverLoadedState);
26112619
break;
26122620
case CMD_STOP_SUPPLICANT_FAILED:
26132621
if (message.arg1 == mSupplicantStopFailureToken) {
26142622
loge("Timed out on a supplicant stop, kill and proceed");
2615-
mWifiNative.killSupplicant();
2623+
mWifiNative.killSupplicant(mP2pSupported);
26162624
mWifiNative.closeSupplicantConnection();
26172625
transitionTo(mDriverLoadedState);
26182626
}

0 commit comments

Comments
 (0)