diff options
author | Philip P. Moltmann <moltmann@google.com> | 2019-11-09 00:56:14 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-11-09 00:56:14 +0000 |
commit | 2c10218113b2b4e05cef2613e94ddd8d5a8bab20 (patch) | |
tree | 4a9329c146892d3a153367a6589ef0a67377e2ef /tests | |
parent | bfa6215f9225708ca7234305c8976f7560984b46 (diff) | |
parent | b380b4739da60242500d9bede8b18a802bd62fda (diff) |
Merge "Pipe through featureId from app-context to wifi location checking code."
Diffstat (limited to 'tests')
12 files changed, 712 insertions, 550 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionStoreDataTest.java index c636bc566..e03d932df 100644 --- a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionStoreDataTest.java +++ b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionStoreDataTest.java @@ -54,6 +54,7 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { private static final int TEST_UID_2 = 14536; private static final String TEST_PACKAGE_NAME_1 = "com.android.test.1"; private static final String TEST_PACKAGE_NAME_2 = "com.android.test.2"; + private static final String TEST_FEATURE_ID = "com.android.feature.1"; private static final String TEST_CORRUPT_DATA_INVALID_SSID = "<NetworkSuggestionPerApp>\n" + "<string name=\"SuggestorPackageName\">com.android.test.1</string>\n" @@ -153,7 +154,7 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { public void serializeDeserializeSingleNetworkSuggestionFromSingleApp() throws Exception { Map<String, PerAppInfo> networkSuggestionsMap = new HashMap<>(); - PerAppInfo appInfo = new PerAppInfo(TEST_PACKAGE_NAME_1); + PerAppInfo appInfo = new PerAppInfo(TEST_PACKAGE_NAME_1, TEST_FEATURE_ID); WifiConfiguration configuration = WifiConfigurationTestUtil.createEapNetwork(); configuration.enterpriseConfig = @@ -187,7 +188,7 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { public void serializeDeserializeSingleNetworkSuggestionFromMultipleApps() throws Exception { Map<String, PerAppInfo> networkSuggestionsMap = new HashMap<>(); - PerAppInfo appInfo1 = new PerAppInfo(TEST_PACKAGE_NAME_1); + PerAppInfo appInfo1 = new PerAppInfo(TEST_PACKAGE_NAME_1, TEST_FEATURE_ID); WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_NAME_1); @@ -196,7 +197,7 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { ExtendedWifiNetworkSuggestion.fromWns(networkSuggestion1, appInfo1)); networkSuggestionsMap.put(TEST_PACKAGE_NAME_1, appInfo1); - PerAppInfo appInfo2 = new PerAppInfo(TEST_PACKAGE_NAME_2); + PerAppInfo appInfo2 = new PerAppInfo(TEST_PACKAGE_NAME_2, TEST_FEATURE_ID); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, TEST_UID_2, TEST_PACKAGE_NAME_2); @@ -215,7 +216,7 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { public void serializeDeserializeMultipleNetworkSuggestionFromMultipleApps() throws Exception { Map<String, PerAppInfo> networkSuggestionsMap = new HashMap<>(); - PerAppInfo appInfo1 = new PerAppInfo(TEST_PACKAGE_NAME_1); + PerAppInfo appInfo1 = new PerAppInfo(TEST_PACKAGE_NAME_1, TEST_FEATURE_ID); WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( WifiConfigurationTestUtil.createOpenNetwork(), null, false, true, TEST_UID_1, TEST_PACKAGE_NAME_1); @@ -229,7 +230,7 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { ExtendedWifiNetworkSuggestion.fromWns(networkSuggestion2, appInfo1)); networkSuggestionsMap.put(TEST_PACKAGE_NAME_1, appInfo1); - PerAppInfo appInfo2 = new PerAppInfo(TEST_PACKAGE_NAME_2); + PerAppInfo appInfo2 = new PerAppInfo(TEST_PACKAGE_NAME_2, TEST_FEATURE_ID); WifiNetworkSuggestion networkSuggestion3 = new WifiNetworkSuggestion( WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, TEST_UID_2, TEST_PACKAGE_NAME_2); diff --git a/tests/wifitests/src/com/android/server/wifi/ScoredNetworkEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/ScoredNetworkEvaluatorTest.java index 7c60fead0..bff45c99b 100644 --- a/tests/wifitests/src/com/android/server/wifi/ScoredNetworkEvaluatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ScoredNetworkEvaluatorTest.java @@ -237,7 +237,7 @@ public class ScoredNetworkEvaluatorTest extends WifiBaseTest { int[] levels = {mThresholdQualifiedRssi2G + 8, mThresholdQualifiedRssi2G + 10}; doThrow(new SecurityException()).when(mWifiPermissionsUtil).enforceCanAccessScanResults( - any(), anyInt()); + any(), any(), anyInt(), any()); ScanDetailsAndWifiConfigs scanDetailsAndConfigs = WifiNetworkSelectorTestUtil .setupScanDetailsAndConfigStore( @@ -247,7 +247,7 @@ public class ScoredNetworkEvaluatorTest extends WifiBaseTest { verify(mNetworkScoreManager, never()).requestScores(any()); verify(mWifiPermissionsUtil).enforceCanAccessScanResults( - eq(TEST_PACKAGE_NAME), eq(TEST_UID)); + eq(TEST_PACKAGE_NAME), eq(null), eq(TEST_UID), nullable(String.class)); } @Test @@ -260,7 +260,7 @@ public class ScoredNetworkEvaluatorTest extends WifiBaseTest { int[] levels = {mThresholdQualifiedRssi2G + 8, mThresholdQualifiedRssi2G + 10}; doThrow(new SecurityException()).when(mWifiPermissionsUtil).enforceCanAccessScanResults( - any(), anyInt()); + any(), any(), anyInt(), any()); ScanDetailsAndWifiConfigs scanDetailsAndConfigs = WifiNetworkSelectorTestUtil .setupScanDetailsAndConfigStore( @@ -270,7 +270,7 @@ public class ScoredNetworkEvaluatorTest extends WifiBaseTest { verify(mNetworkScoreManager, never()).requestScores(any()); verify(mWifiPermissionsUtil).enforceCanAccessScanResults( - eq(TEST_PACKAGE_NAME), eq(TEST_UID)); + eq(TEST_PACKAGE_NAME), eq(null), eq(TEST_UID), nullable(String.class)); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java index faccb1aec..02ea0e3c5 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java @@ -89,6 +89,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { private static final String TEST_PACKAGE_2 = "com.test54321"; private static final String TEST_APP_NAME_1 = "test12345"; private static final String TEST_APP_NAME_2 = "test54321"; + private static final String TEST_FEATURE = "testFeature"; private static final String TEST_BSSID = "00:11:22:33:44:55"; private static final String TEST_FQDN = "FQDN"; private static final int TEST_UID_1 = 5667; @@ -217,10 +218,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { anyInt(), anyString(), eq(true))).thenReturn(true); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_2, - TEST_PACKAGE_2)); + TEST_PACKAGE_2, TEST_FEATURE)); verify(mPasspointManager).addOrUpdateProvider( passpointConfiguration, TEST_UID_2, TEST_PACKAGE_2, true); @@ -271,10 +272,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { anyInt(), anyString(), eq(true))).thenReturn(true); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_1, - TEST_PACKAGE_2)); + TEST_PACKAGE_2, TEST_FEATURE)); // Now remove all of them. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, @@ -327,10 +328,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { anyInt(), anyString(), eq(true))).thenReturn(true); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_2, - TEST_PACKAGE_2)); + TEST_PACKAGE_2, TEST_FEATURE)); // Now remove all of them by sending an empty list. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, @@ -360,13 +361,13 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.remove(networkSuggestionList1, TEST_UID_1, TEST_PACKAGE_1)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); Set<WifiNetworkSuggestion> allNetworkSuggestions = mWifiNetworkSuggestionsManager.getAllNetworkSuggestions(); @@ -392,7 +393,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); // Modify the original suggestion. networkSuggestion.wifiConfiguration.meteredOverride = @@ -401,7 +402,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { // Replace attempt should success. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); assertEquals(WifiConfiguration.METERED_OVERRIDE_METERED, mWifiNetworkSuggestionsManager .get(TEST_PACKAGE_1).get(0).wifiConfiguration.meteredOverride); @@ -422,7 +423,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { // The first add should succeed. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); List<WifiNetworkSuggestion> originalNetworkSuggestionsList = networkSuggestionList; // Now add 3 more. @@ -435,7 +436,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { // The second add should fail. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_EXCEEDS_MAX_PER_APP, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); // Now remove 3 of the initially added ones. networkSuggestionList = new ArrayList<>(); @@ -457,7 +458,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { // This add should now succeed. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); } /** @@ -482,7 +483,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); // Remove should fail because the network list is different. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID, mWifiNetworkSuggestionsManager.remove(networkSuggestionList2, TEST_UID_1, @@ -508,7 +509,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { .thenReturn(true); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); ScanDetail scanDetail = createScanDetailForNetwork(networkSuggestion.wifiConfiguration); @@ -535,7 +536,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); ScanDetail scanDetail = createScanDetailForNetwork(networkSuggestion.wifiConfiguration); @@ -574,10 +575,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_2, - TEST_PACKAGE_2)); + TEST_PACKAGE_2, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_2); @@ -611,7 +612,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); Set<WifiNetworkSuggestion> matchingNetworkSuggestions = @@ -651,10 +652,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_2, - TEST_PACKAGE_2)); + TEST_PACKAGE_2, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_2); @@ -695,7 +696,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); Set<WifiNetworkSuggestion> matchingNetworkSuggestions = @@ -738,10 +739,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_2, - TEST_PACKAGE_2)); + TEST_PACKAGE_2, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_2); @@ -782,7 +783,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); assertFalse(mWifiNetworkSuggestionsManager.hasUserApprovedForApp(TEST_PACKAGE_1)); ScanDetail scanDetail = createScanDetailForNetwork(networkSuggestion.wifiConfiguration); @@ -808,7 +809,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { // add the suggestion & ensure lookup works. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); assertNotNull(mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail( scanDetail)); @@ -834,7 +835,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); // Create a scan result corresponding to a different network. @@ -866,7 +867,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); // Simulate connecting to the network. @@ -881,8 +882,8 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { verify(mWifiMetrics).incrementNetworkSuggestionApiNumConnectSuccess(); // Verify that the correct broadcast was sent out. - mInorder.verify(mWifiPermissionsUtil) - .enforceCanAccessScanResults(TEST_PACKAGE_1, TEST_UID_1); + mInorder.verify(mWifiPermissionsUtil).enforceCanAccessScanResults(eq(TEST_PACKAGE_1), + eq(TEST_FEATURE), eq(TEST_UID_1), nullable(String.class)); validatePostConnectionBroadcastSent(TEST_PACKAGE_1, networkSuggestion); // Verify no more broadcast were sent out. @@ -907,7 +908,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); // Simulate binder was died. drCaptor.getValue().binderDied(); @@ -925,8 +926,8 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { verify(mWifiMetrics).incrementNetworkSuggestionApiNumConnectFailure(); // Verify no connection failure event was sent out. - mInorder.verify(mWifiPermissionsUtil, never()) - .enforceCanAccessScanResults(TEST_PACKAGE_1, TEST_UID_1); + mInorder.verify(mWifiPermissionsUtil, never()).enforceCanAccessScanResults( + eq(TEST_PACKAGE_1), eq(TEST_FEATURE), eq(TEST_UID_1), nullable(String.class)); verify(mListener, never()).onConnectionStatus(any(), anyInt()); // Verify no more broadcast were sent out. @@ -956,7 +957,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); WifiConfiguration connectNetwork = new WifiConfiguration(networkSuggestion.wifiConfiguration); @@ -968,8 +969,8 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { WifiMetrics.ConnectionEvent.FAILURE_DHCP, connectNetwork, TEST_BSSID); // Verify right callback were sent out. - mInorder.verify(mWifiPermissionsUtil) - .enforceCanAccessScanResults(TEST_PACKAGE_1, TEST_UID_1); + mInorder.verify(mWifiPermissionsUtil).enforceCanAccessScanResults(eq(TEST_PACKAGE_1), + eq(TEST_FEATURE), eq(TEST_UID_1), nullable(String.class)); verify(mListener) .onConnectionStatus(networkSuggestion, WifiManager.STATUS_SUGGESTION_CONNECTION_FAILURE_IP_PROVISIONING); @@ -1007,10 +1008,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_2, - TEST_PACKAGE_2)); + TEST_PACKAGE_2, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_2); @@ -1029,9 +1030,12 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { // Verify that the correct broadcasts were sent out. for (int i = 0; i < 2; i++) { ArgumentCaptor<String> packageNameCaptor = ArgumentCaptor.forClass(String.class); + ArgumentCaptor<String> featureIdCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<Integer> uidCaptor = ArgumentCaptor.forClass(Integer.class); - mInorder.verify(mWifiPermissionsUtil) - .enforceCanAccessScanResults(packageNameCaptor.capture(), uidCaptor.capture()); + mInorder.verify(mWifiPermissionsUtil).enforceCanAccessScanResults( + packageNameCaptor.capture(), featureIdCaptor.capture(), uidCaptor.capture(), + nullable(String.class)); + assertEquals(TEST_FEATURE, featureIdCaptor.getValue()); if (packageNameCaptor.getValue().equals(TEST_PACKAGE_1)) { assertEquals(Integer.valueOf(TEST_UID_1), uidCaptor.getValue()); validatePostConnectionBroadcastSent(TEST_PACKAGE_1, networkSuggestion1); @@ -1075,10 +1079,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_2, - TEST_PACKAGE_2)); + TEST_PACKAGE_2, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_2); WifiConfiguration connectNetwork = @@ -1095,9 +1099,12 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { // Verify that the correct broadcasts were sent out. for (int i = 0; i < 2; i++) { ArgumentCaptor<String> packageNameCaptor = ArgumentCaptor.forClass(String.class); + ArgumentCaptor<String> featureIdCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<Integer> uidCaptor = ArgumentCaptor.forClass(Integer.class); - mInorder.verify(mWifiPermissionsUtil) - .enforceCanAccessScanResults(packageNameCaptor.capture(), uidCaptor.capture()); + mInorder.verify(mWifiPermissionsUtil).enforceCanAccessScanResults( + packageNameCaptor.capture(), featureIdCaptor.capture(), uidCaptor.capture(), + nullable(String.class)); + assertEquals(TEST_FEATURE, featureIdCaptor.getValue()); if (packageNameCaptor.getValue().equals(TEST_PACKAGE_1)) { assertEquals(Integer.valueOf(TEST_UID_1), uidCaptor.getValue()); validatePostConnectionBroadcastSent(TEST_PACKAGE_1, networkSuggestion1); @@ -1142,10 +1149,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_2, - TEST_PACKAGE_2)); + TEST_PACKAGE_2, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_2); @@ -1164,9 +1171,12 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { // Verify that the correct broadcasts were sent out. for (int i = 0; i < 2; i++) { ArgumentCaptor<String> packageNameCaptor = ArgumentCaptor.forClass(String.class); + ArgumentCaptor<String> featureIdCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<Integer> uidCaptor = ArgumentCaptor.forClass(Integer.class); - mInorder.verify(mWifiPermissionsUtil) - .enforceCanAccessScanResults(packageNameCaptor.capture(), uidCaptor.capture()); + mInorder.verify(mWifiPermissionsUtil).enforceCanAccessScanResults( + packageNameCaptor.capture(), featureIdCaptor.capture(), uidCaptor.capture(), + nullable(String.class)); + assertEquals(TEST_FEATURE, featureIdCaptor.getValue()); if (packageNameCaptor.getValue().equals(TEST_PACKAGE_1)) { assertEquals(Integer.valueOf(TEST_UID_1), uidCaptor.getValue()); validatePostConnectionBroadcastSent(TEST_PACKAGE_1, networkSuggestion1); @@ -1201,7 +1211,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); verify(mWifiPermissionsUtil, times(2)) .checkNetworkCarrierProvisioningPermission(TEST_UID_1); assertFalse(mWifiNetworkSuggestionsManager.hasUserApprovedForApp(TEST_PACKAGE_1)); @@ -1218,7 +1228,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { // Verify no broadcast was sent out. mInorder.verify(mWifiPermissionsUtil, never()).enforceCanAccessScanResults( - anyString(), anyInt()); + anyString(), nullable(String.class), anyInt(), nullable(String.class)); mInorder.verify(mContext, never()).sendBroadcastAsUser( any(), any()); } @@ -1241,7 +1251,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); verify(mWifiPermissionsUtil, times(2)) .checkNetworkCarrierProvisioningPermission(TEST_UID_1); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); @@ -1258,7 +1268,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { // Verify no broadcast was sent out. mInorder.verify(mWifiPermissionsUtil, never()).enforceCanAccessScanResults( - anyString(), anyInt()); + anyString(), nullable(String.class), anyInt(), nullable(String.class)); mInorder.verify(mContext, never()).sendBroadcastAsUser( any(), any()); } @@ -1281,13 +1291,13 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); verify(mWifiPermissionsUtil, times(2)) .checkNetworkCarrierProvisioningPermission(TEST_UID_1); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); - doThrow(new SecurityException()) - .when(mWifiPermissionsUtil).enforceCanAccessScanResults(TEST_PACKAGE_1, TEST_UID_1); + doThrow(new SecurityException()).when(mWifiPermissionsUtil).enforceCanAccessScanResults( + eq(TEST_PACKAGE_1), eq(TEST_FEATURE), eq(TEST_UID_1), nullable(String.class)); WifiConfiguration connectNetwork = new WifiConfiguration(networkSuggestion.wifiConfiguration); @@ -1299,8 +1309,8 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( WifiMetrics.ConnectionEvent.FAILURE_NONE, connectNetwork, TEST_BSSID); - mInorder.verify(mWifiPermissionsUtil) - .enforceCanAccessScanResults(TEST_PACKAGE_1, TEST_UID_1); + mInorder.verify(mWifiPermissionsUtil).enforceCanAccessScanResults(eq(TEST_PACKAGE_1), + eq(TEST_FEATURE), eq(TEST_UID_1), nullable(String.class)); // Verify no broadcast was sent out. mInorder.verifyNoMoreInteractions(); @@ -1321,7 +1331,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); // Verify config store interactions. verify(mWifiConfigManager).saveToStore(true); @@ -1363,7 +1373,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.remove(networkSuggestionList, TEST_UID_1, TEST_PACKAGE_1)); @@ -1395,7 +1405,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { passpointConfiguration.setHomeSp(homeSp); WifiConfiguration dummyConfiguration = new WifiConfiguration(); dummyConfiguration.FQDN = TEST_FQDN; - PerAppInfo appInfo = new PerAppInfo(TEST_PACKAGE_1); + PerAppInfo appInfo = new PerAppInfo(TEST_PACKAGE_1, TEST_FEATURE); appInfo.hasUserApproved = true; WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, @@ -1449,7 +1459,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testNetworkSuggestionsConfigStoreLoadAfterUserSwitch() { // Read the store initially. - PerAppInfo appInfo1 = new PerAppInfo(TEST_PACKAGE_1); + PerAppInfo appInfo1 = new PerAppInfo(TEST_PACKAGE_1, TEST_FEATURE); appInfo1.hasUserApproved = true; WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, @@ -1463,7 +1473,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { // Now simulate user switch. mDataSource.reset(); - PerAppInfo appInfo2 = new PerAppInfo(TEST_PACKAGE_2); + PerAppInfo appInfo2 = new PerAppInfo(TEST_PACKAGE_2, TEST_FEATURE); appInfo2.hasUserApproved = true; WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, @@ -1513,7 +1523,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); // Simulate connecting to the network. WifiConfiguration connectNetwork = @@ -1548,7 +1558,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); // Simulate connecting to the network. WifiConfiguration connectNetwork = @@ -1592,10 +1602,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_2, - TEST_PACKAGE_2)); + TEST_PACKAGE_2, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_2); @@ -1633,7 +1643,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); // Simulate connecting to some other network. @@ -1661,7 +1671,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); WifiConfiguration connectNetwork = new WifiConfiguration(networkSuggestion.wifiConfiguration); @@ -1709,14 +1719,14 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { // Watch app-ops changes on first add. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); mInorder.verify(mAppOpsManager).startWatchingMode(eq(OPSTR_CHANGE_WIFI_STATE), eq(TEST_PACKAGE_1), mAppOpChangedListenerCaptor.capture()); // Nothing happens on second add. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); // Now remove first add, nothing happens. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, @@ -1747,7 +1757,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); Set<WifiNetworkSuggestion> allNetworkSuggestions = mWifiNetworkSuggestionsManager.getAllNetworkSuggestions(); @@ -1788,7 +1798,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { */ @Test public void testAppOpsChangeAfterConfigStoreLoad() { - PerAppInfo appInfo = new PerAppInfo(TEST_PACKAGE_1); + PerAppInfo appInfo = new PerAppInfo(TEST_PACKAGE_1, TEST_FEATURE); WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); @@ -1846,7 +1856,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); Set<WifiNetworkSuggestion> allNetworkSuggestions = mWifiNetworkSuggestionsManager.getAllNetworkSuggestions(); @@ -1897,10 +1907,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_2, - TEST_PACKAGE_2)); + TEST_PACKAGE_2, TEST_FEATURE)); // Remove all suggestions from TEST_PACKAGE_1 & TEST_PACKAGE_2, we should continue to track. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, @@ -1963,10 +1973,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_2, - TEST_PACKAGE_2)); + TEST_PACKAGE_2, TEST_FEATURE)); // Remove all suggestions from TEST_PACKAGE_1 & TEST_PACKAGE_2, we should continue to track. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, @@ -2011,7 +2021,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); validateUserApprovalNotification(TEST_APP_NAME_1); // Simulate user dismissal notification. sendBroadcastForUserAction( @@ -2052,7 +2062,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); validateUserApprovalNotification(TEST_APP_NAME_1); // Simulate user dismissal notification. @@ -2098,7 +2108,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); verify(mAppOpsManager).startWatchingMode(eq(OPSTR_CHANGE_WIFI_STATE), eq(TEST_PACKAGE_1), mAppOpChangedListenerCaptor.capture()); validateUserApprovalNotification(TEST_APP_NAME_1); @@ -2143,7 +2153,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { // Assuming the user re-enabled the app again & added the same suggestions back. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); // We should resend the notification when the network is again found in scan results. mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail( @@ -2167,7 +2177,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); // Simulate finding the network in scan results. mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail( @@ -2216,7 +2226,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { networkSuggestionList.add(networkSuggestion4); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); storedNetworkSuggestionListPerApp = mWifiNetworkSuggestionsManager.get(TEST_PACKAGE_1); @@ -2258,10 +2268,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_2, - TEST_PACKAGE_2)); + TEST_PACKAGE_2, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(false, TEST_PACKAGE_2); List<WifiScanner.ScanSettings.HiddenNetwork> hiddenNetworks = @@ -2285,7 +2295,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); validateUserApprovalNotification(TEST_APP_NAME_1); // Simulate user clicking on allow in the notification. @@ -2320,7 +2330,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { }}; assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); verify(mAppOpsManager).startWatchingMode(eq(OPSTR_CHANGE_WIFI_STATE), eq(TEST_PACKAGE_1), mAppOpChangedListenerCaptor.capture()); validateUserApprovalNotification(TEST_APP_NAME_1); @@ -2354,7 +2364,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { // Assuming the user re-enabled the app again & added the same suggestions back. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); validateUserApprovalNotification(TEST_APP_NAME_1); verifyNoMoreInteractions(mNotificationManger); } @@ -2386,7 +2396,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { .thenReturn(true); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, - TEST_PACKAGE_1)); + TEST_PACKAGE_1, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); @@ -2402,8 +2412,8 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { verify(mWifiMetrics).incrementNetworkSuggestionApiNumConnectSuccess(); // Verify that the correct broadcast was sent out. - mInorder.verify(mWifiPermissionsUtil) - .enforceCanAccessScanResults(TEST_PACKAGE_1, TEST_UID_1); + mInorder.verify(mWifiPermissionsUtil).enforceCanAccessScanResults(eq(TEST_PACKAGE_1), + eq(TEST_FEATURE), eq(TEST_UID_1), nullable(String.class)); validatePostConnectionBroadcastSent(TEST_PACKAGE_1, networkSuggestion); // Verify no more broadcast were sent out. @@ -2482,7 +2492,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { .thenReturn(true); int status = mWifiNetworkSuggestionsManager - .add(networkSuggestionList, TEST_UID_1, TEST_APP_NAME_1); + .add(networkSuggestionList, TEST_UID_1, TEST_APP_NAME_1, TEST_FEATURE); assertEquals(status, WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS); @@ -2501,7 +2511,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { .thenReturn(false); int status = mWifiNetworkSuggestionsManager - .add(networkSuggestionList, TEST_UID_1, TEST_APP_NAME_1); + .add(networkSuggestionList, TEST_UID_1, TEST_APP_NAME_1, TEST_FEATURE); assertEquals(status, WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_APP_DISALLOWED); @@ -2519,7 +2529,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { .thenReturn(false); int status = mWifiNetworkSuggestionsManager - .add(networkSuggestionList, TEST_UID_1, TEST_APP_NAME_1); + .add(networkSuggestionList, TEST_UID_1, TEST_APP_NAME_1, TEST_FEATURE); assertEquals(status, WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS); } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index ddf6819e3..f69df49cc 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -46,6 +46,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.AdditionalAnswers.returnsSecondArg; import static org.mockito.ArgumentMatchers.notNull; +import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; @@ -172,6 +173,7 @@ public class WifiServiceImplTest extends WifiBaseTest { private static final int DEFAULT_VERBOSE_LOGGING = 0; private static final String ANDROID_SYSTEM_PACKAGE = "android"; private static final String TEST_PACKAGE_NAME = "TestPackage"; + private static final String TEST_FEATURE_ID = "TestFeature"; private static final String SYSUI_PACKAGE_NAME = "com.android.systemui"; private static final int TEST_PID = 6789; private static final int TEST_PID2 = 9876; @@ -346,6 +348,7 @@ public class WifiServiceImplTest extends WifiBaseTest { // Create an OSU provider that can be provisioned via an open OSU AP mOsuProvider = PasspointProvisioningTestUtil.generateOsuProvider(true); when(mContext.getOpPackageName()).thenReturn(TEST_PACKAGE_NAME); + when(mContext.getFeatureId()).thenReturn(TEST_FEATURE_ID); when(mContext.checkPermission(eq(android.Manifest.permission.NETWORK_SETTINGS), anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_DENIED); when(mContext.checkPermission(eq(android.Manifest.permission.NETWORK_SETUP_WIZARD), @@ -438,7 +441,8 @@ public class WifiServiceImplTest extends WifiBaseTest { @Test public void testRemoveNetworkFailureAppBelowQSdk() { doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager) - .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); + .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME, + TEST_FEATURE_ID, null); when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(true); when(mWifiConfigManager.removeNetwork(anyInt(), anyInt(), anyString())).thenReturn(false); @@ -1174,7 +1178,7 @@ public class WifiServiceImplTest extends WifiBaseTest { doReturn(AppOpsManager.MODE_IGNORED).when(mAppOpsManager) .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), SCAN_PACKAGE_NAME); mLooper.startAutoDispatch(); - assertFalse(mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME)); + assertFalse(mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME, TEST_FEATURE_ID)); mLooper.stopAutoDispatchAndIgnoreExceptions(); verify(mScanRequestProxy, never()).startScan(Process.myUid(), SCAN_PACKAGE_NAME); } @@ -1185,9 +1189,10 @@ public class WifiServiceImplTest extends WifiBaseTest { @Test public void testStartScanFailureInCanAccessScanResultsPermission() { doThrow(new SecurityException()).when(mWifiPermissionsUtil) - .enforceCanAccessScanResults(SCAN_PACKAGE_NAME, Process.myUid()); + .enforceCanAccessScanResults(SCAN_PACKAGE_NAME, TEST_FEATURE_ID, Process.myUid(), + null); mLooper.startAutoDispatch(); - assertFalse(mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME)); + assertFalse(mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME, TEST_FEATURE_ID)); mLooper.stopAutoDispatchAndIgnoreExceptions(); verify(mScanRequestProxy, never()).startScan(Process.myUid(), SCAN_PACKAGE_NAME); } @@ -1200,7 +1205,7 @@ public class WifiServiceImplTest extends WifiBaseTest { mWifiServiceImpl = makeWifiServiceImplWithMockRunnerWhichTimesOut(); mLooper.startAutoDispatch(); - assertFalse(mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME)); + assertFalse(mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME, TEST_FEATURE_ID)); mLooper.stopAutoDispatchAndIgnoreExceptions(); verify(mScanRequestProxy, never()).startScan(anyInt(), eq(SCAN_PACKAGE_NAME)); } @@ -1213,7 +1218,7 @@ public class WifiServiceImplTest extends WifiBaseTest { when(mScanRequestProxy.startScan(anyInt(), anyString())).thenReturn(false); mLooper.startAutoDispatch(); - assertFalse(mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME)); + assertFalse(mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME, TEST_FEATURE_ID)); mLooper.stopAutoDispatchAndIgnoreExceptions(); verify(mScanRequestProxy).startScan(Binder.getCallingUid(), SCAN_PACKAGE_NAME); } @@ -1241,9 +1246,9 @@ public class WifiServiceImplTest extends WifiBaseTest { setupForGetConnectionInfo(); doThrow(new SecurityException()).when(mWifiPermissionsUtil).enforceCanAccessScanResults( - anyString(), anyInt()); + anyString(), nullable(String.class), anyInt(), nullable(String.class)); - WifiInfo connectionInfo = mWifiServiceImpl.getConnectionInfo(TEST_PACKAGE); + WifiInfo connectionInfo = mWifiServiceImpl.getConnectionInfo(TEST_PACKAGE, TEST_FEATURE_ID); assertEquals(WifiSsid.NONE, connectionInfo.getSSID()); assertEquals(WifiInfo.DEFAULT_MAC_ADDRESS, connectionInfo.getBSSID()); @@ -1259,9 +1264,9 @@ public class WifiServiceImplTest extends WifiBaseTest { setupForGetConnectionInfo(); doThrow(new SecurityException()).when(mWifiPermissionsUtil).enforceCanAccessScanResults( - anyString(), anyInt()); + anyString(), nullable(String.class), anyInt(), nullable(String.class)); - WifiInfo connectionInfo = mWifiServiceImpl.getConnectionInfo(TEST_PACKAGE); + WifiInfo connectionInfo = mWifiServiceImpl.getConnectionInfo(TEST_PACKAGE, TEST_FEATURE_ID); assertEquals(WifiSsid.NONE, connectionInfo.getSSID()); assertEquals(WifiInfo.DEFAULT_MAC_ADDRESS, connectionInfo.getBSSID()); @@ -1276,7 +1281,7 @@ public class WifiServiceImplTest extends WifiBaseTest { public void testConnectedIdsAreVisibleFromPermittedApp() throws Exception { setupForGetConnectionInfo(); - WifiInfo connectionInfo = mWifiServiceImpl.getConnectionInfo(TEST_PACKAGE); + WifiInfo connectionInfo = mWifiServiceImpl.getConnectionInfo(TEST_PACKAGE, TEST_FEATURE_ID); assertEquals(TEST_SSID_WITH_QUOTES, connectionInfo.getSSID()); assertEquals(TEST_BSSID, connectionInfo.getBSSID()); @@ -1297,7 +1302,7 @@ public class WifiServiceImplTest extends WifiBaseTest { TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS); ParceledListSlice<WifiConfiguration> configs = - mWifiServiceImpl.getConfiguredNetworks(TEST_PACKAGE); + mWifiServiceImpl.getConfiguredNetworks(TEST_PACKAGE, TEST_FEATURE_ID); assertEquals(0, configs.getList().size()); } @@ -1312,10 +1317,10 @@ public class WifiServiceImplTest extends WifiBaseTest { .thenReturn(TEST_WIFI_CONFIGURATION_LIST); doThrow(new SecurityException()).when(mWifiPermissionsUtil).enforceCanAccessScanResults( - anyString(), anyInt()); + anyString(), nullable(String.class), anyInt(), nullable(String.class)); ParceledListSlice<WifiConfiguration> configs = - mWifiServiceImpl.getConfiguredNetworks(TEST_PACKAGE); + mWifiServiceImpl.getConfiguredNetworks(TEST_PACKAGE, TEST_FEATURE_ID); assertEquals(0, configs.getList().size()); @@ -1337,7 +1342,7 @@ public class WifiServiceImplTest extends WifiBaseTest { mLooper.startAutoDispatch(); ParceledListSlice<WifiConfiguration> configs = - mWifiServiceImpl.getConfiguredNetworks(TEST_PACKAGE); + mWifiServiceImpl.getConfiguredNetworks(TEST_PACKAGE, TEST_FEATURE_ID); mLooper.stopAutoDispatchAndIgnoreExceptions(); verify(mWifiConfigManager).getSavedNetworks(eq(Process.WIFI_UID)); @@ -1356,11 +1361,11 @@ public class WifiServiceImplTest extends WifiBaseTest { .thenReturn(TEST_WIFI_CONFIGURATION_LIST); doThrow(new SecurityException()).when(mWifiPermissionsUtil).enforceCanAccessScanResults( - anyString(), anyInt()); + anyString(), nullable(String.class), anyInt(), nullable(String.class)); mLooper.startAutoDispatch(); ParceledListSlice<WifiConfiguration> configs = - mWifiServiceImpl.getPrivilegedConfiguredNetworks(TEST_PACKAGE); + mWifiServiceImpl.getPrivilegedConfiguredNetworks(TEST_PACKAGE, TEST_FEATURE_ID); mLooper.stopAutoDispatchAndIgnoreExceptions(); assertNull(configs); @@ -1376,11 +1381,11 @@ public class WifiServiceImplTest extends WifiBaseTest { .thenReturn(TEST_WIFI_CONFIGURATION_LIST); doThrow(new SecurityException()).when(mWifiPermissionsUtil).enforceCanAccessScanResults( - anyString(), anyInt()); + anyString(), nullable(String.class), anyInt(), nullable(String.class)); mLooper.startAutoDispatch(); ParceledListSlice<WifiConfiguration> configs = - mWifiServiceImpl.getPrivilegedConfiguredNetworks(TEST_PACKAGE); + mWifiServiceImpl.getPrivilegedConfiguredNetworks(TEST_PACKAGE, TEST_FEATURE_ID); mLooper.stopAutoDispatchAndIgnoreExceptions(); assertNull(configs); @@ -1397,7 +1402,7 @@ public class WifiServiceImplTest extends WifiBaseTest { mLooper.startAutoDispatch(); ParceledListSlice<WifiConfiguration> configs = - mWifiServiceImpl.getPrivilegedConfiguredNetworks(TEST_PACKAGE); + mWifiServiceImpl.getPrivilegedConfiguredNetworks(TEST_PACKAGE, TEST_FEATURE_ID); mLooper.stopAutoDispatchAndIgnoreExceptions(); WifiConfigurationTestUtil.assertConfigurationsEqualForBackup( @@ -1417,8 +1422,10 @@ public class WifiServiceImplTest extends WifiBaseTest { when(mScanRequestProxy.getScanResults()).thenReturn(scanResultList); String packageName = "test.com"; + String featureId = "test.com.featureId"; mLooper.startAutoDispatch(); - List<ScanResult> retrievedScanResultList = mWifiServiceImpl.getScanResults(packageName); + List<ScanResult> retrievedScanResultList = mWifiServiceImpl.getScanResults(packageName, + featureId); mLooper.stopAutoDispatchAndIgnoreExceptions(); verify(mScanRequestProxy).getScanResults(); @@ -1441,8 +1448,10 @@ public class WifiServiceImplTest extends WifiBaseTest { when(mScanRequestProxy.getScanResults()).thenReturn(scanResultList); String packageName = "test.com"; + String featureId = "test.com.featureId"; mLooper.startAutoDispatch(); - List<ScanResult> retrievedScanResultList = mWifiServiceImpl.getScanResults(packageName); + List<ScanResult> retrievedScanResultList = mWifiServiceImpl.getScanResults(packageName, + featureId); mLooper.stopAutoDispatchAndIgnoreExceptions(); verify(mScanRequestProxy, never()).getScanResults(); @@ -1459,7 +1468,8 @@ public class WifiServiceImplTest extends WifiBaseTest { private void registerLOHSRequestFull() { setupLohsPermissions(); - int result = mWifiServiceImpl.startLocalOnlyHotspot(mLohsCallback, TEST_PACKAGE_NAME, null); + int result = mWifiServiceImpl.startLocalOnlyHotspot(mLohsCallback, TEST_PACKAGE_NAME, + TEST_FEATURE_ID, null); assertEquals(LocalOnlyHotspotCallback.REQUEST_REGISTERED, result); verifyCheckChangePermission(TEST_PACKAGE_NAME); } @@ -1493,6 +1503,7 @@ public class WifiServiceImplTest extends WifiBaseTest { public void testStartLocalOnlyHotspotThrowsSecurityExceptionWithoutLocationPermission() { doThrow(new SecurityException()) .when(mWifiPermissionsUtil).enforceLocationPermission(eq(TEST_PACKAGE_NAME), + eq(TEST_FEATURE_ID), anyInt()); mWifiServiceImpl.startLocalOnlyHotspot(mLohsCallback, TEST_PACKAGE_NAME); } @@ -1718,7 +1729,8 @@ public class WifiServiceImplTest extends WifiBaseTest { // set up basic permissions, but not NETWORK_SETUP_WIZARD setupLohsPermissions(); setupWardenForCustomLohs(); - mWifiServiceImpl.startLocalOnlyHotspot(mLohsCallback, TEST_PACKAGE_NAME, customConfig); + mWifiServiceImpl.startLocalOnlyHotspot(mLohsCallback, TEST_PACKAGE_NAME, TEST_FEATURE_ID, + customConfig); } private static void nopDeathCallback(LocalOnlyHotspotRequestInfo requestor) { @@ -1735,9 +1747,8 @@ public class WifiServiceImplTest extends WifiBaseTest { setupForCustomLohs(); mWifiServiceImpl.registerLOHSForTest(mPid, new LocalOnlyHotspotRequestInfo( sharedCallback, WifiServiceImplTest::nopDeathCallback, null)); - assertThat(mWifiServiceImpl.startLocalOnlyHotspot( - exclusiveCallback, TEST_PACKAGE_NAME, exclusiveConfig)) - .isEqualTo(ERROR_GENERIC); + assertThat(mWifiServiceImpl.startLocalOnlyHotspot(exclusiveCallback, TEST_PACKAGE_NAME, + TEST_FEATURE_ID, exclusiveConfig)).isEqualTo(ERROR_GENERIC); mLooper.dispatchAll(); assertThat(sharedCallback.mIsStarted).isTrue(); @@ -1755,9 +1766,8 @@ public class WifiServiceImplTest extends WifiBaseTest { setupForCustomLohs(); mWifiServiceImpl.registerLOHSForTest(mPid, new LocalOnlyHotspotRequestInfo( exclusiveCallback, WifiServiceImplTest::nopDeathCallback, exclusiveConfig)); - assertThat(mWifiServiceImpl.startLocalOnlyHotspot( - sharedCallback, TEST_PACKAGE_NAME, null)) - .isEqualTo(ERROR_GENERIC); + assertThat(mWifiServiceImpl.startLocalOnlyHotspot(sharedCallback, TEST_PACKAGE_NAME, + TEST_FEATURE_ID, null)).isEqualTo(ERROR_GENERIC); mLooper.dispatchAll(); assertThat(exclusiveCallback.mIsStarted).isTrue(); @@ -1773,8 +1783,9 @@ public class WifiServiceImplTest extends WifiBaseTest { FakeLohsCallback callback = new FakeLohsCallback(); setupForCustomLohs(); - assertThat(mWifiServiceImpl.startLocalOnlyHotspot(callback, TEST_PACKAGE_NAME, config)) - .isEqualTo(REQUEST_REGISTERED); + assertThat( + mWifiServiceImpl.startLocalOnlyHotspot(callback, TEST_PACKAGE_NAME, TEST_FEATURE_ID, + config)).isEqualTo(REQUEST_REGISTERED); mLooper.dispatchAll(); assertThat(callback.mIsStarted).isTrue(); @@ -1791,8 +1802,9 @@ public class WifiServiceImplTest extends WifiBaseTest { FakeLohsCallback callback = new FakeLohsCallback(); setupForCustomLohs(); - assertThat(mWifiServiceImpl.startLocalOnlyHotspot(callback, TEST_PACKAGE_NAME, config)) - .isEqualTo(REQUEST_REGISTERED); + assertThat( + mWifiServiceImpl.startLocalOnlyHotspot(callback, TEST_PACKAGE_NAME, TEST_FEATURE_ID, + config)).isEqualTo(REQUEST_REGISTERED); mLooper.dispatchAll(); assertThat(callback.mIsStarted).isTrue(); @@ -1809,8 +1821,9 @@ public class WifiServiceImplTest extends WifiBaseTest { FakeLohsCallback callback = new FakeLohsCallback(); setupForCustomLohs(); - assertThat(mWifiServiceImpl.startLocalOnlyHotspot(callback, TEST_PACKAGE_NAME, config)) - .isEqualTo(REQUEST_REGISTERED); + assertThat( + mWifiServiceImpl.startLocalOnlyHotspot(callback, TEST_PACKAGE_NAME, TEST_FEATURE_ID, + config)).isEqualTo(REQUEST_REGISTERED); mLooper.dispatchAll(); assertThat(callback.mIsStarted).isTrue(); @@ -1825,8 +1838,9 @@ public class WifiServiceImplTest extends WifiBaseTest { FakeLohsCallback callback = new FakeLohsCallback(); setupForCustomLohs(); - assertThat(mWifiServiceImpl.startLocalOnlyHotspot(callback, TEST_PACKAGE_NAME, config)) - .isEqualTo(REQUEST_REGISTERED); + assertThat( + mWifiServiceImpl.startLocalOnlyHotspot(callback, TEST_PACKAGE_NAME, TEST_FEATURE_ID, + config)).isEqualTo(REQUEST_REGISTERED); mLooper.dispatchAll(); assertThat(callback.mIsStarted).isTrue(); @@ -3016,7 +3030,7 @@ public class WifiServiceImplTest extends WifiBaseTest { TestUtil.sendIdleModeChanged(mBroadcastReceiverCaptor.getValue(), mContext); // Send a scan request while the device is idle. - assertFalse(mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME)); + assertFalse(mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME, TEST_FEATURE_ID)); // No scans must be made yet as the device is idle. verify(mScanRequestProxy, never()).startScan(Process.myUid(), SCAN_PACKAGE_NAME); @@ -3035,7 +3049,7 @@ public class WifiServiceImplTest extends WifiBaseTest { // Send another scan request. The device is not idle anymore, so it must be executed // immediately. mLooper.startAutoDispatch(); - assertTrue(mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME)); + assertTrue(mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME, TEST_FEATURE_ID)); mLooper.stopAutoDispatchAndIgnoreExceptions(); verify(mScanRequestProxy).startScan(Process.myUid(), SCAN_PACKAGE_NAME); } @@ -3798,22 +3812,25 @@ public class WifiServiceImplTest extends WifiBaseTest { */ @Test public void testAddNetworkSuggestions() { - when(mWifiNetworkSuggestionsManager.add(any(), anyInt(), anyString())) - .thenReturn(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS); + when(mWifiNetworkSuggestionsManager.add(any(), anyInt(), anyString(), + nullable(String.class))).thenReturn(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS); mLooper.startAutoDispatch(); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, - mWifiServiceImpl.addNetworkSuggestions(mock(List.class), TEST_PACKAGE_NAME)); + mWifiServiceImpl.addNetworkSuggestions(mock(List.class), TEST_PACKAGE_NAME, + TEST_FEATURE_ID)); mLooper.stopAutoDispatchAndIgnoreExceptions(); - when(mWifiNetworkSuggestionsManager.add(any(), anyInt(), anyString())) - .thenReturn(WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE); + when(mWifiNetworkSuggestionsManager.add(any(), anyInt(), anyString(), + nullable(String.class))).thenReturn( + WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE); mLooper.startAutoDispatch(); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE, - mWifiServiceImpl.addNetworkSuggestions(mock(List.class), TEST_PACKAGE_NAME)); + mWifiServiceImpl.addNetworkSuggestions(mock(List.class), TEST_PACKAGE_NAME, + TEST_FEATURE_ID)); mLooper.stopAutoDispatchAndIgnoreExceptions(); verify(mWifiNetworkSuggestionsManager, times(2)).add( - any(), eq(Binder.getCallingUid()), eq(TEST_PACKAGE_NAME)); + any(), eq(Binder.getCallingUid()), eq(TEST_PACKAGE_NAME), eq(TEST_FEATURE_ID)); } /** @@ -3826,11 +3843,12 @@ public class WifiServiceImplTest extends WifiBaseTest { mLooper.startAutoDispatch(); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_INTERNAL, - mWifiServiceImpl.addNetworkSuggestions(mock(List.class), TEST_PACKAGE_NAME)); + mWifiServiceImpl.addNetworkSuggestions(mock(List.class), TEST_PACKAGE_NAME, + TEST_FEATURE_ID)); mLooper.stopAutoDispatchAndIgnoreExceptions(); - verify(mWifiNetworkSuggestionsManager, never()).add( - any(), eq(Binder.getCallingUid()), eq(TEST_PACKAGE_NAME)); + verify(mWifiNetworkSuggestionsManager, never()).add(any(), eq(Binder.getCallingUid()), + eq(TEST_PACKAGE_NAME), eq(TEST_FEATURE_ID)); } /** @@ -4401,7 +4419,8 @@ public class WifiServiceImplTest extends WifiBaseTest { doThrow(new SecurityException()).when(mContext).enforceCallingOrSelfPermission( eq(android.Manifest.permission.ACCESS_WIFI_STATE), eq("WifiService")); mWifiServiceImpl.registerSuggestionConnectionStatusListener(mAppBinder, - mSuggestionConnectionStatusListener, NETWORK_CALLBACK_ID, TEST_PACKAGE_NAME); + mSuggestionConnectionStatusListener, NETWORK_CALLBACK_ID, TEST_PACKAGE_NAME, + TEST_FEATURE_ID); } /** @@ -4410,7 +4429,7 @@ public class WifiServiceImplTest extends WifiBaseTest { @Test(expected = IllegalArgumentException.class) public void testRegisterSuggestionNetworkCallbackWithIllegalArgument() { mWifiServiceImpl.registerSuggestionConnectionStatusListener(mAppBinder, null, - NETWORK_CALLBACK_ID, TEST_PACKAGE_NAME); + NETWORK_CALLBACK_ID, TEST_PACKAGE_NAME, TEST_FEATURE_ID); } /** @@ -4430,7 +4449,8 @@ public class WifiServiceImplTest extends WifiBaseTest { @Test public void testRegisterUnregisterSuggestionNetworkCallback() throws Exception { mWifiServiceImpl.registerSuggestionConnectionStatusListener(mAppBinder, - mSuggestionConnectionStatusListener, NETWORK_CALLBACK_ID, TEST_PACKAGE_NAME); + mSuggestionConnectionStatusListener, NETWORK_CALLBACK_ID, TEST_PACKAGE_NAME, + TEST_FEATURE_ID); mLooper.dispatchAll(); verify(mWifiNetworkSuggestionsManager).registerSuggestionConnectionStatusListener( eq(mAppBinder), eq(mSuggestionConnectionStatusListener), eq(NETWORK_CALLBACK_ID), diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java index b803dd515..a488baf2a 100644 --- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java @@ -1615,7 +1615,7 @@ public class WifiAwareDataPathStateManagerTest extends WifiBaseTest { InOrder inOrderS = inOrder(mockAwareService, mockCallback, mockSessionCallback); mgr.attach(mMockLooperHandler, configRequest, mockCallback, null); - inOrderS.verify(mockAwareService).connect(any(), any(), + inOrderS.verify(mockAwareService).connect(any(), any(), any(), clientProxyCallback.capture(), eq(configRequest), eq(false)); IWifiAwareEventCallback iwaec = clientProxyCallback.getValue(); iwaec.onConnectSuccess(clientId); @@ -1624,13 +1624,13 @@ public class WifiAwareDataPathStateManagerTest extends WifiBaseTest { if (doPublish) { sessionCaptor.getValue().publish(publishConfig, mockSessionCallback, mMockLooperHandler); - inOrderS.verify(mockAwareService).publish(any(), eq(clientId), eq(publishConfig), + inOrderS.verify(mockAwareService).publish(any(), any(), eq(clientId), eq(publishConfig), sessionProxyCallback.capture()); } else { sessionCaptor.getValue().subscribe(subscribeConfig, mockSessionCallback, mMockLooperHandler); - inOrderS.verify(mockAwareService).subscribe(any(), eq(clientId), eq(subscribeConfig), - sessionProxyCallback.capture()); + inOrderS.verify(mockAwareService).subscribe(any(), any(), eq(clientId), + eq(subscribeConfig), sessionProxyCallback.capture()); } sessionProxyCallback.getValue().onSessionStarted(sessionId); mMockLooper.dispatchAll(); @@ -1693,7 +1693,7 @@ public class WifiAwareDataPathStateManagerTest extends WifiBaseTest { AttachCallback mockCallback = mock(AttachCallback.class); mgr.attach(mMockLooperHandler, configRequest, mockCallback, null); - verify(mockAwareService).connect(any(), any(), + verify(mockAwareService).connect(any(), any(), any(), clientProxyCallback.capture(), eq(configRequest), eq(false)); clientProxyCallback.getValue().onConnectSuccess(clientId); mMockLooper.dispatchAll(); @@ -1773,6 +1773,7 @@ public class WifiAwareDataPathStateManagerTest extends WifiBaseTest { throws Exception { final int pid = 2000; final String callingPackage = "com.android.somePackage"; + final String callingFeatureId = "com.android.someFeature"; final ConfigRequest configRequest = new ConfigRequest.Builder().build(); ArgumentCaptor<Short> transactionId = ArgumentCaptor.forClass(Short.class); @@ -1803,9 +1804,8 @@ public class WifiAwareDataPathStateManagerTest extends WifiBaseTest { } // (3) create client - mDut.connect(clientId, Process.myUid(), pid, callingPackage, mMockCallback, - configRequest, - false); + mDut.connect(clientId, Process.myUid(), pid, callingPackage, callingFeatureId, + mMockCallback, configRequest, false); mMockLooper.dispatchAll(); if (startUpSequence) { diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareMetricsTest.java index 65edbbb79..b0db9646e 100644 --- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareMetricsTest.java @@ -239,25 +239,25 @@ public class WifiAwareMetricsTest extends WifiBaseTest { // uid1: session 1 clients.put(10, - new WifiAwareClientState(mMockContext, 10, uid1, 0, null, null, null, false, + new WifiAwareClientState(mMockContext, 10, uid1, 0, null, null, null, null, false, mClock.getElapsedSinceBootMillis(), mWifiPermissionsUtil)); mDut.recordAttachSession(uid1, false, clients); // uid1: session 2 clients.put(11, - new WifiAwareClientState(mMockContext, 11, uid1, 0, null, null, null, false, + new WifiAwareClientState(mMockContext, 11, uid1, 0, null, null, null, null, false, mClock.getElapsedSinceBootMillis(), mWifiPermissionsUtil)); mDut.recordAttachSession(uid1, false, clients); // uid2: session 1 clients.put(12, - new WifiAwareClientState(mMockContext, 12, uid2, 0, null, null, null, false, + new WifiAwareClientState(mMockContext, 12, uid2, 0, null, null, null, null, false, mClock.getElapsedSinceBootMillis(), mWifiPermissionsUtil)); mDut.recordAttachSession(uid2, false, clients); // uid2: session 2 clients.put(13, - new WifiAwareClientState(mMockContext, 13, uid2, 0, null, null, null, true, + new WifiAwareClientState(mMockContext, 13, uid2, 0, null, null, null, null, true, mClock.getElapsedSinceBootMillis(), mWifiPermissionsUtil)); mDut.recordAttachSession(uid2, true, clients); @@ -273,7 +273,7 @@ public class WifiAwareMetricsTest extends WifiBaseTest { // uid2: session 3 clients.put(14, - new WifiAwareClientState(mMockContext, 14, uid2, 0, null, null, null, false, + new WifiAwareClientState(mMockContext, 14, uid2, 0, null, null, null, null, false, mClock.getElapsedSinceBootMillis(), mWifiPermissionsUtil)); mDut.recordAttachSession(uid2, false, clients); @@ -317,11 +317,11 @@ public class WifiAwareMetricsTest extends WifiBaseTest { setTime(5); WifiAwareClientState client1 = new WifiAwareClientState(mMockContext, 10, uid1, 0, null, - null, null, false, 0, mWifiPermissionsUtil); + null, null, null, false, 0, mWifiPermissionsUtil); WifiAwareClientState client2 = new WifiAwareClientState(mMockContext, 11, uid2, 0, null, - null, null, false, 0, mWifiPermissionsUtil); + null, null, null, false, 0, mWifiPermissionsUtil); WifiAwareClientState client3 = new WifiAwareClientState(mMockContext, 12, uid3, 0, null, - null, null, false, 0, mWifiPermissionsUtil); + null, null, null, false, 0, mWifiPermissionsUtil); clients.put(10, client1); clients.put(11, client2); clients.put(12, client3); diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java index 95b7b0b14..1dd3ff8a7 100644 --- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java @@ -78,6 +78,7 @@ public class WifiAwareServiceImplTest extends WifiBaseTest { private WifiAwareServiceImplSpy mDut; private int mDefaultUid = 1500; private String mPackageName = "some.package"; + private String mFeatureId = "some.feature"; private TestLooper mMockLooper; @Mock @@ -182,12 +183,13 @@ public class WifiAwareServiceImplTest extends WifiBaseTest { public void testConnectWithConfig() { ConfigRequest configRequest = new ConfigRequest.Builder().setMasterPreference(55).build(); String callingPackage = "com.google.somePackage"; + String callingFeatureId = "com.google.someFeature"; - mDut.connect(mBinderMock, callingPackage, mCallbackMock, + mDut.connect(mBinderMock, callingPackage, callingFeatureId, mCallbackMock, configRequest, false); - verify(mAwareStateManagerMock).connect(anyInt(), anyInt(), anyInt(), - eq(callingPackage), eq(mCallbackMock), eq(configRequest), eq(false)); + verify(mAwareStateManagerMock).connect(anyInt(), anyInt(), anyInt(), eq(callingPackage), + eq(callingFeatureId), eq(mCallbackMock), eq(configRequest), eq(false)); } /** @@ -257,7 +259,7 @@ public class WifiAwareServiceImplTest extends WifiBaseTest { PublishConfig publishConfig = new PublishConfig.Builder().setServiceName("valid.value") .build(); - mDut.publish(mPackageName, clientId, publishConfig, mSessionCallbackMock); + mDut.publish(mPackageName, mFeatureId, clientId, publishConfig, mSessionCallbackMock); verify(mAwareStateManagerMock).publish(clientId, publishConfig, mSessionCallbackMock); assertTrue("SecurityException for invalid access from wrong UID thrown", failsAsExpected); @@ -277,7 +279,7 @@ public class WifiAwareServiceImplTest extends WifiBaseTest { IWifiAwareDiscoverySessionCallback mockCallback = mock( IWifiAwareDiscoverySessionCallback.class); - mDut.publish(mPackageName, clientId, publishConfig, mockCallback); + mDut.publish(mPackageName, mFeatureId, clientId, publishConfig, mockCallback); } /** @@ -294,7 +296,7 @@ public class WifiAwareServiceImplTest extends WifiBaseTest { IWifiAwareDiscoverySessionCallback mockCallback = mock( IWifiAwareDiscoverySessionCallback.class); - mDut.subscribe(mPackageName, clientId, subscribeConfig, mockCallback); + mDut.subscribe(mPackageName, mFeatureId, clientId, subscribeConfig, mockCallback); } @@ -326,9 +328,9 @@ public class WifiAwareServiceImplTest extends WifiBaseTest { int prevId = 0; for (int i = 0; i < loopCount; ++i) { - mDut.connect(mBinderMock, "", mCallbackMock, null, false); + mDut.connect(mBinderMock, "", "", mCallbackMock, null, false); inOrder.verify(mAwareStateManagerMock).connect(clientIdCaptor.capture(), anyInt(), - anyInt(), any(), eq(mCallbackMock), any(), eq(false)); + anyInt(), any(), any(), eq(mCallbackMock), any(), eq(false)); int id = clientIdCaptor.getValue(); if (i != 0) { assertTrue("Client ID incrementing", id > prevId); @@ -361,7 +363,7 @@ public class WifiAwareServiceImplTest extends WifiBaseTest { IWifiAwareDiscoverySessionCallback mockCallback = mock( IWifiAwareDiscoverySessionCallback.class); - mDut.publish(mPackageName, clientId, publishConfig, mockCallback); + mDut.publish(mPackageName, mFeatureId, clientId, publishConfig, mockCallback); verify(mAwareStateManagerMock).publish(clientId, publishConfig, mockCallback); } @@ -456,7 +458,7 @@ public class WifiAwareServiceImplTest extends WifiBaseTest { IWifiAwareDiscoverySessionCallback mockCallback = mock( IWifiAwareDiscoverySessionCallback.class); - mDut.subscribe(mPackageName, clientId, subscribeConfig, mockCallback); + mDut.subscribe(mPackageName, mFeatureId, clientId, subscribeConfig, mockCallback); verify(mAwareStateManagerMock).subscribe(clientId, subscribeConfig, mockCallback); } @@ -642,7 +644,7 @@ public class WifiAwareServiceImplTest extends WifiBaseTest { IWifiAwareDiscoverySessionCallback mockCallback = mock( IWifiAwareDiscoverySessionCallback.class); - mDut.publish(mPackageName, clientId, publishConfig, mockCallback); + mDut.publish(mPackageName, mFeatureId, clientId, publishConfig, mockCallback); verify(mAwareStateManagerMock).publish(clientId, publishConfig, mockCallback); } @@ -658,20 +660,21 @@ public class WifiAwareServiceImplTest extends WifiBaseTest { IWifiAwareDiscoverySessionCallback mockCallback = mock( IWifiAwareDiscoverySessionCallback.class); - mDut.subscribe(mPackageName, clientId, subscribeConfig, mockCallback); + mDut.subscribe(mPackageName, mFeatureId, clientId, subscribeConfig, mockCallback); verify(mAwareStateManagerMock).subscribe(clientId, subscribeConfig, mockCallback); } private int doConnect() { String callingPackage = "com.google.somePackage"; + String callingFeatureId = "com.google.someFeature"; - mDut.connect(mBinderMock, callingPackage, mCallbackMock, null, false); + mDut.connect(mBinderMock, callingPackage, callingFeatureId, mCallbackMock, null, false); ArgumentCaptor<Integer> clientId = ArgumentCaptor.forClass(Integer.class); verify(mAwareStateManagerMock).connect(clientId.capture(), anyInt(), anyInt(), - eq(callingPackage), eq(mCallbackMock), eq(new ConfigRequest.Builder().build()), - eq(false)); + eq(callingPackage), eq(callingFeatureId), eq(mCallbackMock), + eq(new ConfigRequest.Builder().build()), eq(false)); return clientId.getValue(); } diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java index d5948282d..5522d1918 100644 --- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java @@ -30,7 +30,6 @@ import static org.mockito.ArgumentMatchers.anyByte; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyShort; -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.inOrder; @@ -235,6 +234,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int pid1 = 2000; final int pid2 = 2001; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final String serviceName = "some-service-name"; final byte subscribeId1 = 15; final byte subscribeId2 = 16; @@ -268,7 +268,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (1) connect 2 clients - mDut.connect(clientId1, uid1, pid1, callingPackage, mockCallback1, configRequest, false); + mDut.connect(clientId1, uid1, pid1, callingPackage, callingFeature, mockCallback1, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -276,7 +277,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); inOrder.verify(mockCallback1).onConnectSuccess(clientId1); - mDut.connect(clientId2, uid2, pid2, callingPackage, mockCallback2, configRequest, false); + mDut.connect(clientId2, uid2, pid2, callingPackage, callingFeature, mockCallback2, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mockCallback2).onConnectSuccess(clientId2); @@ -349,6 +351,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final ConfigRequest configRequest = new ConfigRequest.Builder().build(); IWifiAwareEventCallback mockCallback = mock(IWifiAwareEventCallback.class); @@ -366,7 +369,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { collector.checkThat("usage enabled", mDut.isUsageEnabled(), equalTo(true)); // (2) connect (enable Aware) - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -395,6 +399,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final ConfigRequest configRequest = new ConfigRequest.Builder().build(); IWifiAwareEventCallback mockCallback = mock(IWifiAwareEventCallback.class); @@ -421,7 +426,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { // (3) try connecting and validate that get failure callback (though app should be aware of // non-availability through state change broadcast and/or query API) - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectFail(anyInt()); @@ -439,6 +445,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final ConfigRequest configRequest = new ConfigRequest.Builder().build(); IWifiAwareEventCallback mockCallback = mock(IWifiAwareEventCallback.class); @@ -459,7 +466,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { collector.checkThat("usage enabled", mDut.isUsageEnabled(), equalTo(true)); // (2) connect (successfully) - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -485,7 +493,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { inOrderM.verify(mAwareMetricsMock).recordDisableAware(); // (4) try connecting again and validate that get a failure - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectFail(anyInt()); inOrderM.verify(mAwareMetricsMock).recordAttachStatus(NanStatusType.INTERNAL_FAILURE); @@ -503,7 +512,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { validateCorrectAwareStatusChangeBroadcast(inOrder); // (7) connect (should be successful) - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -526,6 +536,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final ConfigRequest configRequest = new ConfigRequest.Builder().build(); IWifiAwareEventCallback mockCallback = mock(IWifiAwareEventCallback.class); @@ -544,7 +555,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (2) connect with HAL failure - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -568,6 +580,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final int reason = NanStatusType.INTERNAL_FAILURE; final byte[] someMac = HexEncoding.decode("000102030405".toCharArray(), false); final byte[] someMac2 = HexEncoding.decode("060708090A0B".toCharArray(), false); @@ -588,7 +601,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (1) connect 1st and 2nd clients - mDut.connect(clientId1, uid, pid, callingPackage, mockCallback1, configRequest, false); + mDut.connect(clientId1, uid, pid, callingPackage, callingFeature, mockCallback1, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionIdCapture.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -597,7 +611,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); inOrder.verify(mockCallback1).onConnectSuccess(clientId1); - mDut.connect(clientId2, uid, pid, callingPackage, mockCallback2, configRequest, true); + mDut.connect(clientId2, uid, pid, callingPackage, callingFeature, mockCallback2, + configRequest, true); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionIdCapture.capture(), eq(configRequest), eq(true), eq(false), eq(true), eq(false)); @@ -626,8 +641,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (5) deliver new identity - with LOCATIONING permission - when(mWifiPermissionsUtil.checkCallersLocationPermission(anyString(), anyInt(), - anyBoolean())).thenReturn(true); + when(mWifiPermissionsUtil.checkCallersLocationPermission(eq(callingPackage), + eq(callingFeature), eq(uid), anyBoolean(), any())).thenReturn(true); mDut.onInterfaceAddressChangeNotification(someMac); mMockLooper.dispatchAll(); @@ -655,6 +670,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final ConfigRequest configRequest = new ConfigRequest.Builder().build(); final PublishConfig publishConfig = new PublishConfig.Builder().build(); @@ -673,7 +689,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (1) connect (successfully) - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -717,6 +734,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final int reasonFail = NanStatusType.INTERNAL_FAILURE; ConfigRequest configRequest = new ConfigRequest.Builder().build(); @@ -737,7 +755,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (0) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -786,6 +805,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final int reasonTerminate = NanStatusType.SUCCESS; final byte publishId = 15; @@ -808,7 +828,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (0) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -868,6 +889,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final byte publishId = 15; final int reasonFail = NanStatusType.INTERNAL_FAILURE; @@ -890,7 +912,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (0) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -980,6 +1003,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final byte publishId = 15; ConfigRequest configRequest = new ConfigRequest.Builder().build(); @@ -1000,7 +1024,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (0) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -1046,6 +1071,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final int reasonFail = NanStatusType.INTERNAL_FAILURE; ConfigRequest configRequest = new ConfigRequest.Builder().build(); @@ -1066,7 +1092,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (0) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -1116,6 +1143,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final int reasonTerminate = NanStatusType.SUCCESS; final byte subscribeId = 15; @@ -1138,7 +1166,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (0) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -1196,6 +1225,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final byte subscribeId = 15; final int reasonFail = NanStatusType.INTERNAL_FAILURE; final int rangeMax = 10; @@ -1220,7 +1250,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (0) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -1293,6 +1324,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final byte subscribeId = 15; ConfigRequest configRequest = new ConfigRequest.Builder().build(); @@ -1311,7 +1343,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (0) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -1352,6 +1385,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final String serviceName = "some-service-name"; final String ssi = "some much longer and more arbitrary data"; final int reasonFail = NanStatusType.INTERNAL_FAILURE; @@ -1392,7 +1426,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (0) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -1480,6 +1515,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final int clusterLow = 7; final int clusterHigh = 7; final int masterPref = 0; @@ -1518,7 +1554,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (1) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -1585,6 +1622,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final int clusterLow = 7; final int clusterHigh = 7; final int masterPref = 0; @@ -1620,7 +1658,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (1) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -1686,6 +1725,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final String ssi = "some much longer and more arbitrary data"; final byte subscribeId = 15; final int requestorId = 22; @@ -1712,7 +1752,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (1) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -1755,6 +1796,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final String ssi = "some much longer and more arbitrary data"; final byte subscribeId = 15; final int requestorId = 22; @@ -1781,7 +1823,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (1) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -1880,6 +1923,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final String ssi = "some much longer and more arbitrary data"; final byte subscribeId = 15; final int requestorId = 22; @@ -1907,7 +1951,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (1) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -1967,6 +2012,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final String ssi = "some much longer and more arbitrary data"; final byte subscribeId = 15; final int requestorId = 22; @@ -1994,7 +2040,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (1) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -2054,6 +2101,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final String serviceName = "some-service-name"; final byte subscribeId = 15; final int requestorId = 22; @@ -2082,7 +2130,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (0) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -2153,6 +2202,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int pid2 = 3000; final String callingPackage1 = "com.google.somePackage1"; final String callingPackage2 = "com.google.somePackage2"; + final String callingFeature = "com.google.someFeature"; final String serviceName1 = "some-service-name1"; final String serviceName2 = "some-service-name2"; final byte subscribeId1 = 15; @@ -2194,7 +2244,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (0) connect - mDut.connect(clientId1, uid1, pid1, callingPackage1, mockCallback, configRequest1, false); + mDut.connect(clientId1, uid1, pid1, callingPackage1, callingFeature, mockCallback, + configRequest1, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest1), eq(false), eq(true), eq(true), eq(false)); @@ -2202,7 +2253,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId1); - mDut.connect(clientId2, uid2, pid2, callingPackage2, mockCallback, configRequest2, false); + mDut.connect(clientId2, uid2, pid2, callingPackage2, callingFeature, mockCallback, + configRequest2, false); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId2); @@ -2298,6 +2350,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final String serviceName = "some-service-name"; final byte subscribeId = 15; final int requestorId = 22; @@ -2326,7 +2379,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (0) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -2427,6 +2481,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final String serviceName = "some-service-name"; final String ssi = "some much longer and more arbitrary data"; final byte subscribeId = 15; @@ -2458,7 +2513,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (0) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -2643,6 +2699,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final int masterPref1 = 111; final int masterPref3 = 115; final int dwInterval1Band24 = 2; @@ -2687,7 +2744,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (1) config1 (valid) - mDut.connect(clientId1, uid, pid, callingPackage, mockCallback1, configRequest1, false); + mDut.connect(clientId1, uid, pid, callingPackage, callingFeature, mockCallback1, + configRequest1, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), crCapture.capture(), eq(false), eq(true), eq(true), eq(false)); @@ -2697,13 +2755,15 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { inOrder.verify(mockCallback1).onConnectSuccess(clientId1); // (2) config2 (incompatible with config1) - mDut.connect(clientId2, uid, pid, callingPackage, mockCallback2, configRequest2, false); + mDut.connect(clientId2, uid, pid, callingPackage, callingFeature, mockCallback2, + configRequest2, false); mMockLooper.dispatchAll(); inOrder.verify(mockCallback2).onConnectFail(NanStatusType.INTERNAL_FAILURE); validateInternalClientInfoCleanedUp(clientId2); // (3) config3 (compatible with config1) - mDut.connect(clientId3, uid, pid, callingPackage, mockCallback3, configRequest3, true); + mDut.connect(clientId3, uid, pid, callingPackage, callingFeature, mockCallback3, + configRequest3, true); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), crCapture.capture(), eq(true), eq(false), eq(true), eq(false)); @@ -2758,6 +2818,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; ArgumentCaptor<Short> transactionId = ArgumentCaptor.forClass(Short.class); IWifiAwareEventCallback mockCallback = mock(IWifiAwareEventCallback.class); @@ -2773,7 +2834,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (1) attach w/o identity - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), any(ConfigRequest.class), eq(false), eq(true), eq(true), eq(false)); @@ -2783,13 +2845,15 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { // (2) attach w/o identity ++clientId; - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); // (3) attach w/ identity ++clientId; - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, true); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, true); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), any(ConfigRequest.class), eq(true), eq(false), eq(true), eq(false)); @@ -2799,13 +2863,15 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { // (4) attach w/o identity ++clientId; - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); // (5) attach w/ identity ++clientId; - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, true); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, true); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -2821,6 +2887,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final int clusterLow = 5; final int clusterHigh = 100; final int masterPref = 111; @@ -2848,7 +2915,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (1) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -2897,6 +2965,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final int clusterLow = 15; final int clusterHigh = 192; final int masterPref = 234; @@ -2923,7 +2992,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (1) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -2951,6 +3021,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; ConfigRequest configRequest = new ConfigRequest.Builder().build(); @@ -2967,7 +3038,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (1) connect (no response) - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -2987,6 +3059,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; ConfigRequest configRequest = new ConfigRequest.Builder().build(); @@ -3001,7 +3074,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (1) connect and succeed - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -3037,6 +3111,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final byte publishId = 25; ConfigRequest configRequest = new ConfigRequest.Builder().build(); @@ -3057,7 +3132,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (1) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -3092,6 +3168,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final byte subscribeId = 25; ConfigRequest configRequest = new ConfigRequest.Builder().build(); @@ -3112,7 +3189,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (1) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -3146,6 +3224,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; int loopCount = 100; ConfigRequest configRequest = new ConfigRequest.Builder().build(); @@ -3165,7 +3244,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (1) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -3202,6 +3282,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; ConfigRequest configRequest = new ConfigRequest.Builder().build(); @@ -3219,7 +3300,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); // (1) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -3263,6 +3345,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; setSettableParam(WifiAwareStateManager.PARAM_ON_IDLE_DISABLE_AWARE, Integer.toString(1), true); @@ -3284,7 +3367,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { inOrder.verify(mMockNativeManager).releaseAware(); // (1) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNativeManager).tryToGetAware(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), @@ -3341,6 +3425,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; ConfigRequest configRequest = new ConfigRequest.Builder().build(); @@ -3359,7 +3444,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { inOrder.verify(mMockNativeManager).releaseAware(); // (1) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNativeManager).tryToGetAware(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), @@ -3412,6 +3498,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; ConfigRequest configRequest = new ConfigRequest.Builder().build(); @@ -3430,7 +3517,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { inOrder.verify(mMockNativeManager).releaseAware(); // (1) connect - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNativeManager).tryToGetAware(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), @@ -3483,6 +3571,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.google.somePackage"; + final String callingFeature = "com.google.someFeature"; final ConfigRequest configRequest = new ConfigRequest.Builder().build(); IWifiAwareEventCallback mockCallback = mock(IWifiAwareEventCallback.class); @@ -3499,7 +3588,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { collector.checkThat("usage enabled", mDut.isUsageEnabled(), equalTo(true)); // (1) connect client - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); @@ -3514,7 +3604,8 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { validateCorrectAwareStatusChangeBroadcast(inOrder); // (3) try reconnect client - mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false); + mDut.connect(clientId, uid, pid, callingPackage, callingFeature, mockCallback, + configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), eq(false), eq(true), eq(true), eq(false)); diff --git a/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java index bc51b6d4b..e5d1c3e68 100644 --- a/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java @@ -38,6 +38,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import android.annotation.Nullable; import android.app.test.MockAnswerUtil.AnswerWithArguments; import android.content.BroadcastReceiver; import android.content.Context; @@ -234,15 +235,17 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { * Mock send WifiP2pManager.UPDATE_CHANNEL_INFO * * @param pkgName package name used for p2p channel init + * @param featureId The feature in the package * @param binder client binder used for p2p channel init * @param replyMessenger for checking replied message. */ - private void sendChannelInfoUpdateMsg(String pkgName, Binder binder, - Messenger replyMessenger) throws Exception { + private void sendChannelInfoUpdateMsg(String pkgName, @Nullable String featureId, + Binder binder, Messenger replyMessenger) throws Exception { Message msg = Message.obtain(); msg.what = WifiP2pManager.UPDATE_CHANNEL_INFO; Bundle bundle = new Bundle(); bundle.putString(WifiP2pManager.CALLING_PACKAGE, pkgName); + bundle.putString(WifiP2pManager.CALLING_FEATURE_ID, featureId); bundle.putBinder(WifiP2pManager.CALLING_BINDER, binder); msg.obj = bundle; msg.replyTo = replyMessenger; @@ -879,7 +882,7 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { forceP2pEnabled(mClient1); doThrow(new SecurityException("P2p unit test")) .when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendAddLocalServiceMsg(mClientMessenger); assertTrue(mClientHandler.hasMessages(WifiP2pManager.ADD_LOCAL_SERVICE_FAILED)); verify(mWifiNative, never()).p2pServiceAdd(any()); @@ -894,13 +897,13 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { forceP2pEnabled(mClient1); doNothing().when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); when(mWifiPermissionsUtil.checkCanAccessWifiDirect( - anyString(), anyInt(), anyBoolean())).thenReturn(false); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + anyString(), anyString(), anyInt(), anyBoolean())).thenReturn(false); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendAddLocalServiceMsg(mClientMessenger); assertTrue(mClientHandler.hasMessages(WifiP2pManager.ADD_LOCAL_SERVICE_FAILED)); verify(mWifiNative, never()).p2pServiceAdd(any()); - verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), + anyInt(), eq(false)); } /** @@ -909,15 +912,15 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testAddLocalServiceSuccess() throws Exception { forceP2pEnabled(mClient1); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); doNothing().when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); when(mWifiNative.p2pServiceAdd(any())).thenReturn(true); sendAddLocalServiceMsg(mClientMessenger); verify(mWifiNative).p2pServiceAdd(any()); - verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), + anyInt(), eq(false)); assertTrue(mClientHandler.hasMessages(WifiP2pManager.ADD_LOCAL_SERVICE_SUCCEEDED)); } @@ -927,15 +930,15 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testAddLocalServiceFailureWhenNativeCallFailure() throws Exception { forceP2pEnabled(mClient1); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); doNothing().when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); when(mWifiNative.p2pServiceAdd(any())).thenReturn(false); sendAddLocalServiceMsg(mClientMessenger); verify(mWifiNative).p2pServiceAdd(any()); - verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), + anyInt(), eq(false)); assertTrue(mClientHandler.hasMessages(WifiP2pManager.ADD_LOCAL_SERVICE_FAILED)); } @@ -961,7 +964,7 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { forceP2pEnabled(mClient1); doThrow(new SecurityException("P2p unit test")) .when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendConnectMsgWithConfigValidAsGroup(mClientMessenger); assertTrue(mClientHandler.hasMessages(WifiP2pManager.CONNECT_FAILED)); verify(mWifiNative, never()).p2pGroupAdd(any(), anyBoolean()); @@ -975,14 +978,14 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { public void testConnectWithConfigValidAsGroupFailureWhenPermissionDenied() throws Exception { forceP2pEnabled(mClient1); doNothing().when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(false); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(false); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendConnectMsgWithConfigValidAsGroup(mClientMessenger); assertTrue(mClientHandler.hasMessages(WifiP2pManager.CONNECT_FAILED)); verify(mWifiNative, never()).p2pGroupAdd(any(), anyBoolean()); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(false)); } /** @@ -991,14 +994,14 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testConnectWithConfigValidAsGroupSuccess() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); when(mWifiNative.p2pGroupAdd(any(), eq(true))).thenReturn(true); sendConnectMsgWithConfigValidAsGroup(mClientMessenger); verify(mWifiNative).p2pGroupAdd(any(), eq(true)); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(false)); assertTrue(mClientHandler.hasMessages(WifiP2pManager.CONNECT_SUCCEEDED)); } @@ -1008,14 +1011,14 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testConnectWithConfigValidAsGroupFailureWhenNativeCallFailure() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); when(mWifiNative.p2pGroupAdd(any(), eq(true))).thenReturn(false); sendConnectMsgWithConfigValidAsGroup(mClientMessenger); verify(mWifiNative).p2pGroupAdd(any(), eq(true)); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(false)); assertTrue(mClientHandler.hasMessages(WifiP2pManager.CONNECT_FAILED)); } @@ -1043,7 +1046,7 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { forceP2pEnabled(mClient1); doThrow(new SecurityException("P2p unit test")) .when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendCreateGroupMsgWithConfigValidAsGroup(mClientMessenger); assertTrue(mClientHandler.hasMessages(WifiP2pManager.CREATE_GROUP_FAILED)); verify(mWifiNative, never()).p2pGroupAdd(anyBoolean()); @@ -1059,15 +1062,15 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { throws Exception { forceP2pEnabled(mClient1); doNothing().when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(false); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(false); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendCreateGroupMsgWithConfigValidAsGroup(mClientMessenger); assertTrue(mClientHandler.hasMessages(WifiP2pManager.CREATE_GROUP_FAILED)); verify(mWifiNative, never()).p2pGroupAdd(anyBoolean()); verify(mWifiNative, never()).p2pGroupAdd(any(), anyBoolean()); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(false)); } /** @@ -1076,14 +1079,14 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testCreateGroupWithConfigValidAsGroupSuccess() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); when(mWifiNative.p2pGroupAdd(any(), eq(false))).thenReturn(true); sendCreateGroupMsgWithConfigValidAsGroup(mClientMessenger); verify(mWifiNative).p2pGroupAdd(any(), eq(false)); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(false)); assertTrue(mClientHandler.hasMessages(WifiP2pManager.CREATE_GROUP_SUCCEEDED)); } @@ -1094,14 +1097,14 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { public void testCreateGroupWithConfigValidAsGroupFailureWhenNativeCallFailure() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); when(mWifiNative.p2pGroupAdd(any(), eq(false))).thenReturn(false); sendCreateGroupMsgWithConfigValidAsGroup(mClientMessenger); verify(mWifiNative).p2pGroupAdd(any(), eq(false)); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(false)); assertTrue(mClientHandler.hasMessages(WifiP2pManager.CREATE_GROUP_FAILED)); } @@ -1126,7 +1129,7 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { forceP2pEnabled(mClient1); doThrow(new SecurityException("P2p unit test")) .when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendDiscoverPeersMsg(mClientMessenger); verify(mWifiNative, never()).p2pFind(anyInt()); assertTrue(mClientHandler.hasMessages(WifiP2pManager.DISCOVER_PEERS_FAILED)); @@ -1140,13 +1143,13 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { public void testDiscoverPeersFailureWhenPermissionDenied() throws Exception { forceP2pEnabled(mClient1); doNothing().when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(false); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(false); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendDiscoverPeersMsg(mClientMessenger); verify(mWifiNative, never()).p2pFind(anyInt()); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(true)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(true)); assertTrue(mClientHandler.hasMessages(WifiP2pManager.DISCOVER_PEERS_FAILED)); } @@ -1158,15 +1161,15 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { public void testDiscoverPeersFailureWhenLocationModeDisabled() throws Exception { forceP2pEnabled(mClient1); doNothing().when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), eq(false))) - .thenReturn(true); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), eq(true))) - .thenReturn(false); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + eq(false))).thenReturn(true); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + eq(true))).thenReturn(false); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendDiscoverPeersMsg(mClientMessenger); verify(mWifiNative, never()).p2pFind(anyInt()); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(true)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(true)); assertTrue(mClientHandler.hasMessages(WifiP2pManager.DISCOVER_PEERS_FAILED)); } @@ -1176,14 +1179,14 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testDiscoverPeersSuccess() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); when(mWifiNative.p2pFind(anyInt())).thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendDiscoverPeersMsg(mClientMessenger); verify(mWifiNative).p2pFind(anyInt()); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(true)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(true)); assertTrue(mClientHandler.hasMessages(WifiP2pManager.DISCOVER_PEERS_SUCCEEDED)); } @@ -1193,14 +1196,14 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testDiscoverPeersFailureWhenNativeCallFailure() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); when(mWifiNative.p2pFind(anyInt())).thenReturn(false); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendDiscoverPeersMsg(mClientMessenger); verify(mWifiNative).p2pFind(anyInt()); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(true)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(true)); assertTrue(mClientHandler.hasMessages(WifiP2pManager.DISCOVER_PEERS_FAILED)); } @@ -1230,7 +1233,7 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { forceP2pEnabled(mClient1); doThrow(new SecurityException("P2p unit test")) .when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendAddServiceRequestMsg(mClientMessenger); sendDiscoverServiceMsg(mClientMessenger); verify(mWifiNative, never()).p2pServDiscReq(anyString(), anyString()); @@ -1248,15 +1251,15 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { .thenReturn("mServiceDiscReqId"); forceP2pEnabled(mClient1); doNothing().when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(false); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(false); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendAddServiceRequestMsg(mClientMessenger); sendDiscoverServiceMsg(mClientMessenger); verify(mWifiNative, never()).p2pServDiscReq(anyString(), anyString()); verify(mWifiNative, never()).p2pFind(anyInt()); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(true)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(true)); assertTrue(mClientHandler.hasMessages(WifiP2pManager.DISCOVER_SERVICES_FAILED)); } @@ -1270,17 +1273,17 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { .thenReturn("mServiceDiscReqId"); forceP2pEnabled(mClient1); doNothing().when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), eq(false))) - .thenReturn(true); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), eq(true))) - .thenReturn(false); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + eq(false))).thenReturn(true); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + eq(true))).thenReturn(false); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendAddServiceRequestMsg(mClientMessenger); sendDiscoverServiceMsg(mClientMessenger); verify(mWifiNative, never()).p2pServDiscReq(anyString(), anyString()); verify(mWifiNative, never()).p2pFind(anyInt()); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(true)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(true)); assertTrue(mClientHandler.hasMessages(WifiP2pManager.DISCOVER_SERVICES_FAILED)); } @@ -1293,15 +1296,15 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { .thenReturn("mServiceDiscReqId"); when(mWifiNative.p2pFind(anyInt())).thenReturn(true); forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendAddServiceRequestMsg(mClientMessenger); sendDiscoverServiceMsg(mClientMessenger); verify(mWifiNative).p2pServDiscReq(anyString(), anyString()); verify(mWifiNative).p2pFind(anyInt()); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(true)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(true)); assertTrue(mClientHandler.hasMessages(WifiP2pManager.DISCOVER_SERVICES_SUCCEEDED)); } @@ -1312,15 +1315,15 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { public void testDiscoverServicesFailureWhenAddServiceRequestFailure() throws Exception { when(mWifiNative.p2pServDiscReq(anyString(), anyString())).thenReturn(null); forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendAddServiceRequestMsg(mClientMessenger); sendDiscoverServiceMsg(mClientMessenger); verify(mWifiNative).p2pServDiscReq(anyString(), anyString()); verify(mWifiNative, never()).p2pFind(anyInt()); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(true)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(true)); assertTrue(mClientHandler.hasMessages(WifiP2pManager.DISCOVER_SERVICES_FAILED)); } @@ -1333,15 +1336,15 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { .thenReturn("mServiceDiscReqId"); when(mWifiNative.p2pFind(anyInt())).thenReturn(false); forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendAddServiceRequestMsg(mClientMessenger); sendDiscoverServiceMsg(mClientMessenger); verify(mWifiNative).p2pServDiscReq(anyString(), anyString()); verify(mWifiNative).p2pFind(anyInt()); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(true)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(true)); assertTrue(mClientHandler.hasMessages(WifiP2pManager.DISCOVER_SERVICES_FAILED)); } @@ -1371,7 +1374,7 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { mockPeersList(); doThrow(new SecurityException("P2p unit test")) .when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendRequestPeersMsg(mClientMessenger); verify(mClientHandler).sendMessage(mMessageCaptor.capture()); WifiP2pDeviceList peers = (WifiP2pDeviceList) mMessageCaptor.getValue().obj; @@ -1388,13 +1391,13 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { forceP2pEnabled(mClient1); mockPeersList(); doNothing().when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(false); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(false); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendRequestPeersMsg(mClientMessenger); verify(mClientHandler).sendMessage(mMessageCaptor.capture()); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(true)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(true)); WifiP2pDeviceList peers = (WifiP2pDeviceList) mMessageCaptor.getValue().obj; assertEquals(WifiP2pManager.RESPONSE_PEERS, mMessageCaptor.getValue().what); assertNull(peers.get(mTestWifiP2pDevice.deviceAddress)); @@ -1410,15 +1413,15 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { forceP2pEnabled(mClient1); mockPeersList(); doNothing().when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), eq(false))) - .thenReturn(true); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), eq(true))) - .thenReturn(false); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + eq(false))).thenReturn(true); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + eq(true))).thenReturn(false); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendRequestPeersMsg(mClientMessenger); verify(mClientHandler).sendMessage(mMessageCaptor.capture()); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(true)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(true)); WifiP2pDeviceList peers = (WifiP2pDeviceList) mMessageCaptor.getValue().obj; assertEquals(WifiP2pManager.RESPONSE_PEERS, mMessageCaptor.getValue().what); assertNull(peers.get(mTestWifiP2pDevice.deviceAddress)); @@ -1433,13 +1436,13 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { public void testRequestPeersSuccess() throws Exception { forceP2pEnabled(mClient1); mockPeersList(); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendRequestPeersMsg(mClientMessenger); verify(mClientHandler).sendMessage(mMessageCaptor.capture()); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(true)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(true)); WifiP2pDeviceList peers = (WifiP2pDeviceList) mMessageCaptor.getValue().obj; assertEquals(WifiP2pManager.RESPONSE_PEERS, mMessageCaptor.getValue().what); assertNotEquals(null, peers.get(mTestWifiP2pDevice.deviceAddress)); @@ -1469,7 +1472,7 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { sendGroupStartedMsg(mTestWifiP2pGroup); doThrow(new SecurityException("P2p unit test")) .when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendRequestGroupInfoMsg(mClientMessenger); verify(mClientHandler).sendMessage(mMessageCaptor.capture()); assertEquals(WifiP2pManager.RESPONSE_GROUP_INFO, mMessageCaptor.getValue().what); @@ -1485,13 +1488,13 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { forceP2pEnabled(mClient1); sendGroupStartedMsg(mTestWifiP2pGroup); doNothing().when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(false); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(false); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendRequestGroupInfoMsg(mClientMessenger); verify(mClientHandler).sendMessage(mMessageCaptor.capture()); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(false)); assertEquals(WifiP2pManager.RESPONSE_GROUP_INFO, mMessageCaptor.getValue().what); assertNull(mMessageCaptor.getValue().obj); } @@ -1506,13 +1509,13 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { forceP2pEnabled(mClient1); sendGroupStartedMsg(mTestWifiP2pGroup); when(mWifiPermissionsUtil.checkLocalMacAddressPermission(anyInt())).thenReturn(false); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendRequestGroupInfoMsg(mClientMessenger); verify(mClientHandler).sendMessage(mMessageCaptor.capture()); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(false)); assertEquals(WifiP2pManager.RESPONSE_GROUP_INFO, mMessageCaptor.getValue().what); WifiP2pGroup wifiP2pGroup = (WifiP2pGroup) mMessageCaptor.getValue().obj; assertEquals(mTestWifiP2pGroup.getNetworkName(), wifiP2pGroup.getNetworkName()); @@ -1530,13 +1533,13 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { forceP2pEnabled(mClient1); sendGroupStartedMsg(mTestWifiP2pGroup); when(mWifiPermissionsUtil.checkLocalMacAddressPermission(anyInt())).thenReturn(true); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendRequestGroupInfoMsg(mClientMessenger); verify(mClientHandler).sendMessage(mMessageCaptor.capture()); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(false)); assertEquals(WifiP2pManager.RESPONSE_GROUP_INFO, mMessageCaptor.getValue().what); WifiP2pGroup wifiP2pGroup = (WifiP2pGroup) mMessageCaptor.getValue().obj; assertEquals(thisDeviceMac, wifiP2pGroup.getOwner().deviceAddress); @@ -1694,14 +1697,14 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testPeerScanMetricWhenSendDiscoverPeers() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); when(mWifiNative.p2pFind(anyInt())).thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendDiscoverPeersMsg(mClientMessenger); verify(mWifiP2pMetrics).incrementPeerScans(); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(true)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(true)); } /** @@ -1714,14 +1717,14 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { .thenReturn("mServiceDiscReqId"); when(mWifiNative.p2pFind(anyInt())).thenReturn(true); forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendAddServiceRequestMsg(mClientMessenger); sendDiscoverServiceMsg(mClientMessenger); verify(mWifiP2pMetrics).incrementServiceScans(); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(true)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(true)); } /** @@ -1731,7 +1734,7 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testPersistentGroupMetricWhenSendFactoryReset() throws Exception { forceP2pEnabled(mClient1); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); // permissions for factory reset when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())) @@ -1760,7 +1763,7 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testPersistentGroupMetricWhenSendP2pGroupStartedEvent() throws Exception { forceP2pEnabled(mClient1); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); ArgumentCaptor<WifiP2pGroupList> groupsCaptor = ArgumentCaptor.forClass(WifiP2pGroupList.class); @@ -1781,7 +1784,7 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testPersistentGroupMetricWhenSendDeletePersistentGroup() throws Exception { forceP2pEnabled(mClient1); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); ArgumentCaptor<WifiP2pGroupList> groupsCaptor = ArgumentCaptor.forClass(WifiP2pGroupList.class); @@ -1801,7 +1804,7 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testGroupEventMetric() throws Exception { forceP2pEnabled(mClient1); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendGroupStartedMsg(mTestWifiP2pNewPersistentGoGroup); @@ -1821,14 +1824,14 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testStartFreshConnectionEventWhenSendConnect() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); mockPeersList(); sendConnectMsg(mClientMessenger, mTestWifiP2pPeerConfig); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(false)); ArgumentCaptor<WifiP2pConfig> configCaptor = ArgumentCaptor.forClass(WifiP2pConfig.class); @@ -1844,19 +1847,19 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testStartReinvokeConnectionEventWhenSendConnect() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); when(mWifiNative.p2pGroupAdd(anyInt())) .thenReturn(true); when(mTestWifiP2pDevice.isGroupOwner()).thenReturn(true); when(mWifiNative.p2pGetSsid(eq(mTestWifiP2pDevice.deviceAddress))) .thenReturn(mTestWifiP2pGroup.getNetworkName()); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); mockPeersList(); sendConnectMsg(mClientMessenger, mTestWifiP2pPeerConfig); verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + .checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), eq(false)); ArgumentCaptor<WifiP2pConfig> configCaptor = ArgumentCaptor.forClass(WifiP2pConfig.class); @@ -1877,13 +1880,13 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { public void testStartReinvokeConnectionEventWhenCreateGroup() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendCreateGroupMsg(mClientMessenger, WifiP2pGroup.PERSISTENT_NET_ID, null); - verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), + anyInt(), eq(false)); verify(mWifiP2pMetrics).startConnectionEvent( eq(P2pConnectionEvent.CONNECTION_REINVOKE), @@ -1897,9 +1900,9 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testStartLocalConnectionWhenCreateGroup() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); // permissions for factory reset when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())) @@ -1914,8 +1917,8 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { sendSimpleMsg(mClientMessenger, WifiP2pManager.FACTORY_RESET); sendCreateGroupMsg(mClientMessenger, WifiP2pGroup.PERSISTENT_NET_ID, null); - verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), + anyInt(), eq(false)); verify(mWifiP2pMetrics).startConnectionEvent( eq(P2pConnectionEvent.CONNECTION_LOCAL), @@ -1929,13 +1932,13 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testStartLocalConnectionEventWhenCreateTemporaryGroup() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendCreateGroupMsg(mClientMessenger, WifiP2pGroup.TEMPORARY_NET_ID, null); - verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), + anyInt(), eq(false)); verify(mWifiP2pMetrics).startConnectionEvent( eq(P2pConnectionEvent.CONNECTION_LOCAL), @@ -1950,14 +1953,14 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { public void testStartFastConnectionEventWhenSendConnectWithConfig() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); when(mWifiNative.p2pGroupAdd(any(), eq(true))).thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendConnectMsg(mClientMessenger, mTestWifiP2pFastConnectionConfig); - verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), + anyInt(), eq(false)); ArgumentCaptor<WifiP2pConfig> configCaptor = ArgumentCaptor.forClass(WifiP2pConfig.class); @@ -1976,13 +1979,13 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { public void testStartFastConnectionEventWhenCreateGroupWithConfig() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendCreateGroupMsg(mClientMessenger, 0, mTestWifiP2pFastConnectionConfig); - verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), + anyInt(), eq(false)); ArgumentCaptor<WifiP2pConfig> configCaptor = ArgumentCaptor.forClass(WifiP2pConfig.class); @@ -1999,7 +2002,7 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testEndConnectionEventWhenGroupFormed() throws Exception { forceP2pEnabled(mClient1); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); WifiP2pGroup group = new WifiP2pGroup(); group.setNetworkId(WifiP2pGroup.PERSISTENT_NET_ID); @@ -2017,14 +2020,14 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testEndConnectionEventWhenTimeout() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); when(mWifiNative.p2pGroupAdd(anyBoolean())).thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); mockEnterGroupNegotiationState(); - verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), + anyInt(), eq(false)); mLooper.moveTimeForward(120 * 1000 * 2); mLooper.dispatchAll(); @@ -2039,14 +2042,14 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testEndConnectionEventWhenCancel() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); when(mWifiNative.p2pGroupAdd(anyBoolean())).thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); mockEnterGroupNegotiationState(); - verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), + anyInt(), eq(false)); sendSimpleMsg(mClientMessenger, WifiP2pManager.CANCEL_CONNECT); @@ -2060,14 +2063,14 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testEndConnectionEventWhenProvDiscFailure() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); when(mWifiNative.p2pGroupAdd(anyBoolean())).thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); mockEnterProvisionDiscoveryState(); - verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), + anyInt(), eq(false)); sendSimpleMsg(null, WifiP2pMonitor.P2P_PROV_DISC_FAILURE_EVENT); @@ -2081,14 +2084,14 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testEndConnectionEventWhenGroupRemoval() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); when(mWifiNative.p2pGroupAdd(anyBoolean())).thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); mockEnterGroupNegotiationState(); - verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), + anyInt(), eq(false)); sendSimpleMsg(null, WifiP2pMonitor.P2P_GROUP_REMOVED_EVENT); @@ -2102,14 +2105,14 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testEndConnectionEventWhenInvitationFailure() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); when(mWifiNative.p2pGroupAdd(anyBoolean())).thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); mockEnterGroupNegotiationState(); - verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), + anyInt(), eq(false)); sendInvitationResultMsg(WifiP2pServiceImpl.P2pStatus.UNKNOWN); @@ -2125,12 +2128,12 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { public void testRequestDeviceInfoFailureWhenPermissionDenied() throws Exception { forceP2pEnabled(mClient1); doNothing().when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(false); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(false); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendSimpleMsg(mClientMessenger, WifiP2pManager.REQUEST_DEVICE_INFO); - verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), + anyInt(), eq(false)); verify(mClientHandler).sendMessage(mMessageCaptor.capture()); assertEquals(WifiP2pManager.RESPONSE_DEVICE_INFO, mMessageCaptor.getValue().what); assertNull(mMessageCaptor.getValue().obj); @@ -2143,12 +2146,12 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testRequestDeviceInfoSuccessWhenP2pEnabled() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendSimpleMsg(mClientMessenger, WifiP2pManager.REQUEST_DEVICE_INFO); - verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), + anyInt(), eq(false)); verify(mClientHandler).sendMessage(mMessageCaptor.capture()); assertEquals(WifiP2pManager.RESPONSE_DEVICE_INFO, mMessageCaptor.getValue().what); WifiP2pDevice wifiP2pDevice = (WifiP2pDevice) mMessageCaptor.getValue().obj; @@ -2162,12 +2165,12 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { */ @Test public void testRequestDeviceInfoReturnEmptyWifiP2pDeviceWhenP2pDisabled() throws Exception { - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendSimpleMsg(mClientMessenger, WifiP2pManager.REQUEST_DEVICE_INFO); - verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), + anyInt(), eq(false)); verify(mClientHandler).sendMessage(mMessageCaptor.capture()); assertEquals(WifiP2pManager.RESPONSE_DEVICE_INFO, mMessageCaptor.getValue().what); WifiP2pDevice wifiP2pDevice = (WifiP2pDevice) mMessageCaptor.getValue().obj; @@ -2183,12 +2186,12 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { public void testRequestDeviceInfoReturnsActualMacForNetworkSettingsApp() throws Exception { forceP2pEnabled(mClient1); when(mWifiPermissionsUtil.checkLocalMacAddressPermission(anyInt())).thenReturn(true); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyInt(), anyBoolean())) - .thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendSimpleMsg(mClientMessenger, WifiP2pManager.REQUEST_DEVICE_INFO); - verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(false)); + verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), + anyInt(), eq(false)); verify(mClientHandler).sendMessage(mMessageCaptor.capture()); assertEquals(WifiP2pManager.RESPONSE_DEVICE_INFO, mMessageCaptor.getValue().what); WifiP2pDevice wifiP2pDevice = (WifiP2pDevice) mMessageCaptor.getValue().obj; @@ -3426,14 +3429,14 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testRequestDiscoveryStateWhenStarted() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), anyBoolean())) - .thenReturn(true); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), + anyInt(), anyBoolean())).thenReturn(true); when(mWifiNative.p2pFind(anyInt())).thenReturn(true); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendDiscoverPeersMsg(mClientMessenger); verify(mWifiNative).p2pFind(anyInt()); - verify(mWifiPermissionsUtil) - .checkCanAccessWifiDirect(eq("testPkg1"), anyInt(), eq(true)); + verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), + anyInt(), eq(true)); sendSimpleMsg(mClientMessenger, WifiP2pManager.REQUEST_DISCOVERY_STATE); @@ -3619,7 +3622,7 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testAddServiceRequestSuccessWithoutServiceDiscover() throws Exception { forceP2pEnabled(mClient1); - sendChannelInfoUpdateMsg("testPkg1", mClient1, mClientMessenger); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendAddServiceRequestMsg(mClientMessenger); diff --git a/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java index 76f8b0f63..a355540ff 100644 --- a/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java @@ -29,6 +29,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; @@ -110,6 +111,7 @@ public class RttServiceImplTest extends WifiBaseTest { private BroadcastReceiver mLocationModeReceiver; private final String mPackageName = "some.package.name.for.rtt.app"; + private final String mFeatureId = "some.feature.name.for.rtt.app"; private int mDefaultUid = 1500; private WorkSource mDefaultWs = new WorkSource(mDefaultUid); @@ -205,8 +207,8 @@ public class RttServiceImplTest extends WifiBaseTest { when(mockActivityManager.getUidImportance(anyInt())).thenReturn( ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND_SERVICE); - when(mockPermissionUtil.checkCallersLocationPermission(eq(mPackageName), - anyInt(), anyBoolean())).thenReturn(true); + when(mockPermissionUtil.checkCallersLocationPermission(eq(mPackageName), eq(mFeatureId), + anyInt(), anyBoolean(), nullable(String.class))).thenReturn(true); when(mockPermissionUtil.isLocationModeEnabled()).thenReturn(true); when(mockNative.isReady()).thenReturn(true); when(mockNative.rangeRequest(anyInt(), any(RangingRequest.class), anyBoolean())).thenReturn( @@ -265,7 +267,8 @@ public class RttServiceImplTest extends WifiBaseTest { // (1) request 10 ranging operations for (int i = 0; i < numIter; ++i) { - mDut.startRanging(mockIbinder, mPackageName, null, requests[i], mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, requests[i], + mockCallback); } mMockLooper.dispatchAll(); @@ -324,7 +327,7 @@ public class RttServiceImplTest extends WifiBaseTest { doAnswer(answer).when(mockAwareManagerBinder).requestMacAddresses(anyInt(), any(), any()); // issue request - mDut.startRanging(mockIbinder, mPackageName, null, request, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, request, mockCallback); mMockLooper.dispatchAll(); // verify that requested with MAC address translated from the PeerHandle issued to Native @@ -386,13 +389,14 @@ public class RttServiceImplTest extends WifiBaseTest { // (1) request 10 ranging operations: fail the first one when(mockNative.rangeRequest(anyInt(), any(RangingRequest.class), anyBoolean())).thenReturn( false); - mDut.startRanging(mockIbinder, mPackageName, null, requests[0], mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, requests[0], mockCallback); mMockLooper.dispatchAll(); when(mockNative.rangeRequest(anyInt(), any(RangingRequest.class), anyBoolean())).thenReturn( true); for (int i = 1; i < numIter; ++i) { - mDut.startRanging(mockIbinder, mPackageName, null, requests[i], mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, requests[i], + mockCallback); } mMockLooper.dispatchAll(); @@ -444,7 +448,7 @@ public class RttServiceImplTest extends WifiBaseTest { RttTestUtils.getDummyRangingResults(request); // (1) request ranging operation - mDut.startRanging(mockIbinder, mPackageName, null, request, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, request, mockCallback); mMockLooper.dispatchAll(); // (2) verify that request issued to native @@ -452,8 +456,8 @@ public class RttServiceImplTest extends WifiBaseTest { verifyWakeupSet(true, 0); // (3) native calls back with result - should get a FAILED callback - when(mockPermissionUtil.checkCallersLocationPermission(eq(mPackageName), - anyInt(), anyBoolean())).thenReturn(false); + when(mockPermissionUtil.checkCallersLocationPermission(eq(mPackageName), eq(mFeatureId), + anyInt(), anyBoolean(), nullable(String.class))).thenReturn(false); mDut.onRangingResults(mIntCaptor.getValue(), results.second); mMockLooper.dispatchAll(); @@ -489,7 +493,8 @@ public class RttServiceImplTest extends WifiBaseTest { // (1) request 10 ranging operations: even/odd with different UIDs for (int i = 0; i < numIter; ++i) { mDut.fakeUid = mDefaultUid + i % 2; - mDut.startRanging(mockIbinder, mPackageName, null, requests[i], mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, requests[i], + mockCallback); } mMockLooper.dispatchAll(); @@ -564,7 +569,7 @@ public class RttServiceImplTest extends WifiBaseTest { RttTestUtils.getDummyRangingResults(request); // (1) request ranging operation - mDut.startRanging(mockIbinder, mPackageName, ws, request, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, ws, request, mockCallback); mMockLooper.dispatchAll(); verify(mockIbinder).linkToDeath(mDeathRecipientCaptor.capture(), anyInt()); @@ -614,7 +619,8 @@ public class RttServiceImplTest extends WifiBaseTest { RttTestUtils.getDummyRangingResults(request); // (1) request ranging operation - mDut.startRanging(mockIbinder, mPackageName, worksourceRequest, request, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, worksourceRequest, request, + mockCallback); mMockLooper.dispatchAll(); // (2) verify that request issued to native @@ -660,7 +666,8 @@ public class RttServiceImplTest extends WifiBaseTest { RttTestUtils.getDummyRangingResults(request); // (1) request ranging operation - mDut.startRanging(mockIbinder, mPackageName, worksourceRequest, request, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, worksourceRequest, request, + mockCallback); mMockLooper.dispatchAll(); // (2) verify that request issued to native @@ -698,7 +705,7 @@ public class RttServiceImplTest extends WifiBaseTest { RttTestUtils.getDummyRangingResults(request); // (1) request ranging operation - mDut.startRanging(mockIbinder, mPackageName, null, request, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, request, mockCallback); mMockLooper.dispatchAll(); // (2) verify that request issued to native @@ -749,7 +756,7 @@ public class RttServiceImplTest extends WifiBaseTest { null, null, null, 0)); // (1) request ranging operation - mDut.startRanging(mockIbinder, mPackageName, null, request, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, request, mockCallback); mMockLooper.dispatchAll(); // (2) verify that request issued to native @@ -792,7 +799,7 @@ public class RttServiceImplTest extends WifiBaseTest { } // (1) request ranging operation - mDut.startRanging(mockIbinder, mPackageName, null, request, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, request, mockCallback); mMockLooper.dispatchAll(); // (2) verify that request issued to native @@ -845,7 +852,7 @@ public class RttServiceImplTest extends WifiBaseTest { PackageManager.PERMISSION_DENIED); // (1) request ranging operation - mDut.startRanging(mockIbinder, mPackageName, null, request, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, request, mockCallback); mMockLooper.dispatchAll(); // (2) verify that request issued to native @@ -885,8 +892,8 @@ public class RttServiceImplTest extends WifiBaseTest { RttTestUtils.getDummyRangingResults(request2); // (1) request 2 ranging operation - mDut.startRanging(mockIbinder, mPackageName, null, request1, mockCallback); - mDut.startRanging(mockIbinder, mPackageName, null, request2, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, request1, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, request2, mockCallback); mMockLooper.dispatchAll(); // verify that request 1 issued to native @@ -957,7 +964,7 @@ public class RttServiceImplTest extends WifiBaseTest { // (1) issue a request at time t1: should be dispatched since first one! clock.time = 100; - mDut.startRanging(mockIbinder, mPackageName, null, request1, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, request1, mockCallback); mMockLooper.dispatchAll(); verify(mockNative).rangeRequest(mIntCaptor.capture(), eq(request1), eq(true)); @@ -972,14 +979,14 @@ public class RttServiceImplTest extends WifiBaseTest { // (2) issue a request at time t2 = t1 + 0.5 gap: should be rejected (throttled) clock.time = 100 + BACKGROUND_PROCESS_EXEC_GAP_MS / 2; - mDut.startRanging(mockIbinder, mPackageName, null, request2, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, request2, mockCallback); mMockLooper.dispatchAll(); cbInorder.verify(mockCallback).onRangingFailure(RangingResultCallback.STATUS_CODE_FAIL); // (3) issue a request at time t3 = t1 + 1.1 gap: should be dispatched since enough time clock.time = 100 + BACKGROUND_PROCESS_EXEC_GAP_MS * 11 / 10; - mDut.startRanging(mockIbinder, mPackageName, null, request3, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, request3, mockCallback); mMockLooper.dispatchAll(); verify(mockNative).rangeRequest(mIntCaptor.capture(), eq(request3), eq(true)); @@ -997,7 +1004,7 @@ public class RttServiceImplTest extends WifiBaseTest { ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND); clock.time = clock.time + 5; - mDut.startRanging(mockIbinder, mPackageName, null, request4, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, request4, mockCallback); mMockLooper.dispatchAll(); verify(mockNative).rangeRequest(mIntCaptor.capture(), eq(request4), eq(true)); @@ -1015,7 +1022,7 @@ public class RttServiceImplTest extends WifiBaseTest { ActivityManager.RunningAppProcessInfo.IMPORTANCE_GONE); clock.time = clock.time + 5; - mDut.startRanging(mockIbinder, mPackageName, null, request5, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, request5, mockCallback); mMockLooper.dispatchAll(); cbInorder.verify(mockCallback).onRangingFailure(RangingResultCallback.STATUS_CODE_FAIL); @@ -1088,7 +1095,7 @@ public class RttServiceImplTest extends WifiBaseTest { // (1) issue a request at time t1 for {10}: should be dispatched since first one! clock.time = 100; - mDut.startRanging(mockIbinder, mPackageName, wsReq1, request1, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, wsReq1, request1, mockCallback); mMockLooper.dispatchAll(); verify(mockNative).rangeRequest(mIntCaptor.capture(), eq(request1), eq(true)); @@ -1104,7 +1111,7 @@ public class RttServiceImplTest extends WifiBaseTest { // (2) issue a request at time t2 = t1 + 0.5 gap for {10,20}: should be dispatched since // uid=20 should not be throttled clock.time = 100 + BACKGROUND_PROCESS_EXEC_GAP_MS / 2; - mDut.startRanging(mockIbinder, mPackageName, wsReq2, request2, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, wsReq2, request2, mockCallback); mMockLooper.dispatchAll(); verify(mockNative).rangeRequest(mIntCaptor.capture(), eq(request2), eq(true)); @@ -1119,7 +1126,7 @@ public class RttServiceImplTest extends WifiBaseTest { // (3) issue a request at t3 = t1 + 1.1 * gap for {10}: should be rejected (throttled) clock.time = 100 + BACKGROUND_PROCESS_EXEC_GAP_MS * 11 / 10; - mDut.startRanging(mockIbinder, mPackageName, wsReq1, request3, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, wsReq1, request3, mockCallback); mMockLooper.dispatchAll(); cbInorder.verify(mockCallback).onRangingFailure(RangingResultCallback.STATUS_CODE_FAIL); @@ -1173,7 +1180,7 @@ public class RttServiceImplTest extends WifiBaseTest { WorkSource ws = new WorkSource(10); // 1. issue a request - mDut.startRanging(mockIbinder, mPackageName, ws, request, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, ws, request, mockCallback); mMockLooper.dispatchAll(); verify(mockNative).rangeRequest(mIntCaptor.capture(), eq(request), eq(true)); @@ -1183,7 +1190,8 @@ public class RttServiceImplTest extends WifiBaseTest { for (int i = 0; i < RttServiceImpl.MAX_QUEUED_PER_UID + 10; ++i) { WorkSource wsExtra = new WorkSource(ws); wsExtra.add(11 + i); - mDut.startRanging(mockIbinder, mPackageName, wsExtra, request, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, wsExtra, request, + mockCallback); } mMockLooper.dispatchAll(); @@ -1239,7 +1247,8 @@ public class RttServiceImplTest extends WifiBaseTest { InOrder nativeInorder = inOrder(mockNative); // 1. issue a request - mDut.startRanging(mockIbinder, mPackageName, useUids ? null : ws, request, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, useUids ? null : ws, request, + mockCallback); mMockLooper.dispatchAll(); nativeInorder.verify(mockNative).rangeRequest(mIntCaptor.capture(), eq(request), eq(true)); @@ -1247,7 +1256,7 @@ public class RttServiceImplTest extends WifiBaseTest { // 2. issue FLOOD LEVEL requests + 10: should get 11 failures (10 extra + 1 original) for (int i = 0; i < RttServiceImpl.MAX_QUEUED_PER_UID + 10; ++i) { - mDut.startRanging(mockIbinder, mPackageName, useUids ? null : ws, request, + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, useUids ? null : ws, request, mockCallback); } mMockLooper.dispatchAll(); @@ -1266,7 +1275,8 @@ public class RttServiceImplTest extends WifiBaseTest { verifyWakeupSet(true, 0); // 4. issue a request: don't expect a failure - mDut.startRanging(mockIbinder, mPackageName, useUids ? null : ws, request, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, useUids ? null : ws, request, + mockCallback); mMockLooper.dispatchAll(); // 5. clear queue @@ -1338,8 +1348,8 @@ public class RttServiceImplTest extends WifiBaseTest { IRttCallback mockCallback3 = mock(IRttCallback.class); // (1) request 2 ranging operations: request 1 should be sent to HAL - mDut.startRanging(mockIbinder, mPackageName, null, request1, mockCallback); - mDut.startRanging(mockIbinder, mPackageName, null, request2, mockCallback2); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, request1, mockCallback); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, request2, mockCallback2); mMockLooper.dispatchAll(); verify(mockNative).rangeRequest(mIntCaptor.capture(), eq(request1), eq(true)); @@ -1367,7 +1377,7 @@ public class RttServiceImplTest extends WifiBaseTest { verifyWakeupCancelled(); // (3) issue another request: it should fail - mDut.startRanging(mockIbinder, mPackageName, null, request3, mockCallback3); + mDut.startRanging(mockIbinder, mPackageName, mFeatureId, null, request3, mockCallback3); mMockLooper.dispatchAll(); verify(mockCallback3).onRangingFailure( diff --git a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java index 397c61d2d..666028a98 100644 --- a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java +++ b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java @@ -29,8 +29,7 @@ import static com.android.server.wifi.ScanTestUtil.channelsToSpec; import static com.android.server.wifi.ScanTestUtil.computeSingleScanNativeSettings; import static com.android.server.wifi.ScanTestUtil.createRequest; import static com.android.server.wifi.ScanTestUtil.createSingleScanNativeSettingsForChannels; -import static com.android.server.wifi.scanner.WifiScanningServiceImpl.WifiSingleScanStateMachine - .CACHED_SCAN_RESULTS_MAX_AGE_IN_MILLIS; +import static com.android.server.wifi.scanner.WifiScanningServiceImpl.WifiSingleScanStateMachine.CACHED_SCAN_RESULTS_MAX_AGE_IN_MILLIS; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -122,6 +121,7 @@ public class WifiScanningServiceTest extends WifiBaseTest { private static final int TEST_MAX_SCAN_BUCKETS_IN_CAPABILITIES = 8; private static final String TEST_PACKAGE_NAME = "com.test.123"; + private static final String TEST_FEATURE_ID = "test.feature"; private static final String TEST_IFACE_NAME_0 = "wlan0"; private static final String TEST_IFACE_NAME_1 = "wlan1"; private static final WifiScanner.ScanData DUMMY_SCAN_DATA = @@ -2690,7 +2690,7 @@ public class WifiScanningServiceTest extends WifiBaseTest { // Location permission or mode check fail. doThrow(new SecurityException()).when(mWifiPermissionsUtil) - .enforceCanAccessScanResultsForWifiScanner(any(), eq(Binder.getCallingUid()), + .enforceCanAccessScanResultsForWifiScanner(any(), any(), eq(Binder.getCallingUid()), eq(false), eq(false)); Handler handler = mock(Handler.class); @@ -2751,6 +2751,7 @@ public class WifiScanningServiceTest extends WifiBaseTest { Bundle bundle = new Bundle(); bundle.putString(WifiScanner.REQUEST_PACKAGE_NAME_KEY, TEST_PACKAGE_NAME); + bundle.putString(WifiScanner.REQUEST_FEATURE_ID_KEY, TEST_FEATURE_ID); WifiScanner.ScanSettings scanSettings = new WifiScanner.ScanSettings(); // send single scan request (ignoreLocationSettings == true). @@ -2764,7 +2765,8 @@ public class WifiScanningServiceTest extends WifiBaseTest { // Verify the permission check params (ignoreLocationSettings == true). verify(mWifiPermissionsUtil).enforceCanAccessScanResultsForWifiScanner( - eq(TEST_PACKAGE_NAME), eq(Binder.getCallingUid()), eq(true), eq(false)); + eq(TEST_PACKAGE_NAME), eq(TEST_FEATURE_ID), eq(Binder.getCallingUid()), eq(true), + eq(false)); // send single scan request (ignoreLocationSettings == false). scanSettings.ignoreLocationSettings = false; @@ -2777,7 +2779,8 @@ public class WifiScanningServiceTest extends WifiBaseTest { // Verify the permission check params (ignoreLocationSettings == true). verify(mWifiPermissionsUtil).enforceCanAccessScanResultsForWifiScanner( - eq(TEST_PACKAGE_NAME), eq(Binder.getCallingUid()), eq(false), eq(false)); + eq(TEST_PACKAGE_NAME), eq(TEST_FEATURE_ID), eq(Binder.getCallingUid()), eq(false), + eq(false)); // send background scan request (ignoreLocationSettings == true). scanSettings.ignoreLocationSettings = true; @@ -2790,7 +2793,8 @@ public class WifiScanningServiceTest extends WifiBaseTest { // Verify the permission check params (ignoreLocationSettings == false), the field // is ignored for any requests other than single scan. verify(mWifiPermissionsUtil).enforceCanAccessScanResultsForWifiScanner( - eq(TEST_PACKAGE_NAME), eq(Binder.getCallingUid()), eq(false), eq(false)); + eq(TEST_PACKAGE_NAME), eq(TEST_FEATURE_ID), eq(Binder.getCallingUid()), eq(false), + eq(false)); } /** @@ -2815,6 +2819,7 @@ public class WifiScanningServiceTest extends WifiBaseTest { Bundle bundle = new Bundle(); bundle.putString(WifiScanner.REQUEST_PACKAGE_NAME_KEY, TEST_PACKAGE_NAME); + bundle.putString(WifiScanner.REQUEST_FEATURE_ID_KEY, TEST_FEATURE_ID); WifiScanner.ScanSettings scanSettings = new WifiScanner.ScanSettings(); // send single scan request (hideFromAppOps == true). @@ -2828,7 +2833,8 @@ public class WifiScanningServiceTest extends WifiBaseTest { // Verify the permission check params (hideFromAppOps == true). verify(mWifiPermissionsUtil).enforceCanAccessScanResultsForWifiScanner( - eq(TEST_PACKAGE_NAME), eq(Binder.getCallingUid()), eq(false), eq(true)); + eq(TEST_PACKAGE_NAME), eq(TEST_FEATURE_ID), eq(Binder.getCallingUid()), eq(false), + eq(true)); // send single scan request (hideFromAppOps == false). scanSettings.hideFromAppOps = false; @@ -2841,7 +2847,8 @@ public class WifiScanningServiceTest extends WifiBaseTest { // Verify the permission check params (hideFromAppOps == false). verify(mWifiPermissionsUtil).enforceCanAccessScanResultsForWifiScanner( - eq(TEST_PACKAGE_NAME), eq(Binder.getCallingUid()), eq(false), eq(false)); + eq(TEST_PACKAGE_NAME), eq(TEST_FEATURE_ID), eq(Binder.getCallingUid()), eq(false), + eq(false)); // send background scan request (hideFromAppOps == true). scanSettings.hideFromAppOps = true; @@ -2854,7 +2861,8 @@ public class WifiScanningServiceTest extends WifiBaseTest { // Verify the permission check params (hideFromAppOps == false), the field // is ignored for any requests other than single scan. verify(mWifiPermissionsUtil).enforceCanAccessScanResultsForWifiScanner( - eq(TEST_PACKAGE_NAME), eq(Binder.getCallingUid()), eq(false), eq(false)); + eq(TEST_PACKAGE_NAME), eq(TEST_FEATURE_ID), eq(Binder.getCallingUid()), eq(false), + eq(false)); } /** @@ -2878,6 +2886,7 @@ public class WifiScanningServiceTest extends WifiBaseTest { Bundle bundle = new Bundle(); bundle.putString(WifiScanner.REQUEST_PACKAGE_NAME_KEY, TEST_PACKAGE_NAME); + bundle.putString(WifiScanner.REQUEST_FEATURE_ID_KEY, TEST_FEATURE_ID); WifiScanner.ScanSettings scanSettings = new WifiScanner.ScanSettings(); // send single scan request (hideFromAppOps == true, ignoreLocationSettings = true). @@ -2892,7 +2901,8 @@ public class WifiScanningServiceTest extends WifiBaseTest { // Verify that we didn't invoke the location permission check. verify(mWifiPermissionsUtil, never()).enforceCanAccessScanResultsForWifiScanner( - eq(TEST_PACKAGE_NAME), eq(Binder.getCallingUid()), anyBoolean(), anyBoolean()); + eq(TEST_PACKAGE_NAME), eq(TEST_FEATURE_ID), eq(Binder.getCallingUid()), + anyBoolean(), anyBoolean()); } /** @@ -3508,10 +3518,10 @@ public class WifiScanningServiceTest extends WifiBaseTest { // Location permission or mode check fail. doThrow(new SecurityException()) .when(mWifiPermissionsUtil).enforceCanAccessScanResultsForWifiScanner( - TEST_PACKAGE_NAME, Binder.getCallingUid(), false, false); + TEST_PACKAGE_NAME, TEST_FEATURE_ID, Binder.getCallingUid(), false, false); mWifiScanningServiceImpl.getAvailableChannels(WifiScanner.WIFI_BAND_24_GHZ, - TEST_PACKAGE_NAME); + TEST_PACKAGE_NAME, TEST_FEATURE_ID); } /** @@ -3529,10 +3539,10 @@ public class WifiScanningServiceTest extends WifiBaseTest { // has access scan results permission doNothing().when(mWifiPermissionsUtil).enforceCanAccessScanResultsForWifiScanner( - TEST_PACKAGE_NAME, Binder.getCallingUid(), false, false); + TEST_PACKAGE_NAME, TEST_FEATURE_ID, Binder.getCallingUid(), false, false); Bundle bundle = mWifiScanningServiceImpl.getAvailableChannels( - WifiScanner.WIFI_BAND_24_GHZ, TEST_PACKAGE_NAME); + WifiScanner.WIFI_BAND_24_GHZ, TEST_PACKAGE_NAME, TEST_FEATURE_ID); List<Integer> actual = bundle.getIntegerArrayList(GET_AVAILABLE_CHANNELS_EXTRA); List<Integer> expected = Arrays.asList(2400, 2450); diff --git a/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java index 8e3c1bb71..9bd3fe6f6 100644 --- a/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java +++ b/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doAnswer; @@ -83,6 +84,7 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { private static final String TEST_WIFI_STACK_APK_NAME = "com.android.wifi"; private static final String TEST_PACKAGE_NAME = "com.google.somePackage"; + private static final String TEST_FEATURE_ID = "com.google.someFeature"; private static final String INVALID_PACKAGE = "BAD_PACKAGE"; private static final int MANAGED_PROFILE_UID = 1100000; private static final int OTHER_USER_UID = 1200000; @@ -177,7 +179,7 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { setupTestCase(); WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); - codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid, null); } /** @@ -199,7 +201,7 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { setupTestCase(); WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); - codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid, null); } /** @@ -216,7 +218,8 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); try { - codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid, + null); fail("Expected SecurityException is not thrown"); } catch (SecurityException e) { } @@ -243,7 +246,7 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { setupTestCase(); WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); - codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid, null); } /** @@ -264,7 +267,8 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); try { - codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid, + null); fail("Expected SecurityException is not thrown"); } catch (SecurityException e) { } @@ -288,7 +292,8 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); try { - codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid, + null); fail("Expected SecurityException is not thrown"); } catch (SecurityException e) { } @@ -314,7 +319,7 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { setupTestCase(); WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); - codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid, null); } /** @@ -335,7 +340,8 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); try { - codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid, + null); fail("Expected SecurityException is not thrown"); } catch (SecurityException e) { } @@ -363,7 +369,8 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); try { - codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid, + null); fail("Expected SecurityException is not thrown"); } catch (SecurityException e) { } @@ -395,7 +402,8 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); try { - codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid, + null); fail("Expected SecurityException is not thrown"); } catch (SecurityException e) { } @@ -428,7 +436,8 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); try { - codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid, + null); fail("Expected SecurityException is not thrown"); } catch (SecurityException e) { } @@ -464,7 +473,8 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); try { - codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid, + null); fail("Expected SecurityException is not thrown"); } catch (SecurityException e) { } @@ -499,7 +509,7 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); - codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid, null); } /** @@ -532,7 +542,8 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); try { - codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid, + null); fail("Expected SecurityException is not thrown"); } catch (SecurityException e) { } @@ -567,7 +578,7 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); - codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid, null); } /** @@ -599,7 +610,7 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); - codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid, null); } /** @@ -631,7 +642,7 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); - codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid, null); } /** @@ -663,7 +674,7 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); - codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid, null); } /** @@ -676,7 +687,8 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); try { - codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceCanAccessScanResults(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid, + null); fail("Expected SecurityException is not thrown"); } catch (SecurityException e) { } @@ -698,7 +710,7 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { setupTestCase(); WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); - codeUnderTest.enforceLocationPermission(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceLocationPermission(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid); // verify that checking FINE for legacy apps! verify(mMockAppOps).noteOp(eq(AppOpsManager.OPSTR_FINE_LOCATION), anyInt(), anyString(), @@ -721,7 +733,7 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { setupTestCase(); WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); - codeUnderTest.enforceLocationPermission(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceLocationPermission(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid); verify(mMockAppOps) .noteOp(eq(AppOpsManager.OPSTR_FINE_LOCATION), anyInt(), anyString(), any(), any()); } @@ -745,7 +757,7 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); try { - codeUnderTest.enforceLocationPermission(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceLocationPermission(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid); fail("Expected SecurityException not thrown"); } catch (SecurityException e) { // empty @@ -937,7 +949,7 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { setupTestCase(); WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); - codeUnderTest.enforceLocationPermission(TEST_PACKAGE_NAME, mUid); + codeUnderTest.enforceLocationPermission(TEST_PACKAGE_NAME, TEST_FEATURE_ID, mUid); } /** @@ -960,13 +972,13 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { setupTestCase(); WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); - codeUnderTest.enforceCanAccessScanResultsForWifiScanner(TEST_PACKAGE_NAME, mUid, - CHECK_LOCATION_SETTINGS, DONT_HIDE_FROM_APP_OPS); + codeUnderTest.enforceCanAccessScanResultsForWifiScanner(TEST_PACKAGE_NAME, TEST_FEATURE_ID, + mUid, CHECK_LOCATION_SETTINGS, DONT_HIDE_FROM_APP_OPS); verify(mMockAppOps, never()) .unsafeCheckOp(AppOpsManager.OPSTR_FINE_LOCATION, mUid, TEST_PACKAGE_NAME); - verify(mMockAppOps) - .noteOp(AppOpsManager.OPSTR_FINE_LOCATION, mUid, TEST_PACKAGE_NAME, null, null); + verify(mMockAppOps).noteOp(AppOpsManager.OPSTR_FINE_LOCATION, mUid, TEST_PACKAGE_NAME, + TEST_FEATURE_ID, null); } /** @@ -990,8 +1002,8 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { setupTestCase(); WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); - codeUnderTest.enforceCanAccessScanResultsForWifiScanner(TEST_PACKAGE_NAME, mUid, - IGNORE_LOCATION_SETTINGS, HIDE_FROM_APP_OPS); + codeUnderTest.enforceCanAccessScanResultsForWifiScanner(TEST_PACKAGE_NAME, TEST_FEATURE_ID, + mUid, IGNORE_LOCATION_SETTINGS, HIDE_FROM_APP_OPS); verify(mMockAppOps).unsafeCheckOp(AppOpsManager.OPSTR_FINE_LOCATION, mUid, TEST_PACKAGE_NAME); @@ -1022,8 +1034,8 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); try { - codeUnderTest.enforceCanAccessScanResultsForWifiScanner(TEST_PACKAGE_NAME, mUid, - CHECK_LOCATION_SETTINGS, DONT_HIDE_FROM_APP_OPS); + codeUnderTest.enforceCanAccessScanResultsForWifiScanner(TEST_PACKAGE_NAME, + TEST_FEATURE_ID, mUid, CHECK_LOCATION_SETTINGS, DONT_HIDE_FROM_APP_OPS); fail("Expected SecurityException is not thrown"); } catch (SecurityException e) { } @@ -1050,8 +1062,8 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); try { - codeUnderTest.enforceCanAccessScanResultsForWifiScanner(TEST_PACKAGE_NAME, mUid, - CHECK_LOCATION_SETTINGS, DONT_HIDE_FROM_APP_OPS); + codeUnderTest.enforceCanAccessScanResultsForWifiScanner(TEST_PACKAGE_NAME, + TEST_FEATURE_ID, mUid, CHECK_LOCATION_SETTINGS, DONT_HIDE_FROM_APP_OPS); fail("Expected SecurityException is not thrown"); } catch (SecurityException e) { } @@ -1079,8 +1091,8 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); try { - codeUnderTest.enforceCanAccessScanResultsForWifiScanner(TEST_PACKAGE_NAME, mUid, - CHECK_LOCATION_SETTINGS, DONT_HIDE_FROM_APP_OPS); + codeUnderTest.enforceCanAccessScanResultsForWifiScanner(TEST_PACKAGE_NAME, + TEST_FEATURE_ID, mUid, CHECK_LOCATION_SETTINGS, DONT_HIDE_FROM_APP_OPS); fail("Expected SecurityException is not thrown"); } catch (SecurityException e) { } @@ -1107,8 +1119,8 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); try { - codeUnderTest.enforceCanAccessScanResultsForWifiScanner(TEST_PACKAGE_NAME, mUid, - CHECK_LOCATION_SETTINGS, DONT_HIDE_FROM_APP_OPS); + codeUnderTest.enforceCanAccessScanResultsForWifiScanner(TEST_PACKAGE_NAME, + TEST_FEATURE_ID, mUid, CHECK_LOCATION_SETTINGS, DONT_HIDE_FROM_APP_OPS); fail("Expected SecurityException is not thrown"); } catch (SecurityException e) { } @@ -1135,8 +1147,8 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); try { - codeUnderTest.enforceCanAccessScanResultsForWifiScanner(TEST_PACKAGE_NAME, mUid, - CHECK_LOCATION_SETTINGS, DONT_HIDE_FROM_APP_OPS); + codeUnderTest.enforceCanAccessScanResultsForWifiScanner(TEST_PACKAGE_NAME, + TEST_FEATURE_ID, mUid, CHECK_LOCATION_SETTINGS, DONT_HIDE_FROM_APP_OPS); fail("Expected SecurityException is not thrown"); } catch (SecurityException e) { } @@ -1163,8 +1175,8 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { setupTestCase(); WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); - codeUnderTest.enforceCanAccessScanResultsForWifiScanner(TEST_PACKAGE_NAME, mUid, - IGNORE_LOCATION_SETTINGS, DONT_HIDE_FROM_APP_OPS); + codeUnderTest.enforceCanAccessScanResultsForWifiScanner(TEST_PACKAGE_NAME, TEST_FEATURE_ID, + mUid, IGNORE_LOCATION_SETTINGS, DONT_HIDE_FROM_APP_OPS); } /** @@ -1188,8 +1200,8 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { WifiPermissionsUtil codeUnderTest = new WifiPermissionsUtil(mMockPermissionsWrapper, mMockContext, mMockUserManager, mWifiInjector); try { - codeUnderTest.enforceCanAccessScanResultsForWifiScanner(TEST_PACKAGE_NAME, mUid, - CHECK_LOCATION_SETTINGS, DONT_HIDE_FROM_APP_OPS); + codeUnderTest.enforceCanAccessScanResultsForWifiScanner(TEST_PACKAGE_NAME, + TEST_FEATURE_ID, mUid, CHECK_LOCATION_SETTINGS, DONT_HIDE_FROM_APP_OPS); fail("Expected SecurityException is not thrown"); } catch (SecurityException e) { } @@ -1217,12 +1229,14 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { when(mMockPkgMgr.getApplicationInfoAsUser(eq(TEST_PACKAGE_NAME), eq(0), any())) .thenReturn(mMockApplInfo); when(mMockContext.getPackageManager()).thenReturn(mMockPkgMgr); - when(mMockAppOps.noteOp(AppOpsManager.OPSTR_WIFI_SCAN, mUid, TEST_PACKAGE_NAME, null, null)) - .thenReturn(mWifiScanAllowApps); - when(mMockAppOps.noteOp(AppOpsManager.OPSTR_COARSE_LOCATION, mUid, TEST_PACKAGE_NAME, null, - null)).thenReturn(mAllowCoarseLocationApps); - when(mMockAppOps.noteOp(AppOpsManager.OPSTR_FINE_LOCATION, mUid, TEST_PACKAGE_NAME, null, - null)).thenReturn(mAllowFineLocationApps); + when(mMockAppOps.noteOp(AppOpsManager.OPSTR_WIFI_SCAN, mUid, TEST_PACKAGE_NAME, + TEST_FEATURE_ID, null)).thenReturn(mWifiScanAllowApps); + when(mMockAppOps.noteOp(eq(AppOpsManager.OPSTR_COARSE_LOCATION), eq(mUid), + eq(TEST_PACKAGE_NAME), eq(TEST_FEATURE_ID), nullable(String.class))) + .thenReturn(mAllowCoarseLocationApps); + when(mMockAppOps.noteOp(eq(AppOpsManager.OPSTR_FINE_LOCATION), eq(mUid), + eq(TEST_PACKAGE_NAME), eq(TEST_FEATURE_ID), nullable(String.class))) + .thenReturn(mAllowFineLocationApps); when(mMockAppOps.unsafeCheckOp(AppOpsManager.OPSTR_FINE_LOCATION, mUid, TEST_PACKAGE_NAME)) .thenReturn(mAllowFineLocationApps); if (mThrowSecurityException) { |