Implemented `CommonScript` as a base class with reusable functionality for automation workflows, including PIN input, app navigation, and server communication. Added specialized scripts like `GetCardInfoScript`, `GetProfileInfoScript`, and `LoginAndCheckAccountsScript` for card retrieval, profile parsing, and login validation. Introduced `ScreenXmlParser` for efficient XML-based UI parsing and node detection.
65 lines
2.2 KiB
C++
65 lines
2.2 KiB
C++
#include "LoginAndCheckAccountsScript.h"
|
||
|
||
#include <QThread>
|
||
|
||
#include "adb/AdbUtils.h"
|
||
#include "dao/ApplicationDAO.h"
|
||
#include "dao/DeviceDAO.h"
|
||
#include "AppLogger.h"
|
||
#include "GetProfileInfoScript.h"
|
||
|
||
namespace Black {
|
||
|
||
LoginAndCheckAccountsScript::LoginAndCheckAccountsScript(
|
||
QString deviceId,
|
||
QString appCode,
|
||
QObject *parent
|
||
) : CommonScript(parent),
|
||
m_deviceId(std::move(deviceId)),
|
||
m_appCode(std::move(appCode)) {
|
||
}
|
||
|
||
LoginAndCheckAccountsScript::~LoginAndCheckAccountsScript() = default;
|
||
|
||
void LoginAndCheckAccountsScript::doStart() {
|
||
const DeviceInfo device = DeviceDAO::getDeviceById(m_deviceId);
|
||
const ApplicationInfo app = ApplicationDAO::getApplication(m_deviceId, 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 (!runAppAndGoToHomeScreen(device.id, app.package, app.pinCode, device.screenWidth, device.screenHeight)) {
|
||
m_error = "Cant open the home screen: " + m_deviceId + " " + m_appCode;
|
||
qWarning() << m_error;
|
||
AppLogger::log("black/LoginAndCheck", m_deviceId, m_error,
|
||
AdbUtils::captureScreenshotBytes(m_deviceId),
|
||
"FETCH_PROFILE");
|
||
if (!ApplicationDAO::updatePinCodeStatus(app.id, "no", "Не прошла проверка [дата]")) {
|
||
qWarning() << "Cant update the pincode: " << m_deviceId << " " << m_appCode;
|
||
}
|
||
|
||
AdbUtils::tryToKillApplication(m_deviceId, app.package);
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
}
|
||
|
||
// PIN-код прошёл
|
||
if (!ApplicationDAO::updatePinCodeStatus(app.id, "yes", "")) {
|
||
qWarning() << "Cant update the pincode: " << m_deviceId << " " << m_appCode;
|
||
}
|
||
|
||
// Проверяем профиль и аккаунты (приложение уже на home screen)
|
||
GetProfileInfoScript profileScript(m_deviceId, m_appCode);
|
||
profileScript.start();
|
||
|
||
emit finishedWithResult(m_error);
|
||
}
|
||
|
||
} // namespace Black
|