summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2018-02-06 17:22:59 -0800
committerRoshan Pius <rpius@google.com>2018-07-20 09:44:56 -0700
commit08783ed499bd657dcf9f3d952a0f51515a86527d (patch)
treef38a1e0e425a668c3a5d309977db522df831811f /service
parent31b106d6610b9a61787a71dc51dba24b5f33e278 (diff)
WifiNative: Use the new lazy HAL startup mechanism
Currently, supplicant & hostapd are started/stopped using wificond. There is a new in-band HIDL mechanism to startup HIDL daemons. So, switch to that. Also, with this change we can move the hostapd start/stop to be similar to wpa_supplicant. This was previously not possible because wificond's hostapd startup method was not in the top-level IWificond object. Will use b/71513606 to get rid of the now unused supplicant/hostapd start/stop methods from wificond. Bug: 72394251 Test: Unit tests Test: Manually toggled wifi/softap multiple times. Test: Will send for regression tests. Change-Id: Ibc495b8e74b50150edfbea31acbb0c34d128803c
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/HostapdHal.java29
-rw-r--r--service/java/com/android/server/wifi/SupplicantStaIfaceHal.java20
-rw-r--r--service/java/com/android/server/wifi/WifiNative.java78
3 files changed, 95 insertions, 32 deletions
diff --git a/service/java/com/android/server/wifi/HostapdHal.java b/service/java/com/android/server/wifi/HostapdHal.java
index a090800a5..9395e2daf 100644
--- a/service/java/com/android/server/wifi/HostapdHal.java
+++ b/service/java/com/android/server/wifi/HostapdHal.java
@@ -33,6 +33,8 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.server.wifi.WifiNative.HostapdDeathEventHandler;
import com.android.server.wifi.util.NativeUtil;
+import java.util.NoSuchElementException;
+
import javax.annotation.concurrent.ThreadSafe;
/**
@@ -356,6 +358,26 @@ public class HostapdHal {
}
/**
+ * Start the hostapd daemon.
+ *
+ * @return true on success, false otherwise.
+ */
+ public boolean startDaemon() {
+ synchronized (mLock) {
+ try {
+ // This should startup hostapd daemon using the lazy start HAL mechanism.
+ getHostapdMockable();
+ } catch (RemoteException e) {
+ Log.e(TAG, "Exception while trying to start hostapd: "
+ + e);
+ hostapdServiceDiedHandler();
+ return false;
+ }
+ return true;
+ }
+ }
+
+ /**
* Terminate the hostapd daemon.
*/
public void terminate() {
@@ -383,7 +405,12 @@ public class HostapdHal {
@VisibleForTesting
protected IHostapd getHostapdMockable() throws RemoteException {
synchronized (mLock) {
- return IHostapd.getService();
+ try {
+ return IHostapd.getService();
+ } catch (NoSuchElementException e) {
+ Log.e(TAG, "Failed to get IHostapd", e);
+ return null;
+ }
}
}
diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
index 2c9b5e5ec..535101f93 100644
--- a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
+++ b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
@@ -510,6 +510,26 @@ public class SupplicantStaIfaceHal {
}
/**
+ * Start the supplicant daemon.
+ *
+ * @return true on success, false otherwise.
+ */
+ public boolean startDaemon() {
+ synchronized (mLock) {
+ try {
+ // This should startup supplicant daemon using the lazy start HAL mechanism.
+ getSupplicantMockable();
+ } catch (RemoteException e) {
+ Log.e(TAG, "Exception while trying to start supplicant: "
+ + e);
+ supplicantServiceDiedHandler();
+ return false;
+ }
+ return true;
+ }
+ }
+
+ /**
* Terminate the supplicant daemon.
*/
public void terminate() {
diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java
index aa4dc6a85..9145baa81 100644
--- a/service/java/com/android/server/wifi/WifiNative.java
+++ b/service/java/com/android/server/wifi/WifiNative.java
@@ -335,12 +335,16 @@ public class WifiNative {
*
* @return true if connection is established, false otherwise.
*/
- private boolean waitForSupplicantConnection() {
+ private boolean startAndWaitForSupplicantConnection() {
// Start initialization if not already started.
if (!mSupplicantStaIfaceHal.isInitializationStarted()
&& !mSupplicantStaIfaceHal.initialize()) {
return false;
}
+ if (!mSupplicantStaIfaceHal.startDaemon()) {
+ Log.e(TAG, "Failed to startup supplicant");
+ return false;
+ }
boolean connected = false;
int connectTries = 0;
while (!connected && connectTries++ < CONNECT_TO_SUPPLICANT_RETRY_TIMES) {
@@ -361,11 +365,7 @@ public class WifiNative {
private boolean startSupplicant() {
synchronized (mLock) {
if (!mIfaceMgr.hasAnyStaIfaceForConnectivity()) {
- if (!mWificondControl.enableSupplicant()) {
- Log.e(TAG, "Failed to enable supplicant");
- return false;
- }
- if (!waitForSupplicantConnection()) {
+ if (!startAndWaitForSupplicantConnection()) {
Log.e(TAG, "Failed to connect to supplicant");
return false;
}
@@ -386,9 +386,37 @@ public class WifiNative {
if (!mSupplicantStaIfaceHal.deregisterDeathHandler()) {
Log.e(TAG, "Failed to deregister supplicant death handler");
}
- if (!mWificondControl.disableSupplicant()) {
- Log.e(TAG, "Failed to disable supplicant");
+ mSupplicantStaIfaceHal.terminate();
+ }
+ }
+ }
+
+ /** Helper method invoked to start hostapd if there were no AP ifaces */
+ private boolean startHostapd() {
+ synchronized (mLock) {
+ if (!mIfaceMgr.hasAnyApIface()) {
+ if (!startAndWaitForHostapdConnection()) {
+ Log.e(TAG, "Failed to connect to hostapd");
+ return false;
+ }
+ if (!mHostapdHal.registerDeathHandler(
+ new HostapdDeathHandlerInternal())) {
+ Log.e(TAG, "Failed to register hostapd death handler");
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+
+ /** Helper method invoked to stop hostapd if there are no more AP ifaces */
+ private void stopHostapdIfNecessary() {
+ synchronized (mLock) {
+ if (!mIfaceMgr.hasAnyApIface()) {
+ if (!mHostapdHal.deregisterDeathHandler()) {
+ Log.e(TAG, "Failed to deregister hostapd death handler");
}
+ mHostapdHal.terminate();
}
}
}
@@ -458,16 +486,10 @@ public class WifiNative {
if (!mHostapdHal.removeAccessPoint(iface.name)) {
Log.e(TAG, "Failed to remove access point on " + iface);
}
- if (!mHostapdHal.deregisterDeathHandler()) {
- Log.e(TAG, "Failed to deregister supplicant death handler");
- }
- // TODO(b/71513606): Move this to a global operation.
- if (!mWificondControl.stopHostapd(iface.name)) {
- Log.e(TAG, "Failed to stop hostapd on " + iface);
- }
if (!mWificondControl.tearDownSoftApInterface(iface.name)) {
Log.e(TAG, "Failed to teardown iface in wificond on " + iface);
}
+ stopHostapdIfNecessary();
stopHalAndWificondIfNecessary();
}
}
@@ -1007,6 +1029,11 @@ public class WifiNative {
mWifiMetrics.incrementNumSetupSoftApInterfaceFailureDueToHal();
return null;
}
+ if (!startHostapd()) {
+ Log.e(TAG, "Failed to start hostapd");
+ mWifiMetrics.incrementNumSetupSoftApInterfaceFailureDueToHostapd();
+ return null;
+ }
Iface iface = mIfaceMgr.allocateIface(Iface.IFACE_TYPE_AP);
if (iface == null) {
Log.e(TAG, "Failed to allocate new AP iface");
@@ -1311,12 +1338,16 @@ public class WifiNative {
*
* @return true if connection is established, false otherwise.
*/
- private boolean waitForHostapdConnection() {
+ private boolean startAndWaitForHostapdConnection() {
// Start initialization if not already started.
if (!mHostapdHal.isInitializationStarted()
&& !mHostapdHal.initialize()) {
return false;
}
+ if (!mHostapdHal.startDaemon()) {
+ Log.e(TAG, "Failed to startup hostapd");
+ return false;
+ }
boolean connected = false;
int connectTries = 0;
while (!connected && connectTries++ < CONNECT_TO_HOSTAPD_RETRY_TIMES) {
@@ -1343,21 +1374,6 @@ public class WifiNative {
*/
public boolean startSoftAp(
@NonNull String ifaceName, WifiConfiguration config, SoftApListener listener) {
- if (!mWificondControl.startHostapd(ifaceName, listener)) {
- Log.e(TAG, "Failed to start hostapd");
- mWifiMetrics.incrementNumSetupSoftApInterfaceFailureDueToHostapd();
- return false;
- }
- if (!waitForHostapdConnection()) {
- Log.e(TAG, "Failed to establish connection to hostapd");
- mWifiMetrics.incrementNumSetupSoftApInterfaceFailureDueToHostapd();
- return false;
- }
- if (!mHostapdHal.registerDeathHandler(new HostapdDeathHandlerInternal())) {
- Log.e(TAG, "Failed to register hostapd death handler");
- mWifiMetrics.incrementNumSetupSoftApInterfaceFailureDueToHostapd();
- return false;
- }
if (!mHostapdHal.addAccessPoint(ifaceName, config)) {
Log.e(TAG, "Failed to add acccess point");
mWifiMetrics.incrementNumSetupSoftApInterfaceFailureDueToHostapd();