SlideShare a Scribd company logo
1 of 29
Download to read offline
Extending Android with New Devices
         Android outside the mobile context


    Shree Kumar                   Nitheesh K L
    InnoMinds Software         PES Institute of Technology
Speaker Intro


   Shree Kumar
   InnoMinds Software




                        Nitheesh K L
                 PES Institute of Technology
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
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
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
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
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
Joystick : Step 1
                                                            User App (Java)
                                                      Service Wrapper (optional)
                                                       Privileged Service (Java)

                                                                     JNI Interface

                                                       ueventd       Device Node



 • Kernel drivers
                                                                        Kernel
                                                                        Device



    – Defaults to HID raw driver present
    – Boot & Check
 • Device node
    – /dev/input/eventX
 $ cat /proc/bus/input/devices | grep ^[NH] | grep –A 1 Gamepad 
> | grep event
  N: Logitech Precision Gamepad
  H: Handlers=event15
Joystick : Step 2
                                                        User App (Java)
                                                  Service Wrapper (optional)
                                                   Privileged Service (Java)

                                                                 JNI Interface

                                                   ueventd       Device Node

                                                                    Kernel
                                                                    Device


• Interface to the device node
     fd = open(“/dev/input/event15”, O_RDONLY);

  – Read /dev/input/eventX
     • Get single key code per event
        – ev.code : scan code
        – ev.value : key down/up
       struct input_event ev;
       rd = read (fd, &ev, sizeof(struct input_event);
Joystick : Step 2 (contd)
                                                      User App (Java)
                                                Service Wrapper (optional)
                                                 Privileged Service (Java)

                                                               JNI Interface



• Wrap native code using JNI
                                                 ueventd       Device Node

                                                                  Kernel
                                                                  Device


static const JNINativeMethod gMethods[] = {
       {“open”, “()Z”, (void *)Java_Joystick_open},
       {“getKey”, “()I”, (void *)Java_Joystick_getKey},
       {“close”, “()V”, (void *)Java_Joystick_close},
};

Jint JNI_OnLoad(JavaVM* vm, void* reserved) {

         //register your methods
                ...
}


• Android.mk – generate lib
    LOCAL_MODULE := libsample_joystick
Joystick : Step 3
                                                        User App (Java)
                                                  Service Wrapper (optional)
                                                   Privileged Service (Java)

                                                                 JNI Interface

                                                   ueventd       Device Node


• Permission for device node                                        Kernel
                                                                    Device



  – <Android-src>/system/core/init/devices.c
Static struct perms_devperms[] = {
             ...
{“/dev/input”, 0666, AID_SYSTEM, AID_INPUT, 1},
             ...
}

$ls –l /dev/input
crw-rw---- system input 13, 79 2011-11-18 14:05 event15
crw-rw---- system input 13, 79 2011-11-18 14:05 event11
crw-rw---- system input 13, 79 2011-11-18 14:05 event4
       ...


  – Ueventd.rc
Joystick : Step 4
                                                   User App (Java)
                                             Service Wrapper (optional)
                                              Privileged Service (Java)

                                                            JNI Interface

                                              ueventd       Device Node


• Service Wrapper around JNI                                   Kernel
                                                               Device

 |
 +---com
 |   ---sample
 |       +---hardware
 |       |   ---joystick
 |       |           JoystickAPI.aidl
 |       |           JoystickCallback.aidl
 |       |           Joystick.java
 |       |           Joystick.class
 |       |
 |       ---service
 |               JoystickService.java
 |
 +---jni
 |       Android.mk
 |       Joystick.h
 |       Joystick.cpp
 |       Jsfunctions.h
 |       Jsfunctions.cpp
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” />
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
               }
      }
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
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){
                 }
        }
}
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);
                        }
               });
      }
  };
Joystick : Step 6 (contd)
                                  User App (Java)
                            Service Wrapper (optional)
                             Privileged Service (Java)

                                           JNI Interface

                             ueventd       Device Node

                                              Kernel
                                              Device
Joystick : Overall
                           User App (Java)
                     Service Wrapper (optional)
                      Privileged Service (Java)

                                    JNI Interface

                      ueventd       Device Node

                                       Kernel
                                       Device
