android自动点击的实现流程记录

来源:互联网 发布:万科股权之争 知乎 编辑:程序博客网 时间:2024/05/16 18:22
一个android下自动点击触屏的程序,类似于windows下的按键精灵,自动帮我玩捕鱼达人

目标:用户可以通过配置脚本文件,自定义一系列的操作,例如:点击/长按/拖动/延时/颜色判断/循环,然后用音量+/-键启动/关闭脚本

思路:

1.linux下做一个c程序gameplug.c,此程序负责读取配置文件,完成用户定义的一系列操作。

2.init.rc中添加服务,该服务启动gameplug.c

3.framework用音量+/-开启/关闭服务。

4.settings中增加gameplug的选项,打开后音量+/-键用作启动/关闭脚本服务,关闭后做正常音量+/-用



流程:

1.写好自己的linux服务程序

android\system\core\toolbox\gameplug.c

修改android\system\core\toolbox\Android.mk,增加gameplug.c的编译选项



2.制作libgameplug.so供上层调用
新建android\system\core\libgameplug\文件夹,增加gameplug.c和Android.mk,gameplug.c负责启动
android\system\core\include\gameplug\gameplug.h,和JNI的接口
自己添加的自定义so文件库在编译的时候出现以下错误
-----------------------------------------------------------------------------
build/core/base_rules.mk:78: *** Module name: libgameplug
build/core/base_rules.mk:79: *** Makefile location: system/ibcom/gameplug
build/core/base_rules.mk:80: *
build/core/base_rules.mk:81: * Each module must use a LOCAL_MODULE_TAGS in its
build/core/base_rules.mk:82: * Android.mk. Possible tags declared by a module:
build/core/base_rules.mk:83: *
build/core/base_rules.mk:84: * optional, debug, eng, tests, samples
build/core/base_rules.mk:85: *
build/core/base_rules.mk:86: * If the module is expected to be in all builds
build/core/base_rules.mk:87: * of a product, then it should use the
build/core/base_rules.mk:88: * "optional" tag:
build/core/base_rules.mk:89: *
build/core/base_rules.mk:90: * Add "LOCAL_MODULE_TAGS := optional" in the
build/core/base_rules.mk:91: * Android.mk for the affected module, and add
build/core/base_rules.mk:92: * the LOCAL_MODULE value for that component
build/core/base_rules.mk:93: * into the PRODUCT_PACKAGES section of product
build/core/base_rules.mk:94: * makefile(s) where it's necessary, if
build/core/base_rules.mk:95: * appropriate.
build/core/base_rules.mk:96: *
build/core/base_rules.mk:97: * If the component should be in EVERY build of ALL
build/core/base_rules.mk:98: * products, then add its LOCAL_MODULE value to the
build/core/base_rules.mk:99: * PRODUCT_PACKAGES section of
build/core/base_rules.mk:100: * build/target/product/core.mk
build/core/base_rules.mk:101: *
build/core/base_rules.mk:102: *** user tag detected on new module - user tags are only supported on legacy modules. Stop.
-----------------------------------------------------------------------------
需要在android\build\core\user_tags.mk中添加你在Android.mk中LOCAL_MODULE定义的名字
这里是LOCAL_MODULE := libgameplug

3.init.rc增加service gameplug
android\system\core\rootdir\init.rc
service gameplug /system/bin/gameplug
disabled
oneshot



4.注册framework层JNI接口函数

添加 android\frameworks\base\services\jni\com_android_server_GameplugService.cpp

修改 android\frameworks\base\services\jni\onload.cpp

修改 android\frameworks\base\services\jni\Android.mk

修改 android\frameworks\base\services\java\com\android\server\SystemServer.java

修改 android\frameworks\base\services\java\com\android\server\GameplugService.java

增加 android\frameworks\base\core\java\android\os\IGameplugService.aidl

修改 android\frameworks\base\Android.mk

5.控制,volume+ start , volume- stop
修改 android\frameworks\base\media\java\android\media\AudioManager.java

6.package/app/settings增加选项enable/disbale gameplug,打开此选项后音量+/-当启动/关闭gameplug用,关闭此项还做音量键使用

修改 android\packages\apps\Settings\res\values\strings.xml

修改 android\packages\apps\Settings\res\xml\display_settings.xml

修改 android\packages\apps\Settings\src\com\android\settings\DisplaySettings.java

修改 android\frameworks\base\core\java\android\provider\Settings.java



7.编译

make update-api
make android
原创粉丝点击