android自動點擊的實現流程記錄

一個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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章