Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Ethernet and Wi-Fi at the same time

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...

like image 642
user2492861 Avatar asked Aug 09 '13 09:08

user2492861


2 Answers

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.

like image 144
user2492861 Avatar answered Oct 07 '22 22:10

user2492861


There is a simpler way, which doesn't require you to build AOSP matching your device. You can simply modify smali-decompiled code and recompile it. Use https://github.com/android/platform_frameworks_base/blob/master/services/java/com/android/server/ConnectivityService.java for comparizon. Something along this lines:

adb pull /system/framework/services.jar
cp services.jar services.jar.bak
unzip services.jar classes.dex
java -jar baksmali.jar classes.dex

Edit out/com/android/server/ConnectivityService.smali in handleConnect(), so that this will be the result:

// if this is a default net and other default is running
// kill the one not preferred
if (false && mNetConfigs[newNetType].isDefault()) {
  if (mActiveDefaultNetwork != -1 && mActiveDefaultNetwork != newNetType) { ...

I made the following change:

aget-object v5, v5, v1

invoke-virtual {v5}, Landroid/net/NetworkConfig;->isDefault()Z

move-result v5

#if-eqz v5, :cond_a6 # changed to unconditional jump
goto :cond_a6

Recompile, repack, push. Then reboot and test.

java -jar smali.jar -o classes.dex out
zip services.jar classes.dex
adb push services.jar /system/framework/services.jar
like image 25
Jeremitu Avatar answered Oct 07 '22 21:10

Jeremitu