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
This commit is contained in:
@@ -42,10 +42,6 @@ public final class UidRange implements Parcelable {
|
|||||||
stop = stopUid;
|
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. */
|
/** Creates a UidRange for the specified user. */
|
||||||
public static UidRange createForUser(UserHandle user) {
|
public static UidRange createForUser(UserHandle user) {
|
||||||
final UserHandle nextUser = UserHandle.of(user.getIdentifier() + 1);
|
final UserHandle nextUser = UserHandle.of(user.getIdentifier() + 1);
|
||||||
|
|||||||
@@ -6828,7 +6828,7 @@ public class ConnectivityServiceTest {
|
|||||||
callback.expectCapabilitiesThat(mMockVpn, (caps)
|
callback.expectCapabilitiesThat(mMockVpn, (caps)
|
||||||
-> caps.getUids().size() == 2
|
-> caps.getUids().size() == 2
|
||||||
&& caps.getUids().contains(new UidRange(uid, uid))
|
&& 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_VPN)
|
||||||
&& caps.hasTransport(TRANSPORT_WIFI));
|
&& caps.hasTransport(TRANSPORT_WIFI));
|
||||||
|
|
||||||
@@ -6838,7 +6838,7 @@ public class ConnectivityServiceTest {
|
|||||||
callback.expectCapabilitiesThat(mMockVpn, (caps)
|
callback.expectCapabilitiesThat(mMockVpn, (caps)
|
||||||
-> caps.getUids().size() == 2
|
-> caps.getUids().size() == 2
|
||||||
&& caps.getUids().contains(new UidRange(uid, uid))
|
&& 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_VPN)
|
||||||
&& !caps.hasTransport(TRANSPORT_WIFI));
|
&& !caps.hasTransport(TRANSPORT_WIFI));
|
||||||
|
|
||||||
@@ -7469,7 +7469,7 @@ public class ConnectivityServiceTest {
|
|||||||
assertNotNull(underlying);
|
assertNotNull(underlying);
|
||||||
mMockVpn.setVpnType(VpnManager.TYPE_VPN_LEGACY);
|
mMockVpn.setVpnType(VpnManager.TYPE_VPN_LEGACY);
|
||||||
// The legacy lockdown VPN only supports userId 0.
|
// 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.registerAgent(ranges);
|
||||||
mMockVpn.setUnderlyingNetworks(new Network[]{underlying});
|
mMockVpn.setUnderlyingNetworks(new Network[]{underlying});
|
||||||
mMockVpn.connect(true);
|
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(Inet4Address.ANY, 0), null));
|
||||||
lp.addRoute(new RouteInfo(new IpPrefix(Inet6Address.ANY, 0), RTN_UNREACHABLE));
|
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.
|
// 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);
|
mMockVpn.establish(lp, VPN_UID, vpnRange);
|
||||||
assertVpnUidRangesUpdated(true, vpnRange, VPN_UID);
|
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(Inet6Address.ANY, 0), null));
|
||||||
lp.addRoute(new RouteInfo(new IpPrefix(Inet4Address.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.
|
// 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);
|
mMockVpn.establish(lp, Process.SYSTEM_UID, vpnRange);
|
||||||
assertVpnUidRangesUpdated(true, vpnRange, Process.SYSTEM_UID);
|
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("192.0.2.0/24"), null, "tun0"));
|
||||||
lp.addRoute(new RouteInfo(new IpPrefix(Inet6Address.ANY, 0), RTN_UNREACHABLE));
|
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.
|
// 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);
|
mMockVpn.establish(lp, Process.SYSTEM_UID, vpnRange);
|
||||||
assertVpnUidRangesUpdated(true, vpnRange, Process.SYSTEM_UID);
|
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(Inet4Address.ANY, 0), null));
|
||||||
lp.addRoute(new RouteInfo(new IpPrefix(Inet6Address.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.
|
// 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);
|
mMockVpn.establish(lp, VPN_UID, vpnRange);
|
||||||
assertVpnUidRangesUpdated(true, vpnRange, VPN_UID);
|
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(Inet4Address.ANY, 0), RTN_UNREACHABLE));
|
||||||
lp.addRoute(new RouteInfo(new IpPrefix(Inet6Address.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.
|
// 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);
|
final Set<UidRange> vpnRanges = Collections.singleton(vpnRange);
|
||||||
mMockVpn.establish(lp, VPN_UID, vpnRanges);
|
mMockVpn.establish(lp, VPN_UID, vpnRanges);
|
||||||
assertVpnUidRangesUpdated(true, vpnRanges, VPN_UID);
|
assertVpnUidRangesUpdated(true, vpnRanges, VPN_UID);
|
||||||
@@ -8691,7 +8691,7 @@ public class ConnectivityServiceTest {
|
|||||||
|
|
||||||
private void setupConnectionOwnerUid(int vpnOwnerUid, @VpnManager.VpnType int vpnType)
|
private void setupConnectionOwnerUid(int vpnOwnerUid, @VpnManager.VpnType int vpnType)
|
||||||
throws Exception {
|
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.setVpnType(vpnType);
|
||||||
mMockVpn.establish(new LinkProperties(), vpnOwnerUid, vpnRange);
|
mMockVpn.establish(new LinkProperties(), vpnOwnerUid, vpnRange);
|
||||||
assertVpnUidRangesUpdated(true, vpnRange, vpnOwnerUid);
|
assertVpnUidRangesUpdated(true, vpnRange, vpnOwnerUid);
|
||||||
@@ -9250,7 +9250,7 @@ public class ConnectivityServiceTest {
|
|||||||
lp.setInterfaceName("tun0");
|
lp.setInterfaceName("tun0");
|
||||||
lp.addRoute(new RouteInfo(new IpPrefix(Inet4Address.ANY, 0), null));
|
lp.addRoute(new RouteInfo(new IpPrefix(Inet4Address.ANY, 0), null));
|
||||||
lp.addRoute(new RouteInfo(new IpPrefix(Inet6Address.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);
|
Set<UidRange> vpnRanges = Collections.singleton(vpnRange);
|
||||||
mMockVpn.establish(lp, VPN_UID, vpnRanges);
|
mMockVpn.establish(lp, VPN_UID, vpnRanges);
|
||||||
assertVpnUidRangesUpdated(true, vpnRanges, VPN_UID);
|
assertVpnUidRangesUpdated(true, vpnRanges, VPN_UID);
|
||||||
@@ -9689,4 +9689,8 @@ public class ConnectivityServiceTest {
|
|||||||
createDefaultOemNetworkPreferences(networkPref),
|
createDefaultOemNetworkPreferences(networkPref),
|
||||||
mOnSetOemNetworkPreferenceListener));
|
mOnSetOemNetworkPreferenceListener));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private UidRange createUidRange(int userId) {
|
||||||
|
return UidRange.createForUser(UserHandle.of(userId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,8 @@ public class VpnTest {
|
|||||||
mPackages.put(PKGS[i], PKG_UIDS[i]);
|
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(answer = Answers.RETURNS_DEEP_STUBS) private Context mContext;
|
||||||
@Mock private UserManager mUserManager;
|
@Mock private UserManager mUserManager;
|
||||||
@@ -269,7 +270,7 @@ public class VpnTest {
|
|||||||
vpn.createUserAndRestrictedProfilesRanges(primaryUser.id, null, null);
|
vpn.createUserAndRestrictedProfilesRanges(primaryUser.id, null, null);
|
||||||
|
|
||||||
assertEquals(new ArraySet<>(Arrays.asList(new UidRange[] {
|
assertEquals(new ArraySet<>(Arrays.asList(new UidRange[] {
|
||||||
PRI_USER_RANGE, UidRange.createForUser(restrictedProfileA.id)
|
PRI_USER_RANGE, UidRange.createForUser(UserHandle.of(restrictedProfileA.id))
|
||||||
})), ranges);
|
})), ranges);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user