When I wrote my blog, I found that I jumped to the chapter, and the HAL Hardware Abstraction Layer was not written to JNI. I will complete it here.
 
 
1. Add the Hal header file 
Go to the android-4.0.4_r1.2/hardware/libhardware/include/hardware directory and create the TTT. h file:
 
root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2/hardware/libhardware/include/hardware# gedit ttt.h
 
The file content is as follows:
 
# Ifndefandroid_ttt_interface_h # defineandroid_ttt_interface_h # include <Hardware/hardware. h >__ begin_decls // define module ID # struct "TTT" // hardware module struct ttt_module_t {struct hw_module_t common ;}; // hardware interface structstruct ttt_device_t {struct hw_device_t common; int FD; int (* set_val) (struct ttt_device_t * Dev, int Val); int (* get_val) (struct ttt_device_t * Dev, int * val); };__ end_decls # endif 
According to the requirements of the Android hardware abstraction layer specification, the module ID, module structure, and hardware interface structure are defined respectively.
2. Implement hal 
Go to the android-4.0.4_r1.2/hardware/libhardware/modules directory and create the TTT directory:
 
root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2/hardware/libhardware/modules# mkdir ttt
 
Go to the newly created TTT directory and create the TTT. c file:
 
root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2/hardware/libhardware/modules/ttt# gedit ttt.c
 
The content is as follows:
 
#defineLOG_TAG"TTTStub"#include 
Create the corresponding Android. mk file in this directory:
root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2/hardware/libhardware/modules/ttt# gedit Android.mk
The content is as follows:
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE_TAGS := optionalLOCAL_PRELINK_MODULE := falseLOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hwLOCAL_SHARED_LIBRARIES := liblogLOCAL_SRC_FILES := ttt.cLOCAL_MODULE := ttt.defaultinclude $(BUILD_SHARED_LIBRARY)
 
3. Add Permissions
Because the device files are created in the kernel driver through device_create, the device files created by device_create are only root users by default.
It can be read and written, while ttt_device_open is generally called by upper-layer apps. These apps do not have the root permission. In this case, opening the device file may fail. The prompt is similar:
Permission denied.
The solution is similar to the udev rules of Linux,
Go to the android-4.0.4_r1.2/system/CORE/rootdir directory and open the uenentd. RC file:
root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2/system/core/rootdir# gedit ueventd.rc
Add a sentence:
/dev/ttt                  0666   root       root
4. Start Compilation
Run the following command:
Root @ brantyou-Ubuntu :~ /Workspace/android-4.0.4_r1.2 # Mmm Hardware/libhardware/modules/TTT ====================== ======================== relplatform_version = 4.0.4target _ Product = metric = engtarget_build_type = metric = target_arch = metric = armv7-a-neonHOST_ARCH = x86host_ OS = linuxhost_build_type = releasebuild_id = imm76i ================================ ============ Make: Enter the directory '/home/brantyou/workspace/android-4.0.4_r1.2' target thumb C: TTT. default <= Hardware/libhardware/modules/TTT. ctarget sharedlib: TTT. default (Out/target/product/smdkv210/obj/shared_libraries/TTT. default_intermediates/linked/TTT. default. so) Target symbolic: TTT. default (Out/target/product/smdkv210/symbols/system/lib/HW/TTT. default. so) Target Strip: TTT. default (Out/target/produ CT/smdkv210/obj/lib/TTT. default. so) install: Out/target/product/smdkv210/system/lib/HW/TTT. default. somake: Leave the directory "/home/brantyou/workspace/android-4.0.4_r1.2" root @ brantyou-Ubuntu :~ /Workspace/android-4.0.4_r1.2 #
Repackage system. IMG:
Root @ brantyou-Ubuntu :~ /Workspace/android-4.0.4_r1.2 # Make Snod ==================================== ============ response = relplatform_version = 4.0.4target _ Product = metric = engtarget_build_type = metric = target_arch = metric = armv7-a-neonHOST_ARCH = x86host_ OS = linuxhost_build_type = releasebuild_id = imm76i = ========================================================== = build/CORE/makef Ile: 25: Warning: overwrite the build/CORE/base_rules.mk: 523 command about the target "out/target/product/smdkv210/system/bin/pppd": Warning: ignore the old command make Snod: Ignoring dependenciestarget system FS image: Out/target/product/smdkv210/system/bin/pppd. imgout/target/product/smdkv210/system. IMG total size is 150853824root @ brantyou-Ubuntu :~ /Workspace/android-4.0.4_r1.2 #
 
At this point, the Hal layer has been compiled, and the next article is to compile the corresponding JNI interface.