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