summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2020-01-30 22:40:38 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-01-30 22:40:38 +0000
commiteca23f47586563772c697ac9ca1d37f77347230f (patch)
tree30861013932649599180010bd4c55ac8b5234788
parentdf42004562d45ae47d47204ece640e78cd0602ee (diff)
parenteca205151fe45f43c3f273e61de4d240190f6353 (diff)
Merge "User saved open network post connection broadcast."
-rw-r--r--service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java26
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java51
2 files changed, 71 insertions, 6 deletions
diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
index 00ac1b34c..b2e06c857 100644
--- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
+++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
@@ -1552,7 +1552,6 @@ public class WifiNetworkSuggestionsManager {
if (matchingExtNetworkSuggestions == null
|| matchingExtNetworkSuggestions.isEmpty()) return;
- mWifiMetrics.incrementNetworkSuggestionApiNumConnectSuccess();
if (connectedNetwork.fromWifiNetworkSuggestion) {
// Find subset of network suggestions from app suggested the connected network.
matchingExtNetworkSuggestions =
@@ -1563,14 +1562,29 @@ public class WifiNetworkSuggestionsManager {
Log.wtf(TAG, "Current connected network suggestion is missing!");
return;
}
+ // Store the set of matching network suggestions.
+ mActiveNetworkSuggestionsMatchingConnection =
+ new HashSet<>(matchingExtNetworkSuggestions);
} else {
- //TODO(143173638) open user saved network should only post notification to one of
- // carrier app.
+ if (connectedNetwork.isOpenNetwork()) {
+ // For saved open network, found the matching suggestion from carrier privileged
+ // apps. As we only expect one suggestor app to take action on post connection, if
+ // multiple apps suggested matched suggestions, framework will randomly pick one.
+ matchingExtNetworkSuggestions = matchingExtNetworkSuggestions.stream()
+ .filter(x -> x.perAppInfo.carrierId != TelephonyManager.UNKNOWN_CARRIER_ID
+ || mWifiPermissionsUtil
+ .checkNetworkCarrierProvisioningPermission(x.perAppInfo.uid))
+ .limit(1).collect(Collectors.toSet());
+ if (matchingExtNetworkSuggestions.isEmpty()) {
+ if (mVerboseLoggingEnabled) {
+ Log.v(TAG, "No suggestion matched connected user saved open network.");
+ }
+ return;
+ }
+ }
}
- // Store the set of matching network suggestions.
- mActiveNetworkSuggestionsMatchingConnection =
- new HashSet<>(matchingExtNetworkSuggestions);
+ mWifiMetrics.incrementNetworkSuggestionApiNumConnectSuccess();
// Find subset of network suggestions have set |isAppInteractionRequired|.
Set<ExtendedWifiNetworkSuggestion> matchingExtNetworkSuggestionsWithReqAppInteraction =
matchingExtNetworkSuggestions.stream()
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
index 874b5240a..d8b3632fd 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
@@ -920,6 +920,57 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
mInorder.verifyNoMoreInteractions();
}
+ /**
+ * Verify if a user saved network connected and it can match suggestions. Only the
+ * carrier-privileged suggestor app can receive the broadcast if
+ * {@link WifiNetworkSuggestion#isAppInteractionRequired} flag set to true.
+ */
+ @Test
+ public void testOnSavedOpenNetworkConnectionSuccessWithMultipleMatch() throws Exception {
+ assertTrue(mWifiNetworkSuggestionsManager
+ .registerSuggestionConnectionStatusListener(mBinder, mListener,
+ NETWORK_CALLBACK_ID, TEST_PACKAGE_1));
+ when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(TEST_UID_1))
+ .thenReturn(true);
+ WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
+ WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion(
+ new WifiConfiguration(config), null, true, false, true, true,
+ false);
+ List<WifiNetworkSuggestion> networkSuggestionList1 =
+ new ArrayList<WifiNetworkSuggestion>() {{
+ add(networkSuggestion1);
+ }};
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1,
+ TEST_PACKAGE_1, TEST_FEATURE));
+
+ WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion(
+ new WifiConfiguration(config), null, true, false, true, true,
+ false);
+ List<WifiNetworkSuggestion> networkSuggestionList2 =
+ new ArrayList<WifiNetworkSuggestion>() {{
+ add(networkSuggestion2);
+ }};
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_2,
+ TEST_PACKAGE_2, TEST_FEATURE));
+ mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_2);
+
+ // Simulate connecting to the user saved open network.
+ WifiConfiguration connectNetwork = new WifiConfiguration(config);
+ mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded(
+ WifiMetrics.ConnectionEvent.FAILURE_NONE, connectNetwork, TEST_BSSID);
+
+ verify(mWifiMetrics).incrementNetworkSuggestionApiNumConnectSuccess();
+ // Verify that the correct broadcast was sent out.
+ mInorder.verify(mWifiPermissionsUtil).enforceCanAccessScanResults(eq(TEST_PACKAGE_1),
+ eq(TEST_FEATURE), eq(TEST_UID_1), nullable(String.class));
+ validatePostConnectionBroadcastSent(TEST_PACKAGE_1, networkSuggestion1);
+
+ // Verify no more broadcast were sent out.
+ mInorder.verifyNoMoreInteractions();
+ }
+
@Test
public void testOnNetworkConnectionFailureWithOneMatchButCallbackOnBinderDied()
throws Exception {