Accessing a virtual device from ADB

ADB is the communication protocol specific to Android that must be enabled to allow communication between a computer and Android devices.

Enabling ADB

WARNING

When enabling ADB, it becomes accessible using the standard 5555 TCP port. Since the ADB connection is neither secured nor authenticated, we do not recommend opening the ADB port 5555 in AWS Security Group, nor allowing ADB traffic in your GCP configuration. Instead, we recommend creating an SSH tunnel.

From a web browser

Go to the "Configuration" section of your device (https://X.X.X.X/configuration, where X.X.X.X is your instance IP address).

Configuration screenshot

On the ADB section, click on the toggle button to enable ADB access.

From HTTP API

  1. To get the API reference, refer to DocumentationAPI Reference/configuration/adb from the instance web user interface
  2. To set it directly from the user interface, click on Try it out.
  3. To enable ADB, edit the payload & click on Execute.
    • To enable at runtime, set active=true
    • To enable by default after reboot, set active_on_reboot=true

From Command Line

To establish the communication between your computer and Android virtual devices, follow the steps below:

  1. Log in with SSH or PuTTY. Please refer to Accessing a virtual device from SSH
  2. Enable ADB using setprop persist.sys.usb.config adb

Creating an SSH tunnel

TIP

The following section assumes that you have already read the Accessing a virtual device from SSH section.

With SSH client

From a new terminal/shell create an SSH tunnel:

ssh -i key.pem -NL 5555:localhost:5555 [email protected]_ip

TIP

key.pem is your private key and instance_IP is the IP of your virtual device instance.

WARNING

shell is a specific user for SSH operations. Do not use a different username.

WARNING

Do not close this terminal/shell or this will close the tunnel as well.

To create a tunnel for other virtual devices, make sure you increment the port number for every new virtual device (5556, 5557, 5558, etc.) For example:

ssh -i key.pem -NL 5556:localhost:5555 [email protected]_ip2

With PuTTy

  • Go to Connection > SSH > Tunnels and set Source port to 5555 and Destination to localhost:5555.
  • Click on Add.
    PuTTY tunnel setting
  • Then, click on Open to start the connection.
    PuTTY tunnel save

WARNING

The PuTTy terminal has to remain open during your operations. If PuTTY is closed, it will close the tunnel as well.

TIP

To create a tunnel for other virtual devices, make sure you increment the port number for every new virtual device (5556, 5557, 5558, etc.)

Connecting ADB to the instance

  1. Open another shell to run other commands.

  2. (Optional) Connect your virtual device using adb connect locahost:5555. This command is optional as the first virtual device might have been automatically connected to ADB.

  3. 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\@instance\_ip2\
    
    adb connect localhost:5556
    

How to disable ADB

From a web browser

Go to the "Configuration" section of your device (https://X.X.X.X/configuration, where X.X.X.X is your instance IP address).

Configuration screenshot

On the ADB section, click on the toggle button to disable ADB access.

From HTTP API

  1. To get the API reference, refer to DocumentationAPI Reference/configuration/adb
  2. To set it directly from the user interface, click on Try it out.
  3. To disable ADB, edit the payload & click on Execute.
    • To disable at runtime, set active=false
    • To disable by default after reboot, set active_on_reboot=false

From Command Line

To stop the communication between your computer and Android virtual devices, follow the steps below:

  1. Log in with SSH or PuTTY. Please refer to Accessing a virtual device from SSH
  2. From the instance shell, run the command setprop persist.sys.usb.config none