Allow VPNs to specify their underlying networks.

These are used when responding to getActiveNetworkInfo() (and cousins)
when an app is subject to the VPN.

Bug: 17460017
Change-Id: Ief7a840c760777a41d3358aa6b8e4cdd99c29f24
This commit is contained in:
Sreeram Ramachandran
2014-11-11 16:09:21 -08:00
parent 7c9871648e
commit d2b4fe2b2d
2 changed files with 33 additions and 0 deletions

View File

@@ -170,4 +170,5 @@ interface IConnectivityManager
boolean addVpnAddress(String address, int prefixLength); boolean addVpnAddress(String address, int prefixLength);
boolean removeVpnAddress(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; Network network = null;
NetworkAgentInfo nai = mNetworkForRequestId.get(mDefaultRequest.requestId); 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) { if (nai != null) {
synchronized (nai) { synchronized (nai) {
info = new NetworkInfo(nai.networkInfo); info = new NetworkInfo(nai.networkInfo);
@@ -4376,4 +4399,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
return mVpns.get(user).removeAddress(address, prefixLength); 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);
}
}
} }