diff --git a/core/java/android/net/NetworkAgent.java b/core/java/android/net/NetworkAgent.java index 80e5b91ecc..95e24accf6 100644 --- a/core/java/android/net/NetworkAgent.java +++ b/core/java/android/net/NetworkAgent.java @@ -120,6 +120,18 @@ public abstract class NetworkAgent extends Handler { */ public static final int EVENT_UNBLOCK_ADDRESS_FAMILY = BASE + 8; + /** + * Sent by ConnectivitySerice to the NetworkAgent to inform the agent of the + * networks status - whether we could use the network or could not, due to + * either a bad network configuration (no internet link) or captive portal. + * + * arg1 = either {@code VALID_NETWORK} or {@code INVALID_NETWORK} + */ + public static final int CMD_REPORT_NETWORK_STATUS = BASE + 9; + + public static final int VALID_NETWORK = 1; + public static final int INVALID_NETWORK = 2; + public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni, NetworkCapabilities nc, LinkProperties lp, int score) { this(looper, context, logTag, ni, nc, lp, score, null); @@ -181,6 +193,14 @@ public abstract class NetworkAgent extends Handler { log("Unhandled Message " + msg); break; } + case CMD_REPORT_NETWORK_STATUS: { + if (VDBG) { + log("CMD_REPORT_NETWORK_STATUS(" + + (msg.arg1 == VALID_NETWORK ? "VALID)" : "INVALID)")); + } + networkStatus(msg.arg1); + break; + } } } @@ -268,6 +288,24 @@ public abstract class NetworkAgent extends Handler { */ abstract protected void unwanted(); + /** + * Called when the system determines the usefulness of this network. + * + * Networks claiming internet connectivity will have their internet + * connectivity verified. + * + * Currently there are two possible values: + * {@code VALID_NETWORK} if the system is happy with the connection, + * {@code INVALID_NETWORK} if the system is not happy. + * TODO - add indications of captive portal-ness and related success/failure, + * ie, CAPTIVE_SUCCESS_NETWORK, CAPTIVE_NETWORK for successful login and detection + * + * This may be called multiple times as the network status changes and may + * generate false negatives if we lose ip connectivity before the link is torn down. + */ + protected void networkStatus(int status) { + } + protected void log(String s) { Log.d(LOG_TAG, "NetworkAgent: " + s); } diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 55d8c09da0..c2d92f3d18 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -1935,6 +1935,11 @@ public class ConnectivityService extends IConnectivityManager.Stub { rematchNetworkAndRequests(nai); } updateInetCondition(nai, valid); + // Let the NetworkAgent know the state of its network + nai.asyncChannel.sendMessage( + android.net.NetworkAgent.CMD_REPORT_NETWORK_STATUS, + (valid ? NetworkAgent.VALID_NETWORK : NetworkAgent.INVALID_NETWORK), + 0, null); } break; } @@ -2517,6 +2522,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { nai = mNetworkForNetId.get(network.netId); } if (nai == null) return; + if (DBG) log("reportBadNetwork(" + nai.name() + ") by " + uid); synchronized (nai) { if (isNetworkBlocked(nai, uid)) return;