Shows how a device maker can extend Android to support new devices, while preserving Android compatibility. We demonstrate a joystick & an industrial barcode scanner.
08448380779 Call Girls In Civil Lines Women Seeking Men
Extending Android with New Devices
1. Extending Android with New Devices
Android outside the mobile context
Shree Kumar Nitheesh K L
InnoMinds Software PES Institute of Technology
2. Speaker Intro
Shree Kumar
InnoMinds Software
Nitheesh K L
PES Institute of Technology
3. Background
• Android expected to proliferate
– Not just on smart-phones & tablets
• Android built with MID devices in mind
– Newer use cases => other devices
– Changing the API is not permitted
• New devices, Additional APIs !
Extending Android with New Devices | DroidCon India 2011
4. Overview
• Device support in Linux
• Layered approach for Android
• Two examples
– Joystick
– Industrial Barcode Scanner
• Device Maker’s Perspective
– Standardized interfaces may not happen due to
schedules
– Market compatibility provided
Extending Android with New Devices | DroidCon India 2011
5. Linux Device Support
User App
Device API
setuid()
Privileged Daemon
setgid()
Device
udev
Node
Kernel
SUBSYSTEMS="usb",ATTRS(idVendor)=="0bb4",MODE="0666",OWNER="shree"
SUBSYSTEMS="usb",ATTRS(idVendor)=="8086",MODE="0666",OWNER="shree"
Device
Linux devs : Remember adding these lines to
/etc/udev/rules.d/51-android.rules?
Extending Android with New Devices | DroidCon India 2011
6. Our Android Approach
User App (Java)
uses-permission=USE_DEVICE
Service Wrapper (optional) uses-library=sample_device
Privileged Service (Java) Platform Library
Preserves Android
sharedUserId=android.uid.system JNI Interface Compatibility
ueventd Device Node
Kernel
chown USER:GROUP /dev/XYZ mknod /dev/XYZ
chmod 0ppp /dev/XYZ Device
Extending Android with New Devices | DroidCon India 2011
7. Example 1
• Supporting a USB Joystick
• Why this device ?
– Simplicity
– Map concepts to details
• You need
– Android device with USB host/OTG
Extending Android with New Devices | DroidCon India 2011
13. Joystick : Step 4 (contd)
User App (Java)
Service Wrapper (optional)
Privileged Service (Java)
JNI Interface
ueventd Device Node
• Signed APK provides privileged access Kernel
Device
# we ask for restricted permissions for our service,
# so the apk has to be signed
LOCAL_CERTIFICATE := platform
• Define permission in AndroidManifest.xml
<permission android:name = “com.sample.USE_JOYSTICK” />
14. Joystick : Step 4 (contd)
User App (Java)
Service Wrapper (optional)
Privileged Service (Java)
JNI Interface
ueventd Device Node
Kernel
• IPC service exposes API to applications
Device
– …/ JoystickAPI.aidl
interface JoystickAPI {
boolean setCallback(in JoystickCallback cb);
boolean clearCallback();
}
– … / JoystickService.java
Private JoystickAPI.Stub api = new JoystickAPI.Stub(){
public boolean setCallback(JoystickCallback cb){
// enable setting callback
}
public boolean clearCallback(){
// enable clearing callback
}
}
15. Joystick : Step 5
User App (Java)
Service Wrapper (optional)
Privileged Service (Java)
JNI Interface
ueventd Device Node
Kernel
• Platform Library
Device
• Declare your library to the framework
– /system/etc/permissions
– com.sample.hardware.joystick.xml
<?xml version="1.0" encoding="utf-8"?>
<permissions>
<library name="com.sample.hardware.joystick"
file="/system/framework/com.sample.hardware.joystick.jar"/>
</permissions>
• Output product is raw .jar file, NOT a .apk
adb push
out/target/product/generic_x86/system/framework/com.sample.hardware.joystick.jar
/system/framework
16. Joystick : Step 6
User App (Java)
Service Wrapper (optional)
Privileged Service (Java)
JNI Interface
ueventd Device Node
• Application interacts with device
Kernel
Device
– Binds to Service
Intent intent = new Intent(“com.sample.android.service.JoystickService”);
bindService(intent, serviceConnection, Service.BIND_AUTO_CREATE);
– Uses API provided by Service
ServiceConnection sc = new ServiceConnection(){
private void onServiceConnected(ComponentName n, Ibinder service){
api = Ijoystick.stub.asInterface(service);
try{
api.setCallback(jsCallback);
}catch (RemoteException e){
}
}
}
17. Joystick : Step 6 (contd)
User App (Java)
Service Wrapper (optional)
Privileged Service (Java)
JNI Interface
ueventd Device Node
• Run on UI Thread
Kernel
Device
JoystickCallback jsCallback = new JoystickCallback.Stub() {
private void onKeyPress(int arg0) throws RemoteException {
final int key = arg0;
runOnUiThread(new Runnable(){
public void run(){
updateUI(key);
}
});
}
};
18. Joystick : Step 6 (contd)
User App (Java)
Service Wrapper (optional)
Privileged Service (Java)
JNI Interface
ueventd Device Node
Kernel
Device
19. Joystick : Overall
User App (Java)
Service Wrapper (optional)
Privileged Service (Java)
JNI Interface
ueventd Device Node
Kernel
Device
20. Example 2
• Barcode Scanner
– Opticon MDI 2300
• 2D scanner
– Available as a module for development
Extending Android with New Devices | DroidCon India 2011
21. Example 2
• Why use a dedicated device ?
– Supports tons of symbologies
– Purpose made
• Fast
• Long cables, Laser illumination
– Would you drop your smart-
phone ?
Opticon symbology support, “Menubook” excerpt
Extending Android with New Devices | DroidCon India 2011 ZXing symbology support
22. Barcode Scanner : Step 1
User App (Java)
Service Wrapper (optional)
Privileged Service (Java)
JNI Interface
ueventd Device Node
• Setup the device
Kernel
Device
– We’ll use USB VCP (Virtual COM Port) mode
– Scan barcodes! Barcodes vary by device.
Excerpts from Sec 2-5 of Xenon 1900 User Guide
USB VCP configuration for MDI 2300 | Screenshot from opticonfigure.opticon.com
Extending Android with New Devices | DroidCon India 2011
23. Barcode Scanner : Step 2
User App (Java)
Service Wrapper (optional)
Privileged Service (Java)
JNI Interface
ueventd Device Node
• Change the kernel
Kernel
Device
– Specific steps depend on Android/kernel version
– Include support for CDC ACM devices
• Ensure support for protocol=“None” in cdc-acm.c
/* control interfaces without any protocol set */
{ USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
USB_CDC_PROTO_NONE) },
• Boot with the new kernel & check
Extending Android with New Devices | DroidCon India 2011
24. Barcode Scanner : Step 3
User App (Java)
Service Wrapper (optional)
Privileged Service (Java)
JNI Interface
ueventd Device Node
• Interface to the driver
Kernel
Device
– Read /dev/ttyACM0
– Get single barcode per line
• Test… at every step
• Wrap native code using JNI
– Can an app use the wrapper ?
# ls –l /dev/input*
crw-r----- 1 system input 13, 64 2011-11-02 14:51 event0
crw-r----- 1 system input 13, 64 2011-11-02 14:51 event1
Extending Android with New Devices | DroidCon India 2011
25. Barcode Scanner : Step 4
User App (Java)
Service Wrapper (optional)
Privileged Service (Java)
JNI Interface
ueventd Device Node
• ueventd : fix /dev/ttyACM0 access
Kernel
Device
– owner “system” (android.uid.system)
/dev/ttyACM0 0660 system root
Add this line to : system/core/rootdir/ueventd.rc
– Another method: owner “com.sample.uid.acm”
• Passes Android Compatibility !
mSettings.addSharedUserLP("android.uid.system",
Process.SYSTEM_UID, ApplicationInfo.FLAG_SYSTEM);
…
mSettings.addSharedUserLP("com.sample.uid.acm",
1018, ApplicationInfo.FLAG_SYSTEM);
frameworks/base/services/java/com/android/server/PackageManagerService.java
Extending Android with New Devices | DroidCon India 2011
26. Barcode Scanner : Step 5
User App (Java)
Service Wrapper (optional)
Privileged Service (Java)
JNI Interface
ueventd Device Node
• Service Wrapper around JNI
Kernel
Device
– AIDL based IPC service exposes API to applications
interface IBarcodeScanner {
boolean setCallback(in BarcodeScannerCallback callback);
boolean scanBarcode(int timeout);
boolean clearCallback();
};
Interface BarcodeScannerCallback {
void handlerBarcode(boolean timedout, String barcode);
}
– Signed APK provides privileged access
android:sharedUsedId=“android.uid.system”
Extending Android with New Devices | DroidCon India 2011
27. Barcode Scanner : Step 6
User App (Java)
Service Wrapper (optional)
Privileged Service (Java)
JNI Interface
ueventd Device Node
• Application interacts with device
Kernel
Device
– Binds to Service
– Uses API provided by Service
• Could be beautified…
– Unbinds when done!
Extending Android with New Devices | DroidCon India 2011
28. Summary
• HOWTO-support-devices-on-android.txt
– Important steps
– Examples
• Kept simple on purpose
– Skipped
• Power Management
• Deeper system integration
– You may want to rethink the interfaces !
Extending Android with New Devices | DroidCon India 2011