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
This commit is contained in:
@@ -368,7 +368,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
private static final int DEFAULT_NASCENT_DELAY_MS = 5_000;
|
private static final int DEFAULT_NASCENT_DELAY_MS = 5_000;
|
||||||
|
|
||||||
// The maximum value for the blocking validation result, in milliseconds.
|
// 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.
|
// The maximum number of network request allowed per uid before an exception is thrown.
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -4231,12 +4231,18 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
return nai.isCreated() && !nai.isDestroyed();
|
return nai.isCreated() && !nai.isDestroyed();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldIgnoreValidationFailureAfterRoam(NetworkAgentInfo nai) {
|
@VisibleForTesting
|
||||||
|
boolean shouldIgnoreValidationFailureAfterRoam(NetworkAgentInfo nai) {
|
||||||
// T+ devices should use unregisterAfterReplacement.
|
// T+ devices should use unregisterAfterReplacement.
|
||||||
if (SdkLevel.isAtLeastT()) return false;
|
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(
|
final long blockTimeOut = Long.valueOf(mResources.get().getInteger(
|
||||||
R.integer.config_validationFailureAfterRoamIgnoreTimeMillis));
|
R.integer.config_validationFailureAfterRoamIgnoreTimeMillis));
|
||||||
if (blockTimeOut <= MAX_VALIDATION_FAILURE_BLOCKING_TIME_MS
|
if (blockTimeOut <= MAX_VALIDATION_IGNORE_AFTER_ROAM_TIME_MS
|
||||||
&& blockTimeOut >= 0) {
|
&& blockTimeOut >= 0) {
|
||||||
final long currentTimeMs = SystemClock.elapsedRealtime();
|
final long currentTimeMs = SystemClock.elapsedRealtime();
|
||||||
long timeSinceLastRoam = currentTimeMs - nai.lastRoamTime;
|
long timeSinceLastRoam = currentTimeMs - nai.lastRoamTime;
|
||||||
@@ -9760,8 +9766,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
return ((VpnTransportInfo) ti).getType();
|
return ((VpnTransportInfo) ti).getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void maybeUpdateWifiRoamTimestamp(NetworkAgentInfo nai, NetworkCapabilities nc) {
|
private void maybeUpdateWifiRoamTimestamp(@NonNull NetworkAgentInfo nai,
|
||||||
if (nai == null) return;
|
@NonNull NetworkCapabilities nc) {
|
||||||
final TransportInfo prevInfo = nai.networkCapabilities.getTransportInfo();
|
final TransportInfo prevInfo = nai.networkCapabilities.getTransportInfo();
|
||||||
final TransportInfo newInfo = nc.getTransportInfo();
|
final TransportInfo newInfo = nc.getTransportInfo();
|
||||||
if (!(prevInfo instanceof WifiInfo) || !(newInfo instanceof WifiInfo)) {
|
if (!(prevInfo instanceof WifiInfo) || !(newInfo instanceof WifiInfo)) {
|
||||||
|
|||||||
@@ -16861,6 +16861,35 @@ public class ConnectivityServiceTest {
|
|||||||
doTestIgnoreValidationAfterRoam(5_000, enabled);
|
doTestIgnoreValidationAfterRoam(5_000, enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Test
|
||||||
public void testLegacyTetheringApiGuardWithProperPermission() throws Exception {
|
public void testLegacyTetheringApiGuardWithProperPermission() throws Exception {
|
||||||
final String testIface = "test0";
|
final String testIface = "test0";
|
||||||
|
|||||||
Reference in New Issue
Block a user