diff options
author | Nate Jiang <qiangjiang@google.com> | 2019-06-13 17:09:05 -0700 |
---|---|---|
committer | Nate Jiang <qiangjiang@google.com> | 2019-06-18 00:10:21 +0000 |
commit | 1b9909b212b93ab2c08026a8a2eecb11bb7d25d6 (patch) | |
tree | 1809e70fc34a30bf39af9b38cb5c576ab70eea1e | |
parent | eb25378f0bc54f17392cc8e24cd29068e364aae5 (diff) |
WifiNetworkSuggestionsManager: remove suggestion when Apps remove that
When carrier wifi removed the suggestion, framework should remove it.
And trigger disconnect
Test: atest android.net.wifi
Test: atest com.android.server.wifi
Test: ACTS WifiNetworkSuggestionTest
Bug: 135204977
Change-Id: I89c2d20003f4d58164bade3a010e7d9811ff167b
4 files changed, 82 insertions, 24 deletions
diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java index c2aade90b..35db1b0b2 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java +++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java @@ -634,7 +634,7 @@ public class WifiNetworkSuggestionsManager { * Remove the provided list of network suggestions from the corresponding app's active list. */ public @WifiManager.NetworkSuggestionsStatusCode int remove( - List<WifiNetworkSuggestion> networkSuggestions, String packageName) { + List<WifiNetworkSuggestion> networkSuggestions, int uid, String packageName) { if (mVerboseLoggingEnabled) { Log.v(TAG, "Removing " + networkSuggestions.size() + " networks from " + packageName); } @@ -653,6 +653,9 @@ public class WifiNetworkSuggestionsManager { + ". Network suggestions not found in active network suggestions"); return WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID; } + if (mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(uid)) { + triggerDisconnectIfServingNetworkSuggestionRemoved(extNetworkSuggestions); + } removeInternal(extNetworkSuggestions, packageName, perAppInfo); saveToStore(); mWifiMetrics.incrementNetworkSuggestionApiNumModification(); diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index 6bb36b3b9..f04755fd9 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -3313,11 +3313,12 @@ public class WifiServiceImpl extends BaseWifiService { if (mVerboseLoggingEnabled) { mLog.info("removeNetworkSuggestions uid=%").c(Binder.getCallingUid()).flush(); } + int callingUid = Binder.getCallingUid(); Mutable<Integer> success = new Mutable<>(); boolean runWithScissorsSuccess = mWifiInjector.getClientModeImplHandler().runWithScissors( () -> { success.value = mWifiNetworkSuggestionsManager.remove( - networkSuggestions, callingPackageName); + networkSuggestions, callingUid, callingPackageName); }, RUN_WITH_SCISSORS_TIMEOUT_MILLIS); if (!runWithScissorsSuccess) { Log.e(TAG, "Failed to post runnable to remove network suggestions"); 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)); } /** |