summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorChalard Jean <jchalard@google.com>2018-03-02 13:25:02 +0000
committerandroid-build-merger <android-build-merger@google.com>2018-03-02 13:25:02 +0000
commitd1bf7733afd26c97321ab43384badb3eb9924283 (patch)
tree98e287cd8652b418568670f86fbadfaaf89ad48b /core/java
parent9fae0a82af2be32a6d29001457f686f27e551c4e (diff)
parent1be320a494cd292235d16ce4d155bfb858eaadf0 (diff)
Merge "Give apps with NETWORK_SETTINGS right to see any VPN." am: 6001f72478 am: e5e819f078
am: 1be320a494 Change-Id: I9a9d0eb212f6de105abc070a1eb5ff698b4e67bc
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/net/NetworkCapabilities.java14
-rw-r--r--core/java/android/net/NetworkRequest.java11
2 files changed, 20 insertions, 5 deletions
diff --git a/core/java/android/net/NetworkCapabilities.java b/core/java/android/net/NetworkCapabilities.java
index 74b52c9edbf8..17b46c68ebe1 100644
--- a/core/java/android/net/NetworkCapabilities.java
+++ b/core/java/android/net/NetworkCapabilities.java
@@ -891,7 +891,16 @@ public final class NetworkCapabilities implements Parcelable {
/**
* List of UIDs this network applies to. No restriction if null.
* <p>
- * This is typically (and at this time, only) used by VPN. This network is only available to
+ * For networks, mUids represent the list of network this applies to, and null means this
+ * network applies to all UIDs.
+ * For requests, mUids is the list of UIDs this network MUST apply to to match ; ALL UIDs
+ * must be included in a network so that they match. As an exception to the general rule,
+ * a null mUids field for requests mean "no requirements" rather than what the general rule
+ * would suggest ("must apply to all UIDs") : this is because this has shown to be what users
+ * of this API expect in practice. A network that must match all UIDs can still be
+ * expressed with a set ranging the entire set of possible UIDs.
+ * <p>
+ * mUids is typically (and at this time, only) used by VPN. This network is only available to
* the UIDs in this list, and it is their default network. Apps in this list that wish to
* bypass the VPN can do so iff the VPN app allows them to or if they are privileged. If this
* member is null, then the network is not restricted by app UID. If it's an empty list, then
@@ -1013,8 +1022,7 @@ public final class NetworkCapabilities implements Parcelable {
* @hide
*/
public boolean satisfiedByUids(NetworkCapabilities nc) {
- if (null == nc.mUids) return true; // The network satisfies everything.
- if (null == mUids) return false; // Not everything allowed but requires everything
+ if (null == nc.mUids || null == mUids) return true; // The network satisfies everything.
for (UidRange requiredRange : mUids) {
if (requiredRange.contains(nc.mEstablishingVpnAppUid)) return true;
if (!nc.appliesToUidRange(requiredRange)) {
diff --git a/core/java/android/net/NetworkRequest.java b/core/java/android/net/NetworkRequest.java
index a0724091abee..61199f906e4a 100644
--- a/core/java/android/net/NetworkRequest.java
+++ b/core/java/android/net/NetworkRequest.java
@@ -19,6 +19,7 @@ package android.net;
import android.annotation.NonNull;
import android.os.Parcel;
import android.os.Parcelable;
+import android.os.Process;
import android.text.TextUtils;
import android.util.proto.ProtoOutputStream;
@@ -132,12 +133,18 @@ public class NetworkRequest implements Parcelable {
* needed in terms of {@link NetworkCapabilities} features
*/
public static class Builder {
- private final NetworkCapabilities mNetworkCapabilities = new NetworkCapabilities();
+ private final NetworkCapabilities mNetworkCapabilities;
/**
* Default constructor for Builder.
*/
- public Builder() {}
+ public Builder() {
+ // By default, restrict this request to networks available to this app.
+ // Apps can rescind this restriction, but ConnectivityService will enforce
+ // it for apps that do not have the NETWORK_SETTINGS permission.
+ mNetworkCapabilities = new NetworkCapabilities();
+ mNetworkCapabilities.setSingleUid(Process.myUid());
+ }
/**
* Build {@link NetworkRequest} give the current set of capabilities.