Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66ded137 authored by Chiachang Wang's avatar Chiachang Wang
Browse files

Remove UidRange.createForUser() with userId integers

UidRange will be a part of connectivity mainline module.
Mainline modules should use strongly-typed UserHandle arguments.
The method also refer to the hidden UserHandle.PER_USER_RANGE
which is not available after UidRange is moved into module.
Thus, replace the usage and remove the createForUser method that
takes userId parameter.

Bug: 170598012
Test: atest FrameworksNetTests
Change-Id: I3f33ea92c4a24342af9ec4b0367c50bb64ce6450
parent 76529725
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -42,10 +42,6 @@ public final class UidRange implements Parcelable {
        stop  = stopUid;
    }

    public static UidRange createForUser(int userId) {
        return new UidRange(userId * PER_USER_RANGE, (userId + 1) * PER_USER_RANGE - 1);
    }

    /** Creates a UidRange for the specified user. */
    public static UidRange createForUser(UserHandle user) {
        final UserHandle nextUser = UserHandle.of(user.getIdentifier() + 1);
+3 −3
Original line number Diff line number Diff line
@@ -1509,7 +1509,7 @@ public class Vpn {
            if (start != -1) ranges.add(new UidRange(start, stop));
        } else if (disallowedApplications != null) {
            // Add all ranges for user skipping UIDs for disallowedApplications.
            final UidRange userRange = UidRange.createForUser(userId);
            final UidRange userRange = UidRange.createForUser(UserHandle.of(userId));
            int start = userRange.start;
            for (int uid : getAppsUids(disallowedApplications, userId)) {
                if (uid == start) {
@@ -1522,7 +1522,7 @@ public class Vpn {
            if (start <= userRange.stop) ranges.add(new UidRange(start, userRange.stop));
        } else {
            // Add all UIDs for the user.
            ranges.add(UidRange.createForUser(userId));
            ranges.add(UidRange.createForUser(UserHandle.of(userId)));
        }
    }

@@ -1531,7 +1531,7 @@ public class Vpn {
    private static List<UidRange> uidRangesForUser(int userId, Set<UidRange> existingRanges) {
        // UidRange#createForUser returns the entire range of UIDs available to a macro-user.
        // This is something like 0-99999 ; {@see UserHandle#PER_USER_RANGE}
        final UidRange userRange = UidRange.createForUser(userId);
        final UidRange userRange = UidRange.createForUser(UserHandle.of(userId));
        final List<UidRange> ranges = new ArrayList<>();
        for (UidRange range : existingRanges) {
            if (userRange.containsRange(range)) {
+14 −10
Original line number Diff line number Diff line
@@ -6828,7 +6828,7 @@ public class ConnectivityServiceTest {
        callback.expectCapabilitiesThat(mMockVpn, (caps)
                -> caps.getUids().size() == 2
                && caps.getUids().contains(new UidRange(uid, uid))
                && caps.getUids().contains(UidRange.createForUser(RESTRICTED_USER))
                && caps.getUids().contains(createUidRange(RESTRICTED_USER))
                && caps.hasTransport(TRANSPORT_VPN)
                && caps.hasTransport(TRANSPORT_WIFI));

@@ -6838,7 +6838,7 @@ public class ConnectivityServiceTest {
        callback.expectCapabilitiesThat(mMockVpn, (caps)
                -> caps.getUids().size() == 2
                && caps.getUids().contains(new UidRange(uid, uid))
                && caps.getUids().contains(UidRange.createForUser(RESTRICTED_USER))
                && caps.getUids().contains(createUidRange(RESTRICTED_USER))
                && caps.hasTransport(TRANSPORT_VPN)
                && !caps.hasTransport(TRANSPORT_WIFI));

@@ -7469,7 +7469,7 @@ public class ConnectivityServiceTest {
        assertNotNull(underlying);
        mMockVpn.setVpnType(VpnManager.TYPE_VPN_LEGACY);
        // The legacy lockdown VPN only supports userId 0.
        final Set<UidRange> ranges = Collections.singleton(UidRange.createForUser(PRIMARY_USER));
        final Set<UidRange> ranges = Collections.singleton(createUidRange(PRIMARY_USER));
        mMockVpn.registerAgent(ranges);
        mMockVpn.setUnderlyingNetworks(new Network[]{underlying});
        mMockVpn.connect(true);
@@ -8381,7 +8381,7 @@ public class ConnectivityServiceTest {
        lp.addRoute(new RouteInfo(new IpPrefix(Inet4Address.ANY, 0), null));
        lp.addRoute(new RouteInfo(new IpPrefix(Inet6Address.ANY, 0), RTN_UNREACHABLE));
        // The uid range needs to cover the test app so the network is visible to it.
        final Set<UidRange> vpnRange = Collections.singleton(UidRange.createForUser(PRIMARY_USER));
        final Set<UidRange> vpnRange = Collections.singleton(createUidRange(PRIMARY_USER));
        mMockVpn.establish(lp, VPN_UID, vpnRange);
        assertVpnUidRangesUpdated(true, vpnRange, VPN_UID);

@@ -8409,7 +8409,7 @@ public class ConnectivityServiceTest {
        lp.addRoute(new RouteInfo(new IpPrefix(Inet6Address.ANY, 0), null));
        lp.addRoute(new RouteInfo(new IpPrefix(Inet4Address.ANY, 0), null));
        // The uid range needs to cover the test app so the network is visible to it.
        final Set<UidRange> vpnRange = Collections.singleton(UidRange.createForUser(PRIMARY_USER));
        final Set<UidRange> vpnRange = Collections.singleton(createUidRange(PRIMARY_USER));
        mMockVpn.establish(lp, Process.SYSTEM_UID, vpnRange);
        assertVpnUidRangesUpdated(true, vpnRange, Process.SYSTEM_UID);

@@ -8425,7 +8425,7 @@ public class ConnectivityServiceTest {
        lp.addRoute(new RouteInfo(new IpPrefix("192.0.2.0/24"), null, "tun0"));
        lp.addRoute(new RouteInfo(new IpPrefix(Inet6Address.ANY, 0), RTN_UNREACHABLE));
        // The uid range needs to cover the test app so the network is visible to it.
        final Set<UidRange> vpnRange = Collections.singleton(UidRange.createForUser(PRIMARY_USER));
        final Set<UidRange> vpnRange = Collections.singleton(createUidRange(PRIMARY_USER));
        mMockVpn.establish(lp, Process.SYSTEM_UID, vpnRange);
        assertVpnUidRangesUpdated(true, vpnRange, Process.SYSTEM_UID);

@@ -8440,7 +8440,7 @@ public class ConnectivityServiceTest {
        lp.addRoute(new RouteInfo(new IpPrefix(Inet4Address.ANY, 0), null));
        lp.addRoute(new RouteInfo(new IpPrefix(Inet6Address.ANY, 0), null));
        // The uid range needs to cover the test app so the network is visible to it.
        final Set<UidRange> vpnRange = Collections.singleton(UidRange.createForUser(PRIMARY_USER));
        final Set<UidRange> vpnRange = Collections.singleton(createUidRange(PRIMARY_USER));
        mMockVpn.establish(lp, VPN_UID, vpnRange);
        assertVpnUidRangesUpdated(true, vpnRange, VPN_UID);

@@ -8492,7 +8492,7 @@ public class ConnectivityServiceTest {
        lp.addRoute(new RouteInfo(new IpPrefix(Inet4Address.ANY, 0), RTN_UNREACHABLE));
        lp.addRoute(new RouteInfo(new IpPrefix(Inet6Address.ANY, 0), null));
        // The uid range needs to cover the test app so the network is visible to it.
        final UidRange vpnRange = UidRange.createForUser(PRIMARY_USER);
        final UidRange vpnRange = createUidRange(PRIMARY_USER);
        final Set<UidRange> vpnRanges = Collections.singleton(vpnRange);
        mMockVpn.establish(lp, VPN_UID, vpnRanges);
        assertVpnUidRangesUpdated(true, vpnRanges, VPN_UID);
@@ -8691,7 +8691,7 @@ public class ConnectivityServiceTest {

    private void setupConnectionOwnerUid(int vpnOwnerUid, @VpnManager.VpnType int vpnType)
            throws Exception {
        final Set<UidRange> vpnRange = Collections.singleton(UidRange.createForUser(PRIMARY_USER));
        final Set<UidRange> vpnRange = Collections.singleton(createUidRange(PRIMARY_USER));
        mMockVpn.setVpnType(vpnType);
        mMockVpn.establish(new LinkProperties(), vpnOwnerUid, vpnRange);
        assertVpnUidRangesUpdated(true, vpnRange, vpnOwnerUid);
@@ -9250,7 +9250,7 @@ public class ConnectivityServiceTest {
        lp.setInterfaceName("tun0");
        lp.addRoute(new RouteInfo(new IpPrefix(Inet4Address.ANY, 0), null));
        lp.addRoute(new RouteInfo(new IpPrefix(Inet6Address.ANY, 0), null));
        final UidRange vpnRange = UidRange.createForUser(PRIMARY_USER);
        final UidRange vpnRange = createUidRange(PRIMARY_USER);
        Set<UidRange> vpnRanges = Collections.singleton(vpnRange);
        mMockVpn.establish(lp, VPN_UID, vpnRanges);
        assertVpnUidRangesUpdated(true, vpnRanges, VPN_UID);
@@ -9689,4 +9689,8 @@ public class ConnectivityServiceTest {
                        createDefaultOemNetworkPreferences(networkPref),
                        mOnSetOemNetworkPreferenceListener));
    }

    private UidRange createUidRange(int userId) {
        return UidRange.createForUser(UserHandle.of(userId));
    }
}
+3 −2
Original line number Diff line number Diff line
@@ -179,7 +179,8 @@ public class VpnTest {
            mPackages.put(PKGS[i], PKG_UIDS[i]);
        }
    }
    private static final UidRange PRI_USER_RANGE = UidRange.createForUser(primaryUser.id);
    private static final UidRange PRI_USER_RANGE =
            UidRange.createForUser(UserHandle.of(primaryUser.id));

    @Mock(answer = Answers.RETURNS_DEEP_STUBS) private Context mContext;
    @Mock private UserManager mUserManager;
@@ -269,7 +270,7 @@ public class VpnTest {
                vpn.createUserAndRestrictedProfilesRanges(primaryUser.id, null, null);

        assertEquals(new ArraySet<>(Arrays.asList(new UidRange[] {
                PRI_USER_RANGE, UidRange.createForUser(restrictedProfileA.id)
                PRI_USER_RANGE, UidRange.createForUser(UserHandle.of(restrictedProfileA.id))
        })), ranges);
    }