diff options
author | Nate Jiang <qiangjiang@google.com> | 2019-06-17 18:55:44 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-06-17 18:55:44 -0700 |
commit | 2e531f735b962e759295eb779979065f654ea6d0 (patch) | |
tree | 3891bc604d0373668fb5a911da2e103c43f5078f /tests | |
parent | 68fa6a30e16e32f65f5d82343b0e4c7f96175048 (diff) | |
parent | 0c70bee1f091bee84bf54551904099769a543dab (diff) |
WifiNetworkSuggestionsManager: remove suggestion when Apps remove that am: 1b9909b212
am: 0c70bee1f0
Change-Id: I9008ce1087f240127c182b3e8da2eed0d3d0d528
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java | 91 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java | 7 |
2 files changed, 76 insertions, 22 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java index ca7c13e31..98e5178d7 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java @@ -245,14 +245,16 @@ public class WifiNetworkSuggestionsManagerTest { mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, TEST_PACKAGE_1)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, - mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_2, + mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_1, TEST_PACKAGE_2)); // Now remove all of them. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, - mWifiNetworkSuggestionsManager.remove(networkSuggestionList1, TEST_PACKAGE_1)); + mWifiNetworkSuggestionsManager.remove(networkSuggestionList1, + TEST_UID_1, TEST_PACKAGE_1)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, - mWifiNetworkSuggestionsManager.remove(networkSuggestionList2, TEST_PACKAGE_2)); + mWifiNetworkSuggestionsManager.remove(networkSuggestionList2, + TEST_UID_1, TEST_PACKAGE_2)); assertTrue(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions().isEmpty()); @@ -294,9 +296,11 @@ public class WifiNetworkSuggestionsManagerTest { // Now remove all of them by sending an empty list. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, - mWifiNetworkSuggestionsManager.remove(new ArrayList<>(), TEST_PACKAGE_1)); + mWifiNetworkSuggestionsManager.remove(new ArrayList<>(), TEST_UID_1, + TEST_PACKAGE_1)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, - mWifiNetworkSuggestionsManager.remove(new ArrayList<>(), TEST_PACKAGE_2)); + mWifiNetworkSuggestionsManager.remove(new ArrayList<>(), TEST_UID_2, + TEST_PACKAGE_2)); assertTrue(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions().isEmpty()); } @@ -319,7 +323,8 @@ public class WifiNetworkSuggestionsManagerTest { mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, TEST_PACKAGE_1)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, - mWifiNetworkSuggestionsManager.remove(networkSuggestionList1, TEST_PACKAGE_1)); + mWifiNetworkSuggestionsManager.remove(networkSuggestionList1, TEST_UID_1, + TEST_PACKAGE_1)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, TEST_PACKAGE_1)); @@ -397,7 +402,8 @@ public class WifiNetworkSuggestionsManagerTest { } // The remove should succeed. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, - mWifiNetworkSuggestionsManager.remove(networkSuggestionList, TEST_PACKAGE_1)); + mWifiNetworkSuggestionsManager.remove(networkSuggestionList, TEST_UID_1, + TEST_PACKAGE_1)); // Now add 2 more. networkSuggestionList = new ArrayList<>(); @@ -437,7 +443,8 @@ public class WifiNetworkSuggestionsManagerTest { TEST_PACKAGE_1)); // Remove should fail because the network list is different. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID, - mWifiNetworkSuggestionsManager.remove(networkSuggestionList2, TEST_PACKAGE_1)); + mWifiNetworkSuggestionsManager.remove(networkSuggestionList2, TEST_UID_1, + TEST_PACKAGE_1)); } /** @@ -766,7 +773,8 @@ public class WifiNetworkSuggestionsManagerTest { // remove the suggestion & ensure lookup fails. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, - mWifiNetworkSuggestionsManager.remove(Collections.EMPTY_LIST, TEST_PACKAGE_1)); + mWifiNetworkSuggestionsManager.remove(Collections.EMPTY_LIST, TEST_UID_1, + TEST_PACKAGE_1)); assertNull(mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail(scanDetail)); } @@ -1205,7 +1213,8 @@ public class WifiNetworkSuggestionsManagerTest { mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, TEST_PACKAGE_1)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, - mWifiNetworkSuggestionsManager.remove(networkSuggestionList, TEST_PACKAGE_1)); + mWifiNetworkSuggestionsManager.remove(networkSuggestionList, TEST_UID_1, + TEST_PACKAGE_1)); // Verify config store interactions. verify(mWifiConfigManager, times(2)).saveToStore(true); @@ -1314,10 +1323,11 @@ public class WifiNetworkSuggestionsManagerTest { /** * Verify that we don't disconnect from the network if the only network suggestion matching the - * connected network is removed. + * connected network is removed when App doesn't have NetworkCarrierProvisioningPermission. */ @Test - public void testRemoveNetworkSuggestionsMatchingConnectionSuccessWithOneMatch() { + public void + testRemoveNetworkSuggestionsMatchingConnectionSuccessWithOneMatchNoCarrierProvision() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, TEST_PACKAGE_1); @@ -1325,6 +1335,8 @@ public class WifiNetworkSuggestionsManagerTest { new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); }}; + when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(TEST_UID_1)) + .thenReturn(false); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, TEST_PACKAGE_1)); @@ -1337,11 +1349,46 @@ public class WifiNetworkSuggestionsManagerTest { // Now remove the network suggestion and ensure we did not trigger a disconnect. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, - mWifiNetworkSuggestionsManager.remove(networkSuggestionList, TEST_PACKAGE_1)); + mWifiNetworkSuggestionsManager.remove(networkSuggestionList, TEST_UID_1, + TEST_PACKAGE_1)); verify(mClientModeImpl, never()).disconnectCommand(); } /** + * Verify that we will disconnect from the network if the only network suggestion matching the + * connected network is removed when App has NetworkCarrierProvisioningPermission. + */ + @Test + public void + testRemoveNetworkSuggestionsMatchingConnectionSuccessWithOneMatchCarrierProvision() { + WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( + WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + TEST_PACKAGE_1); + List<WifiNetworkSuggestion> networkSuggestionList = + new ArrayList<WifiNetworkSuggestion>() {{ + add(networkSuggestion); + }}; + when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(TEST_UID_1)) + .thenReturn(true); + assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, + mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, + TEST_PACKAGE_1)); + mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); + + // Simulate connecting to the network. + mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( + WifiMetrics.ConnectionEvent.FAILURE_NONE, networkSuggestion.wifiConfiguration, + TEST_BSSID); + + // Now remove the network suggestion and ensure we did trigger a disconnect. + assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, + mWifiNetworkSuggestionsManager.remove(networkSuggestionList, TEST_UID_1, + TEST_PACKAGE_1)); + verify(mClientModeImpl).disconnectCommand(); + } + + + /** * Verify that we do not disconnect from the network if there are network suggestion from * multiple apps matching the connected network when one of the apps is removed. */ @@ -1484,10 +1531,12 @@ public class WifiNetworkSuggestionsManagerTest { // Now remove first add, nothing happens. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, - mWifiNetworkSuggestionsManager.remove(networkSuggestionList1, TEST_PACKAGE_1)); + mWifiNetworkSuggestionsManager.remove(networkSuggestionList1, TEST_UID_1, + TEST_PACKAGE_1)); // Stop watching app-ops changes on last remove. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, - mWifiNetworkSuggestionsManager.remove(networkSuggestionList2, TEST_PACKAGE_1)); + mWifiNetworkSuggestionsManager.remove(networkSuggestionList2, TEST_UID_1, + TEST_PACKAGE_1)); assertTrue(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions().isEmpty()); mInorder.verify(mAppOpsManager).stopWatchingMode(mAppOpChangedListenerCaptor.getValue()); @@ -1666,9 +1715,11 @@ public class WifiNetworkSuggestionsManagerTest { // Remove all suggestions from TEST_PACKAGE_1 & TEST_PACKAGE_2, we should continue to track. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, - mWifiNetworkSuggestionsManager.remove(networkSuggestionList1, TEST_PACKAGE_1)); + mWifiNetworkSuggestionsManager.remove(networkSuggestionList1, TEST_UID_1, + TEST_PACKAGE_1)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, - mWifiNetworkSuggestionsManager.remove(networkSuggestionList2, TEST_PACKAGE_2)); + mWifiNetworkSuggestionsManager.remove(networkSuggestionList2, TEST_UID_2, + TEST_PACKAGE_2)); assertTrue(mDataSource.hasNewDataToSerialize()); Map<String, PerAppInfo> networkSuggestionsMapToWrite = mDataSource.toSerialize(); @@ -1730,9 +1781,11 @@ public class WifiNetworkSuggestionsManagerTest { // Remove all suggestions from TEST_PACKAGE_1 & TEST_PACKAGE_2, we should continue to track. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, - mWifiNetworkSuggestionsManager.remove(networkSuggestionList1, TEST_PACKAGE_1)); + mWifiNetworkSuggestionsManager.remove(networkSuggestionList1, TEST_UID_1, + TEST_PACKAGE_1)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, - mWifiNetworkSuggestionsManager.remove(networkSuggestionList2, TEST_PACKAGE_2)); + mWifiNetworkSuggestionsManager.remove(networkSuggestionList2, TEST_UID_2, + TEST_PACKAGE_2)); assertTrue(mDataSource.hasNewDataToSerialize()); Map<String, PerAppInfo> networkSuggestionsMapToWrite = mDataSource.toSerialize(); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index b69fba78b..80b7406ee 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -3793,12 +3793,12 @@ public class WifiServiceImplTest { public void testRemoveNetworkSuggestions() { setupClientModeImplHandlerForRunWithScissors(); - when(mWifiNetworkSuggestionsManager.remove(any(), anyString())) + when(mWifiNetworkSuggestionsManager.remove(any(), anyInt(), anyString())) .thenReturn(WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID, mWifiServiceImpl.removeNetworkSuggestions(mock(List.class), TEST_PACKAGE_NAME)); - when(mWifiNetworkSuggestionsManager.remove(any(), anyString())) + when(mWifiNetworkSuggestionsManager.remove(any(), anyInt(), anyString())) .thenReturn(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiServiceImpl.removeNetworkSuggestions(mock(List.class), TEST_PACKAGE_NAME)); @@ -3808,7 +3808,8 @@ public class WifiServiceImplTest { assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_INTERNAL, mWifiServiceImpl.removeNetworkSuggestions(mock(List.class), TEST_PACKAGE_NAME)); - verify(mWifiNetworkSuggestionsManager, times(2)).remove(any(), eq(TEST_PACKAGE_NAME)); + verify(mWifiNetworkSuggestionsManager, times(2)).remove(any(), anyInt(), + eq(TEST_PACKAGE_NAME)); } /** |