summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Plass <mplass@google.com>2019-10-17 16:42:23 -0700
committerMichael Plass <mplass@google.com>2019-10-23 11:17:05 -0700
commit1a39096a4adc17abd6e9301ad9e01587a10d0412 (patch)
treed4042210eac754bae0cb0c3d889cc57465472e9a
parent2b675f5fc532687617bd8d29474657cab35285a0 (diff)
[WifiServiceImplTest] OK to not dispatch any messages
Use stopAutoDispatchAndIgnoreExceptions in TestWifiServiceImpl to stop auto dispatch. When we are already on the right thread, runWithScissors does not post anything. This is the case when running the tests with the coverage script. Bug: 142149650 Test: frameworks/opt/net/wifi/tests/wifitests/coverage.sh /tmp/cov Test: atest FrameworksWifiTests Change-Id: Ib357460154c92a68b5bd7b563d9a1077236a9096
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java78
1 files changed, 39 insertions, 39 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index d53228fde..89cb900d0 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -424,7 +424,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
mLooper.startAutoDispatch();
boolean succeeded = mWifiServiceImpl.removeNetwork(0, TEST_PACKAGE_NAME);
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
assertFalse(succeeded);
}
@@ -449,7 +449,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
public void testDumpNullArgs() {
mLooper.startAutoDispatch();
mWifiServiceImpl.dump(new FileDescriptor(), new PrintWriter(new StringWriter()), null);
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
}
/**
@@ -470,7 +470,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
public void testWifiScoreReportDump() {
mLooper.startAutoDispatch();
mWifiServiceImpl.dump(new FileDescriptor(), new PrintWriter(new StringWriter()), null);
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
InOrder inOrder = inOrder(mClientModeImpl, mWifiScoreReport);
@@ -991,7 +991,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
mLooper.startAutoDispatch();
assertEquals(apConfig, mWifiServiceImpl.getWifiApConfiguration());
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
}
/**
@@ -1195,7 +1195,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
mLooper.startAutoDispatch();
assertFalse(mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verify(mScanRequestProxy).startScan(Binder.getCallingUid(), SCAN_PACKAGE_NAME);
}
@@ -1319,7 +1319,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
mLooper.startAutoDispatch();
ParceledListSlice<WifiConfiguration> configs =
mWifiServiceImpl.getConfiguredNetworks(TEST_PACKAGE);
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verify(mWifiConfigManager).getSavedNetworks(eq(Process.WIFI_UID));
WifiConfigurationTestUtil.assertConfigurationsEqualForBackup(
@@ -1379,7 +1379,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
mLooper.startAutoDispatch();
ParceledListSlice<WifiConfiguration> configs =
mWifiServiceImpl.getPrivilegedConfiguredNetworks(TEST_PACKAGE);
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
WifiConfigurationTestUtil.assertConfigurationsEqualForBackup(
TEST_WIFI_CONFIGURATION_LIST, configs.getList());
@@ -1400,7 +1400,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
String packageName = "test.com";
mLooper.startAutoDispatch();
List<ScanResult> retrievedScanResultList = mWifiServiceImpl.getScanResults(packageName);
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verify(mScanRequestProxy).getScanResults();
ScanTestUtil.assertScanResultsEquals(scanResults,
@@ -2403,7 +2403,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
.thenReturn(true);
mLooper.startAutoDispatch();
assertEquals(0, mWifiServiceImpl.addOrUpdateNetwork(config, TEST_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verifyCheckChangePermission(TEST_PACKAGE_NAME);
verify(mPasspointManager).addOrUpdateProvider(
any(PasspointConfiguration.class), anyInt(), eq(TEST_PACKAGE_NAME), eq(false));
@@ -2414,7 +2414,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
.thenReturn(false);
mLooper.startAutoDispatch();
assertEquals(-1, mWifiServiceImpl.addOrUpdateNetwork(config, TEST_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verifyCheckChangePermission(TEST_PACKAGE_NAME);
verify(mPasspointManager).addOrUpdateProvider(
any(PasspointConfiguration.class), anyInt(), eq(TEST_PACKAGE_NAME), anyBoolean());
@@ -2523,7 +2523,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
mLooper.startAutoDispatch();
mWifiServiceImpl.getPasspointConfigurations(TEST_PACKAGE_NAME);
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verify(mPasspointManager).getProviderConfigs(Binder.getCallingUid(), false);
}
@@ -2537,7 +2537,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
mLooper.startAutoDispatch();
mWifiServiceImpl.getPasspointConfigurations(TEST_PACKAGE_NAME);
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verify(mPasspointManager).getProviderConfigs(Binder.getCallingUid(), true);
}
@@ -2561,14 +2561,14 @@ public class WifiServiceImplTest extends WifiBaseTest {
.thenReturn(expectedConfigs);
mLooper.startAutoDispatch();
assertEquals(expectedConfigs, mWifiServiceImpl.getPasspointConfigurations(TEST_PACKAGE));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
reset(mPasspointManager);
when(mPasspointManager.getProviderConfigs(anyInt(), anyBoolean()))
.thenReturn(new ArrayList<PasspointConfiguration>());
mLooper.startAutoDispatch();
assertTrue(mWifiServiceImpl.getPasspointConfigurations(TEST_PACKAGE).isEmpty());
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
}
/**
@@ -2583,7 +2583,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
mLooper.startAutoDispatch();
mWifiServiceImpl.removePasspointConfiguration(TEST_FQDN, TEST_PACKAGE_NAME);
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verify(mPasspointManager).removeProvider(Binder.getCallingUid(), false, TEST_FQDN);
}
@@ -2598,7 +2598,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
mLooper.startAutoDispatch();
mWifiServiceImpl.removePasspointConfiguration(TEST_FQDN, TEST_PACKAGE_NAME);
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verify(mPasspointManager).removeProvider(Binder.getCallingUid(), true, TEST_FQDN);
}
@@ -2833,7 +2833,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
// immediately.
mLooper.startAutoDispatch();
assertTrue(mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verify(mScanRequestProxy).startScan(Process.myUid(), SCAN_PACKAGE_NAME);
}
@@ -3286,7 +3286,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
mLooper.startAutoDispatch();
mWifiServiceImpl.factoryReset(TEST_PACKAGE_NAME);
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
// Let the final post inside the |factoryReset| method run to completion.
mLooper.dispatchAll();
@@ -3354,7 +3354,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
mLooper.startAutoDispatch();
assertEquals(0, mWifiServiceImpl.addOrUpdateNetwork(config, TEST_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verifyCheckChangePermission(TEST_PACKAGE_NAME);
verify(mWifiConfigManager).addOrUpdateNetwork(any(), anyInt(), any());
@@ -3375,7 +3375,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
mLooper.startAutoDispatch();
assertEquals(0, mWifiServiceImpl.addOrUpdateNetwork(config, TEST_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
// Ensure that we don't check for change permission.
verify(mContext, never()).enforceCallingOrSelfPermission(
@@ -3400,7 +3400,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
mLooper.startAutoDispatch();
assertEquals(0, mWifiServiceImpl.addOrUpdateNetwork(config, TEST_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verifyCheckChangePermission(TEST_PACKAGE_NAME);
verify(mWifiConfigManager).addOrUpdateNetwork(any(), anyInt(), any());
@@ -3423,7 +3423,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
mLooper.startAutoDispatch();
assertEquals(0, mWifiServiceImpl.addOrUpdateNetwork(config, TEST_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verifyCheckChangePermission(TEST_PACKAGE_NAME);
verify(mWifiPermissionsUtil).checkSystemAlertWindowPermission(anyInt(), anyString());
@@ -3446,7 +3446,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
mLooper.startAutoDispatch();
assertEquals(0, mWifiServiceImpl.addOrUpdateNetwork(config, TEST_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verifyCheckChangePermission(TEST_PACKAGE_NAME);
verify(mWifiConfigManager).addOrUpdateNetwork(any(), anyInt(), any());
@@ -3468,7 +3468,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
mLooper.startAutoDispatch();
assertEquals(0, mWifiServiceImpl.addOrUpdateNetwork(config, TEST_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verifyCheckChangePermission(TEST_PACKAGE_NAME);
verify(mWifiConfigManager).addOrUpdateNetwork(any(), anyInt(), any());
@@ -3549,7 +3549,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
.thenReturn(true);
mLooper.startAutoDispatch();
assertTrue(mWifiServiceImpl.enableNetwork(TEST_NETWORK_ID, false, TEST_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verify(mWifiConfigManager).enableNetwork(eq(TEST_NETWORK_ID), eq(false),
eq(Binder.getCallingUid()), eq(TEST_PACKAGE_NAME));
verify(mWifiMetrics).incrementNumEnableNetworkCalls();
@@ -3581,14 +3581,14 @@ public class WifiServiceImplTest extends WifiBaseTest {
mLooper.startAutoDispatch();
assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
mWifiServiceImpl.addNetworkSuggestions(mock(List.class), TEST_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
when(mWifiNetworkSuggestionsManager.add(any(), anyInt(), anyString()))
.thenReturn(WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE);
mLooper.startAutoDispatch();
assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE,
mWifiServiceImpl.addNetworkSuggestions(mock(List.class), TEST_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verify(mWifiNetworkSuggestionsManager, times(2)).add(
any(), eq(Binder.getCallingUid()), eq(TEST_PACKAGE_NAME));
@@ -3622,14 +3622,14 @@ public class WifiServiceImplTest extends WifiBaseTest {
mLooper.startAutoDispatch();
assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID,
mWifiServiceImpl.removeNetworkSuggestions(mock(List.class), TEST_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
when(mWifiNetworkSuggestionsManager.remove(any(), anyInt(), anyString()))
.thenReturn(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS);
mLooper.startAutoDispatch();
assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
mWifiServiceImpl.removeNetworkSuggestions(mock(List.class), TEST_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verify(mWifiNetworkSuggestionsManager, times(2)).remove(any(), anyInt(),
eq(TEST_PACKAGE_NAME));
@@ -3662,7 +3662,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
when(mWifiNetworkSuggestionsManager.get(anyString())).thenReturn(testList);
mLooper.startAutoDispatch();
assertEquals(testList, mWifiServiceImpl.getNetworkSuggestions(TEST_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verify(mWifiNetworkSuggestionsManager).get(eq(TEST_PACKAGE_NAME));
}
@@ -3717,7 +3717,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(true);
mLooper.startAutoDispatch();
final String[] factoryMacs = mWifiServiceImpl.getFactoryMacAddresses();
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
assertEquals(1, factoryMacs.length);
assertEquals(TEST_FACTORY_MAC, factoryMacs[0]);
verify(mClientModeImpl).getFactoryMacAddress();
@@ -3747,7 +3747,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(true);
mLooper.startAutoDispatch();
assertNull(mWifiServiceImpl.getFactoryMacAddresses());
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
verify(mClientModeImpl).getFactoryMacAddress();
}
@@ -3762,7 +3762,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
try {
mLooper.startAutoDispatch();
mWifiServiceImpl.getFactoryMacAddresses();
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
fail();
} catch (SecurityException e) {
assertTrue("Exception message should contain 'factory MAC'",
@@ -3992,7 +3992,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
mLooper.startAutoDispatch();
boolean result = mWifiServiceImpl.removeNetwork(0, TEST_PACKAGE_NAME);
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
assertTrue(result);
verify(mWifiConfigManager).removeNetwork(anyInt(), anyInt(), anyString());
@@ -4014,7 +4014,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
.thenReturn(true);
mLooper.startAutoDispatch();
assertTrue(mWifiServiceImpl.addOrUpdatePasspointConfiguration(config, TEST_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
reset(mPasspointManager);
when(mPasspointManager.addOrUpdateProvider(
@@ -4022,7 +4022,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
.thenReturn(false);
mLooper.startAutoDispatch();
assertFalse(mWifiServiceImpl.addOrUpdatePasspointConfiguration(config, TEST_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
}
/**
* Verify that removePasspointConfiguration will redirect calls to {@link PasspointManager}
@@ -4036,13 +4036,13 @@ public class WifiServiceImplTest extends WifiBaseTest {
when(mPasspointManager.removeProvider(anyInt(), anyBoolean(), eq(fqdn))).thenReturn(true);
mLooper.startAutoDispatch();
assertTrue(mWifiServiceImpl.removePasspointConfiguration(fqdn, TEST_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
reset(mPasspointManager);
when(mPasspointManager.removeProvider(anyInt(), anyBoolean(), eq(fqdn))).thenReturn(false);
mLooper.startAutoDispatch();
assertFalse(mWifiServiceImpl.removePasspointConfiguration(fqdn, TEST_PACKAGE_NAME));
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
}
/**
@@ -4059,7 +4059,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
mLooper.startAutoDispatch();
boolean succeeded = mWifiServiceImpl.disableNetwork(0, TEST_PACKAGE_NAME);
- mLooper.stopAutoDispatch();
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
assertFalse(succeeded);
}