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