diff options
5 files changed, 60 insertions, 45 deletions
diff --git a/service/java/com/android/server/wifi/HostapdHal.java b/service/java/com/android/server/wifi/HostapdHal.java index 04841c8cc..e1e4556ea 100644 --- a/service/java/com/android/server/wifi/HostapdHal.java +++ b/service/java/com/android/server/wifi/HostapdHal.java @@ -67,7 +67,7 @@ public class HostapdHal { // Hostapd HAL interface objects private IServiceManager mIServiceManager = null; private IHostapd mIHostapd; - private HashMap<String, WifiNative.SoftApListener> mSoftApListeners = new HashMap<>(); + private HashMap<String, Runnable> mSoftApFailureListeners = new HashMap<>(); private HostapdDeathEventHandler mDeathEventHandler; private ServiceManagerDeathRecipient mServiceManagerDeathRecipient; private HostapdDeathRecipient mHostapdDeathRecipient; @@ -315,11 +315,11 @@ public class HostapdHal { * * @param ifaceName Name of the interface. * @param config Configuration to use for the AP. - * @param listener Callback for AP events. + * @param onFailureListener A runnable to be triggered on failure. * @return true on success, false otherwise. */ public boolean addAccessPoint(@NonNull String ifaceName, @NonNull SoftApConfiguration config, - @NonNull WifiNative.SoftApListener listener) { + @NonNull Runnable onFailureListener) { synchronized (mLock) { final String methodStr = "addAccessPoint"; IHostapd.IfaceParams ifaceParams = new IHostapd.IfaceParams(); @@ -392,7 +392,7 @@ public class HostapdHal { if (!checkStatusAndLogFailure(status, methodStr)) { return false; } - mSoftApListeners.put(ifaceName, listener); + mSoftApFailureListeners.put(ifaceName, onFailureListener); return true; } catch (RemoteException e) { handleRemoteException(e, methodStr); @@ -416,7 +416,7 @@ public class HostapdHal { if (!checkStatusAndLogFailure(status, methodStr)) { return false; } - mSoftApListeners.remove(ifaceName); + mSoftApFailureListeners.remove(ifaceName); return true; } catch (RemoteException e) { handleRemoteException(e, methodStr); @@ -699,9 +699,9 @@ 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(); + Runnable onFailureListener = mSoftApFailureListeners.get(ifaceName); + if (onFailureListener != null) { + onFailureListener.run(); } } } diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index e4789eb30..f5a52a6ae 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -39,7 +39,6 @@ import com.android.internal.util.HexDump; import com.android.server.net.BaseNetworkObserver; import com.android.server.wifi.util.FrameParser; import com.android.server.wifi.util.NativeUtil; -import com.android.server.wifi.wificond.NativeWifiClient; import java.io.PrintWriter; import java.io.StringWriter; @@ -115,6 +114,13 @@ public class WifiNative { mWifiVendorHal.enableVerboseLogging(mVerboseLoggingEnabled); } + /** + * Callbacks for SoftAp interface. + */ + public interface SoftApListener extends WificondControl.SoftApListener { + // dummy for now - provide a shell so that clients don't use a WificondControl-specific API. + } + /******************************************************** * Interface management related methods. ********************************************************/ @@ -1522,26 +1528,6 @@ public class WifiNative { return frame.array(); } - /** - * Callbacks for SoftAp interface. - */ - public interface SoftApListener { - /** - * Invoked when there is some fatal failure in the lower layers. - */ - void onFailure(); - - /** - * Invoked when the associated stations changes. - */ - void onConnectedClientsChanged(List<NativeWifiClient> clients); - - /** - * Invoked when the channel switch event happens. - */ - void onSoftApChannelSwitched(int frequency, int bandwidth); - } - private static final int CONNECT_TO_HOSTAPD_RETRY_INTERVAL_MS = 100; private static final int CONNECT_TO_HOSTAPD_RETRY_TIMES = 50; /** @@ -1589,7 +1575,7 @@ public class WifiNative { Log.e(TAG, "Failed to register ap listener"); return false; } - if (!mHostapdHal.addAccessPoint(ifaceName, config, listener)) { + if (!mHostapdHal.addAccessPoint(ifaceName, config, () -> listener.onFailure())) { Log.e(TAG, "Failed to add acccess point"); mWifiMetrics.incrementNumSetupSoftApInterfaceFailureDueToHostapd(); return false; diff --git a/service/java/com/android/server/wifi/WificondControl.java b/service/java/com/android/server/wifi/WificondControl.java index 54f5d981e..487a53723 100644 --- a/service/java/com/android/server/wifi/WificondControl.java +++ b/service/java/com/android/server/wifi/WificondControl.java @@ -38,7 +38,6 @@ import android.os.IBinder; import android.os.RemoteException; import android.util.Log; -import com.android.server.wifi.WifiNative.SoftApListener; import com.android.server.wifi.hotspot2.NetworkDetail; import com.android.server.wifi.util.InformationElementUtil; import com.android.server.wifi.util.NativeUtil; @@ -156,6 +155,26 @@ public class WificondControl implements IBinder.DeathRecipient { } /** + * Callbacks for SoftAp interface. + */ + public interface SoftApListener { + /** + * Invoked when there is some fatal failure in the lower layers. + */ + void onFailure(); + + /** + * Invoked when the associated stations changes. + */ + void onConnectedClientsChanged(List<NativeWifiClient> clients); + + /** + * Invoked when the channel switch event happens. + */ + void onSoftApChannelSwitched(int frequency, int bandwidth); + } + + /** * Callback to notify the results of a * {@link #sendMgmtFrame(String, byte[], SendMgmtFrameCallback, int) sendMgmtFrame()} call. * Note: no callbacks will be triggered if the iface dies while sending a frame. diff --git a/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java b/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java index 49c6123a1..6fdffa26f 100644 --- a/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java @@ -64,7 +64,7 @@ public class HostapdHalTest extends WifiBaseTest { private @Mock IServiceManager mServiceManagerMock; private @Mock IHostapd mIHostapdMock; private @Mock WifiNative.HostapdDeathEventHandler mHostapdHalDeathHandler; - private @Mock WifiNative.SoftApListener mSoftApListener; + private @Mock WificondControl.SoftApListener mSoftApListener; private android.hardware.wifi.hostapd.V1_1.IHostapd mIHostapdMockV1_1; private IHostapdCallback mIHostapdCallback; private MockResources mResources; @@ -229,7 +229,8 @@ public class HostapdHalTest extends WifiBaseTest { configurationBuilder.setBand(SoftApConfiguration.BAND_2GHZ); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, - configurationBuilder.build(), mSoftApListener)); + configurationBuilder.build(), + () -> mSoftApListener.onFailure())); verify(mIHostapdMock).addAccessPoint(any(), any()); assertEquals(IFACE_NAME, mIfaceParamsCaptor.getValue().ifaceName); @@ -262,7 +263,8 @@ public class HostapdHalTest extends WifiBaseTest { configurationBuilder.setBand(SoftApConfiguration.BAND_5GHZ); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, - configurationBuilder.build(), mSoftApListener)); + configurationBuilder.build(), + () -> mSoftApListener.onFailure())); verify(mIHostapdMock).addAccessPoint(any(), any()); assertEquals(IFACE_NAME, mIfaceParamsCaptor.getValue().ifaceName); @@ -296,7 +298,8 @@ public class HostapdHalTest extends WifiBaseTest { configurationBuilder.setBand(SoftApConfiguration.BAND_5GHZ); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, - configurationBuilder.build(), mSoftApListener)); + configurationBuilder.build(), + () -> mSoftApListener.onFailure())); verify(mIHostapdMock).addAccessPoint(any(), any()); assertEquals(IFACE_NAME, mIfaceParamsCaptor.getValue().ifaceName); @@ -334,7 +337,8 @@ public class HostapdHalTest extends WifiBaseTest { configurationBuilder.setBand(SoftApConfiguration.BAND_2GHZ); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, - configurationBuilder.build(), mSoftApListener)); + configurationBuilder.build(), + () -> mSoftApListener.onFailure())); verify(mIHostapdMock).addAccessPoint(any(), any()); assertEquals(IFACE_NAME, mIfaceParamsCaptor.getValue().ifaceName); @@ -372,7 +376,8 @@ public class HostapdHalTest extends WifiBaseTest { configurationBuilder.setBand(SoftApConfiguration.BAND_2GHZ); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, - configurationBuilder.build(), mSoftApListener)); + configurationBuilder.build(), + () -> mSoftApListener.onFailure())); verify(mIHostapdMock).addAccessPoint(any(), any()); assertEquals(IFACE_NAME, mIfaceParamsCaptor.getValue().ifaceName); @@ -409,7 +414,8 @@ public class HostapdHalTest extends WifiBaseTest { configurationBuilder.setBand(SoftApConfiguration.BAND_ANY); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, - configurationBuilder.build(), mSoftApListener)); + configurationBuilder.build(), + () -> mSoftApListener.onFailure())); verify(mIHostapdMock).addAccessPoint(any(), any()); assertEquals(IFACE_NAME, mIfaceParamsCaptor.getValue().ifaceName); @@ -447,7 +453,8 @@ public class HostapdHalTest extends WifiBaseTest { configurationBuilder.setBand(SoftApConfiguration.BAND_ANY); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, - configurationBuilder.build(), mSoftApListener)); + configurationBuilder.build(), + () -> mSoftApListener.onFailure())); verify(mIHostapdMock).addAccessPoint(any(), any()); assertEquals(IFACE_NAME, mIfaceParamsCaptor.getValue().ifaceName); @@ -511,9 +518,9 @@ public class HostapdHalTest extends WifiBaseTest { configurationBuilder.setWpa2Passphrase(NETWORK_PSK); configurationBuilder.setBand(SoftApConfiguration.BAND_ANY); - assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, - configurationBuilder.build(), mSoftApListener)); + configurationBuilder.build(), + () -> mSoftApListener.onFailure())); verify(mIHostapdMockV1_1).addAccessPoint_1_1(any(), any()); assertEquals(IFACE_NAME, mIfaceParamsCaptorV1_1.getValue().V1_0.ifaceName); @@ -548,7 +555,8 @@ public class HostapdHalTest extends WifiBaseTest { configurationBuilder.setBand(SoftApConfiguration.BAND_2GHZ); assertFalse(mHostapdHal.addAccessPoint(IFACE_NAME, - configurationBuilder.build(), mSoftApListener)); + configurationBuilder.build(), + () -> mSoftApListener.onFailure())); verify(mIHostapdMock).addAccessPoint(any(), any()); } @@ -566,7 +574,8 @@ public class HostapdHalTest extends WifiBaseTest { configurationBuilder.setChannel(6); assertFalse(mHostapdHal.addAccessPoint(IFACE_NAME, - configurationBuilder.build(), mSoftApListener)); + configurationBuilder.build(), + () -> mSoftApListener.onFailure())); verify(mIHostapdMock).addAccessPoint(any(), any()); } @@ -623,7 +632,8 @@ public class HostapdHalTest extends WifiBaseTest { configurationBuilder.setBand(SoftApConfiguration.BAND_2GHZ); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, - configurationBuilder.build(), mSoftApListener)); + configurationBuilder.build(), + () -> mSoftApListener.onFailure())); verify(mIHostapdMockV1_1).addAccessPoint_1_1(any(), any()); // Trigger on failure. diff --git a/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java b/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java index 1b7a7a1ce..5a0d91488 100644 --- a/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java @@ -99,7 +99,7 @@ public class WificondControlTest extends WifiBaseTest { @Mock private IWifiScannerImpl mWifiScannerImpl; @Mock private CarrierNetworkConfig mCarrierNetworkConfig; @Mock private IApInterface mApInterface; - @Mock private WifiNative.SoftApListener mSoftApListener; + @Mock private WificondControl.SoftApListener mSoftApListener; @Mock private AlarmManager mAlarmManager; @Mock private Clock mClock; @Mock private SendMgmtFrameCallback mSendMgmtFrameCallback; |