SlideShare une entreprise Scribd logo
1  sur  50
Télécharger pour lire hors ligne
Accessing Hardware on Android
FTF2014
04/08/2014
Gary Bisson
Embedded Software Engineer
SESSION OVERVIEW
1. Introduction
2. Native Development
3. Direct Access
4. Android HAL Layer
5. Custom System Service
6. Demonstrations
7. Conclusion
ABOUT THE PRESENTER
• Embedded Software Engineer at Adeneo Embedded
(Bellevue, WA)
Linux / Android
♦ BSP Adaptation
♦ Driver Development
♦ System Integration
Partners with Freescale
Introduction
Accessing HW on Android Introduction
ACCESSING THE HARDWARE
• How different from a GNU/Linux system?
No difference for native dev
What about Java applications?
• Android Architecture
Android API
SDK/NDK
5
Accessing HW on Android Introduction
ANDROID ARCHITECTURE
6
Accessing HW on Android Introduction
ACCESSING THE HARDWARE
Different ways of accessing devices from Android applications:
• Direct access from the application
Either in the Java or JNI layer
• Using the available Android hardware API
HAL adaptation
• Adding a custom System Service
API modification
7
Native Development
Accessing HW on Android Native Development
WHAT IS IT?
• Different from JNI/NDK
The word “native” in the NDK can be misleading as it
still involves all the limitations of Java applications
NDK gives you access only to a very limited subset of
the Android API
• Native application/daemon/library: can be run directly on
the system without the full Java stack
9
Accessing HW on Android Native Development
NATIVE APPLICATION
• Can be built statically
Avoids libc issues
Not preferred solution though
• Can be built against Bionic
Every binary/library in Android
Some adaptation may be required
10
Accessing HW on Android Native Development
BIONIC VS. GLIBC
• C++
No exception handling!
No STL! (Standard Template Library)
• Libpthread
Mutexes, condvars, etc. use Linux futexes
No semaphores
No pthread_cancel
• Misc
No wchar_t and no LOCALE support
No crypt()
11
Accessing HW on Android Native Development
BUILD A NATIVE APPLICATION
• Such applications can be found in AOSP:
system/core/
frameworks/base/cmds/
external/
• Same as a Java application, an Android.mk must be
created:
1 LOCAL_PATH:= $(call my-dir)
2 include $(CLEAR_VARS)
3 LOCAL_MODULE := hello-world
4 LOCAL_MODULE_TAGS := optional
5 LOCAL_SRC_FILES := hello-world.cpp
6 LOCAL_SHARED_LIBRARIES := liblog
7 include $(BUILD_EXECUTABLE)
12
Accessing HW on Android Native Development
ADD A NATIVE APPLICATION
• If LOCAL_MODULE_TAGS is set as optional, the package
name must be registered in the device.mk
• Once built, the binary is copied to
<out_folder>/system/bin
• Modify init.rc to start the application at startup:
1 service myapp /system/bin/myapp
2 oneshot
13
Direct Access
Accessing HW on Android Direct Access
ACCESSING THE HARDWARE
• Using the user-space interface (devfs, sysfs...)
Can be done either in Java or in Native C code
Simple Open / Read / Write / Close to a “file”
Every application that uses a specific hardware must
have code to handle it
• The correct permissions must be set
The device node shall be opened by all users (not
allowed by default) or by the UID/GID of the relevant
application(s)
init.rc or eventd.rc must be modified
15
Accessing HW on Android Direct Access
JAVA SAMPLE CODE
1 private void turnOnLed () throws IOException {
2 FileInputStream fileInputStream;
3 FileOutputStream fileOutputStream;
4 File file = new File("/sys/class/leds/led_usr1/brightness");
5 if (file.canRead()) {
6 fileInputStream = new FileInputStream(file);
7 if (fileInputStream.read() != '0') {
8 System.out.println("LED usr1 already onn");
9 return;
10 }
11 }
12 if (file.canWrite()) {
13 fileOutputStream = new FileOutputStream(file);
14 fileOutputStream.write('1');
15 }
16 }
16
Android HAL Layer
Accessing HW on Android Android HAL Layer
HARDWARE API
• Android Hardware API is accessed through the
android.hardware class.
• This class only provides support for a limited number of
devices such as:
Camera: used to set image capture settings, start/stop
preview, snap pictures, and retrieve frames for
encoding for video
Sensors: accelerometer, gyroscope, magnetometers,
proximity, temperature...
• OEMs may provide their own HAL implementation to
connect to the android hardware API (see hardware/imx)
18
Accessing HW on Android Android HAL Layer
HARDWARE API
• USB Host and Accessory: android.hardware.usb:
Provides support to communicate with USB hardware
peripherals that are connected to Android-powered
devices
• Input: android.hardware.input
Provides information about input devices and
available key layouts
New in API Level 16 (Jelly Bean)
• Other APIs:
For instance the android.app.Notification can be
used to toggle a LED (if properly registered) with the
FLAG_SHOW_LIGHTS parameter
19
Accessing HW on Android Android HAL Layer
HARDWARE ABSTRACTION LAYER (HAL)
20
Accessing HW on Android Android HAL Layer
LIGHTS LIBRARY
• Interface defined in
hardware/libhardware/include/hardware/lights.h
• Library must be named lights.<product_name>.so
• Will get loaded from /system/lib/hw at runtime
• See example in hardware/imx/lights/
• Mandatory to have backlight managed by the OS.
21
Accessing HW on Android Android HAL Layer
CAMERA LIBRARY
• Interface defined in
hardware/libhardware/include/hardware/camera.h
• Library must be named camera.<product_name>.so
• Will get loaded from /system/lib/hw at runtime
• See example in hardware/imx/mx6/libcamera/
22
Accessing HW on Android Android HAL Layer
GPS LIBRARY
• Interface defined in
hardware/libhardware/include/hardware/gps.h
• Library must be named gps.<product_name>.so
• Will get loaded from /system/lib/hw at runtime
• See example in hardware/imx/libgps/
23
Accessing HW on Android Android HAL Layer
SENSORS LIBRARY
• Interface defined in
hardware/libhardware/include/hardware/sensors.h
• Library must be named sensors.<product_name>.so
• Will get loaded from /system/lib/hw at runtime
• See example in hardware/imx/libsensors/
24
Accessing HW on Android Android HAL Layer
EXAMPLE: ADDING A SENSOR
1. Kernel driver must be working and loaded
2. Change directory to hardware/imx/libsensors
3. Add Sensor definition into sSensorList structure in
sensors.cpp
Applications will now be aware of a new sensor
This structure define the following parameters
♦ Name
♦ Vendor
♦ Version
♦ Type (Proximity, Temperature etc…)
♦ ...
25
Accessing HW on Android Android HAL Layer
EXAMPLE: ADDING A SENSOR
4. Create object of new sensor
Set file descriptor and event type
5. Update sensors_poll_context_t structure
6. Add new sensor case to handleToDriver function
7. Implement your class:
1 class AccelSensor : public SensorBase {
2 int mEnabled;
3 int setInitialState();
4 public:
5 AccelSensor();
6 virtual ~AccelSensor();
7 virtual int readEvents(sensors_event_t* data, int cnt);
8 virtual bool hasPendingEvents() const;
9 virtual int enable(int32_t handle, int enabled);
10 };
26
Accessing HW on Android Android HAL Layer
EXAMPLE: TESTING A SENSOR
• Use existing tool:
hardware/libhardware/tests/nusensors
This binary tool will list every sensor and try to pull
data from it
• Use existing java application: AndroSensor
www.appsapk.com/androsensor
• Create your own application
Using SensorManager
www.vogella.com/tutorials/AndroidSensor/article.html
27
Accessing HW on Android Android HAL Layer
EXAMPLE: SENSOR MANAGER
1 public class SensorActivity extends Activity, implements
SensorEventListener {
2 private final SensorManager mSensorManager;
3 private final Sensor mAccelerometer;
4 public SensorActivity() {
5 mSensorManager = (SensorManager)getSystemService(
SENSOR_SERVICE);
6 mAccelerometer = mSensorManager.getDefaultSensor(Sensor.
TYPE_ACCELEROMETER);
7 }
8 protected void onResume() {
9 super.onResume();
10 mSensorManager.registerListener(this, mAccelerometer,
SensorManager.SENSOR_DELAY_NORMAL);
11 }
12 [...]
13 public void onAccuracyChanged(Sensor sensor, int accuracy) {}
14 public void onSensorChanged(SensorEvent event) {}
15 }
28
Custom System Service
Accessing HW on Android Custom System Service
ANDROID SYSTEM SERVICES
• Service: component that performs long-running
operations in the background and does not provide a user
interface
• System Services vs. Local Service
System Services accessible for all
Access through getSystemService() method
Permissions required
30
Accessing HW on Android Custom System Service
ANDROID SYSTEM SERVICES
31
Accessing HW on Android Custom System Service
MAIN SYSTEM SERVICES
• System Server
All components contained in one process:
system_server
Mostly made up of Java-coded services with few
written in C/C++
• Media Server
All components contained in one process:
media-server
These services are all coded in C/C++
• Appear to operate independently to anyone connecting to
them through Binder
32
Accessing HW on Android Custom System Service
ANDROID SYSTEM SERVICES
33
Accessing HW on Android Custom System Service
SERVICE MANAGER
• Service Manager = YellowPages book of all services
• Need to register every System Service to be usable
• Can list all services available: service list
• Application asks the Service Manager for a handle to the
Service and then invokes that service's methods
34
Accessing HW on Android Custom System Service
ADDING A SYSTEM SERVICE
1. Creation of the API layer for the System Service (aidl)
Defines only exposed methods
API added to SDK/add-on
2. Creation of a wrapper class for the Service interface
3. Creation of an implementation of that class
4. Creation of a JNI layer if needed
35
Accessing HW on Android Custom System Service
ADDING A SYSTEM SERVICE
1st approach:
• System Service inside the System Server
• Advantages:
Part of the inner system
First to be started
System permissions
• Drawbacks:
SDK creation required
36
Accessing HW on Android Custom System Service
ADDING A SYSTEM SERVICE
2nd approach:
• System Service outside of the System Server
• Advantages:
No framework/ modification
Located in one folder
Easier to port from one version to another
System permissions
SDK add-on
• Drawbacks:
Considered as a usual App
♦ System might remove it in case it runs out of RAM
37
Accessing HW on Android Custom System Service
ADDING A SYSTEM SERVICE
• Example:
https://github.com/gibsson/BasicService
https://github.com/gibsson/BasicClient
• Although SDK generation is possible, SDK add-on is
preferred:
https://github.com/gibsson/basic_sdk_addon
38
Accessing HW on Android Custom System Service
BASIC SERVICE EXAMPLE
BasicService/
AndroidManifest.xml
Android.mk
src/com/gibsson/basic/service/
app/
BasicServiceApp.java
IBasicServiceImpl.java
lib/
BasicManager.java
com.gibsson.basic.service.lib.xml
IBasicService.aidl
39
Accessing HW on Android Custom System Service
AIDL EXAMPLE
1 /**
2 * System-private API for talking to the BasicService.
3 *
4 * {@hide}
5 */
6 interface IBasicService {
7 int getValue();
8 int setValue(int val);
9 }
40
Accessing HW on Android Custom System Service
WRAPPER CLASS EXAMPLE
1 public class BasicManager {
2 private static final String REMOTE_SERVICE_NAME = IBasicService
.class.getName();
3 private final IBasicService service;
4
5 public static BasicManager getInstance() {
6 return new BasicManager();
7 }
8
9 private BasicManager() {
10 this.service = IBasicService.Stub.asInterface(ServiceManager.
getService(REMOTE_SERVICE_NAME));
11 if (this.service == null) {
12 throw new IllegalStateException("Failed to find
IBasicService by name [" + REMOTE_SERVICE_NAME + "]");
13 }
14 }
15 [...]
16 }
41
Accessing HW on Android Custom System Service
IMPLEMENTATION EXAMPLE
1 class IBasicServiceImpl extends IBasicService.Stub {
2 private final Context context;
3 private int value;
4
5 IBasicServiceImpl(Context context) {
6 this.context = context;
7 }
8 protected void finalize() throws Throwable {
9 super.finalize();
10 }
11 public int getValue() {
12 return value;
13 }
14 public int setValue(int val) {
15 value = val + 4;
16 return 0;
17 }
18 }
42
Accessing HW on Android Custom System Service
IMPLEMENTATION APP EXAMPLE
1 public class BasicServiceApp extends Application {
2 private static final String REMOTE_SERVICE_NAME = IBasicService
.class.getName();
3 private IBasicServiceImpl serviceImpl;
4
5 public void onCreate() {
6 super.onCreate();
7 this.serviceImpl = new IBasicServiceImpl(this);
8 ServiceManager.addService(REMOTE_SERVICE_NAME, this.
serviceImpl);
9 }
10
11 public void onTerminate() {
12 super.onTerminate();
13 }
14 }
43
Demonstrations
Accessing HW on Android Demonstrations
HARDWARE SELECTION
• i.MX6Q SabreLite
• Android 4.3 Jelly Bean
• 10" LVDS display
• Could be any other device
45
Accessing HW on Android Demonstrations
DEMONSTRATIONS
• Demonstration #1
Native app access
• Demonstration #2
Direct JNI access
• Demonstration #3
Using Sensor API
• Demonstration #4
Custom System Service
46
Conclusion
Accessing HW on Android Conclusion
CONCLUSION
• Direct access from application
Permission issue
• HAL modification
Only few hardware targeted
• Adding a System Service
Most complex but elegant way
• Solution depends on constraints
48
Accessing HW on Android Conclusion
QUESTIONS?
49
Accessing HW on Android Conclusion
REFERENCES
• Karim Yaghmour: Embedded Android
http://shop.oreilly.com/product/0636920021094.do
• Karim Yaghmour: Extending Android HAL
http://www.opersys.com/blog/extending-android-hal
• Marko Gargenta: Remixing Android
https://thenewcircle.com/s/post/1044/remixing_android
• Lars Vogel: Android Sensors
http://www.vogella.com/tutorials/AndroidSensor/article.html
50

Contenu connexe

Tendances

Embedded Android Workshop with Pie
Embedded Android Workshop with PieEmbedded Android Workshop with Pie
Embedded Android Workshop with PieOpersys inc.
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsLinaro
 
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.
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System ServerOpersys inc.
 
Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)Xavier Hallade
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesChris Simmonds
 
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.
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessNanik Tolaram
 
