turbo turbo - 1 month ago 15
Android Question

Is it possible to USB tether an android device using adb through the terminal?

I'm setting up some tests and it will require a decent number of phones to be usb tethered and configured. I've been successful in configuring them the way I want to once they have been tethered, however it would be quite tedious to tether the phones through navigating the menus, each and every time I (re)start my computer or move the test bank. I am currently using Nexus S phones running cyanogenmod v10.1.0, however the test bank will likely be Samsung Galaxy S4's possibly mixed with the few Nexus S phones I have on hand.

I want to do this as a bash script, but I'm trying to get it work at the command line (Ubuntu 13.04) first so as to remove issues that could come from scripting. I should be able to handle making it into a script myself, but if it's simple to provide an answer as bash script, please do. I tried shelling into the device (

adb -s $deviceID shell
) and running:

setprop sys.usb.config rndis,adb


This promptly kicks me out of the device shell and the device is no longer accessible. If I run an
adb devices
I see the phone as "?????????? No Permissions" at which point I have to take the USB cable out and then plug it in again, and also restart the adb server with
adb kill-server
adb start-server
. This will not work because I cannot access the phone to make the configuration changes that I need.

I've googled around but have been unable to find anything fruitful. Any suggestions?

Answer

Must have root to change values with setprop, and I am on a Mac OS without a rndis driver so I could not test your method of USB tethering. Another way, if you have the connectivity service (adb shell service list):

adb shell su -c service call connectivity 34 i32 1 turns on USB tethering.

adb shell su -c service call connectivity 34 i32 0 turns off USB tethering.

Calls public int setUsbTethering(boolean enable) in android.net.IConnectivityManager.

Comments