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:
parent
f70b46ce44
commit
b8b2b38f8a
@ -81,6 +81,7 @@ if (WIN32)
|
||||
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}/config.ini" DESTINATION "${CMAKE_BINARY_DIR}")
|
||||
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tools/adb/windows" DESTINATION "${CMAKE_BINARY_DIR}/tools/adb")
|
||||
|
||||
elseif (APPLE)
|
||||
target_link_libraries(ARCDesktopProject
|
||||
|
||||
@ -2,10 +2,19 @@
|
||||
#include <QProcess>
|
||||
#include <qDebug>
|
||||
#include <QString>
|
||||
#include <QCoreApplication>
|
||||
|
||||
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
|
||||
// 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
|
||||
@ -154,16 +163,30 @@ bool AdbUtils::takeScreenshot(const QString &deviceId, const QString &name) {
|
||||
}
|
||||
|
||||
bool AdbUtils::takeXmlDump(const QString &deviceId, const QString &name) {
|
||||
QProcess process;
|
||||
QString xml = QString(
|
||||
"adb -s %1 shell 'uiautomator dump /sdcard/uidump.xml' && "
|
||||
"adb -s %1 pull /sdcard/uidump.xml %2.xml && "
|
||||
"adb -s %1 shell 'cat /sdcard/uidump.xml' && "
|
||||
"adb -s %1 shell 'rm /sdcard/uidump.xml'"
|
||||
).arg(deviceId, name);
|
||||
process.start("sh", {"-c", xml});
|
||||
process.waitForFinished();
|
||||
return process.exitStatus() == QProcess::NormalExit && process.exitCode() == 0;
|
||||
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;
|
||||
#ifdef Q_OS_WIN
|
||||
process.start("cmd.exe", {"/C", cmd});
|
||||
#else
|
||||
process.start("sh", {"-c", cmd});
|
||||
#endif
|
||||
if (!process.waitForFinished() ||
|
||||
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) {
|
||||
@ -256,7 +279,7 @@ QSet<QString> AdbUtils::getListApps(const QString &deviceId) {
|
||||
const QString output = process.readAllStandardOutput();
|
||||
QSet<QString> apps;
|
||||
|
||||
const QStringList lines = output.split('\n');
|
||||
const QStringList lines = output.split("\n");
|
||||
for (int i = 0; i < lines.size(); ++i) {
|
||||
QString line = lines.at(i).trimmed().replace("package:", "");
|
||||
|
||||
|
||||
@ -9,6 +9,8 @@ class AdbUtils final : public QObject {
|
||||
public:
|
||||
explicit AdbUtils(QObject *parent = nullptr);
|
||||
|
||||
static QString adbPath();
|
||||
|
||||
static QList<QPair<QString, QString> > getListDevices();
|
||||
|
||||
static QString tryToGetRunningAppPid(const QString &deviceId, const QString &packageName);
|
||||
|
||||
9
main.cpp
9
main.cpp
@ -16,6 +16,7 @@
|
||||
#include <QFile>
|
||||
|
||||
#include "EventHandler.h"
|
||||
#include "adb/AdbUtils.h"
|
||||
#include "net/NetworkService.h"
|
||||
#include "rshb/GetLastDaysHistoryScript.h"
|
||||
#include "rshb/HomeScreenScript.h"
|
||||
@ -144,9 +145,11 @@ int main(int argc, char *argv[]) {
|
||||
// 79641815146 - Мама Альфа
|
||||
// 79199196105 - Папа рсхб
|
||||
|
||||
startNetworkService(app);
|
||||
startDeviceScreener(app);
|
||||
startEventHandler(app);
|
||||
// startNetworkService(app);
|
||||
// startDeviceScreener(app);
|
||||
// startEventHandler(app);
|
||||
|
||||
AdbUtils::takeXmlDump("29301FDH20036X", "test");
|
||||
|
||||
MainWindow window;
|
||||
window.show();
|
||||
|
||||
BIN
tools/adb/macos/adb
Executable file
BIN
tools/adb/macos/adb
Executable file
Binary file not shown.
BIN
tools/adb/macos/libc++.dylib
Executable file
BIN
tools/adb/macos/libc++.dylib
Executable file
Binary file not shown.
BIN
tools/adb/windows/AdbWinApi.dll
Normal file
BIN
tools/adb/windows/AdbWinApi.dll
Normal file
Binary file not shown.
BIN
tools/adb/windows/AdbWinUsbApi.dll
Normal file
BIN
tools/adb/windows/AdbWinUsbApi.dll
Normal file
Binary file not shown.
BIN
tools/adb/windows/adb.exe
Normal file
BIN
tools/adb/windows/adb.exe
Normal file
Binary file not shown.
BIN
tools/adb/windows/libwinpthread-1.dll
Normal file
BIN
tools/adb/windows/libwinpthread-1.dll
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user