Use NetdUtils instead of NetworkManagementService in IpSecService
NetdUtils has the same method(e.g. setInterfaceUp) as NetworkManagementService so using the one inside NetdUtils instead and try to remove NetworkManagementService from IpSecService in the following commit. Bug: 170598012 Test: atest FrameworksNetTests Change-Id: I0ed8b0c678b067a655b51b938b6b40eadd985321
This commit is contained in:
@@ -16,12 +16,16 @@
|
||||
|
||||
package com.android.server;
|
||||
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
import static android.net.INetd.IF_STATE_DOWN;
|
||||
import static android.net.INetd.IF_STATE_UP;
|
||||
import static android.system.OsConstants.AF_INET;
|
||||
import static android.system.OsConstants.AF_INET6;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
@@ -35,6 +39,7 @@ import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.INetd;
|
||||
import android.net.InetAddresses;
|
||||
import android.net.InterfaceConfigurationParcel;
|
||||
import android.net.IpSecAlgorithm;
|
||||
import android.net.IpSecConfig;
|
||||
import android.net.IpSecManager;
|
||||
@@ -133,6 +138,14 @@ public class IpSecServiceParameterizedTest {
|
||||
}
|
||||
throw new SecurityException("Unavailable permission requested");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkCallingOrSelfPermission(String permission) {
|
||||
if (android.Manifest.permission.NETWORK_STACK.equals(permission)) {
|
||||
return PERMISSION_GRANTED;
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
|
||||
INetd mMockNetd;
|
||||
@@ -625,7 +638,10 @@ public class IpSecServiceParameterizedTest {
|
||||
}
|
||||
|
||||
private IpSecTunnelInterfaceResponse createAndValidateTunnel(
|
||||
String localAddr, String remoteAddr, String pkgName) {
|
||||
String localAddr, String remoteAddr, String pkgName) throws Exception {
|
||||
final InterfaceConfigurationParcel config = new InterfaceConfigurationParcel();
|
||||
config.flags = new String[] {IF_STATE_DOWN};
|
||||
when(mMockNetd.interfaceGetCfg(anyString())).thenReturn(config);
|
||||
IpSecTunnelInterfaceResponse createTunnelResp =
|
||||
mIpSecService.createTunnelInterface(
|
||||
mSourceAddr, mDestinationAddr, fakeNetwork, new Binder(), pkgName);
|
||||
@@ -655,7 +671,8 @@ public class IpSecServiceParameterizedTest {
|
||||
anyInt(),
|
||||
anyInt(),
|
||||
anyInt());
|
||||
verify(mNetworkManager).setInterfaceUp(createTunnelResp.interfaceName);
|
||||
verify(mMockNetd).interfaceSetCfg(argThat(
|
||||
config -> Arrays.asList(config.flags).contains(IF_STATE_UP)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user