android R 应用调用SystemProperties.set(“prop”, “0”);操作,添加seLinux步骤: 以下以设置SystemProperties.set(“vendor.myprop.testprop”, “0”);为例
1、device/qcom/sepolicy_vndr/generic/vendor/common/property.te
type test_prop, property_type;
test_prop为定义的prop名称,这个可以随便起名
2、device/qcom/sepolicy_vndr/generic/vendor/common/property_contexts.te
vendor.myprop.testprop u:object_r:test_prop:s0
此处test_prop需要和上边property.te定义的名称一样,vendor.myprop.testprop就是要设置的property。
3、device/qcom/sepolicy_vndr/generic/vendor/common/需要加权限的te文件
例如我添加的是在platform_app.te
set_prop(platform_app,test_prop);
添加完以上之后就可以去system/sepolicy下编译了,这时候如果编译报错,就是限制了neverallow,需要继续修改。
4、在system/sepolicy/public/property.te中找到如下代码段
compatible_property_only(`
# Neverallow coredomain to set vendor properties
neverallow {
coredomain
-init
-system_writes_vendor_properties_violators
} {
property_type
-system_property_type
-extended_core_property_type
}:property_service set;
')
修改为:
compatible_property_only(`
# Neverallow coredomain to set vendor properties
neverallow {
coredomain
-init
-system_writes_vendor_properties_violators
-platform_app
} {
property_type
-system_property_type
-extended_core_property_type
}:property_service set;
')
将neverallow的te文件减去。同时修改prebuilts/api/30.0/public/property.te,改成一样的,不然在编译时会报文件不一致的错误。
这时候如果在编译时还是报neverallow错误,可根据错误信息继续修改,比如我在编译时遇到报的是private/app_neverallows.te这个文件的错误,
就继续修改private/app_neverallows.te这个文件,将其中的neverallows限制去掉即可。同时也要同步修改prebuilts/api/30.0/private/app_neverallows.te。