Skip to content
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

refactor: 重构 adb argv 并为所有参数添加默认值 #107

Merged
merged 7 commits into from
Nov 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions sample/cpp/main.cpp
Original file line number Diff line number Diff line change
@@ -24,8 +24,8 @@ int main([[maybe_unused]] int argc, char** argv)
{
MaaToolKitInit();

// auto controller_handle = create_adb_controller();
auto controller_handle = create_win32_controller();
auto controller_handle = create_adb_controller();
// auto controller_handle = create_win32_controller();
auto ctrl_id = MaaControllerPostConnection(controller_handle);

auto resource_handle = MaaResourceCreate(nullptr, nullptr);
@@ -46,12 +46,12 @@ int main([[maybe_unused]] int argc, char** argv)
MaaToolKitUninit();
};

// if (!MaaInited(maa_handle)) {
// std::cout << "Failed to init MAA" << std::endl;
if (!MaaInited(maa_handle)) {
std::cout << "Failed to init MAA" << std::endl;

// destroy();
// return -1;
//}
destroy();
return -1;
}

register_my_recognizer(maa_handle);

4 changes: 0 additions & 4 deletions source/MaaAdbControlUnit/API/AdbControlUnitAPI.cpp
Original file line number Diff line number Diff line change
@@ -102,10 +102,6 @@ MaaControlUnitHandle MaaAdbControlUnitCreate( //
switch (screencap_type) {
case MaaAdbControllerType_Screencap_FastestWay:
LogInfo << "screencap_type: ScreencapFastestWay";
if (!std::filesystem::exists(minicap_path)) {
LogError << "minicap path not exists" << VAR(minicap_path);
return nullptr;
}
screencap_unit = std::make_shared<ScreencapFastestWay>(minicap_path);
break;
case MaaAdbControllerType_Screencap_RawByNetcat:
5 changes: 0 additions & 5 deletions source/MaaAdbControlUnit/Manager/ControlUnitMgr.cpp
Original file line number Diff line number Diff line change
@@ -218,11 +218,6 @@ bool ControlUnitMgr::parse(const json::value& config)
{
bool ret = true;

if (config.get("NotParse", false)) {
LogWarn << "NotParse";
return true;
}

ret &= connection_.parse(config);
ret &= device_info_.parse(config);
ret &= activity_.parse(config);
12 changes: 10 additions & 2 deletions source/MaaAdbControlUnit/Screencap/FastestWay.cpp
Original file line number Diff line number Diff line change
@@ -15,10 +15,18 @@ ScreencapFastestWay::ScreencapFastestWay(const std::filesystem::path& minicap_pa
{ Method::RawWithGzip, std::make_shared<ScreencapRawWithGzip>() },
{ Method::Encode, std::make_shared<ScreencapEncode>() },
{ Method::EncodeToFileAndPull, std::make_shared<ScreencapEncodeToFileAndPull>() },
{ Method::MinicapDirect, std::make_shared<MinicapDirect>(minicap_path) },
{ Method::MinicapStream, std::make_shared<MinicapStream>(minicap_path) },
};

if (std::filesystem::exists(minicap_path)) {
units_.merge(decltype(units_) {
{ Method::MinicapDirect, std::make_shared<MinicapDirect>(minicap_path) },
{ Method::MinicapStream, std::make_shared<MinicapStream>(minicap_path) },
});
}
else {
LogWarn << "minicap path not exists" << VAR(minicap_path);
}

for (auto pair : units_) {
children_.emplace_back(pair.second);
}
193 changes: 1 addition & 192 deletions source/MaaToolKit/AdbDevice/AdbConfigDef.hpp
Original file line number Diff line number Diff line change
@@ -9,197 +9,6 @@
MAA_TOOLKIT_DEVICE_NS_BEGIN

using namespace json::literals;
inline static const json::value kAdbConfig = R"(
{
"prebuilt": {
"minicap": {
"arch": [
"x86",
"armeabi-v7a",
"armeabi"
],
"sdk": [
31, 29, 28, 27, 26, 25, 24, 23, 22, 21, 19, 18, 17, 16, 15, 14
]
},
"minitouch": {
"arch": [
"x86_64",
"x86",
"arm64-v8a",
"armeabi-v7a",
"armeabi"
]
},
"maatouch": {
"package": "com.shxyke.MaaTouch.App"
}
},
"command": {
"Devices": [
"{ADB}",
"devices"
],
"Connect": [
"{ADB}",
"connect",
"{ADB_SERIAL}"
],
"KillServer": [
"{ADB}",
"kill-server"
],
"UUID": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"shell",
"settings get secure android_id"
],
"Resolution": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"shell",
"dumpsys window displays | grep -o -E cur=+[^\\ ]+ | grep -o -E [0-9]+"
],
"StartApp": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"shell",
"am start -n {INTENT}"
],
"StopApp": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"shell",
"am force-stop {INTENT}"
],
"Click": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"shell",
"input tap {X} {Y}"
],
"Swipe": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"shell",
"input swipe {X1} {Y1} {X2} {Y2} {DURATION}"
],
"PressKey": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"shell",
"input keyevent {KEY}"
],
"ForwardSocket": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"forward",
"tcp:{FOWARD_PORT}",
"localabstract:{LOCAL_SOCKET}"
],
"NetcatAddress": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"shell",
"cat /proc/net/arp | grep : "
],
"ScreencapRawByNetcat": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"exec-out",
"screencap | nc -w 3 {NETCAT_ADDRESS} {NETCAT_PORT}"
],
"ScreencapRawWithGzip": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"exec-out",
"screencap | gzip -1"
],
"ScreencapEncode": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"exec-out",
"screencap -p"
],
"ScreencapEncodeToFile": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"shell",
"screencap -p > \"/data/local/tmp/{TEMP_FILE}\""
],
"PullFile": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"pull",
"/data/local/tmp/{TEMP_FILE}",
"{DST_PATH}"
],
"Abilist": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"shell",
"getprop ro.product.cpu.abilist | tr -d '\n\r'"
],
"SDK": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"shell",
"getprop ro.build.version.sdk | tr -d '\n\r'"
],
"Orientation": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"shell",
"dumpsys input | grep SurfaceOrientation | grep -m 1 -o -E [0-9]"
],
"PushBin": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"push",
"{BIN_PATH}",
"/data/local/tmp/{BIN_WORKING_FILE}"
],
"ChmodBin": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"shell",
"chmod 700 \"/data/local/tmp/{BIN_WORKING_FILE}\""
],
"InvokeBin": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"shell",
"export LD_LIBRARY_PATH=/data/local/tmp/; \"/data/local/tmp/{BIN_WORKING_FILE}\" {BIN_EXTRA_PARAMS} 2>&1"
],
"InvokeApp": [
"{ADB}",
"-s",
"{ADB_SERIAL}",
"shell",
"export CLASSPATH=\"/data/local/tmp/{APP_WORKING_FILE}\"; app_process /data/local/tmp {PACKAGE_NAME}"
]
}
})"_json;
inline static const json::value kAdbConfig = "{}"_json;

