Merge "Remove the usage of NETID_UNSET from Vpn.java" into sc-dev

This commit is contained in:
Lucas Lin
2021-03-22 09:38:26 +00:00
committed by Android (Google) Code Review
2 changed files with 15 additions and 16 deletions

View File

@@ -17,7 +17,6 @@
package com.android.server.connectivity;
import static android.Manifest.permission.BIND_VPN_SERVICE;
import static android.net.ConnectivityManager.NETID_UNSET;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_METERED;
import static android.net.RouteInfo.RTN_THROW;
import static android.net.RouteInfo.RTN_UNREACHABLE;
@@ -1129,17 +1128,17 @@ public class Vpn {
}
/**
* Return netId of current running VPN network.
* Return Network of current running VPN network.
*
* @return a netId if there is a running VPN network or NETID_UNSET if there is no running VPN
* @return a Network if there is a running VPN network or null if there is no running VPN
* network or network is null.
*/
public synchronized int getNetId() {
public synchronized Network getNetwork() {
final NetworkAgent agent = mNetworkAgent;
if (null == agent) return NETID_UNSET;
if (null == agent) return null;
final Network network = agent.getNetwork();
if (null == network) return NETID_UNSET;
return network.getNetId();
if (null == network) return null;
return network;
}
private LinkProperties makeLinkProperties() {

View File

@@ -1177,11 +1177,6 @@ public class ConnectivityServiceTest {
return (mMockNetworkAgent == null) ? null : mMockNetworkAgent.getNetwork();
}
@Override
public int getNetId() {
return (mMockNetworkAgent == null) ? NETID_UNSET : mMockNetworkAgent.getNetwork().netId;
}
@Override
public int getActiveVpnType() {
return mVpnType;
@@ -1206,10 +1201,12 @@ public class ConnectivityServiceTest {
mNetworkCapabilities);
mMockNetworkAgent.waitForIdle(TIMEOUT_MS);
verify(mMockNetd, times(1)).networkAddUidRanges(eq(mMockVpn.getNetId()),
final int expectedNetId = mMockVpn.getNetwork() == null ? NETID_UNSET
: mMockVpn.getNetwork().getNetId();
verify(mMockNetd, times(1)).networkAddUidRanges(eq(expectedNetId),
eq(toUidRangeStableParcels(uids)));
verify(mMockNetd, never())
.networkRemoveUidRanges(eq(mMockVpn.getNetId()), any());
.networkRemoveUidRanges(eq(expectedNetId), any());
mAgentRegistered = true;
updateState(NetworkInfo.DetailedState.CONNECTED, "registerAgent");
mNetworkCapabilities.set(mMockNetworkAgent.getNetworkCapabilities());
@@ -9745,11 +9742,14 @@ public class ConnectivityServiceTest {
exemptUidCaptor.capture());
assertContainsExactly(exemptUidCaptor.getValue(), Process.VPN_UID, exemptUid);
final int expectedNetId = mMockVpn.getNetwork() == null ? NETID_UNSET
: mMockVpn.getNetwork().getNetId();
if (add) {
inOrder.verify(mMockNetd, times(1)).networkAddUidRanges(eq(mMockVpn.getNetId()),
inOrder.verify(mMockNetd, times(1)).networkAddUidRanges(eq(expectedNetId),
eq(toUidRangeStableParcels(vpnRanges)));
} else {
inOrder.verify(mMockNetd, times(1)).networkRemoveUidRanges(eq(mMockVpn.getNetId()),
inOrder.verify(mMockNetd, times(1)).networkRemoveUidRanges(eq(expectedNetId),
eq(toUidRangeStableParcels(vpnRanges)));
}