CTS: Only listen to wifi events when toggling wifi
When counting all connectivity changed events, we were failing
on devices with sim cards because we were counting both wifi and
mobile connectivity changes the same. Since the test only
toggles wifi, changing the listener only to pay attention to wifi
changes.
Bug: 29346253
Change-Id: I1ed3b976bc21419218c780d4afc4a5e73f128496
diff --git a/tests/cts/net/appForApi23/AndroidManifest.xml b/tests/cts/net/appForApi23/AndroidManifest.xml
index 7203ea5..ed4cedb 100644
--- a/tests/cts/net/appForApi23/AndroidManifest.xml
+++ b/tests/cts/net/appForApi23/AndroidManifest.xml
@@ -28,7 +28,7 @@
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<intent-filter>
- <action android:name="android.net.cts.appForApi23.getConnectivityActionCount" />
+ <action android:name="android.net.cts.appForApi23.getWifiConnectivityActionCount" />
</intent-filter>
</receiver>
diff --git a/tests/cts/net/appForApi23/src/android/net/cts/appForApi23/ConnectivityReceiver.java b/tests/cts/net/appForApi23/src/android/net/cts/appForApi23/ConnectivityReceiver.java
index 5dd77e8..8039a4f 100644
--- a/tests/cts/net/appForApi23/src/android/net/cts/appForApi23/ConnectivityReceiver.java
+++ b/tests/cts/net/appForApi23/src/android/net/cts/appForApi23/ConnectivityReceiver.java
@@ -21,18 +21,21 @@
import android.net.ConnectivityManager;
public class ConnectivityReceiver extends BroadcastReceiver {
- public static String GET_CONNECTIVITY_ACTION_COUNT =
- "android.net.cts.appForApi23.getConnectivityActionCount";
+ public static String GET_WIFI_CONNECTIVITY_ACTION_COUNT =
+ "android.net.cts.appForApi23.getWifiConnectivityActionCount";
- private static int sConnectivityActionCount = 0;
+ private static int sWifiConnectivityActionCount = 0;
@Override
public void onReceive(Context context, Intent intent) {
if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
- sConnectivityActionCount++;
+ int networkType = intent.getIntExtra(ConnectivityManager.EXTRA_NETWORK_TYPE, 0);
+ if (networkType == ConnectivityManager.TYPE_WIFI) {
+ sWifiConnectivityActionCount++;
+ }
}
- if (GET_CONNECTIVITY_ACTION_COUNT.equals(intent.getAction())) {
- setResultCode(sConnectivityActionCount);
+ if (GET_WIFI_CONNECTIVITY_ACTION_COUNT.equals(intent.getAction())) {
+ setResultCode(sWifiConnectivityActionCount);
}
}
}
diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
index df2baac..b8478d2 100644
--- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
+++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
@@ -77,9 +77,9 @@
private static final String NETWORK_CALLBACK_ACTION =
"ConnectivityManagerTest.NetworkCallbackAction";
- // Intent string to get the number of CONNECTIVITY_ACTION callbacks the test app has seen
- public static final String GET_CONNECTIVITY_ACTION_COUNT =
- "android.net.cts.appForApi23.getConnectivityActionCount";
+ // Intent string to get the number of wifi CONNECTIVITY_ACTION callbacks the test app has seen
+ public static final String GET_WIFI_CONNECTIVITY_ACTION_COUNT =
+ "android.net.cts.appForApi23.getWifiConnectivityActionCount";
// device could have only one interface: data, wifi.
private static final int MIN_NUM_NETWORK_TYPES = 1;
@@ -423,7 +423,7 @@
toggleWifi();
- Intent getConnectivityCount = new Intent(GET_CONNECTIVITY_ACTION_COUNT);
+ Intent getConnectivityCount = new Intent(GET_WIFI_CONNECTIVITY_ACTION_COUNT);
assertEquals(2, sendOrderedBroadcastAndReturnResultCode(
getConnectivityCount, SEND_BROADCAST_TIMEOUT));
}