Android O 自定义prop的问题小总结

废话太多 直接上patch Android Q 自定义Prop

diff --git a/device/rockchip/common/sepolicy/vendor/platform_app.te b/device/rockchip/common/sepolicy/vendor/platform_app.te
index c967acedea..de4b48972e 100644
--- a/device/rockchip/common/sepolicy/vendor/platform_app.te
+++ b/device/rockchip/common/sepolicy/vendor/platform_app.te
@@ -6,5 +6,7 @@ allow platform_app vendor_metadata:dir { search };
 #allow platform_app vendor_file:file { getattr open read };
 get_prop(platform_app,vendor_default_prop)
 get_prop(platform_app,serialno_prop)
+get_prop(platform_app,vtech_prop)
+set_prop(platform_app,vtech_prop)
 allow platform_app vendor_file:file { read open getattr map };
 allow platform_app rootfs:dir { create search read open getattr write };
diff --git a/device/rockchip/common/sepolicy/vendor/property.te b/device/rockchip/common/sepolicy/vendor/property.te
index 614320f9ab..68c746daf1 100644
--- a/device/rockchip/common/sepolicy/vendor/property.te
+++ b/device/rockchip/common/sepolicy/vendor/property.te
@@ -9,3 +9,4 @@ type vendor_cec_prop, property_type;
 type vendor_omx_prop, property_type;
 type vendor_hal_wifi_prop, property_type;
 type vendor_camera_prop, property_type;
+type vtech_prop, property_type, mlstrustedobject;
***###这里的很重要。property_service 在init阶段读取已保存的prop字段,
如果没有设置的话,自定义的prop在开机的时候时没有办法读取到相应默认值的***
diff --git a/device/rockchip/common/sepolicy/vendor/vendor_init.te b/device/rockchip/common/sepolicy/vendor/vendor_init.te
index 56b18df594..56b0b1b647 100644
--- a/device/rockchip/common/sepolicy/vendor/vendor_init.te
+++ b/device/rockchip/common/sepolicy/vendor/vendor_init.te
@@ -44,3 +44,5 @@ allow vendor_init vtech_block_device:lnk_file { relabelto };
 #============= vendor_init ==============
 allow vendor_init vtechfs:dir { create setattr getattr mounton };
 allow vendor_init sysfs:lnk_file { setattr getattr read open };
+set_prop(vendor_init, vtech_prop)
+get_prop(vendor_init, vtech_prop)

diff --git a/device/rockchip/common/sepolicy/vendor/property_contexts b/device/rockchip/common/sepolicy/vendor/property_contexts
index 40bacd41bc..c17669ef36 100644
--- a/device/rockchip/common/sepolicy/vendor/property_contexts
+++ b/device/rockchip/common/sepolicy/vendor/property_contexts
@@ -59,3 +59,4 @@ vendor.audio                            u:object_r:public_vendor_system_prop:s0
 
 #for vendor/build.prop
 vendor.all.modules.ready                   u:object_r:public_vendor_system_prop:s0
+vtech.                                    u:object_r:vtech_prop:s0
diff --git a/device/rockchip/common/sepolicy/vendor/shell.te b/device/rockchip/common/sepolicy/vendor/shell.te
index f8b9474a73..fd994df05e 100755
--- a/device/rockchip/common/sepolicy/vendor/shell.te
+++ b/device/rockchip/common/sepolicy/vendor/shell.te
@@ -37,6 +37,8 @@ allow shell sysfs_batteryinfo:file { open read getattr };
 binder_call(shell, wificond)
 
 get_prop(shell, graphic_prop)
+get_prop(shell, vtech_prop)
+set_prop(shell, vtech_prop)
 get_prop(shell, safemode_prop)
 get_prop(shell, mmc_prop)
 get_prop(shell, device_logging_prop)
diff --git a/device/rockchip/common/sepolicy/vendor/system_app.te b/device/rockchip/common/sepolicy/vendor/system_app.te
index 228bb7a696..ede1d64c4b 100644
--- a/device/rockchip/common/sepolicy/vendor/system_app.te
+++ b/device/rockchip/common/sepolicy/vendor/system_app.te
@@ -50,3 +50,5 @@ allow system_app cache_file:file { create read write open getattr };
 #============= system_app ==============
 allow system_app proc_net:file { getattr open read };
 get_prop(system_app,serialno_prop)
