summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Lee <rgl@google.com>2016-12-15 10:59:33 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2016-12-15 10:59:33 +0000
commit8d4dc66e1631568f1632026312b97393567ee1f9 (patch)
tree9d49477cf5f60b267ef450db98327acbe39117ed
parentd505cbe510e1600162e1128c1b30270647feae98 (diff)
parent6126ecd658387dd5d3d3337d7e0119ffa1d75eba (diff)
downloadandroid_frameworks_opt_net_wifi-8d4dc66e1631568f1632026312b97393567ee1f9.tar.gz
android_frameworks_opt_net_wifi-8d4dc66e1631568f1632026312b97393567ee1f9.tar.bz2
android_frameworks_opt_net_wifi-8d4dc66e1631568f1632026312b97393567ee1f9.zip
Merge "Send CMD_DISCONNECT after removing app/user configs DO NOT MERGE" into nyc-mr2-dev
-rw-r--r--service/java/com/android/server/wifi/WifiConfigManager.java55
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java17
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 f325bed29..0bddb6c8f 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