如何使用android init.rc(vendor.rc)读取文件中的值 [英] How to read a value in a file with android init.rc (vendor.rc)
问题描述
在android系统(pie 9.0)中 我想从文件(/cache/sticky/lcdlive)中读取一个值并将其写入init.vendor.rc中的系统属性(persist.vendor.lcd.live)
In the android system (pie 9.0) I want to read a value from a file (/cache/sticky/lcdlive) and write it to a system property (persist.vendor.lcd.live) in a init.vendor.rc
在exe.sh中:
lcdfiletmp="cache/sticky/lcdlive"
lcdlivetmp=$(cat "$lcdfiletmp")
setprop persist.vendor.lcd.live $lcdlivetmp
,但是根据SElinux,我没有权利.
, but according to SElinux I don't have a right.
我已经在vendor.rc中尝试过:
I have tried in vendor.rc:
copy /cache/sticky/lcdlive persist.vendor.lcd.live
write persist.vendor.lcd.live /cache/sticky/lcdlive
结果:persist.vendor.lcd.live ="/cache/sticky/lcdlive",而不是文件/cache/sticky/lcdlive的"value"(数字)
result : persist.vendor.lcd.live = "/cache/sticky/lcdlive" but not the "value" of the file /cache/sticky/lcdlive (which is a number)
on early-init
setprop persist.vendor.lcd.live 0
on property:sys.boot_completed=1
copy /cache/sticky/lcdlive persist.vendor.lcd.live
期望:persist.vendor.lcd.live =文件/cache/sticky/lcdlive中的值
expected : persist.vendor.lcd.live = value in the file /cache/sticky/lcdlive
推荐答案
我在init.vendor.rc中找不到任何读取文件的方法,但是我找到了解决方法:
I haven't found any way to read a file in init.vendor.rc but I found a solution :
- 使用init.vendor.rc中的scripte.sh创建服务
- 在scripte.sh中:
lcdfiletmp="cache/sticky/lcdlive"
lcdlivetmp=$(cat "$lcdfiletmp")
setprop persist.vendor.lcd.live $lcdlivetmp
-
最重要的一点是将脚本声明为系统,并将/cache/sticky/*锁定为系统.将属性声明为vendor_custom
most important to declare scripte to system and chown /cache/sticky/* to system. to declare property as vendor_custom
在* .te
这是一个非常复杂的selinux问题,如果您有任何类似的问题,请随时在这里询问.
it's quite complicated selinux problem, if you have any similar problem feel free to ask here.
这篇关于如何使用android init.rc(vendor.rc)读取文件中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!