upload android base code part8

This commit is contained in:
August 2018-08-08 20:10:12 +08:00
parent 841ae54672
commit 5425409085
57075 changed files with 9846578 additions and 0 deletions

View file

@ -0,0 +1,194 @@
<html devsite>
<head>
<title>Android Open Accessory Protocol 1.0</title>
<meta name="project_path" value="/_project.yaml" />
<meta name="book_path" value="/_book.yaml" />
</head>
<body>
<!--
Copyright 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>Android USB accessories must adhere to the Android Open Accessory (AOA)
protocol, which defines how an accessory detects and sets up communication with
an Android-powered device. Accessories should carry out the following steps:</p>
<ol>
<li>Wait for and detect a connected device.</li>
<li>Determine the device's accessory mode support.</li>
<li>Attempt to start the device in accessory mode (if needed).</li>
<li>If the device supports AOA, establish communication with the device.</li>
</ol>
<p>The following sections explain how to implement these steps.</p>
<p class="note"><strong>Note:</strong> When developing a new accessory that
connects to an Android device over USB, use
<a href="aoa2.html">AOAv2</a>.</p>
<h2 id="wait-for-and-detect-connected-devices">Wait for and detect connected
devices</h2>
<p>Accessories should continuously check for connected Android-powered devices.
When a device is connected, the accessory should determine if the device
supports accessory mode.</p>
<h2 id="determine-accessory-mode-support">Determine accessory mode support</h2>
<p>When an Android-powered device connects, it can be in one of three states:
</p>
<ul>
<li>Supports Android accessory mode and is already in accessory mode.</li>
<li>Supports Android accessory mode but it is not in accessory mode.</li>
<li>Does not support Android accessory mode.</li>
</ul>
<p>During the initial connection, the accessory should check the vendor ID and
product ID of the connected device's USB device descriptor. The vendor ID
should match Google's ID (<code>0x18D1</code>). If the device is already in
accessory mode, the product ID should be <code>0x2D00</code> or
<code>0x2D01</code> and the accessory can
<a href="#establish-communication-with-the-device">establish communication with
the device</a> through bulk transfer endpoints using its own communication
protocol (the device does not need to be started in accessory mode).</p>
<p class="note"><strong>Note:</strong> <code>0x2D00</code> is reserved for
Android-powered devices that support accessory mode. <code>0x2D01</code> is
reserved for devices that support accessory mode as well as the Android Debug
Bridge (ADB) protocol, which exposes a second interface with two bulk endpoints
for ADB. You can use these endpoints for debugging the accessory application if
you are simulating the accessory on a computer. In general, do not use this
interface unless the accessory implements a passthrough to ADB on the device.
</p>
<p>If the vendor ID or the product ID found in USB device descriptor do not
match expected values, the accessory cannot determine if the device supports
Android accessory mode. The accessory should attempt to start the device in
accessory mode (detailed below) to determine device support.</p>
<h2 id="attempt-to-start-in-accessory-mode">Attempt to start in accessory
mode</h2>
<p>If the vendor and product IDs do not correspond to an Android-powered device
in accessory mode, the accessory cannot discern whether the device supports (but
is not in) accessory mode or if the device does not support accessory mode. This
can occur because devices that support accessory mode (but are not in accessory
mode) initially report the <em>device</em> manufacturer vendor and product IDs
instead of the <em>AOA</em> vendor and product IDs.</p>
<p>The accessory should try to start the device in accessory mode to determine
if the device supports that mode:</p>
<ol>
<li>Send a 51 control request ("Get Protocol") to determine if the device
supports the Android accessory protocol. If the device supports the protocol,
it returns a non-zero number that represents the supported protocol version.
The control request is on endpoint 0 with the following characteristics:
<pre class="devsite-click-to-copy">
requestType: USB_DIR_IN | USB_TYPE_VENDOR
request: 51
value: 0
index: 0
data: protocol version number (16 bits little endian sent from the
device to the accessory)
</pre>
</li>
<li>If the device returns a supported protocol version, send a control request
with identifying string information to the device. This information allows the
device to determine an appropriate application for the accessory (or present a
URL to the user if an appropriate application does not exist). The control
request is on endpoint 0 (for each string ID) with the following
characteristics:
<pre class="devsite-click-to-copy">
requestType: USB_DIR_OUT | USB_TYPE_VENDOR
request: 52
value: 0
index: string ID
data zero terminated UTF8 string sent from accessory to device
</pre>
<p>The following string IDs are supported, with a maximum size of 256 bytes
for each string (must be zero-terminated with <code>\0</code>).</p>
<pre class="devsite-click-to-copy">
manufacturer name: 0
model name: 1
description: 2
version: 3
URI: 4
serial number: 5
</pre>
</li>
<li>Send a control request to ask the device to start in accessory mode. The
control request is on endpoint 0 with the following characteristics:
<pre class="devsite-click-to-copy">
requestType: USB_DIR_OUT | USB_TYPE_VENDOR
request: 53
value: 0
index: 0
data: none
</pre>
</li>
</ol>
<p>After completing these steps, the accessory should wait for the connected USB
device to re-introduce itself on the bus in accessory mode, then re-enumerate
connected devices. The algorithm
<a href="#determine-accessory-mode-support">determines accessory mode support</a>
by checking the vendor and product IDs, which should be correct (e.g. correspond
to Google's vendor and product IDs instead of the device manufacturer's IDs) if
the device successfully switched to accessory mode. If IDs are correct, the
accessory moves to <a href="#establish-communication-with-the-device">establish
communication with the device</a>.</p>
<p class="note"><strong>Note:</strong> AOA does not currently support
simultaneous AOA and MTP connections. To switch from AOA to MTP, the accessory
must first disconnect the USB device (either physically or in an electrically
equivalent way) then reconnect using MTP.</p>
<p>If any step fails, the accessory determines the device does not support
Android accessory mode and waits for the next device to connect.</p>
<h2 id="establish-communication-with-the-device">Establish communication with
the device</h2>
<p>If the accessory detects an Android-powered device in accessory mode, the
accessory can query the device interface and endpoint descriptors to obtain the
bulk endpoints for communicating with the device.</p>
<p>The number of interfaces and bulk endpoints depends on the product ID. An
Android-powered device with a product ID of:</p>
<ul>
<li><code>0x2D00</code> has one interface with two bulk endpoints for input and
output communication.</li>
<li><code>0x2D01</code> has two interfaces with two bulk endpoints each for
input and output communication. The first interface handles standard
communication and the second interface handles ADB communication. To use an
interface, locate the first bulk input and output endpoints, set the
device configuration to a value of 1 with a <code>SET_CONFIGURATION</code>
(<code>0x09</code>) device request, then communicate using the endpoints.</li>
</ul>
</body>
</html>

View file

