安卓添加设备节点权限和selinux访问权限

1 修改设备节点权限及配置属性设置节点值

1.1 修改设备节点权限

1.1.1 不会手动卸载的节点

在system/core/rootdir/init.rc中添加节点权限

在on boot下面添加

cpp 复制代码
chown system system /sys/kernel/usb/host
chmod 0664 /sys/kernel/usb/host

1.1.2 支持热插拔的节点(设备移除后,节点会删除)

在system/core/rootdir/ueventd.rc中添加

cpp 复制代码
/dev/ttyUSB*              0666   system     system

1.2 配置属性设置节点值

cpp 复制代码
# on property:sys.boot_completed=1 表示开机完成
# persist.sys.oem.usb_host=*表示随便写入什么值
on property:sys.boot_completed=1 && property:persist.sys.oem.usb_host=*
   write /sys/kernel/usb/host ${persist.sys.oem.usb_host}

2 添加selinux访问权限

2.1 权限报错和添加方法

cpp 复制代码
修改se权限 编译
avc: denied { write } for comm="init" name="disable_charging_screen" dev="sysfs" ino=86923 scontext=u:r:init:s0 tcontext=u:object_r:vendor_sysfs_oem:s0 tclass=file permissive=
缺少什么权限:     { read }权限,
谁缺少权限:        scontext=u:r:hal_secure_element_unisoc:s0 
对哪个文件缺少权限:tcontext=u:object_r:hwservicemanager_prop
什么类型的文件:  tclass=file 
完整的意思: hal_secure_element_unisoc进程对hwservicemanager_prop类型的file缺少read 权限。
allow  hal_secure_element_unisoc hwservicemanager_prop:file  read;
allow init vendor_sysfs_oem:file { open read getattr execute write};

	export SELINUX_IGNORE_NEVERALLOWS=true
	make -j128 selinux_policy
	最后push目录system/etc/selinux(修改system/sepolicy下的权限) 或者 vendor/etc/selinux(修改device下的权限)到设备

2.2 权限添加的位置

cpp 复制代码
# mtk平台添加权限的位置:
device/mediatek/sepolicy/basic/non_plat

# 高通添加的位置:
device/qcom

添加的权限内容:
file.te中添加:type oem_device, fs_type, sysfs_type;
file_contexts中添加:/sys/kernel/usb/host                                 u:object_r:oem_device:s0
init.te中添加:
allow init oem_device:file w_file_perms;
allow init oem_device:file {open write read };
allow init oem_device:fd {use};
相关推荐
百度搜知知学社7 分钟前
一键装裱照片,相框APP内置滤镜与贴纸编辑器
android·编辑器·滤镜·图片编辑·贴纸·相框
AFinalStone1 小时前
Android12 U盘插拔链路源码全解析(四):Framework层(上) —— UsbHostManager
android·frameworks
qq3621967051 小时前
第三方安卓应用商店安全评测 2026:Appteka、Aptoide、APKPure 等 7 家横评
android·网络·人工智能·安全·chatgpt·智能手机
coderhuo2 小时前
JibarOS 简介:Android AICore 开源实现方案
android·ai编程
故渊at2 小时前
第十五板块:Android 系统调试与逆向工程 | 第三十六篇:Smali 字节码语义与 Dalvik 指令集
android·指令集·dalvik·smali·字节码语义
J2虾虾2 小时前
Android支持Java语言的标准
android·java·开发语言
charlee442 小时前
Unity在安卓端如何调试输出信息
android·unity·adb·游戏引擎·真机调试
法欧特斯卡雷特2 小时前
从 Kotlin 编译器 API 的变化开始: 2.4.0
android·开源·github
贾艺驰2 小时前
实战Android Framework: 新增一个系统服务
android·源码
火山上的企鹅2 小时前
Codex实战:APP远程升级服务搭建(五)App端远程升级接入
android·服务器·远程升级·qgc