ADB Multi-Device management

Source: Internet
Author: User
Tags prev

since the development machine is always connected to several devices at the same time, and our equipment has the same name, and we may operate several devices at the same time, in order to solve this problem wrote a shell script to manage these devices, easy to develop.
function Introduction: 1. If a device environment variable exists(android_serial), and the environment variable of the device exists then use the value of the device environment variable, otherwise choose one from the existing device. 2. Added auto-completion to OKADB, adding only a few of my favorites. 3. Integrate some of the common functions. 4. Set the device name this function defaults to "123", setting the device environment variable by default is to select the device that already exists, if NULL this cancels the device environment variable.

Simple to use:

$ source okadb.sh$ adbsetenv null$ okadb shell1) 7f7c509e2) 01234567893) 123 4) 2.2.2.108:5555#? 4select Android device is 2.2.2.108:5555[email protected]:/# exit$ ADBSETENV1) 7f7c509e2) 01234567893) 123 4) 2.2.2.108:5 555#?  2$ okadb shellselect Android device is 0123456789[email protected]:/# exit$ adbsetenv null$ okadb tcpip 55551) 7f7c509e2) 01234567893) 123 4) 2.2.2.108:5555#? 1select Android device is 7f7c509erestarting in TCP mode port:5555$ adbrename myname1) 01234567892) 123 3) 2.2.2.108:5555 4) 7f7c509e#? 1* Daemon not running. Starting it now on port 5037 * * Daemon started successfully *list of devices attached7f7c509e device123 devicemyname
   device


The script code is as follows:

#!/bin/bash# Author: [email protected]# Time:fri May 18:04:09 CST 2015_okadb () {Local cur prev optscompreply= () c Ur= "${comp_words[comp_cword]}" prev= "${comp_words[comp_cword-1]}" opts= "Shell push pull install TCPIP USB Logcat root Reboot Reboot-bootloader forward devices kill-server remount "case" $prev "Inshell | Pull | Reboot-bootloader | Logcat | Devices | Kill-server | Root | remount) compreply= () return 0;; Reboot) compreply= ($ (compgen-w "bootloader Recovery"--$cur)) return 0;; Push) compreply= ($ (compgen-o default-o plusdirs-f-$cur)) return 0;; *) Local prev2= "${comp_words[comp_cword-2]}" if ["$prev 2" = = "Push"] | | ["$prev 2" = = "reboot"];thenreturn 0fi;;  Esaccompreply= ($ (compgen-w "$opts"--$cur)) return 0}select_device () {# If Env dev exist && find it, use it. Choose one of the Devices.if test $#-eq 0-a-n "${android_serial}"; Thenlocal env_dev= "${android_serial}" local devs= (' adb devices ') local env_dev_status=0# find the env devicefor T in ${dev S[@]};Doif test "$t" = "$env _dev"; Thenenv_dev_status=1breakfidoneif Test ${env_dev_status}-eq 1; Thenecho ${env_dev}return 0fifilocal c=0 s=0 devs sel_devdevs= (' adb devices ') for ((c=0; c < ${#devs [@]}; C + +)); DOIF test "Device" = ${devs[c]}; thent=$ ((c-1)) #echo ${devs[$t]}sel_dev[$s]=${devs[$t]}s=$ ((++s)) Fidone#echo "${sel_dev}" if test ${#sel_dev [*]}-ge 2 ; Thenselect var in ${sel_dev[*]}; Dobreak;doneecho $varreturn 0elseecho ${sel_dev}return 0fiechoreturn 1}okadb () {if test $#-eq 1-a "$" = "devices"; Thena DB [Email protected]return 0fidev= "$ (select_device)" echo "Select Android device is $dev" if Test-n "$dev";  Thenadb-s $dev [Email protected]return 0fiadb devicesreturn 1}# Add automatic completion for okadbcomplete-f _OKADB Okadbadbconnect () {# FIX meadb connect 2.2.2.$1}adbdisconnect () {dev= "$ (select_device)" adb disconnect $dev}adbrestart ( {adb kill-serveradb start-server}adblg () {dev= "$ (select_device)" Adb-s $dev logcat}adblgt () {dev= "$ (select_device)" Adb-s $dev LOGCAT-v time}adblgth () {dev= "$ (select_device)" Adb-s $dev logcat-v threadtime}adbrename () {dev= "$ (select_device)" Name= " 123 "If Test-n" $ "; Thenname= "$" fiadb-s $dev Shell "echo" $name ">/sys/class/android_usb/android0/iserial" ADBRESTARTADB devices} Adbsetenv () {if test $#-eq 1-a "$" = "null"; Thenexport android_serial= "" elsedev= "$ (select_device)" Export Android_seria L= "$dev" fi}


ADB Multi-Device management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.