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

127 篇文章 34 订阅
1 篇文章 0 订阅

平台:

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, 打包烧录, 问题解决!

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值