Example 2
    • Barcode Scanner
           – Opticon MDI 2300
                   • 2D scanner
           – Available as a module for development




Extending Android with New Devices | DroidCon India 2011
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
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
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
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
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
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
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
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
Questions ?

      Shree                Nitheesh
shree.shree@gmail.com   nitheeshkl@gmail.com

More Related Content

What's hot

BlackHat Asia 2017-Myth and Truth about Hypervisor-Based Kernel Protector
BlackHat Asia 2017-Myth and Truth about Hypervisor-Based Kernel ProtectorBlackHat Asia 2017-Myth and Truth about Hypervisor-Based Kernel Protector
BlackHat Asia 2017-Myth and Truth about Hypervisor-Based Kernel ProtectorSeunghun han
 
HITBSecConf 2017-Shadow-Box-the Practical and Omnipotent Sandbox
HITBSecConf 2017-Shadow-Box-the Practical and Omnipotent SandboxHITBSecConf 2017-Shadow-Box-the Practical and Omnipotent Sandbox
HITBSecConf 2017-Shadow-Box-the Practical and Omnipotent SandboxSeunghun han
 
Trinity press deck 10 2 2012
Trinity press deck 10 2 2012Trinity press deck 10 2 2012
Trinity press deck 10 2 2012AMD
 
VCOC BonFIRE presentation at FIRE Engineering Workshop 2012
VCOC BonFIRE presentation at FIRE Engineering Workshop 2012VCOC BonFIRE presentation at FIRE Engineering Workshop 2012
VCOC BonFIRE presentation at FIRE Engineering Workshop 2012Andrés Gómez
 
V Labs Product Presentation
V Labs  Product PresentationV Labs  Product Presentation
V Labs Product PresentationWil Huijben
 
ROM Hacking for Fun, Profit & Infinite Lives
ROM Hacking for Fun, Profit & Infinite LivesROM Hacking for Fun, Profit & Infinite Lives
ROM Hacking for Fun, Profit & Infinite LivesUlisses Albuquerque
 
AMD Embedded G-Series Press Presentation
AMD Embedded G-Series Press PresentationAMD Embedded G-Series Press Presentation
AMD Embedded G-Series Press PresentationAMD
 
AMD Embedded Solutions Guide
AMD Embedded Solutions GuideAMD Embedded Solutions Guide
AMD Embedded Solutions GuideAMD
 
AMD Unified Video Decoder
AMD Unified Video DecoderAMD Unified Video Decoder
AMD Unified Video DecoderAMD
 
Keynote Speech: Xen ARM Virtualization
Keynote Speech: Xen ARM VirtualizationKeynote Speech: Xen ARM Virtualization
Keynote Speech: Xen ARM VirtualizationThe Linux Foundation
 
Best Practices in Device Control: An In-Depth Look at Enforcing Data Protecti...
Best Practices in Device Control: An In-Depth Look at Enforcing Data Protecti...Best Practices in Device Control: An In-Depth Look at Enforcing Data Protecti...
Best Practices in Device Control: An In-Depth Look at Enforcing Data Protecti...Lumension
 
Support user group meeting 2012
Support user group meeting 2012Support user group meeting 2012
Support user group meeting 2012Interlatin
 
13.30 hr Hebinck
13.30 hr Hebinck13.30 hr Hebinck
13.30 hr HebinckThemadagen
 

What's hot (20)

BlackHat Asia 2017-Myth and Truth about Hypervisor-Based Kernel Protector
BlackHat Asia 2017-Myth and Truth about Hypervisor-Based Kernel ProtectorBlackHat Asia 2017-Myth and Truth about Hypervisor-Based Kernel Protector
BlackHat Asia 2017-Myth and Truth about Hypervisor-Based Kernel Protector
 
HITBSecConf 2017-Shadow-Box-the Practical and Omnipotent Sandbox
HITBSecConf 2017-Shadow-Box-the Practical and Omnipotent SandboxHITBSecConf 2017-Shadow-Box-the Practical and Omnipotent Sandbox
HITBSecConf 2017-Shadow-Box-the Practical and Omnipotent Sandbox
 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
 
