1、以/dev/test节点为例,在device/init.rc增加
on boot
//android5.0以下到此即可访问,5.0以上设置2-4步
chmod 777 /dev/test
2、在extern/sepolicy/file_contexts 或/device/sepolicy/file_contexts增加
//设备名:test_device
/dev/test u:object_r:test_device:s0
3、在extern/sepolicy/device.te 增加
//类型:dev_type
//For Android5.1
type test_device, dev_type;
//For Android7.0以上版本:这一attribute包含了所有能越过MLS检查的客体type
type test_device, dev_type,mlstrustedobject;
4、允许系统app访问/dev/test,在extern/sepolicy/system_app.te增加
//访问设备的进程:system_app
allow system_app test_device:chr_file rw_file_perms;
5、编译烧写
# mmm /device/sepolicy
# make ramdisk
6、测试
int fd = open("/dev/test",O_RDONLY);