From e4e5a49dbe4ca726c51d9350fa61088c2bb23d8a Mon Sep 17 00:00:00 2001 From: Purushottam Kushwaha Date: Tue, 1 Sep 2020 11:19:37 +0530 Subject: NPE: Add null check for getConfiguredNetwork() During CMD_RESET_SIM_NETWORKS , WifiConfiguration get via getConfiguredNetwork() shall be guarded with null to avoid Null Pointer Exception. Bug: 167345712 Test: atest com.android.server.wifi (cherry-picked from 75f843c66829afc8920f3cf6302651f753985cba) (cherry picked from commit 36f987c05103b123e40f65a792d81e7c3a1710d3) Merged-In: I612817342a9c541d51c8c022f7c09b9462e39d21 Change-Id: I612817342a9c541d51c8c022f7c09b9462e39d21 --- .../src/com/android/server/wifi/ClientModeImplTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java index a9d7f0ce2..fd1ef1718 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java @@ -1113,6 +1113,23 @@ public class ClientModeImplTest extends WifiBaseTest { assertEquals("DisconnectingState", getCurrentState().getName()); } + /** + * When the SIM card was removed, if the current wifi connection is using it, the connection + * should be disconnected, otherwise, the connection shouldn't be impacted. + */ + @Test + public void testResetSimWhenConnectedSimRemovedAfterNetworkRemoval() throws Exception { + setupEapSimConnection(); + doReturn(false).when(mWifiCarrierInfoManager).isSimPresent(eq(DATA_SUBID)); + when(mWifiConfigManager.getConfiguredNetwork(anyInt())).thenReturn(null); + mCmi.sendMessage(ClientModeImpl.CMD_RESET_SIM_NETWORKS, + ClientModeImpl.RESET_SIM_REASON_SIM_REMOVED); + mLooper.dispatchAll(); + + verify(mSimRequiredNotifier, never()).showSimRequiredNotification(any(), any()); + assertEquals("ObtainingIpState", getCurrentState().getName()); + } + /** * When the default data SIM is changed, if the current wifi connection is carrier wifi, * the connection should be disconnected. -- cgit v1.2.3