Instrument SDK level and change IDs to help testing

This patch mocks the SDK level and/or change IDs to help
developing functionality that depends on these without
having to flash a new device every time.

Test: TH
Change-Id: I1011193c99e123a0e5501ed313c9cecbceebdae6
This commit is contained in:
Chalard Jean
2023-05-29 17:02:43 +09:00
parent c8fee363bb
commit df29a85ee7
2 changed files with 144 additions and 68 deletions

View File

@@ -1278,6 +1278,18 @@ public class ConnectivityService extends IConnectivityManager.Stub
return Binder.getCallingUid(); return Binder.getCallingUid();
} }
public boolean isAtLeastS() {
return SdkLevel.isAtLeastS();
}
public boolean isAtLeastT() {
return SdkLevel.isAtLeastT();
}
public boolean isAtLeastU() {
return SdkLevel.isAtLeastU();
}
/** /**
* Get system properties to use in ConnectivityService. * Get system properties to use in ConnectivityService.
*/ */
@@ -1390,7 +1402,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
@Nullable @Nullable
public CarrierPrivilegeAuthenticator makeCarrierPrivilegeAuthenticator( public CarrierPrivilegeAuthenticator makeCarrierPrivilegeAuthenticator(
@NonNull final Context context, @NonNull final TelephonyManager tm) { @NonNull final Context context, @NonNull final TelephonyManager tm) {
if (SdkLevel.isAtLeastT()) { if (isAtLeastT()) {
return new CarrierPrivilegeAuthenticator(context, tm); return new CarrierPrivilegeAuthenticator(context, tm);
} else { } else {
return null; return null;
@@ -1497,6 +1509,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
return CompatChanges.isChangeEnabled(changeId, packageName, user); return CompatChanges.isChangeEnabled(changeId, packageName, user);
} }
/**
* As above but with a UID.
* @see CompatChanges#isChangeEnabled(long, int)
*/
public boolean isChangeEnabled(final long changeId, final int uid) {
return CompatChanges.isChangeEnabled(changeId, uid);
}
/** /**
* Call {@link InetDiagMessage#destroyLiveTcpSockets(Set, Set)} * Call {@link InetDiagMessage#destroyLiveTcpSockets(Set, Set)}
* *
@@ -1710,7 +1730,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
// Even if it could, running on S would at least require mocking out the BPF map, // Even if it could, running on S would at least require mocking out the BPF map,
// otherwise the unit tests will fail on pre-T devices where the seccomp filter blocks // otherwise the unit tests will fail on pre-T devices where the seccomp filter blocks
// the bpf syscall. http://aosp/1907693 // the bpf syscall. http://aosp/1907693
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
mDscpPolicyTracker = new DscpPolicyTracker(); mDscpPolicyTracker = new DscpPolicyTracker();
} }
} catch (ErrnoException e) { } catch (ErrnoException e) {
@@ -1720,13 +1740,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
mIngressRateLimit = ConnectivitySettingsManager.getIngressRateLimitInBytesPerSecond( mIngressRateLimit = ConnectivitySettingsManager.getIngressRateLimitInBytesPerSecond(
mContext); mContext);
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
mCdmps = new CompanionDeviceManagerProxyService(context); mCdmps = new CompanionDeviceManagerProxyService(context);
} else { } else {
mCdmps = null; mCdmps = null;
} }
if (SdkLevel.isAtLeastU() if (mDeps.isAtLeastU()
&& mDeps.isFeatureEnabled(context, KEY_DESTROY_FROZEN_SOCKETS_VERSION)) { && mDeps.isFeatureEnabled(context, KEY_DESTROY_FROZEN_SOCKETS_VERSION)) {
final UidFrozenStateChangedCallback frozenStateChangedCallback = final UidFrozenStateChangedCallback frozenStateChangedCallback =
new UidFrozenStateChangedCallback() { new UidFrozenStateChangedCallback() {
@@ -3229,7 +3249,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
private void applyMostRecentPolicyForConnectivityAction(BroadcastOptions options, private void applyMostRecentPolicyForConnectivityAction(BroadcastOptions options,
NetworkInfo info) { NetworkInfo info) {
// Delivery group policy APIs are only available on U+. // Delivery group policy APIs are only available on U+.
if (!SdkLevel.isAtLeastU()) return; if (!mDeps.isAtLeastU()) return;
final BroadcastOptionsShim optsShim = mDeps.makeBroadcastOptionsShim(options); final BroadcastOptionsShim optsShim = mDeps.makeBroadcastOptionsShim(options);
try { try {
@@ -3307,7 +3327,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
// On T+ devices, register callback for statsd to pull NETWORK_BPF_MAP_INFO atom // On T+ devices, register callback for statsd to pull NETWORK_BPF_MAP_INFO atom
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
mBpfNetMaps.setPullAtomCallback(mContext); mBpfNetMaps.setPullAtomCallback(mContext);
} }
// Wait PermissionMonitor to finish the permission update. Then MultipathPolicyTracker won't // Wait PermissionMonitor to finish the permission update. Then MultipathPolicyTracker won't
@@ -4517,7 +4537,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
@VisibleForTesting @VisibleForTesting
boolean shouldIgnoreValidationFailureAfterRoam(NetworkAgentInfo nai) { boolean shouldIgnoreValidationFailureAfterRoam(NetworkAgentInfo nai) {
// T+ devices should use unregisterAfterReplacement. // T+ devices should use unregisterAfterReplacement.
if (SdkLevel.isAtLeastT()) return false; if (mDeps.isAtLeastT()) return false;
// If the network never roamed, return false. The check below is not sufficient if time // 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. // since boot is less than blockTimeOut, though that's extremely unlikely to happen.
@@ -4656,7 +4676,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
// for an unnecessarily long time. // for an unnecessarily long time.
destroyNativeNetwork(nai); destroyNativeNetwork(nai);
} }
if (!nai.isCreated() && !SdkLevel.isAtLeastT()) { if (!nai.isCreated() && !mDeps.isAtLeastT()) {
// Backwards compatibility: send onNetworkDestroyed even if network was never created. // Backwards compatibility: send onNetworkDestroyed even if network was never created.
// This can never run if the code above runs because shouldDestroyNativeNetwork is // This can never run if the code above runs because shouldDestroyNativeNetwork is
// false if the network was never created. // false if the network was never created.
@@ -4740,7 +4760,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
private void checkNrisConsistency(final NetworkRequestInfo nri) { private void checkNrisConsistency(final NetworkRequestInfo nri) {
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
for (final NetworkRequestInfo n : mNetworkRequests.values()) { for (final NetworkRequestInfo n : mNetworkRequests.values()) {
if (n.mBinder != null && n.mBinder == nri.mBinder) { if (n.mBinder != null && n.mBinder == nri.mBinder) {
// Temporary help to debug b/194394697 ; TODO : remove this function when the // Temporary help to debug b/194394697 ; TODO : remove this function when the
@@ -6330,7 +6350,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
+ Arrays.toString(ranges) + "): netd command failed: " + e); + Arrays.toString(ranges) + "): netd command failed: " + e);
} }
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
mPermissionMonitor.updateVpnLockdownUidRanges(requireVpn, ranges); mPermissionMonitor.updateVpnLockdownUidRanges(requireVpn, ranges);
} }
@@ -7124,7 +7144,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
@NonNull final NetworkCapabilities networkCapabilities) { @NonNull final NetworkCapabilities networkCapabilities) {
// This check is added to fix the linter error for "current min is 30", which is not going // This check is added to fix the linter error for "current min is 30", which is not going
// to happen because Connectivity service always run in S+. // to happen because Connectivity service always run in S+.
if (!SdkLevel.isAtLeastS()) { if (!mDeps.isAtLeastS()) {
Log.wtf(TAG, "Connectivity service should always run in at least SDK S"); Log.wtf(TAG, "Connectivity service should always run in at least SDK S");
return; return;
} }
@@ -8561,7 +8581,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
// On T and above, allow rules are needed for all VPNs. Allow rule with null iface is a // On T and above, allow rules are needed for all VPNs. Allow rule with null iface is a
// wildcard to allow apps to receive packets on all interfaces. This is required to accept // wildcard to allow apps to receive packets on all interfaces. This is required to accept
// incoming traffic in Lockdown mode by overriding the Lockdown blocking rule. // incoming traffic in Lockdown mode by overriding the Lockdown blocking rule.
return SdkLevel.isAtLeastT() && nai.isVPN() && lp != null && lp.getInterfaceName() != null; return mDeps.isAtLeastT() && nai.isVPN() && lp != null && lp.getInterfaceName() != null;
} }
private static UidRangeParcel[] toUidRangeStableParcels(final @NonNull Set<UidRange> ranges) { private static UidRangeParcel[] toUidRangeStableParcels(final @NonNull Set<UidRange> ranges) {
@@ -8809,14 +8829,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
try { try {
if (DBG) log("Sending " + pendingIntent); if (DBG) log("Sending " + pendingIntent);
final BroadcastOptions options = BroadcastOptions.makeBasic(); final BroadcastOptions options = BroadcastOptions.makeBasic();
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
// Explicitly disallow the receiver from starting activities, to prevent apps from // Explicitly disallow the receiver from starting activities, to prevent apps from
// utilizing the PendingIntent as a backdoor to do this. // utilizing the PendingIntent as a backdoor to do this.
options.setPendingIntentBackgroundActivityLaunchAllowed(false); options.setPendingIntentBackgroundActivityLaunchAllowed(false);
} }
pendingIntent.send(mContext, 0, intent, this /* onFinished */, null /* Handler */, pendingIntent.send(mContext, 0, intent, this /* onFinished */, null /* Handler */,
null /* requiredPermission */, null /* requiredPermission */,
SdkLevel.isAtLeastT() ? options.toBundle() : null); mDeps.isAtLeastT() ? options.toBundle() : null);
} catch (PendingIntent.CanceledException e) { } catch (PendingIntent.CanceledException e) {
if (DBG) log(pendingIntent + " was not sent, it had been canceled."); if (DBG) log(pendingIntent + " was not sent, it had been canceled.");
mPendingIntentWakeLock.release(); mPendingIntentWakeLock.release();
@@ -9095,7 +9115,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
private void updateProfileAllowedNetworks() { private void updateProfileAllowedNetworks() {
// Netd command is not implemented before U. // Netd command is not implemented before U.
if (!SdkLevel.isAtLeastU()) return; if (!mDeps.isAtLeastU()) return;
ensureRunningOnConnectivityServiceThread(); ensureRunningOnConnectivityServiceThread();
final ArrayList<NativeUidRangeConfig> configs = new ArrayList<>(); final ArrayList<NativeUidRangeConfig> configs = new ArrayList<>();
@@ -9831,7 +9851,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
// in the absence of a satisfactory, scalable solution which follows an easy/standard // in the absence of a satisfactory, scalable solution which follows an easy/standard
// process to check the interface version, just use an SDK check. NetworkStack will // process to check the interface version, just use an SDK check. NetworkStack will
// always be new enough when running on T+. // always be new enough when running on T+.
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
networkAgent.networkMonitor().notifyNetworkConnected(params); networkAgent.networkMonitor().notifyNetworkConnected(params);
} else { } else {
networkAgent.networkMonitor().notifyNetworkConnected(params.linkProperties, networkAgent.networkMonitor().notifyNetworkConnected(params.linkProperties,
@@ -11307,7 +11327,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
if (um.isManagedProfile(profile.getIdentifier())) { if (um.isManagedProfile(profile.getIdentifier())) {
return true; return true;
} }
if (SdkLevel.isAtLeastT() && dpm.getDeviceOwner() != null) return true; if (mDeps.isAtLeastT() && dpm.getDeviceOwner() != null) return true;
return false; return false;
} }
@@ -11589,7 +11609,7 @@ 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. // Rate-limiting cannot run correctly before T because the BPF program is not loaded.
if (!SdkLevel.isAtLeastT()) return false; if (!mDeps.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
@@ -12096,7 +12116,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }
if (SdkLevel.isAtLeastU() && enable) { if (mDeps.isAtLeastU() && enable) {
try { try {
closeSocketsForFirewallChainLocked(chain); closeSocketsForFirewallChainLocked(chain);
} catch (ErrnoException | SocketException | InterruptedIOException e) { } catch (ErrnoException | SocketException | InterruptedIOException e) {

View File

@@ -167,6 +167,7 @@ import static com.android.testutils.DevSdkIgnoreRule.IgnoreAfter;
import static com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo; import static com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo;
import static com.android.testutils.DevSdkIgnoreRuleKt.SC_V2; import static com.android.testutils.DevSdkIgnoreRuleKt.SC_V2;
import static com.android.testutils.FunctionalUtils.ignoreExceptions; import static com.android.testutils.FunctionalUtils.ignoreExceptions;
import static com.android.testutils.HandlerUtils.visibleOnHandlerThread;
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;
import static com.android.testutils.MiscAsserts.assertContainsExactly; import static com.android.testutils.MiscAsserts.assertContainsExactly;
@@ -376,7 +377,6 @@ import com.android.internal.net.VpnProfile;
import com.android.internal.util.WakeupMessage; import com.android.internal.util.WakeupMessage;
import com.android.internal.util.test.BroadcastInterceptingContext; import com.android.internal.util.test.BroadcastInterceptingContext;
import com.android.internal.util.test.FakeSettingsProvider; import com.android.internal.util.test.FakeSettingsProvider;
import com.android.modules.utils.build.SdkLevel;
import com.android.net.module.util.ArrayTrackRecord; import com.android.net.module.util.ArrayTrackRecord;
import com.android.net.module.util.CollectionUtils; import com.android.net.module.util.CollectionUtils;
import com.android.net.module.util.LocationPermissionChecker; import com.android.net.module.util.LocationPermissionChecker;
@@ -869,7 +869,7 @@ public class ConnectivityServiceTest {
@Override @Override
public void sendStickyBroadcast(Intent intent, Bundle options) { public void sendStickyBroadcast(Intent intent, Bundle options) {
// Verify that delivery group policy APIs were used on U. // Verify that delivery group policy APIs were used on U.
if (SdkLevel.isAtLeastU() && CONNECTIVITY_ACTION.equals(intent.getAction())) { if (mDeps.isAtLeastU() && CONNECTIVITY_ACTION.equals(intent.getAction())) {
final NetworkInfo ni = intent.getParcelableExtra(EXTRA_NETWORK_INFO, final NetworkInfo ni = intent.getParcelableExtra(EXTRA_NETWORK_INFO,
NetworkInfo.class); NetworkInfo.class);
try { try {
@@ -1085,7 +1085,7 @@ public class ConnectivityServiceTest {
} }
private void onValidationRequested() throws Exception { private void onValidationRequested() throws Exception {
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
verify(mNetworkMonitor).notifyNetworkConnectedParcel(any()); verify(mNetworkMonitor).notifyNetworkConnectedParcel(any());
} else { } else {
verify(mNetworkMonitor).notifyNetworkConnected(any(), any()); verify(mNetworkMonitor).notifyNetworkConnected(any(), any());
@@ -1932,6 +1932,7 @@ public class ConnectivityServiceTest {
class ConnectivityServiceDependencies extends ConnectivityService.Dependencies { class ConnectivityServiceDependencies extends ConnectivityService.Dependencies {
final ConnectivityResources mConnRes; final ConnectivityResources mConnRes;
final ArraySet<Pair<Long, Integer>> mEnabledChangeIds = new ArraySet<>();
ConnectivityServiceDependencies(final Context mockResContext) { ConnectivityServiceDependencies(final Context mockResContext) {
mConnRes = new ConnectivityResources(mockResContext); mConnRes = new ConnectivityResources(mockResContext);
@@ -1997,7 +1998,7 @@ public class ConnectivityServiceTest {
@Override @Override
public CarrierPrivilegeAuthenticator makeCarrierPrivilegeAuthenticator( public CarrierPrivilegeAuthenticator makeCarrierPrivilegeAuthenticator(
@NonNull final Context context, @NonNull final TelephonyManager tm) { @NonNull final Context context, @NonNull final TelephonyManager tm) {
return SdkLevel.isAtLeastT() ? mCarrierPrivilegeAuthenticator : null; return mDeps.isAtLeastT() ? mCarrierPrivilegeAuthenticator : null;
} }
@Override @Override
@@ -2096,6 +2097,61 @@ public class ConnectivityServiceTest {
} }
} }
public void setChangeIdEnabled(final boolean enabled, final long changeId, final int uid) {
final Pair<Long, Integer> data = new Pair<>(changeId, uid);
// mEnabledChangeIds is read on the handler thread and maybe the test thread, so
// make sure both threads see it before continuing.
visibleOnHandlerThread(mCsHandlerThread.getThreadHandler(), () -> {
if (enabled) {
mEnabledChangeIds.add(data);
} else {
mEnabledChangeIds.remove(data);
}
});
}
@Override
public boolean isChangeEnabled(final long changeId, final int uid) {
return mEnabledChangeIds.contains(new Pair<>(changeId, uid));
}
// In AOSP, build version codes are all over the place (e.g. at the time of this writing
// U == V). Define custom ones.
private static final int VERSION_UNMOCKED = -1;
private static final int VERSION_R = 1;
private static final int VERSION_S = 2;
private static final int VERSION_T = 3;
private static final int VERSION_U = 4;
private static final int VERSION_V = 5;
private static final int VERSION_MAX = VERSION_V;
private int mSdkLevel = VERSION_UNMOCKED;
private void setBuildSdk(final int sdkLevel) {
if (sdkLevel > VERSION_MAX) {
throw new IllegalArgumentException("setBuildSdk must not be called with"
+ " Build.VERSION constants but Dependencies.VERSION_* constants");
}
visibleOnHandlerThread(mCsHandlerThread.getThreadHandler(), () -> mSdkLevel = sdkLevel);
}
@Override
public boolean isAtLeastS() {
return mSdkLevel == VERSION_UNMOCKED ? super.isAtLeastS()
: mSdkLevel >= VERSION_S;
}
@Override
public boolean isAtLeastT() {
return mSdkLevel == VERSION_UNMOCKED ? super.isAtLeastT()
: mSdkLevel >= VERSION_T;
}
@Override
public boolean isAtLeastU() {
return mSdkLevel == VERSION_UNMOCKED ? super.isAtLeastU()
: mSdkLevel >= VERSION_U;
}
@Override @Override
public BpfNetMaps getBpfNetMaps(Context context, INetd netd) { public BpfNetMaps getBpfNetMaps(Context context, INetd netd) {
return mBpfNetMaps; return mBpfNetMaps;
@@ -5933,7 +5989,7 @@ public class ConnectivityServiceTest {
doReturn(0).when(mResources).getInteger(R.integer.config_activelyPreferBadWifi); doReturn(0).when(mResources).getInteger(R.integer.config_activelyPreferBadWifi);
mPolicyTracker.reevaluate(); mPolicyTracker.reevaluate();
waitForIdle(); waitForIdle();
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
// U+ ignore the setting and always actively prefers bad wifi // U+ ignore the setting and always actively prefers bad wifi
assertTrue(mService.mNetworkRanker.getConfiguration().activelyPreferBadWifi()); assertTrue(mService.mNetworkRanker.getConfiguration().activelyPreferBadWifi());
} else { } else {
@@ -6103,7 +6159,7 @@ public class ConnectivityServiceTest {
@Test @Test
public void testPreferBadWifi_doNotAvoid_doNotPrefer() throws Exception { public void testPreferBadWifi_doNotAvoid_doNotPrefer() throws Exception {
// Starting with U this mode is no longer supported and can't actually be tested // Starting with U this mode is no longer supported and can't actually be tested
assumeFalse(SdkLevel.isAtLeastU()); assumeFalse(mDeps.isAtLeastU());
doTestPreferBadWifi(false /* avoidBadWifi */, false /* preferBadWifi */, doTestPreferBadWifi(false /* avoidBadWifi */, false /* preferBadWifi */,
timeout -> timeout < 14_000); timeout -> timeout < 14_000);
} }
@@ -9772,7 +9828,7 @@ public class ConnectivityServiceTest {
final Set<Integer> excludedUids = new ArraySet<Integer>(); final Set<Integer> excludedUids = new ArraySet<Integer>();
excludedUids.add(VPN_UID); excludedUids.add(VPN_UID);
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
// On T onwards, the corresponding SDK sandbox UID should also be excluded // On T onwards, the corresponding SDK sandbox UID should also be excluded
excludedUids.add(toSdkSandboxUid(VPN_UID)); excludedUids.add(toSdkSandboxUid(VPN_UID));
} }
@@ -9820,7 +9876,7 @@ public class ConnectivityServiceTest {
vpnDefaultCallbackAsUid.assertNoCallback(); vpnDefaultCallbackAsUid.assertNoCallback();
excludedUids.add(uid); excludedUids.add(uid);
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
// On T onwards, the corresponding SDK sandbox UID should also be excluded // On T onwards, the corresponding SDK sandbox UID should also be excluded
excludedUids.add(toSdkSandboxUid(uid)); excludedUids.add(toSdkSandboxUid(uid));
} }
@@ -10554,7 +10610,7 @@ public class ConnectivityServiceTest {
private void verifyClatdStart(@Nullable InOrder inOrder, @NonNull String iface, int netId, private void verifyClatdStart(@Nullable InOrder inOrder, @NonNull String iface, int netId,
@NonNull String nat64Prefix) throws Exception { @NonNull String nat64Prefix) throws Exception {
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
verifyWithOrder(inOrder, mClatCoordinator) verifyWithOrder(inOrder, mClatCoordinator)
.clatStart(eq(iface), eq(netId), eq(new IpPrefix(nat64Prefix))); .clatStart(eq(iface), eq(netId), eq(new IpPrefix(nat64Prefix)));
} else { } else {
@@ -10564,7 +10620,7 @@ public class ConnectivityServiceTest {
private void verifyNeverClatdStart(@Nullable InOrder inOrder, @NonNull String iface) private void verifyNeverClatdStart(@Nullable InOrder inOrder, @NonNull String iface)
throws Exception { throws Exception {
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
verifyNeverWithOrder(inOrder, mClatCoordinator).clatStart(eq(iface), anyInt(), any()); verifyNeverWithOrder(inOrder, mClatCoordinator).clatStart(eq(iface), anyInt(), any());
} else { } else {
verifyNeverWithOrder(inOrder, mMockNetd).clatdStart(eq(iface), anyString()); verifyNeverWithOrder(inOrder, mMockNetd).clatdStart(eq(iface), anyString());
@@ -10573,7 +10629,7 @@ public class ConnectivityServiceTest {
private void verifyClatdStop(@Nullable InOrder inOrder, @NonNull String iface) private void verifyClatdStop(@Nullable InOrder inOrder, @NonNull String iface)
throws Exception { throws Exception {
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
verifyWithOrder(inOrder, mClatCoordinator).clatStop(); verifyWithOrder(inOrder, mClatCoordinator).clatStop();
} else { } else {
verifyWithOrder(inOrder, mMockNetd).clatdStop(eq(iface)); verifyWithOrder(inOrder, mMockNetd).clatdStop(eq(iface));
@@ -10582,7 +10638,7 @@ public class ConnectivityServiceTest {
private void verifyNeverClatdStop(@Nullable InOrder inOrder, @NonNull String iface) private void verifyNeverClatdStop(@Nullable InOrder inOrder, @NonNull String iface)
throws Exception { throws Exception {
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
verifyNeverWithOrder(inOrder, mClatCoordinator).clatStop(); verifyNeverWithOrder(inOrder, mClatCoordinator).clatStop();
} else { } else {
verifyNeverWithOrder(inOrder, mMockNetd).clatdStop(eq(iface)); verifyNeverWithOrder(inOrder, mMockNetd).clatdStop(eq(iface));
@@ -10775,7 +10831,7 @@ public class ConnectivityServiceTest {
networkCallback.assertNoCallback(); networkCallback.assertNoCallback();
verify(mMockNetd, times(1)).networkRemoveInterface(cellNetId, CLAT_MOBILE_IFNAME); verify(mMockNetd, times(1)).networkRemoveInterface(cellNetId, CLAT_MOBILE_IFNAME);
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
verifyWakeupModifyInterface(CLAT_MOBILE_IFNAME, false); verifyWakeupModifyInterface(CLAT_MOBILE_IFNAME, false);
} }
@@ -10815,7 +10871,7 @@ public class ConnectivityServiceTest {
assertRoutesAdded(cellNetId, stackedDefault); assertRoutesAdded(cellNetId, stackedDefault);
verify(mMockNetd, times(1)).networkAddInterface(cellNetId, CLAT_MOBILE_IFNAME); verify(mMockNetd, times(1)).networkAddInterface(cellNetId, CLAT_MOBILE_IFNAME);
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
verifyWakeupModifyInterface(CLAT_MOBILE_IFNAME, true); verifyWakeupModifyInterface(CLAT_MOBILE_IFNAME, true);
} }
@@ -10834,7 +10890,7 @@ public class ConnectivityServiceTest {
verify(mMockNetd, times(1)).networkRemoveInterface(cellNetId, CLAT_MOBILE_IFNAME); verify(mMockNetd, times(1)).networkRemoveInterface(cellNetId, CLAT_MOBILE_IFNAME);
verify(mMockNetd, times(1)).interfaceGetCfg(CLAT_MOBILE_IFNAME); verify(mMockNetd, times(1)).interfaceGetCfg(CLAT_MOBILE_IFNAME);
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
verifyWakeupModifyInterface(CLAT_MOBILE_IFNAME, false); verifyWakeupModifyInterface(CLAT_MOBILE_IFNAME, false);
} }
@@ -10845,13 +10901,13 @@ public class ConnectivityServiceTest {
verify(mMockNetd, times(1)).idletimerRemoveInterface(eq(MOBILE_IFNAME), anyInt(), verify(mMockNetd, times(1)).idletimerRemoveInterface(eq(MOBILE_IFNAME), anyInt(),
eq(Integer.toString(TRANSPORT_CELLULAR))); eq(Integer.toString(TRANSPORT_CELLULAR)));
verify(mMockNetd).networkDestroy(cellNetId); verify(mMockNetd).networkDestroy(cellNetId);
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
verify(mMockNetd).setNetworkAllowlist(any()); verify(mMockNetd).setNetworkAllowlist(any());
} else { } else {
verify(mMockNetd, never()).setNetworkAllowlist(any()); verify(mMockNetd, never()).setNetworkAllowlist(any());
} }
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
verifyWakeupModifyInterface(MOBILE_IFNAME, false); verifyWakeupModifyInterface(MOBILE_IFNAME, false);
} }
@@ -10885,7 +10941,7 @@ public class ConnectivityServiceTest {
// assertRoutesAdded sees all calls since last mMockNetd reset, so expect IPv6 routes again. // assertRoutesAdded sees all calls since last mMockNetd reset, so expect IPv6 routes again.
assertRoutesAdded(cellNetId, ipv6Subnet, ipv6Default, stackedDefault); assertRoutesAdded(cellNetId, ipv6Subnet, ipv6Default, stackedDefault);
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
verifyWakeupModifyInterface(MOBILE_IFNAME, true); verifyWakeupModifyInterface(MOBILE_IFNAME, true);
} }
@@ -10898,20 +10954,20 @@ public class ConnectivityServiceTest {
networkCallback.assertNoCallback(); networkCallback.assertNoCallback();
verifyClatdStop(null /* inOrder */, MOBILE_IFNAME); verifyClatdStop(null /* inOrder */, MOBILE_IFNAME);
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
verifyWakeupModifyInterface(CLAT_MOBILE_IFNAME, false); verifyWakeupModifyInterface(CLAT_MOBILE_IFNAME, false);
} }
verify(mMockNetd).idletimerRemoveInterface(eq(MOBILE_IFNAME), anyInt(), verify(mMockNetd).idletimerRemoveInterface(eq(MOBILE_IFNAME), anyInt(),
eq(Integer.toString(TRANSPORT_CELLULAR))); eq(Integer.toString(TRANSPORT_CELLULAR)));
verify(mMockNetd).networkDestroy(cellNetId); verify(mMockNetd).networkDestroy(cellNetId);
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
verify(mMockNetd).setNetworkAllowlist(any()); verify(mMockNetd).setNetworkAllowlist(any());
} else { } else {
verify(mMockNetd, never()).setNetworkAllowlist(any()); verify(mMockNetd, never()).setNetworkAllowlist(any());
} }
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
verifyWakeupModifyInterface(MOBILE_IFNAME, false); verifyWakeupModifyInterface(MOBILE_IFNAME, false);
} }
@@ -11352,7 +11408,7 @@ public class ConnectivityServiceTest {
mMockVpn.establish(lp, uid, vpnRange); mMockVpn.establish(lp, uid, vpnRange);
assertVpnUidRangesUpdated(true, vpnRange, uid); assertVpnUidRangesUpdated(true, vpnRange, uid);
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
// On T and above, VPN should have rules for null interface. Null Interface is a // On T and above, VPN should have rules for null interface. Null Interface is a
// wildcard and this accepts traffic from all the interfaces. // wildcard and this accepts traffic from all the interfaces.
// There are two expected invocations, one during the VPN initial // There are two expected invocations, one during the VPN initial
@@ -12341,7 +12397,7 @@ public class ConnectivityServiceTest {
@Test @Test
public void testUnderlyingNetworksWillBeSetInNetworkAgentInfoConstructor() throws Exception { public void testUnderlyingNetworksWillBeSetInNetworkAgentInfoConstructor() throws Exception {
assumeTrue(SdkLevel.isAtLeastT()); assumeTrue(mDeps.isAtLeastT());
final Network network1 = new Network(100); final Network network1 = new Network(100);
final Network network2 = new Network(101); final Network network2 = new Network(101);
final List<Network> underlyingNetworks = new ArrayList<>(); final List<Network> underlyingNetworks = new ArrayList<>();
@@ -16234,7 +16290,7 @@ public class ConnectivityServiceTest {
mCellAgent.getNetwork().netId, mCellAgent.getNetwork().netId,
toUidRangeStableParcels(allowedRanges), toUidRangeStableParcels(allowedRanges),
0 /* subPriority */); 0 /* subPriority */);
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[]{config1User}); inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[]{config1User});
} else { } else {
inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any()); inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any());
@@ -16252,7 +16308,7 @@ public class ConnectivityServiceTest {
mCellAgent.getNetwork().netId, mCellAgent.getNetwork().netId,
toUidRangeStableParcels(allowedRanges), toUidRangeStableParcels(allowedRanges),
0 /* subPriority */); 0 /* subPriority */);
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[]{config2Users}); inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[]{config2Users});
} else { } else {
inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any()); inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any());
@@ -16283,7 +16339,7 @@ public class ConnectivityServiceTest {
mCellAgent.getNetwork().netId, mCellAgent.getNetwork().netId,
allowAllUidRangesParcel, allowAllUidRangesParcel,
0 /* subPriority */); 0 /* subPriority */);
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
inOrder.verify(mMockNetd).setNetworkAllowlist( inOrder.verify(mMockNetd).setNetworkAllowlist(
new NativeUidRangeConfig[]{cellAllAllowedConfig}); new NativeUidRangeConfig[]{cellAllAllowedConfig});
} else { } else {
@@ -16302,7 +16358,7 @@ public class ConnectivityServiceTest {
// making the order of the list undeterministic. Thus, verify this in order insensitive way. // making the order of the list undeterministic. Thus, verify this in order insensitive way.
final ArgumentCaptor<NativeUidRangeConfig[]> configsCaptor = ArgumentCaptor.forClass( final ArgumentCaptor<NativeUidRangeConfig[]> configsCaptor = ArgumentCaptor.forClass(
NativeUidRangeConfig[].class); NativeUidRangeConfig[].class);
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture()); inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture());
assertContainsAll(List.of(configsCaptor.getValue()), assertContainsAll(List.of(configsCaptor.getValue()),
List.of(cellAllAllowedConfig, enterpriseAllAllowedConfig)); List.of(cellAllAllowedConfig, enterpriseAllAllowedConfig));
@@ -16336,7 +16392,7 @@ public class ConnectivityServiceTest {
mCellAgent.getNetwork().netId, mCellAgent.getNetwork().netId,
excludeAppRangesParcel, excludeAppRangesParcel,
0 /* subPriority */); 0 /* subPriority */);
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture()); inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture());
assertContainsAll(List.of(configsCaptor.getValue()), assertContainsAll(List.of(configsCaptor.getValue()),
List.of(cellExcludeAppConfig, enterpriseAllAllowedConfig)); List.of(cellExcludeAppConfig, enterpriseAllAllowedConfig));
@@ -16348,7 +16404,7 @@ public class ConnectivityServiceTest {
mCm.setProfileNetworkPreference(testHandle, PROFILE_NETWORK_PREFERENCE_ENTERPRISE, mCm.setProfileNetworkPreference(testHandle, PROFILE_NETWORK_PREFERENCE_ENTERPRISE,
r -> r.run(), listener); r -> r.run(), listener);
listener.expectOnComplete(); listener.expectOnComplete();
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture()); inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture());
assertContainsAll(List.of(configsCaptor.getValue()), assertContainsAll(List.of(configsCaptor.getValue()),
List.of(cellAllAllowedConfig, enterpriseAllAllowedConfig)); List.of(cellAllAllowedConfig, enterpriseAllAllowedConfig));
@@ -16360,7 +16416,7 @@ public class ConnectivityServiceTest {
// disconnects. // disconnects.
enterpriseAgent.disconnect(); enterpriseAgent.disconnect();
waitForIdle(); waitForIdle();
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
inOrder.verify(mMockNetd).setNetworkAllowlist( inOrder.verify(mMockNetd).setNetworkAllowlist(
new NativeUidRangeConfig[]{cellAllAllowedConfig}); new NativeUidRangeConfig[]{cellAllAllowedConfig});
} else { } else {
@@ -16385,7 +16441,7 @@ public class ConnectivityServiceTest {
List.of(prefBuilder.build()), List.of(prefBuilder.build()),
r -> r.run(), listener); r -> r.run(), listener);
listener.expectOnComplete(); listener.expectOnComplete();
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[]{}); inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[]{});
} else { } else {
inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any()); inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any());
@@ -16413,7 +16469,7 @@ public class ConnectivityServiceTest {
mCellAgent.getNetwork().netId, mCellAgent.getNetwork().netId,
excludeAppRangesParcel, excludeAppRangesParcel,
0 /* subPriority */); 0 /* subPriority */);
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
inOrder.verify(mMockNetd).setNetworkAllowlist( inOrder.verify(mMockNetd).setNetworkAllowlist(
new NativeUidRangeConfig[]{cellExcludeAppConfig}); new NativeUidRangeConfig[]{cellExcludeAppConfig});
} else { } else {
@@ -16437,7 +16493,7 @@ public class ConnectivityServiceTest {
// making the order of the list undeterministic. Thus, verify this in order insensitive way. // making the order of the list undeterministic. Thus, verify this in order insensitive way.
final ArgumentCaptor<NativeUidRangeConfig[]> configsCaptor = ArgumentCaptor.forClass( final ArgumentCaptor<NativeUidRangeConfig[]> configsCaptor = ArgumentCaptor.forClass(
NativeUidRangeConfig[].class); NativeUidRangeConfig[].class);
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture()); inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture());
assertContainsAll(List.of(configsCaptor.getValue()), assertContainsAll(List.of(configsCaptor.getValue()),
List.of(enterpriseAllAllowedConfig, cellExcludeAppConfig)); List.of(enterpriseAllAllowedConfig, cellExcludeAppConfig));
@@ -16448,7 +16504,7 @@ public class ConnectivityServiceTest {
// Verify issuing with cellular set only when enterprise network disconnects. // Verify issuing with cellular set only when enterprise network disconnects.
enterpriseAgent.disconnect(); enterpriseAgent.disconnect();
waitForIdle(); waitForIdle();
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
inOrder.verify(mMockNetd).setNetworkAllowlist( inOrder.verify(mMockNetd).setNetworkAllowlist(
new NativeUidRangeConfig[]{cellExcludeAppConfig}); new NativeUidRangeConfig[]{cellExcludeAppConfig});
} else { } else {
@@ -16457,7 +16513,7 @@ public class ConnectivityServiceTest {
mCellAgent.disconnect(); mCellAgent.disconnect();
waitForIdle(); waitForIdle();
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[]{}); inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[]{});
} else { } else {
inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any()); inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any());
@@ -16513,7 +16569,7 @@ public class ConnectivityServiceTest {
profileNetworkPreferenceBuilder.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE); profileNetworkPreferenceBuilder.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE);
profileNetworkPreferenceBuilder.setPreferenceEnterpriseId(NET_ENTERPRISE_ID_1); profileNetworkPreferenceBuilder.setPreferenceEnterpriseId(NET_ENTERPRISE_ID_1);
final TestOnCompleteListener listener = new TestOnCompleteListener(); final TestOnCompleteListener listener = new TestOnCompleteListener();
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
mCm.setProfileNetworkPreferences(testHandle, mCm.setProfileNetworkPreferences(testHandle,
List.of(profileNetworkPreferenceBuilder.build()), List.of(profileNetworkPreferenceBuilder.build()),
r -> r.run(), listener); r -> r.run(), listener);
@@ -16621,7 +16677,7 @@ public class ConnectivityServiceTest {
agent.getNetwork().getNetId(), agent.getNetwork().getNetId(),
intToUidRangeStableParcels(uids), intToUidRangeStableParcels(uids),
preferenceOrder); preferenceOrder);
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
inOrder.verify(mMockNetd, times(1)).networkAddUidRangesParcel(uids200Parcel); inOrder.verify(mMockNetd, times(1)).networkAddUidRangesParcel(uids200Parcel);
} }
@@ -16629,7 +16685,7 @@ public class ConnectivityServiceTest {
uids.add(400); uids.add(400);
nc.setAllowedUids(uids); nc.setAllowedUids(uids);
agent.setNetworkCapabilities(nc, true /* sendToConnectivityService */); agent.setNetworkCapabilities(nc, true /* sendToConnectivityService */);
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
cb.expectCaps(agent, c -> c.getAllowedUids().equals(uids)); cb.expectCaps(agent, c -> c.getAllowedUids().equals(uids));
} else { } else {
cb.assertNoCallback(); cb.assertNoCallback();
@@ -16640,13 +16696,13 @@ public class ConnectivityServiceTest {
agent.getNetwork().getNetId(), agent.getNetwork().getNetId(),
intToUidRangeStableParcels(uids), intToUidRangeStableParcels(uids),
preferenceOrder); preferenceOrder);
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
inOrder.verify(mMockNetd, times(1)).networkAddUidRangesParcel(uids300400Parcel); inOrder.verify(mMockNetd, times(1)).networkAddUidRangesParcel(uids300400Parcel);
} }
nc.setAllowedUids(uids); nc.setAllowedUids(uids);
agent.setNetworkCapabilities(nc, true /* sendToConnectivityService */); agent.setNetworkCapabilities(nc, true /* sendToConnectivityService */);
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
cb.expectCaps(agent, c -> c.getAllowedUids().equals(uids)); cb.expectCaps(agent, c -> c.getAllowedUids().equals(uids));
inOrder.verify(mMockNetd, times(1)).networkRemoveUidRangesParcel(uids200Parcel); inOrder.verify(mMockNetd, times(1)).networkRemoveUidRangesParcel(uids200Parcel);
} else { } else {
@@ -16657,7 +16713,7 @@ public class ConnectivityServiceTest {
uids.add(600); uids.add(600);
nc.setAllowedUids(uids); nc.setAllowedUids(uids);
agent.setNetworkCapabilities(nc, true /* sendToConnectivityService */); agent.setNetworkCapabilities(nc, true /* sendToConnectivityService */);
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
cb.expectCaps(agent, c -> c.getAllowedUids().equals(uids)); cb.expectCaps(agent, c -> c.getAllowedUids().equals(uids));
} else { } else {
cb.assertNoCallback(); cb.assertNoCallback();
@@ -16666,7 +16722,7 @@ public class ConnectivityServiceTest {
agent.getNetwork().getNetId(), agent.getNetwork().getNetId(),
intToUidRangeStableParcels(uids), intToUidRangeStableParcels(uids),
preferenceOrder); preferenceOrder);
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
inOrder.verify(mMockNetd, times(1)).networkAddUidRangesParcel(uids600Parcel); inOrder.verify(mMockNetd, times(1)).networkAddUidRangesParcel(uids600Parcel);
inOrder.verify(mMockNetd, times(1)).networkRemoveUidRangesParcel(uids300400Parcel); inOrder.verify(mMockNetd, times(1)).networkRemoveUidRangesParcel(uids300400Parcel);
} }
@@ -16674,7 +16730,7 @@ public class ConnectivityServiceTest {
uids.clear(); uids.clear();
nc.setAllowedUids(uids); nc.setAllowedUids(uids);
agent.setNetworkCapabilities(nc, true /* sendToConnectivityService */); agent.setNetworkCapabilities(nc, true /* sendToConnectivityService */);
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
cb.expectCaps(agent, c -> c.getAllowedUids().isEmpty()); cb.expectCaps(agent, c -> c.getAllowedUids().isEmpty());
inOrder.verify(mMockNetd, times(1)).networkRemoveUidRangesParcel(uids600Parcel); inOrder.verify(mMockNetd, times(1)).networkRemoveUidRangesParcel(uids600Parcel);
} else { } else {
@@ -16727,7 +16783,7 @@ public class ConnectivityServiceTest {
// Cell gets to set the service UID as access UID // Cell gets to set the service UID as access UID
ncb.setAllowedUids(serviceUidSet); ncb.setAllowedUids(serviceUidSet);
mEthernetAgent.setNetworkCapabilities(ncb.build(), true /* sendToCS */); mEthernetAgent.setNetworkCapabilities(ncb.build(), true /* sendToCS */);
if (SdkLevel.isAtLeastT() && hasAutomotiveFeature) { if (mDeps.isAtLeastT() && hasAutomotiveFeature) {
cb.expectCaps(mEthernetAgent, c -> c.getAllowedUids().equals(serviceUidSet)); cb.expectCaps(mEthernetAgent, c -> c.getAllowedUids().equals(serviceUidSet));
} else { } else {
// S and no automotive feature must ignore access UIDs. // S and no automotive feature must ignore access UIDs.
@@ -16780,7 +16836,7 @@ public class ConnectivityServiceTest {
cb.expectAvailableThenValidatedCallbacks(mCellAgent); cb.expectAvailableThenValidatedCallbacks(mCellAgent);
ncb.setAllowedUids(serviceUidSet); ncb.setAllowedUids(serviceUidSet);
mCellAgent.setNetworkCapabilities(ncb.build(), true /* sendToCS */); mCellAgent.setNetworkCapabilities(ncb.build(), true /* sendToCS */);
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
cb.expectCaps(mCellAgent, c -> c.getAllowedUids().equals(serviceUidSet)); cb.expectCaps(mCellAgent, c -> c.getAllowedUids().equals(serviceUidSet));
} else { } else {
// S must ignore access UIDs. // S must ignore access UIDs.
@@ -16790,7 +16846,7 @@ public class ConnectivityServiceTest {
// ...but not to some other UID. Rejection sets UIDs to the empty set // ...but not to some other UID. Rejection sets UIDs to the empty set
ncb.setAllowedUids(nonServiceUidSet); ncb.setAllowedUids(nonServiceUidSet);
mCellAgent.setNetworkCapabilities(ncb.build(), true /* sendToCS */); mCellAgent.setNetworkCapabilities(ncb.build(), true /* sendToCS */);
if (SdkLevel.isAtLeastT()) { if (mDeps.isAtLeastT()) {
cb.expectCaps(mCellAgent, c -> c.getAllowedUids().isEmpty()); cb.expectCaps(mCellAgent, c -> c.getAllowedUids().isEmpty());
} else { } else {
// S must ignore access UIDs. // S must ignore access UIDs.
@@ -17712,14 +17768,14 @@ public class ConnectivityServiceTest {
@Test @Test
public void testIgnoreValidationAfterRoamEnabled() throws Exception { public void testIgnoreValidationAfterRoamEnabled() throws Exception {
final boolean enabled = !SdkLevel.isAtLeastT(); final boolean enabled = !mDeps.isAtLeastT();
doTestIgnoreValidationAfterRoam(5_000, enabled); doTestIgnoreValidationAfterRoam(5_000, enabled);
} }
@Test @Test
public void testShouldIgnoreValidationFailureAfterRoam() { public void testShouldIgnoreValidationFailureAfterRoam() {
// Always disabled on T+. // Always disabled on T+.
assumeFalse(SdkLevel.isAtLeastT()); assumeFalse(mDeps.isAtLeastT());
NetworkAgentInfo nai = fakeWifiNai(new NetworkCapabilities()); NetworkAgentInfo nai = fakeWifiNai(new NetworkCapabilities());
@@ -17973,7 +18029,7 @@ public class ConnectivityServiceTest {
mCellAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR, cellLp); mCellAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR, cellLp);
mCellAgent.connect(false /* validated */); mCellAgent.connect(false /* validated */);
if (SdkLevel.isAtLeastU()) { if (mDeps.isAtLeastU()) {
final String expectedPrefix = makeNflogPrefix(MOBILE_IFNAME, final String expectedPrefix = makeNflogPrefix(MOBILE_IFNAME,
mCellAgent.getNetwork().getNetworkHandle()); mCellAgent.getNetwork().getNetworkHandle());
verify(mMockNetd).wakeupAddInterface(MOBILE_IFNAME, expectedPrefix, PACKET_WAKEUP_MARK, verify(mMockNetd).wakeupAddInterface(MOBILE_IFNAME, expectedPrefix, PACKET_WAKEUP_MARK,