forked from M66B/cm10-fxp-extended
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwifi_auto_connect1.patch
283 lines (264 loc) · 11.7 KB
/
wifi_auto_connect1.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
From 1cde148be41829c17d94a6b2d4b39e502b01f388 Mon Sep 17 00:00:00 2001
From: ian <[email protected]>
Date: Mon, 3 Dec 2012 14:26:01 -0500
Subject: [PATCH] Patch Set 1/2: Add an "Automatically Connect" option for
WiFi networks Updated white spaces
Change-Id: I80c7a698de183691094352367913cc73f2863810
---
wifi/java/android/net/wifi/WifiConfigStore.java | 58 ++++++++++++++++++++-
wifi/java/android/net/wifi/WifiConfiguration.java | 15 ++++++
wifi/java/android/net/wifi/WifiManager.java | 8 +++
wifi/java/android/net/wifi/WifiStateMachine.java | 1 +
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 e9f3480..9c4eede 100644
--- a/wifi/java/android/net/wifi/WifiConfigStore.java
+++ b/wifi/java/android/net/wifi/WifiConfigStore.java
@@ -141,6 +141,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;
@@ -178,7 +179,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;
@@ -194,6 +195,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
@@ -221,10 +237,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();
@@ -277,6 +296,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
@@ -797,6 +819,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));
}
@@ -849,10 +873,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();
@@ -885,6 +911,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)) {
@@ -941,6 +974,7 @@ class WifiConfigStore {
loge("Ignore invalid proxy settings while reading");
break;
}
+ config.autoConnect = autoConnect;
}
} else {
if (DBG) log("Missing id while parsing configuration");
@@ -1188,6 +1222,7 @@ class WifiConfigStore {
WifiConfiguration newConfig) {
boolean ipChanged = false;
boolean proxyChanged = false;
+ boolean autoConnectChanged = false;
LinkProperties linkProperties = new LinkProperties();
switch (newConfig.ipAssignment) {
@@ -1253,6 +1288,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 {
@@ -1274,7 +1322,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 0a846fd..223f965 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");
@@ -579,6 +590,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();
@@ -590,6 +602,7 @@ public class WifiConfiguration implements Parcelable {
}
ipAssignment = source.ipAssignment;
proxySettings = source.proxySettings;
+ autoConnect = source.autoConnect;
linkProperties = new LinkProperties(source.linkProperties);
}
}
@@ -619,6 +632,7 @@ public class WifiConfiguration implements Parcelable {
}
dest.writeString(ipAssignment.name());
dest.writeString(proxySettings.name());
+ dest.writeInt(autoConnect ? 1 : 0);
dest.writeParcelable(linkProperties, flags);
}
@@ -650,6 +664,7 @@ public class WifiConfiguration implements Parcelable {
config.ipAssignment = IpAssignment.valueOf(in.readString());
config.proxySettings = ProxySettings.valueOf(in.readString());
+ config.autoConnect = in.readInt() != 0;
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 a48d54e..d4a8108 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -1049,6 +1049,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 ce1ad1d..623fd41 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -747,6 +747,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));
--
1.7.10.4