Merge "Revert "Change Ethernet API to use OutcomeReceiver""
diff --git a/framework/api/module-lib-current.txt b/framework/api/module-lib-current.txt
index 7f50237..e4e2151 100644
--- a/framework/api/module-lib-current.txt
+++ b/framework/api/module-lib-current.txt
@@ -141,7 +141,7 @@
}
public final class NetworkCapabilities implements android.os.Parcelable {
- method @NonNull @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY) public java.util.Set<java.lang.Integer> getAccessUids();
+ method @NonNull @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY) public java.util.Set<java.lang.Integer> getAllowedUids();
method @Nullable public java.util.Set<android.util.Range<java.lang.Integer>> getUids();
method public boolean hasForbiddenCapability(int);
field public static final long REDACT_ALL = -1L; // 0xffffffffffffffffL
@@ -153,7 +153,7 @@
}
public static final class NetworkCapabilities.Builder {
- method @NonNull @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY) public android.net.NetworkCapabilities.Builder setAccessUids(@NonNull java.util.Set<java.lang.Integer>);
+ method @NonNull @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY) public android.net.NetworkCapabilities.Builder setAllowedUids(@NonNull java.util.Set<java.lang.Integer>);
method @NonNull public android.net.NetworkCapabilities.Builder setUids(@Nullable java.util.Set<android.util.Range<java.lang.Integer>>);
}
@@ -172,8 +172,8 @@
public final class ProfileNetworkPreference implements android.os.Parcelable {
method public int describeContents();
- method @NonNull public java.util.List<java.lang.Integer> getExcludedUids();
- method @NonNull public java.util.List<java.lang.Integer> getIncludedUids();
+ method @NonNull public int[] getExcludedUids();
+ method @NonNull public int[] getIncludedUids();
method public int getPreference();
method public int getPreferenceEnterpriseId();
method public void writeToParcel(@NonNull android.os.Parcel, int);
@@ -183,8 +183,8 @@
public static final class ProfileNetworkPreference.Builder {
ctor public ProfileNetworkPreference.Builder();
method @NonNull public android.net.ProfileNetworkPreference build();
- method @NonNull public android.net.ProfileNetworkPreference.Builder setExcludedUids(@Nullable java.util.List<java.lang.Integer>);
- method @NonNull public android.net.ProfileNetworkPreference.Builder setIncludedUids(@Nullable java.util.List<java.lang.Integer>);
+ method @NonNull public android.net.ProfileNetworkPreference.Builder setExcludedUids(@NonNull int[]);
+ method @NonNull public android.net.ProfileNetworkPreference.Builder setIncludedUids(@NonNull int[]);
method @NonNull public android.net.ProfileNetworkPreference.Builder setPreference(int);
method @NonNull public android.net.ProfileNetworkPreference.Builder setPreferenceEnterpriseId(int);
}
diff --git a/framework/src/android/net/NetworkCapabilities.java b/framework/src/android/net/NetworkCapabilities.java
index 41be732..f7f2f57 100644
--- a/framework/src/android/net/NetworkCapabilities.java
+++ b/framework/src/android/net/NetworkCapabilities.java
@@ -147,27 +147,32 @@
private String mRequestorPackageName;
/**
- * Enterprise capability identifier 1.
+ * Enterprise capability identifier 1. It will be used to uniquely identify specific
+ * enterprise network.
*/
public static final int NET_ENTERPRISE_ID_1 = 1;
/**
- * Enterprise capability identifier 2.
+ * Enterprise capability identifier 2. It will be used to uniquely identify specific
+ * enterprise network.
*/
public static final int NET_ENTERPRISE_ID_2 = 2;
/**
- * Enterprise capability identifier 3.
+ * Enterprise capability identifier 3. It will be used to uniquely identify specific
+ * enterprise network.
*/
public static final int NET_ENTERPRISE_ID_3 = 3;
/**
- * Enterprise capability identifier 4.
+ * Enterprise capability identifier 4. It will be used to uniquely identify specific
+ * enterprise network.
*/
public static final int NET_ENTERPRISE_ID_4 = 4;
/**
- * Enterprise capability identifier 5.
+ * Enterprise capability identifier 5. It will be used to uniquely identify specific
+ * enterprise network.
*/
public static final int NET_ENTERPRISE_ID_5 = 5;
@@ -264,7 +269,7 @@
mTransportInfo = null;
mSignalStrength = SIGNAL_STRENGTH_UNSPECIFIED;
mUids = null;
- mAccessUids.clear();
+ mAllowedUids.clear();
mAdministratorUids = new int[0];
mOwnerUid = Process.INVALID_UID;
mSSID = null;
@@ -295,7 +300,7 @@
}
mSignalStrength = nc.mSignalStrength;
mUids = (nc.mUids == null) ? null : new ArraySet<>(nc.mUids);
- setAccessUids(nc.mAccessUids);
+ setAllowedUids(nc.mAllowedUids);
setAdministratorUids(nc.getAdministratorUids());
mOwnerUid = nc.mOwnerUid;
mForbiddenNetworkCapabilities = nc.mForbiddenNetworkCapabilities;
@@ -1029,7 +1034,7 @@
final int[] originalAdministratorUids = getAdministratorUids();
final TransportInfo originalTransportInfo = getTransportInfo();
final Set<Integer> originalSubIds = getSubscriptionIds();
- final Set<Integer> originalAccessUids = new ArraySet<>(mAccessUids);
+ final Set<Integer> originalAllowedUids = new ArraySet<>(mAllowedUids);
clearAll();
if (0 != (originalCapabilities & (1 << NET_CAPABILITY_NOT_RESTRICTED))) {
// If the test network is not restricted, then it is only allowed to declare some
@@ -1049,7 +1054,7 @@
mNetworkSpecifier = originalSpecifier;
mSignalStrength = originalSignalStrength;
mTransportInfo = originalTransportInfo;
- mAccessUids.addAll(originalAccessUids);
+ mAllowedUids.addAll(originalAllowedUids);
// Only retain the owner and administrator UIDs if they match the app registering the remote
// caller that registered the network.
@@ -1836,20 +1841,20 @@
* @hide
*/
@NonNull
- private final ArraySet<Integer> mAccessUids = new ArraySet<>();
+ private final ArraySet<Integer> mAllowedUids = new ArraySet<>();
/**
* Set the list of UIDs that can always access this network.
* @param uids
* @hide
*/
- public void setAccessUids(@NonNull final Set<Integer> uids) {
+ public void setAllowedUids(@NonNull final Set<Integer> uids) {
// could happen with nc.set(nc), cheaper than always making a defensive copy
- if (uids == mAccessUids) return;
+ if (uids == mAllowedUids) return;
Objects.requireNonNull(uids);
- mAccessUids.clear();
- mAccessUids.addAll(uids);
+ mAllowedUids.clear();
+ mAllowedUids.addAll(uids);
}
/**
@@ -1867,35 +1872,36 @@
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
@RequiresPermission(android.Manifest.permission.NETWORK_FACTORY)
- public @NonNull Set<Integer> getAccessUids() {
- return new ArraySet<>(mAccessUids);
+ public @NonNull Set<Integer> getAllowedUids() {
+ return new ArraySet<>(mAllowedUids);
}
/** @hide */
// For internal clients that know what they are doing and need to avoid the performance hit
// of the defensive copy.
- public @NonNull ArraySet<Integer> getAccessUidsNoCopy() {
- return mAccessUids;
+ public @NonNull ArraySet<Integer> getAllowedUidsNoCopy() {
+ return mAllowedUids;
}
/**
- * Test whether this UID has special permission to access this network, as per mAccessUids.
+ * Test whether this UID has special permission to access this network, as per mAllowedUids.
* @hide
*/
- public boolean isAccessUid(int uid) {
- return mAccessUids.contains(uid);
+ // TODO : should this be "doesUidHaveAccess" and check the USE_RESTRICTED_NETWORKS permission ?
+ public boolean isUidWithAccess(int uid) {
+ return mAllowedUids.contains(uid);
}
/**
* @return whether any UID is in the list of access UIDs
* @hide
*/
- public boolean hasAccessUids() {
- return !mAccessUids.isEmpty();
+ public boolean hasAllowedUids() {
+ return !mAllowedUids.isEmpty();
}
- private boolean equalsAccessUids(@NonNull NetworkCapabilities other) {
- return mAccessUids.equals(other.mAccessUids);
+ private boolean equalsAllowedUids(@NonNull NetworkCapabilities other) {
+ return mAllowedUids.equals(other.mAllowedUids);
}
/**
@@ -2052,7 +2058,7 @@
&& equalsSpecifier(that)
&& equalsTransportInfo(that)
&& equalsUids(that)
- && equalsAccessUids(that)
+ && equalsAllowedUids(that)
&& equalsSSID(that)
&& equalsOwnerUid(that)
&& equalsPrivateDnsBroken(that)
@@ -2077,7 +2083,7 @@
+ mSignalStrength * 29
+ mOwnerUid * 31
+ Objects.hashCode(mUids) * 37
- + Objects.hashCode(mAccessUids) * 41
+ + Objects.hashCode(mAllowedUids) * 41
+ Objects.hashCode(mSSID) * 43
+ Objects.hashCode(mTransportInfo) * 47
+ Objects.hashCode(mPrivateDnsBroken) * 53
@@ -2114,7 +2120,7 @@
dest.writeParcelable((Parcelable) mTransportInfo, flags);
dest.writeInt(mSignalStrength);
writeParcelableArraySet(dest, mUids, flags);
- dest.writeIntArray(CollectionUtils.toIntArray(mAccessUids));
+ dest.writeIntArray(CollectionUtils.toIntArray(mAllowedUids));
dest.writeString(mSSID);
dest.writeBoolean(mPrivateDnsBroken);
dest.writeIntArray(getAdministratorUids());
@@ -2141,10 +2147,10 @@
netCap.mTransportInfo = in.readParcelable(null);
netCap.mSignalStrength = in.readInt();
netCap.mUids = readParcelableArraySet(in, null /* ClassLoader, null for default */);
- final int[] accessUids = in.createIntArray();
- netCap.mAccessUids.ensureCapacity(accessUids.length);
- for (int uid : accessUids) {
- netCap.mAccessUids.add(uid);
+ final int[] allowedUids = in.createIntArray();
+ netCap.mAllowedUids.ensureCapacity(allowedUids.length);
+ for (int uid : allowedUids) {
+ netCap.mAllowedUids.add(uid);
}
netCap.mSSID = in.readString();
netCap.mPrivateDnsBroken = in.readBoolean();
@@ -2223,8 +2229,8 @@
}
}
- if (hasAccessUids()) {
- sb.append(" AccessUids: <").append(mAccessUids).append(">");
+ if (hasAllowedUids()) {
+ sb.append(" AllowedUids: <").append(mAllowedUids).append(">");
}
if (mOwnerUid != Process.INVALID_UID) {
@@ -3043,9 +3049,9 @@
@NonNull
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
@RequiresPermission(android.Manifest.permission.NETWORK_FACTORY)
- public Builder setAccessUids(@NonNull Set<Integer> uids) {
+ public Builder setAllowedUids(@NonNull Set<Integer> uids) {
Objects.requireNonNull(uids);
- mCaps.setAccessUids(uids);
+ mCaps.setAllowedUids(uids);
return this;
}
diff --git a/framework/src/android/net/ProfileNetworkPreference.java b/framework/src/android/net/ProfileNetworkPreference.java
index f43acce..fb271e3 100644
--- a/framework/src/android/net/ProfileNetworkPreference.java
+++ b/framework/src/android/net/ProfileNetworkPreference.java
@@ -22,14 +22,12 @@
import static android.net.NetworkCapabilities.NET_ENTERPRISE_ID_5;
import android.annotation.NonNull;
-import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.net.ConnectivityManager.ProfileNetworkPreferencePolicy;
import android.os.Parcel;
import android.os.Parcelable;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Arrays;
import java.util.Objects;
/**
@@ -41,31 +39,31 @@
public final class ProfileNetworkPreference implements Parcelable {
private final @ProfileNetworkPreferencePolicy int mPreference;
private final @NetworkCapabilities.EnterpriseId int mPreferenceEnterpriseId;
- private final List<Integer> mIncludedUids;
- private final List<Integer> mExcludedUids;
+ private int[] mIncludedUids = new int[0];
+ private int[] mExcludedUids = new int[0];
- private ProfileNetworkPreference(int preference, List<Integer> includedUids,
- List<Integer> excludedUids,
+ private ProfileNetworkPreference(int preference, int[] includedUids,
+ int[] excludedUids,
@NetworkCapabilities.EnterpriseId int preferenceEnterpriseId) {
mPreference = preference;
mPreferenceEnterpriseId = preferenceEnterpriseId;
if (includedUids != null) {
- mIncludedUids = new ArrayList<>(includedUids);
+ mIncludedUids = includedUids.clone();
} else {
- mIncludedUids = new ArrayList<>();
+ mIncludedUids = new int[0];
}
if (excludedUids != null) {
- mExcludedUids = new ArrayList<>(excludedUids);
+ mExcludedUids = excludedUids.clone();
} else {
- mExcludedUids = new ArrayList<>();
+ mExcludedUids = new int[0];
}
}
private ProfileNetworkPreference(Parcel in) {
mPreference = in.readInt();
- mIncludedUids = in.readArrayList(Integer.class.getClassLoader());
- mExcludedUids = in.readArrayList(Integer.class.getClassLoader());
+ in.readIntArray(mIncludedUids);
+ in.readIntArray(mExcludedUids);
mPreferenceEnterpriseId = in.readInt();
}
@@ -74,31 +72,31 @@
}
/**
- * Get the list of UIDs subject to this preference.
+ * Get the array of UIDs subject to this preference.
*
* Included UIDs and Excluded UIDs can't both be non-empty.
* if both are empty, it means this request applies to all uids in the user profile.
* if included is not empty, then only included UIDs are applied.
* if excluded is not empty, then it is all uids in the user profile except these UIDs.
- * @return List of uids included for the profile preference.
+ * @return Array of uids included for the profile preference.
* {@see #getExcludedUids()}
*/
- public @NonNull List<Integer> getIncludedUids() {
- return new ArrayList<>(mIncludedUids);
+ public @NonNull int[] getIncludedUids() {
+ return mIncludedUids.clone();
}
/**
- * Get the list of UIDS excluded from this preference.
+ * Get the array of UIDS excluded from this preference.
*
* <ul>Included UIDs and Excluded UIDs can't both be non-empty.</ul>
* <ul>If both are empty, it means this request applies to all uids in the user profile.</ul>
* <ul>If included is not empty, then only included UIDs are applied.</ul>
* <ul>If excluded is not empty, then it is all uids in the user profile except these UIDs.</ul>
- * @return List of uids not included for the profile preference.
+ * @return Array of uids not included for the profile preference.
* {@see #getIncludedUids()}
*/
- public @NonNull List<Integer> getExcludedUids() {
- return new ArrayList<>(mExcludedUids);
+ public @NonNull int[] getExcludedUids() {
+ return mExcludedUids.clone();
}
/**
@@ -134,8 +132,8 @@
if (o == null || getClass() != o.getClass()) return false;
final ProfileNetworkPreference that = (ProfileNetworkPreference) o;
return mPreference == that.mPreference
- && (Objects.equals(mIncludedUids, that.mIncludedUids))
- && (Objects.equals(mExcludedUids, that.mExcludedUids))
+ && (Arrays.equals(mIncludedUids, that.mIncludedUids))
+ && (Arrays.equals(mExcludedUids, that.mExcludedUids))
&& mPreferenceEnterpriseId == that.mPreferenceEnterpriseId;
}
@@ -143,8 +141,8 @@
public int hashCode() {
return mPreference
+ mPreferenceEnterpriseId * 2
- + (Objects.hashCode(mIncludedUids) * 11)
- + (Objects.hashCode(mExcludedUids) * 13);
+ + (Arrays.hashCode(mIncludedUids) * 11)
+ + (Arrays.hashCode(mExcludedUids) * 13);
}
/**
@@ -154,8 +152,8 @@
public static final class Builder {
private @ProfileNetworkPreferencePolicy int mPreference =
PROFILE_NETWORK_PREFERENCE_DEFAULT;
- private @NonNull List<Integer> mIncludedUids = new ArrayList<>();
- private @NonNull List<Integer> mExcludedUids = new ArrayList<>();
+ private int[] mIncludedUids = new int[0];
+ private int[] mExcludedUids = new int[0];
private int mPreferenceEnterpriseId;
/**
@@ -177,44 +175,38 @@
}
/**
- * This is a list of uids for which profile perefence is set.
- * Null would mean that this preference applies to all uids in the profile.
- * {@see #setExcludedUids(List<Integer>)}
+ * This is a array of uids for which profile perefence is set.
+ * Empty would mean that this preference applies to all uids in the profile.
+ * {@see #setExcludedUids(int[])}
* Included UIDs and Excluded UIDs can't both be non-empty.
* if both are empty, it means this request applies to all uids in the user profile.
* if included is not empty, then only included UIDs are applied.
* if excluded is not empty, then it is all uids in the user profile except these UIDs.
- * @param uids list of uids that are included
+ * @param uids Array of uids that are included
* @return The builder to facilitate chaining.
*/
@NonNull
- public Builder setIncludedUids(@Nullable List<Integer> uids) {
- if (uids != null) {
- mIncludedUids = new ArrayList<Integer>(uids);
- } else {
- mIncludedUids = new ArrayList<Integer>();
- }
+ public Builder setIncludedUids(@NonNull int[] uids) {
+ Objects.requireNonNull(uids);
+ mIncludedUids = uids.clone();
return this;
}
/**
- * This is a list of uids that are excluded for the profile perefence.
- * {@see #setIncludedUids(List<Integer>)}
+ * This is a array of uids that are excluded for the profile perefence.
+ * {@see #setIncludedUids(int[])}
* Included UIDs and Excluded UIDs can't both be non-empty.
* if both are empty, it means this request applies to all uids in the user profile.
* if included is not empty, then only included UIDs are applied.
* if excluded is not empty, then it is all uids in the user profile except these UIDs.
- * @param uids list of uids that are not included
+ * @param uids Array of uids that are not included
* @return The builder to facilitate chaining.
*/
@NonNull
- public Builder setExcludedUids(@Nullable List<Integer> uids) {
- if (uids != null) {
- mExcludedUids = new ArrayList<Integer>(uids);
- } else {
- mExcludedUids = new ArrayList<Integer>();
- }
+ public Builder setExcludedUids(@NonNull int[] uids) {
+ Objects.requireNonNull(uids);
+ mExcludedUids = uids.clone();
return this;
}
@@ -241,7 +233,7 @@
*/
@NonNull
public ProfileNetworkPreference build() {
- if (mIncludedUids.size() > 0 && mExcludedUids.size() > 0) {
+ if (mIncludedUids.length > 0 && mExcludedUids.length > 0) {
throw new IllegalArgumentException("Both includedUids and excludedUids "
+ "cannot be nonempty");
}
@@ -280,8 +272,8 @@
@Override
public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
dest.writeInt(mPreference);
- dest.writeList(mIncludedUids);
- dest.writeList(mExcludedUids);
+ dest.writeIntArray(mIncludedUids);
+ dest.writeIntArray(mExcludedUids);
dest.writeInt(mPreferenceEnterpriseId);
}
diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java
index eb85120..221b65d 100644
--- a/service/src/com/android/server/ConnectivityService.java
+++ b/service/src/com/android/server/ConnectivityService.java
@@ -2252,7 +2252,7 @@
newNc.setAdministratorUids(new int[0]);
if (!checkAnyPermissionOf(
callerPid, callerUid, android.Manifest.permission.NETWORK_FACTORY)) {
- newNc.setAccessUids(new ArraySet<>());
+ newNc.setAllowedUids(new ArraySet<>());
newNc.setSubscriptionIds(Collections.emptySet());
}
@@ -6466,7 +6466,7 @@
if (nc.isPrivateDnsBroken()) {
throw new IllegalArgumentException("Can't request broken private DNS");
}
- if (nc.hasAccessUids()) {
+ if (nc.hasAllowedUids()) {
throw new IllegalArgumentException("Can't request access UIDs");
}
}
@@ -7923,7 +7923,7 @@
final NetworkCapabilities prevNc = nai.getAndSetNetworkCapabilities(newNc);
updateVpnUids(nai, prevNc, newNc);
- updateAccessUids(nai, prevNc, newNc);
+ updateAllowedUids(nai, prevNc, newNc);
nai.updateScoreForNetworkAgentUpdate();
if (nai.getCurrentScore() == oldScore && newNc.equalRequestableCapabilities(prevNc)) {
@@ -8153,17 +8153,17 @@
}
}
- private void updateAccessUids(@NonNull NetworkAgentInfo nai,
+ private void updateAllowedUids(@NonNull NetworkAgentInfo nai,
@Nullable NetworkCapabilities prevNc, @Nullable NetworkCapabilities newNc) {
// In almost all cases both NC code for empty access UIDs. return as fast as possible.
- final boolean prevEmpty = null == prevNc || prevNc.getAccessUidsNoCopy().isEmpty();
- final boolean newEmpty = null == newNc || newNc.getAccessUidsNoCopy().isEmpty();
+ final boolean prevEmpty = null == prevNc || prevNc.getAllowedUidsNoCopy().isEmpty();
+ final boolean newEmpty = null == newNc || newNc.getAllowedUidsNoCopy().isEmpty();
if (prevEmpty && newEmpty) return;
final ArraySet<Integer> prevUids =
- null == prevNc ? new ArraySet<>() : prevNc.getAccessUidsNoCopy();
+ null == prevNc ? new ArraySet<>() : prevNc.getAllowedUidsNoCopy();
final ArraySet<Integer> newUids =
- null == newNc ? new ArraySet<>() : newNc.getAccessUidsNoCopy();
+ null == newNc ? new ArraySet<>() : newNc.getAllowedUidsNoCopy();
if (prevUids.equals(newUids)) return;
@@ -9113,7 +9113,7 @@
}
networkAgent.created = true;
networkAgent.onNetworkCreated();
- updateAccessUids(networkAgent, null, networkAgent.networkCapabilities);
+ updateAllowedUids(networkAgent, null, networkAgent.networkCapabilities);
}
if (!networkAgent.everConnected && state == NetworkInfo.State.CONNECTED) {
@@ -10625,15 +10625,16 @@
@NonNull final UserHandle profile,
@NonNull final ProfileNetworkPreference profileNetworkPreference) {
final UidRange profileUids = UidRange.createForUser(profile);
- Set<UidRange> uidRangeSet = UidRangeUtils.convertListToUidRange(
- profileNetworkPreference.getIncludedUids());
+ Set<UidRange> uidRangeSet = UidRangeUtils.convertArrayToUidRange(
+ profileNetworkPreference.getIncludedUids());
+
if (uidRangeSet.size() > 0) {
if (!UidRangeUtils.isRangeSetInUidRange(profileUids, uidRangeSet)) {
throw new IllegalArgumentException(
"Allow uid range is outside the uid range of profile.");
}
} else {
- ArraySet<UidRange> disallowUidRangeSet = UidRangeUtils.convertListToUidRange(
+ ArraySet<UidRange> disallowUidRangeSet = UidRangeUtils.convertArrayToUidRange(
profileNetworkPreference.getExcludedUids());
if (disallowUidRangeSet.size() > 0) {
if (!UidRangeUtils.isRangeSetInUidRange(profileUids, disallowUidRangeSet)) {
diff --git a/service/src/com/android/server/connectivity/NetworkAgentInfo.java b/service/src/com/android/server/connectivity/NetworkAgentInfo.java
index ee45e5c..cbfc4f7 100644
--- a/service/src/com/android/server/connectivity/NetworkAgentInfo.java
+++ b/service/src/com/android/server/connectivity/NetworkAgentInfo.java
@@ -1219,16 +1219,16 @@
if (nc.hasTransport(TRANSPORT_TEST)) {
nc.restrictCapabilitiesForTestNetwork(creatorUid);
}
- if (!areAccessUidsAcceptableFromNetworkAgent(nc, authenticator)) {
- nc.setAccessUids(new ArraySet<>());
+ if (!areAllowedUidsAcceptableFromNetworkAgent(nc, authenticator)) {
+ nc.setAllowedUids(new ArraySet<>());
}
}
- private static boolean areAccessUidsAcceptableFromNetworkAgent(
+ private static boolean areAllowedUidsAcceptableFromNetworkAgent(
@NonNull final NetworkCapabilities nc,
@Nullable final CarrierPrivilegeAuthenticator carrierPrivilegeAuthenticator) {
// NCs without access UIDs are fine.
- if (!nc.hasAccessUids()) return true;
+ if (!nc.hasAllowedUids()) return true;
// S and below must never accept access UIDs, even if an agent sends them, because netd
// didn't support the required feature in S.
if (!SdkLevel.isAtLeastT()) return false;
@@ -1244,9 +1244,9 @@
// This can only work in T where there is support for CarrierPrivilegeAuthenticator
if (null != carrierPrivilegeAuthenticator
&& nc.hasSingleTransport(TRANSPORT_CELLULAR)
- && (1 == nc.getAccessUidsNoCopy().size())
+ && (1 == nc.getAllowedUidsNoCopy().size())
&& (carrierPrivilegeAuthenticator.hasCarrierPrivilegeForNetworkCapabilities(
- nc.getAccessUidsNoCopy().valueAt(0), nc))) {
+ nc.getAllowedUidsNoCopy().valueAt(0), nc))) {
return true;
}
diff --git a/service/src/com/android/server/connectivity/NetworkDiagnostics.java b/service/src/com/android/server/connectivity/NetworkDiagnostics.java
index 2e51be3..509110d 100644
--- a/service/src/com/android/server/connectivity/NetworkDiagnostics.java
+++ b/service/src/com/android/server/connectivity/NetworkDiagnostics.java
@@ -206,7 +206,7 @@
}
for (RouteInfo route : mLinkProperties.getRoutes()) {
- if (route.hasGateway()) {
+ if (route.getType() == RouteInfo.RTN_UNICAST && route.hasGateway()) {
InetAddress gateway = route.getGateway();
prepareIcmpMeasurement(gateway);
if (route.isIPv6Default()) {
diff --git a/service/src/com/android/server/connectivity/UidRangeUtils.java b/service/src/com/android/server/connectivity/UidRangeUtils.java
index 7318296..541340b 100644
--- a/service/src/com/android/server/connectivity/UidRangeUtils.java
+++ b/service/src/com/android/server/connectivity/UidRangeUtils.java
@@ -21,6 +21,7 @@
import android.util.ArraySet;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@@ -125,7 +126,7 @@
}
/**
- * Convert a list of uid to set of UidRanges.
+ * Convert a list of uids to set of UidRanges.
* @param uids list of uids
* @return set of UidRanges
* @hide
@@ -153,4 +154,34 @@
uidRangeSet.add(new UidRange(start, stop));
return uidRangeSet;
}
+
+ /**
+ * Convert an array of uids to set of UidRanges.
+ * @param uids array of uids
+ * @return set of UidRanges
+ * @hide
+ */
+ public static ArraySet<UidRange> convertArrayToUidRange(@NonNull int[] uids) {
+ Objects.requireNonNull(uids);
+ final ArraySet<UidRange> uidRangeSet = new ArraySet<UidRange>();
+ if (uids.length == 0) {
+ return uidRangeSet;
+ }
+ int[] uidsNew = uids.clone();
+ Arrays.sort(uidsNew);
+ int start = uidsNew[0];
+ int stop = start;
+
+ for (int i : uidsNew) {
+ if (i <= stop + 1) {
+ stop = i;
+ } else {
+ uidRangeSet.add(new UidRange(start, stop));
+ start = i;
+ stop = i;
+ }
+ }
+ uidRangeSet.add(new UidRange(start, stop));
+ return uidRangeSet;
+ }
}
diff --git a/tests/common/java/android/net/NetworkCapabilitiesTest.java b/tests/common/java/android/net/NetworkCapabilitiesTest.java
index b6926a8..9ae5fab 100644
--- a/tests/common/java/android/net/NetworkCapabilitiesTest.java
+++ b/tests/common/java/android/net/NetworkCapabilitiesTest.java
@@ -310,38 +310,38 @@
}
@Test @IgnoreUpTo(SC_V2)
- public void testSetAccessUids() {
+ public void testSetAllowedUids() {
final NetworkCapabilities nc = new NetworkCapabilities();
- assertThrows(NullPointerException.class, () -> nc.setAccessUids(null));
- assertFalse(nc.hasAccessUids());
- assertFalse(nc.isAccessUid(0));
- assertFalse(nc.isAccessUid(1000));
- assertEquals(0, nc.getAccessUids().size());
- nc.setAccessUids(new ArraySet<>());
- assertFalse(nc.hasAccessUids());
- assertFalse(nc.isAccessUid(0));
- assertFalse(nc.isAccessUid(1000));
- assertEquals(0, nc.getAccessUids().size());
+ assertThrows(NullPointerException.class, () -> nc.setAllowedUids(null));
+ assertFalse(nc.hasAllowedUids());
+ assertFalse(nc.isUidWithAccess(0));
+ assertFalse(nc.isUidWithAccess(1000));
+ assertEquals(0, nc.getAllowedUids().size());
+ nc.setAllowedUids(new ArraySet<>());
+ assertFalse(nc.hasAllowedUids());
+ assertFalse(nc.isUidWithAccess(0));
+ assertFalse(nc.isUidWithAccess(1000));
+ assertEquals(0, nc.getAllowedUids().size());
final ArraySet<Integer> uids = new ArraySet<>();
uids.add(200);
uids.add(250);
uids.add(-1);
uids.add(Integer.MAX_VALUE);
- nc.setAccessUids(uids);
+ nc.setAllowedUids(uids);
assertNotEquals(nc, new NetworkCapabilities());
- assertTrue(nc.hasAccessUids());
+ assertTrue(nc.hasAllowedUids());
final List<Integer> includedList = List.of(-2, 0, 199, 700, 901, 1000, Integer.MIN_VALUE);
final List<Integer> excludedList = List.of(-1, 200, 250, Integer.MAX_VALUE);
for (final int uid : includedList) {
- assertFalse(nc.isAccessUid(uid));
+ assertFalse(nc.isUidWithAccess(uid));
}
for (final int uid : excludedList) {
- assertTrue(nc.isAccessUid(uid));
+ assertTrue(nc.isUidWithAccess(uid));
}
- final Set<Integer> outUids = nc.getAccessUids();
+ final Set<Integer> outUids = nc.getAllowedUids();
assertEquals(4, outUids.size());
for (final int uid : includedList) {
assertFalse(outUids.contains(uid));
@@ -361,10 +361,10 @@
.addCapability(NET_CAPABILITY_EIMS)
.addCapability(NET_CAPABILITY_NOT_METERED);
if (isAtLeastS()) {
- final ArraySet<Integer> accessUids = new ArraySet<>();
- accessUids.add(4);
- accessUids.add(9);
- netCap.setAccessUids(accessUids);
+ final ArraySet<Integer> allowedUids = new ArraySet<>();
+ allowedUids.add(4);
+ allowedUids.add(9);
+ netCap.setAllowedUids(allowedUids);
netCap.setSubscriptionIds(Set.of(TEST_SUBID1, TEST_SUBID2));
netCap.setUids(uids);
}
diff --git a/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt b/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt
index af567ff..53b00db 100644
--- a/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt
+++ b/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt
@@ -493,33 +493,33 @@
}
}
- private fun ncWithAccessUids(vararg uids: Int) = NetworkCapabilities.Builder()
+ private fun ncWithAllowedUids(vararg uids: Int) = NetworkCapabilities.Builder()
.addTransportType(TRANSPORT_TEST)
- .setAccessUids(uids.toSet()).build()
+ .setAllowedUids(uids.toSet()).build()
@Test
fun testRejectedUpdates() {
val callback = TestableNetworkCallback(DEFAULT_TIMEOUT_MS)
// will be cleaned up in tearDown
registerNetworkCallback(makeTestNetworkRequest(), callback)
- val agent = createNetworkAgent(initialNc = ncWithAccessUids(200))
+ val agent = createNetworkAgent(initialNc = ncWithAllowedUids(200))
agent.register()
agent.markConnected()
// Make sure the UIDs have been ignored.
callback.expectCallback<Available>(agent.network!!)
callback.expectCapabilitiesThat(agent.network!!) {
- it.accessUids.isEmpty() && !it.hasCapability(NET_CAPABILITY_VALIDATED)
+ it.allowedUids.isEmpty() && !it.hasCapability(NET_CAPABILITY_VALIDATED)
}
callback.expectCallback<LinkPropertiesChanged>(agent.network!!)
callback.expectCallback<BlockedStatus>(agent.network!!)
callback.expectCapabilitiesThat(agent.network!!) {
- it.accessUids.isEmpty() && it.hasCapability(NET_CAPABILITY_VALIDATED)
+ it.allowedUids.isEmpty() && it.hasCapability(NET_CAPABILITY_VALIDATED)
}
callback.assertNoCallback(NO_CALLBACK_TIMEOUT)
// Make sure that the UIDs are also ignored upon update
- agent.sendNetworkCapabilities(ncWithAccessUids(200, 300))
+ agent.sendNetworkCapabilities(ncWithAllowedUids(200, 300))
callback.assertNoCallback(NO_CALLBACK_TIMEOUT)
}
diff --git a/tests/unit/java/com/android/server/ConnectivityServiceTest.java b/tests/unit/java/com/android/server/ConnectivityServiceTest.java
index 94272b8..6d802af 100644
--- a/tests/unit/java/com/android/server/ConnectivityServiceTest.java
+++ b/tests/unit/java/com/android/server/ConnectivityServiceTest.java
@@ -3906,14 +3906,14 @@
}
@Test
- public void testNoAccessUidsInNetworkRequests() throws Exception {
+ public void testNoAllowedUidsInNetworkRequests() throws Exception {
final PendingIntent pendingIntent = PendingIntent.getBroadcast(
mContext, 0 /* requestCode */, new Intent("a"), FLAG_IMMUTABLE);
final NetworkRequest r = new NetworkRequest.Builder().build();
- final ArraySet<Integer> accessUids = new ArraySet<>();
- accessUids.add(6);
- accessUids.add(9);
- r.networkCapabilities.setAccessUids(accessUids);
+ final ArraySet<Integer> allowedUids = new ArraySet<>();
+ allowedUids.add(6);
+ allowedUids.add(9);
+ r.networkCapabilities.setAllowedUids(allowedUids);
final Handler handler = new Handler(ConnectivityThread.getInstanceLooper());
final NetworkCallback cb = new NetworkCallback();
@@ -3928,7 +3928,7 @@
// Make sure that resetting the access UIDs to the empty set will allow calling
// requestNetwork and registerNetworkCallback.
- r.networkCapabilities.setAccessUids(Collections.emptySet());
+ r.networkCapabilities.setAllowedUids(Collections.emptySet());
mCm.requestNetwork(r, cb);
mCm.unregisterNetworkCallback(cb);
mCm.registerNetworkCallback(r, cb);
@@ -13870,12 +13870,13 @@
ProfileNetworkPreference profileNetworkPreference) {
final Set<UidRange> uidRangeSet;
UidRange range = UidRange.createForUser(handle);
- if (profileNetworkPreference.getIncludedUids().size() != 0) {
- uidRangeSet = UidRangeUtils.convertListToUidRange(
+ if (profileNetworkPreference.getIncludedUids().length != 0) {
+ uidRangeSet = UidRangeUtils.convertArrayToUidRange(
profileNetworkPreference.getIncludedUids());
- } else if (profileNetworkPreference.getExcludedUids().size() != 0) {
+
+ } else if (profileNetworkPreference.getExcludedUids().length != 0) {
uidRangeSet = UidRangeUtils.removeRangeSetFromUidRange(
- range, UidRangeUtils.convertListToUidRange(
+ range, UidRangeUtils.convertArrayToUidRange(
profileNetworkPreference.getExcludedUids()));
} else {
uidRangeSet = new ArraySet<>();
@@ -14247,7 +14248,7 @@
profileNetworkPreferenceBuilder.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE);
profileNetworkPreferenceBuilder.setPreferenceEnterpriseId(NET_ENTERPRISE_ID_1);
profileNetworkPreferenceBuilder.setIncludedUids(
- List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID)));
+ new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID)});
registerDefaultNetworkCallbacks();
testPreferenceForUserNetworkUpDownForGivenPreference(
profileNetworkPreferenceBuilder.build(), false, testHandle,
@@ -14266,7 +14267,7 @@
profileNetworkPreferenceBuilder.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE);
profileNetworkPreferenceBuilder.setPreferenceEnterpriseId(NET_ENTERPRISE_ID_1);
profileNetworkPreferenceBuilder.setIncludedUids(
- List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)));
+ new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)});
registerDefaultNetworkCallbacks();
testPreferenceForUserNetworkUpDownForGivenPreference(
profileNetworkPreferenceBuilder.build(), false,
@@ -14285,7 +14286,7 @@
profileNetworkPreferenceBuilder.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE);
profileNetworkPreferenceBuilder.setPreferenceEnterpriseId(NET_ENTERPRISE_ID_1);
profileNetworkPreferenceBuilder.setExcludedUids(
- List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)));
+ new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)});
registerDefaultNetworkCallbacks();
testPreferenceForUserNetworkUpDownForGivenPreference(
profileNetworkPreferenceBuilder.build(), false,
@@ -14305,7 +14306,7 @@
profileNetworkPreferenceBuilder.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE);
profileNetworkPreferenceBuilder.setPreferenceEnterpriseId(NET_ENTERPRISE_ID_1);
profileNetworkPreferenceBuilder.setExcludedUids(
- List.of(testHandle.getUid(0) - 1));
+ new int[]{testHandle.getUid(0) - 1});
final TestOnCompleteListener listener = new TestOnCompleteListener();
Assert.assertThrows(IllegalArgumentException.class, () -> mCm.setProfileNetworkPreferences(
testHandle, List.of(profileNetworkPreferenceBuilder.build()),
@@ -14313,7 +14314,7 @@
profileNetworkPreferenceBuilder.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE);
profileNetworkPreferenceBuilder.setIncludedUids(
- List.of(testHandle.getUid(0) - 1));
+ new int[]{testHandle.getUid(0) - 1});
Assert.assertThrows(IllegalArgumentException.class,
() -> mCm.setProfileNetworkPreferences(
testHandle, List.of(profileNetworkPreferenceBuilder.build()),
@@ -14322,9 +14323,9 @@
profileNetworkPreferenceBuilder.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE);
profileNetworkPreferenceBuilder.setIncludedUids(
- List.of(testHandle.getUid(0) - 1));
+ new int[]{testHandle.getUid(0) - 1});
profileNetworkPreferenceBuilder.setExcludedUids(
- List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)));
+ new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)});
Assert.assertThrows(IllegalArgumentException.class,
() -> mCm.setProfileNetworkPreferences(
testHandle, List.of(profileNetworkPreferenceBuilder.build()),
@@ -14335,9 +14336,9 @@
profileNetworkPreferenceBuilder2.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE);
profileNetworkPreferenceBuilder2.setPreferenceEnterpriseId(NET_ENTERPRISE_ID_1);
profileNetworkPreferenceBuilder2.setIncludedUids(
- List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)));
+ new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)});
profileNetworkPreferenceBuilder.setIncludedUids(
- List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)));
+ new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)});
Assert.assertThrows(IllegalArgumentException.class,
() -> mCm.setProfileNetworkPreferences(
testHandle, List.of(profileNetworkPreferenceBuilder.build(),
@@ -14346,9 +14347,9 @@
profileNetworkPreferenceBuilder2.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE);
profileNetworkPreferenceBuilder2.setExcludedUids(
- List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)));
+ new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)});
profileNetworkPreferenceBuilder.setExcludedUids(
- List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)));
+ new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)});
Assert.assertThrows(IllegalArgumentException.class,
() -> mCm.setProfileNetworkPreferences(
testHandle, List.of(profileNetworkPreferenceBuilder.build(),
@@ -14358,9 +14359,9 @@
profileNetworkPreferenceBuilder2.setPreference(
PROFILE_NETWORK_PREFERENCE_ENTERPRISE_NO_FALLBACK);
profileNetworkPreferenceBuilder2.setExcludedUids(
- List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)));
+ new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)});
profileNetworkPreferenceBuilder.setExcludedUids(
- List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)));
+ new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)});
Assert.assertThrows(IllegalArgumentException.class,
() -> mCm.setProfileNetworkPreferences(
testHandle, List.of(profileNetworkPreferenceBuilder.build(),
@@ -14687,7 +14688,7 @@
}
@Test
- public void testAccessUids() throws Exception {
+ public void testAllowedUids() throws Exception {
final int preferenceOrder =
ConnectivityService.PREFERENCE_ORDER_IRRELEVANT_BECAUSE_NOT_DEFAULT;
mServiceContext.setPermission(NETWORK_FACTORY, PERMISSION_GRANTED);
@@ -14704,7 +14705,7 @@
final NetworkCapabilities nc = new NetworkCapabilities.Builder()
.addTransportType(TRANSPORT_TEST)
.removeCapability(NET_CAPABILITY_NOT_RESTRICTED)
- .setAccessUids(uids)
+ .setAllowedUids(uids)
.build();
final TestNetworkAgentWrapper agent = new TestNetworkAgentWrapper(TRANSPORT_TEST,
new LinkProperties(), nc);
@@ -14722,10 +14723,10 @@
uids.add(300);
uids.add(400);
- nc.setAccessUids(uids);
+ nc.setAllowedUids(uids);
agent.setNetworkCapabilities(nc, true /* sendToConnectivityService */);
if (SdkLevel.isAtLeastT()) {
- cb.expectCapabilitiesThat(agent, caps -> caps.getAccessUids().equals(uids));
+ cb.expectCapabilitiesThat(agent, caps -> caps.getAllowedUids().equals(uids));
} else {
cb.assertNoCallback();
}
@@ -14739,10 +14740,10 @@
inOrder.verify(mMockNetd, times(1)).networkAddUidRangesParcel(uids300400Parcel);
}
- nc.setAccessUids(uids);
+ nc.setAllowedUids(uids);
agent.setNetworkCapabilities(nc, true /* sendToConnectivityService */);
if (SdkLevel.isAtLeastT()) {
- cb.expectCapabilitiesThat(agent, caps -> caps.getAccessUids().equals(uids));
+ cb.expectCapabilitiesThat(agent, caps -> caps.getAllowedUids().equals(uids));
inOrder.verify(mMockNetd, times(1)).networkRemoveUidRangesParcel(uids200Parcel);
} else {
cb.assertNoCallback();
@@ -14750,10 +14751,10 @@
uids.clear();
uids.add(600);
- nc.setAccessUids(uids);
+ nc.setAllowedUids(uids);
agent.setNetworkCapabilities(nc, true /* sendToConnectivityService */);
if (SdkLevel.isAtLeastT()) {
- cb.expectCapabilitiesThat(agent, caps -> caps.getAccessUids().equals(uids));
+ cb.expectCapabilitiesThat(agent, caps -> caps.getAllowedUids().equals(uids));
} else {
cb.assertNoCallback();
}
@@ -14767,10 +14768,10 @@
}
uids.clear();
- nc.setAccessUids(uids);
+ nc.setAllowedUids(uids);
agent.setNetworkCapabilities(nc, true /* sendToConnectivityService */);
if (SdkLevel.isAtLeastT()) {
- cb.expectCapabilitiesThat(agent, caps -> caps.getAccessUids().isEmpty());
+ cb.expectCapabilitiesThat(agent, caps -> caps.getAllowedUids().isEmpty());
inOrder.verify(mMockNetd, times(1)).networkRemoveUidRangesParcel(uids600Parcel);
} else {
cb.assertNoCallback();
@@ -14781,7 +14782,7 @@
}
@Test
- public void testCbsAccessUids() throws Exception {
+ public void testCbsAllowedUids() throws Exception {
mServiceContext.setPermission(NETWORK_FACTORY, PERMISSION_GRANTED);
mServiceContext.setPermission(MANAGE_TEST_NETWORKS, PERMISSION_GRANTED);
@@ -14818,29 +14819,29 @@
new LinkProperties(), ncb.build());
mCellNetworkAgent.connect(true);
cb.expectAvailableThenValidatedCallbacks(mCellNetworkAgent);
- ncb.setAccessUids(serviceUidSet);
+ ncb.setAllowedUids(serviceUidSet);
mCellNetworkAgent.setNetworkCapabilities(ncb.build(), true /* sendToCS */);
if (SdkLevel.isAtLeastT()) {
cb.expectCapabilitiesThat(mCellNetworkAgent,
- caps -> caps.getAccessUids().equals(serviceUidSet));
+ caps -> caps.getAllowedUids().equals(serviceUidSet));
} else {
// S must ignore access UIDs.
cb.assertNoCallback(TEST_CALLBACK_TIMEOUT_MS);
}
// ...but not to some other UID. Rejection sets UIDs to the empty set
- ncb.setAccessUids(nonServiceUidSet);
+ ncb.setAllowedUids(nonServiceUidSet);
mCellNetworkAgent.setNetworkCapabilities(ncb.build(), true /* sendToCS */);
if (SdkLevel.isAtLeastT()) {
cb.expectCapabilitiesThat(mCellNetworkAgent,
- caps -> caps.getAccessUids().isEmpty());
+ caps -> caps.getAllowedUids().isEmpty());
} else {
// S must ignore access UIDs.
cb.assertNoCallback(TEST_CALLBACK_TIMEOUT_MS);
}
// ...and also not to multiple UIDs even including the service UID
- ncb.setAccessUids(serviceUidSetPlus);
+ ncb.setAllowedUids(serviceUidSetPlus);
mCellNetworkAgent.setNetworkCapabilities(ncb.build(), true /* sendToCS */);
cb.assertNoCallback(TEST_CALLBACK_TIMEOUT_MS);
@@ -14863,7 +14864,7 @@
new LinkProperties(), ncb.build());
mWiFiNetworkAgent.connect(true);
cb.expectAvailableThenValidatedCallbacks(mWiFiNetworkAgent);
- ncb.setAccessUids(serviceUidSet);
+ ncb.setAllowedUids(serviceUidSet);
mWiFiNetworkAgent.setNetworkCapabilities(ncb.build(), true /* sendToCS */);
cb.assertNoCallback(TEST_CALLBACK_TIMEOUT_MS);
mCm.unregisterNetworkCallback(cb);
diff --git a/tests/unit/java/com/android/server/connectivity/UidRangeUtilsTest.java b/tests/unit/java/com/android/server/connectivity/UidRangeUtilsTest.java
index b8c2673..b8c552e 100644
--- a/tests/unit/java/com/android/server/connectivity/UidRangeUtilsTest.java
+++ b/tests/unit/java/com/android/server/connectivity/UidRangeUtilsTest.java
@@ -351,4 +351,55 @@
expected.add(uids6);
assertEquals(expected, UidRangeUtils.convertListToUidRange(input));
}
+
+ @Test @DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.R)
+ public void testConvertArrayToUidRange() {
+ final UidRange uids1_1 = new UidRange(1, 1);
+ final UidRange uids1_2 = new UidRange(1, 2);
+ final UidRange uids100_100 = new UidRange(100, 100);
+ final UidRange uids10_10 = new UidRange(10, 10);
+
+ final UidRange uids10_14 = new UidRange(10, 14);
+ final UidRange uids20_24 = new UidRange(20, 24);
+
+ final Set<UidRange> expected = new ArraySet<>();
+ int[] input = new int[0];
+
+ assertThrows(NullPointerException.class, () -> UidRangeUtils.convertArrayToUidRange(null));
+ assertEquals(expected, UidRangeUtils.convertArrayToUidRange(input));
+
+ input = new int[] {1};
+ expected.add(uids1_1);
+ assertEquals(expected, UidRangeUtils.convertArrayToUidRange(input));
+
+ input = new int[]{1, 2};
+ expected.clear();
+ expected.add(uids1_2);
+ assertEquals(expected, UidRangeUtils.convertArrayToUidRange(input));
+
+ input = new int[]{1, 100};
+ expected.clear();
+ expected.add(uids1_1);
+ expected.add(uids100_100);
+ assertEquals(expected, UidRangeUtils.convertArrayToUidRange(input));
+
+ input = new int[]{100, 1};
+ expected.clear();
+ expected.add(uids1_1);
+ expected.add(uids100_100);
+ assertEquals(expected, UidRangeUtils.convertArrayToUidRange(input));
+
+ input = new int[]{100, 1, 2, 1, 10};
+ expected.clear();
+ expected.add(uids1_2);
+ expected.add(uids10_10);
+ expected.add(uids100_100);
+ assertEquals(expected, UidRangeUtils.convertArrayToUidRange(input));
+
+ input = new int[]{10, 11, 12, 13, 14, 20, 21, 22, 23, 24};
+ expected.clear();
+ expected.add(uids10_14);
+ expected.add(uids20_24);
+ assertEquals(expected, UidRangeUtils.convertArrayToUidRange(input));
+ }
}