Skip to content

Most visited

Recently visited


Testing Apps for Auto

Dependencies and prerequisites

  • Android 5.0 (API level 21) or higher
  • Android Auto companion app installed

In this document

  1. Testing apps for car screen
  2. Testing apps for phone screen
  3. Testing media app "cold start"

Testing your Auto apps ensures that users don't encounter unexpected results or have a poor experience when interacting with your apps. Android Auto is available for both car and phone screens, so you need to test your Auto apps for both types of screens.

This lesson shows you how to test your Auto apps for:

Note: It's important that you test your auto app for the criteria listed on the Auto app quality page prior to submitting to Google Play for review.

Testing apps for car screen

The DHU enables your development machine to emulate an Android Auto head unit, so that you can easily run and test Android Auto apps. The DHU runs on Windows, Mac, and Linux hosts.

The following sections teach you how to install and run the DHU on your development machine to test your apps. After you’ve installed the DHU, you can test your Android Auto apps by connecting your phone and workstation via USB.

Installing the DHU

Follow these steps to install the DHU on your development machine:

  1. Enable developer mode on your mobile device, as described in Enabling On-device Developer Options.
  2. Compile your app in your development environment and install your app on a physical mobile device running Android 5.0 (API level 21) or higher. To check the version of Android on a Nexus device, go to Settings > About phone (or About tablet) > Android version.
  3. Install the Android Auto app on the mobile device.
  4. Open the SDK Manager and download the DHU package Android Auto Desktop Head Unit emulator from the SDK Tools tab. The DHU is installed in the <sdk>/extras/google/auto/ directory.

If you are running the DHU on Linux, you must also install the portaudio, libpng, sdl2, and sdl2_ttf libraries. The installation procedure varies depending on your Linux distribution. For example, on Debian-derived Linux distributions, you can install the libraries with this command:

$ sudo apt-get install libsdl2-2.0-0 libsdl2-ttf-2.0-0 libportaudio2 libpng12-0
Context menu with developer options

Figure 1. Context menu with developer options.

Notification that the head unit server is running

Figure 2. Notification that the head unit server is running.

After you install the DHU, you can test your Android Auto apps by connecting your phone and workstation via USB.

Running the DHU

Run the DHU by connecting your mobile device to a development machine and setting up a connection to the head unit server over Android Debug Bridge (ADB). Follow these steps to set up tunneling and start the DHU:

  1. In the Android Auto app, tap the Hamburger menu.
  2. Tap About.
  3. Tap the About Android Auto header 10 times, until a toast appears that says "Developer mode enabled".

    Now you can access developer mode by selecting the overflow menu dots on the top right of the handheld screen. This step is only required the first time you run the companion app.

  4. If the server is not already running, select Start head unit server from the Android Auto menu.

    On the device, a foreground service appears in the notification area.

  5. In the Android Auto app, return the main screen by pressing the back button, then open Settings -> Connected cars from the navigation drawer, and ensure "Add new cars to Android Auto" is enabled.
  6. Connect the mobile device to the development machine via USB.
  7. Make sure the mobile device has its screen unlocked; otherwise it cannot launch the DHU.
  8. On the development machine, run the following adb command to forward socket connections from the development machine's port 5277 to the same port number on the Android device. This configuration enables the DHU to connect to the head unit server running on your phone over a TCP socket.
    $ adb forward tcp:5277 tcp:5277
  9. Start the DHU by running the command desktop-head-unit.exe (on Windows) or ./desktop-head-unit (on Mac or Linux) from the <sdk>/extras/google/auto/ directory.
    $ cd <sdk>/extras/google/auto
    $ ./desktop-head-unit

    By default, the head unit server connects over port 5277. To override the host or port (for example, to forward over SSH), use the desktop-head-unit --adb <[localhost:]port> flag, as in the following example:

    $ ./desktop-head-unit --adb 5999

    By default, the DHU emulates the most common form of the Android Auto-compatible head unit, which uses a touch screen user interface. You can simulate user touches by clicking the DHU with a mouse. To emulate head units that use a rotary controller for input, you can use the -i controller flag, as in this example:

    $ ./desktop-head-unit -i controller

    When the DHU is in rotary-controller mode, you can use keyboard shortcuts to simulate controller operations, as described in DHU commands and key bindings. In rotary controller mode, the DHU ignores mouse clicks; you must operate Android Auto with the simulated rotary-controller operations.

Android Auto is launched on the mobile device

Figure 3. Android Auto is launched on the mobile device.

DHU is launched on the development machine

Figure 4. DHU is launched on the development machine.

Important: Use of the Android Media Browser and Messaging Simulators for testing Android Auto apps is deprecated. Instead, we recommend using the DHU, which enables your development machine to act as if it were an Android Auto head unit.