Learn C Programming Language by Using GDB
Learn C Programming Language by Using GDBLearn C Programming Language by Using GDB
Learn C Programming Language by Using GDB
 
Android IPC Mechanism
Android IPC MechanismAndroid IPC Mechanism
Android IPC Mechanism
 
Trinity press deck 10 2 2012
Trinity press deck 10 2 2012Trinity press deck 10 2 2012
Trinity press deck 10 2 2012
 
VCOC BonFIRE presentation at FIRE Engineering Workshop 2012
VCOC BonFIRE presentation at FIRE Engineering Workshop 2012VCOC BonFIRE presentation at FIRE Engineering Workshop 2012
VCOC BonFIRE presentation at FIRE Engineering Workshop 2012
 
V Labs Product Presentation
V Labs  Product PresentationV Labs  Product Presentation
V Labs Product Presentation
 
ROM Hacking for Fun, Profit & Infinite Lives
ROM Hacking for Fun, Profit & Infinite LivesROM Hacking for Fun, Profit & Infinite Lives
ROM Hacking for Fun, Profit & Infinite Lives
 
Sahara Net Slate
Sahara Net SlateSahara Net Slate
Sahara Net Slate
 
AMD Embedded G-Series Press Presentation
AMD Embedded G-Series Press PresentationAMD Embedded G-Series Press Presentation
AMD Embedded G-Series Press Presentation
 
AMD Embedded Solutions Guide
AMD Embedded Solutions GuideAMD Embedded Solutions Guide
AMD Embedded Solutions Guide
 
AMD Unified Video Decoder
AMD Unified Video DecoderAMD Unified Video Decoder
AMD Unified Video Decoder
 
Graphics Passthrough With Vt D V2
Graphics Passthrough With Vt D V2Graphics Passthrough With Vt D V2
Graphics Passthrough With Vt D V2
 
Graphics Passthrough With Vt D
Graphics Passthrough With Vt DGraphics Passthrough With Vt D
Graphics Passthrough With Vt D
 
SDN
SDNSDN
SDN
 
Keynote Speech: Xen ARM Virtualization
Keynote Speech: Xen ARM VirtualizationKeynote Speech: Xen ARM Virtualization
Keynote Speech: Xen ARM Virtualization
 
Best Practices in Device Control: An In-Depth Look at Enforcing Data Protecti...
Best Practices in Device Control: An In-Depth Look at Enforcing Data Protecti...Best Practices in Device Control: An In-Depth Look at Enforcing Data Protecti...
Best Practices in Device Control: An In-Depth Look at Enforcing Data Protecti...
 
Support user group meeting 2012
Support user group meeting 2012Support user group meeting 2012
Support user group meeting 2012
 
13.30 hr Hebinck
13.30 hr Hebinck13.30 hr Hebinck
13.30 hr Hebinck
 

Viewers also liked

Droidcon 2013 France - Android Platform Anatomy
Droidcon 2013 France - Android Platform AnatomyDroidcon 2013 France - Android Platform Anatomy
Droidcon 2013 France - Android Platform AnatomyBenjamin Zores
 
Androidにおける強制アクセス制御
Androidにおける強制アクセス制御Androidにおける強制アクセス制御
Androidにおける強制アクセス制御Hiromu Yakura
 
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.
 
Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Opersys inc.
 
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.
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Opersys inc.
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with NougatOpersys inc.
 

Viewers also liked (7)

Droidcon 2013 France - Android Platform Anatomy
Droidcon 2013 France - Android Platform AnatomyDroidcon 2013 France - Android Platform Anatomy
Droidcon 2013 France - Android Platform Anatomy
 
Androidにおける強制アクセス制御
Androidにおける強制アクセス制御Androidにおける強制アクセス制御
Androidにおける強制アクセス制御
 
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...
 
Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013
 
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...
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with Nougat
 

Similar to Extending Android with New Devices

2012 java one-con3648
2012 java one-con36482012 java one-con3648
2012 java one-con3648Eing Ong
 
Android village @nullcon 2012
Android village @nullcon 2012 Android village @nullcon 2012
Android village @nullcon 2012 hakersinfo
 
