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:
- Car screen
Android provides the Desktop Head Unit (DHU), a testing tool for Auto apps that lets you test pre-released versions of your Android Auto apps. This will show your app on Android Auto for the car screen, without having to work from your car.
- Phone screen
Android Auto runs stand alone on your Android phone. This option lets you display and test pre-released versions of your app on Android Auto for the phone screen.
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.
Test 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.
Install the DHU
Follow these steps to install the DHU on your development machine:
- Enable developer mode on your mobile device, as described in Enabling on-device developer options.
- 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.
- Install the Android Auto app on the mobile device.
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
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
After you install the DHU, you can test your Android Auto apps by connecting your phone and workstation via USB.
Run 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:
- In the Android Auto app, tap the Hamburger menu.
- Tap About.
- 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.
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.
- 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.
- Connect the mobile device to the development machine via USB.
- Make sure the mobile device has its screen unlocked; otherwise it cannot launch the DHU.
On the development machine, run the following
adbcommand 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
Start the DHU by running the command
desktop-head-unit.exe(on Windows) or
./desktop-head-unit(on Mac or Linux) from the
$ 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 controllerflag, 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.
Note: You can also test your media integrations using the Media Controller app.
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.
Issue 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.
Switch 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:
Run the command
daynightin the terminal where you launched the DHU.
- Select the DHU window and press the N key.
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
- "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.
Shows the full command set. Specifying a command name (for example,
|quit||Alt+q||Quits the head unit.|
Sleeps for one second. Specifying an argument (for example,
Saves a screenshot to
|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.|
Causes the DHU to treat
Repeats the last
|Arrow keys||Simulates moving the rotary controller.|
|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.|
|Simulates rotating the rotary controller left (counter-clockwise) or right (clockwise).|
|Simulates a fast spin of the rotary controller to the left (counter-clockwise) or right (clockwise).|
Simulates a touch event at the specified coordinates. For example,
|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.|
Test 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
- Install the Android Auto app, available on Google Play, on your handheld.
- In the Android Auto app, tap the Hamburger menu.
- Tap About.
- Tap the About Android Auto header 10 times, until a toast appears that says "Developer mode enabled".
- Select Developer settings from the overflow menu. Select Developer in Application Mode and check Unknown sources.
- Restart Android Auto.
Now you can access developer mode by selecting the overflow menu dots on the top right of the handheld screen.
Step 2. On your handheld, enable USB debugging
- In Settings > About phone, tap Build number seven times to enable the Developer Options.
- 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
adb -d install path/to/your/app.apk
You can now test your app and verify that everything works.
Test 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:
MediaBrowserServiceis run before any activity is opened.
- The user is not signed in.
- No activity can be shown.
Test the following scenarios:
- Force stop the media app, then launch Android Auto
- Clear the media app data, then launch Android Auto
If the app cannot perform the requested behavior, set an appropriate error message.