+get_prop(system_app, vtech_prop)
+set_prop(system_app, vtech_prop)
diff --git a/system/sepolicy/prebuilts/api/29.0/public/property.te b/system/sepolicy/prebuilts/api/29.0/public/property.te
index e166c000ed..088ca530f1 100644
--- a/system/sepolicy/prebuilts/api/29.0/public/property.te
+++ b/system/sepolicy/prebuilts/api/29.0/public/property.te
@@ -349,6 +349,9 @@ compatible_property_only(`
   # Neverallow coredomain to set vendor properties
   neverallow {
     coredomain
+    -platform_app
+    -system_app
+    -shell
     -init
     -system_writes_vendor_properties_violators
   } {
diff --git a/system/sepolicy/public/property.te b/system/sepolicy/public/property.te
index e166c000ed..088ca530f1 100644
--- a/system/sepolicy/public/property.te
+++ b/system/sepolicy/public/property.te
@@ -349,6 +349,9 @@ compatible_property_only(`
   # Neverallow coredomain to set vendor properties
   neverallow {
     coredomain
+    -platform_app
+    -system_app
+    -shell
     -init
     -system_writes_vendor_properties_violators
   } {

前言

忘记是Android M N O 哪个版本开始prop字段开始分放在system/build.prop . vendor/build.prop
system/odm/default.prop …这种花里胡哨的地方了,然后有时候需要自定义一些prop可能有时候会放错位置,或者自定义的不可以被应用读写,最近看了看相关的东西,也查找了相关资料,觉得有丢丢资料不够的感觉,决定用blog给记录下来,避免后来者踩坑了~

自定义prop

这里以MTK P MT6739举例子吧。
我们常规定义的prop字段一般都是用PRODUCT_PROPERTY_OVERRIDES += ro.xx.xx.xx=x 这种定义方式来生成一个prop字段,但是最近发现我自己定义的一个字 ro.build.display.tdcid 始终在Settings里面死活读取不出来。于是我就看了看avclog信息,发现如下LOG信息

type=1400 audit(0.0:3630): avc: denied { read } for name="u:object_r:vendor_default_prop:s0" dev="tmpfs" in`o=10173 scontext=u:r:system_app:s0 tcontext=u:object_r:vendor_default_prop:s0 tclass=file permissive=0

这下尴尬了,然后我就去添加了相应的selinux权限,然并卵~~~。avc log是莫的了,但是!但是位还是读取不到啊…这很尴尬了,由于我使用的是PRODUCT_PROPERTY_OVERRIDES生成的log信息吧,然后我就去偷瞄了一下,却是是在vendor/build.prop中生成的位的 ro.build.display.tdcid 。那为毛读取不到呢 selinux权限 我没加对?
于是
adb shell
tdc:/ # setenforce 0
哈,这下我可以无法无天了吧? 结果一看还是令人绝望的一批,莫的感情,也莫的值,就好像我的心 空空荡荡的。于是没办法啊,找了个MTK的生成的一个prop ro.vendor.mtk_camera_app_version去看了看 看看这个玩意哪里用了,然后发现Camera2中有用到这个prop。 凭啥阿!!!!算了 就凭他是MTK的大佬写的,然后我又跑去看了一堆还有哪里定义,果然发现了端倪,在device/mediatek/sepolicy/basic/non_plat中的property_contexts中发现了这个prop的声明,恩,good了 我就照葫芦画瓢写了一个。

diff --git a/alps/device/mediatek/sepolicy/basic/non_plat/attributes b/alps/device/mediatek/sepolicy/basic/non_plat/attributes
index d70e951ec8..a550d15a61 100644
--- a/alps/device/mediatek/sepolicy/basic/non_plat/attributes
+++ b/alps/device/mediatek/sepolicy/basic/non_plat/attributes
@@ -64,3 +64,8 @@ attribute mtk_hal_em;
 attribute mtk_hal_em_client;
 attribute mtk_hal_em_server;
 
+# Date: 2020/06/11
+# Author: tuliyuan
+# tdc prop
+
+attribute tdc_property_type;
diff --git a/alps/device/mediatek/sepolicy/basic/non_plat/domain.te b/alps/device/mediatek/sepolicy/basic/non_plat/domain.te
index 3367ed03ed..7ee8054a6c 100644
--- a/alps/device/mediatek/sepolicy/basic/non_plat/domain.te
+++ b/alps/device/mediatek/sepolicy/basic/non_plat/domain.te
@@ -7,6 +7,9 @@
 # Align Google change: f01453ad453b29dd723838984ea03978167491e5
 get_prop(domain, mtk_core_property_type)
 
+# add by tuliyuan for tdc_prop_type
+get_prop(domain, tdc_property_type)
+
 # Allow all processes to search /sys/kernel/debug/binder/ since it's has been
 # labeled with specific debugfs label and many violations to dir search debugfs_binder
 # are observed. Grant domain to suppress the violations as originally "debugfs:dir search"
diff --git a/alps/device/mediatek/sepolicy/basic/non_plat/property.te b/alps/device/mediatek/sepolicy/basic/non_plat/property.te
index 3a24e49c3c..b6467bac1e 100644
--- a/alps/device/mediatek/sepolicy/basic/non_plat/property.te
+++ b/alps/device/mediatek/sepolicy/basic/non_plat/property.te
@@ -271,3 +271,7 @@ type persist_xcap_rawurl_prop, property_type, extended_core_property_type;
 
 #=============boot reason property=============
 type vendor_boot_reason_prop, property_type, extended_core_property_type;
+
+#=============tuiyuan tdc type==============
+type tdc_system_prop, property_type, tdc_property_type;
+type tdc_custom_prop, property_type, tdc_property_type;
diff --git a/alps/device/mediatek/sepolicy/basic/non_plat/property_contexts b/alps/device/mediatek/sepolicy/basic/non_plat/property_contexts
index 3f3ad828d3..e2e4a2b50c 100644
--- a/alps/device/mediatek/sepolicy/basic/non_plat/property_contexts
+++ b/alps/device/mediatek/sepolicy/basic/non_plat/property_contexts
@@ -314,4 +314,6 @@ persist.vendor.mtk.xcap.rawurl  u:object_r:persist_xcap_rawurl_prop:s0
 
 #=============boot reason property==============
 vendor.sys.boot.reason u:object_r:vendor_boot_reason_prop:s0
-ro.tdc.project_name u:object_r:exported2_default_prop:s0 exact string
+ro.tdc.project_name u:object_r:tdc_system_prop:s0 exact string
+ro.build.display.tdcid u:object_r:tdc_system_prop:s0 exact string --->其实这里已经犯罪了,错了=。=
+tdc. u:object_r:tdc_custom_prop:s0
diff --git a/alps/device/mediatek/sepolicy/basic/non_plat/system_app.te b/alps/device/mediatek/sepolicy/basic/non_plat/system_app.te
index a7e9def5a4..af817941a7 100644
--- a/alps/device/mediatek/sepolicy/basic/non_plat/system_app.te
+++ b/alps/device/mediatek/sepolicy/basic/non_plat/system_app.te
@@ -29,3 +29,6 @@ allow system_app mtk_thermal_config_prop:file { getattr open read };
 allow system_app aee_exp_data_file:file r_file_perms;
 allow system_app aee_exp_data_file:dir r_dir_perms;
 allow system_app md_monitor:unix_stream_socket connectto;
+
+get_prop(system_app,mtk_amslog_prop);
+get_prop(system_app,vendor_default_prop);
diff --git a/alps/device/mediatek/sepolicy/basic/non_plat/vendor_init.te b/alps/device/mediatek/sepolicy/basic/non_plat/vendor_init.te       -->照抄的
index 9c51b416ca..d2bf5e8323 100644
--- a/alps/device/mediatek/sepolicy/basic/non_plat/vendor_init.te       
+++ b/alps/device/mediatek/sepolicy/basic/non_plat/vendor_init.te
@@ -50,3 +50,7 @@ set_prop(vendor_init, mtk_cxp_vendor_prop)
 allow vendor_init kernel:key search;
 
 set_prop(vendor_init, tel_switch_prop)
+
+#add by tuliyuan for tdc prop
+set_prop(vendor_init, tdc_system_prop)
+set_prop(vendor_init, tdc_custom_prop)

好了,然后,我还赶时间的把字段改了个名字。。。。
这尼玛才是关键吧!!! ro.vendor.build.display.tdcid 然后神奇的好了,虽然我也多此一举的加了selinux权限,对了 如果你们加vendor不行,记得试试我的权限?图一乐吧,后面的vendor_init.te可能有用,真是要出版本没时间分析了~~~后续在看看吧,这里就是提供一个参考
所以应该关键是ro后面要加个vendor?毕竟O以后system分区的build.prop和vendor分区的build.prop算是分家了。。。。所以有需要的朋友们可以。尝试在使用PRODUCT_PROPERTY_OVERRIDES自定义prop的时候切记加上xx.vendor.xxxx确定的

自定义字段到system/build.prop

这个比较简单吧。随便扯扯,其实也让我纠结了一会。我们常规让他生成到system/build.prop的方式是干嘛?是在device/[company]/[project]/system.prop中去添加对吧?但是有时候我需要一个宏开关去动态的改他的值,我不聪明,也很菜。想了想就放xx.mk里面去区分挺好的。然后吧。我就去好动态的分配值,但是这里插一段,我不是之前自定义PRODUCT_PROPERTY_OVERRIDES prop读取不出来码。我给他放system/build.prop中就好了读取正常,这个应该是有权限了。然后又因为想区分项目。觉得不合理,还是要放.mk中比较合适,我就给他想了个小办法,好像没有类似PRODUCT_PROPERTY_OVERRIDES这样的玩意去生成prop到system/build.prop。怎么办。安心当个猴子模仿呗
differ文件如下:

diff --git a/alps/build/make/core/Makefile b/alps/build/make/core/Makefile
index 48e596cc93..673cc4a19e 100644
--- a/alps/build/make/core/Makefile
+++ b/alps/build/make/core/Makefile
@@ -317,6 +317,10 @@ system_prop_file := $(TARGET_SYSTEM_PROP)
 else
 system_prop_file := $(wildcard $(TARGET_DEVICE_DIR)/system.prop)
 endif
+#A:@tuliyuan add for using PRODUCT_TDC_SYSTEM_PROPERTY_OVERRIDES to build system/build.prop
+FINAL_TDC_SYSTEM_BUILD_PROPERTIES += \
+    $(call collapse-pairs, $(PRODUCT_TDC_SYSTEM_PROPERTY_OVERRIDES))
+
 $(intermediate_system_build_prop): $(BUILDINFO_SH) $(INTERNAL_BUILD_ID_MAKEFILE) $(BUILD_SYSTEM)/version_defaults.mk $(system_prop_file) $(INSTALLED_ANDROID_INFO_TXT_TARGET)
        @echo Target buildinfo: $@
        @mkdir -p $(dir $@)
@@ -377,6 +381,9 @@ endif
                        echo "#" >> $@; )
        $(hide) $(foreach line,$(FINAL_BUILD_PROPERTIES), \
                echo "$(line)" >> $@;)
+       #A:@tuliyuan add for custom system prop
+       $(hide) $(foreach line,$(FINAL_TDC_SYSTEM_BUILD_PROPERTIES), \
+                echo "$(line)" >> $@;)
        $(hide) cat $(INSTALLED_ANDROID_INFO_TXT_TARGET) | grep 'require version-' | sed -e 's/require version-/ro.build.expect./g' >> $@
        $(hide) build/make/tools/post_process_props.py $@ $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_PROPERTY_BLACKLIST)

然后在你的mk文件中

PRODUCT_TDC_SYSTEM_PROPERTY_OVERRIDES += ro.tdc.aab=1

就生成了

自定义的prop重启又恢复原值了咋办

很简单。这个,其实property_service.cpp是这个prop关键的的服务

找到他,然后~~
diff如下
补充提交

diff --git a/android/system/core/init/property_service.cpp b/android/system/core/init/property_service.cpp
index fd14bd66f6..50e813e8b4 100644
--- a/android/system/core/init/property_service.cpp
+++ b/android/system/core/init/property_service.cpp
@@ -118,6 +118,31 @@ static int check_control_mac_perms(const char *name, char *sctx, struct ucred *c
     return check_mac_perms(ctl_name, sctx, cr);
 }
 
+/**
+ *A:@tuliyuan add by tuliyuan for write tdc prop to data/property
+ */
+static void write_tdc_property(const char *name, const char *value)
+{
+    char tempPath[PATH_MAX];
+    char path[PATH_MAX];
+    int fd;
+
+    snprintf(tempPath, sizeof(tempPath), "%s/.temp.XXXXXX", PERSISTENT_PROPERTY_DIR);//
+    fd = mkstemp(tempPath);//创建一个临时文件并打开 linux
+    if (fd < 0) {
+        PLOG(ERROR) << "Unable to write persistent property to temp file " << tempPath;
+        return;
+    }
+    write(fd, value, strlen(value));
+    fsync(fd);
+    close(fd);
+
+    snprintf(path, sizeof(path), "%s/%s", PERSISTENT_PROPERTY_DIR, name);
+    if (rename(tempPath, path)) {//重命名文件为path的名称指向 name linux
+        PLOG(ERROR) << "Unable to rename persistent property file " << tempPath << " to " << path;
+        unlink(tempPath);
+    }
+}
 static void write_persistent_property(const char *name, const char *value)
 {
     char tempPath[PATH_MAX];
@@ -204,6 +229,12 @@ static uint32_t PropertySetImpl(const std::string& name, const std::string& valu
     if (persistent_properties_loaded && android::base::StartsWith(name, "persist.")) {
         write_persistent_property(name.c_str(), value.c_str());
     }
+    /**
+     *A:@tuliyuan add for save tdc prop 
+     */
+    if (persistent_properties_loaded && android::base::StartsWith(name, "diff --git a/android/system/core/init/property_service.cpp b/android/system/core/init/property_service.cpp
index fd14bd66f6..50e813e8b4 100644
--- a/android/system/core/init/property_service.cpp
+++ b/android/system/core/init/property_service.cpp
@@ -118,6 +118,31 @@ static int check_control_mac_perms(const char *name, char *sctx, struct ucred *c
     return check_mac_perms(ctl_name, sctx, cr);
 }
 
+/**
+ *A:@tuliyuan add by tuliyuan for write tdc prop to data/property
+ */
+static void write_tdc_property(const char *name, const char *value)
+{
+    char tempPath[PATH_MAX];
+    char path[PATH_MAX];
+    int fd;
+
+    snprintf(tempPath, sizeof(tempPath), "%s/.temp.XXXXXX", PERSISTENT_PROPERTY_DIR);//
+    fd = mkstemp(tempPath);//创建一个临时文件并打开 linux
+    if (fd < 0) {
+        PLOG(ERROR) << "Unable to write persistent property to temp file " << tempPath;
+        return;
+    }
+    write(fd, value, strlen(value));
+    fsync(fd);
+    close(fd);
+
+    snprintf(path, sizeof(path), "%s/%s", PERSISTENT_PROPERTY_DIR, name);
+    if (rename(tempPath, path)) {//重命名文件为path的名称指向 name linux
+        PLOG(ERROR) << "Unable to rename persistent property file " << tempPath << " to " << path;
+        unlink(tempPath);
+    }
+}
 static void write_persistent_property(const char *name, const char *value)
 {
     char tempPath[PATH_MAX];
@@ -204,6 +229,12 @@ static uint32_t PropertySetImpl(const std::string& name, const std::string& valu
     if (persistent_properties_loaded && android::base::StartsWith(name, "persist.")) {
         write_persistent_property(name.c_str(), value.c_str());
     }
+    /**
+     *A:@tuliyuan add for save tdc prop 
+     */
+    if (persistent_properties_loaded && android::base::StartsWith(name, "tdc.")) {///这里是要保存的字段 我这里是以tdc开头的
+        write_tdc_property(name.c_str(), value.c_str());
+    }
     property_changed(name, value);
     return PROP_SUCCESS;
 }
@@ -647,7 +678,7 @@ static void load_persistent_properties() {
             value[length] = 0;
             property_set(entry->d_name, value);
         } else {
-            PLOG(ERROR) << "Unable to read persistent property file " << entry->d_name;
+	    PLOG(ERROR) << "Unable to read persistent property file " << entry->d_name;
         }
         close(fd);
     }.")) {
+        write_tdc_property(name.c_str(), value.c_str());
+    }
     property_changed(name, value);
     return PROP_SUCCESS;
 }
@@ -647,7 +678,7 @@ static void load_persistent_properties() {
             value[length] = 0;
             property_set(entry->d_name, value);
         } else {
-            PLOG(ERROR) << "Unable to read persistent property file " << entry->d_name;
+	    PLOG(ERROR) << "Unable to read persistent property file " << entry->d_name;
         }
         close(fd);
     }

补充提交重新开机时能正确读取以保存的值

@@ -65,6 +65,7 @@ namespace android {
 namespace init {
 
 static int persistent_properties_loaded = 0;
+static int tdc_properties_loaded = 0;
 
 static int property_set_fd = -1;
 
@@ -140,6 +141,30 @@ static void write_persistent_property(const char *name, const char *value)
         unlink(tempPath);
     }
 }
+//A:@tuliyuan add this function for tdc prop save mode 
+static void write_tdc_property(const char *name, const char *value)
+{
+    char tempPath[PATH_MAX];
+    char path[PATH_MAX];
+    int fd;
+
+    snprintf(tempPath, sizeof(tempPath), "%s/.temp.XXXXXX", PERSISTENT_PROPERTY_DIR);
+    fd = mkstemp(tempPath);
+    if (fd < 0) {
+        LOG(ERROR) << "Unable to write tdc property to temp file " << tempPath;
+        return;
+    }
+    write(fd, value, strlen(value));
+    fsync(fd);
+    close(fd);
+
+    snprintf(path, sizeof(path), "%s/%s", PERSISTENT_PROPERTY_DIR, name);
+    if (rename(tempPath, path)) {
+        LOG(ERROR) << "Unable to rename tdc property file " << tempPath << " to " << path;
+        unlink(tempPath);
+    }
+}
+
 
 bool is_legal_property_name(const std::string& name) {
     size_t namelen = name.size();
@@ -204,6 +229,12 @@ static uint32_t PropertySetImpl(const std::string& name, const std::string& valu
     if (persistent_properties_loaded && android::base::StartsWith(name, "persist.")) {
         write_persistent_property(name.c_str(), value.c_str());
     }
+    //A:@tuliyuan add for saving tdc prop
+    if(tdc_properties_loaded && android::base::StartsWith(name, "tdc.")){
+       LOG(VERBOSE) << "saving properties from tdc property ";
+       write_tdc_property(name.c_str(), value.c_str());
+    }
+    //A:@tuliyuan add end
     property_changed(name, value);
     return PROP_SUCCESS;
 }
@@ -652,6 +683,61 @@ static void load_persistent_properties() {
         close(fd);
     }
 }
+//A:@tuliyuan add 
+static void load_tdc_properties() {
+    tdc_properties_loaded = 1;
+
+    std::unique_ptr<DIR, int(*)(DIR*)> dir(opendir(PERSISTENT_PROPERTY_DIR), closedir);
+    if (!dir) {
+        PLOG(ERROR) << "Unable to open tdc property directory \""
+                    << PERSISTENT_PROPERTY_DIR << "\"";
+        return;
+    }
+
+    struct dirent* entry;
+    while ((entry = readdir(dir.get())) != NULL) {
+        if (strncmp("tdc.", entry->d_name, strlen("tdc."))) {
+            continue;
+        }
+        if (entry->d_type != DT_REG) {
+            continue;
+        }
+
+        // Open the file and read the property value.
+        int fd = openat(dirfd(dir.get()), entry->d_name, O_RDONLY | O_NOFOLLOW);
+        if (fd == -1) {
+            PLOG(ERROR) << "Unable to open tdc property file \"" << entry->d_name << "\"";
+            continue;
+        }
+
+        struct stat sb;
+        if (fstat(fd, &sb) == -1) {
+            PLOG(ERROR) << "fstat on property file \"" << entry->d_name << "\" failed";
+            close(fd);
+            continue;
+        }
+
+        // File must not be accessible to others, be owned by root/root, and
+        // not be a hard link to any other file.
+        if (((sb.st_mode & (S_IRWXG | S_IRWXO)) != 0) || sb.st_uid != 0 || sb.st_gid != 0 || sb.st_nlink != 1) {
+            PLOG(ERROR) << "skipping insecure property file " << entry->d_name
+                        << " (uid=" << sb.st_uid << " gid=" << sb.st_gid
+                        << " nlink=" << sb.st_nlink << " mode=" << std::oct << sb.st_mode << ")";
+            close(fd);
+            continue;
+        }
+
+        char value[PROP_VALUE_MAX];
+        int length = read(fd, value, sizeof(value) - 1);
+        if (length >= 0) {
+            value[length] = 0;
+            property_set(entry->d_name, value);
+        } else {
+            PLOG(ERROR) << "Unable to read persistent property file " << entry->d_name;
+        }
+        close(fd);
+    }
+}
 
 // persist.sys.usb.config values can't be combined on build-time when property
 // files are split into each partition.
@@ -698,6 +784,7 @@ void load_persist_props(void) {
     load_override_properties();
     /* Read persistent properties after all default values have been loaded. */
     load_persistent_properties();
+    load_tdc_properties();
     property_set("ro.persistent_properties.ready", "true");
 }

没了

总结

1,细心点吧,少了个vendor 天壤之别。老毛病了…哎
2, 不会就学,抄,Android平台其实很完善了,要做的功能。。。基本都有,抄呗. 。。
3. init阶段的set_prop 这里的很重要。property_service 在init阶段读取已保存的prop字段,如果没有设置的话,自定义的prop在开机的时候时没有办法读取到相应默认值的
不对,读书人怎么叫做抄呢?那叫学习。好了 苦比发版本去了,有需要的朋友看看就好,大佬忽略吧=。=我真的挺菜的。。。。告辞~

  • 5
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值