From 0d7d1da50366788ed999c3d28e1ee0d87cfda838 Mon Sep 17 00:00:00 2001 From: Phil Weaver Date: Wed, 22 Jun 2016 16:50:38 -0700 Subject: [PATCH] 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 --- tests/cts/net/appForApi23/AndroidManifest.xml | 2 +- .../net/cts/appForApi23/ConnectivityReceiver.java | 15 +++++++++------ .../android/net/cts/ConnectivityManagerTest.java | 8 ++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/cts/net/appForApi23/AndroidManifest.xml b/tests/cts/net/appForApi23/AndroidManifest.xml index 7203ea553f..ed4cedbc1d 100644 --- a/tests/cts/net/appForApi23/AndroidManifest.xml +++ b/tests/cts/net/appForApi23/AndroidManifest.xml @@ -28,7 +28,7 @@ - + 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 5dd77e85dd..8039a4f943 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.content.Intent; 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 df2baac17e..b8478d246b 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 @@ public class ConnectivityManagerTest extends AndroidTestCase { 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 @@ public class ConnectivityManagerTest extends AndroidTestCase { 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)); }