Understanding binder in android
Understanding binder in androidUnderstanding binder in android
Understanding binder in androidHaifeng Li
 
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
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android WorkshopOpersys inc.
 
Android Storage - Vold
Android Storage - VoldAndroid Storage - Vold
Android Storage - VoldWilliam Lee
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time OptimizationKan-Ru Chen
 

Tendances (20)

Embedded Android : System Development - Part IV (Android System Services)
Embedded Android : System Development - Part IV (Android System Services)Embedded Android : System Development - Part IV (Android System Services)
Embedded Android : System Development - Part IV (Android System Services)
 
Embedded Android Workshop with Pie
Embedded Android Workshop with PieEmbedded Android Workshop with Pie
Embedded Android Workshop with Pie
 
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)
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new Platforms
 
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
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System Server
 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
 
Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)
 
Embedded Android : System Development - Part IV
Embedded Android : System Development - Part IVEmbedded Android : System Development - Part IV
Embedded Android : System Development - Part IV
 
Porting Android
Porting AndroidPorting Android
Porting Android
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot images
 
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...
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting Process
 
Understanding binder in android
Understanding binder in androidUnderstanding binder in android
Understanding binder in android
 
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
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android Workshop
 
Android Storage - Vold
Android Storage - VoldAndroid Storage - Vold
Android Storage - Vold
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time Optimization
 

