SlideShare a Scribd company logo
Android Open Accessory
USB device to accessory protocol
What is it?
● USB protocol that allows communication between Android devices and accessories in
accessory mode
● AOAv1 - supported since API 12, with lib since API 10, supports basic communication
● AOAv2 - supported since API 16, adds audio streaming and HID capabilities
● Device is USB host and accessory is USB client
How does it work? Android app
● App declares itself to handle an accessory or accessory family
● App handles specific intents
● UsbAccessory object is attached to that intent in a Bundle
● Once it is obtained, transfer of data between USB device and Android device is possible
How does it work? Accessory
● Accessory sends series of specific USB control commands:
○ Get AOA version - device returns integer, currently 0 for not supported, 1 or 2 if supported
○ Accessory identifies itself by sending its vendor, model, manufacturer URI and serial number, which
should match what Android application declared as supported devices
○ If Android device returns valid status on all of those, it sends “go to AOA mode” command
● Android device disconnects from USB and reconnects in AOA mode with static PID and VID
● At this stage, if everything went well, Android OS sends the intent to the application with
UsbAccessory object which is describing the accessory
Declaring support for AOA
res/accessory_filter.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-accessory manufacturer="Tikal" model="Shaul haGadol" version="1.0"/>
</resources>
Manifest
<activity android:name=".UsbTest" android:label="@string/app_name" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
<action
android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
android:resource="@xml/accessory_filter" />
</activity>
In Activity
if (getIntent().getAction().equals("android.hardware.usb.action.USB_ACCESSORY_ATTACHED")) {
UsbAccessory accessory = UsbManager.getAccessory(getIntent());
FileDescriptor fd = null;
try {
fd = UsbManager.getInstance(this).openAccessory(accessory).getFileDescriptor();
} catch (IllegalArgumentException e) {
finish();
} catch (NullPointerException e) {
finish();
}
mFout = new FileOutputStream(fd);
mFin = new FileInputStream(fd);
}
Accessory side, get AOA version
rc = libusb_control_transfer(handle, //handle
USB_CMD_BLOCK_READ, //bmRequestType
ACCESSORY_GET_PROTOCOL, //bRequest
0, //wValue
0, //wIndex
ioBuffer, //data
2, //wLength
0 //timeout
);
libusb_release_interface(handle, 0);
libusb_close(handle);
int aoaVersion = ioBuffer[1] << 8 | ioBuffer[0];
Accessory side, identify device
response = libusb_control_transfer(
device.handle,
USB_CMD_VENDOR_SPECIFIC,
ACCESSORY_SEND_STRING,
0,
ACCESSORY_STRING_MANUFACTURER,
(unsigned char*)manufacturer,
strlen(manufacturer),
0);
Accessory side, put in AOA mode
response = libusb_control_transfer(
device.handle,
USB_CMD_VENDOR_SPECIFIC,
ACCESSORY_START,
0,
0,
NULL,
0,
0);
Accessory side, open device
rc = libusb_get_device_descriptor(device, &desc);
if (rc < 0) {
continue;
}
if ((libusb_open(device, &handle)) < 0) {
fprintf(stdout, "Problem acquiring handlen");
return;
}
libusb_claim_interface(handle, 0);
Accessory side, transfer data
while (libusb_bulk_transfer(sourceHandle, IN, buffer, BUFFER_LEN, &transferred, 1000000 * 10) ==
0) {
rc1 = libusb_bulk_transfer(targetHandle, OUT, buffer, transferred, &transferred,
1000000 * 10);
if(rc1 == 0) {
buffCnt++;
if(buffCnt % 200 == 0) {
double mb = (buffCnt*BUFFER_LEN) / (1024 * 1024);
fprintf(stdout, "%lu s sent %.2f mbn", time(NULL) -
before, mb);
}
} else {
fprintf(stdout, "error sending buffer rc=%dn", rc1);
return -1;
}
}
Accessory side, constants
#define USB_ACCESSORY_PRODUCT_ID 0x2D00
#define USB_ACCESSORY_ADB_PRODUCT_ID 0x2D01
#define ACCESSORY_STRING_MANUFACTURER 0
#define ACCESSORY_STRING_MODEL 1
#define ACCESSORY_STRING_DESCRIPTION 2
#define ACCESSORY_STRING_VERSION 3
#define ACCESSORY_STRING_URI 4
#define ACCESSORY_STRING_SERIAL 5
#define ACCESSORY_GET_PROTOCOL 51
#define ACCESSORY_SEND_STRING 52
#define ACCESSORY_START 53
#define USB_CMD_BLOCK_READ 0xc0
#define USB_CMD_VENDOR_SPECIFIC 0x40
Additional info
● https://source.android.com/devices/accessories/protocol
● https://www.youtube.com/watch?v=kReFemy4UmU
● https://opensourceforu.com/2014/11/the-android-open-accessory-protocol-
all-about/
● http://wiki.p2pfoundation.net/Android_Open_Accessory
● http://jjmilburn.github.io/2017/05/08/Android-AOA-Support/

