1
0
forked from BRT/arc

Add ADB utilities with platform-specific support

Introduce ADB utilities for executing commands like taking XML dumps from connected devices. Refactor the `takeXmlDump` method to dynamically determine the ADB path based on the platform. Include ADB tools and necessary files for both Windows and macOS in the build system.
This commit is contained in:
slava 2025-06-11 16:21:13 +07:00
parent f70b46ce44
commit b8b2b38f8a
10 changed files with 43 additions and 14 deletions

View File

@ -81,6 +81,7 @@ if (WIN32)
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/images" DESTINATION "${CMAKE_BINARY_DIR}") file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/images" DESTINATION "${CMAKE_BINARY_DIR}")
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/rus.traineddata" DESTINATION "${CMAKE_BINARY_DIR}") file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/rus.traineddata" DESTINATION "${CMAKE_BINARY_DIR}")
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/config.ini" DESTINATION "${CMAKE_BINARY_DIR}") file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/config.ini" DESTINATION "${CMAKE_BINARY_DIR}")
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tools/adb/windows" DESTINATION "${CMAKE_BINARY_DIR}/tools/adb")
elseif (APPLE) elseif (APPLE)
target_link_libraries(ARCDesktopProject target_link_libraries(ARCDesktopProject

View File

@ -2,10 +2,19 @@
#include <QProcess> #include <QProcess>
#include <qDebug> #include <qDebug>
#include <QString> #include <QString>
#include <QCoreApplication>
AdbUtils::AdbUtils(QObject *parent) : QObject(parent) { AdbUtils::AdbUtils(QObject *parent) : QObject(parent) {
} }
QString AdbUtils::adbPath() {
#ifdef Q_OS_WIN
return QCoreApplication::applicationDirPath() + "/tools/adb/adb.exe";
#else
return QCoreApplication::applicationDirPath() + "/tools/adb/macos/adb";
#endif
}
// adb shell dumpsys package ru.rshb.dbo | grep permission // adb shell dumpsys package ru.rshb.dbo | grep permission
// TODO доделать обработку пермишинов // TODO доделать обработку пермишинов
// adb shell pm revoke ru.rshb.dbo android.permission.WRITE_CONTACTS; adb shell pm revoke ru.rshb.dbo android.permission.READ_CONTACTS; adb shell pm revoke ru.rshb.dbo android.permission.ACCESS_COARSE_LOCATION; adb shell pm revoke ru.rshb.dbo android.permission.ACCESS_FINE_LOCATION // adb shell pm revoke ru.rshb.dbo android.permission.WRITE_CONTACTS; adb shell pm revoke ru.rshb.dbo android.permission.READ_CONTACTS; adb shell pm revoke ru.rshb.dbo android.permission.ACCESS_COARSE_LOCATION; adb shell pm revoke ru.rshb.dbo android.permission.ACCESS_FINE_LOCATION
@ -154,16 +163,30 @@ bool AdbUtils::takeScreenshot(const QString &deviceId, const QString &name) {
} }
bool AdbUtils::takeXmlDump(const QString &deviceId, const QString &name) { bool AdbUtils::takeXmlDump(const QString &deviceId, const QString &name) {
const QString adb = adbPath();
QStringList commands = {
QString("%1 -s %2 shell uiautomator dump /sdcard/uidump.xml").arg(adb, deviceId),
QString("%1 -s %2 pull /sdcard/uidump.xml %3.xml").arg(adb, deviceId, name),
QString("%1 -s %2 shell cat /sdcard/uidump.xml").arg(adb, deviceId),
QString("%1 -s %2 shell rm /sdcard/uidump.xml").arg(adb, deviceId)
};
for (const QString &cmd: commands) {
QProcess process; QProcess process;
QString xml = QString( #ifdef Q_OS_WIN
"adb -s %1 shell 'uiautomator dump /sdcard/uidump.xml' && " process.start("cmd.exe", {"/C", cmd});
"adb -s %1 pull /sdcard/uidump.xml %2.xml && " #else
"adb -s %1 shell 'cat /sdcard/uidump.xml' && " process.start("sh", {"-c", cmd});
"adb -s %1 shell 'rm /sdcard/uidump.xml'" #endif
).arg(deviceId, name); if (!process.waitForFinished() ||
process.start("sh", {"-c", xml}); process.exitStatus() != QProcess::NormalExit ||
process.waitForFinished(); process.exitCode() != 0) {
return process.exitStatus() == QProcess::NormalExit && process.exitCode() == 0; qWarning() << "ADB command failed:" << cmd;
return false;
}
}
return true;
} }
bool AdbUtils::makeTap(const QString &deviceId, const int x, const int y) { bool AdbUtils::makeTap(const QString &deviceId, const int x, const int y) {
@ -256,7 +279,7 @@ QSet<QString> AdbUtils::getListApps(const QString &deviceId) {
const QString output = process.readAllStandardOutput(); const QString output = process.readAllStandardOutput();
QSet<QString> apps; QSet<QString> apps;
const QStringList lines = output.split('\n'); const QStringList lines = output.split("\n");
for (int i = 0; i < lines.size(); ++i) { for (int i = 0; i < lines.size(); ++i) {
QString line = lines.at(i).trimmed().replace("package:", ""); QString line = lines.at(i).trimmed().replace("package:", "");

View File

@ -9,6 +9,8 @@ class AdbUtils final : public QObject {
public: public:
explicit AdbUtils(QObject *parent = nullptr); explicit AdbUtils(QObject *parent = nullptr);
static QString adbPath();
static QList<QPair<QString, QString> > getListDevices(); static QList<QPair<QString, QString> > getListDevices();
static QString tryToGetRunningAppPid(const QString &deviceId, const QString &packageName); static QString tryToGetRunningAppPid(const QString &deviceId, const QString &packageName);

View File

@ -16,6 +16,7 @@
#include <QFile> #include <QFile>
#include "EventHandler.h" #include "EventHandler.h"
#include "adb/AdbUtils.h"
#include "net/NetworkService.h" #include "net/NetworkService.h"
#include "rshb/GetLastDaysHistoryScript.h" #include "rshb/GetLastDaysHistoryScript.h"
#include "rshb/HomeScreenScript.h" #include "rshb/HomeScreenScript.h"
@ -144,9 +145,11 @@ int main(int argc, char *argv[]) {
// 79641815146 - Мама Альфа // 79641815146 - Мама Альфа
// 79199196105 - Папа рсхб // 79199196105 - Папа рсхб
startNetworkService(app); // startNetworkService(app);
startDeviceScreener(app); // startDeviceScreener(app);
startEventHandler(app); // startEventHandler(app);
AdbUtils::takeXmlDump("29301FDH20036X", "test");
MainWindow window; MainWindow window;
window.show(); window.show();

BIN
tools/adb/macos/adb Executable file

Binary file not shown.

BIN
tools/adb/macos/libc++.dylib Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
tools/adb/windows/adb.exe Normal file

Binary file not shown.

Binary file not shown.