diff options
author | Roshan Pius <rpius@google.com> | 2018-01-22 19:28:44 -0800 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2018-01-23 13:41:30 -0800 |
commit | cc9c910dd0d35ad75003e4777b15562ebd7ada35 (patch) | |
tree | 0f9e0a6fb3c9323b0909b66371c098c587b32602 /tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java | |
parent | b39dea09cec69c6e0c1b4b1f16cbef58b01c1532 (diff) | |
download | android_frameworks_opt_net_wifi-cc9c910dd0d35ad75003e4777b15562ebd7ada35.tar.gz android_frameworks_opt_net_wifi-cc9c910dd0d35ad75003e4777b15562ebd7ada35.tar.bz2 android_frameworks_opt_net_wifi-cc9c910dd0d35ad75003e4777b15562ebd7ada35.zip |
WifiVendorHal: Add support for radio mode change callbacks
The new callback object uses the V1.0 callback object to handle the V1.0
callbacks. Java does not support multiple inheritance, so using two
separate classes to be backward compatible.
Bug: 68349158
Test: Unit tests
Test: Device boots up and connects to wifi networks.
Change-Id: Ic46d3f5929aaf48f3b0e43f0ed1c57ba80f17225
Diffstat (limited to 'tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java | 118 |
1 files changed, 86 insertions, 32 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java index 9830b9183..0ad0431dc 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java @@ -129,11 +129,14 @@ public class WifiVendorHalTest { @Mock private android.hardware.wifi.V1_1.IWifiChip mIWifiChipV11; @Mock + private android.hardware.wifi.V1_2.IWifiChip mIWifiChipV12; + @Mock private IWifiStaIface mIWifiStaIface; @Mock private IWifiRttController mIWifiRttController; private IWifiStaIfaceEventCallback mIWifiStaIfaceEventCallback; private IWifiChipEventCallback mIWifiChipEventCallback; + private android.hardware.wifi.V1_2.IWifiChipEventCallback mIWifiChipEventCallbackV12; @Mock private WifiNative.VendorHalDeathEventHandler mVendorHalDeathHandler; @@ -150,6 +153,31 @@ public class WifiVendorHalTest { protected android.hardware.wifi.V1_1.IWifiChip getWifiChipForV1_1Mockable() { return mIWifiChipV11; } + + @Override + protected android.hardware.wifi.V1_2.IWifiChip getWifiChipForV1_2Mockable() { + return null; + } + } + + /** + * Spy used to return the V1_2 IWifiChip mock object to simulate the 1.2 HAL running on the + * device. + */ + private class WifiVendorHalSpyV1_2 extends WifiVendorHal { + WifiVendorHalSpyV1_2(HalDeviceManager halDeviceManager, Looper looper) { + super(halDeviceManager, looper); + } + + @Override + protected android.hardware.wifi.V1_1.IWifiChip getWifiChipForV1_1Mockable() { + return null; + } + + @Override + protected android.hardware.wifi.V1_2.IWifiChip getWifiChipForV1_2Mockable() { + return mIWifiChipV12; + } } /** @@ -209,13 +237,20 @@ public class WifiVendorHalTest { mIWifiStaIfaceEventCallback = (IWifiStaIfaceEventCallback) args[0]; return (mWifiStatusSuccess); })); - mIWifiChipEventCallback = null; when(mIWifiChip.registerEventCallback(any(IWifiChipEventCallback.class))) .thenAnswer(answerWifiStatus((invocation) -> { Object[] args = invocation.getArguments(); mIWifiChipEventCallback = (IWifiChipEventCallback) args[0]; return (mWifiStatusSuccess); })); + when(mIWifiChipV12.registerEventCallback_1_2( + any(android.hardware.wifi.V1_2.IWifiChipEventCallback.class))) + .thenAnswer(answerWifiStatus((invocation) -> { + Object[] args = invocation.getArguments(); + mIWifiChipEventCallbackV12 = + (android.hardware.wifi.V1_2.IWifiChipEventCallback) args[0]; + return (mWifiStatusSuccess); + })); when(mIWifiRttController.registerEventCallback(any(IWifiRttControllerEventCallback.class))) .thenReturn(mWifiStatusSuccess); @@ -1851,40 +1886,10 @@ public class WifiVendorHalTest { */ @Test public void testAlertCallback() throws Exception { - when(mIWifiChip.enableDebugErrorAlerts(anyBoolean())).thenReturn(mWifiStatusSuccess); - when(mIWifiChip.stopLoggingToDebugRingBuffer()).thenReturn(mWifiStatusSuccess); - assertTrue(mWifiVendorHal.startVendorHalSta()); assertNotNull(mIWifiChipEventCallback); - int errorCode = 5; - byte[] errorData = new byte[45]; - new Random().nextBytes(errorData); - - // Randomly raise the HIDL callback before we register for the log callback. - // This should be safely ignored. (Not trigger NPE.) - mIWifiChipEventCallback.onDebugErrorAlert( - errorCode, NativeUtil.byteArrayToArrayList(errorData)); - mLooper.dispatchAll(); - - WifiNative.WifiLoggerEventHandler eventHandler = - mock(WifiNative.WifiLoggerEventHandler.class); - assertTrue(mWifiVendorHal.setLoggingEventHandler(eventHandler)); - verify(mIWifiChip).enableDebugErrorAlerts(eq(true)); - - // Now raise the HIDL callback, this should be properly handled. - mIWifiChipEventCallback.onDebugErrorAlert( - errorCode, NativeUtil.byteArrayToArrayList(errorData)); - mLooper.dispatchAll(); - verify(eventHandler).onWifiAlert(eq(errorCode), eq(errorData)); - - // Now stop the logging and invoke the callback. This should be ignored. - reset(eventHandler); - assertTrue(mWifiVendorHal.resetLogHandler()); - mIWifiChipEventCallback.onDebugErrorAlert( - errorCode, NativeUtil.byteArrayToArrayList(errorData)); - mLooper.dispatchAll(); - verify(eventHandler, never()).onWifiAlert(anyInt(), anyObject()); + testAlertCallbackUsingProvidedCallback(mIWifiChipEventCallback); } /** @@ -2066,6 +2071,55 @@ public class WifiVendorHalTest { verify(mHalDeviceManager).removeIface(eq(mIWifiApIface)); } + /** + * Test the callback handling for the 1.2 HAL. + */ + @Test + public void testAlertCallbackUsing_1_2_EventCallback() throws Exception { + // Expose the 1.2 IWifiChip. + mWifiVendorHal = new WifiVendorHalSpyV1_2(mHalDeviceManager, mLooper.getLooper()); + + assertTrue(mWifiVendorHal.startVendorHalSta()); + assertNotNull(mIWifiChipEventCallbackV12); + + testAlertCallbackUsingProvidedCallback(mIWifiChipEventCallbackV12); + } + + private void testAlertCallbackUsingProvidedCallback(IWifiChipEventCallback chipCallback) + throws Exception { + when(mIWifiChip.enableDebugErrorAlerts(anyBoolean())).thenReturn(mWifiStatusSuccess); + when(mIWifiChip.stopLoggingToDebugRingBuffer()).thenReturn(mWifiStatusSuccess); + + int errorCode = 5; + byte[] errorData = new byte[45]; + new Random().nextBytes(errorData); + + // Randomly raise the HIDL callback before we register for the log callback. + // This should be safely ignored. (Not trigger NPE.) + chipCallback.onDebugErrorAlert( + errorCode, NativeUtil.byteArrayToArrayList(errorData)); + mLooper.dispatchAll(); + + WifiNative.WifiLoggerEventHandler eventHandler = + mock(WifiNative.WifiLoggerEventHandler.class); + assertTrue(mWifiVendorHal.setLoggingEventHandler(eventHandler)); + verify(mIWifiChip).enableDebugErrorAlerts(eq(true)); + + // Now raise the HIDL callback, this should be properly handled. + chipCallback.onDebugErrorAlert( + errorCode, NativeUtil.byteArrayToArrayList(errorData)); + mLooper.dispatchAll(); + verify(eventHandler).onWifiAlert(eq(errorCode), eq(errorData)); + + // Now stop the logging and invoke the callback. This should be ignored. + reset(eventHandler); + assertTrue(mWifiVendorHal.resetLogHandler()); + chipCallback.onDebugErrorAlert( + errorCode, NativeUtil.byteArrayToArrayList(errorData)); + mLooper.dispatchAll(); + verify(eventHandler, never()).onWifiAlert(anyInt(), anyObject()); + } + private void startBgScan(WifiNative.ScanEventHandler eventHandler) throws Exception { when(mIWifiStaIface.startBackgroundScan( anyInt(), any(StaBackgroundScanParameters.class))).thenReturn(mWifiStatusSuccess); |