Nokia Asha App Development - Part 1
Nokia Asha App Development - Part 1Nokia Asha App Development - Part 1
Nokia Asha App Development - Part 1Marlon Luz
 
"JavaME + Android in action" CCT-CEJUG Dezembro 2008
"JavaME + Android in action" CCT-CEJUG Dezembro 2008"JavaME + Android in action" CCT-CEJUG Dezembro 2008
"JavaME + Android in action" CCT-CEJUG Dezembro 2008Vando Batista
 
Game Development for Nokia Asha Devices with Java ME #1
Game Development for Nokia Asha Devices with Java ME #1Game Development for Nokia Asha Devices with Java ME #1
Game Development for Nokia Asha Devices with Java ME #1Marlon Luz
 
Developing Rich Interfaces in JavaFX for Ultrabooks
Developing Rich Interfaces in JavaFX for UltrabooksDeveloping Rich Interfaces in JavaFX for Ultrabooks
Developing Rich Interfaces in JavaFX for UltrabooksBruno Borges
 
ZFConf 2012: Zend Framework 2, a quick start (Enrico Zimuel)
ZFConf 2012: Zend Framework 2, a quick start (Enrico Zimuel)ZFConf 2012: Zend Framework 2, a quick start (Enrico Zimuel)
ZFConf 2012: Zend Framework 2, a quick start (Enrico Zimuel)ZFConf Conference
 
Zend Framework 2 quick start
Zend Framework 2 quick startZend Framework 2 quick start
Zend Framework 2 quick startEnrico Zimuel
 
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...Paris Open Source Summit
 
Mobile operating systems - Application Benchmarking
Mobile operating systems - Application BenchmarkingMobile operating systems - Application Benchmarking
Mobile operating systems - Application BenchmarkingNicolas Demetriou
 
One Step Ahead of Cheaters -- Instrumenting Android Emulators
One Step Ahead of Cheaters -- Instrumenting Android EmulatorsOne Step Ahead of Cheaters -- Instrumenting Android Emulators
One Step Ahead of Cheaters -- Instrumenting Android EmulatorsPriyanka Aash
 
[A2]android security의 과거와 미래 – from linux to jelly bean
[A2]android security의 과거와 미래 – from linux to jelly bean[A2]android security의 과거와 미래 – from linux to jelly bean
[A2]android security의 과거와 미래 – from linux to jelly beanNAVER D2
 

Similar to Extending Android with New Devices (20)

2012 java one-con3648
2012 java one-con36482012 java one-con3648
2012 java one-con3648
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Android village @nullcon 2012
Android village @nullcon 2012 Android village @nullcon 2012
Android village @nullcon 2012
 
Android Attacks
Android AttacksAndroid Attacks
Android Attacks
 
Mobile Java
Mobile JavaMobile Java
Mobile Java
 
Introduction to Java ME
Introduction to Java MEIntroduction to Java ME
Introduction to Java ME
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Getting Native with NDK
Getting Native with NDKGetting Native with NDK
Getting Native with NDK
 
Nokia Asha App Development - Part 1
Nokia Asha App Development - Part 1Nokia Asha App Development - Part 1
Nokia Asha App Development - Part 1
 
"JavaME + Android in action" CCT-CEJUG Dezembro 2008
"JavaME + Android in action" CCT-CEJUG Dezembro 2008"JavaME + Android in action" CCT-CEJUG Dezembro 2008
"JavaME + Android in action" CCT-CEJUG Dezembro 2008
 
Game Development for Nokia Asha Devices with Java ME #1
Game Development for Nokia Asha Devices with Java ME #1Game Development for Nokia Asha Devices with Java ME #1
Game Development for Nokia Asha Devices with Java ME #1
 
Developing Rich Interfaces in JavaFX for Ultrabooks
Developing Rich Interfaces in JavaFX for UltrabooksDeveloping Rich Interfaces in JavaFX for Ultrabooks
Developing Rich Interfaces in JavaFX for Ultrabooks
 