More Related Content

What's hot

Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting Process
Nanik Tolaram
 
Android audio system(audioflinger)
Android audio system(audioflinger)Android audio system(audioflinger)
Android audio system(audioflinger)
fefe7270
 
Android Things : Building Embedded Devices
Android Things : Building Embedded DevicesAndroid Things : Building Embedded Devices
Android Things : Building Embedded Devices
Emertxe Information Technologies Pvt Ltd
 
iOS I phone operating system
iOS I phone operating system iOS I phone operating system
iOS I phone operating system
Hùssâîn Mîrzã
 
Android vs. IOS: Comparing features & functions
Android vs. IOS: Comparing features & functionsAndroid vs. IOS: Comparing features & functions
Android vs. IOS: Comparing features & functions
Dipesh Bhatiya
 
Android technology prepared by Hritika Raj (Shivalik college of engg.)
Android technology prepared by Hritika Raj (Shivalik college of engg.)Android technology prepared by Hritika Raj (Shivalik college of engg.)
Android technology prepared by Hritika Raj (Shivalik college of engg.)
Hritika Raj
 
android architecture
android architectureandroid architecture
android architecture
Aashita Gupta
 
A deep dive into Android OpenSource Project(AOSP)
A deep dive into Android OpenSource Project(AOSP)A deep dive into Android OpenSource Project(AOSP)
A deep dive into Android OpenSource Project(AOSP)
Siji Sunny
 
PPT on iOS
PPT on iOS PPT on iOS
PPT on iOS
Ravi Ranjan
 
Android ppt
Android pptAndroid ppt
Android ppt
Sunil Kumar
 
Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)
Emertxe Information Technologies Pvt Ltd
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Opersys inc.
 
Android Storage - Vold
Android Storage - VoldAndroid Storage - Vold
Android Storage - Vold
William Lee
 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Opersys inc.
 
Embedded Android : System Development - Part III (Audio / Video HAL)
Embedded Android : System Development - Part III (Audio / Video HAL)Embedded Android : System Development - Part III (Audio / Video HAL)
Embedded Android : System Development - Part III (Audio / Video HAL)
Emertxe Information Technologies Pvt Ltd
 
Android Operating System
Android Operating SystemAndroid Operating System
Android Operating System
Prathamesh Bhosale
 
Embedded Android : System Development - Part IV
Embedded Android : System Development - Part IVEmbedded Android : System Development - Part IV
Embedded Android : System Development - Part IV
Emertxe Information Technologies Pvt Ltd
 
Android operating System
Android operating SystemAndroid operating System
Android operating System
yash lakhmani
 
Android IPC Mechanism
Android IPC MechanismAndroid IPC Mechanism
Android IPC Mechanism
National Cheng Kung University
 
Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debugging
Utkarsh Mankad
 

What's hot (20)

Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting Process
 
Android audio system(audioflinger)
Android audio system(audioflinger)Android audio system(audioflinger)
Android audio system(audioflinger)
 
Android Things : Building Embedded Devices
Android Things : Building Embedded DevicesAndroid Things : Building Embedded Devices
Android Things : Building Embedded Devices
 
iOS I phone operating system
iOS I phone operating system iOS I phone operating system
iOS I phone operating system
 
Android vs. IOS: Comparing features & functions
Android vs. IOS: Comparing features & functionsAndroid vs. IOS: Comparing features & functions
Android vs. IOS: Comparing features & functions
 
Android technology prepared by Hritika Raj (Shivalik college of engg.)
Android technology prepared by Hritika Raj (Shivalik college of engg.)Android technology prepared by Hritika Raj (Shivalik college of engg.)
Android technology prepared by Hritika Raj (Shivalik college of engg.)
 
android architecture
android architectureandroid architecture
android architecture
 
A deep dive into Android OpenSource Project(AOSP)
A deep dive into Android OpenSource Project(AOSP)A deep dive into Android OpenSource Project(AOSP)
A deep dive into Android OpenSource Project(AOSP)
 
