From 25c74bd2505b827512c7029fab6e43124613d65a Mon Sep 17 00:00:00 2001 From: chiachangwang Date: Thu, 13 Apr 2023 09:01:47 +0000 Subject: [PATCH] Fix inexact argument type warning Assign the corresponding VpnProfileState for the null argument. The varargs parameter has type "VpnProfileState...". It needs to decide whether the implementation want the argument to be treated as a single-element of type VpnProfileState or no arguement. Otherwise, it will confuse the compiler and cause warning. Test: atest VpnTest Change-Id: Ic1dee696bb50cd78849de4812fb46fd764b23c6e --- .../android/server/connectivity/VpnTest.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/unit/java/com/android/server/connectivity/VpnTest.java b/tests/unit/java/com/android/server/connectivity/VpnTest.java index dd9177eede..dcad5e337a 100644 --- a/tests/unit/java/com/android/server/connectivity/VpnTest.java +++ b/tests/unit/java/com/android/server/connectivity/VpnTest.java @@ -1293,12 +1293,12 @@ public class VpnTest extends VpnTestBase { } private void verifyVpnManagerEvent(String sessionKey, String category, int errorClass, - int errorCode, String[] packageName, VpnProfileState... profileState) { + int errorCode, String[] packageName, @NonNull VpnProfileState... profileState) { final Context userContext = mContext.createContextAsUser(UserHandle.of(PRIMARY_USER.id), 0 /* flags */); final ArgumentCaptor intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); - final int verifyTimes = (profileState == null) ? 1 : profileState.length; + final int verifyTimes = profileState.length; verify(userContext, times(verifyTimes)).startService(intentArgumentCaptor.capture()); for (int i = 0; i < verifyTimes; i++) { @@ -1329,10 +1329,8 @@ public class VpnTest extends VpnTestBase { VpnManager.EXTRA_UNDERLYING_LINK_PROPERTIES)); } - if (profileState != null) { - assertEquals(profileState[i], intent.getParcelableExtra( - VpnManager.EXTRA_VPN_PROFILE_STATE, VpnProfileState.class)); - } + assertEquals(profileState[i], intent.getParcelableExtra( + VpnManager.EXTRA_VPN_PROFILE_STATE, VpnProfileState.class)); } reset(userContext); } @@ -1341,7 +1339,11 @@ public class VpnTest extends VpnTestBase { // CATEGORY_EVENT_DEACTIVATED_BY_USER is not an error event, so both of errorClass and // errorCode won't be set. verifyVpnManagerEvent(sessionKey, VpnManager.CATEGORY_EVENT_DEACTIVATED_BY_USER, - -1 /* errorClass */, -1 /* errorCode */, packageName, null /* profileState */); + -1 /* errorClass */, -1 /* errorCode */, packageName, + // VPN NetworkAgnet does not switch to CONNECTED in the test, and the state is not + // important here. Verify that the state as it is, i.e. CONNECTING state. + new VpnProfileState(VpnProfileState.STATE_CONNECTING, + sessionKey, false /* alwaysOn */, false /* lockdown */)); } private void verifyAlwaysOnStateChanged(String[] packageName, VpnProfileState... profileState) { @@ -1586,7 +1588,10 @@ public class VpnTest extends VpnTestBase { verifyPowerSaveTempWhitelistApp(TEST_VPN_PKG); reset(mDeviceIdleInternal); verifyVpnManagerEvent(sessionKey, category, errorType, errorCode, - new String[] {TEST_VPN_PKG}, null /* profileState */); + // VPN NetworkAgnet does not switch to CONNECTED in the test, and the state is not + // important here. Verify that the state as it is, i.e. CONNECTING state. + new String[] {TEST_VPN_PKG}, new VpnProfileState(VpnProfileState.STATE_CONNECTING, + sessionKey, false /* alwaysOn */, false /* lockdown */)); if (errorType == VpnManager.ERROR_CLASS_NOT_RECOVERABLE) { verify(mConnectivityManager, timeout(TEST_TIMEOUT_MS)) .unregisterNetworkCallback(eq(cb));