Validate underlying network when VPN switches to unvalidated
Validation failures on VPN networks may be caused by problems
on the VPN network itself or a broken underlying network.
However, the existing mechanism can only detect if the VPN
network is usable or not.
To clarify the cause, this commit adds a mechanism to trigger
underlying network validation when VPN receives validation
failure. This will not only help to clarify the connectivity
issue but also trigger the possible system default network
switch if the breakage happens on the underlying network.
It might also trigger recovery (in the case of cell).
Bug: 296183603
Test: atest FrameworksNetTests
Change-Id: I4a2964001e0787b2c198fdcb2ef9d0819a45b4e8
diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java
index ff35b19..bfccd58 100644
--- a/services/core/java/com/android/server/connectivity/Vpn.java
+++ b/services/core/java/com/android/server/connectivity/Vpn.java
@@ -3066,7 +3066,8 @@
* <p>This variable controls the retry delay, and is reset when the VPN pass network
* validation.
*/
- private int mValidationFailRetryCount = 0;
+ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
+ int mValidationFailRetryCount = 0;
/**
* The number of attempts since the last successful connection.
@@ -3897,6 +3898,18 @@
// Skip other invalid status if the scheduled recovery exists.
if (mScheduledHandleDataStallFuture != null) return;
+ // Trigger network validation on the underlying network to possibly cause system
+ // switch default network or try recover if the current default network is broken.
+ //
+ // For the same underlying network, the first validation result should clarify if
+ // it's caused by broken underlying network. So only perform underlying network
+ // re-evaluation after first validation failure to prevent extra network resource
+ // costs on sending probes.
+ if (mValidationFailRetryCount == 0) {
+ mConnectivityManager.reportNetworkConnectivity(
+ mActiveNetwork, false /* hasConnectivity */);
+ }
+
if (mValidationFailRetryCount < MAX_MOBIKE_RECOVERY_ATTEMPT) {
Log.d(TAG, "Validation failed");