Testing your vehicle apps ensures that users don't encounter unexpected results or have a poor experience. Your app can be accessed on both a car's console and a user's phone screen, so you need to test your Auto apps for both types of screens. In addition, users can access your app in several different modes.
This topic shows you how to test your app for each of these user access modes. In addition, this topic provides instructions for testing other required functionality.
Test your app for Android Automotive OS
You can use the Android Emulator to test how your driver-optimized app runs on an Android Automotive OS vehicle display. This section describes how to set up an Android Virtual Device (AVD) that you can use to test your app.
Edit your run configurations
Automotive OS apps are different other Android apps. Android Automotive OS interacts with your app using explicit intents and your Media Browse Service.
In order to test your app, verify that you have set your automotive module to not launch any activity by following these steps:
In Android Studio, select Run > Edit Configurations.
Select your automotive module from the list of modules in your app.
Under Launch Options > Launch, select Nothing.
Click Apply, and then click OK.
Add system images
Before you can create AVDs that match specific manufacturer hardware, you need to add system images for these devices through the Android Studio SDK Manager. Then, when you're creating an AVD, you can download these system images to use with the AVD.
Follow these steps to add a system image for the Polestar 2:
- In Android Studio, select Tools > SDK Manager.
- Click the SDK Update Sites tab.
- Click Add .
Enter the following Name and URL, then click OK:
Name: Polestar 2 System Image
Click Apply, then click OK.
Create a car AVD and run the emulator
Follow these steps to create an Android Virtual Device (AVD) that represents an Android Automotive OS vehicle and then use that AVD to run the emulator:
- In Android Studio, select Tools > AVD Manager.
- Click Create Virtual Device.
- From the Select Hardware dialog, select Automotive, and then select a device and click Next.
- Select a system image that targets Automotive, such as Android 9.0 (Automotive), and click Next.
- Name your AVD and select any other options that you want to customize and then click Finish.
- From tool window bar, select your Android Automotive OS AVD as your deployment target.
- Click Run .
Test your app for Android Auto compatible car displays
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, macOS, and Linux hosts.
This section teaches 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 pressing 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 your app for phone screens
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 devicescommand 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
.apkon the device by running the following command:
adb -d install path/to/your/app.apk
You can now test your app and verify that everything works.
Other testing requirements
In addition to testing your app for each of the user access modes mentioned in this topic, you should test your app to ensure it can perform the following function.
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.
In addition, 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.