From 8650c035609507340e3a66459cea16ef08cd03a6 Mon Sep 17 00:00:00 2001 From: vandwalle Date: Sun, 11 Jan 2015 11:57:01 -0800 Subject: [PATCH] aggressively blacklist WifiConfiguration for the purpose of switching network In cases where networks are not properly configured, WiFi might tries to repeatdly switch from one network to a bad network, or might try to roam and renew DHCP which can fail. In KK, WiFi autojoin would try other networks (by cycling to network it sees) and end up associated to a "good" network. In L release even thought WiFi might pick a good network it will still repeatedly try to switch to what it thinks is a better network and fail, thus annoying the user whose connection becomes unstable. This CL tries to remember networks that have seen multiple DHCP or auth failure in the past and for those networks it disable roaming temporarily. That is, if wifi is not associated to any network, it will tries to join a network aggressively, however if wifi is currently associated to a network, it will not try to switch to a new network if that new network has seen multiple failure in the past. The maximum blacklist time is set to 2 days for now. An example of such situation is: - user has multiple SSID at home, one of which is incorrectly configured with a wrong password - broken DHCP situation (potentially: multiple servers on home network, broken implementation incorrecting NAK'ing DHCP requests but properly serving DHCP offer...) Bug:18792931 Change-Id: I332a9cebdc19be2e00b455205d386fcffcb70b29 --- core/res/res/values/config.xml | 4 ++ core/res/res/values/symbols.xml | 1 + .../android/net/wifi/WifiConfiguration.java | 46 +++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index d036140451c01..c08b54eddfa62 100755 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -424,6 +424,10 @@ 15000 + + 172800000 + 60000 diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 4a1ed5546ed7b..646bcf52512cd 100755 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -327,6 +327,7 @@ + diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java index 6543c03afb082..87db951e0bd32 100644 --- a/wifi/java/android/net/wifi/WifiConfiguration.java +++ b/wifi/java/android/net/wifi/WifiConfiguration.java @@ -686,6 +686,31 @@ public class WifiConfiguration implements Parcelable { */ public long lastConnectionFailure; + /** + * @hide + * Last time the system tried to roam and failed because of authentication failure or DHCP + * RENEW failure. + */ + public long lastRoamingFailure; + + /** @hide */ + public static int ROAMING_FAILURE_IP_CONFIG = 1; + /** @hide */ + public static int ROAMING_FAILURE_AUTH_FAILURE = 2; + + /** + * @hide + * Initial amount of time this Wifi configuration gets blacklisted for network switching + * because of roaming failure + */ + public long roamingFailureBlackListTimeMilli = 1000; + + /** + * @hide + * Last roaming failure reason code + */ + public int lastRoamingFailureReason; + /** * @hide * Last time the system was disconnected to this configuration. @@ -1148,6 +1173,18 @@ public class WifiConfiguration implements Parcelable { sbuf.append( "sec"); } } + if (this.lastRoamingFailure != 0) { + sbuf.append('\n'); + long diff = now_ms - this.lastRoamingFailure; + if (diff <= 0) { + sbuf.append("lastRoamingFailure since "); + } else { + sbuf.append("lastRoamingFailure: ").append(Long.toString(diff/1000)); + sbuf.append( "sec"); + } + } + sbuf.append("roamingFailureBlackListTimeMilli: "). + append(Long.toString(this.roamingFailureBlackListTimeMilli)); sbuf.append('\n'); if (this.linkedConfigurations != null) { for(String key : this.linkedConfigurations.keySet()) { @@ -1518,6 +1555,9 @@ public class WifiConfiguration implements Parcelable { lastConnected = source.lastConnected; lastDisconnected = source.lastDisconnected; lastConnectionFailure = source.lastConnectionFailure; + lastRoamingFailure = source.lastRoamingFailure; + lastRoamingFailureReason = source.lastRoamingFailureReason; + roamingFailureBlackListTimeMilli = source.roamingFailureBlackListTimeMilli; numConnectionFailures = source.numConnectionFailures; numIpConfigFailures = source.numIpConfigFailures; numAuthFailures = source.numAuthFailures; @@ -1587,6 +1627,9 @@ public class WifiConfiguration implements Parcelable { dest.writeInt(lastUpdateUid); dest.writeLong(blackListTimestamp); dest.writeLong(lastConnectionFailure); + dest.writeLong(lastRoamingFailure); + dest.writeInt(lastRoamingFailureReason); + dest.writeLong(roamingFailureBlackListTimeMilli); dest.writeInt(numConnectionFailures); dest.writeInt(numIpConfigFailures); dest.writeInt(numAuthFailures); @@ -1649,6 +1692,9 @@ public class WifiConfiguration implements Parcelable { config.lastUpdateUid = in.readInt(); config.blackListTimestamp = in.readLong(); config.lastConnectionFailure = in.readLong(); + config.lastRoamingFailure = in.readLong(); + config.lastRoamingFailureReason = in.readInt(); + config.roamingFailureBlackListTimeMilli = in.readLong(); config.numConnectionFailures = in.readInt(); config.numIpConfigFailures = in.readInt(); config.numAuthFailures = in.readInt();