@ -0,0 +1,288 @@
<html devsite>
<head>
<title>Android Open Accessory Protocol 2.0</title>
<meta name="project_path" value="/_project.yaml" />
<meta name="book_path" value="/_book.yaml" />
</head>
<body>
<!--
Copyright 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>This document describes changes in the Android Open Accessory (AOA) protocol
since its initial release and supplements
<a href="aoa.html">AOA 1.0 documentation</a>. AOAv2
adds the following features:</p>
<ul>
<li>Audio output (from the Android device to the accessory).</li>
<li>Support for the accessory acting as one or more Human Interface Devices
(HID) to the Android device.</li>
</ul>
<p>Android SDK APIs available to Android application developers are unchanged.
</p>
<h2 id="detecting-android-open-accessory-20-support">Detecting AOAv2 support</h2>
<p>To determine if a connected Android device supports accessories and the
supported protocol version, an accessory must send a <code>getProtocol()</code>
command and check the result. Android devices that support only the feautures
in AOAv1 must return <code>1</code> as the protocol version; devices that
support the additional feautres in AOAv2 must return <code>2</code> as the
protocol version. AOAv2 is backward-compatible with AOAv1, so accessories
designed for the original accessory protocol continue to work with newer Android
devices.</p>
<p>The following example from the Accessory Development Kit 2011
<a href="http://developer.android.com/tools/adk/adk2.html#src-download">source code</a>
(<code>&lt;adk-src&gt;/adk1/board/AndroidAccessory/AndroidAccessory.cpp</code>)
library demonstrates this protocol check:</p>
<pre class="devsite-click-to-copy">
bool AndroidAccessory::switchDevice(byte addr)
{
int protocol = getProtocol(addr);
if (protocol &gt;= 1) {
Serial.print("device supports protocol 1 or higher\n");
} else {
Serial.print("could not read device protocol version\n");
return false;
}
sendString(addr, ACCESSORY_STRING_MANUFACTURER, manufacturer);
sendString(addr, ACCESSORY_STRING_MODEL, model);
sendString(addr, ACCESSORY_STRING_DESCRIPTION, description);
sendString(addr, ACCESSORY_STRING_VERSION, version);
sendString(addr, ACCESSORY_STRING_URI, uri);
sendString(addr, ACCESSORY_STRING_SERIAL, serial);
usb.ctrlReq(addr, 0, USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_VENDOR |
USB_SETUP_RECIPIENT_DEVICE, ACCESSORY_START, 0, 0, 0, 0, NULL);
return true;
}
</pre>
<p>AOAv2 includes new USB product IDs for each combination of USB interfaces
available in accessory mode:</p>
<table id="AOA-version-comparison">
<tbody>
<tr>
<th>Version</th>
<th>Product ID</th>
<th>Communication</th>
<th>Description</th>
</tr>
<tr>
<td rowspan="2">AOAv1</td>
<td><code>0x2D00</code></td>
<td>accessory</td>
<td>Provides two bulk endpoints for communicating with an Android
application.</td>
</tr>
<tr>
<td><code>0x2D01</code></td>
<td>accessory + adb</td>
<td>For debugging purposes during accessory development. Available only if the
user has enabled <em>USB Debugging</em> in the Android device settings.</td>
</tr>
<tr>
<td rowspan="4">AOAv2</td>
<td><code>0x2D02</code></td>
<td>audio</td>
<td>For streaming audio from an Android device to an accessory.</td>
</tr>
<tr>
<td><code>0x2D03</code></td>
<td>audio + adb</td>
<td></td>
</tr>
<tr>
<td><code>0x2D04</code></td>
<td>accessory + audio</td>
<td></td>
</tr>
<tr>
<td><code>0x2D05</code></td>
<td>accessory + audio + adb</td>
<td></td>
</tr>
</tbody>
</table>
<p>Product IDs used in AOAv1 (<code>0x2D00</code> and <code>0x2D01</code>)
continue to be supported in AOAv2.</p>
<h2 id="audio-support">Audio support</h2>
<p>AOAv2 includes support for audio output from an Android device to an
accessory via a standard USB audio class interface capable of 2 channel, 16-bit
PCM audio with a bit rate of 44100 Khz (additional audio modes may be added in
the future).</p>
<p>To enable audio support, the accessory must send a new USB control request:
</p>
<pre class="devsite-click-to-copy">
**SET_AUDIO_MODE**
requestType: USB_DIR_OUT | USB_TYPE_VENDOR
request: 58
value: 0 for no audio (default),
1 for 2 channel, 16-bit PCM at 44100 KHz
index: 0
data none
</pre>
<p>This command must be sent <em>before</em> sending the
<code>ACCESSORY_START</code> command for entering accessory mode.</p>
<h2 id="hid-support">HID support</h2>
<p>AOAv2 allows accessories to register one or more USB Human Interface
Devices (HID) with an Android device. This approach reverses the direction of
communication for typical USB HID devices such as USB mice and keyboards.
Normally, the HID device is a peripheral connected to a USB host (i.e. a
personal computer), but in AOA the USB host can act as one or more input
devices to a USB peripheral.</p>
<p>HID support is a proxy for standard HID events; the
implementation makes no assumptions about the content or type of events and
simply passes it through to the input system, enabling an AOAv2 accessory to
act as any HID device (mouse, keyboard, game controller, etc.). You can use HID
support to provide basic functionality, such as a play/pause button on a media
dock, or for advanced functionality such as a docking station with a mouse and
full QWERTY keyboard.</p>
<p>AOAv2 adds new USB control requests that allow the accessory to act as
one or more HID input devices to the Android device. HID support is handled
entirely through control requests on endpoint zero, so no new USB interface is
needed. The four new control requests are:</p>
<ul>
<li><strong>ACCESSORY_REGISTER_HID</strong> registers a new HID device with the
Android device. The accessory provides an ID used to identify the HID device for
the other three calls. This ID is valid until USB disconnects or until the
accessory sends <code>ACCESSORY_UNREGISTER_HID</code> to unregister the HID
device.</li>
<li><strong>ACCESSORY_UNREGISTER_HID</strong> unregisters a HID device
previously registered with <code>ACCESSORY_REGISTER_HID</code>.</li>
<li><strong>ACCESSORY_SET_HID_REPORT_DESC</strong> sends a report descriptor for
a HID device to the Android device. This request is used to describe the
capabilities of the HID device and must be sent before reporting any HID events
to the Android device. If the report descriptor is larger than the maximum
packet size for endpoint zero, multiple
<code>ACCESSORY_SET_HID_REPORT_DESC</code> commands are sent to transfer the
entire descriptor.</li>
<li><strong>ACCESSORY_SEND_HID_EVENT</strong> sends input events from the
accessory to the Android device.</li>
</ul>
<p>The code definitions for the new control requests are:</p>
<pre class="devsite-click-to-copy">
/* Control request for registering a HID device.
* Upon registering, a unique ID is sent by the accessory in the
* value parameter. This ID will be used for future commands for
* the device
*
* requestType: USB_DIR_OUT | USB_TYPE_VENDOR
* request: ACCESSORY_REGISTER_HID_DEVICE
* value: Accessory assigned ID for the HID device
* index: total length of the HID report descriptor
* data none
*/
#define ACCESSORY_REGISTER_HID 54
/* Control request for unregistering a HID device.
*
* requestType: USB_DIR_OUT | USB_TYPE_VENDOR
* request: ACCESSORY_REGISTER_HID
* value: Accessory assigned ID for the HID device
* index: 0
* data none
*/
#define ACCESSORY_UNREGISTER_HID 55
/* Control request for sending the HID report descriptor.
* If the HID descriptor is longer than the endpoint zero max packet size,
* the descriptor will be sent in multiple ACCESSORY_SET_HID_REPORT_DESC
* commands. The data for the descriptor must be sent sequentially
* if multiple packets are needed.
*
* requestType: USB_DIR_OUT | USB_TYPE_VENDOR
* request: ACCESSORY_SET_HID_REPORT_DESC
* value: Accessory assigned ID for the HID device
* index: offset of data in descriptor
* (needed when HID descriptor is too big for one packet)
* data the HID report descriptor
*/
#define ACCESSORY_SET_HID_REPORT_DESC 56
/* Control request for sending HID events.
*
* requestType: USB_DIR_OUT | USB_TYPE_VENDOR
* request: ACCESSORY_SEND_HID_EVENT
* value: Accessory assigned ID for the HID device
* index: 0
* data the HID report for the event
*/
#define ACCESSORY_SEND_HID_EVENT 57
</pre>
<h2 id="interoperability-with-aoa-10-features">Interoperability with AOAv1</h2>
<p>The original protocol (<a href="aoa.html">AOAv1</a>)
provides support for an Android application to communicate directly with a USB
host (accessory) over USB. AOAv2 continues this support and adds new features
to allow the accessory to communicate with the Android operating system itself
(specifically the audio and input systems). The design of AOAv2 makes it
possible to build an accessory that uses the new audio and HID support
in addition to the original feature set. Simply use the new features along with
the original features.</p>
<h2 id="connecting-aoa-20-without-an-android-app">Connecting AOAv2 without an
Android app</h2>
<p>You can design an accessory (such as an audio dock) that uses audio and HID
support but does not communicate with an application on the Android device. For
these accessories, users do not need to receive dialog prompts for finding and
associating the newly attached accessory with an Android application that can
communicate with it.</p>
<p>To suppress such dialogs after an accessory connects, the
accessory can choose not to send the manufacturer and model names to the Android
device. When these strings are not provided to the Android device:</p>
<ul>
<li>The system does not attempt to find an application to communicate with the
accessory.</li>
<li>The accessory USB interface is not present in the Android device USB
configuration after the device enters accessory mode.</li>
</ul>
</body>
</html>

