How to read a value in a file with android init.rc

2019-08-17 10:12发布

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

in a exe.sh :

lcdfiletmp="cache/sticky/lcdlive"
lcdlivetmp=$(cat "$lcdfiletmp")
setprop persist.vendor.lcd.live $lcdlivetmp 

, but according to SElinux I don't have a right.

I have tried in vendor.rc:

copy /cache/sticky/lcdlive persist.vendor.lcd.live
write persist.vendor.lcd.live /cache/sticky/lcdlive 

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

expected : persist.vendor.lcd.live = value in the file /cache/sticky/lcdlive

1条回答
干净又极端
2楼-- · 2019-08-17 10:55

I haven't found any way to read a file in init.vendor.rc but I found a solution :

  1. create a service with a scripte.sh in init.vendor.rc
  2. in the scripte.sh :
   lcdfiletmp="cache/sticky/lcdlive"
    lcdlivetmp=$(cat "$lcdfiletmp")
    setprop persist.vendor.lcd.live $lcdlivetmp
  1. most important to declare scripte to system and chown /cache/sticky/* to system. to declare property as vendor_custom

  2. add SElinux rules in *.te

it's quite complicated selinux problem, if you have any similar problem feel free to ask here.

查看更多
登录 后发表回答