summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEcco Park <eccopark@google.com>2018-09-18 15:44:23 -0700
committerEcco Park <eccopark@google.com>2018-10-01 06:10:15 +0000
commit0332aab1d0290e6ac88a4197caf77138c9041bdb (patch)
treea79e782d512c4526ef5b21298c4957113ae7f5f4
parent01d1d200d69e83238f44aa5a0e43051125730ecf (diff)
passpoint-r2: suppress Wi-Fi no internet access notification for OSU
set noInternetAccessExpected flag to suppress the no internet notification set ephemeral flag for temporary network. Bug: 116039833 Test: live test with Passpoint R2 service provider AP Test: ./frameworks/opt/net/wifi/tests/wifitests/runtests.sh Change-Id: I2aa41bbec2a5ee265121a972b050af4bb3ca58e1 Signed-off-by: Ecco Park <eccopark@google.com>
-rw-r--r--service/java/com/android/server/wifi/hotspot2/OsuNetworkConnection.java21
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/OsuNetworkConnectionTest.java31
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));
+
+ }
+}