Loading core/java/android/net/NetworkRequest.java +68 −5 Original line number Diff line number Diff line Loading @@ -46,16 +46,56 @@ public class NetworkRequest implements Parcelable { */ public final int legacyType; /** * A NetworkRequest as used by the system can be one of three types: * * - LISTEN, for which the framework will issue callbacks about any * and all networks that match the specified NetworkCapabilities, * * - REQUEST, capable of causing a specific network to be created * first (e.g. a telephony DUN request), the framework will issue * callbacks about the single, highest scoring current network * (if any) that matches the specified NetworkCapabilities, or * * - TRACK_DEFAULT, a hybrid of the two designed such that the * framework will issue callbacks for the single, highest scoring * current network (if any) that matches the capabilities of the * default Internet request (mDefaultRequest), but which cannot cause * the framework to either create or retain the existence of any * specific network. * * - The value NONE is used only by applications. When an application * creates a NetworkRequest, it does not have a type; the type is set * by the system depending on the method used to file the request * (requestNetwork, registerNetworkCallback, etc.). * * @hide */ public static enum Type { NONE, LISTEN, TRACK_DEFAULT, REQUEST }; /** * The type of the request. This is only used by the system and is always NONE elsewhere. * * @hide */ public final Type type; /** * @hide */ public NetworkRequest(NetworkCapabilities nc, int legacyType, int rId) { public NetworkRequest(NetworkCapabilities nc, int legacyType, int rId, Type type) { if (nc == null) { throw new NullPointerException(); } requestId = rId; networkCapabilities = nc; this.legacyType = legacyType; this.type = type; } /** Loading @@ -65,6 +105,7 @@ public class NetworkRequest implements Parcelable { networkCapabilities = new NetworkCapabilities(that.networkCapabilities); requestId = that.requestId; this.legacyType = that.legacyType; this.type = that.type; } /** Loading @@ -90,7 +131,7 @@ public class NetworkRequest implements Parcelable { final NetworkCapabilities nc = new NetworkCapabilities(mNetworkCapabilities); nc.maybeMarkCapabilitiesRestricted(); return new NetworkRequest(nc, ConnectivityManager.TYPE_NONE, ConnectivityManager.REQUEST_ID_UNSET); ConnectivityManager.REQUEST_ID_UNSET, Type.NONE); } /** Loading Loading @@ -223,6 +264,7 @@ public class NetworkRequest implements Parcelable { dest.writeParcelable(networkCapabilities, flags); dest.writeInt(legacyType); dest.writeInt(requestId); // type intentionally not preserved across process boundaries. } public static final Creator<NetworkRequest> CREATOR = new Creator<NetworkRequest>() { Loading @@ -230,7 +272,8 @@ public class NetworkRequest implements Parcelable { NetworkCapabilities nc = (NetworkCapabilities)in.readParcelable(null); int legacyType = in.readInt(); int requestId = in.readInt(); NetworkRequest result = new NetworkRequest(nc, legacyType, requestId); // type intentionally not preserved across process boundaries. NetworkRequest result = new NetworkRequest(nc, legacyType, requestId, Type.NONE); return result; } public NetworkRequest[] newArray(int size) { Loading @@ -238,8 +281,27 @@ public class NetworkRequest implements Parcelable { } }; /** * Returns true iff. the contained NetworkRequest is one that: * * - should be associated with at most one satisfying network * at a time; * * - should cause a network to be kept up if it is the best network * which can satisfy the NetworkRequest. * * For full detail of how isRequest() is used for pairing Networks with * NetworkRequests read rematchNetworkAndRequests(). * * @hide */ public boolean isRequest() { return type == Type.TRACK_DEFAULT || type == Type.REQUEST; } public String toString() { return "NetworkRequest [ id=" + requestId + ", legacyType=" + legacyType + return "NetworkRequest [ " + type + " id=" + requestId + (legacyType != ConnectivityManager.TYPE_NONE ? ", legacyType=" + legacyType : "") + ", " + networkCapabilities.toString() + " ]"; } Loading @@ -248,6 +310,7 @@ public class NetworkRequest implements Parcelable { NetworkRequest that = (NetworkRequest)obj; return (that.legacyType == this.legacyType && that.requestId == this.requestId && that.type == this.type && ((that.networkCapabilities == null && this.networkCapabilities == null) || (that.networkCapabilities != null && that.networkCapabilities.equals(this.networkCapabilities)))); Loading @@ -255,6 +318,6 @@ public class NetworkRequest implements Parcelable { public int hashCode() { return requestId + (legacyType * 1013) + (networkCapabilities.hashCode() * 1051); (networkCapabilities.hashCode() * 1051) + type.hashCode() * 17; } } services/core/java/com/android/server/ConnectivityService.java +72 −127 File changed.Preview size limit exceeded, changes collapsed. Show changes services/core/java/com/android/server/connectivity/NetworkAgentInfo.java +51 −4 Original line number Diff line number Diff line Loading @@ -162,11 +162,13 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> { private static final int MAXIMUM_NETWORK_SCORE = 100; // The list of NetworkRequests being satisfied by this Network. public final SparseArray<NetworkRequest> networkRequests = new SparseArray<NetworkRequest>(); private final SparseArray<NetworkRequest> mNetworkRequests = new SparseArray<>(); // The list of NetworkRequests that this Network previously satisfied with the highest // score. A non-empty list indicates that if this Network was validated it is lingered. // NOTE: This list is only used for debugging. public final ArrayList<NetworkRequest> networkLingered = new ArrayList<NetworkRequest>(); // How many of the satisfied requests are actual requests and not listens. private int mNumRequestNetworkRequests = 0; public final Messenger messenger; public final AsyncChannel asyncChannel; Loading @@ -188,18 +190,63 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> { networkMisc = misc; } // Functions for manipulating the requests satisfied by this network. // // These functions must only called on ConnectivityService's main thread. /** * Add {@code networkRequest} to this network as it's satisfied by this network. * NOTE: This function must only be called on ConnectivityService's main thread. * @return true if {@code networkRequest} was added or false if {@code networkRequest} was * already present. */ public boolean addRequest(NetworkRequest networkRequest) { if (networkRequests.get(networkRequest.requestId) == networkRequest) return false; networkRequests.put(networkRequest.requestId, networkRequest); NetworkRequest existing = mNetworkRequests.get(networkRequest.requestId); if (existing == networkRequest) return false; if (existing != null && existing.isRequest()) mNumRequestNetworkRequests--; mNetworkRequests.put(networkRequest.requestId, networkRequest); if (networkRequest.isRequest()) mNumRequestNetworkRequests++; return true; } /** * Remove the specified request from this network. */ public void removeRequest(int requestId) { NetworkRequest existing = mNetworkRequests.get(requestId); if (existing != null && existing.isRequest()) mNumRequestNetworkRequests--; mNetworkRequests.remove(requestId); } /** * Returns whether this network is currently satisfying the request with the specified ID. */ public boolean isSatisfyingRequest(int id) { return mNetworkRequests.get(id) != null; } /** * Returns the request at the specified position in the list of requests satisfied by this * network. */ public NetworkRequest requestAt(int index) { return mNetworkRequests.valueAt(index); } /** * Returns the number of requests currently satisfied by this network for which * {@link android.net.NetworkRequest#isRequest} returns {@code true}. */ public int numRequestNetworkRequests() { return mNumRequestNetworkRequests; } /** * Returns the number of requests of any type currently satisfied by this network. */ public int numNetworkRequests() { return mNetworkRequests.size(); } // Does this network satisfy request? public boolean satisfies(NetworkRequest request) { return created && Loading Loading
core/java/android/net/NetworkRequest.java +68 −5 Original line number Diff line number Diff line Loading @@ -46,16 +46,56 @@ public class NetworkRequest implements Parcelable { */ public final int legacyType; /** * A NetworkRequest as used by the system can be one of three types: * * - LISTEN, for which the framework will issue callbacks about any * and all networks that match the specified NetworkCapabilities, * * - REQUEST, capable of causing a specific network to be created * first (e.g. a telephony DUN request), the framework will issue * callbacks about the single, highest scoring current network * (if any) that matches the specified NetworkCapabilities, or * * - TRACK_DEFAULT, a hybrid of the two designed such that the * framework will issue callbacks for the single, highest scoring * current network (if any) that matches the capabilities of the * default Internet request (mDefaultRequest), but which cannot cause * the framework to either create or retain the existence of any * specific network. * * - The value NONE is used only by applications. When an application * creates a NetworkRequest, it does not have a type; the type is set * by the system depending on the method used to file the request * (requestNetwork, registerNetworkCallback, etc.). * * @hide */ public static enum Type { NONE, LISTEN, TRACK_DEFAULT, REQUEST }; /** * The type of the request. This is only used by the system and is always NONE elsewhere. * * @hide */ public final Type type; /** * @hide */ public NetworkRequest(NetworkCapabilities nc, int legacyType, int rId) { public NetworkRequest(NetworkCapabilities nc, int legacyType, int rId, Type type) { if (nc == null) { throw new NullPointerException(); } requestId = rId; networkCapabilities = nc; this.legacyType = legacyType; this.type = type; } /** Loading @@ -65,6 +105,7 @@ public class NetworkRequest implements Parcelable { networkCapabilities = new NetworkCapabilities(that.networkCapabilities); requestId = that.requestId; this.legacyType = that.legacyType; this.type = that.type; } /** Loading @@ -90,7 +131,7 @@ public class NetworkRequest implements Parcelable { final NetworkCapabilities nc = new NetworkCapabilities(mNetworkCapabilities); nc.maybeMarkCapabilitiesRestricted(); return new NetworkRequest(nc, ConnectivityManager.TYPE_NONE, ConnectivityManager.REQUEST_ID_UNSET); ConnectivityManager.REQUEST_ID_UNSET, Type.NONE); } /** Loading Loading @@ -223,6 +264,7 @@ public class NetworkRequest implements Parcelable { dest.writeParcelable(networkCapabilities, flags); dest.writeInt(legacyType); dest.writeInt(requestId); // type intentionally not preserved across process boundaries. } public static final Creator<NetworkRequest> CREATOR = new Creator<NetworkRequest>() { Loading @@ -230,7 +272,8 @@ public class NetworkRequest implements Parcelable { NetworkCapabilities nc = (NetworkCapabilities)in.readParcelable(null); int legacyType = in.readInt(); int requestId = in.readInt(); NetworkRequest result = new NetworkRequest(nc, legacyType, requestId); // type intentionally not preserved across process boundaries. NetworkRequest result = new NetworkRequest(nc, legacyType, requestId, Type.NONE); return result; } public NetworkRequest[] newArray(int size) { Loading @@ -238,8 +281,27 @@ public class NetworkRequest implements Parcelable { } }; /** * Returns true iff. the contained NetworkRequest is one that: * * - should be associated with at most one satisfying network * at a time; * * - should cause a network to be kept up if it is the best network * which can satisfy the NetworkRequest. * * For full detail of how isRequest() is used for pairing Networks with * NetworkRequests read rematchNetworkAndRequests(). * * @hide */ public boolean isRequest() { return type == Type.TRACK_DEFAULT || type == Type.REQUEST; } public String toString() { return "NetworkRequest [ id=" + requestId + ", legacyType=" + legacyType + return "NetworkRequest [ " + type + " id=" + requestId + (legacyType != ConnectivityManager.TYPE_NONE ? ", legacyType=" + legacyType : "") + ", " + networkCapabilities.toString() + " ]"; } Loading @@ -248,6 +310,7 @@ public class NetworkRequest implements Parcelable { NetworkRequest that = (NetworkRequest)obj; return (that.legacyType == this.legacyType && that.requestId == this.requestId && that.type == this.type && ((that.networkCapabilities == null && this.networkCapabilities == null) || (that.networkCapabilities != null && that.networkCapabilities.equals(this.networkCapabilities)))); Loading @@ -255,6 +318,6 @@ public class NetworkRequest implements Parcelable { public int hashCode() { return requestId + (legacyType * 1013) + (networkCapabilities.hashCode() * 1051); (networkCapabilities.hashCode() * 1051) + type.hashCode() * 17; } }
services/core/java/com/android/server/ConnectivityService.java +72 −127 File changed.Preview size limit exceeded, changes collapsed. Show changes
services/core/java/com/android/server/connectivity/NetworkAgentInfo.java +51 −4 Original line number Diff line number Diff line Loading @@ -162,11 +162,13 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> { private static final int MAXIMUM_NETWORK_SCORE = 100; // The list of NetworkRequests being satisfied by this Network. public final SparseArray<NetworkRequest> networkRequests = new SparseArray<NetworkRequest>(); private final SparseArray<NetworkRequest> mNetworkRequests = new SparseArray<>(); // The list of NetworkRequests that this Network previously satisfied with the highest // score. A non-empty list indicates that if this Network was validated it is lingered. // NOTE: This list is only used for debugging. public final ArrayList<NetworkRequest> networkLingered = new ArrayList<NetworkRequest>(); // How many of the satisfied requests are actual requests and not listens. private int mNumRequestNetworkRequests = 0; public final Messenger messenger; public final AsyncChannel asyncChannel; Loading @@ -188,18 +190,63 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> { networkMisc = misc; } // Functions for manipulating the requests satisfied by this network. // // These functions must only called on ConnectivityService's main thread. /** * Add {@code networkRequest} to this network as it's satisfied by this network. * NOTE: This function must only be called on ConnectivityService's main thread. * @return true if {@code networkRequest} was added or false if {@code networkRequest} was * already present. */ public boolean addRequest(NetworkRequest networkRequest) { if (networkRequests.get(networkRequest.requestId) == networkRequest) return false; networkRequests.put(networkRequest.requestId, networkRequest); NetworkRequest existing = mNetworkRequests.get(networkRequest.requestId); if (existing == networkRequest) return false; if (existing != null && existing.isRequest()) mNumRequestNetworkRequests--; mNetworkRequests.put(networkRequest.requestId, networkRequest); if (networkRequest.isRequest()) mNumRequestNetworkRequests++; return true; } /** * Remove the specified request from this network. */ public void removeRequest(int requestId) { NetworkRequest existing = mNetworkRequests.get(requestId); if (existing != null && existing.isRequest()) mNumRequestNetworkRequests--; mNetworkRequests.remove(requestId); } /** * Returns whether this network is currently satisfying the request with the specified ID. */ public boolean isSatisfyingRequest(int id) { return mNetworkRequests.get(id) != null; } /** * Returns the request at the specified position in the list of requests satisfied by this * network. */ public NetworkRequest requestAt(int index) { return mNetworkRequests.valueAt(index); } /** * Returns the number of requests currently satisfied by this network for which * {@link android.net.NetworkRequest#isRequest} returns {@code true}. */ public int numRequestNetworkRequests() { return mNumRequestNetworkRequests; } /** * Returns the number of requests of any type currently satisfied by this network. */ public int numNetworkRequests() { return mNetworkRequests.size(); } // Does this network satisfy request? public boolean satisfies(NetworkRequest request) { return created && Loading