Merge "Allow VPNs to specify their underlying networks." into lmp-mr1-dev

This commit is contained in:
Sreeram Ramachandran
2014-11-24 17:24:03 +00:00
committed by Android (Google) Code Review
2 changed files with 33 additions and 0 deletions

View File

@@ -170,4 +170,5 @@ interface IConnectivityManager
boolean addVpnAddress(String address, int prefixLength);
boolean removeVpnAddress(String address, int prefixLength);
boolean setUnderlyingNetworksForVpn(in Network[] networks);
}

View File

@@ -865,6 +865,29 @@ public class ConnectivityService extends IConnectivityManager.Stub
Network network = null;
NetworkAgentInfo nai = mNetworkForRequestId.get(mDefaultRequest.requestId);
if (!mLockdownEnabled) {
int user = UserHandle.getUserId(uid);
synchronized (mVpns) {
Vpn vpn = mVpns.get(user);
if (vpn != null && vpn.appliesToUid(uid)) {
// getUnderlyingNetworks() returns:
// null => the VPN didn't specify anything, so we use the default.
// empty array => the VPN explicitly said "no default network".
// non-empty array => the VPN specified one or more default networks; we use the
// first one.
Network[] networks = vpn.getUnderlyingNetworks();
if (networks != null) {
if (networks.length > 0) {
nai = getNetworkAgentInfoForNetwork(networks[0]);
} else {
nai = null;
}
}
}
}
}
if (nai != null) {
synchronized (nai) {
info = new NetworkInfo(nai.networkInfo);
@@ -4376,4 +4399,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
return mVpns.get(user).removeAddress(address, prefixLength);
}
}
@Override
public boolean setUnderlyingNetworksForVpn(Network[] networks) {
throwIfLockdownEnabled();
int user = UserHandle.getUserId(Binder.getCallingUid());
synchronized (mVpns) {
return mVpns.get(user).setUnderlyingNetworks(networks);
}
}
}