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

 我来答
bluetear007
推荐于2016-11-15 · 知道合伙人数码行家
bluetear007
知道合伙人数码行家
采纳数:1077 获赞数:6395
电子电器类维修 包括电脑 手机 mp3 mp4 家用电器 电玩具等等

向TA提问 私信TA
展开全部

adb sehll setProp所设属性值在重起之后被清除。

是因为必须采用persist.开头的属性名才能永久保存。


如果拥有root权限,可直接编辑/system/build.prop并加入需要永久保存的属性。

具体操作参考原创文章:

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

地址:blog.csdn.net/cloudwu007/article/details/7850496

文章预览:

a876480121
2013-10-18 · 超过60用户采纳过TA的回答
知道答主
回答量:113
采纳率:66%
帮助的人:111万
展开全部
结论:1.必须采用persist.开头的属性名才能永久保存。2.如果具有root权限,可以直接编辑/system/build.prop并加入需要永久保存的属性 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 后读入的属性将覆盖前面读取的相同的属性。 int property_set(const char *name, const char *value) { if(namelen < 1) return -1; pi = (prop_info*) __system_property_find(name); if(pi != 0) { /* ro.* properties may NEVER be modified once set */ if(!strncmp(name, "ro.", 3)) return -1; pa = __system_property_area__; update_prop_info(pi, value, valuelen); pa->serial++; __futex_wake(&pa->serial, INT32_MAX); } else { pa = __system_property_area__; if(pa->count == PA_COUNT_MAX) return -1; pi = pa_info_array + pa->count; pi->serial = (valuelen name, name, namelen + 1); memcpy(pi->value, value, valuelen + 1); pa->toc[pa->count] = (namelen count++; pa->serial++; __futex_wake(&pa->serial, INT32_MAX); } /* If name starts with "net." treat as a DNS property. */ if (strncmp("net.", name, strlen("net.")) == 0) { if (strcmp("net.change", name) == 0) { return 0; } /* * The 'net.change' property is a special property used track when any * 'net.*' property name is updated. It is _ONLY_ updated here. Its value * contains the last updated 'net.*' property. */ property_set("net.change", name); } else if (persistent_properties_loaded && strncmp("persist.", name, strlen("persist.")) == 0) { /* * Don't write properties to disk until after we have read all default properties * to prevent them from being overwritten by default values. */ write_persistent_property(name, value); } property_changed(name, value); return 0; } 当用户设置属性时,如果以属性名字以persist.开头,则会同时在/data/property目录下创建以该属性名字命名的文件,并写入属性值。
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式