After you set up and start the DHU, you can run DHU commands from the command line to run and test your app from the terminal. You can also use keyboard shortcuts to run these commands.

Issuing DHU commands

DHU commands allow you to test your app with Android Auto features, such as playing voice input or switching between night and day display mode. You can issue commands to the DHU from the terminal window where you launched the DHU. You can also issue commands by selecting the DHU window and using keyboard shortcuts. The DHU commands and key bindings for all controls are listed in DHU commands and key bindings.

Switching between day and night mode

Android Auto supports different color schemes for day and night. You should test your app in both day and night mode. You can switch between night and day mode in either of the following ways:

Microphone testing

The DHU supports using a microphone for voice input. You can also instruct the DHU to treat a prerecorded voice track as input, as if the DHU had heard the track through the microphone.

To use a prerecorded sound file as input, enter this command:

$ mic play <sound_file_path>/<sound_file>.wav

For your convenience, we have provided the following sound files for common voice commands. These sound files are installed in the <sdk>/extras/google/auto/voice/ directory.

"Exit navigation."
"Navigate to 1600 Amphitheatre Parkway, Mountain View."
"Navigate to Sydney Opera House."
"When is my next turn?"
"Show alternate routes."
"How long until I get there?"
"Navigate to home."
"Navigate to work."
"Pause music."
"Show traffic."

DHU commands and key bindings

The DHU supports the following commands.

Table 1. Commands and key bindings

Category Command Subcommand Argument(s) Keyboard Shortcut(s) Description
System help [command] Shows the full command set. Specifying a command name (for example, help day) causes the system to show help for that command.
quit Alt+q Quits the head unit.
sleep [seconds] Sleeps for one second. Specifying an argument (for example, sleep 30) causes the system to sleep the specified number of seconds. This command is useful if you are writing scripts for the DHU. (You can run a script by using I/O redirection from the command line: ./desktop-head-unit < script.txt loads commands from the file script.txt.)
screenshot filename.png Saves a screenshot to filename.png.
Microphone mic begin m Activates the microphone (equivalent to clicking the microphone button on the steering wheel) and waits for input from the computer microphone.
play filename.wav Causes the DHU to treat filename.wav as voice input, as if that sound were relayed through the microphone. You do not hear the sound file being played, but you do hear the response from Android Auto.
repeat Repeats the last mic play command, as if you had called mic play again with the same sound file parameter.
Input dpad up
Arrow keys Simulates moving the rotary controller.
soft left
soft right
Shift+Arrow keys Simulates pressing the side buttons available on some rotary controllers.
click Return Simulates pressing the rotary controller.
back Backspace Simulates pressing the back button available below some rotary controllers.
rotate left
rotate right
Simulates rotating the rotary controller left (counter-clockwise) or right (clockwise).
flick left
flick right
Simulates a fast spin of the rotary controller to the left (counter-clockwise) or right (clockwise).
tap x y Simulates a touch event at the specified coordinates. For example, tap 50 100
Day/Night day Shift+N Activates day mode (high brightness, full color).
night Control+N Activates night mode (low brightness, high contrast).
daynight n Toggles current day/night mode.

Testing apps for phone screen

Follow the steps below to sideload your app onto a handheld and test.

Step 1. On the Android Auto app, enable unknown sources in developer mode

  1. Install the Android Auto app, available on Google Play, on your handheld.
  2. In the Android Auto app, tap the Hamburger menu.
  3. Tap About.
  4. Tap the About Android Auto header 10 times, until a toast appears that says "Developer mode enabled".
  5. Now you can access developer mode by selecting the overflow menu dots on the top right of the handheld screen.

  6. Select Developer settings from the overflow menu. Select Developer in Application Mode and check Unknown sources.
  7. Restart Android Auto.

Step 2. On your handheld, enable USB debugging

  1. In Settings > About phone, tap Build number seven times to enable the Developer Options.
  2. Go back to Settings > Developer Options, enable USB debugging.

Step 3. Install your app onto the handheld and test

Connect the handheld to your machine through USB, so you can install apps directly to it as you develop. Use the adb devices command to ensure that your development computer can detect your device when connected via USB.

Once your device is set up and connected via USB, navigate to your SDK's platform-tools/ directory and install the .apk on the device:

adb -d install path/to/your/app.apk

You can now test your app and verify that everything works.

Testing media app "cold start"

Android Auto media apps should work even if no Activity has ever been opened. Your app should respond appropriately under the following conditions:

Test the following scenarios:

If the app cannot perform the requested behavior, set an appropriate error message.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields


Sigue a Google Developers en WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)