Home | History | Annotate | Download | only in accessories
      1 <html devsite>
      2   <head>
      3     <title>Android Open Accessory Protocol 1.0</title>
      4     <meta name="project_path" value="/_project.yaml" />
      5     <meta name="book_path" value="/_book.yaml" />
      6   </head>
      7   <body>
      8   <!--
      9       Copyright 2017 The Android Open Source Project
     10 
     11       Licensed under the Apache License, Version 2.0 (the "License");
     12       you may not use this file except in compliance with the License.
     13       You may obtain a copy of the License at
     14 
     15           http://www.apache.org/licenses/LICENSE-2.0
     16 
     17       Unless required by applicable law or agreed to in writing, software
     18       distributed under the License is distributed on an "AS IS" BASIS,
     19       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     20       See the License for the specific language governing permissions and
     21       limitations under the License.
     22   -->
     23 
     24 
     25 <p>Android USB accessories must adhere to the Android Open Accessory (AOA)
     26 protocol, which defines how an accessory detects and sets up communication with
     27 an Android-powered device. Accessories should carry out the following steps:</p>
     28 
     29 <ol>
     30 <li>Wait for and detect a connected device.</li>
     31 <li>Determine the device's accessory mode support.</li>
     32 <li>Attempt to start the device in accessory mode (if needed).</li>
     33 <li>If the device supports AOA, establish communication with the device.</li>
     34 </ol>
     35 
     36 <p>The following sections explain how to implement these steps.</p>
     37 
     38 <p class="note"><strong>Note:</strong> When developing a new accessory that
     39 connects to an Android device over USB, use
     40 <a href="aoa2.html">AOAv2</a>.</p>
     41 
     42 <h2 id="wait-for-and-detect-connected-devices">Wait for and detect connected
     43 devices</h2>
     44 
     45 <p>Accessories should continuously check for connected Android-powered devices.
     46 When a device is connected, the accessory should determine if the device
     47 supports accessory mode.</p>
     48 
     49 <h2 id="determine-accessory-mode-support">Determine accessory mode support</h2>
     50 
     51 <p>When an Android-powered device connects, it can be in one of three states:
     52 </p>
     53 
     54 <ul>
     55 <li>Supports Android accessory mode and is already in accessory mode.</li>
     56 <li>Supports Android accessory mode but it is not in accessory mode.</li>
     57 <li>Does not support Android accessory mode.</li>
     58 </ul>
     59 
     60 <p>During the initial connection, the accessory should check the vendor ID and
     61 product ID of the connected device's USB device descriptor. The vendor ID
     62 should match Google's ID (<code>0x18D1</code>). If the device is already in
     63 accessory mode, the product ID should be <code>0x2D00</code> or
     64 <code>0x2D01</code> and the accessory can
     65 <a href="#establish-communication-with-the-device">establish communication with
     66 the device</a> through bulk transfer endpoints using its own communication
     67 protocol (the device does not need to be started in accessory mode).</p>
     68 
     69 <p class="note"><strong>Note:</strong> <code>0x2D00</code> is reserved for
     70 Android-powered devices that support accessory mode. <code>0x2D01</code> is
     71 reserved for devices that support accessory mode as well as the Android Debug
     72 Bridge (ADB) protocol, which exposes a second interface with two bulk endpoints
     73 for ADB. You can use these endpoints for debugging the accessory application if
     74 you are simulating the accessory on a computer. In general, do not use this
     75 interface unless the accessory implements a passthrough to ADB on the device.
     76 </p>
     77 
     78 <p>If the vendor ID or the product ID found in USB device descriptor do not
     79 match expected values, the accessory cannot determine if the device supports
     80 Android accessory mode. The accessory should attempt to start the device in
     81 accessory mode (detailed below) to determine device support.</p>
     82 
     83 <h2 id="attempt-to-start-in-accessory-mode">Attempt to start in accessory
     84 mode</h2>
     85 
     86 <p>If the vendor and product IDs do not correspond to an Android-powered device
     87 in accessory mode, the accessory cannot discern whether the device supports (but
     88 is not in) accessory mode or if the device does not support accessory mode. This
     89 can occur because devices that support accessory mode (but are not in accessory
     90 mode) initially report the <em>device</em> manufacturer vendor and product IDs
     91 instead of the <em>AOA</em> vendor and product IDs.</p>
     92 
     93 <p>The accessory should try to start the device in accessory mode to determine
     94 if the device supports that mode:</p>
     95 
     96 <ol>
     97   <li>Send a 51 control request ("Get Protocol") to determine if the device
     98   supports the Android accessory protocol. If the device supports the protocol,
     99   it returns a non-zero number that represents the supported protocol version.
    100   The control request is on endpoint 0 with the following characteristics:
    101 
    102 <pre class="devsite-click-to-copy">
    103 requestType:    USB_DIR_IN | USB_TYPE_VENDOR
    104 request:        51
    105 value:          0
    106 index:          0
    107 data:           protocol version number (16 bits little endian sent from the
    108                 device to the accessory)
    109 </pre>
    110   </li>
    111 
    112   <li>If the device returns a supported protocol version, send a control request
    113   with identifying string information to the device. This information allows the
    114   device to determine an appropriate application for the accessory (or present a
    115   URL to the user if an appropriate application does not exist). The control
    116   request is on endpoint 0 (for each string ID) with the following
    117   characteristics:
    118 
    119 <pre class="devsite-click-to-copy">
    120 requestType:    USB_DIR_OUT | USB_TYPE_VENDOR
    121 request:        52
    122 value:          0
    123 index:          string ID
    124 data            zero terminated UTF8 string sent from accessory to device
    125 </pre>
    126 
    127   <p>The following string IDs are supported, with a maximum size of 256 bytes
    128   for each string (must be zero-terminated with <code>\0</code>).</p>
    129 
    130 <pre class="devsite-click-to-copy">
    131 manufacturer name:  0
    132 model name:         1
    133 description:        2
    134 version:            3
    135 URI:                4
    136 serial number:      5
    137 </pre>
    138   </li>
    139 
    140   <li>Send a control request to ask the device to start in accessory mode. The
    141   control request is on endpoint 0 with the following characteristics:
    142 
    143 <pre class="devsite-click-to-copy">
    144 requestType:    USB_DIR_OUT | USB_TYPE_VENDOR
    145 request:        53
    146 value:          0
    147 index:          0
    148 data:           none
    149 </pre>
    150   </li>
    151 </ol>
    152 
    153 <p>After completing these steps, the accessory should wait for the connected USB
    154 device to re-introduce itself on the bus in accessory mode, then re-enumerate
    155 connected devices. The algorithm
    156 <a href="#determine-accessory-mode-support">determines accessory mode support</a>
    157 by checking the vendor and product IDs, which should be correct (e.g. correspond
    158 to Google's vendor and product IDs instead of the device manufacturer's IDs) if
    159 the device successfully switched to accessory mode. If IDs are correct, the
    160 accessory moves to <a href="#establish-communication-with-the-device">establish
    161 communication with the device</a>.</p>
    162 
    163 <p class="note"><strong>Note:</strong> AOA does not currently support
    164 simultaneous AOA and MTP connections. To switch from AOA to MTP, the accessory
    165 must first disconnect the USB device (either physically or in an electrically
    166 equivalent way) then reconnect using MTP.</p>
    167 
    168 <p>If any step fails, the accessory determines the device does not support
    169 Android accessory mode and waits for the next device to connect.</p>
    170 
    171 
    172 <h2 id="establish-communication-with-the-device">Establish communication with
    173 the device</h2>
    174 
    175 <p>If the accessory detects an Android-powered device in accessory mode, the
    176 accessory can query the device interface and endpoint descriptors to obtain the
    177 bulk endpoints for communicating with the device.</p>
    178 
    179 <p>The number of interfaces and bulk endpoints depends on the product ID. An
    180 Android-powered device with a product ID of:</p>
    181 
    182 <ul>
    183 <li><code>0x2D00</code> has one interface with two bulk endpoints for input and
    184 output communication.</li>
    185 <li><code>0x2D01</code> has two interfaces with two bulk endpoints each for
    186 input and output communication. The first interface handles standard
    187 communication and the second interface handles ADB communication. To use an
    188 interface, locate the first bulk input and output endpoints, set the
    189 device configuration to a value of 1 with a <code>SET_CONFIGURATION</code>
    190 (<code>0x09</code>) device request, then communicate using the endpoints.</li>
    191 </ul>
    192 
    193   </body>
    194 </html>
    195