Similaire à Accessing Hardware on Android

lecture-2-android-dev.pdf
lecture-2-android-dev.pdflecture-2-android-dev.pdf
lecture-2-android-dev.pdfjakjak36
 
Android development tutorial
Android development tutorialAndroid development tutorial
Android development tutorialMohammad Taj
 
Android development tutorial
Android development tutorialAndroid development tutorial
Android development tutorialnazzf
 
3. Android Architecture.pptx
3. Android Architecture.pptx3. Android Architecture.pptx
3. Android Architecture.pptxHarshiniB11
 
Android Applications Development: A Quick Start Guide
Android Applications Development: A Quick Start GuideAndroid Applications Development: A Quick Start Guide
Android Applications Development: A Quick Start GuideSergii Zhuk
 
AWS Summit Singapore 2019 | Latest Trends for Cloud-Native Application Develo...
AWS Summit Singapore 2019 | Latest Trends for Cloud-Native Application Develo...AWS Summit Singapore 2019 | Latest Trends for Cloud-Native Application Develo...
AWS Summit Singapore 2019 | Latest Trends for Cloud-Native Application Develo...AWS Summits
 
Android development classes in chandigarh : Big Boxx Academy
Android development classes in chandigarh : Big Boxx AcademyAndroid development classes in chandigarh : Big Boxx Academy
Android development classes in chandigarh : Big Boxx AcademyBig Boxx Animation Academy
 
