Andrid 7.1 启动init.rc中自定义service

平台:

RK3288 + Android7.12

问题:

无法启动init.rc中新增的服务.

步骤:

新增服务

|–system/extras/info-service/Android.mk

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_CFLAGS := -std=c11 -Wall
#-Wmacro-redefined -Wunused-parameter -Wunused-variable
LOCAL_SRC_FILES:= infoservice.cpp
LOCAL_MODULE:= infoservice
LOCAL_SHARED_LIBRARIES := \
    libcutils \
    liblog \
	libc \
	libm
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
LOCAL_MODULE_TAGS := debug

include $(BUILD_EXECUTABLE)

|–system/extras/info-service/infoservice.cpp

#define LOG_TAG "InfoService"
#include <errno.h>
#include <error.h>
#include <getopt.h>
#include <paths.h>
#include <pwd.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <utils/Log.h>

char configFile[] = "/data/system/device.cfg";
char profile[] = "/data/profile";

int main(int argc, char** argv) {
    ALOGI("start Info Service");
}

在init.rc中添服务
|–device/rockchip/rk3288/init.rk3288.rc

 on verity-logging
     exec u:r:slideshow:s0 -- /sbin/slideshow warning/verity_red_1 warning/verity_red_2
+
+service infoservice /system/xbin/infoservice
+    class core
+    user root
+    group root system
+    disabled
+    oneshot

尝试启动服务:

setprop ctl.start infoservice
服务无法启动!

查看LOG:

[   58.364922] init: ALog Starting 'infoservice'...
[   58.365266] init: Service infoservice does not have a SELinux domain defined.

SELinux无法找到自定义服务的域定义.

解决:

参考bootanimation的源码:

新增文件:

|–system/sepolicy/infoservice.te

type infoservice, domain;
type infoservice_exec, exec_type, file_type;

init_daemon_domain(infoservice)

修改文件如下:

|–system/sepolicy/file_contexts

 /system/bin/sh         --      u:object_r:shell_exec:s0
 /system/bin/run-as     --      u:object_r:runas_exec:s0
 /system/bin/bootanimation u:object_r:bootanim_exec:s0
+/system/xbin/infoservice u:object_r:infoservice_exec:s0
 /system/bin/bootstat           u:object_r:bootstat_exec:s0
 /system/bin/app_process32      u:object_r:zygote_exec:s0
 /system/bin/app_process64      u:object_r:zygote_exec:s0

|–system/sepolicy/property.te

 type vold_prop, property_type, core_property_type;
 type wifi_log_prop, property_type, log_property_type;
 type ctl_bootanim_prop, property_type;
+type ctl_infoservice_prop, property_type;
 type ctl_default_prop, property_type;
 type ctl_dumpstate_prop, property_type;
 type ctl_fuse_prop, property_type;

|–system/sepolicy/property_contexts

 # ctl properties
 ctl.bootanim            u:object_r:ctl_bootanim_prop:s0
+ctl.infoservice         u:object_r:ctl_infoservice_prop:s0
 ctl.dumpstate           u:object_r:ctl_dumpstate_prop:s0
 ctl.fuse_               u:object_r:ctl_fuse_prop:s0
 ctl.mdnsd               u:object_r:ctl_mdnsd_prop:s0

编译system/sepolicy, 打包烧录, 问题解决!

猜你喜欢

转载自blog.csdn.net/ansondroider/article/details/85317627
7.1
今日推荐