Commit 6b7f403e authored by Jeff Davidson's avatar Jeff Davidson Committed by Android (Google) Code Review
Browse files

Merge "Support conversion of untrusted networks to trusted." into lmp-mr1-dev

parents 917a6ea4 3aed1e5a
......@@ -564,6 +564,8 @@ public class WifiConfigStore extends IpConfigStore {
List<WifiConfiguration> networks = new ArrayList<>();
for(WifiConfiguration config : mConfiguredNetworks.values()) {
WifiConfiguration newConfig = new WifiConfiguration(config);
// When updating this condition, update WifiStateMachine's CONNECT_NETWORK handler to
// correctly handle updating existing configs that are filtered out here.
if (config.autoJoinStatus == WifiConfiguration.AUTO_JOIN_DELETED || config.ephemeral) {
// Do not enumerate and return this configuration to any one,
// for instance WiFi Picker.
......
......@@ -4344,12 +4344,7 @@ public class WifiStateMachine extends StateMachine {
c.numConnectionFailures = 0;
// Tell the framework whether the newly connected network is trusted or untrusted.
if (c.ephemeral) {
mNetworkCapabilities.removeCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED);
} else {
mNetworkCapabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED);
}
mNetworkAgent.sendNetworkCapabilities(mNetworkCapabilities);
updateCapabilities(c);
}
if (c != null) {
ScanResult result = getCurrentScanResult();
......@@ -6345,9 +6340,25 @@ public class WifiStateMachine extends StateMachine {
netId = message.arg1;
config = (WifiConfiguration) message.obj;
mWifiConnectionStatistics.numWifiManagerJoinAttempt++;
boolean updatedExisting = false;
/* Save the network config */
if (config != null) {
String configKey = config.configKey(true /* allowCached */);
WifiConfiguration savedConfig =
mWifiConfigStore.getWifiConfiguration(configKey);
if (savedConfig != null) {
// There is an existing config with this netId, but it wasn't exposed
// (either AUTO_JOIN_DELETED or ephemeral; see WifiConfigStore#
// getConfiguredNetworks). Remove those bits and update the config.
config = savedConfig;
loge("CONNECT_NETWORK updating existing config with id=" +
config.networkId + " configKey=" + configKey);
config.ephemeral = false;
config.autoJoinStatus = WifiConfiguration.AUTO_JOIN_ENABLED;
updatedExisting = true;
}
result = mWifiConfigStore.saveNetwork(config, message.sendingUid);
netId = result.getNetworkId();
}
......@@ -6415,6 +6426,11 @@ public class WifiStateMachine extends StateMachine {
if (didDisconnect) {
/* Expect a disconnection from the old connection */
transitionTo(mDisconnectingState);
} else if (updatedExisting && getCurrentState() == mConnectedState &&
getCurrentWifiConfiguration().networkId == netId) {
// Update the current set of network capabilities, but stay in the
// current state.
updateCapabilities(config);
} else {
/**
* Directly go to disconnected state where we
......@@ -6570,6 +6586,17 @@ public class WifiStateMachine extends StateMachine {
}
}
private void updateCapabilities(WifiConfiguration config) {
if (config.ephemeral) {
mNetworkCapabilities.removeCapability(
NetworkCapabilities.NET_CAPABILITY_TRUSTED);
} else {
mNetworkCapabilities.addCapability(
NetworkCapabilities.NET_CAPABILITY_TRUSTED);
}
mNetworkAgent.sendNetworkCapabilities(mNetworkCapabilities);
}
private class WifiNetworkAgent extends NetworkAgent {
public WifiNetworkAgent(Looper l, Context c, String TAG, NetworkInfo ni,
NetworkCapabilities nc, LinkProperties lp, int score) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment