#include "GetProfileInfoScript.h" #include #include #include #include "adb/AdbUtils.h" #include "dao/MaterialDAO.h" #include "dao/BankProfileDAO.h" #include "dao/DeviceDAO.h" #include "net/NetworkService.h" namespace Dushanbe { GetProfileInfoScript::GetProfileInfoScript( QString deviceId, QString appCode, QObject *parent ) : CommonScript(parent), m_deviceId(std::move(deviceId)), m_appCode(std::move(appCode)) { } GetProfileInfoScript::~GetProfileInfoScript() = default; void GetProfileInfoScript::doStart() { DeviceInfo device = DeviceDAO::getDeviceById(m_deviceId); if (device.id.isEmpty()) device = DeviceDAO::findByAdbSerial(m_deviceId); if (!device.adbSerial.isEmpty()) m_deviceId = device.adbSerial; const BankProfileInfo app = BankProfileDAO::getApplication(device.id, m_appCode); if (device.id.isEmpty() || app.id == -1) { m_error = "Device or app not found: " + m_deviceId + " " + m_appCode; qCritical() << m_error; emit finishedWithResult(m_error); return; } xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter)); if (!xmlScreenParser.isHomeScreen()) { qDebug() << "[Dushanbe::GetProfileInfo] Not on home screen, restarting app..."; if (!runAppAndGoToHomeScreen(m_deviceId, app.package, app.pinCode, device.screenWidth, device.screenHeight)) { m_error = "Cannot reach home screen: " + m_deviceId + " " + m_appCode; qWarning() << m_error; AdbUtils::tryToKillApplication(m_deviceId, app.package); emit finishedWithResult(m_error); return; } xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter)); } // Парсим баланс с домашнего экрана const double balance = xmlScreenParser.parseBalanceFromHomeScreen(); qDebug() << "[Dushanbe::GetProfileInfo] balance:" << balance; BankProfileDAO::updateAmount(app.id, balance); // Тапаем по кнопке меню (гамбургер, левый верхний угол) // Это первый clickable ImageView в верхней панели Node menuButton; for (const Node &node : xmlScreenParser.findAllNodes()) { if (node.className == "android.widget.ImageView" && node.clickable && node.y() < 300) { menuButton = node; break; } } if (menuButton.x() == 0 && menuButton.y() == 0) { m_error = "Cannot find menu button: " + m_deviceId; qWarning() << m_error; AdbUtils::tryToKillApplication(m_deviceId, app.package); emit finishedWithResult(m_error); return; } AdbUtils::makeTap(m_deviceId, menuButton.x(), menuButton.y()); QThread::msleep(2000); // Ждём боковое меню bool sideMenuFound = false; for (int attempt = 0; attempt < 5; ++attempt) { xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter)); if (xmlScreenParser.isSideMenu()) { sideMenuFound = true; break; } QThread::msleep(1000); } if (!sideMenuFound) { m_error = "Side menu not detected: " + m_deviceId; qWarning() << m_error; AdbUtils::tryToKillApplication(m_deviceId, app.package); emit finishedWithResult(m_error); return; } // Парсим ФИО и телефон из бокового меню const QString fullName = xmlScreenParser.parseProfileFullName(); const QString phone = xmlScreenParser.parseProfilePhone(); qDebug() << "[Dushanbe::GetProfileInfo] fullName:" << fullName << "phone:" << phone; if (!fullName.isEmpty()) { BankProfileDAO::updateProfileInfo(app.id, fullName, phone, ""); } createBankProfileIfNeeded(device.id, m_appCode); const QList allAccounts = MaterialDAO::getAccounts(device.id, m_appCode); QList> accountsToPost; for (const auto &acc : allAccounts) { if (acc.materialId.isEmpty()) { accountsToPost.append({acc, Node()}); } } if (!accountsToPost.isEmpty()) { postAccountsData(accountsToPost); } emit finishedWithResult(m_error); } } // namespace Dushanbe