am ac0bc4ad: Merge "Make getNetworkInfo() take into account VPN underlying networks." into lmp-mr1-dev automerge: c38b90b automerge: 00c8450
* commit 'ac0bc4ad5f53a659928666fc9accec7bddf173e8': Make getNetworkInfo() take into account VPN underlying networks.
This commit is contained in:
@@ -832,6 +832,19 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private Network[] getVpnUnderlyingNetworks(int uid) {
|
||||||
|
if (!mLockdownEnabled) {
|
||||||
|
int user = UserHandle.getUserId(uid);
|
||||||
|
synchronized (mVpns) {
|
||||||
|
Vpn vpn = mVpns.get(user);
|
||||||
|
if (vpn != null && vpn.appliesToUid(uid)) {
|
||||||
|
return vpn.getUnderlyingNetworks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private NetworkState getUnfilteredActiveNetworkState(int uid) {
|
private NetworkState getUnfilteredActiveNetworkState(int uid) {
|
||||||
NetworkInfo info = null;
|
NetworkInfo info = null;
|
||||||
LinkProperties lp = null;
|
LinkProperties lp = null;
|
||||||
@@ -841,25 +854,17 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
NetworkAgentInfo nai = mNetworkForRequestId.get(mDefaultRequest.requestId);
|
NetworkAgentInfo nai = mNetworkForRequestId.get(mDefaultRequest.requestId);
|
||||||
|
|
||||||
if (!mLockdownEnabled) {
|
final Network[] networks = getVpnUnderlyingNetworks(uid);
|
||||||
int user = UserHandle.getUserId(uid);
|
if (networks != null) {
|
||||||
synchronized (mVpns) {
|
// getUnderlyingNetworks() returns:
|
||||||
Vpn vpn = mVpns.get(user);
|
// null => there was no VPN, or the VPN didn't specify anything, so we use the default.
|
||||||
if (vpn != null && vpn.appliesToUid(uid)) {
|
// empty array => the VPN explicitly said "no default network".
|
||||||
// getUnderlyingNetworks() returns:
|
// non-empty array => the VPN specified one or more default networks; we use the
|
||||||
// null => the VPN didn't specify anything, so we use the default.
|
// first one.
|
||||||
// empty array => the VPN explicitly said "no default network".
|
if (networks.length > 0) {
|
||||||
// non-empty array => the VPN specified one or more default networks; we use the
|
nai = getNetworkAgentInfoForNetwork(networks[0]);
|
||||||
// first one.
|
} else {
|
||||||
Network[] networks = vpn.getUnderlyingNetworks();
|
nai = null;
|
||||||
if (networks != null) {
|
|
||||||
if (networks.length > 0) {
|
|
||||||
nai = getNetworkAgentInfoForNetwork(networks[0]);
|
|
||||||
} else {
|
|
||||||
nai = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -990,6 +995,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
public NetworkInfo getNetworkInfo(int networkType) {
|
public NetworkInfo getNetworkInfo(int networkType) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
final int uid = Binder.getCallingUid();
|
final int uid = Binder.getCallingUid();
|
||||||
|
if (getVpnUnderlyingNetworks(uid) != null) {
|
||||||
|
// A VPN is active, so we may need to return one of its underlying networks. This
|
||||||
|
// information is not available in LegacyTypeTracker, so we have to get it from
|
||||||
|
// getUnfilteredActiveNetworkState.
|
||||||
|
NetworkState state = getUnfilteredActiveNetworkState(uid);
|
||||||
|
if (state.networkInfo != null && state.networkInfo.getType() == networkType) {
|
||||||
|
return getFilteredNetworkInfo(state.networkInfo, state.linkProperties, uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
NetworkState state = getFilteredNetworkState(networkType, uid);
|
NetworkState state = getFilteredNetworkState(networkType, uid);
|
||||||
return state.networkInfo;
|
return state.networkInfo;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user