diff options
author | Etan Cohen <etancohen@google.com> | 2019-12-10 02:46:36 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-12-10 02:46:36 +0000 |
commit | fcd87af28d921bba79f2a0c4e818945682fb772c (patch) | |
tree | 91fe2ddbc5ce308eedf347435e9f057cd8381229 | |
parent | 77236e5278abc5167da85b334f1e9e84fb09652a (diff) | |
parent | d41ee729484c8cf82acd7bf58d7c3fd2f01afc22 (diff) |
Merge changes from topic "wificond_phase2"
* changes:
[WIFI][MAINLINE] Transition WificondControl interfaces: DeathListner -> Runnable
[WIFI][MAINLINE] Transition WificondControl interfaces: PnoSettings
5 files changed, 61 insertions, 58 deletions
diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index f5a52a6ae..c8c0da8d6 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -602,9 +602,9 @@ public class WifiNative { /** * Death handler for the wificond daemon. */ - private class WificondDeathHandlerInternal implements WificondDeathEventHandler { + private class WificondDeathHandlerInternal implements Runnable { @Override - public void onDeath() { + public void run() { synchronized (mLock) { Log.i(TAG, "wificond died. Cleaning up internal state."); onNativeDaemonDeath(); @@ -1318,16 +1318,6 @@ public class WifiNative { ********************************************************/ /** - * Callback to notify wificond death. - */ - public interface WificondDeathEventHandler { - /** - * Invoked when the wificond dies. - */ - void onDeath(); - } - - /** * Request signal polling to wificond. * * @param ifaceName Name of the interface. @@ -1408,7 +1398,7 @@ public class WifiNative { * @return true on success. */ public boolean startPnoScan(@NonNull String ifaceName, PnoSettings pnoSettings) { - return mWificondControl.startPnoScan(ifaceName, pnoSettings); + return mWificondControl.startPnoScan(ifaceName, pnoSettings.toNativePnoSettings()); } /** @@ -2480,6 +2470,22 @@ public class WifiNative { public int hashCode() { return Objects.hash(ssid, flags, auth_bit_field, frequencies); } + + com.android.server.wifi.wificond.PnoNetwork toNativePnoNetwork() { + com.android.server.wifi.wificond.PnoNetwork nativePnoNetwork = + new com.android.server.wifi.wificond.PnoNetwork(); + nativePnoNetwork.isHidden = + (flags & WifiScanner.PnoSettings.PnoNetwork.FLAG_DIRECTED_SCAN) != 0; + try { + nativePnoNetwork.ssid = + NativeUtil.byteArrayFromArrayList(NativeUtil.decodeSsid(ssid)); + } catch (IllegalArgumentException e) { + Log.e(TAG, "Illegal argument " + ssid, e); + return null; + } + nativePnoNetwork.frequencies = frequencies; + return nativePnoNetwork; + } } /** @@ -2499,6 +2505,27 @@ public class WifiNative { public int periodInMs; public boolean isConnected; public PnoNetwork[] networkList; + + com.android.server.wifi.wificond.PnoSettings toNativePnoSettings() { + com.android.server.wifi.wificond.PnoSettings nativePnoSettings = + new com.android.server.wifi.wificond.PnoSettings(); + nativePnoSettings.intervalMs = periodInMs; + nativePnoSettings.min2gRssi = min24GHzRssi; + nativePnoSettings.min5gRssi = min5GHzRssi; + nativePnoSettings.min6gRssi = min6GHzRssi; + + nativePnoSettings.pnoNetworks = new ArrayList<>(); + if (networkList != null) { + for (PnoNetwork network : networkList) { + com.android.server.wifi.wificond.PnoNetwork nativeNetwork = + network.toNativePnoNetwork(); + if (nativeNetwork != null) { + nativePnoSettings.pnoNetworks.add(nativeNetwork); + } + } + } + return nativePnoSettings; + } } public static interface ScanEventHandler { diff --git a/service/java/com/android/server/wifi/WificondControl.java b/service/java/com/android/server/wifi/WificondControl.java index 487a53723..2c8d1ac0c 100644 --- a/service/java/com/android/server/wifi/WificondControl.java +++ b/service/java/com/android/server/wifi/WificondControl.java @@ -46,7 +46,6 @@ import com.android.server.wifi.wificond.ChannelSettings; import com.android.server.wifi.wificond.HiddenNetwork; import com.android.server.wifi.wificond.NativeScanResult; import com.android.server.wifi.wificond.NativeWifiClient; -import com.android.server.wifi.wificond.PnoNetwork; import com.android.server.wifi.wificond.PnoSettings; import com.android.server.wifi.wificond.RadioChainInfo; import com.android.server.wifi.wificond.SingleScanSettings; @@ -102,7 +101,7 @@ public class WificondControl implements IBinder.DeathRecipient { private HashMap<String, IScanEvent> mScanEventHandlers = new HashMap<>(); private HashMap<String, IPnoScanEvent> mPnoScanEventHandlers = new HashMap<>(); private HashMap<String, IApInterfaceEventCallback> mApInterfaceListeners = new HashMap<>(); - private WifiNative.WificondDeathEventHandler mDeathEventHandler; + private Runnable mDeathEventHandler; /** * Ensures that no more than one sendMgmtFrame operation runs concurrently. */ @@ -371,7 +370,7 @@ public class WificondControl implements IBinder.DeathRecipient { // on the next setup call. mWificond = null; if (mDeathEventHandler != null) { - mDeathEventHandler.onDeath(); + mDeathEventHandler.run(); } }); } @@ -389,11 +388,11 @@ public class WificondControl implements IBinder.DeathRecipient { * * @return Returns true on success. */ - public boolean initialize(@NonNull WifiNative.WificondDeathEventHandler handler) { + public boolean initialize(@NonNull Runnable deathEventHandler) { if (mDeathEventHandler != null) { Log.e(TAG, "Death handler already present"); } - mDeathEventHandler = handler; + mDeathEventHandler = deathEventHandler; tearDownInterfaces(); return true; } @@ -845,37 +844,15 @@ public class WificondControl implements IBinder.DeathRecipient { * @param pnoSettings Pno scan configuration. * @return true on success. */ - public boolean startPnoScan(@NonNull String ifaceName, WifiNative.PnoSettings pnoSettings) { + public boolean startPnoScan(@NonNull String ifaceName, PnoSettings pnoSettings) { IWifiScannerImpl scannerImpl = getScannerImpl(ifaceName); if (scannerImpl == null) { Log.e(TAG, "No valid wificond scanner interface handler"); return false; } - PnoSettings settings = new PnoSettings(); - settings.pnoNetworks = new ArrayList<>(); - settings.intervalMs = pnoSettings.periodInMs; - settings.min2gRssi = pnoSettings.min24GHzRssi; - settings.min5gRssi = pnoSettings.min5GHzRssi; - settings.min6gRssi = pnoSettings.min6GHzRssi; - if (pnoSettings.networkList != null) { - for (WifiNative.PnoNetwork network : pnoSettings.networkList) { - PnoNetwork condNetwork = new PnoNetwork(); - condNetwork.isHidden = (network.flags - & WifiScanner.PnoSettings.PnoNetwork.FLAG_DIRECTED_SCAN) != 0; - try { - condNetwork.ssid = - NativeUtil.byteArrayFromArrayList(NativeUtil.decodeSsid(network.ssid)); - } catch (IllegalArgumentException e) { - Log.e(TAG, "Illegal argument " + network.ssid, e); - continue; - } - condNetwork.frequencies = network.frequencies; - settings.pnoNetworks.add(condNetwork); - } - } try { - boolean success = scannerImpl.startPnoScan(settings); + boolean success = scannerImpl.startPnoScan(pnoSettings); mWifiInjector.getWifiMetrics().incrementPnoScanStartAttempCount(); if (!success) { mWifiInjector.getWifiMetrics().incrementPnoScanFailedCount(); @@ -928,7 +905,7 @@ public class WificondControl implements IBinder.DeathRecipient { * The result depends on the on the country code that has been set. * * @param band as specified by one of the WifiScanner.WIFI_BAND_* constants. - * The following bands are supported {@link WifiBandBasic}: + * The following bands are supported {@link @WifiScanner.WifiBandBasic}: * WifiScanner.WIFI_BAND_24_GHZ * WifiScanner.WIFI_BAND_5_GHZ * WifiScanner.WIFI_BAND_5_GHZ_DFS_ONLY diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java index 648faa55a..1a56504e1 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java @@ -52,7 +52,6 @@ import com.android.server.net.BaseNetworkObserver; import com.android.server.wifi.HalDeviceManager.InterfaceDestroyedListener; import com.android.server.wifi.WifiNative.SupplicantDeathEventHandler; import com.android.server.wifi.WifiNative.VendorHalDeathEventHandler; -import com.android.server.wifi.WifiNative.WificondDeathEventHandler; import org.junit.After; import org.junit.Before; @@ -91,8 +90,8 @@ public class WifiNativeInterfaceManagementTest extends WifiBaseTest { private ArgumentCaptor<VendorHalDeathEventHandler> mWifiVendorHalDeathHandlerCaptor = ArgumentCaptor.forClass(VendorHalDeathEventHandler.class); - private ArgumentCaptor<WificondDeathEventHandler> mWificondDeathHandlerCaptor = - ArgumentCaptor.forClass(WificondDeathEventHandler.class); + private ArgumentCaptor<Runnable> mWificondDeathHandlerCaptor = + ArgumentCaptor.forClass(Runnable.class); private ArgumentCaptor<WifiNative.VendorHalRadioModeChangeEventHandler> mWifiVendorHalRadioModeChangeHandlerCaptor = ArgumentCaptor.forClass(WifiNative.VendorHalRadioModeChangeEventHandler.class); @@ -742,7 +741,7 @@ public class WifiNativeInterfaceManagementTest extends WifiBaseTest { false, false, IFACE_NAME_0, mIfaceCallback0, mIfaceDestroyedListenerCaptor0, mNetworkObserverCaptor0); // Trigger wificond death - mWificondDeathHandlerCaptor.getValue().onDeath(); + mWificondDeathHandlerCaptor.getValue().run(); mInOrder.verify(mWifiMetrics).incrementNumWificondCrashes(); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java index c13a5fc90..73969d7a6 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java @@ -558,7 +558,7 @@ public class WifiNativeTest extends WifiBaseTest { public void testStartPnoScan() throws Exception { mWifiNative.startPnoScan(WIFI_IFACE_NAME, TEST_PNO_SETTINGS); verify(mWificondControl).startPnoScan( - WIFI_IFACE_NAME, TEST_PNO_SETTINGS); + WIFI_IFACE_NAME, TEST_PNO_SETTINGS.toNativePnoSettings()); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java b/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java index 5a0d91488..722c86842 100644 --- a/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java @@ -796,7 +796,8 @@ public class WificondControlTest extends WifiBaseTest { @Test public void testStartPnoScan() throws Exception { when(mWifiScannerImpl.startPnoScan(any(PnoSettings.class))).thenReturn(true); - assertTrue(mWificondControl.startPnoScan(TEST_INTERFACE_NAME, TEST_PNO_SETTINGS)); + assertTrue(mWificondControl.startPnoScan(TEST_INTERFACE_NAME, + TEST_PNO_SETTINGS.toNativePnoSettings())); verify(mWifiScannerImpl).startPnoScan(argThat(new PnoScanMatcher(TEST_PNO_SETTINGS))); } @@ -889,7 +890,8 @@ public class WificondControlTest extends WifiBaseTest { @Test public void testStartPnoScanForMetrics() throws Exception { when(mWifiScannerImpl.startPnoScan(any(PnoSettings.class))).thenReturn(false); - assertFalse(mWificondControl.startPnoScan(TEST_INTERFACE_NAME, TEST_PNO_SETTINGS)); + assertFalse(mWificondControl.startPnoScan(TEST_INTERFACE_NAME, + TEST_PNO_SETTINGS.toNativePnoSettings())); verify(mWifiMetrics).incrementPnoScanStartAttempCount(); verify(mWifiMetrics).incrementPnoScanFailedCount(); } @@ -939,13 +941,12 @@ public class WificondControlTest extends WifiBaseTest { */ @Test public void testRegisterDeathHandler() throws Exception { - WifiNative.WificondDeathEventHandler handler = - mock(WifiNative.WificondDeathEventHandler.class); - assertTrue(mWificondControl.initialize(handler)); + Runnable deathHandler = mock(Runnable.class); + assertTrue(mWificondControl.initialize(deathHandler)); verify(mWificond).tearDownInterfaces(); mWificondControl.binderDied(); mLooper.dispatchAll(); - verify(handler).onDeath(); + verify(deathHandler).run(); } /** @@ -954,15 +955,14 @@ public class WificondControlTest extends WifiBaseTest { */ @Test public void testDeathHandling() throws Exception { - WifiNative.WificondDeathEventHandler handler = - mock(WifiNative.WificondDeathEventHandler.class); - assertTrue(mWificondControl.initialize(handler)); + Runnable deathHandler = mock(Runnable.class); + assertTrue(mWificondControl.initialize(deathHandler)); testSetupInterfaceForClientMode(); mWificondControl.binderDied(); mLooper.dispatchAll(); - verify(handler).onDeath(); + verify(deathHandler).run(); // The handles should be cleared after death. assertNull(mWificondControl.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ)); |