From 2c39d1313a79bbb48900737b403b59fe1230c3d3 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Thu, 14 May 2015 23:15:10 +0900 Subject: [PATCH] Don't display the "no Internet access" prompt on captive portals. Bug: 20081183 Bug: 21066461 Change-Id: Idc71844a604f9ca655411c6916de256780ea4586 --- .../com/android/server/ConnectivityService.java | 6 ++++-- .../server/connectivity/NetworkAgentInfo.java | 13 +++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 0961ffe1ff..16b3dcfa8b 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -1982,7 +1982,7 @@ public class ConnectivityService extends IConnectivityManager.Stub if (msg.arg1 == 0) { setProvNotificationVisibleIntent(false, msg.arg2, 0, null, null); } else { - NetworkAgentInfo nai = null; + final NetworkAgentInfo nai; synchronized (mNetworkForNetId) { nai = mNetworkForNetId.get(msg.arg2); } @@ -1990,6 +1990,7 @@ public class ConnectivityService extends IConnectivityManager.Stub loge("EVENT_PROVISIONING_NOTIFICATION from unknown NetworkMonitor"); break; } + nai.captivePortalDetected = true; setProvNotificationVisibleIntent(true, msg.arg2, nai.networkInfo.getType(), nai.networkInfo.getExtraInfo(), (PendingIntent)msg.obj); } @@ -2384,7 +2385,8 @@ public class ConnectivityService extends IConnectivityManager.Stub // Only prompt if the network is unvalidated and was explicitly selected by the user, and if // we haven't already been told to switch to it regardless of whether it validated or not. - if (nai == null || nai.everValidated || + // Also don't prompt on captive portals because we're already prompting the user to sign in. + if (nai == null || nai.everValidated || nai.captivePortalDetected || !nai.networkMisc.explicitlySelected || nai.networkMisc.acceptUnvalidated) { return; } diff --git a/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java b/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java index 8a7c9020d9..eac748f4cf 100644 --- a/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java +++ b/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java @@ -50,12 +50,11 @@ public class NetworkAgentInfo { public final NetworkMisc networkMisc; // Indicates if netd has been told to create this Network. Once created the appropriate routing // rules are setup and routes are added so packets can begin flowing over the Network. - // NOTE: This is a sticky bit; once set it is never cleared. + // This is a sticky bit; once set it is never cleared. public boolean created; // Set to true if this Network successfully passed validation or if it did not satisfy the // default NetworkRequest in which case validation will not be attempted. - // NOTE: This is a sticky bit; once set it is never cleared even if future validation attempts - // fail. + // This is a sticky bit; once set it is never cleared even if future validation attempts fail. public boolean everValidated; // The result of the last validation attempt on this network (true if validated, false if not). @@ -65,6 +64,10 @@ public class NetworkAgentInfo { // TODO: Fix the network scoring code, remove this, and rename everValidated to validated. public boolean lastValidated; + // Whether a captive portal was ever detected on this network. + // This is a sticky bit; once set it is never cleared. + public boolean captivePortalDetected; + // This represents the last score received from the NetworkAgent. private int currentScore; // Penalty applied to scores of Networks that have not been validated. @@ -101,9 +104,6 @@ public class NetworkAgentInfo { currentScore = score; networkMonitor = new NetworkMonitor(context, handler, this, defaultRequest); networkMisc = misc; - created = false; - everValidated = false; - lastValidated = false; } public void addRequest(NetworkRequest networkRequest) { @@ -166,6 +166,7 @@ public class NetworkAgentInfo { "created{" + created + "} " + "explicitlySelected{" + networkMisc.explicitlySelected + "} " + "acceptUnvalidated{" + networkMisc.acceptUnvalidated + "} " + + "captivePortalDetected{" + captivePortalDetected + "} " + "}"; }