diff options
author | Roshan Pius <rpius@google.com> | 2018-08-17 11:37:11 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2018-08-20 14:13:32 -0700 |
commit | 4d4ab7b5b841ea7284aa7510ab24112c1874dab4 (patch) | |
tree | 9c05f458eb6d95fb6cd27d32373ac89e48e58084 /service | |
parent | bdebe2a4348c6b61375a683a4010263a0a835c18 (diff) |
SoftApManager: Handle asynchronous failures
SoftApManager currently does not get a notification when
hostapd runs into any failure after |IHostapd.addAccesPoint|.
Use the new onFailure() callback from hostapd to handle asynchronous
failures. The failure callback from hostapd will be treated similar to
an interface down indication (i.e will send
CMD_INTERFACE_STATUS_CHANGED message).
Bug: 112705137
Test: Manual test. Simulated the issue reported in the bug and ensured
that UI toggled off.
Test: Unit tests
Change-Id: I59e36fc7e457d1b21f5426b4b9f32a5e64b3463b
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/HostapdHal.java | 22 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/SoftApManager.java | 10 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiNative.java | 7 |
3 files changed, 35 insertions, 4 deletions
diff --git a/service/java/com/android/server/wifi/HostapdHal.java b/service/java/com/android/server/wifi/HostapdHal.java index b44e68fb7..5fb828ba0 100644 --- a/service/java/com/android/server/wifi/HostapdHal.java +++ b/service/java/com/android/server/wifi/HostapdHal.java @@ -33,6 +33,7 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.server.wifi.WifiNative.HostapdDeathEventHandler; import com.android.server.wifi.util.NativeUtil; +import java.util.HashMap; import java.util.NoSuchElementException; import javax.annotation.concurrent.ThreadSafe; @@ -55,6 +56,7 @@ public class HostapdHal { // Hostapd HAL interface objects private IServiceManager mIServiceManager = null; private IHostapd mIHostapd; + private HashMap<String, WifiNative.SoftApListener> mSoftApListeners = new HashMap<>(); private HostapdDeathEventHandler mDeathEventHandler; private final IServiceNotification mServiceNotificationCallback = @@ -271,9 +273,11 @@ public class HostapdHal { * * @param ifaceName Name of the interface. * @param config Configuration to use for the AP. + * @param listener Callback for AP events. * @return true on success, false otherwise. */ - public boolean addAccessPoint(@NonNull String ifaceName, @NonNull WifiConfiguration config) { + public boolean addAccessPoint(@NonNull String ifaceName, @NonNull WifiConfiguration config, + @NonNull WifiNative.SoftApListener listener) { synchronized (mLock) { final String methodStr = "addAccessPoint"; IHostapd.IfaceParams ifaceParams = new IHostapd.IfaceParams(); @@ -314,7 +318,11 @@ public class HostapdHal { if (!checkHostapdAndLogFailure(methodStr)) return false; try { HostapdStatus status = mIHostapd.addAccessPoint(ifaceParams, nwParams); - return checkStatusAndLogFailure(status, methodStr); + if (!checkStatusAndLogFailure(status, methodStr)) { + return false; + } + mSoftApListeners.put(ifaceName, listener); + return true; } catch (RemoteException e) { handleRemoteException(e, methodStr); return false; @@ -334,7 +342,11 @@ public class HostapdHal { if (!checkHostapdAndLogFailure(methodStr)) return false; try { HostapdStatus status = mIHostapd.removeAccessPoint(ifaceName); - return checkStatusAndLogFailure(status, methodStr); + if (!checkStatusAndLogFailure(status, methodStr)) { + return false; + } + mSoftApListeners.remove(ifaceName); + return true; } catch (RemoteException e) { handleRemoteException(e, methodStr); return false; @@ -559,6 +571,10 @@ public class HostapdHal { @Override public void onFailure(String ifaceName) { Log.w(TAG, "Failure on iface " + ifaceName); + WifiNative.SoftApListener listener = mSoftApListeners.get(ifaceName); + if (listener != null) { + listener.onFailure(); + } } } } diff --git a/service/java/com/android/server/wifi/SoftApManager.java b/service/java/com/android/server/wifi/SoftApManager.java index 1d11996b4..53cbd7958 100644 --- a/service/java/com/android/server/wifi/SoftApManager.java +++ b/service/java/com/android/server/wifi/SoftApManager.java @@ -99,6 +99,12 @@ public class SoftApManager implements ActiveModeManager { * Listener for soft AP events. */ private final SoftApListener mSoftApListener = new SoftApListener() { + + @Override + public void onFailure() { + mStateMachine.sendMessage(SoftApStateMachine.CMD_FAILURE); + } + @Override public void onNumAssociatedStationsChanged(int numStations) { mStateMachine.sendMessage( @@ -292,6 +298,7 @@ public class SoftApManager implements ActiveModeManager { private class SoftApStateMachine extends StateMachine { // Commands for the state machine. public static final int CMD_START = 0; + public static final int CMD_FAILURE = 2; public static final int CMD_INTERFACE_STATUS_CHANGED = 3; public static final int CMD_NUM_ASSOCIATED_STATIONS_CHANGED = 4; public static final int CMD_NO_ASSOCIATED_STATIONS_TIMEOUT = 5; @@ -622,6 +629,9 @@ public class SoftApManager implements ActiveModeManager { mApInterfaceName = null; transitionTo(mIdleState); break; + case CMD_FAILURE: + Log.w(TAG, "hostapd failure, stop and report failure"); + /* fall through */ case CMD_INTERFACE_DOWN: Log.w(TAG, "interface error, stop and report failure"); updateApState(WifiManager.WIFI_AP_STATE_FAILED, diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index 625f89cfa..72663e7ab 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -1321,6 +1321,11 @@ public class WifiNative { */ public interface SoftApListener { /** + * Invoked when there is some fatal failure in the lower layers. + */ + void onFailure(); + + /** * Invoked when the number of associated stations changes. */ void onNumAssociatedStationsChanged(int numStations); @@ -1378,7 +1383,7 @@ public class WifiNative { Log.e(TAG, "Failed to register ap listener"); return false; } - if (!mHostapdHal.addAccessPoint(ifaceName, config)) { + if (!mHostapdHal.addAccessPoint(ifaceName, config, listener)) { Log.e(TAG, "Failed to add acccess point"); mWifiMetrics.incrementNumSetupSoftApInterfaceFailureDueToHostapd(); return false; |