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

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


相关文章
电力规约DL/T 654 2007多功能电表通信协议 调试工具
电力规约DL/T 654 2007多功能电表通信协议 调试工具
238 1
|
安全 API 开发工具
oss加密的配置方法
阿里云OSS提供多种加密选项:SSE-OSS(默认或对象级AES-256加密)、SSE-KMS(使用KMS托管CMK)、临时密钥加密和客户端加密(CSE)。可通过控制台或API设置Bucket策略,使用HTTP头部指定加密方式。KMS和临时密钥可能涉及更复杂的密钥管理和权限配置。
1311 5
|
存储 PyTorch 算法框架/工具
Transformers 4.37 中文文档(二十七)(2)
Transformers 4.37 中文文档(二十七)
231 0
|
8月前
|
数据采集 数据可视化 机器人
FastGPT 社区版快速部署指南
FastGPT 是一款基于大语言模型的智能知识库系统,具备开箱即用、可视化编排和多场景适配(客服机器人、知识检索等)的核心能力。通过阿里云计算巢,用户可在 2-3 分钟内完成快速部署,实现复杂问答逻辑设计与高效数据处理。
|
机器学习/深度学习 搜索推荐 TensorFlow
使用Python实现智能电子商务推荐系统:深度学习模型详解
使用Python实现智能电子商务推荐系统:深度学习模型详解
711 4
|
8月前
|
存储 大数据 数据处理
您有一份 Apache Flink 社区年度报告请查收~
您有一份 Apache Flink 社区年度报告请查收~
135 0
|
存储 安全 区块链
智能合约开发中13种最常见的漏洞
智能合约开发中13种最常见的漏洞
1370 5
|
消息中间件 存储 SQL
RocketMQ与Kafka架构深度对比
RocketMQ与Kafka架构深度对比
|
存储 JSON 小程序
微信小程序的资源引用方式
微信小程序的资源引用方式
1544 0