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

Source: Internet
Author: User

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 to hardware drivers

We have compiled the hardware Abstraction Layer module, the following will start to write a Jni method for the HAL layer to provide services for the upper layer.

CD to the Frameworks/base/services/jni folder, 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 The gpio_hardware_module_id is defined in hardware/gpio.h and is loaded into the hardware layer module at initialization time by means of the Hw_get_module method. Change the onload.cpp under the current folder:

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);
Change Frameworks/base/core/jni under AndroidRuntime.cpp, add a statement to namespace Android:

extern int Register_android_server_gpioservice (jnienv* env);

Change the Android.mk file under the Services/jni folder:

Increase in Local_src_files:

Com_android_server_gpioservice.cpp \
To compile the Jni method:

Make Target_product=am335xevm_sk-j8 omapes=4.x

If successful, the libandroid_servers.so is generated

Out/target/product/am335xevm_sk/obj/lib/libandroid_servers.so  

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

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.