Notify the platform if network validation is skipped in NetworkMonitor. am: 78156e4701 am: 5d06ecfc3e
Original change: https://android-review.googlesource.com/c/platform/packages/modules/NetworkStack/+/1392711
Change-Id: I1b87d696b58837f3e363307937e84cf00ffa61c5
diff --git a/common/networkstackclient/aidl_api/networkstack-aidl-interfaces/current/android/net/INetworkMonitor.aidl b/common/networkstackclient/aidl_api/networkstack-aidl-interfaces/current/android/net/INetworkMonitor.aidl
index db9145f..9e7b40d 100644
--- a/common/networkstackclient/aidl_api/networkstack-aidl-interfaces/current/android/net/INetworkMonitor.aidl
+++ b/common/networkstackclient/aidl_api/networkstack-aidl-interfaces/current/android/net/INetworkMonitor.aidl
@@ -35,6 +35,7 @@
const int NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY = 2;
const int NETWORK_VALIDATION_RESULT_VALID = 1;
const int NETWORK_VALIDATION_RESULT_PARTIAL = 2;
+ const int NETWORK_VALIDATION_RESULT_SKIPPED = 4;
const int NETWORK_VALIDATION_PROBE_DNS = 4;
const int NETWORK_VALIDATION_PROBE_HTTP = 8;
const int NETWORK_VALIDATION_PROBE_HTTPS = 16;
diff --git a/common/networkstackclient/src/android/net/INetworkMonitor.aidl b/common/networkstackclient/src/android/net/INetworkMonitor.aidl
index 3fc81a3..b124734 100644
--- a/common/networkstackclient/src/android/net/INetworkMonitor.aidl
+++ b/common/networkstackclient/src/android/net/INetworkMonitor.aidl
@@ -44,10 +44,16 @@
// are set, then it's equal to NETWORK_TEST_RESULT_INVALID. If NETWORK_VALIDATION_RESULT_VALID
// is set, then the network validates and equal to NETWORK_TEST_RESULT_VALID. If
// NETWORK_VALIDATION_RESULT_PARTIAL is set, then the network has partial connectivity which
- // is equal to NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY. NETWORK_VALIDATION_PROBE_* is set
- // when the specific probe result of the network is resolved.
+ // is equal to NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY. Networks receiving validation that both
+ // do not require validation and are not validated will have NETWORK_VALIDATION_RESULT_SKIPPED
+ // set. NETWORK_VALIDATION_PROBE_* is set when the specific probe result of the network is
+ // resolved.
const int NETWORK_VALIDATION_RESULT_VALID = 0x01;
const int NETWORK_VALIDATION_RESULT_PARTIAL = 0x02;
+ const int NETWORK_VALIDATION_RESULT_SKIPPED = 0x04;
+
+ // NETWORK_VALIDATION_RESULT_* and NETWORK_VALIDATION_PROBE_* are independent values sent in
+ // different ints.
const int NETWORK_VALIDATION_PROBE_DNS = 0x04;
const int NETWORK_VALIDATION_PROBE_HTTP = 0x08;
const int NETWORK_VALIDATION_PROBE_HTTPS = 0x10;
diff --git a/src/com/android/server/connectivity/NetworkMonitor.java b/src/com/android/server/connectivity/NetworkMonitor.java
index 8950938..ce0374d 100755
--- a/src/com/android/server/connectivity/NetworkMonitor.java
+++ b/src/com/android/server/connectivity/NetworkMonitor.java
@@ -31,6 +31,7 @@
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_HTTPS;
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_PRIVDNS;
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_PARTIAL;
+import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_SKIPPED;
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_VALID;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_METERED;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED;
@@ -3435,6 +3436,14 @@
}
protected void reportEvaluationResult(int result, @Nullable String redirectUrl) {
+ if (!isValidationRequired() && mProbeCompleted == 0 && ShimUtils.isAtLeastS()) {
+ // If validation is not required AND no probes were attempted, the validation was
+ // skipped. Report this to ConnectivityService for ConnectivityDiagnostics, but only
+ // if the platform is Android S+, as ConnectivityService must also know how to
+ // understand this bit.
+ result |= NETWORK_VALIDATION_RESULT_SKIPPED;
+ }
+
mEvaluationResult = result;
mRedirectUrl = redirectUrl;
final NetworkTestResultParcelable p = new NetworkTestResultParcelable();
diff --git a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
index 0de2965..b1c167e 100644
--- a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
+++ b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
@@ -25,6 +25,7 @@
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_HTTPS;
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_PRIVDNS;
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_PARTIAL;
+import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_SKIPPED;
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_VALID;
import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_METERED;
@@ -1794,8 +1795,13 @@
@Test
public void testNoInternetCapabilityValidated() throws Exception {
- runNetworkTest(TEST_LINK_PROPERTIES, CELL_NO_INTERNET_CAPABILITIES,
- NETWORK_VALIDATION_RESULT_VALID, 0 /* probesSucceeded */, null /* redirectUrl */);
+ // For S+, the RESULT_SKIPPED bit will be included on networks that both do not require
+ // validation and for which validation is not performed.
+ final int validationResult = ShimUtils.isAtLeastS()
+ ? NETWORK_VALIDATION_RESULT_VALID | NETWORK_VALIDATION_RESULT_SKIPPED
+ : NETWORK_VALIDATION_RESULT_VALID;
+ runNetworkTest(TEST_LINK_PROPERTIES, CELL_NO_INTERNET_CAPABILITIES, validationResult,
+ 0 /* probesSucceeded */, null /* redirectUrl */);
verify(mCleartextDnsNetwork, never()).openConnection(any());
}
@@ -2678,8 +2684,12 @@
final NetworkCapabilities networkCapabilities =
new NetworkCapabilities(WIFI_OEM_PAID_CAPABILITIES);
networkCapabilities.removeCapability(NET_CAPABILITY_INTERNET);
+
+ final int validationResult = ShimUtils.isAtLeastS()
+ ? NETWORK_VALIDATION_RESULT_VALID | NETWORK_VALIDATION_RESULT_SKIPPED
+ : NETWORK_VALIDATION_RESULT_VALID;
runNetworkTest(TEST_LINK_PROPERTIES, networkCapabilities,
- NETWORK_VALIDATION_RESULT_VALID, 0 /* probesSucceeded */, null /* redirectUrl */);
+ validationResult, 0 /* probesSucceeded */, null /* redirectUrl */);
verify(mCleartextDnsNetwork, never()).openConnection(any());
verify(mHttpsConnection, never()).getResponseCode();