Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

bash - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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):

The following commands call ConnectivityManager.setUsbTethering(boolean enable) in Android 4.3:

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.

For other Android versions replace 34 with the following setUsbTethering calling codes per Android version:

4.4.4: 34
5.1.0: 30
6.0.1: 30
7.0.0: 33

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...