Dependencies and prerequisites
- Android 5.0 (API level 21) or higher
- Android Auto companion app installed
In this document
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.
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:
- 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
<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
Figure 1. Context menu with developer options.
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:
- On the mobile device, enable Android Auto developer mode by starting the Android Auto companion app and then tapping the Android Auto toolbar title 10 times. 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, make sure the Only connect to known cars option is disabled.
- 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<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 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.
Figure 4. DHU is launched on the development machine.
Figure 3. Android Auto is launched on the mobile device.
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:
- Run the command
daynightin the terminal where you launched the DHU. - Select the DHU window and press the N key.
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.
-
exitnav.wav - "Exit navigation."
-
navgoogle.wav - "Navigate to 1600 Amphitheatre Parkway, Mountain View."
-
navsoh.wav - "Navigate to Sydney Opera House."
-
nextturn.wav - "When is my next turn?"
-
showalternateroute.wav - "Show alternate routes.""
-
howlong.wav - "How long until I get there?"
-
navhome.wav - "Navigate to home."
-
navwork.wav - "Navigate to work.""
-
pause.wav - "Pause music."
-
showtraffic.wav - "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 steering wheel's microphone button) 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 down left right |
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 |
1 2 |
Simulates rotating the rotary controller left (counter-clockwise) or right (clockwise). | |||
| flick left flick right |
Shift+1 Shift+2 |
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
- Install the Android Auto app, available on Google Play, on your handheld.
- In the Android Auto app, tap the Hamburger menu.
- Tap About.
- Tap About Android Auto header 10 times, until a toast appears thar says "Developer mode enabled".
- Select Developer settings from the overflow menu and check unknown sources.
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 device:
adb -d install path/to/your/app.apk
You can now test your app and verify that everything works.