Setting properties from app fails


#1

On another platform we devised a sysprop mechanism for the app to change some things. In our init.project.rc we added some on property code like below:

on property:usb.mydevice=1
#do something

I call this from app code like this:
Process proc = Runtime.getRuntime().exec(new String[] {"/system/bin/setprop",“usb.mydevice”,“1”});

And I get the following output:
setprop: failed to set property ‘usb.mydevice’ to ‘1’


#2

Android System properties should not be changed by user application, there are others communication ways like Android Intents.
I suppose application does not have sufficient rights to set the propery, could you please check dmesg for sepolicy/avc issues.


#3

I know that in a normal Android environment setting system properties from an app is not ideal. This is an embedded device that runs only one app at startup and this worked on a previous device.

I ran dmesg but it doesn’t show anything relevant. I have found that if I run “setenforce 0” from adb my app works.


#4

Great, that means sepolicy forbids setenforce to be executed form app ‘context’. Even if sepolicy is in permissive mode (setenforce 0), you should be able to see ‘error’ messages from dmesg (dmesg | grep avc). If you want to keep sepolicy enforced (which is recommended for security reasons), you will need to fix them.

https://source.android.com/security/selinux/validate