Skip to content

Commit 1b6989c

Browse files
author
Mike Lockwood
committed
Merge commit '74803dc'
Change-Id: I35a76a27390c75a47e6387fb0ee853a5a689a56f
1 parent a91da5d commit 1b6989c

File tree

3 files changed

+113
-13
lines changed

3 files changed

+113
-13
lines changed

wifi/java/android/net/wifi/NetworkUpdateResult.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class NetworkUpdateResult {
2222
int netId;
2323
boolean ipChanged;
2424
boolean proxyChanged;
25+
boolean isNewNetwork = false;
2526

2627
public NetworkUpdateResult(int id) {
2728
netId = id;
@@ -58,4 +59,12 @@ public void setProxyChanged(boolean proxy) {
5859
public boolean hasProxyChanged() {
5960
return proxyChanged;
6061
}
62+
63+
public boolean isNewNetwork() {
64+
return isNewNetwork;
65+
}
66+
67+
public void setIsNewNetwork(boolean isNew) {
68+
isNewNetwork = isNew;
69+
}
6170
}

wifi/java/android/net/wifi/WifiConfigStore.java

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ NetworkUpdateResult saveNetwork(WifiConfiguration config) {
273273
mConfiguredNetworks.get(netId).status = Status.ENABLED;
274274
}
275275
mWifiNative.saveConfig();
276-
sendConfiguredNetworksChangedBroadcast();
276+
sendConfiguredNetworksChangedBroadcast(config, result.isNewNetwork() ?
277+
WifiManager.CHANGE_REASON_ADDED : WifiManager.CHANGE_REASON_CONFIG_CHANGE);
277278
return result;
278279
}
279280

@@ -307,13 +308,16 @@ void updateStatus(int netId, DetailedState state) {
307308
boolean forgetNetwork(int netId) {
308309
if (mWifiNative.removeNetwork(netId)) {
309310
mWifiNative.saveConfig();
311+
WifiConfiguration target = null;
310312
WifiConfiguration config = mConfiguredNetworks.get(netId);
311313
if (config != null) {
312-
mConfiguredNetworks.remove(netId);
314+
target = mConfiguredNetworks.remove(netId);
313315
mNetworkIds.remove(configKey(config));
314316
}
315-
writeIpAndProxyConfigurations();
316-
sendConfiguredNetworksChangedBroadcast();
317+
if (target != null) {
318+
writeIpAndProxyConfigurations();
319+
sendConfiguredNetworksChangedBroadcast(target, WifiManager.CHANGE_REASON_REMOVED);
320+
}
317321
return true;
318322
} else {
319323
loge("Failed to remove network " + netId);
@@ -332,7 +336,11 @@ boolean forgetNetwork(int netId) {
332336
*/
333337
int addOrUpdateNetwork(WifiConfiguration config) {
334338
NetworkUpdateResult result = addOrUpdateNetworkNative(config);
335-
sendConfiguredNetworksChangedBroadcast();
339+
if (result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID) {
340+
sendConfiguredNetworksChangedBroadcast(mConfiguredNetworks.get(result.getNetworkId()),
341+
result.isNewNetwork ? WifiManager.CHANGE_REASON_ADDED :
342+
WifiManager.CHANGE_REASON_CONFIG_CHANGE);
343+
}
336344
return result.getNetworkId();
337345
}
338346

@@ -347,14 +355,17 @@ int addOrUpdateNetwork(WifiConfiguration config) {
347355
*/
348356
boolean removeNetwork(int netId) {
349357
boolean ret = mWifiNative.removeNetwork(netId);
358+
WifiConfiguration config = null;
350359
if (ret) {
351-
WifiConfiguration config = mConfiguredNetworks.get(netId);
360+
config = mConfiguredNetworks.get(netId);
352361
if (config != null) {
353-
mConfiguredNetworks.remove(netId);
362+
config = mConfiguredNetworks.remove(netId);
354363
mNetworkIds.remove(configKey(config));
355364
}
356365
}
357-
sendConfiguredNetworksChangedBroadcast();
366+
if (config != null) {
367+
sendConfiguredNetworksChangedBroadcast(config, WifiManager.CHANGE_REASON_REMOVED);
368+
}
358369
return ret;
359370
}
360371

@@ -364,12 +375,24 @@ boolean removeNetwork(int netId) {
364375
* API. The more powerful selectNetwork()/saveNetwork() is used by the
365376
* state machine for connecting to a network
366377
*
367-
* @param netId network to be removed
378+
* @param netId network to be enabled
368379
* @return {@code true} if it succeeds, {@code false} otherwise
369380
*/
370381
boolean enableNetwork(int netId, boolean disableOthers) {
371382
boolean ret = enableNetworkWithoutBroadcast(netId, disableOthers);
372-
sendConfiguredNetworksChangedBroadcast();
383+
if (disableOthers) {
384+
sendConfiguredNetworksChangedBroadcast();
385+
} else {
386+
WifiConfiguration enabledNetwork = null;
387+
synchronized(mConfiguredNetworks) {
388+
enabledNetwork = mConfiguredNetworks.get(netId);
389+
}
390+
// check just in case the network was removed by someone else.
391+
if (enabledNetwork != null) {
392+
sendConfiguredNetworksChangedBroadcast(enabledNetwork,
393+
WifiManager.CHANGE_REASON_CONFIG_CHANGE);
394+
}
395+
}
373396
return ret;
374397
}
375398

@@ -402,13 +425,18 @@ boolean disableNetwork(int netId) {
402425
*/
403426
boolean disableNetwork(int netId, int reason) {
404427
boolean ret = mWifiNative.disableNetwork(netId);
428+
WifiConfiguration network = null;
405429
WifiConfiguration config = mConfiguredNetworks.get(netId);
406430
/* Only change the reason if the network was not previously disabled */
407431
if (config != null && config.status != Status.DISABLED) {
408432
config.status = Status.DISABLED;
409433
config.disableReason = reason;
434+
network = config;
435+
}
436+
if (network != null) {
437+
sendConfiguredNetworksChangedBroadcast(network,
438+
WifiManager.CHANGE_REASON_CONFIG_CHANGE);
410439
}
411-
sendConfiguredNetworksChangedBroadcast();
412440
return ret;
413441
}
414442

@@ -574,9 +602,29 @@ boolean isUsingStaticIp(int netId) {
574602
return false;
575603
}
576604

605+
/**
606+
* Should be called when a single network configuration is made.
607+
* @param network The network configuration that changed.
608+
* @param reason The reason for the change, should be one of WifiManager.CHANGE_REASON_ADDED,
609+
* WifiManager.CHANGE_REASON_REMOVED, or WifiManager.CHANGE_REASON_CHANGE.
610+
*/
611+
private void sendConfiguredNetworksChangedBroadcast(WifiConfiguration network,
612+
int reason) {
613+
Intent intent = new Intent(WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION);
614+
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
615+
intent.putExtra(WifiManager.EXTRA_MULTIPLE_NETWORKS_CHANGED, false);
616+
intent.putExtra(WifiManager.EXTRA_WIFI_CONFIGURATION, network);
617+
intent.putExtra(WifiManager.EXTRA_CHANGE_REASON, reason);
618+
mContext.sendBroadcast(intent);
619+
}
620+
621+
/**
622+
* Should be called when multiple network configuration changes are made.
623+
*/
577624
private void sendConfiguredNetworksChangedBroadcast() {
578625
Intent intent = new Intent(WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION);
579626
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
627+
intent.putExtra(WifiManager.EXTRA_MULTIPLE_NETWORKS_CHANGED, true);
580628
mContext.sendBroadcast(intent);
581629
}
582630

@@ -1135,6 +1183,7 @@ private NetworkUpdateResult addOrUpdateNetworkNative(WifiConfiguration config) {
11351183
mNetworkIds.put(configKey(currentConfig), netId);
11361184

11371185
NetworkUpdateResult result = writeIpAndProxyConfigurationsOnChange(currentConfig, config);
1186+
result.setIsNewNetwork(newNetwork);
11381187
result.setNetworkId(netId);
11391188
return result;
11401189
}
@@ -1234,7 +1283,8 @@ private NetworkUpdateResult writeIpAndProxyConfigurationsOnChange(
12341283
if (ipChanged || proxyChanged) {
12351284
currentConfig.linkProperties = linkProperties;
12361285
writeIpAndProxyConfigurations();
1237-
sendConfiguredNetworksChangedBroadcast();
1286+
sendConfiguredNetworksChangedBroadcast(currentConfig,
1287+
WifiManager.CHANGE_REASON_CONFIG_CHANGE);
12381288
}
12391289
return new NetworkUpdateResult(ipChanged, proxyChanged);
12401290
}

wifi/java/android/net/wifi/WifiManager.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,52 @@ public class WifiManager {
294294

295295
/**
296296
* Broadcast intent action indicating that the configured networks changed.
297-
* This can be as a result of adding/updating/deleting a network
297+
* This can be as a result of adding/updating/deleting a network. If
298+
* {@link #EXTRA_MULTIPLE_NETWORKS_CHANGED} is set to true the new configuration
299+
* can be retreived with the {@link #EXTRA_WIFI_CONFIGURATION} extra. If multiple
300+
* Wi-Fi configurations changed, {@link #EXTRA_WIFI_CONFIGURATION} will not be present.
298301
* @hide
299302
*/
300303
public static final String CONFIGURED_NETWORKS_CHANGED_ACTION =
301304
"android.net.wifi.CONFIGURED_NETWORKS_CHANGE";
305+
/**
306+
* The lookup key for a (@link android.net.wifi.WifiConfiguration} object representing
307+
* the changed Wi-Fi configuration when the {@link #CONFIGURED_NETWORKS_CHANGED_ACTION}
308+
* broadcast is sent.
309+
* @hide
310+
*/
311+
public static final String EXTRA_WIFI_CONFIGURATION = "wifiConfiguration";
312+
/**
313+
* Multiple network configurations have changed.
314+
* @see #CONFIGURED_NETWORKS_CHANGED_ACTION
315+
*
316+
* @hide
317+
*/
318+
public static final String EXTRA_MULTIPLE_NETWORKS_CHANGED = "multipleChanges";
319+
/**
320+
* The lookup key for an integer indicating the reason a Wi-Fi network configuration
321+
* has changed. Only present if {@link #EXTRA_MULTIPLE_NETWORKS_CHANGED} is {@code false}
322+
* @see #CONFIGURED_NETWORKS_CHANGED_ACTION
323+
* @hide
324+
*/
325+
public static final String EXTRA_CHANGE_REASON = "changeReason";
326+
/**
327+
* The configuration is new and was added.
328+
* @hide
329+
*/
330+
public static final int CHANGE_REASON_ADDED = 0;
331+
/**
332+
* The configuration was removed and is no longer present in the system's list of
333+
* configured networks.
334+
* @hide
335+
*/
336+
public static final int CHANGE_REASON_REMOVED = 1;
337+
/**
338+
* The configuration has changed as a result of explicit action or because the system
339+
* took an automated action such as disabling a malfunctioning configuration.
340+
* @hide
341+
*/
342+
public static final int CHANGE_REASON_CONFIG_CHANGE = 2;
302343
/**
303344
* An access point scan has completed, and results are available from the supplicant.
304345
* Call {@link #getScanResults()} to obtain the results.

0 commit comments

Comments
 (0)