我想在启动时执行一个可执行文件,在具有Android 5.1 的目标板上,因此我将其添加到init.rc中:

on boot
    start myservice

service myservice /system/bin/myservice
    #class main
    user root
    group root
    #oneshot

我做了拆包和重新包装的工作。
但是,进行更改后,屏幕将继续打印:
 init warning: Service myservice needs a SELinux domain defined. Please fix.
 type=1400 ... avc:denied ... scontext ... tcontext ... #some annoying warning messages like this

SELinux对我来说似乎是一个巨大的项目。我只是想避免这种情况。我尝试了两种方法:
1. setenv kernelargs 'console=ttyS0,115200n8 rootdelay=1 selinux=0' and saveenv
2. set enforce 0

对于方法1,printenv给出结果:
kernelargs=console=ttyS0,115200n8 rootdelay=1 selinux=0

如此看来,已经进行了更改。但是,重新启动后,警告消息仍会继续打印。
对于方法2,它说:
Could not set enforce status. Permission denied.

所以现在我陷入了困境,不知道该去哪里。我的问题:
  • 有人知道如何在android中禁用或设置许可模式吗?
  • 如果要为新服务定义域,应该修改哪些文件?

  • 此外,ls -Z /system/bin/myservice还提供了以下内容:
    u:object_r:system_file:s0
    

    最佳答案

  • 您需要su来设置许可模式。或者,您需要源代码来禁用SELinux,例如在内核配置中禁用SELinux,或在device/vendor_name/product_name/BoardConfig.mk中的BOARD_KERNEL_CMDLINE中禁用SELinux。
  • 如果您有源代码,则可以根据需要定义新域。

  • 请引用Android官方文件:https://source.android.com/security/selinux/device-policy

    部分:标记新服务并解决拒绝问题

    10-08 02:45