From b47b977afa522c696a713d9f7e5b3bdf7f2233c2 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Thu, 24 Aug 2017 23:32:21 +0900 Subject: [PATCH] Ensure that Ethernet is supported if the service is running. Currently, it's possible for isNetworkSupported() to return false for TYPE_ETHERNET even if the device could otherwise support Ethernet (e.g., via a USB host adapter). This can lead to APIs APIs such as getActiveNetworkInfo and CONNECTIVITY_ACTION behaving as if Ethernet was not present, even if it's connected. Reduce the chance of this sort of misconfiguration by ensuring that if the Ethernet service is running, isNetworkSupported will return true for TYPE_ETHERNET. OEMs that would like the function to return false should avoid starting the Ethernet service. (cherry picked from commit c4f38c2e5bf0f57299e1e86543c82e4e578c4ab6) Bug: 37359230 Test: ConnectivityManagerTest passes on aosp_bullhead Change-Id: Iad8884bf7d12bbf661e5502b31f052a6e8457a6f Merged-In: Iad8884bf7d12bbf661e5502b31f052a6e8457a6f --- .../net/src/android/net/cts/ConnectivityManagerTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java index cd6dbb2441..e98dfcc61b 100644 --- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java +++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java @@ -37,6 +37,7 @@ import android.net.NetworkInfo.DetailedState; import android.net.NetworkInfo.State; import android.net.NetworkRequest; import android.net.wifi.WifiManager; +import android.os.Looper; import android.os.SystemProperties; import android.system.Os; import android.system.OsConstants; @@ -110,6 +111,7 @@ public class ConnectivityManagerTest extends AndroidTestCase { @Override protected void setUp() throws Exception { super.setUp(); + Looper.prepare(); mContext = getContext(); mCm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); @@ -279,11 +281,10 @@ public class ConnectivityManagerTest extends AndroidTestCase { } private boolean isSupported(int networkType) { - // Change-Id I02eb5f22737720095f646f8db5c87fd66da129d6 added VPN support - // to all devices directly in software, independent of any external - // configuration. return mNetworks.containsKey(networkType) || - (networkType == ConnectivityManager.TYPE_VPN); + (networkType == ConnectivityManager.TYPE_VPN) || + (networkType == ConnectivityManager.TYPE_ETHERNET && + mContext.getSystemService(Context.ETHERNET_SERVICE) != null); } public void testIsNetworkSupported() {