The Android Cluster Toolkit helps organize and manipulate a collection of Android devices. It was designed to work with a collection of devices connected to the same host machine, either directly or via one or more tiers of powered USB hubs. The tools within can operate on single devices, a selected subset, or all connected devices at once.
- A Ruby Interpreter (Tested with Ruby 1.9.3 and 2.0.0)
- A Linux Host machine (YMMV on other OSes)
- One or more Android devices
- Open USB ports (one per device)
There are no special hardware components, though various hardware has been used with varying results.
D-Link DUB-H7 hubs seem to work well.
Although it looks cool and has a lot of ports, the Manhattan MondoHub is not recommended. It simply doesn't have enough power to support all ports being in use at the same time.
Several scripts comprise the Android Cluster Toolkit. These scripts are described below.
The toolkit contains three scripts that are included by the other scripts. These scripts each serve a particular purpose.
This file contains a Ruby Hash that describes various properties of the devices within your Android cluster. A sample file is included as "lib/devices/pool.rb.sample". This file is never changed by the toolkit, so this is a great place to put manual comments and so forth. You can generate one from the sample by running './init.rb' or 'make'.
The lib/devices/connected.rb script is generated from the Hash in lib/devices/pool.rb. It contains the list of devices that are currently connected to the host machine (the ADB Server). It's created by the reconfig.rb script.
This file only contains a simple helper function to help pluralize words talking about arrays.
This file contains functionality for dealing with devices or the lists of devices in the lib/devices directory.
This file only contains a simple helper function to help pluralize words talking about arrays.
This file contains functionality that is shared between several of the scripts in the Android Cluster Toolkit. It is included by those scripts and currently only contains a few utility method implementations.
Dealing with a large collection of Android devices isn't painless. A couple of scripts in the toolkit ease the pain. These scripts take no arguments and just do their thing when you run them.
The scan.rb script exists to make adding new devices easier. Once you obtain a new device, plug it in and run the scan.rb script. If it finds any devices that are not in lib/devices/pool.rb it will output suitable Hash entries for them. Add these entries to lib/devices/pool.rb to make these devices accessible to the multi-device scripts. Make sure to set a unique name for the device (perhaps the model number or slang name, ie. GT-I9505 or sgs4). Re-run reconfig.rb to activate the changes.
The reconfig.rb script automatically generates the Hash in lib/devices/connected.rb. When executed, it copies the entries in lib/devices/pool.rb that are currently connected to the ADB Server. This way, you can avoid silly "no such device" output from the multi-device scripts.
Although there used to be more single device scripts, they were deprecated in favor of a more unified interface (described in the next section). That said, one single-device script remains: shell.rb.
This script executes a shell suitable for operating on the specified device only. This is useful for maintenance or doing more focused research on a single device. When executed, it simply sets up the environment so that other ADB-aware tools will operate on the specified device. Once the environment is set up, the script spawns a shell for your pleasure. Exit the new shell to return to the original shell.
The Android Cluster Toolkit's best feature is its multi-device scripts. These scripts can be used to perform some action against one, several, or all of the devices in your Android cluster at once. The first argument to these scripts specifies which device(s) to act upon as follows:
- "." (a literal period, without the quotes): Act upon all devices
- One or more device names or serial numbers separated by commas (quote your spaces if necessary): Act upon only the selected devices.
The arguments that follow the device selector are specific to each script. In some cases they are optional, but in other cases they are not.
A couple of options, -v and -1, toggle verbosity and single-line mode. NOTE: Single-line mode does not accept input and will block if the device reads from stdin.
This multi-device script enables you to run an arbitrary ADB command against the selected device(s). Any command supported by the ADB client should work (ie, push, shell, reboot, etc). Validation is done to prevent non-desirable results; relax it at your own risk.
./mdo -1d . install /path/to/my/app.apk
This will install app.apk to all connected devices.
This multi-device script enables you to run an arbitrary shell command on the selected device(s). For example:
./mcmd -d . getprop ro.build.fingerprint
This will list the build fingerprint of all connected devices.
During research, the need arose to use tools from the BusyBox binary in lieu of the default versions. For example, the ls(1) binary inside BusyBox offers color output, among other features whereas the default one (usually from toolbox) does not. This script accomplishes this goal by prefixing the specified command with "/data/local/tmp/busybox". Placing a suitable busybox binary in this location is up to you. You can find a suitable binary at: http://cache.saurik.com/android/armeabi/busybox
Another common task is pulling a particular file or path from all devices so that the data can be inspected on the host machine. This script will pull the specified paths from all devices and store them into a device-specific sub-directory within the "devices" directory in the Android Cluster Toolkit directory. For example:
./mpull -d sgs4 /proc/version
This command will pull the kernel version information from /proc/version and save it to devices/sgs4/proc/version.
There are only a handful steps to getting up and running.
- Clone this repository
- Go into the directory
- Connect all of the desired devices
The relevant commands are:
$ git clone https://github.com/jduck/android-cluster-toolkit.git
$ cd android-cluster-toolkit
At this point you can follow either the QUICK or MANUAL methods to provision devices.
- Run the ./init.rb to generate lib/devices/pool.rb from the connected devices
- Run ./reconfig.rb to generate lib/devices/connected.rb from lib/devices/pool.rb
The relevant commands are:
$ ./init.rb
$ $EDITOR lib/devices/pool.rb # optionally set names for the devices
$ ./reconfig.rb
- Run the ./scan.rb script to see newly connected devices
- Add the Hash entries to lib/devices/pool.rb, assigning names as you go
- Run ./reconfig.rb
The relevant commands are:
$ ./scan.rb
$ $EDITOR lib/devices/pool.rb # add and set names for the devices
$ ./reconfig.rb
At this point you're ready to go. To confirm everything is working, run something against all the devices.
./mcmd -1d . getprop ro.build.fingerprint