Merge "Unbreak unregisterNetworkCallback." into nyc-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
0271c0d4ef
@@ -19,6 +19,8 @@ package android.net;
|
|||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines a request for a network, made through {@link NetworkRequest.Builder} and used
|
* Defines a request for a network, made through {@link NetworkRequest.Builder} and used
|
||||||
* to request a network via {@link ConnectivityManager#requestNetwork} or listen for changes
|
* to request a network via {@link ConnectivityManager#requestNetwork} or listen for changes
|
||||||
@@ -264,7 +266,7 @@ public class NetworkRequest implements Parcelable {
|
|||||||
dest.writeParcelable(networkCapabilities, flags);
|
dest.writeParcelable(networkCapabilities, flags);
|
||||||
dest.writeInt(legacyType);
|
dest.writeInt(legacyType);
|
||||||
dest.writeInt(requestId);
|
dest.writeInt(requestId);
|
||||||
// type intentionally not preserved across process boundaries.
|
dest.writeString(type.name());
|
||||||
}
|
}
|
||||||
public static final Creator<NetworkRequest> CREATOR =
|
public static final Creator<NetworkRequest> CREATOR =
|
||||||
new Creator<NetworkRequest>() {
|
new Creator<NetworkRequest>() {
|
||||||
@@ -272,8 +274,8 @@ public class NetworkRequest implements Parcelable {
|
|||||||
NetworkCapabilities nc = (NetworkCapabilities)in.readParcelable(null);
|
NetworkCapabilities nc = (NetworkCapabilities)in.readParcelable(null);
|
||||||
int legacyType = in.readInt();
|
int legacyType = in.readInt();
|
||||||
int requestId = in.readInt();
|
int requestId = in.readInt();
|
||||||
// type intentionally not preserved across process boundaries.
|
Type type = Type.valueOf(in.readString()); // IllegalArgumentException if invalid.
|
||||||
NetworkRequest result = new NetworkRequest(nc, legacyType, requestId, Type.NONE);
|
NetworkRequest result = new NetworkRequest(nc, legacyType, requestId, type);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public NetworkRequest[] newArray(int size) {
|
public NetworkRequest[] newArray(int size) {
|
||||||
@@ -311,13 +313,10 @@ public class NetworkRequest implements Parcelable {
|
|||||||
return (that.legacyType == this.legacyType &&
|
return (that.legacyType == this.legacyType &&
|
||||||
that.requestId == this.requestId &&
|
that.requestId == this.requestId &&
|
||||||
that.type == this.type &&
|
that.type == this.type &&
|
||||||
((that.networkCapabilities == null && this.networkCapabilities == null) ||
|
Objects.equals(that.networkCapabilities, this.networkCapabilities));
|
||||||
(that.networkCapabilities != null &&
|
|
||||||
that.networkCapabilities.equals(this.networkCapabilities))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return requestId + (legacyType * 1013) +
|
return Objects.hash(requestId, legacyType, networkCapabilities, type);
|
||||||
(networkCapabilities.hashCode() * 1051) + type.hashCode() * 17;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3836,6 +3836,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ensureNetworkRequestHasType(NetworkRequest request) {
|
||||||
|
if (request.type == NetworkRequest.Type.NONE) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"All NetworkRequests in ConnectivityService must have a type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tracks info about the requester.
|
* Tracks info about the requester.
|
||||||
* Also used to notice when the calling process dies so we can self-expire
|
* Also used to notice when the calling process dies so we can self-expire
|
||||||
@@ -3851,7 +3858,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
NetworkRequestInfo(NetworkRequest r, PendingIntent pi) {
|
NetworkRequestInfo(NetworkRequest r, PendingIntent pi) {
|
||||||
request = r;
|
request = r;
|
||||||
ensureRequestHasType();
|
ensureNetworkRequestHasType(request);
|
||||||
mPendingIntent = pi;
|
mPendingIntent = pi;
|
||||||
messenger = null;
|
messenger = null;
|
||||||
mBinder = null;
|
mBinder = null;
|
||||||
@@ -3864,7 +3871,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
super();
|
super();
|
||||||
messenger = m;
|
messenger = m;
|
||||||
request = r;
|
request = r;
|
||||||
ensureRequestHasType();
|
ensureNetworkRequestHasType(request);
|
||||||
mBinder = binder;
|
mBinder = binder;
|
||||||
mPid = getCallingPid();
|
mPid = getCallingPid();
|
||||||
mUid = getCallingUid();
|
mUid = getCallingUid();
|
||||||
@@ -3878,13 +3885,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureRequestHasType() {
|
|
||||||
if (request.type == NetworkRequest.Type.NONE) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"All NetworkRequests in ConnectivityService must have a type");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void enforceRequestCountLimit() {
|
private void enforceRequestCountLimit() {
|
||||||
synchronized (mUidToNetworkRequestCount) {
|
synchronized (mUidToNetworkRequestCount) {
|
||||||
int networkRequests = mUidToNetworkRequestCount.get(mUid, 0) + 1;
|
int networkRequests = mUidToNetworkRequestCount.get(mUid, 0) + 1;
|
||||||
@@ -4138,6 +4138,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void releaseNetworkRequest(NetworkRequest networkRequest) {
|
public void releaseNetworkRequest(NetworkRequest networkRequest) {
|
||||||
|
ensureNetworkRequestHasType(networkRequest);
|
||||||
mHandler.sendMessage(mHandler.obtainMessage(EVENT_RELEASE_NETWORK_REQUEST, getCallingUid(),
|
mHandler.sendMessage(mHandler.obtainMessage(EVENT_RELEASE_NETWORK_REQUEST, getCallingUid(),
|
||||||
0, networkRequest));
|
0, networkRequest));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user