Revert^2 "Replace the usage of UidRange"

1b5c01b06f

UidRange is used in a shared way between ConnectivityService
and VPN through the use of NetworkCapabilities. UidRange will
be part of the ConnectivityService mainline but Vpn.java will
stay in the framework. We need a way to replace the APIs using
UidRange, or to make UidRange system API. The only really
relevant surface here is NetworkCapabilities#{setUids, getUids}.
The need for UidRange could be replaced by an integer Range, so
replace the usage of UidRange by a integer Range in
NetworkCapabilities#{setUids, getUids} and update the relevant
callers.

Bug: 172183305
Test: atest FrameworksNetTests CtsNetTestCasesLatestSdk

Change-Id: I0f679fb5fb8f4fe26461ca4912ca1fdfe7f43c9e
Merged-In: I4e5aec6ef1ea02e038fcd7ed117a3b67b69c5cb9
This commit is contained in:
Chiachang Wang
2021-03-19 00:45:39 +00:00
parent 1b5c01b06f
commit 8156c4ea31
8 changed files with 274 additions and 185 deletions

View File

@@ -20,8 +20,11 @@ import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.UserHandle;
import android.util.ArraySet;
import android.util.Range;
import java.util.Collection;
import java.util.Set;
/**
* An inclusive range of UIDs.
@@ -149,4 +152,32 @@ public final class UidRange implements Parcelable {
}
return false;
}
/**
* Convert a set of {@code Range<Integer>} to a set of {@link UidRange}.
*/
@Nullable
public static ArraySet<UidRange> fromIntRanges(@Nullable Set<Range<Integer>> ranges) {
if (null == ranges) return null;
final ArraySet<UidRange> uids = new ArraySet<>();
for (Range<Integer> range : ranges) {
uids.add(new UidRange(range.getLower(), range.getUpper()));
}
return uids;
}
/**
* Convert a set of {@link UidRange} to a set of {@code Range<Integer>}.
*/
@Nullable
public static ArraySet<Range<Integer>> toIntRanges(@Nullable Set<UidRange> ranges) {
if (null == ranges) return null;
final ArraySet<Range<Integer>> uids = new ArraySet<>();
for (UidRange range : ranges) {
uids.add(new Range<Integer>(range.start, range.stop));
}
return uids;
}
}