Fix NullPointerException in Ikev2VpnTest for watches

Watches do not have a VpnManager instance anymore, so the tests crashes
at the teardown step when trying to interact with a null VpnManager.

Bug: 368624224
Bug: 340928692
Test: Ikev2VpnTest
Change-Id: Iedf784625933e73bcb5fed9bfa36fbae1e11d398
This commit is contained in:
Yeabkal Wubshit 2024-09-20 19:44:53 +00:00
commit 13c6573270

View file

@ -184,6 +184,8 @@ public class Ikev2VpnTest {
// Static state to reduce setup/teardown
private static final Context sContext = InstrumentationRegistry.getContext();
private static boolean sIsWatch =
sContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH);
private static final ConnectivityManager sCM =
(ConnectivityManager) sContext.getSystemService(Context.CONNECTIVITY_SERVICE);
private static final VpnManager sVpnMgr =
@ -205,12 +207,15 @@ public class Ikev2VpnTest {
@Before
public void setUp() {
assumeFalse("Skipping test because watches don't support VPN",
sContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH));
assumeFalse("Skipping test because watches don't support VPN", sIsWatch);
}
@After
public void tearDown() {
if (sIsWatch) {
return; // Tests are skipped for watches.
}
for (TestableNetworkCallback callback : mCallbacksToUnregister) {
sCM.unregisterNetworkCallback(callback);
}