Android from hardware to application: Step-by-step 4--using the JNI method to tune the hardware driver

Source: Internet
Author: User

Under Android, Java applications invoke the hardware Abstraction Layer module through the Jni method, on Android from hardware to application: Step-by-step 3-Hardware abstraction Layer access hardware driver

We have compiled the hardware Abstraction Layer module, we will begin to write a JNI method for the HAL layer, to provide services for the upper layer.

CD to the Frameworks/base/services/jni directory, create a new Com_android_server_gpioservice.cpp file:

#include "jni.h" #include "JNIHelp.h" #include "android_runtime/androidruntime.h" #include <utils/misc.h> #inclu De <utils/Log.h> #include Where android_gpio_hardware_module_id is defined in hardware/android_gpio.h, the hardware layer module is loaded by the Hw_get_module method during initialization. To modify the onload.cpp in the current directory:

Add a function declaration to namespace Android:

int Register_android_server_gpioservice (jnienv* env);
To add a function call in Jni_onload:

Register_android_server_gpioservice (env);
Modify AndroidRuntime.cpp under Frameworks/base/core/jni to add a statement to namespace Android:

extern int Register_android_server_gpioservice (jnienv* env);

Modify the Android.mk file in the current directory:

Join in Local_src_files:

Com_android_server_gpioservice.cpp \
To compile the Jni method:

Mmm Frameworks/base/services/jni
If the hint is missing libandroid_runtime.so, libsystem_server.so, libandroid_servers.so, execute:

Make Libandroid_runtime

Make Libsystem_server
Make Libandroid_servers
Once the Jni method has been compiled, the JNI method can be invoked via the Android hardware service Gpioservice to invoke the hardware abstraction layer to access the underlying hardware.

Android from hardware to application: Step-by-step 4--using the JNI method to tune the hardware driver

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.