From 45448ffb610477fc7ac2406c33276f461288bb91 Mon Sep 17 00:00:00 2001 From: xshu Date: Tue, 12 Nov 2019 13:46:10 -0800 Subject: MAC randomization SSID hotlist support Reads from DeviceConfig and parses a comma separated of SSIDs. Bug: 144172117 Test: atest FrameworksWifiTests Test: Manually tested on device Change-Id: I53b15e884ecba377277eac81f9e3ca86474f5c13 Merged-In: Ie42ce853810aa5dfd4eef89dff281740dafaf3be (cherry picked from a522b345fa15716a21fd9edcf523cf3c1331dd94) --- .../android/server/wifi/DeviceConfigFacade.java | 21 +++++++++++++++++ .../com/android/server/wifi/WifiConfigManager.java | 26 +++++++++++++++++++++- .../java/com/android/server/wifi/WifiInjector.java | 2 +- 3 files changed, 47 insertions(+), 2 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/DeviceConfigFacade.java b/service/java/com/android/server/wifi/DeviceConfigFacade.java index a9889f424..25cc2f72d 100644 --- a/service/java/com/android/server/wifi/DeviceConfigFacade.java +++ b/service/java/com/android/server/wifi/DeviceConfigFacade.java @@ -17,7 +17,9 @@ package com.android.server.wifi; import android.provider.DeviceConfig; +import android.util.ArraySet; +import java.util.Set; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; @@ -105,4 +107,23 @@ public class DeviceConfigFacade { return DeviceConfig.getInt(NAMESPACE, "data_stall_cca_level_thr", DEFAULT_DATA_STALL_CCA_LEVEL_THR); } + + /** + * Gets the Set of SSIDs in the flaky SSID hotlist. + */ + public Set getRandomizationFlakySsidHotlist() { + String ssidHotlist = DeviceConfig.getString(NAMESPACE, + "randomization_flaky_ssid_hotlist", ""); + Set result = new ArraySet(); + String[] ssidHotlistArray = ssidHotlist.split(","); + for (int i = 0; i < ssidHotlistArray.length; i++) { + String cur = ssidHotlistArray[i]; + if (cur.length() == 0) { + continue; + } + // Make sure the SSIDs are quoted. Server side should not quote ssids. + result.add("\"" + cur + "\""); + } + return result; + } } diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java index a246a86f7..80b583feb 100644 --- a/service/java/com/android/server/wifi/WifiConfigManager.java +++ b/service/java/com/android/server/wifi/WifiConfigManager.java @@ -321,6 +321,7 @@ public class WifiConfigManager { private final int mMaxNumActiveChannelsForPartialScans; private final FrameworkFacade mFrameworkFacade; + private final DeviceConfigFacade mDeviceConfigFacade; /** * Verbose logging flag. Toggled by developer options. @@ -378,6 +379,7 @@ public class WifiConfigManager { private boolean mPnoFrequencyCullingEnabled = false; private boolean mPnoRecencySortingEnabled = false; + private Set mRandomizationFlakySsidHotlist; @@ -395,7 +397,8 @@ public class WifiConfigManager { NetworkListUserStoreData networkListUserStoreData, DeletedEphemeralSsidsStoreData deletedEphemeralSsidsStoreData, RandomizedMacStoreData randomizedMacStoreData, - FrameworkFacade frameworkFacade, Looper looper) { + FrameworkFacade frameworkFacade, Looper looper, + DeviceConfigFacade deviceConfigFacade) { mContext = context; mClock = clock; mUserManager = userManager; @@ -447,6 +450,14 @@ public class WifiConfigManager { updatePnoRecencySortingSetting(); mConnectedMacRandomzationSupported = mContext.getResources() .getBoolean(R.bool.config_wifi_connected_mac_randomization_supported); + mDeviceConfigFacade = deviceConfigFacade; + mDeviceConfigFacade.addOnPropertiesChangedListener( + command -> new Handler(looper).post(command), + properties -> { + mRandomizationFlakySsidHotlist = + mDeviceConfigFacade.getRandomizationFlakySsidHotlist(); + }); + mRandomizationFlakySsidHotlist = mDeviceConfigFacade.getRandomizationFlakySsidHotlist(); try { mSystemUiUid = mContext.getPackageManager().getPackageUidAsUser(SYSUI_PACKAGE_NAME, PackageManager.MATCH_SYSTEM_ONLY, UserHandle.USER_SYSTEM); @@ -1521,6 +1532,19 @@ public class WifiConfigManager { return false; } + /** + * Check whether a network belong to a known list of networks that may not support randomized + * MAC. + * @param networkId + * @return true if the network is in the hotlist and MAC randomization is enabled. + */ + public boolean isInFlakyRandomizationSsidHotlist(int networkId) { + WifiConfiguration config = getConfiguredNetwork(networkId); + return config != null + && config.macRandomizationSetting == WifiConfiguration.RANDOMIZATION_PERSISTENT + && mRandomizationFlakySsidHotlist.contains(config.SSID); + } + /** * Helper method to mark a network enabled for network selection. */ diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index 83ae89cdc..af8c14764 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -253,7 +253,7 @@ public class WifiInjector { mWifiPermissionsWrapper, this, new NetworkListSharedStoreData(mContext), new NetworkListUserStoreData(mContext), new DeletedEphemeralSsidsStoreData(mClock), new RandomizedMacStoreData(), - mFrameworkFacade, mWifiCoreHandlerThread.getLooper()); + mFrameworkFacade, mWifiCoreHandlerThread.getLooper(), mDeviceConfigFacade); mWifiMetrics.setWifiConfigManager(mWifiConfigManager); mWifiConnectivityHelper = new WifiConnectivityHelper(mWifiNative); mConnectivityLocalLog = new LocalLog(ActivityManager.isLowRamDeviceStatic() ? 256 : 512); -- cgit v1.2.3