SlideShare ist ein Scribd-Unternehmen logo
1 von 14
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/

Weitere ähnliche Inhalte

Was ist angesagt?

Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALOpersys inc.
 
Android seminar-presentation
Android seminar-presentationAndroid seminar-presentation
Android seminar-presentationconnectshilpa
 
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 architecture
android architectureandroid architecture
android architectureAashita Gupta
 
U-boot and Android Verified Boot 2.0
U-boot and Android Verified Boot 2.0U-boot and Android Verified Boot 2.0
U-boot and Android Verified Boot 2.0GlobalLogic Ukraine
 
Learning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device DriverLearning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device DriverNanik Tolaram
 
Embedded Android Workshop with Pie
Embedded Android Workshop with PieEmbedded Android Workshop with Pie
Embedded Android Workshop with PieOpersys inc.
 
Introduction of USB 3.1
Introduction of USB 3.1 Introduction of USB 3.1
Introduction of USB 3.1 Rainny Tu
 
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 debuggingUtkarsh Mankad
 
Android device driver structure introduction
Android device driver structure introductionAndroid device driver structure introduction
Android device driver structure introductionWilliam Liang
 
Secured Mobile Application Development in Android, Blackberry & iOS
Secured Mobile Application Development in Android, Blackberry & iOSSecured Mobile Application Development in Android, Blackberry & iOS
Secured Mobile Application Development in Android, Blackberry & iOSAppin Delhi
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessNanik Tolaram
 
Android Operating System
Android Operating SystemAndroid Operating System
Android Operating SystemBilal Mirza
 
Introduction to Android
Introduction to Android Introduction to Android
Introduction to Android Ranjith Kumar
 

Was ist angesagt? (20)

Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HAL
 
Deep Dive into the AOSP
Deep Dive into the AOSPDeep Dive into the AOSP
Deep Dive into the AOSP
 
Android seminar-presentation
Android seminar-presentationAndroid seminar-presentation
Android seminar-presentation
 
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 architecture
android architectureandroid architecture
android architecture
 
U-boot and Android Verified Boot 2.0
U-boot and Android Verified Boot 2.0U-boot and Android Verified Boot 2.0
U-boot and Android Verified Boot 2.0
 
Learning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device DriverLearning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device Driver
 
Embedded Android Workshop with Pie
Embedded Android Workshop with PieEmbedded Android Workshop with Pie
Embedded Android Workshop with Pie
 
Introduction of USB 3.1
Introduction of USB 3.1 Introduction of USB 3.1
Introduction of USB 3.1
 
Android seminar ppt
Android seminar pptAndroid seminar ppt
Android seminar ppt
 
Android Audio System
Android Audio SystemAndroid Audio System
Android Audio System
 
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
 
Android device driver structure introduction
Android device driver structure introductionAndroid device driver structure introduction
Android device driver structure introduction
 
Secured Mobile Application Development in Android, Blackberry & iOS
Secured Mobile Application Development in Android, Blackberry & iOSSecured Mobile Application Development in Android, Blackberry & iOS
Secured Mobile Application Development in Android, Blackberry & iOS
 
Hacking Android OS
Hacking Android OSHacking Android OS
Hacking Android OS
 
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 studio ppt
Android studio pptAndroid studio ppt
Android studio ppt
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting Process
 
Android Operating System
Android Operating SystemAndroid Operating System
Android Operating System
 
Introduction to Android
Introduction to Android Introduction to Android
Introduction to Android
 

Ähnlich wie Android Open Accessory

Hello android world
Hello android worldHello android world
Hello android worldeleksdev
 
FTF2014 - Android Accessory Protocol
FTF2014 - Android Accessory ProtocolFTF2014 - Android Accessory Protocol
FTF2014 - Android Accessory ProtocolGary Bisson
 
Native Android Development Practices
Native Android Development PracticesNative Android Development Practices
Native Android Development PracticesRoy Clarkson
 
Android studio
Android studioAndroid studio
Android studioAndri Yabu
 
01 introduction to android
01 introduction to android01 introduction to android
01 introduction to androidSokngim Sa
 
Getting started with android programming
Getting started with android programmingGetting started with android programming
Getting started with android programmingPERKYTORIALS
 
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 2015MobileMoxie
 
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 2015Suzzicks
 
Android deep dive
Android deep diveAndroid deep dive
Android deep diveAnuSahniNCI
 
Android broadcast receiver tutorial
Android broadcast receiver  tutorialAndroid broadcast receiver  tutorial
Android broadcast receiver tutorialmaamir farooq
 
Android broadcast receiver tutorial
Android broadcast receiver   tutorialAndroid broadcast receiver   tutorial
Android broadcast receiver tutorialmaamir farooq
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android DevelopmentAly Abdelkareem
 
Android Application Development Using Java
Android Application Development Using JavaAndroid Application Development Using Java
Android Application Development Using Javaamaankhan
 
Android terminologies
Android terminologiesAndroid terminologies
Android terminologiesjerry 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 ApplicationArcadian Learning
 

Ähnlich wie 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
 

Mehr von Shaul Rosenzwieg

Mehr von Shaul Rosenzwieg (8)

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
 
Binder: Android IPC
Binder: Android IPCBinder: Android IPC
Binder: Android IPC
 
Why learn Internals?
Why learn Internals?Why learn Internals?
Why learn Internals?
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 

Kürzlich hochgeladen

Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile EnvironmentVictorSzoltysek
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 

Kürzlich hochgeladen (20)

Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 

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/