Revert "Revert "Expose uids related APIs in NetworkRequest and N..."

Revert^2 "Add shims for NetworkRequest"

b72b3ca768fc25ef72dc78f1396b08447b8ef5c6

NetworkRequest is moving into the incoming connectivity mainline
module. The hidden setUids becomes inaccessible outside the
module. Shims for support cts in different API levels will need
to use it to verify the behavior of NetworkRequest. Thus, expose
it to the API surface.

Also, VPN uses getUids and setUids to control network
capabilities. Networkcapabilities is a part of incoming
connectivity mainline module but VPN is not. Thus, exposing these
two methods are needed to allow VPN to continue using it.

Test: make update-api
Bug: 172183305

Change-Id: I4b8e1aa558e3459a932535f9901f4ae86b0ecb67
Merged-In: I107c329d4d7130d488772166eae8b5e7aaa2ff04
This commit is contained in:
Chiachang Wang
2021-03-19 00:45:39 +00:00
parent 16cbb7423a
commit 8d81c8d76b
3 changed files with 34 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.net.ConnectivityManager.NetworkCallback;
@@ -1477,8 +1478,13 @@ public final class NetworkCapabilities implements Parcelable {
/**
* 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.
*
* @return the list of UIDs this network applies to. If {@code null}, then the network applies
* to all UIDs.
* @hide
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
@SuppressLint("NullableCollection")
public @Nullable Set<Range<Integer>> getUids() {
return UidRange.toIntRanges(mUids);
}
@@ -2661,6 +2667,21 @@ public final class NetworkCapabilities implements Parcelable {
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.
*

View File

@@ -36,6 +36,7 @@ import static android.net.NetworkCapabilities.TRANSPORT_TEST;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.net.NetworkCapabilities.NetCapability;
@@ -282,6 +283,9 @@ public class NetworkRequest implements Parcelable {
* @return The builder to facilitate chaining.
* @hide
*/
@NonNull
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
@SuppressLint("MissingGetterMatchingBuilder")
public Builder setUids(@Nullable Set<Range<Integer>> uids) {
mNetworkCapabilities.setUids(uids);
return this;