Android属性:所设属性值为何在重起后被清除

问题:发现adb sehll setProp所设属性值在下次重起后被清除

adb shell setprop testing.mediascanner.skiplist /storage/sdcard1/test

结论:必须采用persist.开头的属性名才能永久保存。

On system initialization, Android will allocates a block of shared memory for storing the properties. This is done in “init” daemon whose sourcecode is at: device/system/init. The “init” daemon will start a PropertyService.

The Property Service is running in the process of “init”daemon. Every client that wants to SET property needs to connect to theProperty Service and send message to Property Service. Property Servicewill update/create the property in shared memory. Any client that wants to GET property can read the property from the shared memory directly.This promotes the read performance.

Java API:

import android.os.SystemProperties;

public static String get(String key, String def) {}   public static void set(String key, String val) {}  

The Native API:

int property_get(const char *key, char *value, const char *default_value);      int property_set(const char *key, const char *value);  

bionic/libc/include/sys/system_properties.h

#define PROP_NAME_MAX   32    #define PROP_VALUE_MAX  92  

以上定义可知属性最大长度为32,属性值最大长度92字节.

bionic/libc/include/sys/_system_properties.h

#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"  

属性服务启动后会从系统文件中读取默认的属性,并写入共享内存中,以下4个文件为按顺序读取:
 /default.prop
 /system/build.prop
 /system/default.prop
 /data/local.prop

后读入的属性将覆盖前面读取的相同的属性。
system/core/init/property_service.c

void start_property_service(void)   {       int fd;          load_properties_from_file(PROP_PATH_SYSTEM_BUILD);       load_properties_from_file(PROP_PATH_SYSTEM_DEFAULT);   #ifdef ALLOW_LOCAL_PROP_OVERRIDE        load_properties_from_file(PROP_PATH_LOCAL_OVERRIDE);   #endif /* ALLOW_LOCAL_PROP_OVERRIDE */        /* Read persistent properties after all default values have been loaded. */       load_persistent_properties();          update_legacy_atvc_properties();  

设置属性,ro.开头的属性将不能被更改属性值,persist.开头的属性会被永久纪录,其他属性值在重新开机后均将被丢弃:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/ed19da62a93ee4c698ed4bd9bdfdd479.html