问题现象: 无法打开某个设备文件,提示权限失败
问题信息:unable to open /dev/ttyS0, error:Permission denied
解决步骤:

1 确认设备节点是否存在;
2 确认设备节点权限;尝试向所有组添加权限(chmod 777 /dev/ttyS0);

上述步骤如果还不能解决问题,就需要考虑Android Selinux权限策略。
1 临时取消Android Selinux 安全检查。

root@dev:# getenforceEnforcingroot@dev:# setenforce 0root@dev:# getenforcePermissive

上述问题如果解决权限问题,那么就是Android Selinux对进行访问进行了权限限制,setenforce只能一次性、临时性解决问题,完整的解决方案需要根据Android AVC的提示对进行进行权限设定。

01-01 01:33:48.409 21230 21230 W chinaycheng: type=1400 audit(0.0:76): avc: denied { read write } for name="ttyS0" dev="tmpfs" ino=2532 scontext=u:r:platform_app:s0:c512,c768 tcontext=u:object_r:serial_device:s0 tclass=chr_file permissive=0

AVC分析结果:

描述 关键值 测试值
缺少什么权限 denied {} read write
谁缺少 scontext u:r:platform_app
对那个文件 tcontext u:object_r:serial_device:s0
文件类型 tclass chr_file

解决方法:
在指定文件platform_app.te中添加权限
allow platform_app serial_device:chr_file { read write }
文件路径不确定,主要位于external/sepolicy 和device/**/sepolicy文件夹下面。修改之后需要重新少些boot.img才能生效。

PS:以上是对已经存在进程修改权限,如果进程不存在,对应的te文件不存在,那么就需要重新新增te文件。
1 找到对应的sepolicy文件夹,有一个file_contexts文件,模仿已经存在的信息,多写一条。以新增一个叫chinaycheng的程序为例

/system/bin/dex2oat     u:object_r:dex2oat_exec:s0 /system/bin/patchoat    u:object_r:dex2oat_exec:s0 /system/bin/chinaycheng u:object_r:chinaycheng_exec:s0

这就指定了chinaycheng这个程序的权限设置路径为:chinaycheng_exec,名字不重要,主要以_exec结尾就可以了。然后再参考目录下,其他文件的te,拷贝一个过来,修改里面的allow信息即可。

更多相关文章

  1. android 版本号适配 9.0网络请求方法
  2. Android(安卓)-- 系统结构 /system/ 目录下文件夹功能说明
  3. 详解Android(安卓)检测权限的三种写法
  4. Android多线程断点续传详解与案例
  5. Android(安卓)Studio 一些使用经验 - 传说之美
  6. 【转】PC安卓模拟器PANIC: Could not open:C:\Documents and Se
  7. Android(安卓)ADT升级出现的问题和解决方案
  8. Android之给ImageView添加点击效果
  9. parseSdkContent failed Could not initialize class android.gr

随机推荐

  1. (OK) android——Repo sync cm—解决—er
  2. Android(安卓)驱动开发系列三
  3. android 中layer-list的用法
  4. Android Studio 遇到 “method ID not in
  5. Android引导页面的实现
  6. Android 深入研究SQLite实例(一) 之 业务类
  7. Android UI的加载源码分析
  8. 【android】获取屏幕宽和高
  9. Android利用RecognizerIntent识别语音并
  10. android 获取当前运行进程的名称