Global Sources
EE Times-India
Stay in touch with EE Times India
EE Times-India > Embedded

Designing USB device with Android framework

Posted: 05 Dec 2014     Print Version  Bookmark and Share

Keywords:Android  USB  Compatibility Test Suite  Linux kernel  RFC2119 

Now that you understand how the Android framework in USB device mode works, you can explore the Android framework in USB host mode. Similar to device mode, host mode keeps most of the class functions implemented within the Linux kernel, but classes like MTP host mode are implemented in Android user space. It is important to note that, unlike the device stack (gadget driver), which differs from the mainline Linux kernel, the USB host stack is same as the mainline Linux kernel.

Though Linux kernel has support for almost all USB devices, an Android device in USB host mode might not support all devices because the Android device is functioning as a limited capability USB embedded host or USB OTG host. It is important to note that Android CDD did not define USB host functionalities like it did for the USB device mode. Thus USB host class support, like support for the 3G dongle, is determined by the Android device manufacturer.

Figure 5 provides a top-level architecture diagram of the Android USB host mode framework.

 Android USB host framework architecture

Figure 5: Android USB host framework architecture.

USB host mode service
Similar to device mode, USB Service is the key part in the USB host mode. The main role of this framework is to detect state changes like connection and disconnection within the USB host kernel drivers, and convert those changes into a format that is understood in the Android space.

USB host mode classes
USB host mode classes (functions) like MTP are implemented within the Android framework, and their functionality is spread across the Java and JNI layers. This USB function framework represents the class implementation and the implementation necessary for USB Host APIs. Thus, the main role of this framework is to translate USB application requests and communicate them to the USB device connected to the kernel below.

Libusbhost user space drivers
One of the most popular USB user space drivers on Linux is libusb, while libusbhost is a similar, thinner version of it, adapted to Android USB host requirements. The main role of this library is to act as an interface between the Linux kernel USB driver and the Android USB framework. This also makes it possible to implement necessary infrastructure to facilitate detection of any new USB device connected to the kernel below.

Kernel USB File System
In USB host mode, the kernel file system plays a key role, starting from detecting a USB device when it gets identified within the kernel, to transferring information from Android to the kernel space. To better understand the USB host mode operation, it is important to first understand the kernel USB file system.

Other Android infrastructure frameworks
Inside the Android framework, there are other frameworks like audio, volume daemon, and so on, that are interested in knowing USB state changes. Some of these infrastructures take on the role of presenting the USB functionality to the user.

Having understood the Android USB requirements and the top-level blocks of Android USB framework, you'll now explore the various USB-related APIs that the Android framework exposes in order to manage a USB device or functionality.

Android USB Packages
The Android framework is a Java-based system, and the term "package" is used in Java programming to organise similar Java classes into a namespace. This practice enables programmers to easily manage access rights and avoid conflicts. Along the same line of thought, Android USB functional implementations are collated in a single namespace, called the android.hardware.usb. This section explores different USB classes collated in this package, as well as the APIs that deliver these USB classes' exports to a programmer. The section further covers the MTP class, a USB host function packaged separately to manage media device connected to an Android device over USB.

he android.hardware.usb package is a collection of USB host APIs and USB accessory APIs. USB host APIs were introduced as part of Android Honey Comb 3.1 version (API level 12), and the support is available on Android 3.1 and higher. USB accessory APIs were introduced in Android Honey Comb 3.1 version (API level 12) as well, but the support was back-ported to Android Ginger Bread 2.3.4 version (API level 10). The back-ported version of accessory APIs can be imported using the package name The next sections explore the different classes and their functions.

This class represents a USB accessory device connected to an Android device that's in USB device mode. Note that a USB accessory is an external hardware device acting as a USB host, as explained in figure 3. When an accessory device is connected to an Android device, applications can search for and get product information like the manufacturer name, model, version, and so on, from other devices that connect to the accessory. This class provides necessary methods for an application developer to get product information, as previously stated. Complete details of this class are available here.

 First Page Previous Page 1 • 2 • 3 • 4 • 5 Next Page Last Page

Comment on "Designing USB device with Android fr..."
*  You can enter [0] more charecters.
*Verify code:


Visit Asia Webinars to learn about the latest in technology and get practical design tips.


Go to top             Connect on Facebook      Follow us on Twitter      Follow us on Orkut

Back to Top