android setprop 权限,android property_getproperty_set设置与avc权限添加

androidproperty_get/property_set设置与avc权限添加介绍了作者的心中所想,无论在工作还是生活上都有较好的参考价值,喜欢的可以仔细研读一下

1.使用需要添加对应的头文件,同时需要在Android.mk文件中加入库libcutils.

#include

2.property_get/property_set 函数原型

/* property_get: returns the length of the value which will never be

** greater than PROPERTY_VALUE_MAX - 1 and will always be zero terminated.

** (the length does not include the terminating zero).

**

** If the property read fails or returns an empty value, the default

** value is used (if nonnull).

*/

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

/* property_set: returns 0 on success, < 0 on failure

*/

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

3.使用简单实例

property_set("debug.xxx","ture");

property_set("debug.xxx","false");

// 0--auto adjust,1--enable,2--disable

property_get("debug.xxx", prop, "0");

condition = static_cast(atoi(prop));

4.debug问题,查看是否设置生效

adb shell

getprop | grep debug.xxx

5. avc 权限问题,手动关闭selinux确认是否生效

a)属性值设置失败

W libc    : Unable to set property "debug.xxx" to "false": error code: 0x18

b)关闭selinux测试

adb root;adb shell setenforce 0

getprop | grep debug.xxx

6.avc 权限修改

a)查看是否有对应的debug.xxx avc报错,没有需要先把debug.xxx 属性值加到系统里面去

android/device/xxx/xxx/system.prop

debug.xxx=false

b) avc 报错

E selinux : avc:  denied  { set } for property=debug.xxx pid=862 uid=1047 gid=1005 scontext=u:r:hal_camera_default:s0 tcontext=u:object_r:debug_prop:s0 tclass=property_service permissive=0

c)首先将我们的报错avc日志拷出来做成一个avc.txt放在Ubuntu系统下面在终端中运行以下命令生成的avc.te文件就是我们的解决方法了.

audit2allow工具路径: external/selinux/prebuilts/bin/audit2allow

lunch

./audit2allow –i avc.txt >avc.te

avc.txt

E selinux : avc:  denied  { set } for property=debug.xxx pid=862 uid=1047 gid=1005 scontext=u:r:hal_camera_default:s0 tcontext=u:object_r:debug_prop:s0 tclass=property_service permissive=0

E selinux : avc:  denied  { set } for property=debug.xxx pid=862 uid=1047 gid=1005 scontext=u:r:hal_camera_default:s0 tcontext=u:object_r:debug_prop:s0 tclass=property_service permissive=0

得到的avc.te信息,

#============= hal_camera_default ==============

allow hal_camera_default debug_prop:property_service set;

然后把allow hal_camera_default debug_prop:property_service set;  这句加到对应的权限文件里面去.

关键词:android,设置,权限,添加

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值