Merge "Implement support for bypassable VPNs." into lmp-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
eb527ef7a6
@@ -2068,9 +2068,9 @@ public class ConnectivityManager {
|
||||
|
||||
/** {@hide} */
|
||||
public void registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp,
|
||||
NetworkCapabilities nc, int score) {
|
||||
NetworkCapabilities nc, int score, NetworkMisc misc) {
|
||||
try {
|
||||
mService.registerNetworkAgent(messenger, ni, lp, nc, score);
|
||||
mService.registerNetworkAgent(messenger, ni, lp, nc, score, misc);
|
||||
} catch (RemoteException e) { }
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.net.LinkProperties;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.NetworkMisc;
|
||||
import android.net.NetworkQuotaInfo;
|
||||
import android.net.NetworkRequest;
|
||||
import android.net.NetworkState;
|
||||
@@ -150,7 +151,7 @@ interface IConnectivityManager
|
||||
void unregisterNetworkFactory(in Messenger messenger);
|
||||
|
||||
void registerNetworkAgent(in Messenger messenger, in NetworkInfo ni, in LinkProperties lp,
|
||||
in NetworkCapabilities nc, int score);
|
||||
in NetworkCapabilities nc, int score, in NetworkMisc misc);
|
||||
|
||||
NetworkRequest requestNetwork(in NetworkCapabilities networkCapabilities,
|
||||
in Messenger messenger, int timeoutSec, in IBinder binder, int legacy);
|
||||
|
||||
@@ -108,6 +108,11 @@ public abstract class NetworkAgent extends Handler {
|
||||
|
||||
public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
|
||||
NetworkCapabilities nc, LinkProperties lp, int score) {
|
||||
this(looper, context, logTag, ni, nc, lp, score, null);
|
||||
}
|
||||
|
||||
public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
|
||||
NetworkCapabilities nc, LinkProperties lp, int score, NetworkMisc misc) {
|
||||
super(looper);
|
||||
LOG_TAG = logTag;
|
||||
mContext = context;
|
||||
@@ -119,7 +124,7 @@ public abstract class NetworkAgent extends Handler {
|
||||
ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService(
|
||||
Context.CONNECTIVITY_SERVICE);
|
||||
cm.registerNetworkAgent(new Messenger(this), new NetworkInfo(ni),
|
||||
new LinkProperties(lp), new NetworkCapabilities(nc), score);
|
||||
new LinkProperties(lp), new NetworkCapabilities(nc), score, misc);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
19
core/java/android/net/NetworkMisc.aidl
Normal file
19
core/java/android/net/NetworkMisc.aidl
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.net;
|
||||
|
||||
parcelable NetworkMisc;
|
||||
57
core/java/android/net/NetworkMisc.java
Normal file
57
core/java/android/net/NetworkMisc.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.net;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
/**
|
||||
* A grab-bag of information (metadata, policies, properties, etc) about a {@link Network}.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public class NetworkMisc implements Parcelable {
|
||||
/**
|
||||
* If the {@link Network} is a VPN, whether apps are allowed to bypass the VPN. This is set by
|
||||
* a {@link VpnService} and used by {@link ConnectivityService} when creating a VPN.
|
||||
*/
|
||||
public boolean allowBypass;
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeInt(allowBypass ? 1 : 0);
|
||||
}
|
||||
|
||||
public static final Creator<NetworkMisc> CREATOR = new Creator<NetworkMisc>() {
|
||||
@Override
|
||||
public NetworkMisc createFromParcel(Parcel in) {
|
||||
NetworkMisc networkMisc = new NetworkMisc();
|
||||
networkMisc.allowBypass = in.readInt() != 0;
|
||||
return networkMisc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkMisc[] newArray(int size) {
|
||||
return new NetworkMisc[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -563,7 +563,7 @@ public class VpnService extends Service {
|
||||
* @return this {@link Builder} object to facilitate chaining of method calls.
|
||||
*/
|
||||
public Builder allowBypass() {
|
||||
// TODO
|
||||
mConfig.allowBypass = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -367,7 +367,7 @@ interface INetworkManagementService
|
||||
/**
|
||||
* Setup a new VPN.
|
||||
*/
|
||||
void createVirtualNetwork(int netId, boolean hasDNS);
|
||||
void createVirtualNetwork(int netId, boolean hasDNS, boolean secure);
|
||||
|
||||
/**
|
||||
* Remove a network.
|
||||
|
||||
@@ -74,6 +74,7 @@ public class VpnConfig implements Parcelable {
|
||||
public long startTime = -1;
|
||||
public boolean legacy;
|
||||
public boolean blocking;
|
||||
public boolean allowBypass;
|
||||
|
||||
public void addLegacyRoutes(String routesStr) {
|
||||
if (routesStr.trim().equals("")) {
|
||||
@@ -122,6 +123,7 @@ public class VpnConfig implements Parcelable {
|
||||
out.writeLong(startTime);
|
||||
out.writeInt(legacy ? 1 : 0);
|
||||
out.writeInt(blocking ? 1 : 0);
|
||||
out.writeInt(allowBypass ? 1 : 0);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<VpnConfig> CREATOR =
|
||||
@@ -141,6 +143,7 @@ public class VpnConfig implements Parcelable {
|
||||
config.startTime = in.readLong();
|
||||
config.legacy = in.readInt() != 0;
|
||||
config.blocking = in.readInt() != 0;
|
||||
config.allowBypass = in.readInt() != 0;
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,7 @@ import android.net.NetworkConfig;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.NetworkInfo.DetailedState;
|
||||
import android.net.NetworkFactory;
|
||||
import android.net.NetworkMisc;
|
||||
import android.net.NetworkQuotaInfo;
|
||||
import android.net.NetworkRequest;
|
||||
import android.net.NetworkState;
|
||||
@@ -5259,12 +5260,13 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
||||
|
||||
public void registerNetworkAgent(Messenger messenger, NetworkInfo networkInfo,
|
||||
LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
|
||||
int currentScore) {
|
||||
int currentScore, NetworkMisc networkMisc) {
|
||||
enforceConnectivityInternalPermission();
|
||||
|
||||
NetworkAgentInfo nai = new NetworkAgentInfo(messenger, new AsyncChannel(), nextNetId(),
|
||||
new NetworkInfo(networkInfo), new LinkProperties(linkProperties),
|
||||
new NetworkCapabilities(networkCapabilities), currentScore, mContext, mTrackerHandler);
|
||||
new NetworkCapabilities(networkCapabilities), currentScore, mContext, mTrackerHandler,
|
||||
networkMisc);
|
||||
if (VDBG) log("registerNetworkAgent " + nai);
|
||||
mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_AGENT, nai));
|
||||
}
|
||||
@@ -5665,7 +5667,9 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
||||
// to tell us whether we've already created this network or not.
|
||||
if (networkAgent.isVPN()) {
|
||||
mNetd.createVirtualNetwork(networkAgent.network.netId,
|
||||
!networkAgent.linkProperties.getDnsServers().isEmpty());
|
||||
!networkAgent.linkProperties.getDnsServers().isEmpty(),
|
||||
(networkAgent.networkMisc == null ||
|
||||
!networkAgent.networkMisc.allowBypass));
|
||||
} else {
|
||||
mNetd.createPhysicalNetwork(networkAgent.network.netId);
|
||||
}
|
||||
|
||||
@@ -1947,11 +1947,12 @@ public class NetworkManagementService extends INetworkManagementService.Stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createVirtualNetwork(int netId, boolean hasDNS) {
|
||||
public void createVirtualNetwork(int netId, boolean hasDNS, boolean secure) {
|
||||
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
|
||||
|
||||
try {
|
||||
mConnector.execute("network", "create", netId, "vpn", hasDNS ? "1" : "0");
|
||||
mConnector.execute("network", "create", netId, "vpn", hasDNS ? "1" : "0",
|
||||
secure ? "1" : "0");
|
||||
} catch (NativeDaemonConnectorException e) {
|
||||
throw e.rethrowAsParcelableException();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.net.LinkProperties;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.NetworkMisc;
|
||||
import android.net.NetworkRequest;
|
||||
import android.os.Handler;
|
||||
import android.os.Messenger;
|
||||
@@ -44,6 +45,7 @@ public class NetworkAgentInfo {
|
||||
public NetworkCapabilities networkCapabilities;
|
||||
public int currentScore;
|
||||
public final NetworkMonitor networkMonitor;
|
||||
public final NetworkMisc networkMisc;
|
||||
|
||||
// The list of NetworkRequests being satisfied by this Network.
|
||||
public final SparseArray<NetworkRequest> networkRequests = new SparseArray<NetworkRequest>();
|
||||
@@ -53,8 +55,8 @@ public class NetworkAgentInfo {
|
||||
public final AsyncChannel asyncChannel;
|
||||
|
||||
public NetworkAgentInfo(Messenger messenger, AsyncChannel ac, int netId, NetworkInfo info,
|
||||
LinkProperties lp, NetworkCapabilities nc, int score, Context context,
|
||||
Handler handler) {
|
||||
LinkProperties lp, NetworkCapabilities nc, int score, Context context, Handler handler,
|
||||
NetworkMisc misc) {
|
||||
this.messenger = messenger;
|
||||
asyncChannel = ac;
|
||||
network = new Network(netId);
|
||||
@@ -63,6 +65,7 @@ public class NetworkAgentInfo {
|
||||
networkCapabilities = nc;
|
||||
currentScore = score;
|
||||
networkMonitor = new NetworkMonitor(context, handler, this);
|
||||
networkMisc = misc;
|
||||
}
|
||||
|
||||
public void addRequest(NetworkRequest networkRequest) {
|
||||
|
||||
@@ -48,6 +48,7 @@ import android.net.NetworkAgent;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.NetworkInfo.DetailedState;
|
||||
import android.net.NetworkMisc;
|
||||
import android.net.NetworkUtils;
|
||||
import android.net.RouteInfo;
|
||||
import android.net.UidRange;
|
||||
@@ -331,10 +332,14 @@ public class Vpn {
|
||||
lp.setDomains(buffer.toString().trim());
|
||||
mNetworkInfo.setIsAvailable(true);
|
||||
mNetworkInfo.setDetailedState(DetailedState.CONNECTED, null, null);
|
||||
NetworkMisc networkMisc = new NetworkMisc();
|
||||
if (mConfig.allowBypass) {
|
||||
networkMisc.allowBypass = true;
|
||||
}
|
||||
long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
mNetworkAgent = new NetworkAgent(mLooper, mContext, NETWORKTYPE,
|
||||
mNetworkInfo, mNetworkCapabilities, lp, 0) {
|
||||
mNetworkInfo, mNetworkCapabilities, lp, 0, networkMisc) {
|
||||
public void unwanted() {
|
||||
// We are user controlled, not driven by NetworkRequest.
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user