Earlier, I wrote a standalone daemon for accessing a user device (/ dev / mydev0). Looking at the source of AOSP, I decided that I needed the configuration policies in the following files to make it work:
A new device.te file containing:
type mydev_device, dev_type;
a new mydevsrvc.te file containing
# service flash_recovery in init.rc type mydevsrvc_type, domain; type mydevsrvc_type_exec, exec_type, file_type; init_daemon_domain(mydevsrvc_type) allow mydevsrvc_type mydev_device:chr_file rw_file_perms;
edited context_file to add:
/dev/mydev[0-9]* u:object_r:mydev_device:s0
edited service context to add:
mydevsrvc u:object_r:mydevsrvc_type:s0
And launched the daemon by editing init.flo.rc to include these lines:
service mydevsrvc /system/bin/mydevsrvc class main user system group system seclabel u:r:mydevsrvc_type:s0 oneshot
Now I need to access the device in Android applications, so I have to change the daemon to the Android system service.
I can start the service (thread) using the BOOT_COMPLETED intent, as described in the previous question
I cannot figure out how to configure SELinux policies so that this java service also has access to the dev file.
[Update] I continued to use the privileged daemon for this purpose. My java service connects to the daemon via sockets. I do not have a better solution.
android service android-source selinux
GPS
source share