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