赞
踩
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; }
同级目录(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)
添加编译rk3399\device\rockchip\rk3399\rk3399\device.mk
最后一行添加
PRODUCT_PACKAGES += helloword
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
3、添加权限rk3399\system\sepolicy\vendor\file_contexts
文件最后面空一行添加
/system/bin/helloword u:object_r:helloword_exec:s0
同级目录(rk3399\system\sepolicy\vendor)创建文件helloword.te
type helloword, domain, coredomain;
type helloword_exec, exec_type, file_type;
init_daemon_domain(helloword)
开机查看到服务已经启动: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
命令查看服务已经running:
console:/ $ getprop | grep "helloword"
[init.svc.helloword]: [running]
[ro.boottime.helloword]: [9042863759]
console:/ $
查看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 !
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。