diff options
author | Robin Lee <rgl@google.com> | 2016-12-01 20:44:57 +0000 |
---|---|---|
committer | Robin Lee <rgl@google.com> | 2016-12-09 15:47:14 +0000 |
commit | 6126ecd658387dd5d3d3337d7e0119ffa1d75eba (patch) | |
tree | f270e5a101490fc13e9b7d8c6a43f83293c03104 /service | |
parent | d98d7625e0a47c2fdaa8c85819391eb622a5249a (diff) | |
download | android_frameworks_opt_net_wifi-6126ecd658387dd5d3d3337d7e0119ffa1d75eba.tar.gz android_frameworks_opt_net_wifi-6126ecd658387dd5d3d3337d7e0119ffa1d75eba.tar.bz2 android_frameworks_opt_net_wifi-6126ecd658387dd5d3d3337d7e0119ffa1d75eba.zip |
Send CMD_DISCONNECT after removing app/user configs DO NOT MERGE
Otherwise they might linger in wpa_supplicant longer than they were
supposed to.
This is already done by every other callsite for removing networks which
might still be in use.
Test: runtest -x tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
Bug: 32660379
Change-Id: I45b0bcc87129be02bcce940f07f7c48543207bf0
(cherry-picked from commit 1fe1065da82165183fa057ddbbd2e33bc5708c1b)
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/WifiConfigManager.java | 55 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiStateMachine.java | 17 |
2 files changed, 45 insertions, 27 deletions
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java index 407773ce9..8e990ce08 100644 --- a/service/java/com/android/server/wifi/WifiConfigManager.java +++ b/service/java/com/android/server/wifi/WifiConfigManager.java @@ -51,6 +51,7 @@ import android.os.UserManager; import android.provider.Settings; import android.security.KeyStore; import android.text.TextUtils; +import android.util.ArraySet; import android.util.LocalLog; import android.util.Log; import android.util.SparseArray; @@ -1231,52 +1232,56 @@ public class WifiConfigManager { /* * Remove all networks associated with an application * - * @param packageName name of the package of networks to remove - * @return {@code true} if all networks removed successfully, {@code false} otherwise + * @param app Application info of the package of networks to remove. + * @return the {@link Set} of networks that were removed by this call. Networks which matched + * but failed to remove are omitted from this set. */ - boolean removeNetworksForApp(ApplicationInfo app) { + public Set<Integer> removeNetworksForApp(ApplicationInfo app) { if (app == null || app.packageName == null) { - return false; + return Collections.<Integer>emptySet(); } - boolean success = true; - - WifiConfiguration [] copiedConfigs = - mConfiguredNetworks.valuesForCurrentUser().toArray(new WifiConfiguration[0]); + Log.d(TAG, "Remove all networks for app " + app); + Set<Integer> removedNetworks = new ArraySet<>(); + WifiConfiguration[] copiedConfigs = + mConfiguredNetworks.valuesForAllUsers().toArray(new WifiConfiguration[0]); for (WifiConfiguration config : copiedConfigs) { if (app.uid != config.creatorUid || !app.packageName.equals(config.creatorName)) { continue; } - if (mShowNetworks) { - localLog("Removing network " + config.SSID - + ", application \"" + app.packageName + "\" uninstalled" - + " from user " + UserHandle.getUserId(app.uid)); + localLog("Removing network " + config.SSID + + ", application \"" + app.packageName + "\" uninstalled" + + " from user " + UserHandle.getUserId(app.uid)); + if (removeNetwork(config.networkId)) { + removedNetworks.add(config.networkId); } - success &= removeNetwork(config.networkId); } - saveConfig(); - - return success; + return removedNetworks; } - boolean removeNetworksForUser(int userId) { - boolean success = true; - + /** + * Remove all networks associated with a user. + * + * @param userId The identifier of the user which is being removed. + * @return the {@link Set} of networks that were removed by this call. Networks which matched + * but failed to remove are omitted from this set. + */ + Set<Integer> removeNetworksForUser(int userId) { + Log.d(TAG, "Remove all networks for user " + userId); + Set<Integer> removedNetworks = new ArraySet<>(); WifiConfiguration[] copiedConfigs = mConfiguredNetworks.valuesForAllUsers().toArray(new WifiConfiguration[0]); for (WifiConfiguration config : copiedConfigs) { if (userId != UserHandle.getUserId(config.creatorUid)) { continue; } - success &= removeNetwork(config.networkId); - if (mShowNetworks) { - localLog("Removing network " + config.SSID - + ", user " + userId + " removed"); + localLog("Removing network " + config.SSID + ", user " + userId + " removed"); + if (removeNetwork(config.networkId)) { + removedNetworks.add(config.networkId); } } - - return success; + return removedNetworks; } /** diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index 0c7e987ee..cba03324e 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -5394,6 +5394,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss String bssid; String ssid; NetworkUpdateResult result; + Set<Integer> removedNetworkIds; logStateAndMessage(message, this); switch (message.what) { @@ -5884,10 +5885,22 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss } break; case CMD_REMOVE_APP_CONFIGURATIONS: - mWifiConfigManager.removeNetworksForApp((ApplicationInfo) message.obj); + removedNetworkIds = + mWifiConfigManager.removeNetworksForApp((ApplicationInfo) message.obj); + if (removedNetworkIds.contains(mTargetNetworkId) || + removedNetworkIds.contains(mLastNetworkId)) { + // Disconnect and let autojoin reselect a new network. + sendMessage(CMD_DISCONNECT); + } break; case CMD_REMOVE_USER_CONFIGURATIONS: - mWifiConfigManager.removeNetworksForUser(message.arg1); + removedNetworkIds = + mWifiConfigManager.removeNetworksForUser((Integer) message.arg1); + if (removedNetworkIds.contains(mTargetNetworkId) || + removedNetworkIds.contains(mLastNetworkId)) { + // Disconnect and let autojoin reselect a new network. + sendMessage(CMD_DISCONNECT); + } break; case WifiManager.CONNECT_NETWORK: // Only the current foreground user and System UI (which runs as user 0 but acts |