Merge "Block incoming non-VPN packets to apps under fully-routed VPN" am: fd20f8da0a

am: 8951473446

Change-Id: I5af81bc80dadd086261ba4b1eb706cc873bb7cfa
This commit is contained in:
Rubin Xu 2019-04-11 11:45:43 -07:00 • committed by android-build-merger
commit 131a0722cc

View file

@ -21,6 +21,8 @@ import static android.os.UserHandle.PER_USER_RANGE;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.Collection;
/**
* An inclusive range of UIDs.
*
@ -42,10 +44,16 @@ public final class UidRange implements Parcelable {
return new UidRange(userId * PER_USER_RANGE, (userId + 1) * PER_USER_RANGE - 1);
}
/** Returns the smallest user Id which is contained in this UidRange */
public int getStartUser() {
return start / PER_USER_RANGE;
}
/** Returns the largest user Id which is contained in this UidRange */
public int getEndUser() {
return stop / PER_USER_RANGE;
}
public boolean contains(int uid) {
return start <= uid && uid <= stop;
}
@ -117,4 +125,23 @@ public final class UidRange implements Parcelable {
return new UidRange[size];
}
};
/**
* Returns whether any of the UidRange in the collection contains the specified uid
*
* @param ranges The collection of UidRange to check
* @param uid the uid in question
* @return {@code true} if the uid is contained within the ranges, {@code false} otherwise
*
* @see UidRange#contains(int)
*/
public static boolean containsUid(Collection<UidRange> ranges, int uid) {
if (ranges == null) return false;
for (UidRange range : ranges) {
if (range.contains(uid)) {
return true;
}
}
return false;
}
}