PPT on iOS
PPT on iOS PPT on iOS
PPT on iOS
 
Android ppt
Android pptAndroid ppt
Android ppt
 
Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
 
Android Storage - Vold
Android Storage - VoldAndroid Storage - Vold
Android Storage - Vold
 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
 
Embedded Android : System Development - Part III (Audio / Video HAL)
Embedded Android : System Development - Part III (Audio / Video HAL)Embedded Android : System Development - Part III (Audio / Video HAL)
Embedded Android : System Development - Part III (Audio / Video HAL)
 
Android Operating System
Android Operating SystemAndroid Operating System
Android Operating System
 
Embedded Android : System Development - Part IV
Embedded Android : System Development - Part IVEmbedded Android : System Development - Part IV
Embedded Android : System Development - Part IV
 
Android operating System
Android operating SystemAndroid operating System
Android operating System
 
Android IPC Mechanism
Android IPC MechanismAndroid IPC Mechanism
Android IPC Mechanism
 
Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debugging
 

Similar to Android Open Accessory

Hello android world
Hello android worldHello android world
Hello android world
eleksdev
 
FTF2014 - Android Accessory Protocol
FTF2014 - Android Accessory ProtocolFTF2014 - Android Accessory Protocol
FTF2014 - Android Accessory Protocol
Gary Bisson
 
Native Android Development Practices
Native Android Development PracticesNative Android Development Practices
Native Android Development Practices
Roy Clarkson
 
Android studio
Android studioAndroid studio
Android studio
Andri Yabu
 
Android Development Basics
Android Development BasicsAndroid Development Basics
Android Development Basics
Prajakta Dharmpurikar
 
Android session 2
Android session 2Android session 2
Android session 2
Ahesanali Suthar
 
Migrating JavaME Apps to Android
Migrating JavaME Apps to AndroidMigrating JavaME Apps to Android
Migrating JavaME Apps to Android
Motorola Mobility - MOTODEV
 
01 introduction to android
01 introduction to android01 introduction to android
01 introduction to android
Sokngim Sa
 
Getting started with android programming
Getting started with android programmingGetting started with android programming
Getting started with android programming
PERKYTORIALS
 
Life After Mobilegeddon: App Deep Linking Strategies - Pubcon October 2015
Life After Mobilegeddon: App Deep Linking Strategies - Pubcon October 2015Life After Mobilegeddon: App Deep Linking Strategies - Pubcon October 2015
Life After Mobilegeddon: App Deep Linking Strategies - Pubcon October 2015
MobileMoxie
 
Life After Mobilegeddon: App Deep Linking Strategies - Pubcon October 2015
Life After Mobilegeddon: App Deep Linking Strategies - Pubcon October 2015Life After Mobilegeddon: App Deep Linking Strategies - Pubcon October 2015
Life After Mobilegeddon: App Deep Linking Strategies - Pubcon October 2015
Suzzicks
 
Android のusb support
Android のusb supportAndroid のusb support
Android のusb support
magoroku Yamamoto
 
Android deep dive
Android deep diveAndroid deep dive
Android deep dive
AnuSahniNCI
 
Android broadcast receiver tutorial
Android broadcast receiver  tutorialAndroid broadcast receiver  tutorial
Android broadcast receiver tutorial
maamir farooq
 
Android broadcast receiver tutorial
Android broadcast receiver   tutorialAndroid broadcast receiver   tutorial
Android broadcast receiver tutorial
maamir farooq
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
Aly Abdelkareem
 
Android Application Development Using Java
Android Application Development Using JavaAndroid Application Development Using Java
Android Application Development Using Java
amaankhan
 
Android terminologies
Android terminologiesAndroid terminologies
Android terminologies
jerry vasoya
 
Beginning android
Beginning android Beginning android
Beginning android
Igor R
 
Industrial Training in Android Application
Industrial Training in Android ApplicationIndustrial Training in Android Application
Industrial Training in Android Application
Arcadian Learning
 

Similar to Android Open Accessory (20)

Hello android world
Hello android worldHello android world
Hello android world
 
FTF2014 - Android Accessory Protocol
FTF2014 - Android Accessory ProtocolFTF2014 - Android Accessory Protocol
FTF2014 - Android Accessory Protocol
 
Native Android Development Practices
Native Android Development PracticesNative Android Development Practices
Native Android Development Practices
 
Android studio
Android studioAndroid studio
Android studio
 
Android Development Basics
Android Development BasicsAndroid Development Basics
Android Development Basics
 
