Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What linux permissions are needed for SystemProperties.set to work? (android)

What linux permissions are needed for SystemProperties.set to work? (android)

I am writing an app that runs in system/app on an android device.

It is running as

android:sharedUserId="android.uid.systemui"

in Android.mk

LOCAL_CERTIFICATE := platform

However, I am finding that I cannot create, write or set a property. In the console, I can do a getprop, setprop. However, my program cannot create it.

ls -l /data/property/

shows it does not exist.

        Slog.d(TAG, "key is not set, will set APPLE");
        SystemProperties.set(keyName, favorite);
        if(SystemProperties.get(keyName).equals(favorite)) {
            Slog.d(TAG, keyName + " = " + SystemProperties.get(keyName));
        } else {
            Slog.e(TAG, "setting SystemProperties failed. value written = " + SystemProperties.get(keyName));
        }

logcat:

Line 1365: D/MyTag( 2593): keyName: persist.fruit.user.favorite
Line 1373: D/MyTag( 2593): keyName has value []
Line 1377: D/MyTag( 2593): key is not set, will set APPLE
Line 1381: E/MyTag( 2593): setting SystemProperties failed. value written = 

evidently perhaps it is a matter of insufficient permissions - but which ones?

like image 386
likejudo Avatar asked Dec 12 '22 02:12

likejudo


1 Answers

I had accepted fadden's answer but after more exploration, found it was incorrect though it was very helpful in reaching the correct answer.

step 1: look at the array in https://android.googlesource.com/platform/system/core/+/kitkat-release/init/property_service.c

{ "persist.sys.",     AID_SYSTEM,   0 },

the name of your property should begin with the same key string in the array. thus I had to change my property name to "persist.sys.fruit.user.favorite"

step 2: in your android manifest file, run as user id mentioned in the array above.

<manifest android:sharedUserId="android.uid.system" >
like image 180
likejudo Avatar answered Apr 09 '23 02:04

likejudo