Merge "Don't attempt to enable rate-limiting before T." am: 33f4e14073

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2010337

Change-Id: If26026f57421c51eb34f38c82229fd524b734299
This commit is contained in:
Treehugger Robot
2022-03-07 16:17:40 +00:00
committed by Automerger Merge Worker
2 changed files with 32 additions and 5 deletions

View File

@@ -10699,6 +10699,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
private boolean canNetworkBeRateLimited(@NonNull final NetworkAgentInfo networkAgent) { private boolean canNetworkBeRateLimited(@NonNull final NetworkAgentInfo networkAgent) {
// Rate-limiting cannot run correctly before T because the BPF program is not loaded.
if (!SdkLevel.isAtLeastT()) return false;
final NetworkCapabilities agentCaps = networkAgent.networkCapabilities; final NetworkCapabilities agentCaps = networkAgent.networkCapabilities;
// Only test networks (they cannot hold NET_CAPABILITY_INTERNET) and networks that provide // Only test networks (they cannot hold NET_CAPABILITY_INTERNET) and networks that provide
// internet connectivity can be rate limited. // internet connectivity can be rate limited.

View File

@@ -137,6 +137,9 @@ import static com.android.server.ConnectivityService.PREFERENCE_ORDER_VPN;
import static com.android.server.ConnectivityServiceTestUtils.transportToLegacyType; import static com.android.server.ConnectivityServiceTestUtils.transportToLegacyType;
import static com.android.testutils.ConcurrentUtils.await; import static com.android.testutils.ConcurrentUtils.await;
import static com.android.testutils.ConcurrentUtils.durationOf; import static com.android.testutils.ConcurrentUtils.durationOf;
import static com.android.testutils.DevSdkIgnoreRule.IgnoreAfter;
import static com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo;
import static com.android.testutils.DevSdkIgnoreRuleKt.SC_V2;
import static com.android.testutils.ExceptionUtils.ignoreExceptions; import static com.android.testutils.ExceptionUtils.ignoreExceptions;
import static com.android.testutils.HandlerUtils.waitForIdleSerialExecutor; import static com.android.testutils.HandlerUtils.waitForIdleSerialExecutor;
import static com.android.testutils.MiscAsserts.assertContainsAll; import static com.android.testutils.MiscAsserts.assertContainsAll;
@@ -358,6 +361,7 @@ import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.AdditionalAnswers; import org.mockito.AdditionalAnswers;
@@ -420,6 +424,9 @@ import kotlin.reflect.KClass;
public class ConnectivityServiceTest { public class ConnectivityServiceTest {
private static final String TAG = "ConnectivityServiceTest"; private static final String TAG = "ConnectivityServiceTest";
@Rule
public final DevSdkIgnoreRule ignoreRule = new DevSdkIgnoreRule();
private static final int TIMEOUT_MS = 2_000; private static final int TIMEOUT_MS = 2_000;
// Broadcasts can take a long time to be delivered. The test will not wait for that long unless // Broadcasts can take a long time to be delivered. The test will not wait for that long unless
// there is a failure, so use a long timeout. // there is a failure, so use a long timeout.
@@ -15397,7 +15404,7 @@ public class ConnectivityServiceTest {
null /* callingAttributionTag */)); null /* callingAttributionTag */));
} }
@Test @Test @IgnoreUpTo(SC_V2)
public void testUpdateRateLimit_EnableDisable() throws Exception { public void testUpdateRateLimit_EnableDisable() throws Exception {
final LinkProperties wifiLp = new LinkProperties(); final LinkProperties wifiLp = new LinkProperties();
wifiLp.setInterfaceName(WIFI_IFNAME); wifiLp.setInterfaceName(WIFI_IFNAME);
@@ -15436,7 +15443,7 @@ public class ConnectivityServiceTest {
it -> it.first == cellLp.getInterfaceName() && it.second == -1)); it -> it.first == cellLp.getInterfaceName() && it.second == -1));
} }
@Test @Test @IgnoreUpTo(SC_V2)
public void testUpdateRateLimit_WhenNewNetworkIsAdded() throws Exception { public void testUpdateRateLimit_WhenNewNetworkIsAdded() throws Exception {
final LinkProperties wifiLp = new LinkProperties(); final LinkProperties wifiLp = new LinkProperties();
wifiLp.setInterfaceName(WIFI_IFNAME); wifiLp.setInterfaceName(WIFI_IFNAME);
@@ -15462,7 +15469,7 @@ public class ConnectivityServiceTest {
&& it.second == rateLimitInBytesPerSec)); && it.second == rateLimitInBytesPerSec));
} }
@Test @Test @IgnoreUpTo(SC_V2)
public void testUpdateRateLimit_OnlyAffectsInternetCapableNetworks() throws Exception { public void testUpdateRateLimit_OnlyAffectsInternetCapableNetworks() throws Exception {
final LinkProperties wifiLp = new LinkProperties(); final LinkProperties wifiLp = new LinkProperties();
wifiLp.setInterfaceName(WIFI_IFNAME); wifiLp.setInterfaceName(WIFI_IFNAME);
@@ -15480,7 +15487,7 @@ public class ConnectivityServiceTest {
assertNull(readHeadWifi.poll(TIMEOUT_MS, it -> it.first == wifiLp.getInterfaceName())); assertNull(readHeadWifi.poll(TIMEOUT_MS, it -> it.first == wifiLp.getInterfaceName()));
} }
@Test @Test @IgnoreUpTo(SC_V2)
public void testUpdateRateLimit_DisconnectingResetsRateLimit() public void testUpdateRateLimit_DisconnectingResetsRateLimit()
throws Exception { throws Exception {
// Steps: // Steps:
@@ -15516,7 +15523,7 @@ public class ConnectivityServiceTest {
assertNull(readHeadWifi.poll(TIMEOUT_MS, it -> it.first == wifiLp.getInterfaceName())); assertNull(readHeadWifi.poll(TIMEOUT_MS, it -> it.first == wifiLp.getInterfaceName()));
} }
@Test @Test @IgnoreUpTo(SC_V2)
public void testUpdateRateLimit_UpdateExistingRateLimit() throws Exception { public void testUpdateRateLimit_UpdateExistingRateLimit() throws Exception {
final LinkProperties wifiLp = new LinkProperties(); final LinkProperties wifiLp = new LinkProperties();
wifiLp.setInterfaceName(WIFI_IFNAME); wifiLp.setInterfaceName(WIFI_IFNAME);
@@ -15545,4 +15552,21 @@ public class ConnectivityServiceTest {
it -> it.first == wifiLp.getInterfaceName() it -> it.first == wifiLp.getInterfaceName()
&& it.second == 2000)); && it.second == 2000));
} }
@Test @IgnoreAfter(SC_V2)
public void testUpdateRateLimit_DoesNothingBeforeT() throws Exception {
final LinkProperties wifiLp = new LinkProperties();
wifiLp.setInterfaceName(WIFI_IFNAME);
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI, wifiLp);
mWiFiNetworkAgent.connect(true);
waitForIdle();
final ArrayTrackRecord<Pair<String, Long>>.ReadHead readHead =
mDeps.mRateLimitHistory.newReadHead();
setIngressRateLimit(1000);
waitForIdle();
assertNull(readHead.poll(TEST_CALLBACK_TIMEOUT_MS, it -> true));
}
} }