diff options
author | Xianyuan Jia <xianyuanjia@google.com> | 2022-01-13 18:07:46 -0800 |
---|---|---|
committer | Xianyuan Jia <xianyuanjia@google.com> | 2022-01-13 18:14:02 -0800 |
commit | 6e2742bd6dbb58346cac585d72e18681a8feec25 (patch) | |
tree | 061dee143c80a4ecaead9c5325fe60d402acf9b9 | |
parent | e0fdbaa2de253753fdd6dce00a28f4de34053579 (diff) | |
download | mobly-bundled-snippets-6e2742bd6dbb58346cac585d72e18681a8feec25.tar.gz |
Compile removeNetwork failures as a list. Add explanation for new strategy.
-rw-r--r-- | src/main/java/com/google/android/mobly/snippet/bundled/WifiManagerSnippet.java | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/WifiManagerSnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/WifiManagerSnippet.java index 0c415a9..7e1a416 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/WifiManagerSnippet.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/WifiManagerSnippet.java @@ -78,15 +78,25 @@ public class WifiManagerSnippet implements Snippet { + "networks were added through this MBS instance") public void wifiClearConfiguredNetworks() throws WifiManagerSnippetException { List<WifiConfiguration> unremovedConfigs = mWifiManager.getConfiguredNetworks(); + List<WifiConfiguration> failedConfigs = new ArrayList<>(); if (unremovedConfigs == null) { throw new WifiManagerSnippetException( "Failed to get a list of configured networks. Is wifi disabled?"); } for (WifiConfiguration config : unremovedConfigs) { if (!mWifiManager.removeNetwork(config.networkId)) { - Log.e("Encountered error while removing network: " + config); + failedConfigs.add(config); } } + + // If removeNetwork is called on a network with both an open and OWE config, it will remove + // both. The subsequent call on the same network will fail. The clear operation may succeed + // even if failures appear in the log below. + if (!failedConfigs.isEmpty()) { + Log.e("Encountered error while removing networks: " + failedConfigs); + } + + // Re-check configured configs list to ensure that it is cleared unremovedConfigs = mWifiManager.getConfiguredNetworks(); if (!unremovedConfigs.isEmpty()) { throw new WifiManagerSnippetException("Failed to remove networks: " + unremovedConfigs); |