当前位置:   article > 正文

RK3399-android9.0添加开机自启服务_init: could not start service '' as part of class

init: could not start service '' as part of class 'main':

1、创建rk3399\system\core\helloword\helloword.c

#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <termio.h>
#include <stdio.h>
#include <cutils/log.h>
#ifdef LOG_TAG
#undef LOG_TAG
#define LOG_TAG "HellowordService"
#endif 

int main(void)
{
    while(1)
    {
		ALOGE("hello word !\n");
        usleep(1000000);
		
    }
    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

同级目录(system\core\helloword)下创建Android.mk

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_SRC_FILES:= \
    helloword.c
LOCAL_C_INCLUDES += bionic \
$(call include-path-for, libhardware_legacy)/hardware_legacy
LOCAL_MODULE:=helloword
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_LIBRARIES := libfs_mgr libcutils libc liblog
LOCAL_SHARED_LIBRARIES := libhardware_legacy libnetutils liblog
include $(BUILD_EXECUTABLE)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

添加编译rk3399\device\rockchip\rk3399\rk3399\device.mk
最后一行添加

PRODUCT_PACKAGES += helloword
  • 1

2、添加系统服务rk3399\device\rockchip\common\init.rk30board.rc
文件最后面添加上:

service helloword /system/bin/helloword
	class main
	user root
	group root
	oneshot
	seclabel u:r:helloword:s0

on property:sys.boot_completed=1           
	chmod 0777 /system/bin/helloword 
	start helloword
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

3、添加权限rk3399\system\sepolicy\vendor\file_contexts
文件最后面空一行添加

/system/bin/helloword u:object_r:helloword_exec:s0 
  • 1

同级目录(rk3399\system\sepolicy\vendor)创建文件helloword.te

type helloword, domain, coredomain;
type helloword_exec, exec_type, file_type;
init_daemon_domain(helloword)
  • 1
  • 2
  • 3

开机查看到服务已经启动:init: starting service 'helloword'...

[    9.043655] init: starting service 'helloword'...
[    9.045210] init: Could not start service 'akmd' as part of class 'main': Cannot find '/system/bin/akmd': No such file or directory
[    9.045611] init: starting service 'zygote'...
[    9.047105] init: starting service 'zygote_secondary'...
[    9.048865] init: starting service 'cameraserver'...
[    9.048983] init: Created socket '/dev/socket/zygote_secondary', mode 660, user 0, group 1000
[    9.050020] init: couldn't write 381 to /dev/cpuset/camera-daemon/tasks: No such file or directory
[    9.051199] init: starting service 'drm'...
[    9.052423] init: Created socket '/dev/socket/zygote', mode 660, user 0, group 1000
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

命令查看服务已经running:

console:/ $ getprop | grep "helloword"                                         
[init.svc.helloword]: [running]
[ro.boottime.helloword]: [9042863759]
console:/ $
  • 1
  • 2
  • 3
  • 4

查看log:

console:/ $ logcat | grep "HellowordService"
05-05 15:02:37.195   378   378 E HellowordService: hello word !
05-05 15:02:38.195   378   378 E HellowordService: hello word !
05-05 15:02:39.195   378   378 E HellowordService: hello word !
05-05 15:02:40.196   378   378 E HellowordService: hello word !
05-05 15:02:41.196   378   378 E HellowordService: hello word !
05-05 15:02:42.196   378   378 E HellowordService: hello word !
05-05 15:02:43.196   378   378 E HellowordService: hello word !
05-05 15:02:44.197   378   378 E HellowordService: hello word !
05-05 15:02:45.197   378   378 E HellowordService: hello word !
05-05 15:02:46.197   378   378 E HellowordService: hello word !
05-05 15:02:47.198   378   378 E HellowordService: hello word !
05-05 15:02:48.198   378   378 E HellowordService: hello word !
05-05 15:02:49.199   378   378 E HellowordService: hello word !
05-05 15:02:50.199   378   378 E HellowordService: hello word !
05-05 15:02:51.199   378   378 E HellowordService: hello word !
05-05 15:02:52.200   378   378 E HellowordService: hello word !
05-05 15:02:53.200   378   378 E HellowordService: hello word !
05-05 15:02:54.201   378   378 E HellowordService: hello word !
05-05 15:02:55.201   378   378 E HellowordService: hello word !
05-05 15:02:56.202   378   378 E HellowordService: hello word !
05-05 15:02:57.202   378   378 E HellowordService: hello word !
05-05 15:03:01.204   378   378 E HellowordService: hello word !
05-05 15:03:02.204   378   378 E HellowordService: hello word !
05-05 15:03:03.205   378   378 E HellowordService: hello word !
05-05 15:03:04.205   378   378 E HellowordService: hello word !
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/273067
推荐阅读
相关标签
  

闽ICP备14008679号