Setting System Property

If you want to add/modify some system properties, it's an good idea to use SystemProperties.get & SystemProperties.set.

Note that the application should share the system uid, and have the signature of platform.

This example is creating a new system properties which would persist even if device reboot. Unless you erase User Data partition (such as performing factory reset)

1.AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"  
    package="com.example.demomodesettingstest"  
    android:versionCode="1"  
    android:versionName="1.0"  
  **  android:sharedUserId="android.uid.system" **>

2.Android.mk

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)


LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_PACKAGE_NAME := DemoApp

**LOCAL_CERTIFICATE := platform**

include $(BUILD_PACKAGE)

3.MainActivity.java

import android.os.SystemProperties; 
  
public class MainActivity extends Activity {  
  
      //Add in somewhere  
      SystemProperties.set("persist.sys.demo", "1");
}  

After these three steps, you can find the property "persist.sys.demo" is
added in /data/property

Note:

  1. About naming property, please follow the prefix that defined in system/core/init/property_service.c

     property_perms[] = {
        { "net.rmnet0.",      AID_RADIO,    0 },
        { "net.gprs.",        AID_RADIO,    0 },
        { "net.ppp",          AID_RADIO,    0 },
        { "net.qmi",          AID_RADIO,    0 },
        { "net.lte",          AID_RADIO,    0 },
        { "net.cdma",         AID_RADIO,    0 },
        { "ril.",             AID_RADIO,    0 },
        { "gsm.",             AID_RADIO,    0 },
        { "persist.radio",    AID_RADIO,    0 },
        { "net.dns",          AID_RADIO,    0 },
        { "sys.usb.config",   AID_RADIO,    0 },
        { "net.",             AID_SYSTEM,   0 },
        { "dev.",             AID_SYSTEM,   0 },
        { "runtime.",         AID_SYSTEM,   0 },
        { "hw.",              AID_SYSTEM,   0 },
        { "sys.",             AID_SYSTEM,   0 },
        { "service.",         AID_SYSTEM,   0 },
        { "wlan.",            AID_SYSTEM,   0 },
        { "persist.wlan.",    AID_SYSTEM,   0 },
        { "bluetooth.",       AID_BLUETOOTH,   0 },
        { "dhcp.",            AID_SYSTEM,   0 },
        { "dhcp.",            AID_DHCP,     0 },
        { "debug.",           AID_SYSTEM,   0 },
        { "debug.",           AID_SHELL,    0 },
        { "log.",             AID_SHELL,    0 },
        { "service.adb.root", AID_SHELL,    0 },
        { "service.adb.tcp.port", AID_SHELL,    0 },
        { "persist.sys.",     AID_SYSTEM,   0 }, -> I chose this one.
        { "persist.service.", AID_SYSTEM,   0 },
        { "persist.security.", AID_SYSTEM,   0 },
        { "persist.service.bdroid.", AID_BLUETOOTH,   0 },
        { "selinux."         , AID_SYSTEM,   0 },
        { "modem.",            AID_RADIO,   0},
        { "media.",            AID_MEDIA,   0},
        { "persist.camera.front.freq", AID_SYSTEM,   0 },
        { "persist.camera.usb.freq", AID_SYSTEM,   0},
        { "sf.lcd_density",   AID_SYSTEM,   0 },
        { "persist.sys.cam",   AID_MEDIA,   0},
        { "media.", AID_MEDIA, 0},
        { NULL, 0, 0 }
    
  2. There are some property file other than /data/property

#define PROP_PATH_RAMDISK_DEFAULT  "/default.prop"  
  
#define PROP_PATH_SYSTEM_BUILD     "/system/build.prop"  
  
#define PROP_PATH_SYSTEM_DEFAULT   "/system/default.prop"  
  
#define PROP_PATH_LOCAL_OVERRIDE   "/data/local.prop"  
  
#define PROP_PATH_FACTORY          "/factory/factory.prop"  

Take a look if you're interested in it.