From 6e2b9d32ef0c5e2786e2bde97fa7fe117916a37b Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Mon, 2 Mar 2020 11:56:55 -0800 Subject: [PATCH] WifiManagerTest: Add CTS tests for factory reset Bug: 150236894 Test: atest android.net.wifi.cts.WifiManagerTest Change-Id: I0abaf771f2016398eea104b8ff0a9e7a8ca5017e --- .../android/net/wifi/cts/WifiManagerTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java b/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java index 25ce7be6e0..98f3d44e68 100644 --- a/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java +++ b/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java @@ -1473,4 +1473,34 @@ public class WifiManagerTest extends AndroidTestCase { uiAutomation.dropShellPermissionIdentity(); } } + + /** + * Tests {@link WifiManager#factoryReset()}. + * + * Note: This test assumes that the device only has 1 or more saved networks before the test. + * The test will restore those when the test exits. But, it does not restore the softap + * configuration, suggestions, etc which will also have been lost on factory reset. + */ + public void testFactoryReset() throws Exception { + UiAutomation uiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation(); + List savedNetworks = null; + try { + uiAutomation.adoptShellPermissionIdentity(); + // These below API's only work with privileged permissions (obtained via shell identity + // for test) + savedNetworks = mWifiManager.getConfiguredNetworks(); + + mWifiManager.factoryReset(); + // Ensure all the saved networks are removed. + assertEquals(0, mWifiManager.getConfiguredNetworks().size()); + } finally { + // Restore the original saved networks. + if (savedNetworks != null) { + for (WifiConfiguration network : savedNetworks) { + mWifiManager.save(network, null); + } + } + uiAutomation.dropShellPermissionIdentity(); + } + } }