Introduction to android sessions new
Introduction to android   sessions newIntroduction to android   sessions new
Introduction to android sessions newJoe Jacob
 
Android dev o_auth
Android dev o_authAndroid dev o_auth
Android dev o_authlzongren
 
Zeelogic android-training-2013
Zeelogic android-training-2013Zeelogic android-training-2013
Zeelogic android-training-2013Zeelogic Solu
 
Developing for Android-Types of Android Application
Developing for Android-Types of Android ApplicationDeveloping for Android-Types of Android Application
Developing for Android-Types of Android ApplicationNandini Prabhu
 
Android In A Nutshell
Android In A NutshellAndroid In A Nutshell
Android In A NutshellTed Chien
 
Manish Chasta - Securing Android Applications
Manish Chasta - Securing Android ApplicationsManish Chasta - Securing Android Applications
Manish Chasta - Securing Android ApplicationsPositive Hack Days
 
Getting started with the NDK
Getting started with the NDKGetting started with the NDK
Getting started with the NDKKirill Kounik
 
Android Overview
Android OverviewAndroid Overview
Android OverviewRaju Kadam
 

Similaire à Accessing Hardware on Android (20)

lecture-2-android-dev.pdf
lecture-2-android-dev.pdflecture-2-android-dev.pdf
lecture-2-android-dev.pdf
 