MAA_TOOLKIT_DEVICE_NS_END
17 changes: 11 additions & 6 deletions test/dlopen/main.cpp
Original file line number Diff line number Diff line change
@@ -5,19 +5,22 @@
int main()
{
#ifdef WITH_ADB_CONTROLLER
auto adb_type = MaaAdbControllerType_Input_Preset_Adb | MaaAdbControllerType_Screencap_FastestWay;
std::cout << "********** AdbControlUnitLibraryHolder::create_control_unit **********" << std::endl;
auto adb_handle = MAA_NS::AdbControlUnitLibraryHolder::create_control_unit(
"adb", "127.0.0.1:5555", 0, R"({"NotParse":true})", "./", nullptr, nullptr);
auto adb_handle = MAA_NS::AdbControlUnitLibraryHolder::create_control_unit("adb", "127.0.0.1:5555", adb_type, "{}",
"./", nullptr, nullptr);
if (!adb_handle) {
std::cerr << "Failed to create adb control unit" << std::endl;
return -1;
}
#endif

#ifdef WITH_WIN32_CONTROLLER
auto win32_type = MaaWin32ControllerType_Touch_SendMessage | MaaWin32ControllerType_Key_SendMessage |
MaaWin32ControllerType_Screencap_GDI;
std::cout << "********** Win32ControlUnitLibraryHolder::create_control_unit **********" << std::endl;
auto win32_handle =
MAA_NS::Win32ControlUnitLibraryHolder::create_control_unit(FindWindowA(nullptr, nullptr), 0, nullptr, nullptr);
auto win32_handle = MAA_NS::Win32ControlUnitLibraryHolder::create_control_unit(FindWindowA(nullptr, nullptr),
win32_type, nullptr, nullptr);
if (!win32_handle) {
std::cerr << "Failed to create win32 control unit" << std::endl;
return -1;
@@ -26,7 +29,8 @@ int main()

#ifdef WITH_THRIFT_CONTROLLER
std::cout << "********** ThriftControlUnitLibraryHolder::create_control_unit **********" << std::endl;
auto thrift_handle = MAA_NS::ThriftControlUnitLibraryHolder::create_control_unit(1, "127.0.0.1", 8080, "{}");
auto thrift_handle = MAA_NS::ThriftControlUnitLibraryHolder::create_control_unit(MaaThriftControllerType_Socket,
"127.0.0.1", 8080, "{}");
if (!thrift_handle) {
std::cerr << "Failed to create thrift control unit" << std::endl;
return -1;
@@ -35,7 +39,8 @@ int main()

#ifdef WITH_DBG_CONTROLLER
std::cout << "********** DbgControlUnitLibraryHolder::create_control_unit **********" << std::endl;
auto dbg_handle = MAA_NS::DbgControlUnitLibraryHolder::create_control_unit(1, "./");
auto dbg_handle =
MAA_NS::DbgControlUnitLibraryHolder::create_control_unit(MaaDbgControllerType_CarouselImage, "./");
if (!dbg_handle) {
std::cerr << "Failed to create dbg control unit" << std::endl;
return -1;