View file

@ -0,0 +1,96 @@
<html devsite>
<head>
<title>Building Audio Accessories</title>
<meta name="project_path" value="/_project.yaml" />
<meta name="book_path" value="/_book.yaml" />
</head>
<body>
<!--
Copyright 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>When implementing an audio accessory such as a headset, headphone amplifier,
microphone, DAC/ADC, or dock, consider how the accessory connects to Android
devices. The following sections describe wired 3.5 mm headset connections,
Universal Serial Bus (USB) connections, and Bluetooth connections for streaming
music or other audio content.</p>
<h2 id="audio-over-35mm">Audio over 3.5 mm headset connector</h2>
<p>Many Android devices include a 3.5 mm (&#8220;mini&#8221;) headset connector.
In addition to traditional stereo output and mono input features, the
<a href="headset/plug-headset-spec.html">3.5 mm headset specification</a>
defines standard impedances and functions that enable interoperability between
a range of Android devices and headsets.</p>
<h2 id="audio-over-usb">Audio over USB</h2>
<p>Android can use USB in several modes:</p>
<ul>
<li><strong>Development</strong>. Does not support audio. </li>
<li><strong>Accessory</strong>. Provided by Android Open Accessory (AOA) 2.0
and provides limited audio capability, as described in
<a href="custom.html#audio-over-usb">Connecting custom audio over USB</a>.
</li>
<li><strong>Host</strong>. Enables the Android device to drive the USB bus
and operate with a wide range of USB-based peripherals, including audio
interfaces. Devices that implement host mode will be compatible with USB
headsets that follow the
<a href="/devices/accessories/headset/usb-headset-spec.html">USB
headset specification</a>.
Host mode audio is described in
<a href="/devices/audio/usb.html">USB Digital Audio</a>.
</ul>
<h2 id="audio-over-bluetooth">Audio over Bluetooth</h2>
<p>An accessory that connects with Android over Bluetooth can use an Advanced
Audio Distribution Profile (A2DP) connection to stream music for playback. Playing
audio over Bluetooth with A2DP is supported on Android 1.5 (API Level 3) and
higher. An Android user can connect to an accessory that supports this profile
using the system Settings &gt; Bluetooth and play music directly to the
accessory without a secondary application.</p>
<p>As of Android 3.0 (API Level 11), applications can operate an A2DP connection
using the
<a href="http://developer.android.com/reference/android/bluetooth/BluetoothA2dp.html">
<code>BluetoothA2dp</code></a> class. To provide a custom application for
output to an audio accessory, you must use Android 3.0 or higher.
</p>
<h3 id="next-steps_1">Next steps</h3>
<p>To get started building an audio accessory that uses a Bluetooth connection:
</p>
<ul>
<li>Select a hardware platform or build a hardware device that can support
Bluetooth communications and the A2DP connection profile.</li>
<li>Review the ADK 2012
<a href="http://developer.android.com/tools/adk/adk2.html#src-download">firmware
source code</a> (<code>&lt;adk-src&gt;/adk2012/board/library/ADK2/</code>),
which includes an example implementation of an audio playback accessory using
a Bluetooth connection.</li>
</ul>
<p class="note"><strong>Note:</strong> The ADK 2012 source code includes an open
source Bluetooth stack built for the Texas Instruments CC2564 chip, but is
designed to work with any Bluetooth chip that implements a standard
Host/Controller Interface (HCI).</p>
<h2 id="midi-over-usb">MIDI over USB and Bluetooth LE</h2>
<p>Both USB and Bluetooth Low Energy can be used as transports for the
<a href="http://en.wikipedia.org/wiki/MIDI">MIDI</a> protocol. For details, see
<a href="/devices/audio/midi.html">MIDI</a>.</p>
</body>
</html>

View file

@ -0,0 +1,134 @@
<html devsite>
<head>
<title>Custom Accessories</title>
<meta name="project_path" value="/_project.yaml" />
<meta name="book_path" value="/_book.yaml" />
</head>
<body>
<!--
Copyright 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>An accessory for Android can be anything: keyboard, thermometer, robot,
lighting control, or anything else you can imagine. All Android accessories
connect to an Android device in some way, so when building an accessory you must
consider the type of connections your accessory will use. This page provides a
quick overview of your options for connecting your Android accessory and
a list of resources to help you get started.</p>
<h2 id="connecting-over-usb">Connecting over USB</h2>
<p>An accessory that connects to an Android device through a USB cable must
support the Android Open Accessory (AOA) protocol, which specifies how an
accessory can establish communication with an Android device via USB.
Due to the low power output of Android devices, AOA requires the accessory to
act as a USB host, meaning the connecting accessory must power the bus.</p>
<p>AOA has two versions that support different types of communication:</p>
<ul>
<li><strong>AOAv1</strong>. Supports generic accessory communication and adb
debugging. Available in Android 3.1 (API Level 12) and higher and supported
through an
<a href="https://developers.google.com/android/add-ons/google-apis/">Add-On
Library</a> in Android 2.3.4 (API Level 10) and higher.</li>
<li><strong>AOAv2</strong>. Supports audio streaming and human interface
device (HID) capabilities. Available in Android 4.1 (API Level 16).</li>
</ul>
<p>If you use the general accessory protocol to communicate with your accessory
(rather than the adb or audio protocol), you must provide an Android application
that can detect the connection of your USB accessory and establish communication.
</p>
<h3 id="next-steps_0">Next steps</h3>
<p>To get started building an Android accessory that uses a USB connection:
</p>
<ul>
<li>Select a hardware platform or build a hardware device that can support USB
host mode.</li>
<li>Review <a href="protocol.html">AOA</a> specifications to
understand how to implement this protocol on your accessory hardware.
Implementing <a href="aoa2.html">AOAv2</a> is
recommended for all new Android USB accessories.</li>
<li>Review the ADK 2012
<a href="http://developer.android.com/tools/adk/adk2.html#src-download">firmware
source code</a> (<code>&lt;adk-src&gt;/adk2012/board/library/ADK2/</code>),
which demonstrates an implementation of an accessory using a USB connection for
general data communications and audio streaming.</li>
<li>When planning to build an Android application that communicates with your
accessory via USB, review the ADK 2012 Android
<a href="http://developer.android.com/tools/adk/adk2.html#src-download">application
source code</a> (<code>&lt;adk-src&gt;/adk2012/app/</code>).</li>
</ul>
<h2 id="connecting-over-bluetooth">Connecting over Bluetooth</h2>
<p>An accessory that connects with Android devices over a Bluetooth connection
can use connection profiles supported by Android, including the Simple Serial
Protocol (SSP) and Advanced Audio Distribution Profile (A2DP) profile. An
accessory that uses Bluetooth to connect to Android devices must support
Bluetooth communications and at least one of the supported connection profiles.
</p>
<p>Users must enable Bluetooth on their Android device and pair with your
accessory to use the accessory. You can also provide a secondary Android
application that handles specialized communication such as data input or control
outputs to interface with your accessory.</p>
<h3 id="next-steps_1">Next steps</h3>
<p>To get started building an Android accessory that uses a Bluetooth connection:
</p>
<ul>
<li>Select a hardware platform or build an hardware device that can support
Bluetooth communications and an Android supported connection profile, such as
SSP or A2DP.</li>
<li>Review the ADK 2012
<a href="http://developer.android.com/tools/adk/adk2.html#src-download">firmware
source code</a> (<code>&lt;adk-src&gt;/adk2012/board/library/ADK2/</code>),
which includes an example implementation of general data communications and
audio streaming using a Bluetooth connection.</li>
<li>When planning to build an Android application that communicates with your
accessory via Bluetooth, review the ADK 2012 Android
<a href="http://developer.android.com/tools/adk/adk2.html#src-download">application
source code</a> (<code>&lt;adk-src&gt;/adk2012/app/</code>).</li>
</ul>
<p class="note"><strong>Note:</strong> The ADK 2012 source code includes an open
source Bluetooth stack built for the Texas Instruments CC2564 chip but is
designed to work with any Bluetooth chip that supports a standard
Host/Controller Interface (HCI).</p>
<h2 id="audio-over-usb">Connecting audio over USB</h2>
<p>An accessory that connects with Android over USB can use AOAv2 (supported on
Android 4.1 (API Level 16) and higher. After an Android device connects to an
accessory that supports this protocol, the Android system treats it as a
standard audio output device and routes all audio to that accessory. No
secondary software application is required on the Android device.</p>
<p class="note"><strong>Note:</strong> Due to the low power output of Android
devices, AOA requires accessories to act as a USB host, meaning the connecting
accessory must power the bus.</p>
<h3 id="next-steps_2">Next steps</h3>
<p>To get started building an audio accessory that uses a USB connection, see
<a href="#next-steps_0">next steps for USB connections.</a></p>
<p>AOAv2 also supports the
<a href="aoa2.html#hid-support">human interface device</a>
(HID) protocol through a USB connection, enabling accessories such as audio
docks to provide hardware play back controls such as pause, fast-forward or
volume buttons.</p>
</body>
</html>

View file

@ -0,0 +1,195 @@
<html devsite>
<head>
<title>Headset Expected Behavior</title>
<meta name="project_path" value="/_project.yaml" />
<meta name="book_path" value="/_book.yaml" />
</head>
<body>
<!--
Copyright 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>
This article details the functional requirements for
<a href="plug-headset-spec.html">3.5 mm plug</a> and
<a href="usb-headset-spec.html">USB</a> headsets.</p>
<p>
When verifying the behaviors of the device and the audio headset, note these
requirements:</p>
<ul>
<li>only apply when no other audio accessories (e.g. Bluetooth) are
available</li>
<li>cover the default behavior for devices and do not apply to applications
that use audio routing APIs to select which audio peripheral to use</li>
</ul>
<h2 id=media>Media</h2>
<p>If a user connects a headset to the device while playing media, the audio
output (sound) should be heard only via the headset.</p>
<p>For example, while playing media with the <a
href="https://github.com/googlesamples/android-UniversalMusicPlayer">open
source</a> <a
href="https://android-developers.blogspot.com/2015/03/a-new-reference-app-for-multi-device.html">Universal
Music Player</a>, pressing the play/pause button should pause playback.
Pressing the same button when media is paused should resume playback.</p>
<p>If the headset has volume control buttons: </p>
<ul>
<li> Pressing the volume-up button should increase the volume incrementally each
time the button is pressed until maximum volume is reached. If the volume-up
button is pressed and held, the volume should gradually increase to maximum
volume setting.
<li> Pressing the volume-down button should decrease the volume incrementally each
time the button is pressed until entirely muted. If the volume-down button is
pressed and held, the volume should gradually decrease to silent.
<li> Pressing the volume-up button when in a muted state should increase the volume
one notch at a time starting from silent.
</ul>
<p><strong>Recommended for Apps</strong>: On disconnecting the headset, sound output should stop and playback should
pause. On reconnecting, playback should not start again unless the user presses
the play button. Upon pressing play, sound output should again be limited to
the headset.</p>
<h3 id=one_button>One button</h3>
<img src="images/media_one.png" alt="Button functions for one-button headsets handling a media stream.">
</span>
<p class="img-caption"><strong>Figure 1.</strong> Button functions for one-button headsets handling a media stream.</p>
<h3 id=two_buttons>Two buttons</h3>
<img src="images/media_two.png" alt="Button functions for two-button headsets handling a media stream.">
<p class="img-caption"><strong>Figure 2.</strong> Button functions for two-button headsets handling a media stream.</p>
<h3 id=three_buttons>Three buttons</h3>
<img src="images/media_three.png" alt="Button functions for three-button headsets handling a media stream.">
<p class="img-caption"><strong>Figure 3.</strong> Button functions for three-button headsets handling a media stream.</p>
<h3 id=four_buttons>Four buttons</h3>
<img src="images/media_four.png" alt="Button functions for four-button headsets handling a media stream.">
<p class="img-caption"><strong>Figure 4.</strong> Button functions for four-button headsets handling a media stream.</p>
<h2 id=telephony>Telephony</h2>
<p>If a user connects a headset to the device while a call is in progress, the
conversation should continue on the headset. The call should not get
disconnected, and the microphone should not be muted. If present, volume
buttons should behave identically to media playback.</p>
<p class="note"><strong>Note</strong>: The actions to mute and hang up a phone
call may differ across Android devices. This documents the most common behavior;
but for some devices, a short press on the headset mutes the call, and a long
press hangs up.</p>
<h3 id=one_button>One button</h3>
<img src="images/telephony_one.png" alt="Button functions for one-button headsets handling a phone call.">
<p class="img-caption"><strong>Figure 5.</strong> Button functions for one-button headsets handling a phone call. </p>
<h3 id=two_buttons>Two buttons</h3>
<img src="images/telephony_two.png" alt="Button functions for two-button headsets handling a phone call.">
<p class="img-caption"><strong>Figure 6.</strong> Button functions for two-button headsets handling a phone call. </p>
<h3 id=three_buttons>Three buttons</h3>
<img src="images/telephony_three.png" alt="Button functions for three-button headsets handling a phone call.">
<p class="img-caption"><strong>Figure 7.</strong> Button functions for three-button headsets handling a phone call. </p>
<h3 id=four_buttons>Four buttons</h3>
<img src="images/telephony_four.png" alt="Button functions for four-button headsets handling a phone call.">
<p class="img-caption"><strong>Figure 8.</strong> Button functions for four-button headsets handling a phone call. </p>
<h2 id=voice_command>Voice commands</h2>
<p>The voice command button is a new inline control standard for consistently
and conveniently accessing a voice command feature from any approved wearable
audio device. By pressing the button defined here, users will hear the two-tone
signature <a href="http://en.wikipedia.org/wiki/Earcon">earcon</a> indicating
that the device is listening and ready to receive the query.</p>
<p>Whether embedded into a multi-function button or highlighted as a single
button, it should always be quickly accessible, ergonomically correct, and
placed intuitively as described in the following section.</p>
<h2 id=buttons_and_function_mapping>Buttons and function mapping recommendations</h2>
<p>The following diagrams depict the acceptable configuration of the Android voice
command button.</p>
<h3 id=options>Options</h3>
<img src="images/button_configuration.png" alt="Button configuration options.">
<p class="img-caption"><strong>Figure 9.</strong> Button configuration options. </p>
<p>Buttons should always be front facing and spaced out so they can be easily
located by touch only.</p>
<h3 id=spacing>Spacing</h3>
<p>Buttons must be more than 5 mm and must have at least 5 mm distance between
buttons. For four-button headsets, there must be at least 9 mm of space between
button D and the cluster of other buttons. </p>
<img src="images/button_spacing.png" alt="Button spacing requirements">
<p class="img-caption"><strong>Figure 10.</strong> Button spacing requirements.</p>
<h3 id=icon>Icon</h3>
<p>In the following diagram, A is unlabeled or labeled with a dot. B is labeled
with a + or an arrow pointing up. C is labeled with a - or an arrow pointing
down. D is labeled with the selected button icon.</p>
<img src="images/button_icons.png" alt="Button icon requirements">
<p class="img-caption"><strong>Figure 11.</strong> Button icon requirements. </p>
<h3 id=sizing>Sizing</h3>
<p>The following diagram shows the ratio of button icon to the space around it.</p>
<img src="images/icon_sizing.png" alt="Voice search button icon sizing requirements">
<p class="img-caption"><strong>Figure 12.</strong> Voice search button icon sizing requirements. </p>
<h3 id=microphone_port>Microphone port</h3>
<p>The microphone should never be obstructed when operating the buttons. Place the
port away from finger interface area.</p>
<img src="images/microphone.png" alt="Microphone placement">
<p class="img-caption"><strong>Figure 13.</strong> Microphone placement. </p>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View file

@ -0,0 +1,45 @@
<html devsite>
<head>
<title>Android Audio Headset</title>
<meta name="project_path" value="/_project.yaml" />
<meta name="book_path" value="/_book.yaml" />
</head>
<body>
<!--
Copyright 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>This section describes the development and testing of the Android headset
accessory interface. This documentation presents the interface guidelines for the
Android headset inline remote.</p>
<p>Accessory manufacturers should follow the guidelines in the
<a href="plug-headset-spec.html">3.5 mm headset specification</a> or
<a href="usb-headset-spec.html">USB headset specification</a>.
Device manufacturers should follow the guidelines in the
<a href="jack-headset-spec.html">3.5 mm headset jack specification</a> or
<a href="/devices/audio/usb.html">USB digital audio page</a>.</p>
<p>The goal is to maintain certain standards for consistency and design while
allowing for freedom in design expression. If you choose to implement a
dedicated Android headset accessory, please follow these guidelines to ensure
your headset is compatible with devices following the recommendations in the <a
href="/compatibility/android-cdd.pdf">Android Compatibility Definition
Document (CDD)</a>.</p>
</body>
</html>

View file

@ -0,0 +1,249 @@
<html devsite>
<head>
<title>3.5 mm Headset Jack: Device Specification</title>
<meta name="project_path" value="/_project.yaml" />
<meta name="book_path" value="/_book.yaml" />
</head>
<body>
<!--
Copyright 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>To achieve compatibility with the <a href="plug-headset-spec.html">3.5 mm plug
headset specification</a>, devices that include a 4 conductor 3.5 mm audio jack
must meet the following specifications. For Android compatibility requirements,
refer to the <em>Analog audio ports</em> section of the <a
href="/compatibility/android-cdd.html#7_8_audio">Android CDD</a>.</p>
<h2 id="headset_jack_functions">Functions</h2>
<table>
<tr>
<th>Function</th>
<th>Device Support</th>
</tr>
<tr>
<td>Stereo Audio Out</td>
<td>Required</td>
</tr>
<tr>
<td>Audio in (Mic)</td>
<td>Required</td>
</tr>
<tr>
<td>Ground</td>
<td>Required</td>
</tr>
</table>
<h2 id="software_mapping">Software mapping</h2>
<table>
<tr>
<th style="width:33%">Function</th>
<th style="width:33%">Device Support</th>
<th style="width:33%">Description</th>
</tr>
<tr>
<td>Function A control event</td>
<td>Required</td>
<td>Input event: <code>KEY_MEDIA</code>
<p>Android key: <code>KEYCODE_HEADSETHOOK<code></p></td>
</tr>
<tr>
<td>Function D control event</td>
<td>Required</td>
<td>Input event: <code>KEY_VOICECOMMAND</code>
<p>Android key: <code>KEYCODE_VOICE_ASSIST</code></p></td>
</tr>
<tr>
<td>Function B control event</td>
<td>Required</td>
<td>Input event: <code>KEY_VOLUMEUP</code>
<p>Android key: <code>VOLUME_UP</code></p></td>
</tr>
<tr>
<td>Function C control event</td>
<td>Required</td>
<td>Input event: <code>KEY_VOLUMEDOWN</code>
<p>Android key: <code>VOLUME_DOWN</code></p></td>
</tr>
<tr>
<td>Headset insertion detection</td>
<td>Required</td>
<td>Input event: <code>SW_JACK_PHYSICAL_INSERT 7</code></td>
</tr>
<tr>
<td rowspan="2">Headset type detection</td>
<td>Mic</td>
<td>Input event: <code>SW_MICROPHONE_INSERT 4</code></td>
</tr>
<tr>
<td>No Mic</td>
<td>Input event: <code>SW_HEADPHONE_INSERT 2</code></td>
</tr>
<tr>
<td rowspan="2">Headset speaker impedance</td>
<td>Required Headphone (low)</td>
<td>Failure mode is to indicate headphones so limitation would be on</td>
</tr>
<tr>
<td>Required Line In (high)</td>
<td>Input event: <code>SW_LINEOUT_INSERT 6</code></td>
</tr>
</table>
<h2 id="mechanical11">Mechanical</h2>
<table>
<tr>
<th style="width:33%">Function</th>
<th style="width:33%">Device Support</th>
<th style="width:33%">Description</th>
</tr>
<tr>
<td>4 conductor 3.5 mm jack</td>
<td>Required</td>
<td></td>
</tr>
<tr>
<td>CTIA pinout order (LRGM)</td>
<td>Required</td>
<td>3 Pin & Mono Plug Compatible</td>
</tr>
<tr>
<td>OMTP pinout order (LRMG)</td>
<td>Optional but strongly recommended</td>
<td></td>
</tr>
<tr>
<td>Headset detect sequence</td>
<td>Required</td>
<td>Plug insert notification must be triggered only after all contacts on
plug are touching their relevant segments (this prevents unreliable headset
detection due to slow insertion.</td>
</tr>
</table>
<h2 id="electrical12">Electrical</h2>
<h3 id="general">General</h3>
<table>
<tr>
<th style="width:33%">Function</th>
<th style="width:33%">Device Support</th>
<th style="width:33%">Notes</th>
</tr>
<tr>
<td>Maximum output voltage drive</td>
<td>150mV</td>
<td>&gt;= 150mV on 32 ohm
<p>Test conditions: EN50332-2</p></td>
</tr>
<tr>
<td>Mic bias resistance</td>
<td>Required</td>
<td>Flexible on detection method used and microphone bias resistor
selection. Require that all button resistance value ranges specified below
be detected and related to their respective function</td>
</tr>
<tr>
<td>Mic bias voltage</td>
<td>1.8V - 2.9V</td>
<td>To guarantee compatibility to common microphone capsules.</td>
</tr>
</table>
<h3 id="function_impedance_and_threshold_detection">Function impedance and
threshold detection</h3>
<p>Devices must detect the following resistor ladder on the accessories. The
accessories will be tested to the standardized circuit diagram in the diagram
illustrated earlier (Reference Headset Test Circuit) where the total impedance
is measured from MIC terminal to GND when a button is pressed with 2.2V mic
bias applied through 2.2 kOhm resistor. This is the same effective resistance
as the button detection circuit with the microphone in parallel with the button
resistor.</p>
<table>
<tr>
<th style="width:40%">Button Impedance Level</th>
<th style="width:20%">Device Support</th>
<th style="width:40%">Notes</th>
</tr>
<tr>
<td>70 ohm or less</td>
<td>Required</td>
<td>[Function A]</td>
</tr>
<tr>
<td>110 - 180 ohm</td>
<td>Required</td>
<td>[Function D]</td>
</tr>
<tr>
<td>210 - 290 ohm</td>
<td>Required</td>
<td>[Function B]</td>
</tr>
<tr>
<td>360 - 680 ohm</td>
<td>Required</td>
<td>[Function C]</td>
</tr>
</table>
<table>
<tr>
<th style="width:40%">Headset Speaker Impedance Level</th>
<th style="width:20%">Device Support</th>
<th style="width:40%">Notes</th>
</tr>
<tr>
<td>Low Threshold Detection</td>
<td>Required</td>
<td>Headphone (low) &lt; 1 Kohm</td>
</tr>
<tr>
<td>High Threshold Detection</td>
<td>Required</td>
<td>Line In (high) &gt; 5 Kohm</td>
</tr>
</table>
<table>
<tr>
<th style="width:40%">4-Segment Plug Detection Resistance (between 3rd and 4th segment)</th>
<th style="width:20%">Device Support</th>
<th style="width:40%">Notes</th>
</tr>
<tr>
<td>4-Segment Plug Threshold</td>
<td>Required</td>
<td>Resistance &gt;= 100 ohms</td>
</tr>
<tr>
<td>3-Segment Plug Threshold</td>
<td>Required</td>
<td>Resistance &lt; 100 ohms</td>
</tr>
</table>
</body>
</html>

View file

@ -0,0 +1,207 @@
<html devsite>
<head>
<title>3.5 mm Headset: Accessory Specification</title>
<meta name="project_path" value="/_project.yaml" />
<meta name="book_path" value="/_book.yaml" />
</head>
<body>
<!--
Copyright 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>This article specifies requirements for 3.5 mm plug headsets to
function uniformly across the Android ecosystem.</p>
<p>Device manufacturers should consult the <a href="jack-headset-spec.html">3.5 mm
jack specification</a> and the
<a href="/compatibility/android-cdd.html">Android Compatibility Definition Document</a>
(CDD) for additional requirements.</p>
<h2 id="functions">Functions</h2>
<table style="width:50%">
<tr>
<th>Function</th>
<th>Accessory Support</th>
</tr>
<tr>
<td>Stereo Audio Out</td>
<td>Required</td>
</tr>
<tr>
<td>Audio in (Mic)</td>
<td>Required</td>
</tr>
<tr>
<td>Ground</td>
<td>Required</td>
</tr>
</table>
<h2 id="control-function_mapping">Control-function mapping</h2>
<table>
<tr>
<th style="width:33%">Control Function</th>
<th style="width:33%">Accessory Support</th>
<th style="width:33%">Description</th>
</tr>
<tr>
<td>Function A</td>
<td>Required</td>
<td>Play/pause/hook (Short Press), Trigger Assist (Long Press), Next
(Double Press)</td>
</tr>
<tr>
<td>Function B</td>
<td>Optional</td>
<td>Vol+</td>
</tr>
<tr>
<td>Function C</td>
<td>Optional</td>
<td>Vol-</td>
</tr>
<tr>
<td>Function D</td>
<td>Optional</td>
<td>Reserved (Nexus devices use this to launch voice commands)
</td>
</tr>
</table>
<p>Assign functions to buttons as follows:</p>
<ul>
<li> All one-button headsets must implement Function A.
<li> Headsets with multiple buttons must implement functions according to the
following pattern:
<ul>
<li> 2 functions: A and D
<li> 3 functions: A, B, C
<li> 4 functions: A, B, C, D
</ul>
</ul>
<h2 id="mechanical">Mechanical</h2>
<table>
<tr>
<th style="width:33%">Function</th>
<th style="width:33%">Accessory Support</th>
<th style="width:33%">Notes</th>
</tr>
<tr>
<td>4 conductor 3.5 mm plug</td>
<td>Required</td>
<td>Ref: EIAJ-RC5325A standard</td>
</tr>
<tr>
<td>CTIA pinout order (LRGM)</td>
<td>Required</td>
<td>Except in regions with legal requirements for OMTP pinout</td>
</tr>
<tr>
<td>OMTP pinout order (LRMG)</td>
<td>Optional</td>
<td></td>
</tr>
<tr>
<td>Microphone</td>
<td>Required</td>
<td>Must not be obstructed when operating headset controls</td>
</tr>
</table>
<h2 id="electrical">Electrical</h2>
<table>
<tr>
<th style="width:33%">Function</th>
<th style="width:33%">Accessory Support</th>
<th style="width:33%">Description</th>
</tr>
<tr>
<td>Ear speaker impedance</td>
<td>16 ohms or higher</td>
<td>Recommend 32 - 300 ohms</td>
</tr>
<tr>
<td>Mic DC resistance</td>
<td>1000 ohms or higher
</td>
<td>Mic characteristics must be compliant with section 5.4
<em>Audio Recording</em> of the current
<a href="/compatibility/android-cdd.html#5_4_audio_recording">Android CDD</a></td>
</tr>
<tr>
<td rowspan="4">Control Function Equivalent impedance*</td>
<td>0 ohm</td>
<td>[Function A] Play/Pause/Hook</td>
</tr>
<tr>
<td>240 ohm +/- 1% resistance</td>
<td>[Function B]</td>
</tr>
<tr>
<td>470 ohm +/- 1% resistance</td>
<td>[Function C]</td>
</tr>
<tr>
<td>135 ohm +/- 1% resistance</td>
<td>[Function D]</td>
</tr>
</table>
<p><em>*Total impedance from positive mic terminal to GND when button is
pressed with 2.2 V mic bias applied through 2.2 kOhm resistor</em></p>
<p>In the following diagrams, Button A maps to Function A, Button B to
Function B, and so on.</p>
<h2 id="reference_headsets">Reference headset test circuits</h2>
<p>The following diagram for Reference Headset Test Circuit 1 shows the CTIA
pinout for a 4-segment plug. For the OMTP pinout, switch the positions of the
MIC and GND segments.</p>
<img src="images/headset-circuit1.png" alt="Reference Headset Test Circuit 1" />
<p class="img-caption"><strong>Figure 1.</strong> Reference headset test circuit 1</p>
<p>The following diagram for Reference Headset Test Circuit 2 shows how the
actual resistor values (R1 - R4) are altered to meet this specification.</p>
<img src="images/headset-circuit2.png" alt="Reference Headset Test Circuit 2" />
<p class="img-caption"><strong>Figure 2.</strong> Reference headset test circuit 2</p>
<p>The actual resistance of the buttons parallel with the microphone (R1-R4) is
based on the microphone capsule resistance (Rmic) and the equivalent impedance
values (ReqA-ReqD). Use the following formula:</p>
<p><em>Req<sub>N</sub>=(R<sub>mic</sub>*R<sub>n</sub>)/(R<sub>mic</sub>+R<sub>n</sub>)</em></p>
<p>Where R<em>n</em> is the actual resistance of a button, Req<em>N</em> is the
equivalent impedance value of that button (provided), and Rmic is the
microphone impedance value.</p>
<p>The example above assumes a 5 kohm microphone impedance (Rmic); to achieve
an equivalent R4 impedance of 135 ohm (ReqD), the actual resistor value (R4)
must be 139 ohms.</p>
</body>
</html>

View file

@ -0,0 +1,119 @@
<html devsite>
<head>
<title>Testing</title>
<meta name="project_path" value="/_project.yaml" />
<meta name="book_path" value="/_book.yaml" />
</head>
<body>
<!--
Copyright 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>To ensure your headset is compatible with the minimally required
functionality, conduct these tests.</p>
<h2 id=headset_insertion>Headset insertion</h2>
<ol>
<li> Start with the Android device turned off.
<li> Plug in the headset.
<li> Turn the device on.
<li> Unlock.
<li> Open the <a
href="https://github.com/googlesamples/android-UniversalMusicPlayer">open
source</a> <a
href="https://android-developers.blogspot.com/2015/03/a-new-reference-app-for-multi-device.html">Universal
Music Player</a>.
<li> Press the device volume buttons to maximize media volume.
<li> Start playing music and verify audio comes out of the headset.
<li> While music is playing, disconnect the headset and verify music stops.
<li> Reconnect the headset, start playing music again, and verify audio comes out of
the headset.
</ol>
<h2 id=volume_buttons>Volume buttons</h2>
<ol>
<li> Play music and ensure it is coming out of the headset.
<li> Press the volume-down button. Verify the volume panel
displays the media volume decrease by one notch and the volume output is
reduced as expected.
<li> Long press the volume-down button. Verify the volume panel shows media
volume going all the way down and volume output is reduced gradually to muted.
<li> Press the volume-up button. Verify the volume panel displays the media
volume go up one notch and the volume output is increased as expected.
<li> Long press the volume-up button. Verify the volume panel shows the
media volume go all the way up to maximum and the volume output is increased as
expected.
</ol>
<h2 id=play_pause_for_music>Play/pause for music</h2>
<p>Press quickly on the play/pause button and verify music stops playing out of
the headset. If music was not already playing, then it should start playing out
of the headset.</p>
<h2 id=play_pause_for_telephony>Play/pause for telephony</h2>
<p>The actions to mute and hang up a phone call may differ across Android
devices. This test documents the most common behavior.</p>
<ol>
<li> Make a phone call.
<li> Long press the play/pause button while in the call.
<li> Verify the microphone mutes. And if you long press again, the microphone
should un-mute.
<li> While still in the call, short press the play/pause button.
<li> Verify the short press ends the telephone call.
<li> Receive a phone call on the Android device.
<li> Short press the play/pause button while the phone is ringing and verify
the call is accepted.
<li> Receive another phone call on the Android device.
<li> Long press the play/pause button while the phone is ringing and verify the
call is rejected.
</ol>
<h2 id=play_pause_for_voice_commands_microphone>Play/pause for voice commands and microphone</h2>
<ol>
<li> Unlock the Android device and go to the home screen.
<li> Long press the play/pause button.
<li> Verify:
<ol>
<li> you hear a beep after which you should be able to make a voice search query,
such as “What time is it?”
<li> you hear a response, such as “The time is ...”
</ol>
</ol>
<h2 id=voice_button_for_voice_commands_microphone>Voice command button for voice commands and microphone</h2>
<ol>
<li> Unlock the Android device and go to the home screen.
<li> Short press the voice command button.
<li> Verify:
<ol>
<li> you hear a beep after which you should be able to make a search query, such as
“What time is it?”
<li> you hear a response, such as “The time is ...”
</ol>
</ol>
<p class="note"><strong>Important</strong>: A press on the voice command button can launch any search app, for example
Google search.</p>
</body>
</html>

View file

@ -0,0 +1,190 @@
<html devsite>
<head>
<title>USB Headset: Accessory Specification</title>
<meta name="project_path" value="/_project.yaml" />
<meta name="book_path" value="/_book.yaml" />
</head>
<body>
<!--
Copyright 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>
This documentation specifies USB headset buttons behavior to function uniformly
across the Android ecosystem. Device manufacturers should also consult the
<a href="/devices/audio/usb.html">USB
Digital Audio</a> page for more information about USB implementation on Android
and the <a href="http://source.android.com/compatibility/android-cdd.html">Android
Compatibility Definition Document (CDD)</a> for requirements related to Android
devices.
</p>
<p>There are also specifications for
<a href="plug-headset-spec.html">3.5 mm headsets</a> for accessory manufacturers and
<a href="jack-headset-spec.html">3.5 mm jacks</a> for device manufacturers.
</p>
<p>
This documentation specifies the minimum requirements: accessory manufacturers
are encouraged to add features while keeping these requirements in mind.
</p>
<h2 id="control-function-mapping">Control-function mapping</h2>
<table>
<tr>
<th>Control Function</th>
<th>Accessory Support</th>
<th>Description</th>
</tr>
<tr>
<td>A</td>
<td>Required</td>
<td>Play/pause (short press), launch voice command (long press), next (double
press)</td>
</tr>
<tr>
<td>B</td>
<td>Optional</td>
<td>Vol+</td>
</tr>
<tr>
<td>C</td>
<td>Optional</td>
<td>Vol-</td>
</tr>
<tr>
<td>D</td>
<td>Optional</td>
<td>Launch voice command</td>
</tr>
</table>
<p>
<strong>Assign functions to buttons as follows:</strong>
</p>
<ul>
<li>All one-button headsets must implement Function A.</li>
<li>Headsets with multiple buttons must implement functions according to the
following pattern:
<ul>
<li>2 functions: A and D</li>
<li>3 functions: A, B, C</li>
<li>4 functions: A, B, C, D</li>
</ul>
</li>
</ul>
<p class="note">
<strong>Note</strong>: No key latching allowed. Each key press by the end user
must generate the corresponding "down" and "up" key event, matching the end user
action. In other words, the keys for functions A through D are never "latched"
or implemented to be used as a toggle (where the "up" event only follows "down"
on a second key press).
</p>
<h2 id="software-mapping">Software mapping</h2>
<p>
Compatible USB headsets are required to support the following software mappings
for the headset buttons. Device support is required for the following software
mappings.
</p>
<table>
<tr>
<th>Function</th>
<th>Mappings</th>
<th>Context</th>
<th>Behavior</th>
</tr>
<tr>
<td rowspan="6">A</td>
<td rowspan="6"><strong>HID usage page</strong>: 0x0C<br>
<strong>HID usage</strong>: 0x0CD<br>
<strong>Kernel key</strong>: <code>KEY_PLAYPAUSE</code><br>
<strong>Android key</strong>: <code>KEYCODE_MEDIA_PLAY_PAUSE</code></td>
<td rowspan="2">Media playback</td>
<td><strong>Input</strong>: Short press<br>
<strong>Output</strong>: Play or pause</td>
</tr>
<tr>
<td><strong>Input</strong>: Long press<br>
<strong>Output</strong>: Launch voice command<br>
<strong>Sends</strong>:
<code>android.intent.action.VOICE_SEARCH_HANDS_FREE</code></td>
</tr>
<tr>
<td rowspan="2">Incoming call</td>
<td><strong>Input</strong>: Short press<br>
<strong>Output</strong>: Accept call</td>
</tr>
<tr>
<td><strong>Input</strong>: Long press<br>
<strong>Output</strong>: Reject call</td>
</tr>
<tr>
<td rowspan="2">Ongoing call</td>
<td><strong>Input</strong>: Short press<br>
<strong>Output</strong>: End call</td>
</tr>
<tr>
<td><strong>Input</strong>: Long press<br>
<strong>Output</strong>: Mute or unmute microphone</td>
</tr>
<tr>
<td>B</td>
<td><strong>HID usage page</strong>: 0x0C<br>
<strong>HID usage</strong>: 0x0E9<br>
<strong>Kernel key</strong>: <code>KEY_VOLUMEUP</code><br>
<strong>Android key</strong>: <code>VOLUME_UP</code></td>
<td>Media playback, Ongoing call</td>
<td><strong>Input</strong>: Short or long press<br>
<strong>Output</strong>: Increases the system or headset volume</td>
</tr>
<tr>
<td>C</td>
<td><strong>HID usage page</strong>: 0x0C<br>
<strong>HID usage</strong>: 0x0EA<br>
<strong>Kernel key</strong>: <code>KEY_VOLUMEDOWN</code><br>
<strong>Android key</strong>: <code>VOLUME_DOWN</code></td>
<td>Media playback, Ongoing call</td>
<td><strong>Input</strong>: Short or long press<br>
<strong>Output</strong>: Decreases the system or headset volume</td>
</tr>
<tr>
<td>D</td>
<td><strong>HID usage page</strong>: 0x0C<br>
<strong>HID usage</strong>: 0x0CF<br>
<strong>Kernel key</strong>: <code>KEY_VOICECOMMAND</code><br>
<strong>Android key</strong>: <code>KEYCODE_VOICE_ASSIST</code></td>
<td>All. Can be triggered in any instance.</td>
<td><strong>Input</strong>: Short or long press<br>
<strong>Output</strong>: Launch voice command</td>
</tr>
</table>
<p class="note">Key mappings should be declared within a HID application
collection. For accessories without a microphone, use Headphone (Usage
Page: Consumer (0x0C), Usage: Headphone (0x05)). For accesories with a
microphone, use Headset (Usage Page: Telephony (0x0B), Usage: Headset (0x05)).</p>
<h2 id="mechanical">Mechanical</h2>
<p>
Accessory manufacturers must follow the requirements for USB connectors
as specified by <a href="http://www.usb.org/">USB.org</a>.
</p>
<p>
Device manufacturers must follow the requirements in the
<a href="/compatibility/android-cdd.html#7_7_usb">USB section</a> of
the Android CDD.
</p>
</body>
</html>

View file

@ -0,0 +1,55 @@
<html devsite>
<head>
<title>Accessories for Android</title>
<meta name="project_path" value="/_project.yaml" />
<meta name="book_path" value="/_book.yaml" />
</head>
<body>
<!--
Copyright 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>Using a suite of standard protocols, you can implement compelling accessories
that extend Android capabilities in a wide range of Android-powered devices.
</p>
<div class="layout-content-row">
<div class="layout-content-col span-6">
<h4 id="audio-accessories">Audio Accessories</h4>
<p>Android supports local on-device audio and remote off-device audio
over a wired 3.5 mm headset jack, USB connection, or Bluetooth.
Manufacturers should see the <a
href="headset/index.html">headset
specifications</a>, while users can learn how to <a
href="https://support.google.com/nexus/answer/6127700">record and play
back audio using USB host mode</a>.</p>
<p><a href="audio.html">&raquo; Audio Accessories</a></p>
</div>
<div class="layout-content-col span-6">
<h4 id="custom-accessories">Custom Accessories</h4>
<p>What do you want to connect to your Android device? Alarm clock?
Keyboard? Thermostat? Robot? Learn how to connect existing equipment or
your own unique hardware to Android using the Android Open Accessory
(AOA) protocol.</p>
<p><a href="custom.html">&raquo; Custom Accessories</a></p>
</div>
</div>
</body>
</html>

View file

@ -0,0 +1,60 @@
<html devsite>
<head>
<title>Android Open Accessory (AOA)</title>
<meta name="project_path" value="/_project.yaml" />
<meta name="book_path" value="/_book.yaml" />
</head>
<body>
<!--
Copyright 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>Android Open Accessory (AOA) support allows external USB hardware
(Android USB accessories) to interact with Android-powered devices in
<em>accessory mode</em>. When an Android-powered powered device is in
accessory mode, the connected accessory acts as the USB host (powers the bus and
enumerates devices) and the Android-powered device acts as the USB accessory.
</p>
<p>Android USB accessories are designed to attach to Android-powered devices.
Such accessories adhere to AOA, enabling them to detect Android-powered devices
that support accessory mode, and must provide 500mA at 5V for charging power.
Some previously-released Android-powered devices are capable of acting only
as a USB device and cannot initiate connections with external USB devices. AOA
support overcomes this limitation, enabling you to build accessories that can
initiate connections and interact with an assortment of Android-powered devices.
</p>
<p class="note"><strong>Note:</strong> Accessory mode is dependent on device
hardware; not all devices support accessory mode. Devices that support accessory
mode can be filtered using a <code>&lt;uses-feature&gt;</code> element in the
corresponding application's Android manifest. For details, see the
<a href="http://developer.android.com/guide/topics/connectivity/usb/accessory.html#manifest">USB
Accessory</a> developer guide.</p>
<p>AOA has two versions that support different types of communication:</p>
<ul>
<li><strong>AOAv1</strong>. Supports generic accessory communication and adb
debugging. Available in Android 3.1 (API Level 12) and higher and supported
through an
<a href="https://developers.google.com/android/add-ons/google-apis/">Add-On
Library</a> in Android 2.3.4 (API Level 10) and higher.</li>
<li><strong>AOAv2</strong>. Supports audio streaming and human interface
device (HID) capabilities. Available in Android 4.1 (API Level 16).</li>
</ul>
</body>
</html>

View file

@ -0,0 +1,122 @@
<html devsite>
<head>
<title>Stylus</title>
<meta name="project_path" value="/_project.yaml" />
<meta name="book_path" value="/_book.yaml" />
</head>
<body>
<!--
Copyright 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>Android 6.0 and higher supports a standard data format for Bluetooth stylus
connections over Bluetooth (BT), Bluetooth Low Energy (BTLE), or USB. The
platform correlates timing between touch input and stylus data then provides
stylus data to render MotionEvents to the active application. The following
sections provide guidelines for OEM device implementers, stylus accessory creators, and
stylus application developers.</p>
<h2 id="guide-partners">Guidelines for OEM device implementers</h2>
<p>To enable Bluetooth stylus support, OEM device implementers must support Bluetooth
(and should support BTLE for wider compatibility). The platform handles data
collection, timing correlation, and rendering to the application for supported
stylus events.</p>
<p>At this time, the Android CTS <strong>does not</strong> include tests to
ensure existing APIs for touch events support default behavior. As a
workaround, we recommend creating a stylus accessory or emulator that can
simulate stylus events.</p>
<h2 id="guide-creators">Guidelines for stylus accessory creators</h2>
<p>To implement support on a stylus device, device implementers must use the Stylus
Human Interface Device (HID) Descriptor shown below to describe how stylus data
(pressure sensitivity, eraser, side buttons, device ID, etc.) is represented.
The stylus device sends the HID information to the Android mobile device,
enabling the platform to correlate HID data with touch data from the touchscreen
to produce stylus events via MotionEvent. Data can be sent over Bluetooth (BT),
Bluetooth Low Energy (BTLE), or USB.</p>
<h3 id="hid-descriptor">HID descriptor</h3>
<pre class="devsite-click-to-copy">
UsagePage(Digitizer)
Usage(Pen)
Collection(Application)
Usage(Stylus)
Collection(Logical)
Usage(Tip Pressure)
Logical Minimum(0)
Logical Maximum(1023)
Report Count(1)
Report Size(10)
Input(Data, Variable, Absolute, No Null)
Usage(Barrel Switch)
Usage(Secondary Barrel Switch)
Usage(Tip Switch)
Usage(Invert)
Logical Maximum(1)
Report Count(4)
Report Size(1)
Input(Data, Variable, Absolute, No Null)
Usage(Transducer Serial Number)
Report Count(1)
Report Size(128)
Feature(Constant, Variable)
EndCollection
EndCollection
unsigned char HID_DESC[] = {
0x05, 0x0D, // UsagePage(Digitizer)
0x09, 0x02, // Usage(Pen)
0xA1, 0x01, // Collection(Application)
0x09, 0x20, // Usage(Stylus)
0xA1, 0x02, // Collection(Logical)
0x09, 0x30, // Usage(Tip Pressure)
0x15, 0x00, // Logical Minimum(0)
0x26, 0xFF, 0x03, // Logical Maximum(1023)
0x95, 0x01, // Report Count(1)
0x75, 0x0A, // Report Size(10)
0x81, 0x02, // Input(Data, Variable, Absolute, No Null)
0x09, 0x44, // Usage(Barrel Switch)
0x09, 0x5A, // Usage(Secondary Barrel Switch)
0x09, 0x42, // Usage(Tip Switch)
0x09, 0x3C, // Usage(Invert)
0x25, 0x01, // Logical Maximum(1)
0x95, 0x04, // Report Count(4)
0x75, 0x01, // Report Size(1)
0x81, 0x02, // Input(Data, Variable, Absolute, No Null)
0x09, 0x5B, // Usage(Transducer Serial Number)
0x95, 0x01, // Report Count(1)
0x75, 0x80, // Report Size(128)
0xB1, 0x03, // Feature(Constant, Variable)
0xC0, // End Collection
0xC0, // End Collection
}
</pre>
<h2 id="guidelines-devs">Guidelines for stylus application developers</h2>
<p>The Android 6.0 platform automatically handles pairing and event correlation,
so both existing and new applications running on Android 6.0 support Bluetooth
stylus by default. For details on Bluetooth stylus APIs, refer to
<a href="http://developer.android.com/about/versions/marshmallow/android-6.0.html#bluetooth-stylus">developer.android.com</a>.
</body>
</html>