Notes Unit2.pptx
Notes Unit2.pptxNotes Unit2.pptx
Notes Unit2.pptx
 
Android development tutorial
Android development tutorialAndroid development tutorial
Android development tutorial
 
Android development tutorial
Android development tutorialAndroid development tutorial
Android development tutorial
 
3. Android Architecture.pptx
3. Android Architecture.pptx3. Android Architecture.pptx
3. Android Architecture.pptx
 
Android Applications Development: A Quick Start Guide
Android Applications Development: A Quick Start GuideAndroid Applications Development: A Quick Start Guide
Android Applications Development: A Quick Start Guide
 
AWS Summit Singapore 2019 | Latest Trends for Cloud-Native Application Develo...
AWS Summit Singapore 2019 | Latest Trends for Cloud-Native Application Develo...AWS Summit Singapore 2019 | Latest Trends for Cloud-Native Application Develo...
AWS Summit Singapore 2019 | Latest Trends for Cloud-Native Application Develo...
 
Android development classes in chandigarh : Big Boxx Academy
Android development classes in chandigarh : Big Boxx AcademyAndroid development classes in chandigarh : Big Boxx Academy
Android development classes in chandigarh : Big Boxx Academy
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
Introduction to android sessions new
Introduction to android   sessions newIntroduction to android   sessions new
Introduction to android sessions new
 
Android dev o_auth
Android dev o_authAndroid dev o_auth
Android dev o_auth
 
Zeelogic android-training-2013
Zeelogic android-training-2013Zeelogic android-training-2013
Zeelogic android-training-2013
 
Developing for Android-Types of Android Application
Developing for Android-Types of Android ApplicationDeveloping for Android-Types of Android Application
Developing for Android-Types of Android Application
 
Android zensar
Android zensarAndroid zensar
Android zensar
 
Android In A Nutshell
Android In A NutshellAndroid In A Nutshell
Android In A Nutshell
 
Android session-1-sajib
Android session-1-sajibAndroid session-1-sajib
Android session-1-sajib
 
Manish Chasta - Securing Android Applications
Manish Chasta - Securing Android ApplicationsManish Chasta - Securing Android Applications
Manish Chasta - Securing Android Applications
 
Getting started with the NDK
Getting started with the NDKGetting started with the NDK
Getting started with the NDK
 
Android Overview
Android OverviewAndroid Overview
Android Overview
 
Android - Anroid Pproject
Android - Anroid PprojectAndroid - Anroid Pproject
Android - Anroid Pproject
 

Plus de Gary Bisson

FTF2014 - Android Accessory Protocol
FTF2014 - Android Accessory ProtocolFTF2014 - Android Accessory Protocol
FTF2014 - Android Accessory ProtocolGary Bisson
 
Android OTA updates
Android OTA updatesAndroid OTA updates
Android OTA updatesGary Bisson
 
Headless Android Strikes Back!
Headless Android Strikes Back!Headless Android Strikes Back!
Headless Android Strikes Back!Gary Bisson
 
Quickboot on i.MX6
Quickboot on i.MX6Quickboot on i.MX6
Quickboot on i.MX6Gary Bisson
 
Leveraging the Android Open Accessory Protocol
Leveraging the Android Open Accessory ProtocolLeveraging the Android Open Accessory Protocol
Leveraging the Android Open Accessory ProtocolGary Bisson
 
Useful USB Gadgets on Linux
Useful USB Gadgets on LinuxUseful USB Gadgets on Linux
Useful USB Gadgets on LinuxGary Bisson
 

Plus de Gary Bisson (6)

FTF2014 - Android Accessory Protocol
FTF2014 - Android Accessory ProtocolFTF2014 - Android Accessory Protocol
FTF2014 - Android Accessory Protocol
 
Android OTA updates
Android OTA updatesAndroid OTA updates
Android OTA updates
 
Headless Android Strikes Back!
Headless Android Strikes Back!Headless Android Strikes Back!
Headless Android Strikes Back!
 
Quickboot on i.MX6
Quickboot on i.MX6Quickboot on i.MX6
Quickboot on i.MX6
 
Leveraging the Android Open Accessory Protocol
Leveraging the Android Open Accessory ProtocolLeveraging the Android Open Accessory Protocol
Leveraging the Android Open Accessory Protocol
 
Useful USB Gadgets on Linux
Useful USB Gadgets on LinuxUseful USB Gadgets on Linux
Useful USB Gadgets on Linux
 

Dernier

Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfsumitt6_25730773
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Ramkumar k
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"mphochane1998
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdfAldoGarca30
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxMuhammadAsimMuhammad6
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksMagic Marks
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxmaisarahman1
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxpritamlangde
 

Dernier (20)

Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 

