9

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

3 Answers 3

8

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.

1
  • thanks for your comment! I tied the following (for Android 4.4.2), but without success: I edited my 'frameworks/base/services/java/com/android/server/ConnectivityService.java' file like this: I commented out in the function 'private void handleConnect' both calls 'teardown(thisNet);'. Then I compiled android, BAKSMALIed the compiled and original services.jar, replaced all original 'ConnectivityService*.smali' with the the compiled ones. SMALIed again and replace the services.jar on the android devices. Then I rebooted and still WIFI is disabled when I connect Ethernet. Any help appreciated!
    – bonanza
    Aug 18, 2014 at 17:14
4

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
5
  • thanks a lot! totally worked for me. Just look for the line: invoke-virtual {v5}, Landroid/net/NetworkConfig;->isDefault()Z and make the changes
    – Qiong Wu
    Nov 17, 2015 at 14:07
  • any idea how to do this for Android 5.1?
    – Qiong Wu
    Nov 26, 2015 at 10:25
  • is it possibly here? github.com/CyanogenMod/android_frameworks_base/blob/…
    – Qiong Wu
    Nov 26, 2015 at 10:58
  • for Android 6 it seems that services.jar is empty :( any ideas where to find the fix in Android 6?
    – Qiong Wu
    Jan 11, 2016 at 21:09
  • Nevermind, it was just a non-deodexed ROM. installing CM13 fixed it for me.
    – Qiong Wu
    Jan 11, 2016 at 22:18
1

So I also found out how to do it on CM12.1

Just change this line over here https://github.com/CyanogenMod/android_frameworks_base/blob/e49d5ea0858a765c22d8aa96cc660d4708a413fb/services/core/java/com/android/server/ConnectivityService.java#L4264

or in smali replace the line before .line 4266 with goto :cond_1b1

Not the answer you're looking for? Browse other questions tagged or ask your own question.