From 1e5c1abdeb4e3e180e5344c777f7a7db2095c246 Mon Sep 17 00:00:00 2001 From: Rebecca Silberstein Date: Sat, 25 Mar 2017 17:02:03 -0700 Subject: WifiApConfigStore: create temp sharing AP config Create a temporary config for use by local only hotspot. These configs are generated by the WifiApConfigStore, but will not be stored. Bug: 36704784 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Change-Id: I3470708a274e97f6e4a752ea1863cfa86bfbf8b6 --- .../com/android/server/wifi/WifiApConfigStore.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'service') 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; + } } -- cgit v1.2.3