| page.title= Testing Apps for Auto |
| page.tags="auto", "car", "automotive" |
| page.article=true |
| |
| @jd:body |
| |
| <div id="tb-wrapper"> |
| <div id="tb"> |
| <h2>Dependencies and Prerequisites</h2> |
| <ul> |
| <li>Android 5.0 (API level 21) or higher</li> |
| <li>Android Auto companion app installed</li> |
| </ul> |
| <h2>In this document</h2> |
| <ol> |
| <li><a href="#install">Installing the DHU</a></li> |
| <li><a href="#running-dhu">Running the DHU</a></li> |
| <li><a href="#dhu-commands">Issuing DHU Commands</a></li> |
| </ol> |
| </div> |
| </div> |
| |
| |
| <p> |
| Testing your Auto app ensures that users do not encounter unexpected results or |
| have a poor experience when interacting with your apps. Android now provides |
| Desktop Head Unit (DHU), a testing tool for Auto apps that lets you test |
| pre-released versions of your Android Auto apps without having to work from |
| your car.</P> |
| |
| <p>The Desktop Head Unit (DHU) enables your development machine to emulate an |
| Android Auto head unit, so you can easily run and test Android Auto apps. |
| The DHU runs on Windows, Mac, and Linux hosts and replaces previous Android Auto |
| simulators, such as the Android Media Browser and Messaging simulators.</p> |
| |
| |
| <p class ="note"><strong>Note:</strong> It's important that you test your auto |
| app for the criteria listed on <a href={@docRoot}distribute/essentials/quality/auto.html> |
| Auto app quality </a> page prior to submitting to Google Play for review. |
| </p> |
| <p> |
| This lesson teaches you how to install and run the DHU on your development |
| machine for testing your apps. Once you’ve |
| installed the DHU, you can test your Android Auto apps by connecting your phone |
| and workstation via USB. |
| |
| <h2 id ="install"> Installing the DHU</h2> |
| <p>Follow these steps to install the DHU on your development machine:</p> |
| <li>Enable developer mode on your mobile device, as described in |
| <a href="{@docRoot}tools/device.html#developer-device-options">Enabling On-device |
| Developer Options</a>. </li> |
| <li>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 |
| <strong>Settings > About phone</strong> (or <strong>About tablet</strong>) <strong>> |
| Android version</strong>.</li> |
| |
| <li>Install the |
| <a class="external-link" |
| href="https://play.google.com/store/apps/details?id=com.google.android.projection.gearhead&hl=en" |
| >Android Auto app</a> on the mobile device.</li> |
| <li>Open the <a href="{@docRoot}tools/help/sdk-manager.html">SDK Manager</a> and |
| download the DHU package <strong>Android Auto Desktop Head Unit emulator</strong> from the |
| <em>SDK Tools</em> tab. The DHU installs in the <code><sdk>/extras/google/auto/</code> |
| directory.</li> |
| <li>If you are running the DHU on Linux, you must also install |
| the portaudio, libpng, sdl2, and sdl2_ttf libraries. |
| The procedure to do this varies depending on your Linux distribution. For example, on |
| Debian-derived Linux distributions, you can install the libraries with this command: |
| |
| <pre class="no-pretty-print"> |
| $ sudo apt-get install libsdl2-2.0-0 libsdl2-ttf-2.0-0 libportaudio2 libpng12-0 |
| </pre> |
| |
| </li> |
| </ol> |
| |
| <div class="cols"> |
| <div class="col-6"> |
| <img src="{@docRoot}images/training/auto-desktop-head-unit-context-menu-enabled.png" |
| alt="" > |
| <p class="img-caption"> |
| <strong>Figure 1.</strong> Context menu with developer options. |
| </p> |
| </div> |
| |
| <div class="col-6"> |
| <img src="{@docRoot}images/training/auto-desktop-head-unit-server-running.png" |
| alt="" > |
| <p class="img-caption"> |
| <strong>Figure 2.</strong> Notification that the head unit server is running. |
| </p> |
| </div> |
| </div> <!-- end cols--> |
| |
| |
| <h2 id="running-dhu">Running the DHU</h2> |
| |
| <p>Run the DHU by connecting your mobile device to a development machine and |
| setting up a connection to the head unit server over <a href="{@docRoot}tools/help/adb.html">Android Debug Bridge |
| (ADB)</a>. Follow these steps to set up tunneling and start the DHU:</p> |
| |
| <ol> |
| <li>On the mobile device, enable Android Auto developer mode by starting the Android Auto |
| companion app, and then tapping the <i>Android Auto</i> toolbar title 10 times. |
| This step is only required the first time you run the companion app. |
| </li> |
| <li>If the server is not already running, select <strong>Start head unit server</strong> |
| from the Android Auto menu. |
| <p>On the device, a foreground service appears in the notification area. </p> |
| </li> |
| |
| <li>In the Android Auto app, make sure the <strong>Only connect to known cars</strong> option |
| is disabled.</li> |
| |
| <li>Connect the mobile device to the development machine via USB.</li> |
| |
| <li>Make sure the mobile device has its screen unlocked, otherwise it cannot launch the DHU.</li> |
| |
| <li>On the development machine, run the following {@code adb} command to |
| forward socket connections from the |
| development machine's port 5277 to the same port number on the Android device. |
| This configuration allows the DHU to connect to the head unit server running on your phone over |
| a TCP socket. |
| <pre class="no-pretty-print">$ adb forward tcp:5277 tcp:5277</pre> |
| </li> |
| |
| <li>Start the DHU by running the command <code>desktop-head-unit.exe</code> (on Windows) |
| or <code>./desktop-head-unit</code> (on Mac or Linux) from the |
| <code><sdk>/extras/google/auto/</code> directory. |
| |
| <pre class="no-pretty-print">$ cd <sdk>/extras/google/auto |
| $ ./desktop-head-unit</pre> |
| |
| <p> |
| By default, the head unit server connects over port 5277. To override the host or port |
| (for example, to forward over SSH), use the |
| <code>desktop-head-unit --adb <[localhost:]port></code> flag, as in |
| the following example: |
| </p> |
| |
| <pre class="no-pretty-print">$ ./desktop-head-unit --adb 5999</pre> |
| <p> |
| By default, the DHU emulates the most common form of 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 which use |
| a rotary controller for input, you can use the <code>-i controller</code> flag, |
| as in this example: |
| </p> |
| <pre class="no-pretty-print">$ ./desktop-head-unit -i controller</pre> |
| <p> |
| When the DHU is in rotary-controller mode you can simulate controller |
| operations by using keyboard shortcuts, as described in <a href= |
| "#cmd-bindings">DHU commands and key bindings</a>. If the DHU is in rotary |
| controller mode, it ignores mouse clicks; you must operate Android Auto with |
| the simulated rotary controller operations. |
| </p> |
| </li> |
| </ol> |
| |
| |
| |
| |
| <div class="figure" style="width:432px"> |
| |
| <img src="{@docRoot}images/training/auto-desktop-head-unit-wkst-launch.png" |
| alt="" > |
| <p class="img-caption"> |
| <strong>Figure 4.</strong> DHU launches on the development machine. |
| </p> |
| </div> |
| |
| <img src="{@docRoot}images/training/auto-desktop-head-unit-launch.png" |
| alt="" > |
| <p class="img-caption"> |
| <strong>Figure 3.</strong> Android Auto launches on the mobile device. |
| </p> |
| |
| <p> |
| 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 run these commands |
| by using keyboard shortcuts. |
| </p> |
| |
| <h2 id="dhu-commands">Issuing DHU Commands</h2> |
| |
| <p> |
| 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 by running commands from the terminal window where you launched 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 <a href="#cmd-bindings">DHU |
| commands and key bindings</a>. |
| </p> |
| |
| |
| <h3 id="day-night">Switching between day and night mode</h3> |
| |
| <p> |
| 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: |
| </p> |
| |
| <ul> |
| <li>Run the command <code>daynight</code> in the terminal where you launched the DHU. |
| </li> |
| |
| <li>Select the DHU window and press the <strong>N</strong> key. |
| </li> |
| </ul> |
| |
| <h3>Microphone testing</h3> |
| |
| <p>The DHU supports using a microphone for voice input. You can also instruct the DHU to treat |
| a pre-recorded voice track as input, as if the DHU had heard the track through the microphone.</p> |
| |
| <p>To use a pre-recorded sound file as input, enter this command: </p> |
| <pre class="no-pretty-print"> |
| $ mic play <sound_file_path>/<sound_file>.wav |
| </pre> |
| |
| <p>For your convenience, we have provided the following sound files for common |
| voice commands. These sound files are installed in the |
| <code><sdk>/extras/google/auto/voice/</code> directory.</p> |
| |
| <dl> |
| <dt> |
| <code>exitnav.wav</code> |
| </dt> |
| |
| <dd> |
| "Exit navigation." |
| </dd> |
| |
| <dt> |
| <code>navgoogle.wav</code> |
| </dt> |
| |
| <dd> |
| "Navigate to 1600 Amphitheatre Parkway, Mountain View." |
| </dd> |
| |
| <dt> |
| <code>navsoh.wav</code> |
| </dt> |
| |
| <dd> |
| "Navigate to Sydney Opera House." |
| </dd> |
| |
| <dt> |
| <code>nextturn.wav</code> |
| </dt> |
| |
| <dd> |
| "When is my next turn?" |
| </dd> |
| |
| <dt> |
| <code>showalternateroute.wav</code> |
| </dt> |
| |
| <dd> |
| "Show alternate routes."" |
| </dd> |
| |
| <dt> |
| <code>howlong.wav</code> |
| </dt> |
| |
| <dd> |
| "How long until I get there?" |
| </dd> |
| |
| <dt> |
| <code>navhome.wav</code> |
| </dt> |
| |
| <dd> |
| "Navigate to home." |
| </dd> |
| |
| <dt> |
| <code>navwork.wav</code> |
| </dt> |
| |
| <dd> |
| "Navigate to work."" |
| </dd> |
| |
| <dt> |
| <code>pause.wav</code> |
| </dt> |
| |
| <dd> |
| "Pause music." |
| </dd> |
| |
| <dt> |
| <code>showtraffic.wav</code> |
| </dt> |
| |
| <dd> |
| "Show traffic." |
| </dd> |
| </dl> |
| <h3 id="cmd-bindings">DHU commands and key bindings</h3> |
| |
| <p>The DHU supports the following commands.</p> |
| |
| <p class="table-caption" id="table-commands"><strong>Table 1.</strong> Commands and key bindings</p> |
| <table> |
| <tr> |
| <th>Category</th> |
| <th>Command</th> |
| <th>Subcommand</th> |
| <th>Argument(s)</th> |
| <th>Keyboard Shortcut(s)</th> |
| <th>Description</th> |
| </tr> |
| |
| <!--system--> |
| |
| <tr> |
| <td rowspan="4">System</td> |
| <td>help</td> |
| <td></td> |
| <td>[command]</td> |
| <td></td> |
| <td>Shows the full command set. Specifying a command name (for example, <code>help day</code>) |
| causes the system to show help for that command.</td> |
| </tr> |
| |
| <tr> |
| |
| <td>quit</td> |
| <td></td> |
| <td></td> |
| <td>Alt+q</td> |
| <td>Quits the head unit.</td> |
| </tr> |
| |
| <tr> |
| |
| <td>sleep</td> |
| <td></td> |
| <td>[seconds]</td> |
| <td></td> |
| <td>Sleeps for one second. Specifying an argument (for example, <code>sleep 30</code>) 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: <code>./desktop-head-unit < script.txt</code> loads commands from the |
| file <code>script.txt</code>.)</td> |
| </tr> |
| |
| <tr> |
| |
| <td>screenshot</td> |
| <td></td> |
| <td>filename.png</td> |
| <td></td> |
| <td>Saves a screenshot to <code>filename.png</code>.</td> |
| </tr> |
| |
| |
| <!--microphone--> |
| |
| <tr> |
| <td rowspan="3">Microphone</td> |
| <td rowspan="3">mic</td> |
| <td>begin</td> |
| <td></td> |
| <td>m </td> |
| <td>Activates the microphone (equivalent to clicking the steering wheel's microphone button) and |
| waits for input from the computer microphone.</td> |
| </tr> |
| |
| <tr> |
| |
| |
| <td>play</td> |
| <td>filename.wav</td> |
| <td></td> |
| <td>Causes the DHU to treat <code>filename.wav</code> as voice input, as if it had heard that sound |
| through the microphone. You do not hear the sound file being played, but you do hear |
| the response from Android Auto.</td> |
| </tr> |
| |
| <tr> |
| |
| |
| <td>repeat</td> |
| <td></td> |
| <td></td> |
| <td>Repeats the last <code>mic play</code> command, as if you had called <code>mic play</code> |
| again with the same sound file parameter.</td> |
| </tr> |
| |
| <!--Input--> |
| |
| <tr> |
| <td rowspan="7">Input</td> |
| <td rowspan="6">dpad</td> |
| <td>up <br> down <br> left <br> right</td> |
| <td></td> |
| <td>Arrow keys</td> |
| <td>Simulates moving the rotary controller.</td> |
| </tr> |
| |
| <tr> |
| |
| |
| <td>soft left <br> soft right</td> |
| <td></td> |
| <td>Shift+Arrow keys</td> |
| <td>Simulates pressing the side buttons available on some rotary controllers.</td> |
| </tr> |
| |
| <tr> |
| |
| |
| <td>click</td> |
| <td></td> |
| <td>Return</td> |
| <td>Simulates pressing the rotary controller.</td> |
| </tr> |
| |
| <tr> |
| |
| |
| <td>back</td> |
| <td></td> |
| <td>Backspace</td> |
| <td>Simulates pressing the <strong>back</strong> button available below some rotary |
| controllers.</td> |
| </tr> |
| |
| <tr> |
| |
| |
| <td>rotate left <br> rotate right</td> |
| <td></td> |
| <td>1 <br> 2</td> |
| <td>Simulates rotating the rotary controller left (counter-clockwise) or right (clockwise).</td> |
| </tr> |
| |
| <tr> |
| |
| |
| <td>flick left <br> flick right</td> |
| <td></td> |
| <td>Shift+1 <br> Shift+2</td> |
| <td>Simulates a fast spin of the rotary controller to the left (counter-clockwise) or right |
| (clockwise).</td> |
| </tr> |
| |
| <tr> |
| |
| <td>tap</td> |
| <td></td> |
| <td>x y</td> |
| <td></td> |
| <td>Simulates a touch event at the specified coordinates. For example, <code>tap 50 100</code></td> |
| </tr> |
| |
| |
| <!--Day/Night--> |
| |
| <tr> |
| <td rowspan="3">Day/Night</td> |
| <td>day</td> |
| <td></td> |
| <td></td> |
| <td>Shift+n</td> |
| <td>Activates day mode (high brightness, full color).</td> |
| </tr> |
| |
| <tr> |
| |
| <td>night</td> |
| <td></td> |
| <td> </td> |
| <td>Ctrl+n </td> |
| <td>Activates night mode (low brightness, high contrast).</td> |
| </tr> |
| |
| <tr> |
| |
| <td>daynight</td> |
| <td></td> |
| <td></td> |
| <td>n </td> |
| <td>Toggles current day/night mode.</td> |
| </tr> |
| |
| </table> |
| |
| |
| |
| |
| <h2 id="auto-simulators">Media Browser and Messaging Simulators</h2> |
| |
| <p class="caution"><strong>Important:</strong> Use of the Android Media Browser and Messaging |
| Simulators for testing Android Auto apps is deprecated. Instead, we recommend using the |
| Desktop Head Unit, which enables your development machine to act as if it were an Android Auto head |
| unit.</p> |
| |
| <p>To get the simulators, open the |
| <a href="{@docRoot}tools/help/sdk-manager.html">SDK Manager</a> and download |
| them from <strong>Extras > Android Auto API Simulators</strong>.</p> |
| |
| <p>Before you begin testing, compile your app in your development environment. |
| Install your app and the Android simulator for the features you want to test |
| (that is, audio or messaging) on a physical or virtual device running Android |
| 5.0 (API level 21) or higher. To check the version of Android on the device, go |
| to <strong>Settings > About phone</strong> (or <strong>About tablet</strong>) |
| <strong>> Android Version</strong>.</p> |
| |
| <h3 id="testing-audio-apps">Testing audio apps</h3> |
| <p>To run and test audio apps:</p> |
| |
| <ol> |
| <li>Install the Android Media Browser simulator |
| ({@code <sdk>/extras/google/simulators/media-browser-simulator.apk}) on |
| the test device. You can do this using |
| the <a href="{@docRoot}tools/help/adb.html#move">adb</a> command line tool.</li> |
| <li>Enable <a href="{@docRoot}tools/device.html#developer-device-options"> |
| developer options</a> on the test device.</li> |
| <li>Install your app on the test device.</li> |
| <li>Launch the Android Media Browser simulator to see how your audio app |
| appears in Auto. If your app does not appear, stop the simulator from |
| <strong>Settings > Apps</strong> and restart it.</li> |
| </ol> |
| |
| |
| <h3 id="testing-messaging-apps">Testing messaging apps</h3> |
| <p>To run and test messaging apps:</p> |
| |
| <ol> |
| <li>Install the Android Messaging simulator |
| ({@code <sdk>/extras/google/simulators/messaging-simulator.apk}) |
| on the test device. You can do this using the |
| <a href="{@docRoot}tools/help/adb.html#move">adb</a> command line tool.</li> |
| <li>Enable the simulator to read notifications posted on the system: |
| <ol type="a"> |
| <li>Enable <a href="{@docRoot}tools/device.html#developer-device-options"> |
| developer options</a> on the test device.</li> |
| <li>Click <strong>Settings > Sounds & Notifications > Notification |
| Access</strong> and check the box labeled |
| <strong>Messaging Simulator</strong>.</li> |
| </ol> |
| <li>Install your app on the test device.</li> |
| <li>Launch the Android Messaging Simulator to see how your messaging app appears |
| in Auto. If your app does not appear, stop the simulator from |
| <strong>Settings > Apps</strong> and restart it.</li> |
| </ol> |
| |
| |