Accessing Hardware on Android

  • 1. Accessing Hardware on Android FTF2014 04/08/2014 Gary Bisson Embedded Software Engineer
  • 2. SESSION OVERVIEW 1. Introduction 2. Native Development 3. Direct Access 4. Android HAL Layer 5. Custom System Service 6. Demonstrations 7. Conclusion
  • 3. ABOUT THE PRESENTER • Embedded Software Engineer at Adeneo Embedded (Bellevue, WA) Linux / Android ♦ BSP Adaptation ♦ Driver Development ♦ System Integration Partners with Freescale
  • 5. Accessing HW on Android Introduction ACCESSING THE HARDWARE • How different from a GNU/Linux system? No difference for native dev What about Java applications? • Android Architecture Android API SDK/NDK 5
  • 6. Accessing HW on Android Introduction ANDROID ARCHITECTURE 6
  • 7. Accessing HW on Android Introduction ACCESSING THE HARDWARE Different ways of accessing devices from Android applications: • Direct access from the application Either in the Java or JNI layer • Using the available Android hardware API HAL adaptation • Adding a custom System Service API modification 7
  • 9. Accessing HW on Android Native Development WHAT IS IT? • Different from JNI/NDK The word “native” in the NDK can be misleading as it still involves all the limitations of Java applications NDK gives you access only to a very limited subset of the Android API • Native application/daemon/library: can be run directly on the system without the full Java stack 9
  • 10. Accessing HW on Android Native Development NATIVE APPLICATION • Can be built statically Avoids libc issues Not preferred solution though • Can be built against Bionic Every binary/library in Android Some adaptation may be required 10
  • 11. Accessing HW on Android Native Development BIONIC VS. GLIBC • C++ No exception handling! No STL! (Standard Template Library) • Libpthread Mutexes, condvars, etc. use Linux futexes No semaphores No pthread_cancel • Misc No wchar_t and no LOCALE support No crypt() 11
  • 12. Accessing HW on Android Native Development BUILD A NATIVE APPLICATION • Such applications can be found in AOSP: system/core/ frameworks/base/cmds/ external/ • Same as a Java application, an Android.mk must be created: 1 LOCAL_PATH:= $(call my-dir) 2 include $(CLEAR_VARS) 3 LOCAL_MODULE := hello-world 4 LOCAL_MODULE_TAGS := optional 5 LOCAL_SRC_FILES := hello-world.cpp 6 LOCAL_SHARED_LIBRARIES := liblog 7 include $(BUILD_EXECUTABLE) 12
  • 13. Accessing HW on Android Native Development ADD A NATIVE APPLICATION • If LOCAL_MODULE_TAGS is set as optional, the package name must be registered in the device.mk • Once built, the binary is copied to <out_folder>/system/bin • Modify init.rc to start the application at startup: 1 service myapp /system/bin/myapp 2 oneshot 13
  • 15. Accessing HW on Android Direct Access ACCESSING THE HARDWARE • Using the user-space interface (devfs, sysfs...) Can be done either in Java or in Native C code Simple Open / Read / Write / Close to a “file” Every application that uses a specific hardware must have code to handle it • The correct permissions must be set The device node shall be opened by all users (not allowed by default) or by the UID/GID of the relevant application(s) init.rc or eventd.rc must be modified 15
  • 16. Accessing HW on Android Direct Access JAVA SAMPLE CODE 1 private void turnOnLed () throws IOException { 2 FileInputStream fileInputStream; 3 FileOutputStream fileOutputStream; 4 File file = new File("/sys/class/leds/led_usr1/brightness"); 5 if (file.canRead()) { 6 fileInputStream = new FileInputStream(file); 7 if (fileInputStream.read() != '0') { 8 System.out.println("LED usr1 already onn"); 9 return; 10 } 11 } 12 if (file.canWrite()) { 13 fileOutputStream = new FileOutputStream(file); 14 fileOutputStream.write('1'); 15 } 16 } 16
  • 18. Accessing HW on Android Android HAL Layer HARDWARE API • Android Hardware API is accessed through the android.hardware class. • This class only provides support for a limited number of devices such as: Camera: used to set image capture settings, start/stop preview, snap pictures, and retrieve frames for encoding for video Sensors: accelerometer, gyroscope, magnetometers, proximity, temperature... • OEMs may provide their own HAL implementation to connect to the android hardware API (see hardware/imx) 18
  • 19. Accessing HW on Android Android HAL Layer HARDWARE API • USB Host and Accessory: android.hardware.usb: Provides support to communicate with USB hardware peripherals that are connected to Android-powered devices • Input: android.hardware.input Provides information about input devices and available key layouts New in API Level 16 (Jelly Bean) • Other APIs: For instance the android.app.Notification can be used to toggle a LED (if properly registered) with the FLAG_SHOW_LIGHTS parameter 19
  • 20. Accessing HW on Android Android HAL Layer HARDWARE ABSTRACTION LAYER (HAL) 20
  • 21. Accessing HW on Android Android HAL Layer LIGHTS LIBRARY • Interface defined in hardware/libhardware/include/hardware/lights.h • Library must be named lights.<product_name>.so • Will get loaded from /system/lib/hw at runtime • See example in hardware/imx/lights/ • Mandatory to have backlight managed by the OS. 21
  • 22. Accessing HW on Android Android HAL Layer CAMERA LIBRARY • Interface defined in hardware/libhardware/include/hardware/camera.h • Library must be named camera.<product_name>.so • Will get loaded from /system/lib/hw at runtime • See example in hardware/imx/mx6/libcamera/ 22
  • 23. Accessing HW on Android Android HAL Layer GPS LIBRARY • Interface defined in hardware/libhardware/include/hardware/gps.h • Library must be named gps.<product_name>.so • Will get loaded from /system/lib/hw at runtime • See example in hardware/imx/libgps/ 23
  • 24. Accessing HW on Android Android HAL Layer SENSORS LIBRARY • Interface defined in hardware/libhardware/include/hardware/sensors.h • Library must be named sensors.<product_name>.so • Will get loaded from /system/lib/hw at runtime • See example in hardware/imx/libsensors/ 24
  • 25. Accessing HW on Android Android HAL Layer EXAMPLE: ADDING A SENSOR 1. Kernel driver must be working and loaded 2. Change directory to hardware/imx/libsensors 3. Add Sensor definition into sSensorList structure in sensors.cpp Applications will now be aware of a new sensor This structure define the following parameters ♦ Name ♦ Vendor ♦ Version ♦ Type (Proximity, Temperature etc…) ♦ ... 25
  • 26. Accessing HW on Android Android HAL Layer EXAMPLE: ADDING A SENSOR 4. Create object of new sensor Set file descriptor and event type 5. Update sensors_poll_context_t structure 6. Add new sensor case to handleToDriver function 7. Implement your class: 1 class AccelSensor : public SensorBase { 2 int mEnabled; 3 int setInitialState(); 4 public: 5 AccelSensor(); 6 virtual ~AccelSensor(); 7 virtual int readEvents(sensors_event_t* data, int cnt); 8 virtual bool hasPendingEvents() const; 9 virtual int enable(int32_t handle, int enabled); 10 }; 26
  • 27. Accessing HW on Android Android HAL Layer EXAMPLE: TESTING A SENSOR • Use existing tool: hardware/libhardware/tests/nusensors This binary tool will list every sensor and try to pull data from it • Use existing java application: AndroSensor www.appsapk.com/androsensor • Create your own application Using SensorManager www.vogella.com/tutorials/AndroidSensor/article.html 27
  • 28. Accessing HW on Android Android HAL Layer EXAMPLE: SENSOR MANAGER 1 public class SensorActivity extends Activity, implements SensorEventListener { 2 private final SensorManager mSensorManager; 3 private final Sensor mAccelerometer; 4 public SensorActivity() { 5 mSensorManager = (SensorManager)getSystemService( SENSOR_SERVICE); 6 mAccelerometer = mSensorManager.getDefaultSensor(Sensor. TYPE_ACCELEROMETER); 7 } 8 protected void onResume() { 9 super.onResume(); 10 mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL); 11 } 12 [...] 13 public void onAccuracyChanged(Sensor sensor, int accuracy) {} 14 public void onSensorChanged(SensorEvent event) {} 15 } 28
  • 30. Accessing HW on Android Custom System Service ANDROID SYSTEM SERVICES • Service: component that performs long-running operations in the background and does not provide a user interface • System Services vs. Local Service System Services accessible for all Access through getSystemService() method Permissions required 30
  • 31. Accessing HW on Android Custom System Service ANDROID SYSTEM SERVICES 31
  • 32. Accessing HW on Android Custom System Service MAIN SYSTEM SERVICES • System Server All components contained in one process: system_server Mostly made up of Java-coded services with few written in C/C++ • Media Server All components contained in one process: media-server These services are all coded in C/C++ • Appear to operate independently to anyone connecting to them through Binder 32
  • 33. Accessing HW on Android Custom System Service ANDROID SYSTEM SERVICES 33
  • 34. Accessing HW on Android Custom System Service SERVICE MANAGER • Service Manager = YellowPages book of all services • Need to register every System Service to be usable • Can list all services available: service list • Application asks the Service Manager for a handle to the Service and then invokes that service's methods 34
  • 35. Accessing HW on Android Custom System Service ADDING A SYSTEM SERVICE 1. Creation of the API layer for the System Service (aidl) Defines only exposed methods API added to SDK/add-on 2. Creation of a wrapper class for the Service interface 3. Creation of an implementation of that class 4. Creation of a JNI layer if needed 35
  • 36. Accessing HW on Android Custom System Service ADDING A SYSTEM SERVICE 1st approach: • System Service inside the System Server • Advantages: Part of the inner system First to be started System permissions • Drawbacks: SDK creation required 36
  • 37. Accessing HW on Android Custom System Service ADDING A SYSTEM SERVICE 2nd approach: • System Service outside of the System Server • Advantages: No framework/ modification Located in one folder Easier to port from one version to another System permissions SDK add-on • Drawbacks: Considered as a usual App ♦ System might remove it in case it runs out of RAM 37
  • 38. Accessing HW on Android Custom System Service ADDING A SYSTEM SERVICE • Example: https://github.com/gibsson/BasicService https://github.com/gibsson/BasicClient • Although SDK generation is possible, SDK add-on is preferred: https://github.com/gibsson/basic_sdk_addon 38
  • 39. Accessing HW on Android Custom System Service BASIC SERVICE EXAMPLE BasicService/ AndroidManifest.xml Android.mk src/com/gibsson/basic/service/ app/ BasicServiceApp.java IBasicServiceImpl.java lib/ BasicManager.java com.gibsson.basic.service.lib.xml IBasicService.aidl 39
  • 40. Accessing HW on Android Custom System Service AIDL EXAMPLE 1 /** 2 * System-private API for talking to the BasicService. 3 * 4 * {@hide} 5 */ 6 interface IBasicService { 7 int getValue(); 8 int setValue(int val); 9 } 40
  • 41. Accessing HW on Android Custom System Service WRAPPER CLASS EXAMPLE 1 public class BasicManager { 2 private static final String REMOTE_SERVICE_NAME = IBasicService .class.getName(); 3 private final IBasicService service; 4 5 public static BasicManager getInstance() { 6 return new BasicManager(); 7 } 8 9 private BasicManager() { 10 this.service = IBasicService.Stub.asInterface(ServiceManager. getService(REMOTE_SERVICE_NAME)); 11 if (this.service == null) { 12 throw new IllegalStateException("Failed to find IBasicService by name [" + REMOTE_SERVICE_NAME + "]"); 13 } 14 } 15 [...] 16 } 41
  • 42. Accessing HW on Android Custom System Service IMPLEMENTATION EXAMPLE 1 class IBasicServiceImpl extends IBasicService.Stub { 2 private final Context context; 3 private int value; 4 5 IBasicServiceImpl(Context context) { 6 this.context = context; 7 } 8 protected void finalize() throws Throwable { 9 super.finalize(); 10 } 11 public int getValue() { 12 return value; 13 } 14 public int setValue(int val) { 15 value = val + 4; 16 return 0; 17 } 18 } 42
  • 43. Accessing HW on Android Custom System Service IMPLEMENTATION APP EXAMPLE 1 public class BasicServiceApp extends Application { 2 private static final String REMOTE_SERVICE_NAME = IBasicService .class.getName(); 3 private IBasicServiceImpl serviceImpl; 4 5 public void onCreate() { 6 super.onCreate(); 7 this.serviceImpl = new IBasicServiceImpl(this); 8 ServiceManager.addService(REMOTE_SERVICE_NAME, this. serviceImpl); 9 } 10 11 public void onTerminate() { 12 super.onTerminate(); 13 } 14 } 43
  • 45. Accessing HW on Android Demonstrations HARDWARE SELECTION • i.MX6Q SabreLite • Android 4.3 Jelly Bean • 10" LVDS display • Could be any other device 45
  • 46. Accessing HW on Android Demonstrations DEMONSTRATIONS • Demonstration #1 Native app access • Demonstration #2 Direct JNI access • Demonstration #3 Using Sensor API • Demonstration #4 Custom System Service 46
  • 48. Accessing HW on Android Conclusion CONCLUSION • Direct access from application Permission issue • HAL modification Only few hardware targeted • Adding a System Service Most complex but elegant way • Solution depends on constraints 48
  • 49. Accessing HW on Android Conclusion QUESTIONS? 49
  • 50. Accessing HW on Android Conclusion REFERENCES • Karim Yaghmour: Embedded Android http://shop.oreilly.com/product/0636920021094.do • Karim Yaghmour: Extending Android HAL http://www.opersys.com/blog/extending-android-hal • Marko Gargenta: Remixing Android https://thenewcircle.com/s/post/1044/remixing_android • Lars Vogel: Android Sensors http://www.vogella.com/tutorials/AndroidSensor/article.html 50