自定义系统service SELinux权限报错

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lf12345678910/article/details/77993762

报错:

E SELinux : avc:  denied  { add } for service=flashlight pid=3485 uid=1000 scontext=u:r:system_server:s0 tcontext=u:object_r:default_android_service:s0 tclass=service_manager permissive=1

添加权限:

android\out\target\product\product-xxx\root\service_contexts

Android源码添加自定义系统服务

http://www.cnblogs.com/liam999/p/5933827.html

android\device\xxx\sepolicy

android\system\sepolicy

报错:

01-01 07:34:37.870  3704  3704 E flashlightHAL: Failed to open device file /sys/class/leds/flashlight/brightness -- Permission denied.

修改文件权限:(类似)

@ubuntu-server:~$ grep -rsn "timed_output" android/device/ android/system/
android/device/xxx/common/rootdir/etc/init.xxx.factory.rc:224:    chown system system /sys/class/timed_output/vibrator/enable
android/device/xxx/common/rootdir/etc/init.xxx.factory.rc:237:    chown system system /sys/class/timed_output/vibrator/enable
android/system/core/rootdir/init.rc:565:    chown system system /sys/class/timed_output/vibrator/enable
android/system/core/rootdir/init.rc:577:    chown system system /sys/class/timed_output/vibrator/enable
android/system/sepolicy/dumpstate.te:87:# /sys/class/timed_output/vibrator/enable

一、ramdisk介绍

ramdisk通过直面意思就大概能理解意思,ram disk虚拟内存盘,将ram模拟成硬盘来使用的文件系统。对于传统的磁盘文件系统来说,这样做的好处是可以极大提高文件访问速度;但由于是ram,所以在掉电后,这部分内容不能保存。ramdisk文件系统是在系统上电后直接从磁盘一次性加载到内存,在整个运行期间都不会有写回操作,所以,任何修改都掉电后丢失。

二、ramdisk.img介绍

ramdisk.img是编译Android生成的一个镜像文件,最后和kernel一起打包生成boot.img镜像。ramdisk.img中主要是存放android启动后第一个用户进程init可执行文件和init.*.rc等相关启动脚本以及sbin目录下的adbd工具。如下图所示


ramdisk.img是将上图目录打包压缩而来的,我们可以通过下面命令,来解压出其中的内容
首先使用file命令查看ramdisk.img文件类型

[python] view plain copy

  1. file ramdisk.img  

[python] view plain copy

  1. ramdisk.img: gzip compressed data, from Unix  
  2. 看出为gzip压缩过的文件,将ramdisk.img重命名为ramdisk.img.gz  

[python] view plain copy

  1. mv ramdisk.img ramdisk.img.gz  

[python] view plain copy

  1. 再用file来看一下ramdisk.img,此时为  
  2. ramdisk.img: ASCII cpio archive (SVR4 with no CRC)  
  3. 这时候使用cpio来提取ramdisk.img中的内容  

[python] view plain copy

  1. mkdir temp  
  2. cp temp  
  3. cpio -i -F ../ramdisk.img  


android的init.rc脚本就是ramdisk一个例子,在板子上修改是没有用的,重启丢失,只有修改device/平台/../init.rc然后重新make bootimage重新生产boot.img烧录到板子上才能修改成功


 

猜你喜欢

转载自blog.csdn.net/lf12345678910/article/details/77993762