forked from qt-creator/qt-creator
AndroidDeployQtStep: Make it cancelable
And use QFutureInterface for it. Change-Id: I1145b70b119d92af7316977c813f4f29b1f20b74 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -291,20 +291,20 @@ QString AndroidAvdManager::findAvd(const QString &avdName) const
|
||||
}
|
||||
|
||||
QString AndroidAvdManager::waitForAvd(const QString &avdName,
|
||||
const std::function<bool()> &cancelChecker) const
|
||||
const QFutureInterfaceBase &fi) const
|
||||
{
|
||||
// we cannot use adb -e wait-for-device, since that doesn't work if a emulator is already running
|
||||
// 60 rounds of 2s sleeping, two minutes for the avd to start
|
||||
QString serialNumber;
|
||||
for (int i = 0; i < 60; ++i) {
|
||||
if (cancelChecker && cancelChecker())
|
||||
return QString();
|
||||
if (fi.isCanceled())
|
||||
return {};
|
||||
serialNumber = findAvd(avdName);
|
||||
if (!serialNumber.isEmpty())
|
||||
return waitForBooted(serialNumber, cancelChecker) ? serialNumber : QString();
|
||||
return waitForBooted(serialNumber, fi) ? serialNumber : QString();
|
||||
QThread::sleep(2);
|
||||
}
|
||||
return QString();
|
||||
return {};
|
||||
}
|
||||
|
||||
bool AndroidAvdManager::isAvdBooted(const QString &device) const
|
||||
@@ -325,11 +325,11 @@ bool AndroidAvdManager::isAvdBooted(const QString &device) const
|
||||
}
|
||||
|
||||
bool AndroidAvdManager::waitForBooted(const QString &serialNumber,
|
||||
const std::function<bool()> &cancelChecker) const
|
||||
const QFutureInterfaceBase &fi) const
|
||||
{
|
||||
// found a serial number, now wait until it's done booting...
|
||||
for (int i = 0; i < 60; ++i) {
|
||||
if (cancelChecker && cancelChecker())
|
||||
if (fi.isCanceled())
|
||||
return false;
|
||||
if (isAvdBooted(serialNumber))
|
||||
return true;
|
||||
|
@@ -22,16 +22,14 @@ public:
|
||||
QString startAvd(const QString &name) const;
|
||||
bool startAvdAsync(const QString &avdName) const;
|
||||
QString findAvd(const QString &avdName) const;
|
||||
QString waitForAvd(const QString &avdName,
|
||||
const std::function<bool()> &cancelChecker = {}) const;
|
||||
QString waitForAvd(const QString &avdName, const QFutureInterfaceBase &fi = {}) const;
|
||||
bool isAvdBooted(const QString &device) const;
|
||||
static bool avdManagerCommand(const AndroidConfig &config,
|
||||
const QStringList &args,
|
||||
QString *output);
|
||||
|
||||
private:
|
||||
bool waitForBooted(const QString &serialNumber,
|
||||
const std::function<bool()> &cancelChecker) const;
|
||||
bool waitForBooted(const QString &serialNumber, const QFutureInterfaceBase &fi = {}) const;
|
||||
|
||||
private:
|
||||
const AndroidConfig &m_config;
|
||||
|
@@ -3,16 +3,14 @@
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "androidavdmanager.h"
|
||||
#include "androidbuildapkstep.h"
|
||||
#include "androidconstants.h"
|
||||
#include "androiddeployqtstep.h"
|
||||
#include "androiddevice.h"
|
||||
#include "androidglobal.h"
|
||||
#include "androidmanager.h"
|
||||
#include "androidqtversion.h"
|
||||
#include "androidtr.h"
|
||||
#include "androidtr.h"
|
||||
#include "certificatesmodel.h"
|
||||
#include "javaparser.h"
|
||||
|
||||
#include <coreplugin/fileutils.h>
|
||||
#include <coreplugin/icore.h>
|
||||
@@ -35,6 +33,7 @@
|
||||
#include <utils/layoutbuilder.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/runextensions.h>
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QFileDialog>
|
||||
@@ -402,15 +401,16 @@ void AndroidDeployQtStep::slotAskForUninstall(DeployErrorCode errorCode)
|
||||
m_askForUninstall = button == QMessageBox::Yes;
|
||||
}
|
||||
|
||||
bool AndroidDeployQtStep::runImpl()
|
||||
void AndroidDeployQtStep::runImpl(QFutureInterface<bool> &fi)
|
||||
{
|
||||
if (!m_avdName.isEmpty()) {
|
||||
QString serialNumber = AndroidAvdManager().waitForAvd(m_avdName, cancelChecker());
|
||||
QString serialNumber = AndroidAvdManager().waitForAvd(m_avdName, fi);
|
||||
qCDebug(deployStepLog) << "Deploying to AVD:" << m_avdName << serialNumber;
|
||||
if (serialNumber.isEmpty()) {
|
||||
reportWarningOrError(Tr::tr("The deployment AVD \"%1\" cannot be started.")
|
||||
.arg(m_avdName), Task::Error);
|
||||
return false;
|
||||
fi.reportResult(false);
|
||||
return;
|
||||
}
|
||||
m_serialNumber = serialNumber;
|
||||
qCDebug(deployStepLog) << "Deployment device serial number changed:" << serialNumber;
|
||||
@@ -445,8 +445,7 @@ bool AndroidDeployQtStep::runImpl()
|
||||
reportWarningOrError(error, Task::Error);
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue == NoError;
|
||||
fi.reportResult(returnValue == NoError);
|
||||
}
|
||||
|
||||
void AndroidDeployQtStep::gatherFilesToPull()
|
||||
@@ -480,7 +479,20 @@ void AndroidDeployQtStep::gatherFilesToPull()
|
||||
|
||||
void AndroidDeployQtStep::doRun()
|
||||
{
|
||||
m_synchronizer.addFuture(runInThread([this] { return runImpl(); }));
|
||||
auto * const watcher = new QFutureWatcher<bool>(this);
|
||||
connect(watcher, &QFutureWatcher<bool>::finished, this, [this, watcher] {
|
||||
const bool success = !watcher->isCanceled() && watcher->result();
|
||||
emit finished(success);
|
||||
watcher->deleteLater();
|
||||
});
|
||||
auto future = Utils::runAsync(&AndroidDeployQtStep::runImpl, this);
|
||||
watcher->setFuture(future);
|
||||
m_synchronizer.addFuture(future);
|
||||
}
|
||||
|
||||
void AndroidDeployQtStep::doCancel()
|
||||
{
|
||||
m_synchronizer.cancelAllFutures();
|
||||
}
|
||||
|
||||
void AndroidDeployQtStep::runCommand(const CommandLine &command)
|
||||
|
@@ -4,8 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "androidbuildapkstep.h"
|
||||
#include "androidconfigurations.h"
|
||||
#include "androiddeviceinfo.h"
|
||||
|
||||
#include <projectexplorer/abstractprocessstep.h>
|
||||
#include <qtsupport/baseqtversion.h>
|
||||
@@ -49,11 +48,12 @@ private:
|
||||
|
||||
bool init() override;
|
||||
void doRun() override;
|
||||
void doCancel() override;
|
||||
void gatherFilesToPull();
|
||||
DeployErrorCode runDeploy();
|
||||
void slotAskForUninstall(DeployErrorCode errorCode);
|
||||
|
||||
bool runImpl();
|
||||
void runImpl(QFutureInterface<bool> &fi);
|
||||
|
||||
QWidget *createConfigWidget() override;
|
||||
|
||||
|
@@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "androidconfigurations.h"
|
||||
#include "androidbuildapkstep.h"
|
||||
#include "androidconstants.h"
|
||||
#include "androiddebugsupport.h"
|
||||
#include "androiddeployqtstep.h"
|
||||
|
Reference in New Issue
Block a user