Disable ignoring validation on roam just after boot.
shouldIgnoreValidationFailureAfterRoam will incorrectly return
true in the first few seconds after boot even if the network
never roamed. This is extremely unlikely to happen, but add a
check for that just in case.
Fix: 230450214
Test: new unit test
Change-Id: I0789d9bdaa0bd9e78673e8f4248a2ca610052f1e
diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java
index 10b3dc8..0774e24 100755
--- a/service/src/com/android/server/ConnectivityService.java
+++ b/service/src/com/android/server/ConnectivityService.java
@@ -368,7 +368,7 @@
private static final int DEFAULT_NASCENT_DELAY_MS = 5_000;
// The maximum value for the blocking validation result, in milliseconds.
- public static final int MAX_VALIDATION_FAILURE_BLOCKING_TIME_MS = 10000;
+ public static final int MAX_VALIDATION_IGNORE_AFTER_ROAM_TIME_MS = 10000;
// The maximum number of network request allowed per uid before an exception is thrown.
@VisibleForTesting
@@ -4231,12 +4231,18 @@
return nai.isCreated() && !nai.isDestroyed();
}
- private boolean shouldIgnoreValidationFailureAfterRoam(NetworkAgentInfo nai) {
+ @VisibleForTesting
+ boolean shouldIgnoreValidationFailureAfterRoam(NetworkAgentInfo nai) {
// T+ devices should use unregisterAfterReplacement.
if (SdkLevel.isAtLeastT()) return false;
+
+ // If the network never roamed, return false. The check below is not sufficient if time
+ // since boot is less than blockTimeOut, though that's extremely unlikely to happen.
+ if (nai.lastRoamTime == 0) return false;
+
final long blockTimeOut = Long.valueOf(mResources.get().getInteger(
R.integer.config_validationFailureAfterRoamIgnoreTimeMillis));
- if (blockTimeOut <= MAX_VALIDATION_FAILURE_BLOCKING_TIME_MS
+ if (blockTimeOut <= MAX_VALIDATION_IGNORE_AFTER_ROAM_TIME_MS
&& blockTimeOut >= 0) {
final long currentTimeMs = SystemClock.elapsedRealtime();
long timeSinceLastRoam = currentTimeMs - nai.lastRoamTime;
@@ -9760,8 +9766,8 @@
return ((VpnTransportInfo) ti).getType();
}
- private void maybeUpdateWifiRoamTimestamp(NetworkAgentInfo nai, NetworkCapabilities nc) {
- if (nai == null) return;
+ private void maybeUpdateWifiRoamTimestamp(@NonNull NetworkAgentInfo nai,
+ @NonNull NetworkCapabilities nc) {
final TransportInfo prevInfo = nai.networkCapabilities.getTransportInfo();
final TransportInfo newInfo = nc.getTransportInfo();
if (!(prevInfo instanceof WifiInfo) || !(newInfo instanceof WifiInfo)) {
diff --git a/tests/unit/java/com/android/server/ConnectivityServiceTest.java b/tests/unit/java/com/android/server/ConnectivityServiceTest.java
index 9f3bed2..86b5241 100755
--- a/tests/unit/java/com/android/server/ConnectivityServiceTest.java
+++ b/tests/unit/java/com/android/server/ConnectivityServiceTest.java
@@ -16862,6 +16862,35 @@
}
@Test
+ public void testShouldIgnoreValidationFailureAfterRoam() {
+ // Always disabled on T+.
+ assumeFalse(SdkLevel.isAtLeastT());
+
+ NetworkAgentInfo nai = fakeWifiNai(new NetworkCapabilities());
+
+ // Enabled, but never roamed.
+ doReturn(5_000).when(mResources)
+ .getInteger(R.integer.config_validationFailureAfterRoamIgnoreTimeMillis);
+ assertEquals(0, nai.lastRoamTime);
+ assertFalse(mService.shouldIgnoreValidationFailureAfterRoam(nai));
+
+ // Roamed recently.
+ nai.lastRoamTime = SystemClock.elapsedRealtime() - 500 /* ms */;
+ assertTrue(mService.shouldIgnoreValidationFailureAfterRoam(nai));
+
+ // Disabled due to invalid setting (maximum is 10 seconds).
+ doReturn(15_000).when(mResources)
+ .getInteger(R.integer.config_validationFailureAfterRoamIgnoreTimeMillis);
+ assertFalse(mService.shouldIgnoreValidationFailureAfterRoam(nai));
+
+ // Disabled.
+ doReturn(-1).when(mResources)
+ .getInteger(R.integer.config_validationFailureAfterRoamIgnoreTimeMillis);
+ assertFalse(mService.shouldIgnoreValidationFailureAfterRoam(nai));
+ }
+
+
+ @Test
public void testLegacyTetheringApiGuardWithProperPermission() throws Exception {
final String testIface = "test0";
mServiceContext.setPermission(ACCESS_NETWORK_STATE, PERMISSION_DENIED);