This article was reproduced from: http://blog.csdn.net/tung214/article/details/44461985
Android 5.0, because of the seandroid/selinux security mechanism, even if you have root privileges, or a kernel node set to 777 of the permissions, still cannot be accessed at the JNI layer.
This article will use a user-defined kernel node
/DEV/WF_BTAs an example, hands-on teaches the reader how to gain access to the node in the JNI layer. The first step: find the process that needs to access the kernel node, the author myself This node is accessed by the System_server process for the second step: Open File Androidl/android/external/sepolicy/file_ contexts.be follow the notation in this file to define a name you want for your node:
[Python]View PlainCopy
- /dev/tegra.* U:object_r:video_device:s0
- /dev/tf_driver U:object_r:tee_device:s0
- /dev/tty U:object_r:owntty_device:s0
- /dev/tty[0-9]* u:object_r:tty_device:s0
- # We Add here
- /DEV/WF_BT U:object_r:wf_bt_device:s0
Wf_bt_device is custom, and the other left and right sides of the content are consistent with the example above. The third step: Open the file Androidl/android/external/sepolicy/device.te in the same style as in this file, the second step has just written Wf_bt_device declared as Dev_type:
[Python]View PlainCopy
- # DEVICE TYPES  
- type device, dev_type, fs_type;
- type alarm_device , dev_type, mlstrustedobject;
- type adb_device, dev_type;
- TYPE ASHMEM_DEVICE, DEV_TYPE, MLSTRUSTEDOBJECT;  
- type audio_device, dev_type;
- type binder_device, dev_type, mlstrustedobject;
- type block_device, dev_type;
- # WE ADD HERE  
- type wf_bt_device, dev_type;
Fourth Step: androidl/android/external/sepolicy/ Many. te files in the directory end with the process name, such as Surfaceflinger for the Surfaceflinger process, with Vold.te for the vold process, just from the first step, the node is accessed by the System_server process, So, we find system_server.te open, join to allow this process to read and write permission to/DEV/WF_BT,
[Python]View PlainCopy
- # Read/write To/proc/net/xt_qtaguid/ctrl and And/dev/xt_qtaguid.
- Allow System_server qtaguid_proc:file rw_file_perms;
- Allow System_server qtaguid_device:chr_file rw_file_perms;
- # Chr_file indicates the character device file, if it is a normal file, directory please use Dir
- # rw_file_perms represents read and Write permissions
- Allow System_server wf_bt_device:chr_file rw_file_perms;
This means that the system_server process is allowed to have read and write access to the Wf_bt_device character device. After you change this, you can make installclean;make-j16 compile the image to verify that the permissions are successful. FD =open ("/dev/wf_bt", O_rdonly | O_noctty); ABSOLUTE SUCCESS!!!!! Acknowledgement: Thank Joly_xie
Android 5.x seandroid/selinux kernel node read and Write permissions "learning notes"