This document discusses various ways to access hardware on Android systems. It begins with an introduction to accessing hardware differently on Android compared to GNU/Linux systems. It then covers direct access from applications, using the Android Hardware Abstraction Layer (HAL), adding a custom system service, and building native applications that can directly access hardware. The document provides code examples for each method.
There is a surge in number of sensors / devices that are getting connected under the umbrella of Internet-Of-Things (IoT). These devices need to be integrated into the Android system and accessed via applications, which is covered in the course. Our Android system development course curriculum over weekends with practicals ensures you learn all critical components to get started.
Embedded Android System Development - Part II talks about Hardware Abstraction Layer (HAL). HAL is an interfacing layer through which Android service can place a request to device. Uses functions provided by Linux system to service the request from android framework. A C/C++ layer with purely vendor specific implementation. Packaged into modules (.so) file & loaded by Android system at appropriate time
Android Audio HAL – Audio Architecture – Audio HAL interface – Audio Policy – Audio HAL compilation & verification – Overview of Tinyalsa
Android Video HAL – Camera Architecture – Overview of camera HAL interface – Overview of V4L2 – Enabling V4l2 in kernel – Camera HAL compilation and verification
Embedded Android system development workshop is focused on integrating new device with Android framework. Our hands-on approach makes Emertxe as the best institute to learn android system development training. This workshop deep dives into Android porting, Android Hardware Abstraction Layer (HAL), Android Services and Linux device driver ecosystem. This workshop based training program will enable you to efficiently integrate new hardware with Android HAL / Framework.
There is a surge in number of sensors / devices that are getting connected under the umbrella of Internet-Of-Things (IoT). These devices need to be integrated into the Android system and accessed via applications, which is covered in the course. Our Android system development course curriculum over weekends with practicals ensures you learn all critical components to get started.
Embedded Android System Development - Part II talks about Hardware Abstraction Layer (HAL). HAL is an interfacing layer through which Android service can place a request to device. Uses functions provided by Linux system to service the request from android framework. A C/C++ layer with purely vendor specific implementation. Packaged into modules (.so) file & loaded by Android system at appropriate time
Android Audio HAL – Audio Architecture – Audio HAL interface – Audio Policy – Audio HAL compilation & verification – Overview of Tinyalsa
Android Video HAL – Camera Architecture – Overview of camera HAL interface – Overview of V4L2 – Enabling V4l2 in kernel – Camera HAL compilation and verification
Embedded Android system development workshop is focused on integrating new device with Android framework. Our hands-on approach makes Emertxe as the best institute to learn android system development training. This workshop deep dives into Android porting, Android Hardware Abstraction Layer (HAL), Android Services and Linux device driver ecosystem. This workshop based training program will enable you to efficiently integrate new hardware with Android HAL / Framework.
Android Things is the latest attempt from Google to connect the dots between the cloud and devices by introducing an OS that is exclusively built for IoT devices. Initially announced as project Brillo, Android Things helps developers to build devices faster and enable them integrate with cloud services. This presentation traces the architectural aspects of Android Things by connecting it back with Embedded Linux, Embedded Android and Brillo.
For new age touch-based embedded devices, Android is becoming a popular OS going beyond mobile phones. With its roots from Embedded Linux, Android framework offers benefits in terms of rich libraries, open-source and multi-device support. Emertxe’s hands-on Embedded Android Training Course is designed to customize, build and deploy custom Embedded OS on ARM target. Rich set of projects will make your learning complete.
Youtube Link: https://youtu.be/DFbhpQpqyuo
** Android Certification Training: https://www.edureka.co/android-development-certification-course **
This Edureka ppt on "Android SDK Tutorial" (Blog Series: http://bit.ly/2MJ6zbc ) will help you understand how Android SDK works.
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in
Slides from Android Builder's Summit 2014 in San Jose, CA
In this talk I describe the internal workings of the Android graphics stack from the Application layer down through the stack to pixels on the screen. It is a fairly complex journey, taking in two different 2D rendering engines, applications calling OpenGL ES directory, passing buffers on to the system compositor, SurfaceFlinger, and then down to the display controller or frame buffer.
Android Things is the latest attempt from Google to connect the dots between the cloud and devices by introducing an OS that is exclusively built for IoT devices. Initially announced as project Brillo, Android Things helps developers to build devices faster and enable them integrate with cloud services. This presentation traces the architectural aspects of Android Things by connecting it back with Embedded Linux, Embedded Android and Brillo.
For new age touch-based embedded devices, Android is becoming a popular OS going beyond mobile phones. With its roots from Embedded Linux, Android framework offers benefits in terms of rich libraries, open-source and multi-device support. Emertxe’s hands-on Embedded Android Training Course is designed to customize, build and deploy custom Embedded OS on ARM target. Rich set of projects will make your learning complete.
Youtube Link: https://youtu.be/DFbhpQpqyuo
** Android Certification Training: https://www.edureka.co/android-development-certification-course **
This Edureka ppt on "Android SDK Tutorial" (Blog Series: http://bit.ly/2MJ6zbc ) will help you understand how Android SDK works.
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in
Slides from Android Builder's Summit 2014 in San Jose, CA
In this talk I describe the internal workings of the Android graphics stack from the Application layer down through the stack to pixels on the screen. It is a fairly complex journey, taking in two different 2D rendering engines, applications calling OpenGL ES directory, passing buffers on to the system compositor, SurfaceFlinger, and then down to the display controller or frame buffer.
Android Apps Development Classes in Chandigarh. We at Big Boxx Academy Chandigarh providing 100% job oriented course and industrial Training in Android apps Development in Chandigarh
For More information call us at : +91 8427023322 | 0172-4612244
Website : www.bigboxx.in
This presentation gives detailed overview of Android, Android Architecture, Software Stack, Platform, Database Support, Licensing, File System, Network Connectivity, Security and Permissions, IDE and Tools, Other IDEs Overview, Development Evaluation, Singing your application, Versioning your application, Preparing to publish your application, Publish your App on Android Market. This presentation also includes links to sample exampled.
Note: Few slides from this presentation are taken from internet or slideshare.com as it is or modified little bit. I have no intention of saying someone’s else work as mine. I prepared this presentation to just educate co-workers about android. So I want the best material from internet and slideshare.com.
This Presentation will give u information about Android :
1. Working with resources- String resource,
2. Color resource,
3. Array resource Android layouts and views Handling user interaction events Grouping,
4. accessing of resources Localization of Resources Handling runtime changes of resources Designing your GUI
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSveerababupersonal22
It consists of cw radar and fmcw radar ,range measurement,if amplifier and fmcw altimeterThe CW radar operates using continuous wave transmission, while the FMCW radar employs frequency-modulated continuous wave technology. Range measurement is a crucial aspect of radar systems, providing information about the distance to a target. The IF amplifier plays a key role in signal processing, amplifying intermediate frequency signals for further analysis. The FMCW altimeter utilizes frequency-modulated continuous wave technology to accurately measure altitude above a reference point.
Cosmetic shop management system project report.pdfKamal Acharya
Buying new cosmetic products is difficult. It can even be scary for those who have sensitive skin and are prone to skin trouble. The information needed to alleviate this problem is on the back of each product, but it's thought to interpret those ingredient lists unless you have a background in chemistry.
Instead of buying and hoping for the best, we can use data science to help us predict which products may be good fits for us. It includes various function programs to do the above mentioned tasks.
Data file handling has been effectively used in the program.
The automated cosmetic shop management system should deal with the automation of general workflow and administration process of the shop. The main processes of the system focus on customer's request where the system is able to search the most appropriate products and deliver it to the customers. It should help the employees to quickly identify the list of cosmetic product that have reached the minimum quantity and also keep a track of expired date for each cosmetic product. It should help the employees to find the rack number in which the product is placed.It is also Faster and more efficient way.
Overview of the fundamental roles in Hydropower generation and the components involved in wider Electrical Engineering.
This paper presents the design and construction of hydroelectric dams from the hydrologist’s survey of the valley before construction, all aspects and involved disciplines, fluid dynamics, structural engineering, generation and mains frequency regulation to the very transmission of power through the network in the United Kingdom.
Author: Robbie Edward Sayers
Collaborators and co editors: Charlie Sims and Connor Healey.
(C) 2024 Robbie E. Sayers
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)MdTanvirMahtab2
This presentation is about the working procedure of Shahjalal Fertilizer Company Limited (SFCL). A Govt. owned Company of Bangladesh Chemical Industries Corporation under Ministry of Industries.
Forklift Classes Overview by Intella PartsIntella Parts
Discover the different forklift classes and their specific applications. Learn how to choose the right forklift for your needs to ensure safety, efficiency, and compliance in your operations.
For more technical information, visit our website https://intellaparts.com
Welcome to WIPAC Monthly the magazine brought to you by the LinkedIn Group Water Industry Process Automation & Control.
In this month's edition, along with this month's industry news to celebrate the 13 years since the group was created we have articles including
A case study of the used of Advanced Process Control at the Wastewater Treatment works at Lleida in Spain
A look back on an article on smart wastewater networks in order to see how the industry has measured up in the interim around the adoption of Digital Transformation in the Water Industry.
Hierarchical Digital Twin of a Naval Power SystemKerry Sado
A hierarchical digital twin of a Naval DC power system has been developed and experimentally verified. Similar to other state-of-the-art digital twins, this technology creates a digital replica of the physical system executed in real-time or faster, which can modify hardware controls. However, its advantage stems from distributing computational efforts by utilizing a hierarchical structure composed of lower-level digital twin blocks and a higher-level system digital twin. Each digital twin block is associated with a physical subsystem of the hardware and communicates with a singular system digital twin, which creates a system-level response. By extracting information from each level of the hierarchy, power system controls of the hardware were reconfigured autonomously. This hierarchical digital twin development offers several advantages over other digital twins, particularly in the field of naval power systems. The hierarchical structure allows for greater computational efficiency and scalability while the ability to autonomously reconfigure hardware controls offers increased flexibility and responsiveness. The hierarchical decomposition and models utilized were well aligned with the physical twin, as indicated by the maximum deviations between the developed digital twin hierarchy and the hardware.
Student information management system project report ii.pdfKamal Acharya
Our project explains about the student management. This project mainly explains the various actions related to student details. This project shows some ease in adding, editing and deleting the student details. It also provides a less time consuming process for viewing, adding, editing and deleting the marks of the students.
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Dr.Costas Sachpazis
Terzaghi's soil bearing capacity theory, developed by Karl Terzaghi, is a fundamental principle in geotechnical engineering used to determine the bearing capacity of shallow foundations. This theory provides a method to calculate the ultimate bearing capacity of soil, which is the maximum load per unit area that the soil can support without undergoing shear failure. The Calculation HTML Code included.
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdffxintegritypublishin
Advancements in technology unveil a myriad of electrical and electronic breakthroughs geared towards efficiently harnessing limited resources to meet human energy demands. The optimization of hybrid solar PV panels and pumped hydro energy supply systems plays a pivotal role in utilizing natural resources effectively. This initiative not only benefits humanity but also fosters environmental sustainability. The study investigated the design optimization of these hybrid systems, focusing on understanding solar radiation patterns, identifying geographical influences on solar radiation, formulating a mathematical model for system optimization, and determining the optimal configuration of PV panels and pumped hydro storage. Through a comparative analysis approach and eight weeks of data collection, the study addressed key research questions related to solar radiation patterns and optimal system design. The findings highlighted regions with heightened solar radiation levels, showcasing substantial potential for power generation and emphasizing the system's efficiency. Optimizing system design significantly boosted power generation, promoted renewable energy utilization, and enhanced energy storage capacity. The study underscored the benefits of optimizing hybrid solar PV panels and pumped hydro energy supply systems for sustainable energy usage. Optimizing the design of solar PV panels and pumped hydro energy supply systems as examined across diverse climatic conditions in a developing country, not only enhances power generation but also improves the integration of renewable energy sources and boosts energy storage capacities, particularly beneficial for less economically prosperous regions. Additionally, the study provides valuable insights for advancing energy research in economically viable areas. Recommendations included conducting site-specific assessments, utilizing advanced modeling tools, implementing regular maintenance protocols, and enhancing communication among system components.
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
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
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
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