Add javadoc for NetworkRequest. am: 469fa2a36d
Original change: undetermined Change-Id: I1e9c3dc51395f661df4063ea7a8e3fedce856b4f
This commit is contained in:
@@ -22,11 +22,19 @@ import android.os.Parcelable;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Defines a request for a network, made by calling {@link ConnectivityManager.requestNetwork}.
|
||||
*
|
||||
* This token records the {@link NetworkCapabilities} used to make the request and identifies
|
||||
* the request. It should be used to release the request via
|
||||
* {@link ConnectivityManager.releaseNetworkRequest} when the network is no longer desired.
|
||||
* @hide
|
||||
*/
|
||||
public class NetworkRequest implements Parcelable {
|
||||
/**
|
||||
* The NetworkCapabilities that define this request
|
||||
* The {@link NetworkCapabilities} that define this request. This should not be modified.
|
||||
* The networkCapabilities of the request are set when
|
||||
* {@link ConnectivityManager.requestNetwork} is called and the value is presented here
|
||||
* as a convenient reminder of what was requested.
|
||||
*/
|
||||
public final NetworkCapabilities networkCapabilities;
|
||||
|
||||
@@ -34,7 +42,7 @@ public class NetworkRequest implements Parcelable {
|
||||
* Identifies the request. NetworkRequests should only be constructed by
|
||||
* the Framework and given out to applications as tokens to be used to identify
|
||||
* the request.
|
||||
* TODO - make sure this input is checked whenever a NR is passed in a public API
|
||||
* @hide
|
||||
*/
|
||||
public final int requestId;
|
||||
|
||||
@@ -45,31 +53,18 @@ public class NetworkRequest implements Parcelable {
|
||||
*/
|
||||
public final boolean needsBroadcasts;
|
||||
|
||||
private static final AtomicInteger sNextRequestId = new AtomicInteger(1);
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public NetworkRequest(NetworkCapabilities nc) {
|
||||
this(nc, false, sNextRequestId.getAndIncrement());
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public NetworkRequest(NetworkCapabilities nc, boolean needsBroadcasts) {
|
||||
this(nc, needsBroadcasts, sNextRequestId.getAndIncrement());
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
private NetworkRequest(NetworkCapabilities nc, boolean needsBroadcasts, int rId) {
|
||||
public NetworkRequest(NetworkCapabilities nc, boolean needsBroadcasts, int rId) {
|
||||
requestId = rId;
|
||||
networkCapabilities = nc;
|
||||
this.needsBroadcasts = needsBroadcasts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public NetworkRequest(NetworkRequest that) {
|
||||
networkCapabilities = new NetworkCapabilities(that.networkCapabilities);
|
||||
requestId = that.requestId;
|
||||
|
||||
@@ -507,10 +507,14 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
||||
|
||||
TelephonyManager mTelephonyManager;
|
||||
|
||||
// sequence number for Networks
|
||||
private final static int MIN_NET_ID = 10; // some reserved marks
|
||||
private final static int MAX_NET_ID = 65535;
|
||||
private int mNextNetId = MIN_NET_ID;
|
||||
|
||||
// sequence number of NetworkRequests
|
||||
private int mNextNetworkRequestId = 1;
|
||||
|
||||
public ConnectivityService(Context context, INetworkManagementService netd,
|
||||
INetworkStatsService statsService, INetworkPolicyManager policyManager) {
|
||||
// Currently, omitting a NetworkFactory will create one internally
|
||||
@@ -526,7 +530,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
||||
NetworkCapabilities netCap = new NetworkCapabilities();
|
||||
netCap.addNetworkCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
|
||||
netCap.addNetworkCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED);
|
||||
mDefaultRequest = new NetworkRequest(netCap, true);
|
||||
mDefaultRequest = new NetworkRequest(netCap, true, nextNetworkRequestId());
|
||||
NetworkRequestInfo nri = new NetworkRequestInfo(null, mDefaultRequest, new Binder(),
|
||||
NetworkRequestInfo.REQUEST);
|
||||
mNetworkRequests.put(mDefaultRequest, nri);
|
||||
@@ -773,6 +777,10 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
||||
mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
|
||||
}
|
||||
|
||||
private synchronized int nextNetworkRequestId() {
|
||||
return mNextNetworkRequestId++;
|
||||
}
|
||||
|
||||
private synchronized int nextNetId() {
|
||||
int netId = mNextNetId;
|
||||
if (++mNextNetId > MAX_NET_ID) mNextNetId = MIN_NET_ID;
|
||||
@@ -5271,7 +5279,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
||||
throw new IllegalArgumentException("Bad timeout specified");
|
||||
}
|
||||
NetworkRequest networkRequest = new NetworkRequest(new NetworkCapabilities(
|
||||
networkCapabilities));
|
||||
networkCapabilities), false, nextNetworkRequestId());
|
||||
if (DBG) log("requestNetwork for " + networkRequest);
|
||||
NetworkRequestInfo nri = new NetworkRequestInfo(messenger, networkRequest, binder,
|
||||
NetworkRequestInfo.REQUEST);
|
||||
@@ -5297,7 +5305,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
||||
enforceAccessPermission();
|
||||
|
||||
NetworkRequest networkRequest = new NetworkRequest(new NetworkCapabilities(
|
||||
networkCapabilities));
|
||||
networkCapabilities), false, nextNetworkRequestId());
|
||||
if (DBG) log("listenForNetwork for " + networkRequest);
|
||||
NetworkRequestInfo nri = new NetworkRequestInfo(messenger, networkRequest, binder,
|
||||
NetworkRequestInfo.LISTEN);
|
||||
|
||||
Reference in New Issue
Block a user