summaryrefslogtreecommitdiffstats
path: root/wifi
diff options
context:
space:
mode:
authorian <ian.t.roy@gmail.com>2012-12-17 12:30:00 -0500
committerGerrit Code Review <gerrit@review.cyanogenmod.com>2013-01-08 21:01:36 -0800
commit19c7d4995a554bc26a17b55f481193c435d30560 (patch)
treed206bbb155dd7319aca2b39e31ecba7f700a3acd /wifi
parentf1a7df3c19d631db55b2e78843641c268965b845 (diff)
downloadframeworks_base-19c7d4995a554bc26a17b55f481193c435d30560.zip
frameworks_base-19c7d4995a554bc26a17b55f481193c435d30560.tar.gz
frameworks_base-19c7d4995a554bc26a17b55f481193c435d30560.tar.bz2
Patch Set 1/2: Add an "Automatically Connect" option for WiFi networks
Allows the ability for a user to determine whether to connect to an SSID automatically. e.g. At work, there are several SSIDs with long, complex keys. I don't want to connect to them all of the time, but would like them to be remebered. The default behaviour is to allow automatic connection, as it is today. Change-Id: If6fb33d5aff91688aec73317a9e43c9e210f90fc
Diffstat (limited to 'wifi')
-rw-r--r--wifi/java/android/net/wifi/WifiConfigStore.java58
-rw-r--r--wifi/java/android/net/wifi/WifiConfiguration.java15
-rw-r--r--wifi/java/android/net/wifi/WifiManager.java8
-rw-r--r--wifi/java/android/net/wifi/WifiStateMachine.java1
4 files changed, 80 insertions, 2 deletions
diff --git a/wifi/java/android/net/wifi/WifiConfigStore.java b/wifi/java/android/net/wifi/WifiConfigStore.java
index 84506b6..4267eb2 100644
--- a/wifi/java/android/net/wifi/WifiConfigStore.java
+++ b/wifi/java/android/net/wifi/WifiConfigStore.java
@@ -142,6 +142,7 @@ class WifiConfigStore {
private static final String PROXY_PORT_KEY = "proxyPort";
private static final String EXCLUSION_LIST_KEY = "exclusionList";
private static final String EOS = "eos";
+ private static final String AUTO_CONNECT_KEY = "autoConnect";
private WifiNative mWifiNative;
@@ -179,7 +180,7 @@ class WifiConfigStore {
void enableAllNetworks() {
boolean networkEnabledStateChanged = false;
for(WifiConfiguration config : mConfiguredNetworks.values()) {
- if(config != null && config.status == Status.DISABLED) {
+ if(config != null && config.status == Status.DISABLED && config.autoConnect) {
if(mWifiNative.enableNetwork(config.networkId, false)) {
networkEnabledStateChanged = true;
config.status = Status.ENABLED;
@@ -195,6 +196,21 @@ class WifiConfigStore {
}
}
+ /**
+ * disable all networks that don't have autoConnect set and save config.
+ */
+ void setStateFromAutoConnectAllNetworks() {
+ for(WifiConfiguration config : mConfiguredNetworks.values()) {
+ if(config != null) {
+ if (config.status == Status.DISABLED && config.autoConnect) {
+ enableNetwork(config.networkId, false);
+ } else if (config.status == Status.ENABLED && !config.autoConnect) {
+ disableNetwork(config.networkId);
+ }
+ }
+ }
+
+ }
/**
* Selects the specified network for connection. This involves
@@ -222,10 +238,13 @@ class WifiConfigStore {
mLastPriority = 0;
}
+ boolean tmpAutoConnect = true;
+ tmpAutoConnect = mConfiguredNetworks.get(netId).autoConnect;
// Set to the highest priority and save the configuration.
WifiConfiguration config = new WifiConfiguration();
config.networkId = netId;
config.priority = ++mLastPriority;
+ config.autoConnect = tmpAutoConnect;
addOrUpdateNetworkNative(config);
mWifiNative.saveConfig();
@@ -278,6 +297,9 @@ class WifiConfigStore {
if (config.status == Status.CURRENT) {
config.status = Status.ENABLED;
}
+ else if (!config.autoConnect) {
+ config.status = Status.DISABLED;
+ }
break;
default:
//do nothing, retain the existing state
@@ -798,6 +820,8 @@ class WifiConfigStore {
break;
}
if (writeToFile) {
+ out.writeUTF(AUTO_CONNECT_KEY);
+ out.writeUTF((config.autoConnect ? "True" : "False"));
out.writeUTF(ID_KEY);
out.writeInt(configKey(config));
}
@@ -850,10 +874,12 @@ class WifiConfigStore {
IpAssignment ipAssignment = IpAssignment.UNASSIGNED;
ProxySettings proxySettings = ProxySettings.UNASSIGNED;
LinkProperties linkProperties = new LinkProperties();
+ boolean autoConnect = true;
String proxyHost = null;
int proxyPort = -1;
String exclusionList = null;
String key;
+ String value;
do {
key = in.readUTF();
@@ -886,6 +912,13 @@ class WifiConfigStore {
} else if (key.equals(DNS_KEY)) {
linkProperties.addDns(
NetworkUtils.numericToInetAddress(in.readUTF()));
+ } else if (key.equals(AUTO_CONNECT_KEY)) {
+ value = in.readUTF();
+ if (value.equals("True")) {
+ autoConnect = true;
+ } else {
+ autoConnect = false;
+ }
} else if (key.equals(PROXY_SETTINGS_KEY)) {
proxySettings = ProxySettings.valueOf(in.readUTF());
} else if (key.equals(PROXY_HOST_KEY)) {
@@ -942,6 +975,7 @@ class WifiConfigStore {
loge("Ignore invalid proxy settings while reading");
break;
}
+ config.autoConnect = autoConnect;
}
} else {
if (DBG) log("Missing id while parsing configuration");
@@ -1189,6 +1223,7 @@ class WifiConfigStore {
WifiConfiguration newConfig) {
boolean ipChanged = false;
boolean proxyChanged = false;
+ boolean autoConnectChanged = false;
LinkProperties linkProperties = new LinkProperties();
switch (newConfig.ipAssignment) {
@@ -1254,6 +1289,19 @@ class WifiConfigStore {
break;
}
+ boolean newAutoConnect = newConfig.autoConnect;
+ boolean currentAutoConnect = currentConfig.autoConnect;
+ if (newAutoConnect == currentAutoConnect) {
+ autoConnectChanged = false;
+ } else {
+ autoConnectChanged = true;
+ if (newAutoConnect) {
+ enableNetwork(newConfig.networkId, false);
+ } else {
+ disableNetwork(newConfig.networkId);
+ }
+ }
+
if (!ipChanged) {
addIpSettingsFromConfig(linkProperties, currentConfig);
} else {
@@ -1275,7 +1323,13 @@ class WifiConfigStore {
}
}
- if (ipChanged || proxyChanged) {
+ if (!autoConnectChanged) {
+ currentConfig.autoConnect = currentConfig.autoConnect;
+ } else {
+ currentConfig.autoConnect = newConfig.autoConnect;
+ }
+
+ if (ipChanged || proxyChanged || autoConnectChanged) {
currentConfig.linkProperties = linkProperties;
writeIpAndProxyConfigurations();
sendConfiguredNetworksChangedBroadcast(currentConfig,
diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java
index c4fe1b4..7ef85b9 100644
--- a/wifi/java/android/net/wifi/WifiConfiguration.java
+++ b/wifi/java/android/net/wifi/WifiConfiguration.java
@@ -77,6 +77,8 @@ public class WifiConfiguration implements Parcelable {
/** {@hide} */
public static final String hiddenSSIDVarName = "scan_ssid";
/** {@hide} */
+ public static final String autoConnectVarName = "autoConnect";
+ /** {@hide} */
public static final int INVALID_NETWORK_ID = -1;
/** {@hide} */
@@ -399,12 +401,18 @@ public class WifiConfiguration implements Parcelable {
*/
public LinkProperties linkProperties;
+ /**
+ * @hide
+ */
+ public boolean autoConnect;
+
public WifiConfiguration() {
networkId = INVALID_NETWORK_ID;
SSID = null;
BSSID = null;
priority = 0;
hiddenSSID = false;
+ status = WifiConfiguration.Status.DISABLED;
disableReason = DISABLED_UNKNOWN_REASON;
allowedKeyManagement = new BitSet();
allowedProtocols = new BitSet();
@@ -419,6 +427,7 @@ public class WifiConfiguration implements Parcelable {
}
ipAssignment = IpAssignment.UNASSIGNED;
proxySettings = ProxySettings.UNASSIGNED;
+ autoConnect = false;
linkProperties = new LinkProperties();
}
@@ -506,6 +515,8 @@ public class WifiConfiguration implements Parcelable {
sbuf.append("\n");
sbuf.append("Proxy settings: " + proxySettings.toString());
sbuf.append("\n");
+ sbuf.append("Auto Connect: " + (autoConnect ? "True" : "False"));
+ sbuf.append("\n");
sbuf.append(linkProperties.toString());
sbuf.append("\n");
@@ -600,6 +611,7 @@ public class WifiConfiguration implements Parcelable {
wepTxKeyIndex = source.wepTxKeyIndex;
priority = source.priority;
hiddenSSID = source.hiddenSSID;
+ status = source.status;
allowedKeyManagement = (BitSet) source.allowedKeyManagement.clone();
allowedProtocols = (BitSet) source.allowedProtocols.clone();
allowedAuthAlgorithms = (BitSet) source.allowedAuthAlgorithms.clone();
@@ -611,6 +623,7 @@ public class WifiConfiguration implements Parcelable {
}
ipAssignment = source.ipAssignment;
proxySettings = source.proxySettings;
+ autoConnect = source.autoConnect;
linkProperties = new LinkProperties(source.linkProperties);
}
}
@@ -640,6 +653,7 @@ public class WifiConfiguration implements Parcelable {
}
dest.writeString(ipAssignment.name());
dest.writeString(proxySettings.name());
+ dest.writeString(autoConnect ? "True" : "False");
dest.writeParcelable(linkProperties, flags);
}
@@ -671,6 +685,7 @@ public class WifiConfiguration implements Parcelable {
config.ipAssignment = IpAssignment.valueOf(in.readString());
config.proxySettings = ProxySettings.valueOf(in.readString());
+ config.autoConnect = !in.readString().equals("False");
config.linkProperties = in.readParcelable(null);
return config;
}
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index 5e4f117..7463060 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -1077,6 +1077,14 @@ public class WifiManager {
*/
public boolean stopWifi() {
try {
+ for (WifiConfiguration config : getConfiguredNetworks()) {
+ if (config != null) {
+ if (!config.autoConnect) {
+ disableNetwork(config.networkId);
+ }
+ }
+ }
+ saveConfiguration();
mService.stopWifi();
return true;
} catch (RemoteException e) {
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index 26bb095..76c3311 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -766,6 +766,7 @@ public class WifiStateMachine extends StateMachine {
sendMessage(obtainMessage(CMD_LOAD_DRIVER, WIFI_STATE_ENABLING, 0));
sendMessage(CMD_START_SUPPLICANT);
} else {
+ mWifiConfigStore.setStateFromAutoConnectAllNetworks();
sendMessage(CMD_STOP_SUPPLICANT);
/* Argument is the state that is entered upon success */
sendMessage(obtainMessage(CMD_UNLOAD_DRIVER, WIFI_STATE_DISABLED, 0));