Declare support for Ethernet if the service is running.
On some devices, support for TYPE_ETHERNET is not specified in the networkAttributes config resource, even though the device is capable of supporting Ethernet (e.g., via USB host adapters). This leads to Ethernet working but various connectivity APIs behaving as if it was not - for example, no CONNECTIVITY_ACTION broadcasts will be issues when it connects or disconnects. Ensure that ConnectivityService always treats Ethernet as available if the service is running. Currently the service is started if the device supports FEATURE_ETHERNET or FEATURE_USB_HOST. (cherry picked from commit 7bbe3eee52c08ee92a81b7bed395ca5499554cc4) Bug: 37359230 Test: bullhead builds, boots Test: ConnectivityServiceTest passes Test: Ethernet is available even if removed from networkAttributes resource Test: ConnectivityManagerTest CTS test passes Change-Id: I9b6db4edeaf966ee6715011dd92770b9d25dd938 Merged-In: I9b6db4edeaf966ee6715011dd92770b9d25dd938
This commit is contained in:
@@ -19,6 +19,7 @@ package com.android.server;
|
|||||||
import static android.Manifest.permission.RECEIVE_DATA_ACTIVITY_CHANGE;
|
import static android.Manifest.permission.RECEIVE_DATA_ACTIVITY_CHANGE;
|
||||||
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
|
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
|
||||||
import static android.net.ConnectivityManager.NETID_UNSET;
|
import static android.net.ConnectivityManager.NETID_UNSET;
|
||||||
|
import static android.net.ConnectivityManager.TYPE_ETHERNET;
|
||||||
import static android.net.ConnectivityManager.TYPE_NONE;
|
import static android.net.ConnectivityManager.TYPE_NONE;
|
||||||
import static android.net.ConnectivityManager.TYPE_VPN;
|
import static android.net.ConnectivityManager.TYPE_VPN;
|
||||||
import static android.net.ConnectivityManager.getNetworkTypeName;
|
import static android.net.ConnectivityManager.getNetworkTypeName;
|
||||||
@@ -90,6 +91,7 @@ import android.os.PowerManager;
|
|||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ResultReceiver;
|
import android.os.ResultReceiver;
|
||||||
|
import android.os.ServiceManager;
|
||||||
import android.os.ServiceSpecificException;
|
import android.os.ServiceSpecificException;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
@@ -781,6 +783,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
mNetworksDefined++; // used only in the log() statement below.
|
mNetworksDefined++; // used only in the log() statement below.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do the same for Ethernet, since it's often not specified in the configs, although many
|
||||||
|
// devices can use it via USB host adapters.
|
||||||
|
if (mNetConfigs[TYPE_ETHERNET] == null && hasService(Context.ETHERNET_SERVICE)) {
|
||||||
|
mLegacyTypeTracker.addSupportedType(TYPE_ETHERNET);
|
||||||
|
mNetworksDefined++;
|
||||||
|
}
|
||||||
|
|
||||||
if (VDBG) log("mNetworksDefined=" + mNetworksDefined);
|
if (VDBG) log("mNetworksDefined=" + mNetworksDefined);
|
||||||
|
|
||||||
mProtectedNetworks = new ArrayList<Integer>();
|
mProtectedNetworks = new ArrayList<Integer>();
|
||||||
@@ -5546,6 +5555,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
return new WakeupMessage(c, h, s, cmd, 0, 0, obj);
|
return new WakeupMessage(c, h, s, cmd, 0, 0, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
public boolean hasService(String name) {
|
||||||
|
return ServiceManager.checkService(name) != null;
|
||||||
|
}
|
||||||
|
|
||||||
private void logDefaultNetworkEvent(NetworkAgentInfo newNai, NetworkAgentInfo prevNai) {
|
private void logDefaultNetworkEvent(NetworkAgentInfo newNai, NetworkAgentInfo prevNai) {
|
||||||
int newNetid = NETID_UNSET;
|
int newNetid = NETID_UNSET;
|
||||||
int prevNetid = NETID_UNSET;
|
int prevNetid = NETID_UNSET;
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ package com.android.server;
|
|||||||
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
|
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
|
||||||
import static android.net.ConnectivityManager.TYPE_ETHERNET;
|
import static android.net.ConnectivityManager.TYPE_ETHERNET;
|
||||||
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
||||||
|
import static android.net.ConnectivityManager.TYPE_MOBILE_FOTA;
|
||||||
|
import static android.net.ConnectivityManager.TYPE_MOBILE_MMS;
|
||||||
import static android.net.ConnectivityManager.TYPE_NONE;
|
import static android.net.ConnectivityManager.TYPE_NONE;
|
||||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||||
import static android.net.ConnectivityManager.getNetworkTypeName;
|
import static android.net.ConnectivityManager.getNetworkTypeName;
|
||||||
@@ -781,6 +783,13 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
|||||||
return new FakeWakeupMessage(context, handler, cmdName, cmd, 0, 0, obj);
|
return new FakeWakeupMessage(context, handler, cmdName, cmd, 0, 0, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasService(String name) {
|
||||||
|
// Currenty, the only relevant service that ConnectivityService checks for is
|
||||||
|
// ETHERNET_SERVICE.
|
||||||
|
return Context.ETHERNET_SERVICE.equals(name);
|
||||||
|
}
|
||||||
|
|
||||||
public WrappedNetworkMonitor getLastCreatedWrappedNetworkMonitor() {
|
public WrappedNetworkMonitor getLastCreatedWrappedNetworkMonitor() {
|
||||||
return mLastCreatedNetworkMonitor;
|
return mLastCreatedNetworkMonitor;
|
||||||
}
|
}
|
||||||
@@ -928,6 +937,13 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
|||||||
// will fail. Failing here is much easier to debug.
|
// will fail. Failing here is much easier to debug.
|
||||||
assertTrue(mCm.isNetworkSupported(TYPE_WIFI));
|
assertTrue(mCm.isNetworkSupported(TYPE_WIFI));
|
||||||
assertTrue(mCm.isNetworkSupported(TYPE_MOBILE));
|
assertTrue(mCm.isNetworkSupported(TYPE_MOBILE));
|
||||||
|
assertTrue(mCm.isNetworkSupported(TYPE_MOBILE_MMS));
|
||||||
|
assertFalse(mCm.isNetworkSupported(TYPE_MOBILE_FOTA));
|
||||||
|
|
||||||
|
// Check that TYPE_ETHERNET is supported. Unlike the asserts above, which only validate our
|
||||||
|
// mocks, this assert exercises the ConnectivityService code path that ensures that
|
||||||
|
// TYPE_ETHERNET is supported if the ethernet service is running.
|
||||||
|
assertTrue(mCm.isNetworkSupported(TYPE_ETHERNET));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
|
|||||||
Reference in New Issue
Block a user