diff options
author | Oscar Shu <xshu@google.com> | 2019-01-22 17:53:16 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-01-22 17:53:16 +0000 |
commit | 702d93dab2851d0418ce233b35672fa2b4d7361c (patch) | |
tree | 53f8af4663c4a73ab42fff502ca6668c83ad33f2 /service/java/com/android/server/wifi/WifiConfigManager.java | |
parent | cc7a0e4d7a2427db4a8bd9473ba361748547b0d1 (diff) | |
parent | 44135417f89f8fc0bb593f184659f7a382771bf2 (diff) | |
download | android_frameworks_opt_net_wifi-702d93dab2851d0418ce233b35672fa2b4d7361c.tar.gz android_frameworks_opt_net_wifi-702d93dab2851d0418ce233b35672fa2b4d7361c.tar.bz2 android_frameworks_opt_net_wifi-702d93dab2851d0418ce233b35672fa2b4d7361c.zip |
Merge "Persist randomized MAC over forget network"
Diffstat (limited to 'service/java/com/android/server/wifi/WifiConfigManager.java')
-rw-r--r-- | service/java/com/android/server/wifi/WifiConfigManager.java | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java index a17c8c908..bd5ffe905 100644 --- a/service/java/com/android/server/wifi/WifiConfigManager.java +++ b/service/java/com/android/server/wifi/WifiConfigManager.java @@ -283,6 +283,14 @@ public class WifiConfigManager { * The SSIDs are encoded in a String as per definition of WifiConfiguration.SSID field. */ private final Set<String> mDeletedEphemeralSSIDs; + + /** + * Framework keeps a mapping from configKey to the randomized MAC address so that + * when a user forgets a network and thne adds it back, the same randomized MAC address + * will get used. + */ + private final Map<String, String> mRandomizedMacAddressMapping; + /** * Flag to indicate if only networks with the same psk should be linked. * TODO(b/30706406): Remove this flag if unused. @@ -348,6 +356,7 @@ public class WifiConfigManager { private final NetworkListSharedStoreData mNetworkListSharedStoreData; private final NetworkListUserStoreData mNetworkListUserStoreData; private final DeletedEphemeralSsidsStoreData mDeletedEphemeralSsidsStoreData; + private final RandomizedMacStoreData mRandomizedMacStoreData; // Store the saved network update listener. private OnSavedNetworkUpdateListener mListener = null; @@ -369,6 +378,7 @@ public class WifiConfigManager { NetworkListSharedStoreData networkListSharedStoreData, NetworkListUserStoreData networkListUserStoreData, DeletedEphemeralSsidsStoreData deletedEphemeralSsidsStoreData, + RandomizedMacStoreData randomizedMacStoreData, FrameworkFacade frameworkFacade, Looper looper) { mContext = context; mClock = clock; @@ -384,14 +394,17 @@ public class WifiConfigManager { mConfiguredNetworks = new ConfigurationMap(userManager); mScanDetailCaches = new HashMap<>(16, 0.75f); mDeletedEphemeralSSIDs = new HashSet<>(); + mRandomizedMacAddressMapping = new HashMap<>(); // Register store data for network list and deleted ephemeral SSIDs. mNetworkListSharedStoreData = networkListSharedStoreData; mNetworkListUserStoreData = networkListUserStoreData; mDeletedEphemeralSsidsStoreData = deletedEphemeralSsidsStoreData; + mRandomizedMacStoreData = randomizedMacStoreData; mWifiConfigStore.registerStoreData(mNetworkListSharedStoreData); mWifiConfigStore.registerStoreData(mNetworkListUserStoreData); mWifiConfigStore.registerStoreData(mDeletedEphemeralSsidsStoreData); + mWifiConfigStore.registerStoreData(mRandomizedMacStoreData); mOnlyLinkSameCredentialConfigurations = mContext.getResources().getBoolean( R.bool.config_wifi_only_link_same_credential_configurations); @@ -1025,11 +1038,37 @@ public class WifiConfigManager { mContext.getPackageManager().getNameForUid(uid); newInternalConfig.creationTime = newInternalConfig.updateTime = createDebugTimeStampString(mClock.getWallClockMillis()); + updateRandomizedMacAddress(newInternalConfig); return newInternalConfig; } /** + * Sets the randomized address for the given configuration from stored map if it exist. + * Otherwise generates a new randomized address and save to the stored map. + * @param config + */ + private void updateRandomizedMacAddress(WifiConfiguration config) { + // Update randomized MAC address according to stored map + final String key = config.configKey(); + // If the key is not found in the current store, then it means this network has never been + // seen before. So add it to store. + if (!mRandomizedMacAddressMapping.containsKey(key)) { + mRandomizedMacAddressMapping.put(key, + config.getOrCreateRandomizedMacAddress().toString()); + } else { // Otherwise read from the store and set the WifiConfiguration + try { + config.setRandomizedMacAddress( + MacAddress.fromString(mRandomizedMacAddressMapping.get(key))); + } catch (IllegalArgumentException e) { + Log.e(TAG, "Error creating randomized MAC address from stored value."); + mRandomizedMacAddressMapping.put(key, + config.getOrCreateRandomizedMacAddress().toString()); + } + } + } + + /** * Create a new internal WifiConfiguration object by copying over parameters from the provided * external configuration to a copy of the existing internal WifiConfiguration object. * @@ -2818,6 +2857,7 @@ public class WifiConfigManager { localLog("clearInternalData: Clearing all internal data"); mConfiguredNetworks.clear(); mDeletedEphemeralSSIDs.clear(); + mRandomizedMacAddressMapping.clear(); mScanDetailCaches.clear(); clearLastSelectedNetwork(); } @@ -2860,7 +2900,8 @@ public class WifiConfigManager { * @param configurations list of configurations retrieved from store. */ private void loadInternalDataFromSharedStore( - List<WifiConfiguration> configurations) { + List<WifiConfiguration> configurations, + Map<String, String> macAddressMapping) { for (WifiConfiguration configuration : configurations) { configuration.networkId = mNextNetworkId++; if (mVerboseLoggingEnabled) { @@ -2872,6 +2913,7 @@ public class WifiConfigManager { Log.e(TAG, "Failed to add network to config map", e); } } + mRandomizedMacAddressMapping.putAll(macAddressMapping); } /** @@ -2914,11 +2956,12 @@ public class WifiConfigManager { */ private void loadInternalData( List<WifiConfiguration> sharedConfigurations, - List<WifiConfiguration> userConfigurations, Set<String> deletedEphemeralSSIDs) { + List<WifiConfiguration> userConfigurations, Set<String> deletedEphemeralSSIDs, + Map<String, String> macAddressMapping) { // Clear out all the existing in-memory lists and load the lists from what was retrieved // from the config store. clearInternalData(); - loadInternalDataFromSharedStore(sharedConfigurations); + loadInternalDataFromSharedStore(sharedConfigurations, macAddressMapping); loadInternalDataFromUserStore(userConfigurations, deletedEphemeralSSIDs); if (mConfiguredNetworks.sizeForAllUsers() == 0) { Log.w(TAG, "No stored networks found."); @@ -2952,7 +2995,7 @@ public class WifiConfigManager { WifiConfigStoreDataLegacy storeData = mWifiConfigStoreLegacy.read(); Log.d(TAG, "Reading from legacy store completed"); loadInternalData(storeData.getConfigurations(), new ArrayList<WifiConfiguration>(), - storeData.getDeletedEphemeralSSIDs()); + storeData.getDeletedEphemeralSSIDs(), mRandomizedMacStoreData.getMacMapping()); // Setup user store for the current user in case it have not setup yet, so that data // owned by the current user will be backed to the user store. @@ -3003,7 +3046,8 @@ public class WifiConfigManager { } loadInternalData(mNetworkListSharedStoreData.getConfigurations(), mNetworkListUserStoreData.getConfigurations(), - mDeletedEphemeralSsidsStoreData.getSsidList()); + mDeletedEphemeralSsidsStoreData.getSsidList(), + mRandomizedMacStoreData.getMacMapping()); return true; } @@ -3093,6 +3137,7 @@ public class WifiConfigManager { mNetworkListSharedStoreData.setConfigurations(sharedConfigurations); mNetworkListUserStoreData.setConfigurations(userConfigurations); mDeletedEphemeralSsidsStoreData.setSsidList(mDeletedEphemeralSSIDs); + mRandomizedMacStoreData.setMacMapping(mRandomizedMacAddressMapping); try { mWifiConfigStore.write(forceWrite); |