diff options
author | Roshan Pius <rpius@google.com> | 2017-03-28 05:25:25 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-03-28 05:25:25 +0000 |
commit | 96455476082f5680fd0f66eb5a87cd6f2fde1a70 (patch) | |
tree | 6750bebbca86bb86d4e8eeee021a3a5d13bf2e2d /tests | |
parent | 8700fa5b38ce4d9a439936df04058b557bbd4cd1 (diff) | |
parent | cb594dc8e61189be19c56ab03626df045ed90d1a (diff) |
Merge changes from topic 'unused_code'
* changes:
WifiNative: Fixing some nits
Add try/catch blocks for incoming HAL params
WSM: Reconnect on network credential change
WifiStateMachine: Handle vendor HAL death
WifiStateMachine: Remove unused code
Diffstat (limited to 'tests')
4 files changed, 71 insertions, 6 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java index abf533d1f..f2cb90e63 100644 --- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java @@ -501,6 +501,24 @@ public class SupplicantStaIfaceHalTest { } /** + * Tests connection to a specified network failure due to exception in network save. + */ + @Test + public void testConnectFailureDueToNetworkSaveException() throws Exception { + executeAndValidateInitializationSequence(); + setupMocksForConnectSequence(true); + + doThrow(new IllegalArgumentException("Some error!!!")) + .when(mSupplicantStaNetworkMock).saveWifiConfiguration( + any(WifiConfiguration.class)); + + assertFalse(mDut.connectToNetwork(new WifiConfiguration(), false)); + // We should have removed the existing network once before connection and once more + // on failure to save network configuration. + verify(mISupplicantStaIfaceMock, times(2)).removeNetwork(anyInt()); + } + + /** * Tests connection to a specified network failure due to network select. */ @Test @@ -1148,12 +1166,12 @@ public class SupplicantStaIfaceHalTest { .thenReturn(mStatusSuccess); // Fail before initialization is performed. - assertFalse(mDut.setLogLevel(SupplicantStaIfaceHal.LOG_LEVEL_DEBUG)); + assertFalse(mDut.setLogLevel(true)); executeAndValidateInitializationSequence(); // This should work. - assertTrue(mDut.setLogLevel(SupplicantStaIfaceHal.LOG_LEVEL_DEBUG)); + assertTrue(mDut.setLogLevel(true)); verify(mISupplicantMock) .setDebugParams(eq(ISupplicant.DebugLevel.DEBUG), eq(false), eq(false)); } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java index 615f61190..951f8e114 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -1325,6 +1325,7 @@ public class WifiConfigManagerTest { mWifiConfigManager.getConfiguredNetwork(result.getNetworkId()); assertTrue("Updating network non-credentials config should not clear hasEverConnected.", retrievedNetwork.getNetworkSelectionStatus().getHasEverConnected()); + assertFalse(result.hasCredentialChanged()); } /** @@ -3790,6 +3791,7 @@ public class WifiConfigManagerTest { mWifiConfigManager.getConfiguredNetwork(result.getNetworkId()); assertFalse("Updating network credentials config should clear hasEverConnected.", retrievedNetwork.getNetworkSelectionStatus().getHasEverConnected()); + assertTrue(result.hasCredentialChanged()); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index cc8535318..ad441f54d 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -1383,6 +1383,35 @@ public class WifiStateMachineTest { assertFalse("WpsRunningState".equals(getCurrentState().getName())); } + @Test + public void handleVendorHalDeath() throws Exception { + ArgumentCaptor<WifiNative.VendorHalDeathEventHandler> deathHandlerCapturer = + ArgumentCaptor.forClass(WifiNative.VendorHalDeathEventHandler.class); + when(mWifiNative.initializeVendorHal(deathHandlerCapturer.capture())).thenReturn(true); + + // Trigger initialize to capture the death handler registration. + mLooper.startAutoDispatch(); + assertTrue(mWsm.syncInitialize(mWsmAsyncChannel)); + mLooper.stopAutoDispatch(); + + verify(mWifiNative).initializeVendorHal(any(WifiNative.VendorHalDeathEventHandler.class)); + WifiNative.VendorHalDeathEventHandler deathHandler = deathHandlerCapturer.getValue(); + + mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE); + mLooper.dispatchAll(); + + // We should not be in initial state now. + assertFalse("InitialState".equals(getCurrentState().getName())); + + // Now trigger the death notification. + mLooper.startAutoDispatch(); + deathHandler.onDeath(); + mLooper.stopAutoDispatch(); + + // We should back to initial state after vendor HAL death. + assertTrue("InitialState".equals(getCurrentState().getName())); + } + private void setupMocksForWpsNetworkMigration() { int newNetworkId = 5; // Now trigger the network connection event for adding the WPS network. diff --git a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java index 36fe7d2df..4e5594bcc 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java @@ -55,7 +55,7 @@ import android.net.wifi.WifiManager; import android.net.wifi.WifiScanner; import android.net.wifi.WifiSsid; import android.net.wifi.WifiWakeReasonAndCounts; -import android.os.HandlerThread; +import android.os.test.TestLooper; import android.os.RemoteException; import android.util.Pair; @@ -90,7 +90,7 @@ public class WifiVendorHalTest { @Mock private HalDeviceManager mHalDeviceManager; @Mock - private HandlerThread mWifiStateMachineHandlerThread; + private TestLooper mLooper; @Mock private WifiVendorHal.HalDeviceManagerStatusListener mHalDeviceManagerStatusCallbacks; @Mock @@ -103,6 +103,8 @@ public class WifiVendorHalTest { private IWifiRttController mIWifiRttController; private IWifiStaIfaceEventCallback mIWifiStaIfaceEventCallback; private IWifiChipEventCallback mIWifiChipEventCallback; + @Mock + private WifiNative.VendorHalDeathEventHandler mVendorHalDeathHandler; /** * Identity function to supply a type to its argument, which is a lambda @@ -118,6 +120,7 @@ public class WifiVendorHalTest { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); mWifiLog = new FakeWifiLog(); + mLooper = new TestLooper(); mWifiStatusSuccess = new WifiStatus(); mWifiStatusSuccess.code = WifiStatusCode.SUCCESS; mWifiStatusFailure = new WifiStatus(); @@ -169,10 +172,10 @@ public class WifiVendorHalTest { })); // Create the vendor HAL object under test. - mWifiVendorHal = new WifiVendorHal(mHalDeviceManager, mWifiStateMachineHandlerThread); + mWifiVendorHal = new WifiVendorHal(mHalDeviceManager, mLooper.getLooper()); // Initialize the vendor HAL to capture the registered callback. - mWifiVendorHal.initialize(); + mWifiVendorHal.initialize(mVendorHalDeathHandler); ArgumentCaptor<WifiVendorHal.HalDeviceManagerStatusListener> hdmCallbackCaptor = ArgumentCaptor.forClass(WifiVendorHal.HalDeviceManagerStatusListener.class); verify(mHalDeviceManager).registerStatusListener(hdmCallbackCaptor.capture(), any()); @@ -1729,6 +1732,19 @@ public class WifiVendorHalTest { new WifiDebugRingBufferStatus(), NativeUtil.byteArrayToArrayList(errorData)); } + /** + * Test the handling of Vendor HAL death. + */ + @Test + public void testVendorHalDeath() { + // Invoke the HAL device manager status callback with ready set to false to indicate the + // death of the HAL. + when(mHalDeviceManager.isReady()).thenReturn(false); + mHalDeviceManagerStatusCallbacks.onStatusChanged(); + + verify(mVendorHalDeathHandler).onDeath(); + } + private void startBgScan(WifiNative.ScanEventHandler eventHandler) throws Exception { when(mIWifiStaIface.startBackgroundScan( anyInt(), any(StaBackgroundScanParameters.class))).thenReturn(mWifiStatusSuccess); |