-
Notifications
You must be signed in to change notification settings - Fork 411
feat: Android Native Controller #933
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f263c37
fd064af
e56c514
ca88c03
a5568c3
574642e
2b15225
8c77ae6
05fd127
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -46,6 +46,27 @@ By default, all methods except `RawByNetcat`, `MinicapDirect`, and `MinicapStrea | |||||||||
| | MinicapStream | `32` | Takes streaming screenshots and encodes to jpg via minicap tool, transfers via adb process pipe. | | ||||||||||
| | EmulatorExtras | `64` | Uses emulator-specific tools for screenshots. Currently supported emulators: MuMu 12, LDPlayer 9 | | ||||||||||
|
|
||||||||||
| ## Android | ||||||||||
|
|
||||||||||
| ### Android Input | ||||||||||
|
|
||||||||||
| > Reference: `MaaAndroidInputMethod`. | ||||||||||
|
|
||||||||||
| | Name | Value | Description | | ||||||||||
| | --- | --- | --- | | ||||||||||
| | Accessibility | `1` | Uses accessibility service for control, including `dispatchGesture` for tap/swipe/scroll, global actions for key events (back/home/recents), and `ACTION_SET_TEXT` on current focused input node. | | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (typo): 将 "current focused" 改为 "currently focused" 以符合正确的语法 将 "on current focused input node" 修改为 "on the currently focused input node",以保证语法正确且表达更清晰。
Suggested change
Original comment in Englishissue (typo): Use "currently focused" instead of "current focused" for correct grammar. Change "on current focused input node" to "on the currently focused input node" for correct grammar and clarity.
Suggested change
|
||||||||||
|
|
||||||||||
| ### Android Screencap | ||||||||||
|
|
||||||||||
| > Reference: `MaaAndroidScreencapMethod`. | ||||||||||
|
|
||||||||||
| Combine the selected methods below using **bitwise OR**. Framework will choose available ones, preferring MediaProjection (faster and more stable), then AccessibilityScreenshot. | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (typo): 建议在 "Framework will choose available ones" 中补充冠词,使语句更顺畅 可以改成这样以使表达更自然且语法完整:"The framework will choose the available ones, preferring MediaProjection …"。
Suggested change
Original comment in Englishsuggestion (typo): Consider adding an article to "Framework will choose available ones" for smoother phrasing. You could rephrase to: "The framework will choose the available ones, preferring MediaProjection …" for more natural, grammatically complete wording.
Suggested change
|
||||||||||
|
|
||||||||||
| | Name | Value | Description | | ||||||||||
| | --- | --- | --- | | ||||||||||
| | AccessibilityScreenshot | `1` | API 33+ accessibility `takeScreenshot`. No extra permission required, but needs Android 13 or above. | | ||||||||||
| | MediaProjection | `2` | MediaProjection virtual display screenshot, requires user consent. Faster and better compatibility. | | ||||||||||
|
|
||||||||||
| ## Win32 | ||||||||||
|
|
||||||||||
| ### Win32 Input | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -249,6 +249,27 @@ typedef uint64_t MaaAdbInputMethod; | |||||||||
| #define MaaAdbInputMethod_All (~MaaAdbInputMethod_None) | ||||||||||
| #define MaaAdbInputMethod_Default (MaaAdbInputMethod_All & (~MaaAdbInputMethod_EmulatorExtras)) | ||||||||||
|
|
||||||||||
| // MaaAndroidScreencapMethod: | ||||||||||
| /** | ||||||||||
| * Use bitwise OR to set the method you need, MaaFramework will test their availability. | ||||||||||
| */ | ||||||||||
| typedef uint64_t MaaAndroidScreencapMethod; | ||||||||||
| #define MaaAndroidScreencapMethod_None 0ULL | ||||||||||
| /// API 33+ AccessibilityService.takeScreenshot | ||||||||||
| #define MaaAndroidScreencapMethod_AccessibilityScreenshot 1ULL | ||||||||||
| /// MediaProjection VirtualDisplay capture (requires user consent) | ||||||||||
| #define MaaAndroidScreencapMethod_MediaProjection (1ULL << 1) | ||||||||||
| #define MaaAndroidScreencapMethod_All (~MaaAndroidScreencapMethod_None) | ||||||||||
| #define MaaAndroidScreencapMethod_Default (MaaAndroidScreencapMethod_AccessibilityScreenshot | MaaAndroidScreencapMethod_MediaProjection) | ||||||||||
|
|
||||||||||
| // MaaAndroidInputMethod: | ||||||||||
| /** | ||||||||||
| * Use bitwise OR to set the method you need. | ||||||||||
| */ | ||||||||||
| typedef uint64_t MaaAndroidInputMethod; | ||||||||||
| #define MaaAndroidInputMethod_None 0ULL | ||||||||||
| #define MaaAndroidInputMethod_Accessibility 1ULL | ||||||||||
|
Comment on lines
+269
to
+271
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): 定义 MaaAndroidInputMethod_All 和 MaaAndroidInputMethod_Default 以与模块导出和用法保持一致
#define MaaAndroidInputMethod_All (~MaaAndroidInputMethod_None)
#define MaaAndroidInputMethod_Default MaaAndroidInputMethod_Accessibility或者使用你偏好的语义),以保证 C API 与模块导出保持一致。 Original comment in Englishissue (bug_risk): Define MaaAndroidInputMethod_All and MaaAndroidInputMethod_Default to match module exports and usage
#define MaaAndroidInputMethod_All (~MaaAndroidInputMethod_None)
#define MaaAndroidInputMethod_Default MaaAndroidInputMethod_Accessibilityor whatever semantics you prefer) so the C API and module exports remain consistent.
|
||||||||||
| #define MaaAndroidInputMethod_Accessibility 1ULL | |
| #define MaaAndroidInputMethod_Accessibility 1ULL | |
| #define MaaAndroidInputMethod_All (~MaaAndroidInputMethod_None) | |
| #define MaaAndroidInputMethod_Default MaaAndroidInputMethod_Accessibility |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #include "ControlUnit/AndroidControlUnitAPI.h" | ||
|
|
||
| #include <meojson/json.hpp> | ||
|
|
||
| #include "MaaUtils/Logger.h" | ||
| #include "Manager/AndroidControlUnitMgr.h" | ||
|
|
||
| const char* MaaAndroidControlUnitGetVersion() | ||
| { | ||
| #pragma message("MaaAndroidControlUnit MAA_VERSION: " MAA_VERSION) | ||
|
|
||
| return MAA_VERSION; | ||
| } | ||
|
|
||
| MaaAndroidControlUnitHandle MaaAndroidControlUnitCreate( | ||
| MaaAndroidScreencapMethod screencap_methods, | ||
| MaaAndroidInputMethod input_methods) | ||
| { | ||
| using namespace MAA_CTRL_UNIT_NS; | ||
|
|
||
| LogFunc << VAR(screencap_methods) << VAR(input_methods); | ||
|
|
||
| auto unit_mgr = std::make_unique<AndroidControlUnitMgr>(screencap_methods, input_methods); | ||
|
|
||
| return unit_mgr.release(); | ||
| } | ||
|
|
||
| void MaaAndroidControlUnitDestroy(MaaAndroidControlUnitHandle handle) | ||
| { | ||
| LogFunc << VAR_VOIDP(handle); | ||
|
|
||
| if (handle) { | ||
| delete handle; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| if(NOT ANDROID) | ||
| message(STATUS "MaaAndroidControlUnit skipped: not on Android") | ||
| return() | ||
| endif() | ||
|
|
||
| file(GLOB_RECURSE maa_android_control_unit_src *.h *.hpp *.cpp) | ||
| file(GLOB_RECURSE maa_android_control_unit_header ${MAA_PRIVATE_INC}/ControlUnit/AndroidControlUnitAPI.h ${MAA_PRIVATE_INC}/ControlUnit/ControlUnitAPI.h) | ||
|
|
||
| add_library(MaaAndroidControlUnit SHARED ${maa_android_control_unit_src} ${maa_android_control_unit_header}) | ||
|
|
||
| target_include_directories(MaaAndroidControlUnit | ||
| PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${MAA_PRIVATE_INC} ${MAA_PUBLIC_INC}) | ||
|
|
||
| target_compile_definitions(MaaAndroidControlUnit PRIVATE MAA_CONTROL_UNIT_EXPORTS) | ||
|
|
||
| target_link_libraries(MaaAndroidControlUnit | ||
| PRIVATE MaaUtils HeaderOnlyLibraries ${OpenCV_LIBS} log jnigraphics android) | ||
|
|
||
| add_dependencies(MaaAndroidControlUnit MaaUtils) | ||
|
|
||
| install( | ||
| TARGETS MaaAndroidControlUnit | ||
| RUNTIME DESTINATION bin | ||
| LIBRARY DESTINATION bin | ||
| # ARCHIVE DESTINATION lib | ||
| ) | ||
|
|
||
| source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${maa_android_control_unit_src}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation mentions a
configparameter that doesn't exist in the actual API signature. TheMaaAndroidControllerCreatefunction only takesscreencap_methodsandinput_methodsparameters, not aconfigparameter.