Disconnect network when captive portal returns unwanted.
When the user selects "Do not use this network" in the captive portal
app, it indicates that the user does not want to log in and does not
want to use the network. Thus, the network should be disconnected.
Internally handle the network disconnect in ConnectivityService upon
receiving a captive portal app response of APP_RETURN_UNWANTED.
Test: atest ConnectivityServiceTest
Change-Id: I789ddb663b533a71a77ed435fa91b0c20d3bbfd4
diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java
index 2535974..dd4f33b 100755
--- a/service/src/com/android/server/ConnectivityService.java
+++ b/service/src/com/android/server/ConnectivityService.java
@@ -737,6 +737,12 @@
private static final int EVENT_INITIAL_EVALUATION_TIMEOUT = 57;
/**
+ * Used internally when the user does not want the network from captive portal app.
+ * obj = Network
+ */
+ private static final int EVENT_USER_DOES_NOT_WANT = 58;
+
+ /**
* Argument for {@link #EVENT_PROVISIONING_NOTIFICATION} to indicate that the notification
* should be shown.
*/
@@ -5055,6 +5061,10 @@
public void appResponse(final int response) {
if (response == CaptivePortal.APP_RETURN_WANTED_AS_IS) {
enforceSettingsPermission();
+ } else if (response == CaptivePortal.APP_RETURN_UNWANTED) {
+ mHandler.sendMessage(mHandler.obtainMessage(EVENT_USER_DOES_NOT_WANT, mNetwork));
+ // Since the network will be disconnected, skip notifying NetworkMonitor
+ return;
}
final NetworkMonitorManager nm = getNetworkMonitorManager(mNetwork);
@@ -5496,6 +5506,12 @@
case EVENT_INGRESS_RATE_LIMIT_CHANGED:
handleIngressRateLimitChanged();
break;
+ case EVENT_USER_DOES_NOT_WANT:
+ final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork((Network) msg.obj);
+ if (nai == null) break;
+ nai.onPreventAutomaticReconnect();
+ nai.disconnect();
+ break;
}
}
}