Android Ethernet and Wi-Fi at the same time

user2492861 picture user2492861 · Aug 9, 2013 · Viewed 17.2k times · Source

I have a small TV box device running Android. Whenever I bring up the Wi-Fi interface, the Ethernet interface is disconnected. If I then bring up the Ethernet device, the Wi-Fi interface. I have tried various methods including using the command line to manually bring up the interfaces and the same issue occurs. I want to be able to connect to the Wi-Fi and have it as my default gateway but then also be connected to the Ethernet port to route certain traffic over that interface. Obviously this is possible to do in Linux so there must be a way... does anybody know what it is that is tearing down the interfaces when the other is initiated...

Answer

user2492861 picture user2492861 · Nov 20, 2013

This is a restriction in Android. It purposely only allows one connection to be up at a time and has a handler in the 'ConnectivityServices.java' file that tears down a 'non-preferred' network when a network with a priority is enabled. This is also what brings wifi up and tears down cellular data connections when in range of a recognised hotspot...

Just in case anybody ever needs this, here is what I did :

Download the AOSP source code for the version of Android on the device.

Edit the 'ConnectivityServices.java' file accordingly. I basically just commented out the command in the failover command in the connection change handler. I don't have the source code in front of me so message me if you need to know what I did here...

Anyway, then build the AOSP source code on your machine.

Once completed, grab the 'services.jar' file in the /dexclasses/ directory that has been created. Extract it using WinRAR then copy the 'classes.dex' file out of the .jar file to a separate directory. Use this to extract the classes.dex : https://code.google.com/p/smali/ Grab the 'ConnectivityServices.smali' file and keep it safe.

From the device Go onto the device you wish to enable both network interfaces on and copy the /system/framework/services.jar file to a PC. Extract it using WinRAR then copy the 'classes.dex' file out of the .jar file to a separate directory. Use the Java Smali command to extract the classes.dex.

Take the ConnectivityServices.smali file from the AOSP and put it in the directly you have just extracted using the classes.dex on the device. Might be a good idea to make a backup of the original ConnectivityServices.smali file before overwriting it.

Then simple repackage the classes.dex file using the baksmali command. Copy the classes.dex file into the original services.jar file using winRAR. Again, take a backup of the original but then overwrite it in the .jar file.

Then simply put the new services.jar file back on the device in the /system/framework/ directory.

Then reboot - it will take longer than normal to boot up on the first time.