• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1page.title= Testing Apps for Auto
2page.tags="auto", "car", "automotive"
3page.article=true
4
5@jd:body
6
7<div id="tb-wrapper">
8<div id="tb">
9  <h2>Dependencies and Prerequisites</h2>
10  <ul>
11    <li>Android 5.0 (API level 21) or higher</li>
12    <li>Android Auto companion app installed</li>
13  </ul>
14  <h2>In this document</h2>
15  <ol>
16      <li><a href="#install">Installing the DHU</a></li>
17      <li><a href="#running-dhu">Running the DHU</a></li>
18      <li><a href="#dhu-commands">Issuing DHU Commands</a></li>
19  </ol>
20</div>
21</div>
22
23
24<p>
25  Testing your Auto app ensures that users do not encounter unexpected results or
26   have a poor experience when interacting with your apps. Android now provides
27    Desktop Head Unit (DHU), a testing tool for Auto apps that lets you test
28    pre-released versions of your Android Auto apps without having to work from
29    your car.</P>
30
31<p>The Desktop Head Unit (DHU) enables your development machine to emulate an
32Android Auto head unit, so you can easily run and test Android Auto apps.
33The DHU runs on Windows, Mac, and Linux hosts and replaces previous Android Auto
34 simulators, such as the Android Media Browser and Messaging simulators.</p>
35
36
37  <p class ="note"><strong>Note:</strong> It's important that you test your auto
38   app for the criteria listed on <a href={@docRoot}distribute/essentials/quality/auto.html>
39    Auto app quality </a> page prior to submitting to Google Play for review.
40  </p>
41  <p>
42   This lesson teaches you how to install and run the DHU on your development
43   machine for testing your apps. Once you’ve
44  installed the DHU, you can test your Android Auto apps by connecting your phone
45  and workstation via USB.
46
47  <h2 id ="install"> Installing the DHU</h2>
48  <p>Follow these steps to install the DHU on your development machine:</p>
49  <li>Enable developer mode on your mobile device, as described in
50    <a href="{@docRoot}tools/device.html#developer-device-options">Enabling On-device
51    Developer Options</a>. </li>
52  <li>Compile your app in your development environment and install your app on
53    a physical mobile device running Android 5.0 (API level 21) or higher. To check the
54    version of Android on a Nexus device, go to
55    <strong>Settings &gt; About phone</strong> (or <strong>About tablet</strong>) <strong>&gt;
56    Android version</strong>.</li>
57
58  <li>Install the
59     <a class="external-link"
60     href="https://play.google.com/store/apps/details?id=com.google.android.projection.gearhead&hl=en"
61     >Android Auto app</a> on the mobile device.</li>
62  <li>Open the <a href="{@docRoot}tools/help/sdk-manager.html">SDK Manager</a> and
63    download the DHU package <strong>Android Auto Desktop Head Unit emulator</strong> from the
64    <em>SDK Tools</em> tab. The DHU installs in the <code>&lt;sdk&gt;/extras/google/auto/</code>
65    directory.</li>
66  <li>If you are running the DHU on Linux, you must also install
67    the portaudio, libpng, sdl2, and sdl2_ttf libraries.
68    The procedure to do this varies depending on your Linux distribution. For example, on
69    Debian-derived Linux distributions, you can install the libraries with this command:
70
71<pre class="no-pretty-print">
72$ sudo apt-get install libsdl2-2.0-0 libsdl2-ttf-2.0-0 libportaudio2 libpng12-0
73</pre>
74
75  </li>
76</ol>
77
78<div class="cols">
79  <div class="col-6">
80    <img src="{@docRoot}images/training/auto-desktop-head-unit-context-menu-enabled.png"
81        alt="" >
82    <p class="img-caption">
83      <strong>Figure 1.</strong> Context menu with developer options.
84    </p>
85  </div>
86
87  <div class="col-6">
88    <img src="{@docRoot}images/training/auto-desktop-head-unit-server-running.png"
89        alt="" >
90    <p class="img-caption">
91      <strong>Figure 2.</strong> Notification that the head unit server is running.
92    </p>
93  </div>
94</div> <!-- end cols-->
95
96
97<h2 id="running-dhu">Running the DHU</h2>
98
99<p>Run the DHU by connecting your mobile device to a development machine and
100setting up a connection to the head unit server over <a href="{@docRoot}tools/help/adb.html">Android Debug Bridge
101  (ADB)</a>. Follow these steps to set up tunneling and start the DHU:</p>
102
103<ol>
104  <li>On the mobile device, enable Android Auto developer mode by starting the Android Auto
105    companion app, and then tapping the <i>Android Auto</i> toolbar title 10 times.
106    This step is only required the first time you run the companion app.
107  </li>
108  <li>If the server is not already running, select <strong>Start head unit server</strong>
109     from the Android Auto menu.
110    <p>On the device, a foreground service appears in the notification area. </p>
111  </li>
112
113  <li>In the Android Auto app, make sure the <strong>Only connect to known cars</strong> option
114    is disabled.</li>
115
116  <li>Connect the mobile device to the development machine via USB.</li>
117
118  <li>Make sure the mobile device has its screen unlocked, otherwise it cannot launch the DHU.</li>
119
120  <li>On the development machine, run the following {@code adb} command to
121    forward socket connections from the
122    development machine's port 5277 to the same port number on the Android device.
123    This configuration allows the DHU to connect to the head unit server running on your phone over
124    a TCP socket.
125    <pre class="no-pretty-print">$ adb forward tcp:5277 tcp:5277</pre>
126  </li>
127
128  <li>Start the DHU by running the command <code>desktop-head-unit.exe</code> (on Windows)
129    or <code>./desktop-head-unit</code> (on Mac or Linux) from the
130    <code>&lt;sdk&gt;/extras/google/auto/</code> directory.
131
132<pre class="no-pretty-print">$ cd &lt;sdk&gt;/extras/google/auto
133$ ./desktop-head-unit</pre>
134
135    <p>
136      By default, the head unit server connects over port 5277. To override the host or port
137      (for example, to forward over SSH), use the
138      <code>desktop-head-unit --adb &lt;[localhost:]port&gt;</code> flag, as in
139      the following example:
140    </p>
141
142    <pre class="no-pretty-print">$ ./desktop-head-unit --adb 5999</pre>
143    <p>
144    By default, the DHU emulates the most common form of Android Auto-compatible
145    head unit, which uses a touch screen user interface. You can simulate user
146    touches by clicking the DHU with a mouse. To emulate head units which use
147    a rotary controller for input, you can use the <code>-i controller</code> flag,
148   as in this example:
149   </p>
150   <pre class="no-pretty-print">$ ./desktop-head-unit -i controller</pre>
151   <p>
152   When the DHU is in rotary-controller mode you can simulate controller
153   operations by using keyboard shortcuts, as described in <a href=
154   "#cmd-bindings">DHU commands and key bindings</a>. If the DHU is in rotary
155   controller mode, it ignores mouse clicks; you must operate Android Auto with
156   the simulated rotary controller operations.
157  </p>
158  </li>
159</ol>
160
161
162
163
164<div class="figure" style="width:432px">
165
166    <img src="{@docRoot}images/training/auto-desktop-head-unit-wkst-launch.png"
167        alt="" >
168    <p class="img-caption">
169      <strong>Figure 4.</strong> DHU launches on the development machine.
170    </p>
171</div>
172
173    <img src="{@docRoot}images/training/auto-desktop-head-unit-launch.png"
174        alt="" >
175    <p class="img-caption">
176      <strong>Figure 3.</strong> Android Auto launches on the mobile device.
177    </p>
178
179<p>
180  After you set up and start the DHU, you can run DHU commands from the command
181  line to run and test your app from the terminal. You can also run these commands
182   by using keyboard shortcuts.
183</p>
184
185<h2 id="dhu-commands">Issuing DHU Commands</h2>
186
187<p>
188  DHU commands allow you to test your app with Android Auto features, such as
189  playing voice input or switching between night and day display mode. You can issue commands to
190  the DHU by running commands from the terminal window where you launched DHU.
191  You can also issue commands by selecting the DHU window and
192  using keyboard shortcuts. The DHU commands
193  and key bindings for all controls are listed in <a href="#cmd-bindings">DHU
194  commands and key bindings</a>.
195</p>
196
197
198<h3 id="day-night">Switching between day and night mode</h3>
199
200<p>
201  Android Auto supports different color schemes for day and night. You should test your app in both
202  day and night mode. You can switch between night and day mode in either of the
203  following ways:
204</p>
205
206<ul>
207  <li>Run the command <code>daynight</code> in the terminal where you launched the DHU.
208  </li>
209
210  <li>Select the DHU window and press the <strong>N</strong> key.
211  </li>
212</ul>
213
214<h3>Microphone testing</h3>
215
216<p>The DHU supports using a microphone for voice input. You can also instruct the DHU to treat
217a pre-recorded voice track as input, as if the DHU had heard the track through the microphone.</p>
218
219<p>To use a pre-recorded sound file as input, enter this command: </p>
220<pre class="no-pretty-print">
221$ mic play &lt;sound_file_path&gt;/&lt;sound_file&gt;.wav
222</pre>
223
224<p>For your convenience, we have provided the following sound files for common
225voice commands. These sound files are installed in the
226<code>&lt;sdk&gt;/extras/google/auto/voice/</code> directory.</p>
227
228<dl>
229  <dt>
230    <code>exitnav.wav</code>
231  </dt>
232
233  <dd>
234    "Exit navigation."
235  </dd>
236
237  <dt>
238    <code>navgoogle.wav</code>
239  </dt>
240
241  <dd>
242    "Navigate to 1600 Amphitheatre Parkway, Mountain View."
243  </dd>
244
245  <dt>
246    <code>navsoh.wav</code>
247  </dt>
248
249  <dd>
250    "Navigate to Sydney Opera House."
251  </dd>
252
253  <dt>
254    <code>nextturn.wav</code>
255  </dt>
256
257  <dd>
258    "When is my next turn?"
259  </dd>
260
261  <dt>
262    <code>showalternateroute.wav</code>
263  </dt>
264
265  <dd>
266    "Show alternate routes.""
267  </dd>
268
269  <dt>
270    <code>howlong.wav</code>
271  </dt>
272
273  <dd>
274    "How long until I get there?"
275  </dd>
276
277  <dt>
278    <code>navhome.wav</code>
279  </dt>
280
281  <dd>
282    "Navigate to home."
283  </dd>
284
285  <dt>
286    <code>navwork.wav</code>
287  </dt>
288
289  <dd>
290    "Navigate to work.""
291  </dd>
292
293  <dt>
294    <code>pause.wav</code>
295  </dt>
296
297  <dd>
298    "Pause music."
299  </dd>
300
301  <dt>
302    <code>showtraffic.wav</code>
303  </dt>
304
305  <dd>
306    "Show traffic."
307  </dd>
308</dl>
309<h3 id="cmd-bindings">DHU commands and key bindings</h3>
310
311<p>The DHU supports the following commands.</p>
312
313<p class="table-caption" id="table-commands"><strong>Table 1.</strong> Commands and key bindings</p>
314<table>
315<tr>
316  <th>Category</th>
317  <th>Command</th>
318  <th>Subcommand</th>
319  <th>Argument(s)</th>
320  <th>Keyboard Shortcut(s)</th>
321  <th>Description</th>
322</tr>
323
324<!--system-->
325
326<tr>
327<td rowspan="4">System</td>
328<td>help</td>
329<td></td>
330<td>[command]</td>
331<td></td>
332<td>Shows the full command set. Specifying a command name (for example, <code>help day</code>)
333  causes the system to show help for that command.</td>
334</tr>
335
336<tr>
337
338<td>quit</td>
339<td></td>
340<td></td>
341<td>Alt+q</td>
342<td>Quits the head unit.</td>
343</tr>
344
345<tr>
346
347<td>sleep</td>
348<td></td>
349<td>[seconds]</td>
350<td></td>
351<td>Sleeps for one second. Specifying an argument (for example, <code>sleep 30</code>) causes the
352system to sleep the specified number of seconds. This command
353is useful if you are writing scripts for the DHU. (You can run a script by using I/O redirection
354from the command line: <code>./desktop-head-unit &lt; script.txt</code> loads commands from the
355file <code>script.txt</code>.)</td>
356</tr>
357
358<tr>
359
360<td>screenshot</td>
361<td></td>
362<td>filename.png</td>
363<td></td>
364<td>Saves a screenshot to <code>filename.png</code>.</td>
365</tr>
366
367
368<!--microphone-->
369
370<tr>
371<td rowspan="3">Microphone</td>
372<td rowspan="3">mic</td>
373<td>begin</td>
374<td></td>
375<td>m </td>
376<td>Activates the microphone (equivalent to clicking the steering wheel's microphone button) and
377waits for input from the computer microphone.</td>
378</tr>
379
380<tr>
381
382
383<td>play</td>
384<td>filename.wav</td>
385<td></td>
386<td>Causes the DHU to treat <code>filename.wav</code> as voice input, as if it had heard that sound
387  through the microphone. You do not hear the sound file being played, but you do hear
388  the response from Android Auto.</td>
389</tr>
390
391<tr>
392
393
394<td>repeat</td>
395<td></td>
396<td></td>
397<td>Repeats the last <code>mic play</code> command, as if you had called <code>mic play</code>
398  again with the same sound file parameter.</td>
399</tr>
400
401<!--Input-->
402
403<tr>
404<td rowspan="7">Input</td>
405<td rowspan="6">dpad</td>
406<td>up <br> down <br> left <br> right</td>
407<td></td>
408<td>Arrow keys</td>
409<td>Simulates moving the rotary controller.</td>
410</tr>
411
412<tr>
413
414
415<td>soft left <br> soft right</td>
416<td></td>
417<td>Shift+Arrow keys</td>
418<td>Simulates pressing the side buttons available on some rotary controllers.</td>
419</tr>
420
421<tr>
422
423
424<td>click</td>
425<td></td>
426<td>Return</td>
427<td>Simulates pressing the rotary controller.</td>
428</tr>
429
430<tr>
431
432
433<td>back</td>
434<td></td>
435<td>Backspace</td>
436<td>Simulates pressing the <strong>back</strong> button available below some rotary
437  controllers.</td>
438</tr>
439
440<tr>
441
442
443<td>rotate left <br> rotate right</td>
444<td></td>
445<td>1 <br> 2</td>
446<td>Simulates rotating the rotary controller left (counter-clockwise) or right (clockwise).</td>
447</tr>
448
449<tr>
450
451
452<td>flick left <br> flick right</td>
453<td></td>
454<td>Shift+1 <br> Shift+2</td>
455<td>Simulates a fast spin of the rotary controller to the left (counter-clockwise) or right
456  (clockwise).</td>
457</tr>
458
459<tr>
460
461<td>tap</td>
462<td></td>
463<td>x y</td>
464<td></td>
465<td>Simulates a touch event at the specified coordinates. For example, <code>tap 50 100</code></td>
466</tr>
467
468
469<!--Day/Night-->
470
471<tr>
472<td rowspan="3">Day/Night</td>
473<td>day</td>
474<td></td>
475<td></td>
476<td>Shift+n</td>
477<td>Activates day mode (high brightness, full color).</td>
478</tr>
479
480<tr>
481
482<td>night</td>
483<td></td>
484<td> </td>
485<td>Ctrl+n </td>
486<td>Activates night mode (low brightness, high contrast).</td>
487</tr>
488
489<tr>
490
491<td>daynight</td>
492<td></td>
493<td></td>
494<td>n </td>
495<td>Toggles current day/night mode.</td>
496</tr>
497
498</table>
499
500
501
502
503<h2 id="auto-simulators">Media Browser and Messaging Simulators</h2>
504
505<p class="caution"><strong>Important:</strong> Use of the Android Media Browser and Messaging
506Simulators for testing Android Auto apps is deprecated. Instead, we recommend using the
507Desktop Head Unit, which enables your development machine to act as if it were an Android Auto head
508unit.</p>
509
510<p>To get the simulators, open the
511<a href="{@docRoot}tools/help/sdk-manager.html">SDK Manager</a> and download
512them from <strong>Extras &gt; Android Auto API Simulators</strong>.</p>
513
514<p>Before you begin testing, compile your app in your development environment.
515Install your app and the Android simulator for the features you want to test
516(that is, audio or messaging) on a physical or virtual device running Android
5175.0 (API level 21) or higher. To check the version of Android on the device, go
518to <strong>Settings &gt; About phone</strong> (or <strong>About tablet</strong>)
519<strong>&gt; Android Version</strong>.</p>
520
521<h3 id="testing-audio-apps">Testing audio apps</h3>
522<p>To run and test audio apps:</p>
523
524<ol>
525<li>Install the Android Media Browser simulator
526({@code &lt;sdk&gt;/extras/google/simulators/media-browser-simulator.apk}) on
527the test device. You can do this using
528the <a href="{@docRoot}tools/help/adb.html#move">adb</a> command line tool.</li>
529<li>Enable <a href="{@docRoot}tools/device.html#developer-device-options">
530developer options</a> on the test device.</li>
531<li>Install your app on the test device.</li>
532<li>Launch the Android Media Browser simulator to see how your audio app
533appears in Auto. If your app does not appear, stop the simulator from
534<strong>Settings &gt; Apps</strong> and restart it.</li>
535</ol>
536
537
538<h3 id="testing-messaging-apps">Testing messaging apps</h3>
539<p>To run and test messaging apps:</p>
540
541<ol>
542<li>Install the Android Messaging simulator
543  ({@code &lt;sdk&gt;/extras/google/simulators/messaging-simulator.apk})
544on the test device. You can do this using the
545<a href="{@docRoot}tools/help/adb.html#move">adb</a> command line tool.</li>
546<li>Enable the simulator to read notifications posted on the system:
547<ol type="a">
548  <li>Enable <a href="{@docRoot}tools/device.html#developer-device-options">
549developer options</a> on the test device.</li>
550  <li>Click <strong>Settings &gt; Sounds &amp; Notifications &gt; Notification
551    Access</strong> and check the box labeled
552    <strong>Messaging Simulator</strong>.</li>
553</ol>
554<li>Install your app on the test device.</li>
555<li>Launch the Android Messaging Simulator to see how your messaging app appears
556in Auto. If your app does not appear, stop the simulator from
557<strong>Settings &gt; Apps</strong> and restart it.</li>
558</ol>
559
560
561