忘记是Android M N O 哪个版本开始prop字段开始分放在system/build.prop . vendor/build.prop
system/odm/default.prop …这种花里胡哨的地方了,然后有时候需要自定义一些prop可能有时候会放错位置,或者自定义的不可以被应用读写,最近看了看相关的东西,也查找了相关资料,觉得有丢丢资料不够的感觉,决定用blog给记录下来,避免后来者踩坑了~
这里以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的方式是干嘛?是在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
就生成了
很简单。这个,其实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);
}
没了
1,细心点吧,少了个vendor 天壤之别。老毛病了…哎
2, 不会就学,抄,Android平台其实很完善了,要做的功能。。。基本都有,抄呗. 。。
不对,读书人怎么叫做抄呢?那叫学习。好了 苦比发版本去了,有需要的朋友看看就好,大佬忽略吧=。=我真的挺菜的。。。。告辞~