Android session 2
Android session 2Android session 2
Android session 2
 
Migrating JavaME Apps to Android
Migrating JavaME Apps to AndroidMigrating JavaME Apps to Android
Migrating JavaME Apps to Android
 
01 introduction to android
01 introduction to android01 introduction to android
01 introduction to android
 
Getting started with android programming
Getting started with android programmingGetting started with android programming
Getting started with android programming
 
Life After Mobilegeddon: App Deep Linking Strategies - Pubcon October 2015
Life After Mobilegeddon: App Deep Linking Strategies - Pubcon October 2015Life After Mobilegeddon: App Deep Linking Strategies - Pubcon October 2015
Life After Mobilegeddon: App Deep Linking Strategies - Pubcon October 2015
 
Life After Mobilegeddon: App Deep Linking Strategies - Pubcon October 2015
Life After Mobilegeddon: App Deep Linking Strategies - Pubcon October 2015Life After Mobilegeddon: App Deep Linking Strategies - Pubcon October 2015
Life After Mobilegeddon: App Deep Linking Strategies - Pubcon October 2015
 
Android のusb support
Android のusb supportAndroid のusb support
Android のusb support
 
Android deep dive
Android deep diveAndroid deep dive
Android deep dive
 
Android broadcast receiver tutorial
Android broadcast receiver  tutorialAndroid broadcast receiver  tutorial
Android broadcast receiver tutorial
 
Android broadcast receiver tutorial
Android broadcast receiver   tutorialAndroid broadcast receiver   tutorial
Android broadcast receiver tutorial
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
Android Application Development Using Java
Android Application Development Using JavaAndroid Application Development Using Java
Android Application Development Using Java
 
Android terminologies
Android terminologiesAndroid terminologies
Android terminologies
 
Beginning android
Beginning android Beginning android
Beginning android
 
Industrial Training in Android Application
Industrial Training in Android ApplicationIndustrial Training in Android Application
Industrial Training in Android Application
 

More from Shaul Rosenzwieg

Brainstorming: Manage your ideas like a pro
Brainstorming: Manage your ideas like a proBrainstorming: Manage your ideas like a pro
Brainstorming: Manage your ideas like a pro
Shaul Rosenzwieg
 
Kotlin Coroutines and Rx
Kotlin Coroutines and RxKotlin Coroutines and Rx
Kotlin Coroutines and Rx
Shaul Rosenzwieg
 
Lifecycle of a pixel
Lifecycle of a pixelLifecycle of a pixel
Lifecycle of a pixel
Shaul Rosenzwieg
 
Secure Android Development
Secure Android DevelopmentSecure Android Development
Secure Android Development
Shaul Rosenzwieg
 
Android virtual machine internals
Android virtual machine internalsAndroid virtual machine internals
Android virtual machine internals
Shaul Rosenzwieg
 
Why learn Internals?
Why learn Internals?Why learn Internals?
Why learn Internals?
Shaul Rosenzwieg
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
Shaul Rosenzwieg
 

More from Shaul Rosenzwieg (7)

Brainstorming: Manage your ideas like a pro
Brainstorming: Manage your ideas like a proBrainstorming: Manage your ideas like a pro
Brainstorming: Manage your ideas like a pro
 
Kotlin Coroutines and Rx
Kotlin Coroutines and RxKotlin Coroutines and Rx
Kotlin Coroutines and Rx
 
Lifecycle of a pixel
Lifecycle of a pixelLifecycle of a pixel
Lifecycle of a pixel
 
Secure Android Development
Secure Android DevelopmentSecure Android Development
Secure Android Development
 
Android virtual machine internals
Android virtual machine internalsAndroid virtual machine internals
Android virtual machine internals
 
Why learn Internals?
Why learn Internals?Why learn Internals?
Why learn Internals?
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 

Recently uploaded

Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 

Recently uploaded (20)

Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 

