Merge "Remove last @hide usage in CtsNetTestCases" into main
This commit is contained in:
commit
643c401087
3 changed files with 37 additions and 21 deletions
|
|
@ -72,8 +72,8 @@ import com.android.compatibility.common.util.PropertyUtil.getVsrApiLevel
|
|||
import com.android.compatibility.common.util.SystemUtil.runShellCommand
|
||||
import com.android.compatibility.common.util.SystemUtil.runShellCommandOrThrow
|
||||
import com.android.compatibility.common.util.VsrTest
|
||||
import com.android.internal.util.HexDump
|
||||
import com.android.modules.utils.build.SdkLevel
|
||||
import com.android.net.module.util.HexDump
|
||||
import com.android.net.module.util.NetworkStackConstants.ETHER_ADDR_LEN
|
||||
import com.android.net.module.util.NetworkStackConstants.ETHER_DST_ADDR_OFFSET
|
||||
import com.android.net.module.util.NetworkStackConstants.ETHER_HEADER_LEN
|
||||
|
|
@ -170,7 +170,10 @@ class ApfIntegrationTest {
|
|||
val packageManager = context.getPackageManager()
|
||||
val userManager = context.getSystemService(UserManager::class.java)!!
|
||||
return (packageManager.hasSystemFeature(FEATURE_AUTOMOTIVE) &&
|
||||
userManager.isVisibleBackgroundUsersSupported)
|
||||
// isVisibleBackgroundUsersSupported is @TestApi, but this test should build
|
||||
// against module API stubs, which do not include it (b/409931932).
|
||||
userManager.javaClass.getMethod("isVisibleBackgroundUsersSupported")
|
||||
.invoke(userManager) as Boolean)
|
||||
}
|
||||
|
||||
private fun disableLowPowerStandby() {
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ import static android.net.NetworkCapabilities.TRANSPORT_VPN;
|
|||
import static android.net.cts.util.CtsNetUtils.TestNetworkCallback;
|
||||
|
||||
import static com.android.compatibility.common.util.SystemUtil.runWithShellPermissionIdentity;
|
||||
import static com.android.modules.utils.build.SdkLevel.isAtLeastU;
|
||||
import static com.android.modules.utils.build.SdkLevel.isAtLeastT;
|
||||
import static com.android.modules.utils.build.SdkLevel.isAtLeastU;
|
||||
import static com.android.testutils.DevSdkIgnoreRuleKt.SC_V2;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
|
@ -34,12 +34,11 @@ import static org.junit.Assert.assertNull;
|
|||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.junit.Assume.assumeFalse;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.NonNull;
|
||||
import android.app.AppOpsManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
|
|
@ -99,6 +98,10 @@ import javax.security.auth.x500.X500Principal;
|
|||
public class Ikev2VpnTest {
|
||||
private static final String TAG = Ikev2VpnTest.class.getSimpleName();
|
||||
|
||||
// TODO: make AppOpsManager.OP_ACTIVATE_VPN API
|
||||
private static final int OP_ACTIVATE_VPN = 47;
|
||||
private static final int OP_ACTIVATE_PLATFORM_VPN = 94;
|
||||
|
||||
@Rule
|
||||
public final DevSdkIgnoreRule ignoreRule = new DevSdkIgnoreRule();
|
||||
|
||||
|
|
@ -219,8 +222,8 @@ public class Ikev2VpnTest {
|
|||
for (TestableNetworkCallback callback : mCallbacksToUnregister) {
|
||||
sCM.unregisterNetworkCallback(callback);
|
||||
}
|
||||
setAppop(AppOpsManager.OP_ACTIVATE_VPN, false);
|
||||
setAppop(AppOpsManager.OP_ACTIVATE_PLATFORM_VPN, false);
|
||||
setAppop(OP_ACTIVATE_VPN, false);
|
||||
setAppop(OP_ACTIVATE_PLATFORM_VPN, false);
|
||||
|
||||
// Make sure the VpnProfile is not provisioned already.
|
||||
sVpnMgr.stopProvisionedVpnProfile();
|
||||
|
|
@ -265,14 +268,22 @@ public class Ikev2VpnTest {
|
|||
builder.setAutomaticNattKeepaliveTimerEnabled(automaticNattKeepaliveTimerEnabled);
|
||||
}
|
||||
|
||||
// TODO: replace it in alternative way to remove the hidden method usage
|
||||
if (isRestrictedToTestNetworks) {
|
||||
builder.restrictToTestNetworks();
|
||||
restrictToTestNetworks(builder);
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private void restrictToTestNetworks(@NonNull Ikev2VpnProfile.Builder builder) {
|
||||
try {
|
||||
// TODO: replace it in alternative way to remove the hidden method usage
|
||||
builder.getClass().getMethod("restrictToTestNetworks").invoke(builder);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private Ikev2VpnProfile buildIkev2VpnProfileIkeTunConnParams(
|
||||
final boolean isRestrictedToTestNetworks, final boolean requiresValidation,
|
||||
final boolean testIpv6) throws Exception {
|
||||
|
|
@ -288,9 +299,8 @@ public class Ikev2VpnTest {
|
|||
.setMaxMtu(TEST_MTU)
|
||||
.setMetered(false);
|
||||
|
||||
// TODO: replace it in alternative way to remove the hidden method usage
|
||||
if (isRestrictedToTestNetworks) {
|
||||
builder.restrictToTestNetworks();
|
||||
restrictToTestNetworks(builder);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
|
@ -335,7 +345,8 @@ public class Ikev2VpnTest {
|
|||
assertTrue(profile.isBypassable());
|
||||
assertFalse(profile.isMetered());
|
||||
assertEquals(TEST_MTU, profile.getMaxMtu());
|
||||
assertFalse(profile.isRestrictedToTestNetworks());
|
||||
assertFalse((boolean) profile.getClass().getMethod("isRestrictedToTestNetworks")
|
||||
.invoke(profile));
|
||||
}
|
||||
|
||||
public void doTestBuildIkev2VpnProfilePsk(final boolean requiresValidation) throws Exception {
|
||||
|
|
@ -427,8 +438,8 @@ public class Ikev2VpnTest {
|
|||
throws Exception {
|
||||
assumeTrue(mCtsNetUtils.hasIpsecTunnelsFeature());
|
||||
|
||||
setAppop(AppOpsManager.OP_ACTIVATE_VPN, hasActivateVpn);
|
||||
setAppop(AppOpsManager.OP_ACTIVATE_PLATFORM_VPN, hasActivatePlatformVpn);
|
||||
setAppop(OP_ACTIVATE_VPN, hasActivateVpn);
|
||||
setAppop(OP_ACTIVATE_PLATFORM_VPN, hasActivatePlatformVpn);
|
||||
|
||||
final Ikev2VpnProfile profile = buildIkev2VpnProfilePsk(TEST_SERVER_ADDR_V6,
|
||||
false /* isRestrictedToTestNetworks */, false /* requiresValidation */);
|
||||
|
|
@ -472,19 +483,19 @@ public class Ikev2VpnTest {
|
|||
public void testDeleteVpnProfile() throws Exception {
|
||||
assumeTrue(mCtsNetUtils.hasIpsecTunnelsFeature());
|
||||
|
||||
setAppop(AppOpsManager.OP_ACTIVATE_PLATFORM_VPN, true);
|
||||
setAppop(OP_ACTIVATE_PLATFORM_VPN, true);
|
||||
|
||||
final Ikev2VpnProfile profile = buildIkev2VpnProfilePsk(TEST_SERVER_ADDR_V6,
|
||||
false /* isRestrictedToTestNetworks */, false /* requiresValidation */);
|
||||
assertNull(sVpnMgr.provisionVpnProfile(profile));
|
||||
|
||||
// Verify that deleting the profile works (even without the appop)
|
||||
setAppop(AppOpsManager.OP_ACTIVATE_PLATFORM_VPN, false);
|
||||
setAppop(OP_ACTIVATE_PLATFORM_VPN, false);
|
||||
sVpnMgr.deleteProvisionedVpnProfile();
|
||||
|
||||
// Test that the profile was deleted - starting it should throw an IAE.
|
||||
try {
|
||||
setAppop(AppOpsManager.OP_ACTIVATE_PLATFORM_VPN, true);
|
||||
setAppop(OP_ACTIVATE_PLATFORM_VPN, true);
|
||||
sVpnMgr.startProvisionedVpnProfile();
|
||||
fail("Expected IllegalArgumentException due to missing profile");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
|
|
@ -495,8 +506,8 @@ public class Ikev2VpnTest {
|
|||
public void testStartVpnProfileNoPreviousConsent() throws Exception {
|
||||
assumeTrue(mCtsNetUtils.hasIpsecTunnelsFeature());
|
||||
|
||||
setAppop(AppOpsManager.OP_ACTIVATE_VPN, false);
|
||||
setAppop(AppOpsManager.OP_ACTIVATE_PLATFORM_VPN, false);
|
||||
setAppop(OP_ACTIVATE_VPN, false);
|
||||
setAppop(OP_ACTIVATE_PLATFORM_VPN, false);
|
||||
|
||||
// Make sure the VpnProfile is not provisioned already.
|
||||
sVpnMgr.stopProvisionedVpnProfile();
|
||||
|
|
@ -518,7 +529,7 @@ public class Ikev2VpnTest {
|
|||
boolean hasNat = !testIpv6;
|
||||
|
||||
// Requires MANAGE_TEST_NETWORKS to provision a test-mode profile.
|
||||
mCtsNetUtils.setAppopPrivileged(AppOpsManager.OP_ACTIVATE_PLATFORM_VPN, true);
|
||||
mCtsNetUtils.setAppopPrivileged(OP_ACTIVATE_PLATFORM_VPN, true);
|
||||
|
||||
final Ikev2VpnProfile profile = testIkeTunConnParams
|
||||
? buildIkev2VpnProfileIkeTunConnParams(true /* isRestrictedToTestNetworks */,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package android.net.cts;
|
||||
|
||||
import static android.app.AppOpsManager.OP_MANAGE_IPSEC_TUNNELS;
|
||||
import static android.net.IpSecManager.UdpEncapsulationSocket;
|
||||
import static android.net.cts.IpSecManagerTest.assumeExperimentalIpv6UdpEncapSupported;
|
||||
import static android.net.cts.IpSecManagerTest.assumeRequestIpSecTransformStateSupported;
|
||||
|
|
@ -87,6 +86,9 @@ import java.net.NetworkInterface;
|
|||
public class IpSecManagerTunnelTest extends IpSecBaseTest {
|
||||
@Rule public final DevSdkIgnoreRule ignoreRule = new DevSdkIgnoreRule();
|
||||
|
||||
// TODO: make AppOpsManager.OP_MANAGE_IPSEC_TUNNELS API
|
||||
private static final int OP_MANAGE_IPSEC_TUNNELS = 75;
|
||||
|
||||
private static final String TAG = IpSecManagerTunnelTest.class.getSimpleName();
|
||||
|
||||
private static final InetAddress LOCAL_OUTER_4 = InetAddress.parseNumericAddress("192.0.2.1");
|
||||
|
|
|
|||
Loading…
Reference in a new issue