diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2018-10-05 20:32:22 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-10-05 20:32:22 +0000 |
commit | da556945c630d816b1a195b7d8064575857dfd4f (patch) | |
tree | 1db4d73629ceb5cb119c5d1b789fa09891cb6bbe | |
parent | 574dad6518cec201bab9cee3942995094e4a6b40 (diff) | |
parent | 0332aab1d0290e6ac88a4197caf77138c9041bdb (diff) |
Merge "passpoint-r2: suppress Wi-Fi no internet access notification for OSU"
-rw-r--r-- | service/java/com/android/server/wifi/hotspot2/OsuNetworkConnection.java | 21 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/hotspot2/OsuNetworkConnectionTest.java | 31 |
2 files changed, 47 insertions, 5 deletions
diff --git a/service/java/com/android/server/wifi/hotspot2/OsuNetworkConnection.java b/service/java/com/android/server/wifi/hotspot2/OsuNetworkConnection.java index 73dcca505..12a99899b 100644 --- a/service/java/com/android/server/wifi/hotspot2/OsuNetworkConnection.java +++ b/service/java/com/android/server/wifi/hotspot2/OsuNetworkConnection.java @@ -16,6 +16,8 @@ package com.android.server.wifi.hotspot2; +import static android.net.NetworkCapabilities.NET_CAPABILITY_TRUSTED; + import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -173,6 +175,12 @@ public class OsuNetworkConnection { } WifiConfiguration config = new WifiConfiguration(); config.SSID = "\"" + ssid.toString() + "\""; + + // To suppress Wi-Fi has no internet access notification. + config.noInternetAccessExpected = true; + + // Do not save this network + config.ephemeral = true; if (TextUtils.isEmpty(nai)) { config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); } else { @@ -185,11 +193,18 @@ public class OsuNetworkConnection { Log.e(TAG, "Unable to add network"); return false; } - NetworkRequest networkRequest = null; - networkRequest = new NetworkRequest.Builder() - .addTransportType(NetworkCapabilities.TRANSPORT_WIFI).build(); + + // NET_CAPABILITY_TRUSTED is added by builder by default. + // But for ephemeral network, the capability needs to be removed + // as wifi stack creates network agent without the capability. + // That could cause connectivity service not to find the matching agent. + NetworkRequest networkRequest = new NetworkRequest.Builder() + .addTransportType(NetworkCapabilities.TRANSPORT_WIFI).removeCapability( + NET_CAPABILITY_TRUSTED).build(); mConnectivityManager.requestNetwork(networkRequest, mConnectivityCallbacks, mHandler, TIMEOUT_MS); + + // TODO(b/112195429): replace it with new connectivity API. if (!mWifiManager.enableNetwork(mNetworkId, true)) { Log.e(TAG, "Unable to enable network " + mNetworkId); disconnectIfNeeded(); diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/OsuNetworkConnectionTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/OsuNetworkConnectionTest.java index a331e9887..ae1f6ce03 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/OsuNetworkConnectionTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/OsuNetworkConnectionTest.java @@ -16,6 +16,8 @@ package com.android.server.wifi.hotspot2; +import static android.net.NetworkCapabilities.NET_CAPABILITY_TRUSTED; + import static org.junit.Assert.*; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; @@ -55,7 +57,7 @@ import org.mockito.MockitoAnnotations; import java.net.InetAddress; /** - * Unit tests for {@link com.android.server.wifi.hotspot2.PasspointProvisioner}. + * Unit tests for {@link OsuNetworkConnection}. */ @SmallTest public class OsuNetworkConnectionTest { @@ -259,5 +261,30 @@ public class OsuNetworkConnectionTest { mNetworkConnection.disconnectIfNeeded(); verify(mWifiManager).removeNetwork(TEST_NETWORK_ID); } -} + /** + * Verifies that {@link WifiConfiguration} has been created properly for OSU network. + * It is supposed to create a network as ephemeral network and suppress no internet access + * notification. + */ + @Test + public void verifyWifiConfigurationForOsuNetwork() { + mNetworkConnection.init(mHandler); + + assertEquals(true, mNetworkConnection.connect(TEST_SSID, TEST_NAI)); + + ArgumentCaptor<WifiConfiguration> wifiConfigurationCaptor = ArgumentCaptor.forClass( + WifiConfiguration.class); + verify(mWifiManager, times(1)).addNetwork(wifiConfigurationCaptor.capture()); + WifiConfiguration wifiConfiguration = wifiConfigurationCaptor.getValue(); + assertTrue(wifiConfiguration.isNoInternetAccessExpected()); + assertTrue(wifiConfiguration.isEphemeral()); + + ArgumentCaptor<NetworkRequest> networkRequestCaptor = ArgumentCaptor.forClass( + NetworkRequest.class); + verify(mConnectivityManager, times(1)).requestNetwork(networkRequestCaptor.capture(), + any(ConnectivityManager.NetworkCallback.class), any(Handler.class), anyInt()); + assertFalse(networkRequestCaptor.getValue().hasCapability(NET_CAPABILITY_TRUSTED)); + + } +} |