diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2018-03-30 23:51:43 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-03-30 23:51:43 +0000 |
commit | b7eeb863bd07bd691eb815ac0b5583749efa0b62 (patch) | |
tree | 4f25ac1fee4af7f8132c9814fd97a79885e98f7b | |
parent | b485ce7e9ecf0fa448e0224f6e410a1a5f0c86f5 (diff) | |
parent | 1c7f0d2c83318cdd1c127a083362e91765c0d941 (diff) |
Merge "Move setMacAddress from wifiCond to vendor HAL" into pi-dev
4 files changed, 114 insertions, 5 deletions
diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index 4beb6c332..aebb236ca 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -1243,7 +1243,7 @@ public class WifiNative { */ public boolean setMacAddress(String interfaceName, MacAddress mac) { // TODO(b/72459123): Suppress interface down/up events from this call - return mWificondControl.setMacAddress(interfaceName, mac); + return mWifiVendorHal.setMacAddress(interfaceName, mac); } /******************************************************** diff --git a/service/java/com/android/server/wifi/WifiVendorHal.java b/service/java/com/android/server/wifi/WifiVendorHal.java index f90c49a05..36060fa55 100644 --- a/service/java/com/android/server/wifi/WifiVendorHal.java +++ b/service/java/com/android/server/wifi/WifiVendorHal.java @@ -54,6 +54,7 @@ import android.hardware.wifi.V1_0.WifiDebugTxPacketFateReport; import android.hardware.wifi.V1_0.WifiInformationElement; import android.hardware.wifi.V1_0.WifiStatus; import android.hardware.wifi.V1_0.WifiStatusCode; +import android.net.MacAddress; import android.net.apf.ApfCapabilities; import android.net.wifi.RttManager; import android.net.wifi.RttManager.ResponderConfig; @@ -1654,6 +1655,30 @@ public class WifiVendorHal { } /** + * Set Mac address on the given interface + * + * @param ifaceName Name of the interface + * @param mac MAC address to change into + * @return true for success + */ + public boolean setMacAddress(@NonNull String ifaceName, @NonNull MacAddress mac) { + byte[] macByteArray = mac.toByteArray(); + synchronized (sLock) { + try { + android.hardware.wifi.V1_2.IWifiStaIface ifaceV12 = + getWifiStaIfaceForV1_2Mockable(ifaceName); + if (ifaceV12 == null) return boolResult(false); + WifiStatus status = ifaceV12.setMacAddress(macByteArray); + if (!ok(status)) return false; + return true; + } catch (RemoteException e) { + handleRemoteException(e); + return false; + } + } + } + + /** * Get the APF (Android Packet Filter) capabilities of the device * * @param ifaceName Name of the interface. @@ -2544,6 +2569,21 @@ public class WifiVendorHal { return android.hardware.wifi.V1_2.IWifiChip.castFrom(mIWifiChip); } + /** + * Method to mock out the V1_2 IWifiStaIface retrieval in unit tests. + * + * @param ifaceName Name of the interface + * @return 1.2 IWifiStaIface object if the device is running the 1.2 wifi hal service, null + * otherwise. + */ + protected android.hardware.wifi.V1_2.IWifiStaIface getWifiStaIfaceForV1_2Mockable( + @NonNull String ifaceName) { + IWifiStaIface iface = getStaIface(ifaceName); + if (iface == null) return null; + return android.hardware.wifi.V1_2.IWifiStaIface.castFrom(iface); + } + + private int frameworkToHalTxPowerScenario(int scenario) { switch (scenario) { case WifiNative.TX_POWER_SCENARIO_VOICE_CALL: diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java index ee3b425ad..6bbc55810 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java @@ -566,12 +566,12 @@ public class WifiNativeTest { } /** - * Verifies that setMacAddress() calls underlying WificondControl. + * Verifies that setMacAddress() calls underlying WifiVendorHal. */ @Test public void testSetMacAddress() throws Exception { mWifiNative.setMacAddress(WIFI_IFACE_NAME, TEST_MAC_ADDRESS); - verify(mWificondControl).setMacAddress(WIFI_IFACE_NAME, TEST_MAC_ADDRESS); + verify(mWifiVendorHal).setMacAddress(WIFI_IFACE_NAME, TEST_MAC_ADDRESS); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java index 9da4c70b9..70c612918 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java @@ -30,6 +30,7 @@ import static org.mockito.Mockito.anyObject; import static org.mockito.Mockito.anyShort; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -75,6 +76,7 @@ import android.hardware.wifi.V1_0.WifiInformationElement; import android.hardware.wifi.V1_0.WifiStatus; import android.hardware.wifi.V1_0.WifiStatusCode; import android.net.KeepalivePacketData; +import android.net.MacAddress; import android.net.apf.ApfCapabilities; import android.net.wifi.RttManager; import android.net.wifi.ScanResult; @@ -113,6 +115,8 @@ import java.util.Set; public class WifiVendorHalTest { private static final String TEST_IFACE_NAME = "wlan0"; + private static final MacAddress TEST_MAC_ADDRESS = MacAddress.fromString("ee:33:a2:94:10:92"); + WifiVendorHal mWifiVendorHal; private WifiStatus mWifiStatusSuccess; private WifiStatus mWifiStatusFailure; @@ -134,6 +138,8 @@ public class WifiVendorHalTest { @Mock private IWifiStaIface mIWifiStaIface; @Mock + private android.hardware.wifi.V1_2.IWifiStaIface mIWifiStaIfaceV12; + @Mock private IWifiRttController mIWifiRttController; private IWifiStaIfaceEventCallback mIWifiStaIfaceEventCallback; private IWifiChipEventCallback mIWifiChipEventCallback; @@ -159,11 +165,17 @@ public class WifiVendorHalTest { protected android.hardware.wifi.V1_2.IWifiChip getWifiChipForV1_2Mockable() { return null; } + + @Override + protected android.hardware.wifi.V1_2.IWifiStaIface getWifiStaIfaceForV1_2Mockable( + String ifaceName) { + return null; + } } /** - * Spy used to return the V1_2 IWifiChip mock object to simulate the 1.2 HAL running on the - * device. + * Spy used to return the V1_2 IWifiChip and IWifiStaIface mock objects to simulate + * the 1.2 HAL running on the device. */ private class WifiVendorHalSpyV1_2 extends WifiVendorHal { WifiVendorHalSpyV1_2(HalDeviceManager halDeviceManager, Looper looper) { @@ -179,6 +191,12 @@ public class WifiVendorHalTest { protected android.hardware.wifi.V1_2.IWifiChip getWifiChipForV1_2Mockable() { return mIWifiChipV12; } + + @Override + protected android.hardware.wifi.V1_2.IWifiStaIface getWifiStaIfaceForV1_2Mockable( + String ifaceName) { + return mIWifiStaIfaceV12; + } } /** @@ -2089,6 +2107,57 @@ public class WifiVendorHalTest { testAlertCallbackUsingProvidedCallback(mIWifiChipEventCallbackV12); } + /** + * Verifies setMacAddress() success. + */ + @Test + public void testSetMacAddressSuccess() throws Exception { + // Expose the 1.2 IWifiStaIface. + mWifiVendorHal = new WifiVendorHalSpyV1_2(mHalDeviceManager, mLooper.getLooper()); + byte[] macByteArray = TEST_MAC_ADDRESS.toByteArray(); + when(mIWifiStaIfaceV12.setMacAddress(macByteArray)).thenReturn(mWifiStatusSuccess); + + assertTrue(mWifiVendorHal.setMacAddress(TEST_IFACE_NAME, TEST_MAC_ADDRESS)); + verify(mIWifiStaIfaceV12).setMacAddress(macByteArray); + } + + /** + * Verifies setMacAddress() can handle failure status. + */ + @Test + public void testSetMacAddressFailDueToStatusFailure() throws Exception { + // Expose the 1.2 IWifiStaIface. + mWifiVendorHal = new WifiVendorHalSpyV1_2(mHalDeviceManager, mLooper.getLooper()); + byte[] macByteArray = TEST_MAC_ADDRESS.toByteArray(); + when(mIWifiStaIfaceV12.setMacAddress(macByteArray)).thenReturn(mWifiStatusFailure); + + assertFalse(mWifiVendorHal.setMacAddress(TEST_IFACE_NAME, TEST_MAC_ADDRESS)); + verify(mIWifiStaIfaceV12).setMacAddress(macByteArray); + } + + /** + * Verifies setMacAddress() can handle RemoteException. + */ + @Test + public void testSetMacAddressFailDueToRemoteException() throws Exception { + // Expose the 1.2 IWifiStaIface. + mWifiVendorHal = new WifiVendorHalSpyV1_2(mHalDeviceManager, mLooper.getLooper()); + byte[] macByteArray = TEST_MAC_ADDRESS.toByteArray(); + doThrow(new RemoteException()).when(mIWifiStaIfaceV12).setMacAddress(macByteArray); + + assertFalse(mWifiVendorHal.setMacAddress(TEST_IFACE_NAME, TEST_MAC_ADDRESS)); + verify(mIWifiStaIfaceV12).setMacAddress(macByteArray); + } + + /** + * Verifies setMacAddress() does not crash with older HALs. + */ + @Test + public void testSetMacAddressDoesNotCrashOnOlderHal() throws Exception { + byte[] macByteArray = TEST_MAC_ADDRESS.toByteArray(); + assertFalse(mWifiVendorHal.setMacAddress(TEST_IFACE_NAME, TEST_MAC_ADDRESS)); + } + private void testAlertCallbackUsingProvidedCallback(IWifiChipEventCallback chipCallback) throws Exception { when(mIWifiChip.enableDebugErrorAlerts(anyBoolean())).thenReturn(mWifiStatusSuccess); |