summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/WifiApConfigStore.java18
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java23
2 files changed, 35 insertions, 6 deletions
diff --git a/service/java/com/android/server/wifi/WifiApConfigStore.java b/service/java/com/android/server/wifi/WifiApConfigStore.java
index 4233f5834..850c5aebe 100644
--- a/service/java/com/android/server/wifi/WifiApConfigStore.java
+++ b/service/java/com/android/server/wifi/WifiApConfigStore.java
@@ -203,8 +203,24 @@ public class WifiApConfigStore {
return config;
}
- private int getRandomIntForDefaultSsid() {
+ private static int getRandomIntForDefaultSsid() {
Random random = new Random();
return random.nextInt((RAND_SSID_INT_MAX - RAND_SSID_INT_MIN) + 1) + RAND_SSID_INT_MIN;
}
+
+ /**
+ * Generate a temporary WPA2 based configuration for use by the local only hotspot.
+ * This config is not persisted and will not be stored by the WifiApConfigStore.
+ */
+ public static WifiConfiguration generateLocalOnlyHotspotConfig(Context context) {
+ WifiConfiguration config = new WifiConfiguration();
+ config.SSID = context.getResources().getString(
+ R.string.wifi_localhotspot_configure_ssid_default) + "_"
+ + getRandomIntForDefaultSsid();
+ config.allowedKeyManagement.set(KeyMgmt.WPA2_PSK);
+ String randomUUID = UUID.randomUUID().toString();
+ // first 12 chars from xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
+ config.preSharedKey = randomUUID.substring(0, 8) + randomUUID.substring(9, 13);
+ return config;
+ }
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
index 42161fa54..d4a3ff549 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
@@ -49,6 +49,7 @@ public class WifiApConfigStoreTest {
private static final String TEST_DEFAULT_2G_CHANNEL_LIST = "1,2,3,4,5,6";
private static final String TEST_DEFAULT_AP_SSID = "TestAP";
private static final String TEST_CONFIGURED_AP_SSID = "ConfiguredAP";
+ private static final String TEST_DEFAULT_HOTSPOT_SSID = "TestShare";
private static final int RAND_SSID_INT_MIN = 1000;
private static final int RAND_SSID_INT_MAX = 9999;
@@ -69,6 +70,8 @@ public class WifiApConfigStoreTest {
TEST_DEFAULT_2G_CHANNEL_LIST);
resources.setString(R.string.wifi_tether_configure_ssid_default,
TEST_DEFAULT_AP_SSID);
+ resources.setString(R.string.wifi_localhotspot_configure_ssid_default,
+ TEST_DEFAULT_HOTSPOT_SSID);
when(mContext.getResources()).thenReturn(resources);
}
@@ -107,10 +110,10 @@ public class WifiApConfigStoreTest {
assertEquals(config1.apChannel, config2.apChannel);
}
- private void verifyDefaultApConfig(WifiConfiguration config) {
+ private void verifyDefaultApConfig(WifiConfiguration config, String expectedSsid) {
String[] splitSsid = config.SSID.split("_");
assertEquals(2, splitSsid.length);
- assertEquals(TEST_DEFAULT_AP_SSID, splitSsid[0]);
+ assertEquals(expectedSsid, splitSsid[0]);
int randomPortion = Integer.parseInt(splitSsid[1]);
assertTrue(randomPortion >= RAND_SSID_INT_MIN && randomPortion <= RAND_SSID_INT_MAX);
assertTrue(config.allowedKeyManagement.get(KeyMgmt.WPA2_PSK));
@@ -124,7 +127,7 @@ public class WifiApConfigStoreTest {
public void initWithDefaultConfiguration() throws Exception {
WifiApConfigStore store = new WifiApConfigStore(
mContext, mBackupManagerProxy, mApConfigFile.getPath());
- verifyDefaultApConfig(store.getApConfiguration());
+ verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID);
}
/**
@@ -165,7 +168,7 @@ public class WifiApConfigStoreTest {
verifyApConfig(expectedConfig, store.getApConfiguration());
store.setApConfiguration(null);
- verifyDefaultApConfig(store.getApConfiguration());
+ verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID);
verify(mBackupManagerProxy).notifyDataChanged();
}
@@ -177,7 +180,7 @@ public class WifiApConfigStoreTest {
/* Initialize WifiApConfigStore with default configuration. */
WifiApConfigStore store = new WifiApConfigStore(
mContext, mBackupManagerProxy, mApConfigFile.getPath());
- verifyDefaultApConfig(store.getApConfiguration());
+ verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID);
/* Update with a valid configuration. */
WifiConfiguration expectedConfig = setupApConfig(
@@ -190,4 +193,14 @@ public class WifiApConfigStoreTest {
verifyApConfig(expectedConfig, store.getApConfiguration());
verify(mBackupManagerProxy).notifyDataChanged();
}
+
+ /**
+ * Verify a proper local only hotspot config is generated when called properly with the valid
+ * context.
+ */
+ @Test
+ public void generateLocalOnlyHotspotConfigIsValid() {
+ WifiConfiguration config = WifiApConfigStore.generateLocalOnlyHotspotConfig(mContext);
+ verifyDefaultApConfig(config, TEST_DEFAULT_HOTSPOT_SSID);
+ }
}