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

Commit 9c92c37f authored by Chiachang Wang's avatar Chiachang Wang Committed by Gerrit Code Review
Browse files

Merge "Remove UidRange.createForUser() with userId integers"

parents ae6583b3 66ded137
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
@@ -1510,7 +1510,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) {
@@ -1523,7 +1523,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)));
        }
    }

@@ -1532,7 +1532,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
@@ -6851,7 +6851,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));

@@ -6861,7 +6861,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));

@@ -7495,7 +7495,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);
@@ -8414,7 +8414,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);

@@ -8442,7 +8442,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);

@@ -8458,7 +8458,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);

@@ -8473,7 +8473,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);

@@ -8525,7 +8525,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);
@@ -8724,7 +8724,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);
@@ -9283,7 +9283,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);
@@ -10342,4 +10342,8 @@ public class ConnectivityServiceTest {
                mEthernetNetworkAgent.getNetwork().netId, 0 /* times */,
                true /* shouldDestroyNetwork */);
    }

    private UidRange createUidRange(int userId) {
        return UidRange.createForUser(UserHandle.of(userId));
    }
}
+3 −2
Original line number Diff line number Diff line
@@ -182,7 +182,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;
@@ -272,7 +273,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);
    }