summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libwifi_system/wifi.cpp6
-rw-r--r--service/java/com/android/server/wifi/WifiMonitor.java8
-rw-r--r--service/java/com/android/server/wifi/WifiNative.java16
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java47
-rw-r--r--service/jni/com_android_server_wifi_WifiNative.cpp12
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java17
6 files changed, 39 insertions, 67 deletions
diff --git a/libwifi_system/wifi.cpp b/libwifi_system/wifi.cpp
index 4406affc0..da00ba5b1 100644
--- a/libwifi_system/wifi.cpp
+++ b/libwifi_system/wifi.cpp
@@ -214,9 +214,6 @@ int wifi_start_supplicant() {
/* Clear out any stale socket files that might be left over. */
wpa_ctrl_cleanup();
- /* Reset sockets used for exiting from hung state */
- exit_sockets[0] = exit_sockets[1] = -1;
-
/*
* Get a reference to the status property, so we can distinguish
* the case where it goes stopped => running => stopped (i.e.,
@@ -228,7 +225,6 @@ int wifi_start_supplicant() {
if (pi != NULL) {
serial = __system_property_serial(pi);
}
- property_get("wifi.interface", primary_iface, WIFI_TEST_INTERFACE);
property_set("ctl.start", SUPPLICANT_SERVICE_NAME);
sched_yield();
@@ -466,6 +462,8 @@ int wifi_wait_on_socket(char* buf, size_t buflen) {
int wifi_connect_to_supplicant() {
static char path[PATH_MAX];
+ property_get("wifi.interface", primary_iface, WIFI_TEST_INTERFACE);
+
if (access(IFACE_DIR, F_OK) == 0) {
snprintf(path, sizeof(path), "%s/%s", IFACE_DIR, primary_iface);
} else {
diff --git a/service/java/com/android/server/wifi/WifiMonitor.java b/service/java/com/android/server/wifi/WifiMonitor.java
index 4b2150fb2..34dcfd79f 100644
--- a/service/java/com/android/server/wifi/WifiMonitor.java
+++ b/service/java/com/android/server/wifi/WifiMonitor.java
@@ -575,6 +575,7 @@ public class WifiMonitor {
private void setMonitoring(String iface, boolean enabled) {
mMonitoringMap.put(iface, enabled);
}
+
private void setMonitoringNone() {
for (String iface : mMonitoringMap.keySet()) {
setMonitoring(iface, false);
@@ -633,12 +634,7 @@ public class WifiMonitor {
mWifiNative.stopSupplicant();
}
- public synchronized void killSupplicant() {
- String suppState = System.getProperty("init.svc.wpa_supplicant");
- if (suppState == null) suppState = "unknown";
-
- Log.e(TAG, "killSupplicant init.svc.wpa_supplicant=" + suppState);
- mWifiNative.killSupplicant();
+ public synchronized void stopAllMonitoring() {
mConnected = false;
setMonitoringNone();
}
diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java
index 91a11e821..e20ef4398 100644
--- a/service/java/com/android/server/wifi/WifiNative.java
+++ b/service/java/com/android/server/wifi/WifiNative.java
@@ -176,22 +176,6 @@ public class WifiNative {
/*
* Supplicant management
*/
- private native static boolean startSupplicantNative();
- public boolean startSupplicant() {
- synchronized (sLock) {
- return startSupplicantNative();
- }
- }
-
- /* Sends a kill signal to supplicant. To be used when we have lost connection
- or when the supplicant is hung */
- private native static boolean killSupplicantNative();
- public boolean killSupplicant() {
- synchronized (sLock) {
- return killSupplicantNative();
- }
- }
-
private native static boolean connectToSupplicantNative();
public boolean connectToSupplicant() {
synchronized (sLock) {
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index 725dbd815..53382eb26 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -195,6 +195,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
private WifiQualifiedNetworkSelector mWifiQualifiedNetworkSelector;
private INetworkManagementService mNwService;
private IWificond mWificond;
+ private IClientInterface mClientInterface;
private ConnectivityManager mCm;
private BaseWifiDiagnostics mWifiDiagnostics;
private WifiApConfigStore mWifiApConfigStore;
@@ -3379,7 +3380,14 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
* or when the driver is hung. Ensure supplicant is stopped here.
*/
if (killSupplicant) {
- mWifiMonitor.killSupplicant();
+ mWifiMonitor.stopAllMonitoring();
+ try {
+ if (!mClientInterface.disableSupplicant()) {
+ loge("Failed to disable supplicant after connection loss");
+ }
+ } catch (RemoteException e) {
+ // Remote interface has died, there is no cleanup we can do.
+ }
}
mWifiNative.closeSupplicantConnection();
sendSupplicantConnectionChangedBroadcast(false);
@@ -3565,15 +3573,15 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
mWifiNative.disconnect();
}
- private IClientInterface setupDriverForClientMode() {
- if (mWificond == null) {
+ private static IClientInterface setupDriverForClientMode(IWificond wificond) {
+ if (wificond == null) {
Log.e(TAG, "Failed to get reference to wificond");
return null;
}
IClientInterface clientInterface = null;
try {
- clientInterface = mWificond.createClientInterface();
+ clientInterface = wificond.createClientInterface();
} catch (RemoteException e1) { }
if (clientInterface == null) {
@@ -4018,11 +4026,8 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
class InitialState extends State {
private void cleanup() {
- /* Stop a running supplicant after a runtime restart
- * Avoids issues with drivers that do not handle interface down
- * on a running supplicant properly.
- */
- mWifiMonitor.killSupplicant();
+ // Tearing down the client interfaces below is going to stop our supplicant.
+ mWifiMonitor.stopAllMonitoring();
mDeathRecipient.unlinkToDeath();
if (mWificond != null) {
@@ -4058,9 +4063,9 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
case CMD_START_SUPPLICANT:
// Refresh our reference to wificond. This allows us to tolerate restarts.
mWificond = mWifiInjector.makeWificond();
- IClientInterface clientInterface = setupDriverForClientMode();
- if (clientInterface == null ||
- !mDeathRecipient.linkToDeath(clientInterface.asBinder())) {
+ mClientInterface = setupDriverForClientMode(mWificond);
+ if (mClientInterface == null ||
+ !mDeathRecipient.linkToDeath(mClientInterface.asBinder())) {
setWifiState(WifiManager.WIFI_STATE_UNKNOWN);
cleanup();
break;
@@ -4094,9 +4099,14 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
Log.e(TAG, "Failed to start HAL for client mode");
}
- if (!mWifiNative.startSupplicant()) {
- loge("Failed to start supplicant!");
- setWifiState(WifiManager.WIFI_STATE_UNKNOWN);
+ try {
+ if (!mClientInterface.enableSupplicant()) {
+ loge("Failed to start supplicant!");
+ setWifiState(WifiManager.WIFI_STATE_UNKNOWN);
+ cleanup();
+ break;
+ }
+ } catch (RemoteException e) {
cleanup();
break;
}
@@ -4185,7 +4195,12 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
case WifiMonitor.SUP_DISCONNECTION_EVENT:
if (++mSupplicantRestartCount <= SUPPLICANT_RESTART_TRIES) {
loge("Failed to setup control channel, restart supplicant");
- mWifiMonitor.killSupplicant();
+ mWifiMonitor.stopAllMonitoring();
+ try {
+ mClientInterface.disableSupplicant();
+ } catch (RemoteException e) {
+ // The client interface is dead, there is nothing more we can do.
+ }
transitionTo(mInitialState);
sendMessageDelayed(CMD_START_SUPPLICANT, SUPPLICANT_RESTART_INTERVAL_MSECS);
} else {
diff --git a/service/jni/com_android_server_wifi_WifiNative.cpp b/service/jni/com_android_server_wifi_WifiNative.cpp
index a7534e55a..d8db06129 100644
--- a/service/jni/com_android_server_wifi_WifiNative.cpp
+++ b/service/jni/com_android_server_wifi_WifiNative.cpp
@@ -115,16 +115,6 @@ static jstring doStringCommand(JNIEnv* env, jstring javaCommand) {
return env->NewStringUTF(reply);
}
-static jboolean android_net_wifi_startSupplicant(JNIEnv* env, jclass)
-{
- return (wifi_system::wifi_start_supplicant() == 0);
-}
-
-static jboolean android_net_wifi_killSupplicant(JNIEnv* env, jclass)
-{
- return (wifi_system::wifi_stop_supplicant() == 0);
-}
-
static jboolean android_net_wifi_connectToSupplicant(JNIEnv* env, jclass)
{
return (wifi_system::wifi_connect_to_supplicant() == 0);
@@ -2456,8 +2446,6 @@ static jint android_net_wifi_configure_nd_offload(JNIEnv *env, jclass cls,
static JNINativeMethod gWifiMethods[] = {
/* name, signature, funcPtr */
- { "startSupplicantNative", "()Z", (void *)android_net_wifi_startSupplicant },
- { "killSupplicantNative", "()Z", (void *)android_net_wifi_killSupplicant },
{ "connectToSupplicantNative", "()Z", (void *)android_net_wifi_connectToSupplicant },
{ "closeSupplicantConnectionNative", "()V",
(void *)android_net_wifi_closeSupplicantConnection },
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index 0e2581d24..ac879f9b3 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -383,6 +383,8 @@ public class WifiStateMachineTest {
when(mWificond.createClientInterface()).thenReturn(mClientInterface);
when(mClientInterface.asBinder()).thenReturn(mClientInterfaceBinder);
+ when(mClientInterface.enableSupplicant()).thenReturn(true);
+ when(mClientInterface.disableSupplicant()).thenReturn(true);
mWsm = new WifiStateMachine(context, factory, mLooper.getLooper(),
mUserManager, mWifiInjector, mBackupManagerProxy, mCountryCode);
@@ -441,7 +443,6 @@ public class WifiStateMachineTest {
@Test
public void loadComponents() throws Exception {
when(mWifiNative.startHal()).thenReturn(true);
- when(mWifiNative.startSupplicant()).thenReturn(true);
mWsm.setSupplicantRunning(true);
mLooper.dispatchAll();
@@ -465,16 +466,8 @@ public class WifiStateMachineTest {
}
@Test
- public void shouldRequireHalToLeaveInitialState() throws Exception {
- when(mWifiNative.startHal()).thenReturn(false);
- mWsm.setSupplicantRunning(true);
- mLooper.dispatchAll();
- assertEquals("InitialState", getCurrentState().getName());
- }
-
- @Test
public void shouldRequireSupplicantStartupToLeaveInitialState() throws Exception {
- when(mWifiNative.startSupplicant()).thenReturn(false);
+ when(mClientInterface.enableSupplicant()).thenReturn(false);
mWsm.setSupplicantRunning(true);
mLooper.dispatchAll();
assertEquals("InitialState", getCurrentState().getName());
@@ -507,7 +500,7 @@ public class WifiStateMachineTest {
@Test
public void loadComponentsFailure() throws Exception {
when(mWifiNative.startHal()).thenReturn(false);
- when(mWifiNative.startSupplicant()).thenReturn(false);
+ when(mClientInterface.enableSupplicant()).thenReturn(false);
mWsm.setSupplicantRunning(true);
mLooper.dispatchAll();
@@ -534,7 +527,6 @@ public class WifiStateMachineTest {
@Test
public void shouldStartSupplicantWhenConnectModeRequested() throws Exception {
when(mWifiNative.startHal()).thenReturn(true);
- when(mWifiNative.startSupplicant()).thenReturn(true);
// The first time we start out in InitialState, we sit around here.
mLooper.dispatchAll();
@@ -554,7 +546,6 @@ public class WifiStateMachineTest {
@Test
public void checkStartInCorrectStateAfterChangingInitialState() throws Exception {
when(mWifiNative.startHal()).thenReturn(true);
- when(mWifiNative.startSupplicant()).thenReturn(true);
// Check initial state
mLooper.dispatchAll();