summaryrefslogtreecommitdiffstats
path: root/tests/wifitests
diff options
context:
space:
mode:
authorxshu <xshu@google.com>2020-01-14 12:12:22 -0800
committerxshu <xshu@google.com>2020-01-14 16:01:24 -0800
commit0b3eca3c05190e5824638f3da25b8b3167dc9d60 (patch)
tree292ebd3e7bee6ce56048cb05cbea9f4d66f29cf0 /tests/wifitests
parent221cd9e93b94def60aa4a5adbdd3bfa91502bdc8 (diff)
downloadandroid_frameworks_opt_net_wifi-0b3eca3c05190e5824638f3da25b8b3167dc9d60.tar.gz
android_frameworks_opt_net_wifi-0b3eca3c05190e5824638f3da25b8b3167dc9d60.tar.bz2
android_frameworks_opt_net_wifi-0b3eca3c05190e5824638f3da25b8b3167dc9d60.zip
fix soft reboot caused by KeyStore exception
The Mac handle obtained from AndroidKeyStore is sometimes invalidated by the AndroidKeyStore based on some LRU technique. This change make sure that we always get a valid handle. And adds exception handling to make sure a crash will not happen for the same reason again. If KeyStore continuously fails to generate MAC address, we will use locally generated MAC as it is the next best option. Bug: 146203882 Test: atest FrameworksWifiTests Merged-In: I8a3b810ba95898a96d81fe57979db4787e1a46c4 Change-Id: I8a3b810ba95898a96d81fe57979db4787e1a46c4 (cherry-picked from e299359a6e6e9e13217862f7f66627eccbff46ce)
Diffstat (limited to 'tests/wifitests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/MacAddressUtilTest.java15
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java24
2 files changed, 34 insertions, 5 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/MacAddressUtilTest.java b/tests/wifitests/src/com/android/server/wifi/MacAddressUtilTest.java
index 253310840..7e598db31 100644
--- a/tests/wifitests/src/com/android/server/wifi/MacAddressUtilTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/MacAddressUtilTest.java
@@ -29,6 +29,7 @@ import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import java.security.ProviderException;
import java.util.Random;
import javax.crypto.Mac;
@@ -69,4 +70,18 @@ public class MacAddressUtilTest {
assertTrue(WifiConfiguration.isValidMacAddressForRandomization(macAddress));
}
}
+
+ /**
+ * Verify the java.security.ProviderException is caught.
+ */
+ @Test
+ public void testCalculatePersistentMacCatchesException() {
+ when(mMac.doFinal(any())).thenThrow(new ProviderException("error occurred"));
+ try {
+ WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
+ assertNull(mMacAddressUtil.calculatePersistentMacForConfiguration(config, mMac));
+ } catch (Exception e) {
+ fail("Exception not caught.");
+ }
+ }
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index 23eea328f..6fa1868cb 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -303,13 +303,27 @@ public class WifiConfigManagerTest {
}
/**
- * Verifies that the Mac randomization secret hashfunction is obtained after |loadFromStore|.
+ * Verify that a randomized MAC address is generated even if the KeyStore operation fails.
*/
@Test
- public void testMacHashIsObtainedAfterLoadFromStore() {
- verify(mMacAddressUtil, never()).obtainMacRandHashFunction(anyInt());
- assertTrue(mWifiConfigManager.loadFromStore());
- verify(mMacAddressUtil).obtainMacRandHashFunction(anyInt());
+ public void testRandomizedMacIsGeneratedEvenIfKeyStoreFails() {
+ when(mMacAddressUtil.calculatePersistentMacForConfiguration(any(), any())).thenReturn(null);
+
+ // Try adding a network.
+ WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork();
+ List<WifiConfiguration> networks = new ArrayList<>();
+ networks.add(openNetwork);
+ verifyAddNetworkToWifiConfigManager(openNetwork);
+ List<WifiConfiguration> retrievedNetworks =
+ mWifiConfigManager.getConfiguredNetworksWithPasswords();
+
+ // Verify that we have attempted to generate the MAC address twice (1 retry)
+ verify(mMacAddressUtil, times(2)).calculatePersistentMacForConfiguration(any(), any());
+ assertEquals(1, retrievedNetworks.size());
+
+ // Verify that despite KeyStore returning null, we are still getting a valid MAC address.
+ assertNotEquals(WifiInfo.DEFAULT_MAC_ADDRESS,
+ retrievedNetworks.get(0).getRandomizedMacAddress().toString());
}
/**