Connect to ADB

Connect to ADB

ADB is a communication protocol specific to Android that allows to connect or control an Android device from a computer.

It can be used with a Genymotion Device image instance to:

Prerequisite

Your EC2 firewall has an inbound rule to allow TCP port 5555 or SSH connection from authorized hosts. See Requirements. Android SDK platform-tools from https://developer.android.com or Android Studio. Android Studio includes the Android SDK platform-tools. By default, they are located in the following folders:

Step 1 - Toggle ADB connection

ADB connections are neither secured nor authenticated: you should ONLY allow TCP port 5555 from authorized hosts in your Firewall inbound rules. Instead of opening TCP port 5555, you can use an SSH tunnel to secure the connection.

You can use Web UI, Command Line (SSH), and HTTP API to control ADB access. Go to the Configuration panel. In the ADB section, click on the toggle button to enable or disable ADB access. Setup SSH and use the following commands:

Enable ADB
ssh -i key.pem shell@{instance_IP} 'su -c "setprop persist.sys.usb.config adb"'
Disable ADB
ssh -i key.pem shell@{instance_IP} 'su -c "setprop persist.sys.usb.config none"'

You can use the POST method and call the /configuration/adb API to set the following variables:

Set active:true
to enable ABD at run-time, and/or active_on_reboot:true to enable after reboot.
Set active:false
to disable ADB at run-time, and/or active_on_reboot:false to disable after reboot.

For detailed usage, please refer to Genymotion HTTP API. It is also possible to use user data parameters, to enable ABD connection at boot. For detailed instructions, please refer to Automate instance parameters.

Step 2 - Connect ADB to the instance

After enabling ADB connection, you can connect the instance to ADB:

adb {instance_IP}

Use an SSH tunnel

Though it is possible to open TCP port 5555 to restricted hosts in your EC2 firewall, using an SSH tunnel is the most secured method.

1. Set SSH access

Follow the instructions from chapter Access with SSH to setup and enable SSH access to your instances.

2. Create an ssh tunnel

From a new terminal/shell create an SSH tunnel:

ssh -i key.pem -NL 5555:localhost:5555 shell@{instance_ip}

Do not close this terminal/shell or this will close the tunnel as well. To create a tunnel for other virtual devices, just increment the port number for every new virtual device (5556, 5557, 5558, etc.).

PuTTy (Windows)

3. Connect ADB

Open another shell to run other commands. Connect your virtual device to ADB:

adb localhost:5555

To connect other virtual devices to ADB, make sure you increment the port number for every new virtual device (e.g. 5556, 5557, 5558, etc.). For example:

ssh -i key.pem -NL 5556:localhost:5555 shell@{instance2_ip}

Then, to connect this instance to ADB:

adb localhost:5556

Back to top