From df29a85ee70e56a888c82e4e885ab6f775416ff7 Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Mon, 29 May 2023 17:02:43 +0900 Subject: [PATCH] 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 --- .../android/server/ConnectivityService.java | 58 ++++--- .../server/ConnectivityServiceTest.java | 154 ++++++++++++------ 2 files changed, 144 insertions(+), 68 deletions(-) diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index 51df1ddbc1..98ad861007 100755 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -1278,6 +1278,18 @@ public class ConnectivityService extends IConnectivityManager.Stub 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. */ @@ -1390,7 +1402,7 @@ public class ConnectivityService extends IConnectivityManager.Stub @Nullable public CarrierPrivilegeAuthenticator makeCarrierPrivilegeAuthenticator( @NonNull final Context context, @NonNull final TelephonyManager tm) { - if (SdkLevel.isAtLeastT()) { + if (isAtLeastT()) { return new CarrierPrivilegeAuthenticator(context, tm); } else { return null; @@ -1497,6 +1509,14 @@ public class ConnectivityService extends IConnectivityManager.Stub 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)} * @@ -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, // otherwise the unit tests will fail on pre-T devices where the seccomp filter blocks // the bpf syscall. http://aosp/1907693 - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { mDscpPolicyTracker = new DscpPolicyTracker(); } } catch (ErrnoException e) { @@ -1720,13 +1740,13 @@ public class ConnectivityService extends IConnectivityManager.Stub mIngressRateLimit = ConnectivitySettingsManager.getIngressRateLimitInBytesPerSecond( mContext); - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { mCdmps = new CompanionDeviceManagerProxyService(context); } else { mCdmps = null; } - if (SdkLevel.isAtLeastU() + if (mDeps.isAtLeastU() && mDeps.isFeatureEnabled(context, KEY_DESTROY_FROZEN_SOCKETS_VERSION)) { final UidFrozenStateChangedCallback frozenStateChangedCallback = new UidFrozenStateChangedCallback() { @@ -3229,7 +3249,7 @@ public class ConnectivityService extends IConnectivityManager.Stub private void applyMostRecentPolicyForConnectivityAction(BroadcastOptions options, NetworkInfo info) { // Delivery group policy APIs are only available on U+. - if (!SdkLevel.isAtLeastU()) return; + if (!mDeps.isAtLeastU()) return; final BroadcastOptionsShim optsShim = mDeps.makeBroadcastOptionsShim(options); 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 - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { mBpfNetMaps.setPullAtomCallback(mContext); } // Wait PermissionMonitor to finish the permission update. Then MultipathPolicyTracker won't @@ -4517,7 +4537,7 @@ public class ConnectivityService extends IConnectivityManager.Stub @VisibleForTesting boolean shouldIgnoreValidationFailureAfterRoam(NetworkAgentInfo nai) { // 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 // 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. destroyNativeNetwork(nai); } - if (!nai.isCreated() && !SdkLevel.isAtLeastT()) { + if (!nai.isCreated() && !mDeps.isAtLeastT()) { // Backwards compatibility: send onNetworkDestroyed even if network was never created. // This can never run if the code above runs because shouldDestroyNativeNetwork is // false if the network was never created. @@ -4740,7 +4760,7 @@ public class ConnectivityService extends IConnectivityManager.Stub } private void checkNrisConsistency(final NetworkRequestInfo nri) { - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { for (final NetworkRequestInfo n : mNetworkRequests.values()) { if (n.mBinder != null && n.mBinder == nri.mBinder) { // 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); } - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { mPermissionMonitor.updateVpnLockdownUidRanges(requireVpn, ranges); } @@ -7124,7 +7144,7 @@ public class ConnectivityService extends IConnectivityManager.Stub @NonNull final NetworkCapabilities networkCapabilities) { // 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+. - if (!SdkLevel.isAtLeastS()) { + if (!mDeps.isAtLeastS()) { Log.wtf(TAG, "Connectivity service should always run in at least SDK S"); 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 // 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. - 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 ranges) { @@ -8809,14 +8829,14 @@ public class ConnectivityService extends IConnectivityManager.Stub try { if (DBG) log("Sending " + pendingIntent); final BroadcastOptions options = BroadcastOptions.makeBasic(); - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { // Explicitly disallow the receiver from starting activities, to prevent apps from // utilizing the PendingIntent as a backdoor to do this. options.setPendingIntentBackgroundActivityLaunchAllowed(false); } pendingIntent.send(mContext, 0, intent, this /* onFinished */, null /* Handler */, null /* requiredPermission */, - SdkLevel.isAtLeastT() ? options.toBundle() : null); + mDeps.isAtLeastT() ? options.toBundle() : null); } catch (PendingIntent.CanceledException e) { if (DBG) log(pendingIntent + " was not sent, it had been canceled."); mPendingIntentWakeLock.release(); @@ -9095,7 +9115,7 @@ public class ConnectivityService extends IConnectivityManager.Stub private void updateProfileAllowedNetworks() { // Netd command is not implemented before U. - if (!SdkLevel.isAtLeastU()) return; + if (!mDeps.isAtLeastU()) return; ensureRunningOnConnectivityServiceThread(); final ArrayList 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 // process to check the interface version, just use an SDK check. NetworkStack will // always be new enough when running on T+. - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { networkAgent.networkMonitor().notifyNetworkConnected(params); } else { networkAgent.networkMonitor().notifyNetworkConnected(params.linkProperties, @@ -11307,7 +11327,7 @@ public class ConnectivityService extends IConnectivityManager.Stub if (um.isManagedProfile(profile.getIdentifier())) { return true; } - if (SdkLevel.isAtLeastT() && dpm.getDeviceOwner() != null) return true; + if (mDeps.isAtLeastT() && dpm.getDeviceOwner() != null) return true; return false; } @@ -11589,7 +11609,7 @@ public class ConnectivityService extends IConnectivityManager.Stub 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; + if (!mDeps.isAtLeastT()) return false; final NetworkCapabilities agentCaps = networkAgent.networkCapabilities; // 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); } - if (SdkLevel.isAtLeastU() && enable) { + if (mDeps.isAtLeastU() && enable) { try { closeSocketsForFirewallChainLocked(chain); } catch (ErrnoException | SocketException | InterruptedIOException e) { diff --git a/tests/unit/java/com/android/server/ConnectivityServiceTest.java b/tests/unit/java/com/android/server/ConnectivityServiceTest.java index e434649a63..904e4bd300 100755 --- a/tests/unit/java/com/android/server/ConnectivityServiceTest.java +++ b/tests/unit/java/com/android/server/ConnectivityServiceTest.java @@ -167,6 +167,7 @@ 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.FunctionalUtils.ignoreExceptions; +import static com.android.testutils.HandlerUtils.visibleOnHandlerThread; import static com.android.testutils.HandlerUtils.waitForIdleSerialExecutor; import static com.android.testutils.MiscAsserts.assertContainsAll; 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.test.BroadcastInterceptingContext; 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.CollectionUtils; import com.android.net.module.util.LocationPermissionChecker; @@ -869,7 +869,7 @@ public class ConnectivityServiceTest { @Override public void sendStickyBroadcast(Intent intent, Bundle options) { // 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, NetworkInfo.class); try { @@ -1085,7 +1085,7 @@ public class ConnectivityServiceTest { } private void onValidationRequested() throws Exception { - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { verify(mNetworkMonitor).notifyNetworkConnectedParcel(any()); } else { verify(mNetworkMonitor).notifyNetworkConnected(any(), any()); @@ -1932,6 +1932,7 @@ public class ConnectivityServiceTest { class ConnectivityServiceDependencies extends ConnectivityService.Dependencies { final ConnectivityResources mConnRes; + final ArraySet> mEnabledChangeIds = new ArraySet<>(); ConnectivityServiceDependencies(final Context mockResContext) { mConnRes = new ConnectivityResources(mockResContext); @@ -1997,7 +1998,7 @@ public class ConnectivityServiceTest { @Override public CarrierPrivilegeAuthenticator makeCarrierPrivilegeAuthenticator( @NonNull final Context context, @NonNull final TelephonyManager tm) { - return SdkLevel.isAtLeastT() ? mCarrierPrivilegeAuthenticator : null; + return mDeps.isAtLeastT() ? mCarrierPrivilegeAuthenticator : null; } @Override @@ -2096,6 +2097,61 @@ public class ConnectivityServiceTest { } } + public void setChangeIdEnabled(final boolean enabled, final long changeId, final int uid) { + final Pair 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 public BpfNetMaps getBpfNetMaps(Context context, INetd netd) { return mBpfNetMaps; @@ -5933,7 +5989,7 @@ public class ConnectivityServiceTest { doReturn(0).when(mResources).getInteger(R.integer.config_activelyPreferBadWifi); mPolicyTracker.reevaluate(); waitForIdle(); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { // U+ ignore the setting and always actively prefers bad wifi assertTrue(mService.mNetworkRanker.getConfiguration().activelyPreferBadWifi()); } else { @@ -6103,7 +6159,7 @@ public class ConnectivityServiceTest { @Test public void testPreferBadWifi_doNotAvoid_doNotPrefer() throws Exception { // 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 */, timeout -> timeout < 14_000); } @@ -9772,7 +9828,7 @@ public class ConnectivityServiceTest { final Set excludedUids = new ArraySet(); excludedUids.add(VPN_UID); - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { // On T onwards, the corresponding SDK sandbox UID should also be excluded excludedUids.add(toSdkSandboxUid(VPN_UID)); } @@ -9820,7 +9876,7 @@ public class ConnectivityServiceTest { vpnDefaultCallbackAsUid.assertNoCallback(); excludedUids.add(uid); - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { // On T onwards, the corresponding SDK sandbox UID should also be excluded excludedUids.add(toSdkSandboxUid(uid)); } @@ -10554,7 +10610,7 @@ public class ConnectivityServiceTest { private void verifyClatdStart(@Nullable InOrder inOrder, @NonNull String iface, int netId, @NonNull String nat64Prefix) throws Exception { - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { verifyWithOrder(inOrder, mClatCoordinator) .clatStart(eq(iface), eq(netId), eq(new IpPrefix(nat64Prefix))); } else { @@ -10564,7 +10620,7 @@ public class ConnectivityServiceTest { private void verifyNeverClatdStart(@Nullable InOrder inOrder, @NonNull String iface) throws Exception { - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { verifyNeverWithOrder(inOrder, mClatCoordinator).clatStart(eq(iface), anyInt(), any()); } else { verifyNeverWithOrder(inOrder, mMockNetd).clatdStart(eq(iface), anyString()); @@ -10573,7 +10629,7 @@ public class ConnectivityServiceTest { private void verifyClatdStop(@Nullable InOrder inOrder, @NonNull String iface) throws Exception { - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { verifyWithOrder(inOrder, mClatCoordinator).clatStop(); } else { verifyWithOrder(inOrder, mMockNetd).clatdStop(eq(iface)); @@ -10582,7 +10638,7 @@ public class ConnectivityServiceTest { private void verifyNeverClatdStop(@Nullable InOrder inOrder, @NonNull String iface) throws Exception { - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { verifyNeverWithOrder(inOrder, mClatCoordinator).clatStop(); } else { verifyNeverWithOrder(inOrder, mMockNetd).clatdStop(eq(iface)); @@ -10775,7 +10831,7 @@ public class ConnectivityServiceTest { networkCallback.assertNoCallback(); verify(mMockNetd, times(1)).networkRemoveInterface(cellNetId, CLAT_MOBILE_IFNAME); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { verifyWakeupModifyInterface(CLAT_MOBILE_IFNAME, false); } @@ -10815,7 +10871,7 @@ public class ConnectivityServiceTest { assertRoutesAdded(cellNetId, stackedDefault); verify(mMockNetd, times(1)).networkAddInterface(cellNetId, CLAT_MOBILE_IFNAME); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { 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)).interfaceGetCfg(CLAT_MOBILE_IFNAME); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { verifyWakeupModifyInterface(CLAT_MOBILE_IFNAME, false); } @@ -10845,13 +10901,13 @@ public class ConnectivityServiceTest { verify(mMockNetd, times(1)).idletimerRemoveInterface(eq(MOBILE_IFNAME), anyInt(), eq(Integer.toString(TRANSPORT_CELLULAR))); verify(mMockNetd).networkDestroy(cellNetId); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { verify(mMockNetd).setNetworkAllowlist(any()); } else { verify(mMockNetd, never()).setNetworkAllowlist(any()); } - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { 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(cellNetId, ipv6Subnet, ipv6Default, stackedDefault); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { verifyWakeupModifyInterface(MOBILE_IFNAME, true); } @@ -10898,20 +10954,20 @@ public class ConnectivityServiceTest { networkCallback.assertNoCallback(); verifyClatdStop(null /* inOrder */, MOBILE_IFNAME); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { verifyWakeupModifyInterface(CLAT_MOBILE_IFNAME, false); } verify(mMockNetd).idletimerRemoveInterface(eq(MOBILE_IFNAME), anyInt(), eq(Integer.toString(TRANSPORT_CELLULAR))); verify(mMockNetd).networkDestroy(cellNetId); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { verify(mMockNetd).setNetworkAllowlist(any()); } else { verify(mMockNetd, never()).setNetworkAllowlist(any()); } - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { verifyWakeupModifyInterface(MOBILE_IFNAME, false); } @@ -11352,7 +11408,7 @@ public class ConnectivityServiceTest { mMockVpn.establish(lp, uid, vpnRange); 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 // wildcard and this accepts traffic from all the interfaces. // There are two expected invocations, one during the VPN initial @@ -12341,7 +12397,7 @@ public class ConnectivityServiceTest { @Test public void testUnderlyingNetworksWillBeSetInNetworkAgentInfoConstructor() throws Exception { - assumeTrue(SdkLevel.isAtLeastT()); + assumeTrue(mDeps.isAtLeastT()); final Network network1 = new Network(100); final Network network2 = new Network(101); final List underlyingNetworks = new ArrayList<>(); @@ -16234,7 +16290,7 @@ public class ConnectivityServiceTest { mCellAgent.getNetwork().netId, toUidRangeStableParcels(allowedRanges), 0 /* subPriority */); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[]{config1User}); } else { inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any()); @@ -16252,7 +16308,7 @@ public class ConnectivityServiceTest { mCellAgent.getNetwork().netId, toUidRangeStableParcels(allowedRanges), 0 /* subPriority */); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[]{config2Users}); } else { inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any()); @@ -16283,7 +16339,7 @@ public class ConnectivityServiceTest { mCellAgent.getNetwork().netId, allowAllUidRangesParcel, 0 /* subPriority */); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { inOrder.verify(mMockNetd).setNetworkAllowlist( new NativeUidRangeConfig[]{cellAllAllowedConfig}); } else { @@ -16302,7 +16358,7 @@ public class ConnectivityServiceTest { // making the order of the list undeterministic. Thus, verify this in order insensitive way. final ArgumentCaptor configsCaptor = ArgumentCaptor.forClass( NativeUidRangeConfig[].class); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture()); assertContainsAll(List.of(configsCaptor.getValue()), List.of(cellAllAllowedConfig, enterpriseAllAllowedConfig)); @@ -16336,7 +16392,7 @@ public class ConnectivityServiceTest { mCellAgent.getNetwork().netId, excludeAppRangesParcel, 0 /* subPriority */); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture()); assertContainsAll(List.of(configsCaptor.getValue()), List.of(cellExcludeAppConfig, enterpriseAllAllowedConfig)); @@ -16348,7 +16404,7 @@ public class ConnectivityServiceTest { mCm.setProfileNetworkPreference(testHandle, PROFILE_NETWORK_PREFERENCE_ENTERPRISE, r -> r.run(), listener); listener.expectOnComplete(); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture()); assertContainsAll(List.of(configsCaptor.getValue()), List.of(cellAllAllowedConfig, enterpriseAllAllowedConfig)); @@ -16360,7 +16416,7 @@ public class ConnectivityServiceTest { // disconnects. enterpriseAgent.disconnect(); waitForIdle(); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { inOrder.verify(mMockNetd).setNetworkAllowlist( new NativeUidRangeConfig[]{cellAllAllowedConfig}); } else { @@ -16385,7 +16441,7 @@ public class ConnectivityServiceTest { List.of(prefBuilder.build()), r -> r.run(), listener); listener.expectOnComplete(); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[]{}); } else { inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any()); @@ -16413,7 +16469,7 @@ public class ConnectivityServiceTest { mCellAgent.getNetwork().netId, excludeAppRangesParcel, 0 /* subPriority */); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { inOrder.verify(mMockNetd).setNetworkAllowlist( new NativeUidRangeConfig[]{cellExcludeAppConfig}); } else { @@ -16437,7 +16493,7 @@ public class ConnectivityServiceTest { // making the order of the list undeterministic. Thus, verify this in order insensitive way. final ArgumentCaptor configsCaptor = ArgumentCaptor.forClass( NativeUidRangeConfig[].class); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture()); assertContainsAll(List.of(configsCaptor.getValue()), List.of(enterpriseAllAllowedConfig, cellExcludeAppConfig)); @@ -16448,7 +16504,7 @@ public class ConnectivityServiceTest { // Verify issuing with cellular set only when enterprise network disconnects. enterpriseAgent.disconnect(); waitForIdle(); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { inOrder.verify(mMockNetd).setNetworkAllowlist( new NativeUidRangeConfig[]{cellExcludeAppConfig}); } else { @@ -16457,7 +16513,7 @@ public class ConnectivityServiceTest { mCellAgent.disconnect(); waitForIdle(); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[]{}); } else { inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any()); @@ -16513,7 +16569,7 @@ public class ConnectivityServiceTest { profileNetworkPreferenceBuilder.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE); profileNetworkPreferenceBuilder.setPreferenceEnterpriseId(NET_ENTERPRISE_ID_1); final TestOnCompleteListener listener = new TestOnCompleteListener(); - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { mCm.setProfileNetworkPreferences(testHandle, List.of(profileNetworkPreferenceBuilder.build()), r -> r.run(), listener); @@ -16621,7 +16677,7 @@ public class ConnectivityServiceTest { agent.getNetwork().getNetId(), intToUidRangeStableParcels(uids), preferenceOrder); - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { inOrder.verify(mMockNetd, times(1)).networkAddUidRangesParcel(uids200Parcel); } @@ -16629,7 +16685,7 @@ public class ConnectivityServiceTest { uids.add(400); nc.setAllowedUids(uids); agent.setNetworkCapabilities(nc, true /* sendToConnectivityService */); - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { cb.expectCaps(agent, c -> c.getAllowedUids().equals(uids)); } else { cb.assertNoCallback(); @@ -16640,13 +16696,13 @@ public class ConnectivityServiceTest { agent.getNetwork().getNetId(), intToUidRangeStableParcels(uids), preferenceOrder); - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { inOrder.verify(mMockNetd, times(1)).networkAddUidRangesParcel(uids300400Parcel); } nc.setAllowedUids(uids); agent.setNetworkCapabilities(nc, true /* sendToConnectivityService */); - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { cb.expectCaps(agent, c -> c.getAllowedUids().equals(uids)); inOrder.verify(mMockNetd, times(1)).networkRemoveUidRangesParcel(uids200Parcel); } else { @@ -16657,7 +16713,7 @@ public class ConnectivityServiceTest { uids.add(600); nc.setAllowedUids(uids); agent.setNetworkCapabilities(nc, true /* sendToConnectivityService */); - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { cb.expectCaps(agent, c -> c.getAllowedUids().equals(uids)); } else { cb.assertNoCallback(); @@ -16666,7 +16722,7 @@ public class ConnectivityServiceTest { agent.getNetwork().getNetId(), intToUidRangeStableParcels(uids), preferenceOrder); - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { inOrder.verify(mMockNetd, times(1)).networkAddUidRangesParcel(uids600Parcel); inOrder.verify(mMockNetd, times(1)).networkRemoveUidRangesParcel(uids300400Parcel); } @@ -16674,7 +16730,7 @@ public class ConnectivityServiceTest { uids.clear(); nc.setAllowedUids(uids); agent.setNetworkCapabilities(nc, true /* sendToConnectivityService */); - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { cb.expectCaps(agent, c -> c.getAllowedUids().isEmpty()); inOrder.verify(mMockNetd, times(1)).networkRemoveUidRangesParcel(uids600Parcel); } else { @@ -16727,7 +16783,7 @@ public class ConnectivityServiceTest { // Cell gets to set the service UID as access UID ncb.setAllowedUids(serviceUidSet); mEthernetAgent.setNetworkCapabilities(ncb.build(), true /* sendToCS */); - if (SdkLevel.isAtLeastT() && hasAutomotiveFeature) { + if (mDeps.isAtLeastT() && hasAutomotiveFeature) { cb.expectCaps(mEthernetAgent, c -> c.getAllowedUids().equals(serviceUidSet)); } else { // S and no automotive feature must ignore access UIDs. @@ -16780,7 +16836,7 @@ public class ConnectivityServiceTest { cb.expectAvailableThenValidatedCallbacks(mCellAgent); ncb.setAllowedUids(serviceUidSet); mCellAgent.setNetworkCapabilities(ncb.build(), true /* sendToCS */); - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { cb.expectCaps(mCellAgent, c -> c.getAllowedUids().equals(serviceUidSet)); } else { // 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 ncb.setAllowedUids(nonServiceUidSet); mCellAgent.setNetworkCapabilities(ncb.build(), true /* sendToCS */); - if (SdkLevel.isAtLeastT()) { + if (mDeps.isAtLeastT()) { cb.expectCaps(mCellAgent, c -> c.getAllowedUids().isEmpty()); } else { // S must ignore access UIDs. @@ -17712,14 +17768,14 @@ public class ConnectivityServiceTest { @Test public void testIgnoreValidationAfterRoamEnabled() throws Exception { - final boolean enabled = !SdkLevel.isAtLeastT(); + final boolean enabled = !mDeps.isAtLeastT(); doTestIgnoreValidationAfterRoam(5_000, enabled); } @Test public void testShouldIgnoreValidationFailureAfterRoam() { // Always disabled on T+. - assumeFalse(SdkLevel.isAtLeastT()); + assumeFalse(mDeps.isAtLeastT()); NetworkAgentInfo nai = fakeWifiNai(new NetworkCapabilities()); @@ -17973,7 +18029,7 @@ public class ConnectivityServiceTest { mCellAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR, cellLp); mCellAgent.connect(false /* validated */); - if (SdkLevel.isAtLeastU()) { + if (mDeps.isAtLeastU()) { final String expectedPrefix = makeNflogPrefix(MOBILE_IFNAME, mCellAgent.getNetwork().getNetworkHandle()); verify(mMockNetd).wakeupAddInterface(MOBILE_IFNAME, expectedPrefix, PACKET_WAKEUP_MARK,