Android Open Accessory

  • 1. Android Open Accessory USB device to accessory protocol
  • 2. What is it? ● USB protocol that allows communication between Android devices and accessories in accessory mode ● AOAv1 - supported since API 12, with lib since API 10, supports basic communication ● AOAv2 - supported since API 16, adds audio streaming and HID capabilities ● Device is USB host and accessory is USB client
  • 3. How does it work? Android app ● App declares itself to handle an accessory or accessory family ● App handles specific intents ● UsbAccessory object is attached to that intent in a Bundle ● Once it is obtained, transfer of data between USB device and Android device is possible
  • 4. How does it work? Accessory ● Accessory sends series of specific USB control commands: ○ Get AOA version - device returns integer, currently 0 for not supported, 1 or 2 if supported ○ Accessory identifies itself by sending its vendor, model, manufacturer URI and serial number, which should match what Android application declared as supported devices ○ If Android device returns valid status on all of those, it sends “go to AOA mode” command ● Android device disconnects from USB and reconnects in AOA mode with static PID and VID ● At this stage, if everything went well, Android OS sends the intent to the application with UsbAccessory object which is describing the accessory
  • 5. Declaring support for AOA res/accessory_filter.xml: <?xml version="1.0" encoding="utf-8"?> <resources> <usb-accessory manufacturer="Tikal" model="Shaul haGadol" version="1.0"/> </resources>
  • 6. Manifest <activity android:name=".UsbTest" android:label="@string/app_name" android:launchMode="singleTop"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> <action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" /> </intent-filter> <meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" android:resource="@xml/accessory_filter" /> </activity>
  • 7. In Activity if (getIntent().getAction().equals("android.hardware.usb.action.USB_ACCESSORY_ATTACHED")) { UsbAccessory accessory = UsbManager.getAccessory(getIntent()); FileDescriptor fd = null; try { fd = UsbManager.getInstance(this).openAccessory(accessory).getFileDescriptor(); } catch (IllegalArgumentException e) { finish(); } catch (NullPointerException e) { finish(); } mFout = new FileOutputStream(fd); mFin = new FileInputStream(fd); }
  • 8. Accessory side, get AOA version rc = libusb_control_transfer(handle, //handle USB_CMD_BLOCK_READ, //bmRequestType ACCESSORY_GET_PROTOCOL, //bRequest 0, //wValue 0, //wIndex ioBuffer, //data 2, //wLength 0 //timeout ); libusb_release_interface(handle, 0); libusb_close(handle); int aoaVersion = ioBuffer[1] << 8 | ioBuffer[0];
  • 9. Accessory side, identify device response = libusb_control_transfer( device.handle, USB_CMD_VENDOR_SPECIFIC, ACCESSORY_SEND_STRING, 0, ACCESSORY_STRING_MANUFACTURER, (unsigned char*)manufacturer, strlen(manufacturer), 0);
  • 10. Accessory side, put in AOA mode response = libusb_control_transfer( device.handle, USB_CMD_VENDOR_SPECIFIC, ACCESSORY_START, 0, 0, NULL, 0, 0);
  • 11. Accessory side, open device rc = libusb_get_device_descriptor(device, &desc); if (rc < 0) { continue; } if ((libusb_open(device, &handle)) < 0) { fprintf(stdout, "Problem acquiring handlen"); return; } libusb_claim_interface(handle, 0);
  • 12. Accessory side, transfer data while (libusb_bulk_transfer(sourceHandle, IN, buffer, BUFFER_LEN, &transferred, 1000000 * 10) == 0) { rc1 = libusb_bulk_transfer(targetHandle, OUT, buffer, transferred, &transferred, 1000000 * 10); if(rc1 == 0) { buffCnt++; if(buffCnt % 200 == 0) { double mb = (buffCnt*BUFFER_LEN) / (1024 * 1024); fprintf(stdout, "%lu s sent %.2f mbn", time(NULL) - before, mb); } } else { fprintf(stdout, "error sending buffer rc=%dn", rc1); return -1; } }
  • 13. Accessory side, constants #define USB_ACCESSORY_PRODUCT_ID 0x2D00 #define USB_ACCESSORY_ADB_PRODUCT_ID 0x2D01 #define ACCESSORY_STRING_MANUFACTURER 0 #define ACCESSORY_STRING_MODEL 1 #define ACCESSORY_STRING_DESCRIPTION 2 #define ACCESSORY_STRING_VERSION 3 #define ACCESSORY_STRING_URI 4 #define ACCESSORY_STRING_SERIAL 5 #define ACCESSORY_GET_PROTOCOL 51 #define ACCESSORY_SEND_STRING 52 #define ACCESSORY_START 53 #define USB_CMD_BLOCK_READ 0xc0 #define USB_CMD_VENDOR_SPECIFIC 0x40
  • 14. Additional info ● https://source.android.com/devices/accessories/protocol ● https://www.youtube.com/watch?v=kReFemy4UmU ● https://opensourceforu.com/2014/11/the-android-open-accessory-protocol- all-about/ ● http://wiki.p2pfoundation.net/Android_Open_Accessory ● http://jjmilburn.github.io/2017/05/08/Android-AOA-Support/