ZFConf 2012: Zend Framework 2, a quick start (Enrico Zimuel)
ZFConf 2012: Zend Framework 2, a quick start (Enrico Zimuel)ZFConf 2012: Zend Framework 2, a quick start (Enrico Zimuel)
ZFConf 2012: Zend Framework 2, a quick start (Enrico Zimuel)
 
Android ppt
Android pptAndroid ppt
Android ppt
 
Zend Framework 2 quick start
Zend Framework 2 quick startZend Framework 2 quick start
Zend Framework 2 quick start
 
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
 
Improve Android System Component Performance
Improve Android System Component PerformanceImprove Android System Component Performance
Improve Android System Component Performance
 
Mobile operating systems - Application Benchmarking
Mobile operating systems - Application BenchmarkingMobile operating systems - Application Benchmarking
Mobile operating systems - Application Benchmarking
 
One Step Ahead of Cheaters -- Instrumenting Android Emulators
One Step Ahead of Cheaters -- Instrumenting Android EmulatorsOne Step Ahead of Cheaters -- Instrumenting Android Emulators
One Step Ahead of Cheaters -- Instrumenting Android Emulators
 
[A2]android security의 과거와 미래 – from linux to jelly bean
[A2]android security의 과거와 미래 – from linux to jelly bean[A2]android security의 과거와 미래 – from linux to jelly bean
[A2]android security의 과거와 미래 – from linux to jelly bean
 

Recently uploaded

Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 

Recently uploaded (20)

Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

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
  • 8. Joystick : Step 1 User App (Java) Service Wrapper (optional) Privileged Service (Java) JNI Interface ueventd Device Node • Kernel drivers Kernel Device – Defaults to HID raw driver present – Boot & Check • Device node – /dev/input/eventX $ cat /proc/bus/input/devices | grep ^[NH] | grep –A 1 Gamepad > | grep event N: Logitech Precision Gamepad H: Handlers=event15
  • 9. Joystick : Step 2 User App (Java) Service Wrapper (optional) Privileged Service (Java) JNI Interface ueventd Device Node Kernel Device • Interface to the device node fd = open(“/dev/input/event15”, O_RDONLY); – Read /dev/input/eventX • Get single key code per event – ev.code : scan code – ev.value : key down/up struct input_event ev; rd = read (fd, &ev, sizeof(struct input_event);
  • 10. Joystick : Step 2 (contd) User App (Java) Service Wrapper (optional) Privileged Service (Java) JNI Interface • Wrap native code using JNI ueventd Device Node Kernel Device static const JNINativeMethod gMethods[] = { {“open”, “()Z”, (void *)Java_Joystick_open}, {“getKey”, “()I”, (void *)Java_Joystick_getKey}, {“close”, “()V”, (void *)Java_Joystick_close}, }; Jint JNI_OnLoad(JavaVM* vm, void* reserved) { //register your methods ... } • Android.mk – generate lib LOCAL_MODULE := libsample_joystick
  • 11. Joystick : Step 3 User App (Java) Service Wrapper (optional) Privileged Service (Java) JNI Interface ueventd Device Node • Permission for device node Kernel Device – <Android-src>/system/core/init/devices.c Static struct perms_devperms[] = { ... {“/dev/input”, 0666, AID_SYSTEM, AID_INPUT, 1}, ... } $ls –l /dev/input crw-rw---- system input 13, 79 2011-11-18 14:05 event15 crw-rw---- system input 13, 79 2011-11-18 14:05 event11 crw-rw---- system input 13, 79 2011-11-18 14:05 event4 ... – Ueventd.rc
  • 12. Joystick : Step 4 User App (Java) Service Wrapper (optional) Privileged Service (Java) JNI Interface ueventd Device Node • Service Wrapper around JNI Kernel Device | +---com | ---sample | +---hardware | | ---joystick | | JoystickAPI.aidl | | JoystickCallback.aidl | | Joystick.java | | Joystick.class | | | ---service | JoystickService.java | +---jni | Android.mk | Joystick.h | Joystick.cpp | Jsfunctions.h | Jsfunctions.cpp
  • 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
  • 29. Questions ? Shree Nitheesh shree.shree@gmail.com nitheeshkl@gmail.com