问题描述
在Android12系统开发过程中移植自己编写的linux底层可执行程序,该程序存放位置为/system/bin路径下,在Android7,Android8等系统中设置程序自启动的方法为:
1、在device/rockchip/common/sepolicy路径中添加对应可执行程序的te文件;
2、更改device/rockchip/common/sepolicy路径中的file_contexts文件;
3、更改device/rockchip/common/rootdir路径下的init.rockchip.rc文件;
添加的te文件如下图所示:
type hwd-test, domain, coredomain;
type hwd-test_exec, exec_type, system_file_type, file_type;
#typeattribute hwd-test coredomain;
init_daemon_domain(hwd-test)
在file_contexts文件中添加如下语句:
#add by hwd
/system/bin/hwd-test u:object_r:hwd-test_exec:s0
在init.rockchip.rc文件中添加如下语句:
#hwd-test add by hwd
service hwd-test /system/bin/hwd-test
class core
user root
但在更高的安卓系统中,如Android11、12中,device/rockchip/common/sepolicy路径下的te文件被分类存放,分为private、public、vendor等,此时以上方法不可以,编译会报错。解决措施如下
解决措施
在Android11、12以上系统中设置自定义的/system/bin/hwd-test程序开机自启动则需要在system/sepolicy/private路径中添加te文件,同时修改该路径下的file_contexts文件,修改方式和上面一致。此外需注意,在system/sepolicy/private中完成修改后应当在system/sepolicy/prebuilts/api/32.0/private路径中进行完全相同的修改,否则系统编译将会报错。