Merge changes from topic "revert-1626206-replaceUidRange-MSYTKFNGUE" am: 35b926cc47
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1645768 Change-Id: I311d4e3e5718afbe7d9817a4c85040d8afe5d66d
This commit is contained in:
@@ -36,18 +36,9 @@ package android.net {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final class NetworkCapabilities implements android.os.Parcelable {
|
public final class NetworkCapabilities implements android.os.Parcelable {
|
||||||
method @Nullable public java.util.Set<android.util.Range<java.lang.Integer>> getUids();
|
|
||||||
field public static final int TRANSPORT_TEST = 7; // 0x7
|
field public static final int TRANSPORT_TEST = 7; // 0x7
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class NetworkCapabilities.Builder {
|
|
||||||
method @NonNull public android.net.NetworkCapabilities.Builder setUids(@Nullable java.util.Set<android.util.Range<java.lang.Integer>>);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class NetworkRequest.Builder {
|
|
||||||
method @NonNull public android.net.NetworkRequest.Builder setUids(@Nullable java.util.Set<android.util.Range<java.lang.Integer>>);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ParseException extends java.lang.RuntimeException {
|
public class ParseException extends java.lang.RuntimeException {
|
||||||
ctor public ParseException(@NonNull String);
|
ctor public ParseException(@NonNull String);
|
||||||
ctor public ParseException(@NonNull String, @NonNull Throwable);
|
ctor public ParseException(@NonNull String, @NonNull Throwable);
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import android.annotation.IntDef;
|
|||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.annotation.RequiresPermission;
|
import android.annotation.RequiresPermission;
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.annotation.SystemApi;
|
import android.annotation.SystemApi;
|
||||||
import android.compat.annotation.UnsupportedAppUsage;
|
import android.compat.annotation.UnsupportedAppUsage;
|
||||||
import android.net.ConnectivityManager.NetworkCallback;
|
import android.net.ConnectivityManager.NetworkCallback;
|
||||||
@@ -33,7 +32,6 @@ import android.os.Parcelable;
|
|||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
import android.util.Range;
|
|
||||||
import android.util.proto.ProtoOutputStream;
|
import android.util.proto.ProtoOutputStream;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
@@ -155,7 +153,7 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
setTransportInfo(null);
|
setTransportInfo(null);
|
||||||
}
|
}
|
||||||
mSignalStrength = nc.mSignalStrength;
|
mSignalStrength = nc.mSignalStrength;
|
||||||
mUids = (nc.mUids == null) ? null : new ArraySet<>(nc.mUids);
|
setUids(nc.mUids); // Will make the defensive copy
|
||||||
setAdministratorUids(nc.getAdministratorUids());
|
setAdministratorUids(nc.getAdministratorUids());
|
||||||
mOwnerUid = nc.mOwnerUid;
|
mOwnerUid = nc.mOwnerUid;
|
||||||
mUnwantedNetworkCapabilities = nc.mUnwantedNetworkCapabilities;
|
mUnwantedNetworkCapabilities = nc.mUnwantedNetworkCapabilities;
|
||||||
@@ -1460,8 +1458,9 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public @NonNull NetworkCapabilities setSingleUid(int uid) {
|
public @NonNull NetworkCapabilities setSingleUid(int uid) {
|
||||||
mUids = new ArraySet<>(1);
|
final ArraySet<UidRange> identity = new ArraySet<>(1);
|
||||||
mUids.add(new UidRange(uid, uid));
|
identity.add(new UidRange(uid, uid));
|
||||||
|
setUids(identity);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1470,34 +1469,22 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
* This makes a copy of the set so that callers can't modify it after the call.
|
* This makes a copy of the set so that callers can't modify it after the call.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public @NonNull NetworkCapabilities setUids(@Nullable Set<Range<Integer>> uids) {
|
public @NonNull NetworkCapabilities setUids(Set<UidRange> uids) {
|
||||||
mUids = UidRange.fromIntRanges(uids);
|
if (null == uids) {
|
||||||
|
mUids = null;
|
||||||
|
} else {
|
||||||
|
mUids = new ArraySet<>(uids);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of UIDs this network applies to.
|
* Get the list of UIDs this network applies to.
|
||||||
* This returns a copy of the set so that callers can't modify the original object.
|
* This returns a copy of the set so that callers can't modify the original object.
|
||||||
*
|
|
||||||
* @return the list of UIDs this network applies to. If {@code null}, then the network applies
|
|
||||||
* to all UIDs.
|
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
public @Nullable Set<UidRange> getUids() {
|
||||||
@SuppressLint("NullableCollection")
|
return null == mUids ? null : new ArraySet<>(mUids);
|
||||||
public @Nullable Set<Range<Integer>> getUids() {
|
|
||||||
return UidRange.toIntRanges(mUids);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the list of UIDs this network applies to.
|
|
||||||
* This returns a copy of the set so that callers can't modify the original object.
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public @Nullable Set<UidRange> getUidRanges() {
|
|
||||||
if (mUids == null) return null;
|
|
||||||
|
|
||||||
return new ArraySet<>(mUids);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2667,21 +2654,6 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the list of UIDs this network applies to.
|
|
||||||
*
|
|
||||||
* @param uids the list of UIDs this network applies to, or {@code null} if this network
|
|
||||||
* applies to all UIDs.
|
|
||||||
* @return this builder
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
|
||||||
public Builder setUids(@Nullable Set<Range<Integer>> uids) {
|
|
||||||
mCaps.setUids(uids);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the instance of the capabilities.
|
* Builds the instance of the capabilities.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ import static android.net.NetworkCapabilities.TRANSPORT_TEST;
|
|||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.annotation.RequiresPermission;
|
import android.annotation.RequiresPermission;
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.annotation.SystemApi;
|
import android.annotation.SystemApi;
|
||||||
import android.compat.annotation.UnsupportedAppUsage;
|
import android.compat.annotation.UnsupportedAppUsage;
|
||||||
import android.net.NetworkCapabilities.NetCapability;
|
import android.net.NetworkCapabilities.NetCapability;
|
||||||
@@ -46,7 +45,6 @@ import android.os.Parcel;
|
|||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Range;
|
|
||||||
import android.util.proto.ProtoOutputStream;
|
import android.util.proto.ProtoOutputStream;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -279,14 +277,11 @@ public class NetworkRequest implements Parcelable {
|
|||||||
* Set the watched UIDs for this request. This will be reset and wiped out unless
|
* Set the watched UIDs for this request. This will be reset and wiped out unless
|
||||||
* the calling app holds the CHANGE_NETWORK_STATE permission.
|
* the calling app holds the CHANGE_NETWORK_STATE permission.
|
||||||
*
|
*
|
||||||
* @param uids The watched UIDs as a set of {@code Range<Integer>}, or null for everything.
|
* @param uids The watched UIDs as a set of UidRanges, or null for everything.
|
||||||
* @return The builder to facilitate chaining.
|
* @return The builder to facilitate chaining.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@NonNull
|
public Builder setUids(Set<UidRange> uids) {
|
||||||
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
|
||||||
@SuppressLint("MissingGetterMatchingBuilder")
|
|
||||||
public Builder setUids(@Nullable Set<Range<Integer>> uids) {
|
|
||||||
mNetworkCapabilities.setUids(uids);
|
mNetworkCapabilities.setUids(uids);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,8 @@ import android.annotation.Nullable;
|
|||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.util.ArraySet;
|
|
||||||
import android.util.Range;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An inclusive range of UIDs.
|
* An inclusive range of UIDs.
|
||||||
@@ -152,32 +149,4 @@ public final class UidRange implements Parcelable {
|
|||||||
}
|
}
|
||||||
return false;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user