forked from qt-creator/qt-creator
Android: Replace QFutureInterfaceBase with QFuture<void>
In case a passed future interface is used only for checking for cancel, use QFuture<void> instead. This will properly integrate with QPromise API. Change-Id: I33e5e9c62dbcfb1f7aa71eace6158e5b7c0a7098 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -14,21 +14,17 @@
|
|||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
#include <utils/runextensions.h>
|
#include <utils/runextensions.h>
|
||||||
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QSettings>
|
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
namespace Android::Internal {
|
namespace Android::Internal {
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
const int avdCreateTimeoutMs = 30000;
|
const int avdCreateTimeoutMs = 30000;
|
||||||
|
|
||||||
static Q_LOGGING_CATEGORY(avdManagerLog, "qtc.android.avdManager", QtWarningMsg)
|
static Q_LOGGING_CATEGORY(avdManagerLog, "qtc.android.avdManager", QtWarningMsg)
|
||||||
@@ -228,7 +224,7 @@ QString AndroidAvdManager::startAvd(const QString &name) const
|
|||||||
{
|
{
|
||||||
if (!findAvd(name).isEmpty() || startAvdAsync(name))
|
if (!findAvd(name).isEmpty() || startAvdAsync(name))
|
||||||
return waitForAvd(name);
|
return waitForAvd(name);
|
||||||
return QString();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is32BitUserSpace()
|
static bool is32BitUserSpace()
|
||||||
@@ -301,21 +297,21 @@ QString AndroidAvdManager::findAvd(const QString &avdName) const
|
|||||||
if (device.avdName == avdName)
|
if (device.avdName == avdName)
|
||||||
return device.serialNumber;
|
return device.serialNumber;
|
||||||
}
|
}
|
||||||
return QString();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
QString AndroidAvdManager::waitForAvd(const QString &avdName,
|
QString AndroidAvdManager::waitForAvd(const QString &avdName,
|
||||||
const QFutureInterfaceBase &fi) const
|
const std::optional<QFuture<void>> &future) const
|
||||||
{
|
{
|
||||||
// we cannot use adb -e wait-for-device, since that doesn't work if a emulator is already running
|
// 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
|
// 60 rounds of 2s sleeping, two minutes for the avd to start
|
||||||
QString serialNumber;
|
QString serialNumber;
|
||||||
for (int i = 0; i < 60; ++i) {
|
for (int i = 0; i < 60; ++i) {
|
||||||
if (fi.isCanceled())
|
if (future && future->isCanceled())
|
||||||
return {};
|
return {};
|
||||||
serialNumber = findAvd(avdName);
|
serialNumber = findAvd(avdName);
|
||||||
if (!serialNumber.isEmpty())
|
if (!serialNumber.isEmpty())
|
||||||
return waitForBooted(serialNumber, fi) ? serialNumber : QString();
|
return waitForBooted(serialNumber, future) ? serialNumber : QString();
|
||||||
QThread::sleep(2);
|
QThread::sleep(2);
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
@@ -339,11 +335,11 @@ bool AndroidAvdManager::isAvdBooted(const QString &device) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool AndroidAvdManager::waitForBooted(const QString &serialNumber,
|
bool AndroidAvdManager::waitForBooted(const QString &serialNumber,
|
||||||
const QFutureInterfaceBase &fi) const
|
const std::optional<QFuture<void>> &future) const
|
||||||
{
|
{
|
||||||
// found a serial number, now wait until it's done booting...
|
// found a serial number, now wait until it's done booting...
|
||||||
for (int i = 0; i < 60; ++i) {
|
for (int i = 0; i < 60; ++i) {
|
||||||
if (fi.isCanceled())
|
if (future && future->isCanceled())
|
||||||
return false;
|
return false;
|
||||||
if (isAvdBooted(serialNumber))
|
if (isAvdBooted(serialNumber))
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -4,8 +4,9 @@
|
|||||||
|
|
||||||
#include "androidconfigurations.h"
|
#include "androidconfigurations.h"
|
||||||
|
|
||||||
#include <functional>
|
#include <QFuture>
|
||||||
#include <memory>
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace Android::Internal {
|
namespace Android::Internal {
|
||||||
|
|
||||||
@@ -22,14 +23,14 @@ public:
|
|||||||
QString startAvd(const QString &name) const;
|
QString startAvd(const QString &name) const;
|
||||||
bool startAvdAsync(const QString &avdName) const;
|
bool startAvdAsync(const QString &avdName) const;
|
||||||
QString findAvd(const QString &avdName) const;
|
QString findAvd(const QString &avdName) const;
|
||||||
QString waitForAvd(const QString &avdName, const QFutureInterfaceBase &fi = {}) const;
|
QString waitForAvd(const QString &avdName, const std::optional<QFuture<void>> &future = {}) const;
|
||||||
bool isAvdBooted(const QString &device) const;
|
bool isAvdBooted(const QString &device) const;
|
||||||
static bool avdManagerCommand(const AndroidConfig &config,
|
static bool avdManagerCommand(const AndroidConfig &config,
|
||||||
const QStringList &args,
|
const QStringList &args,
|
||||||
QString *output);
|
QString *output);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool waitForBooted(const QString &serialNumber, const QFutureInterfaceBase &fi = {}) const;
|
bool waitForBooted(const QString &serialNumber, const std::optional<QFuture<void>> &future = {}) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const AndroidConfig &m_config;
|
const AndroidConfig &m_config;
|
||||||
|
|||||||
@@ -404,7 +404,8 @@ void AndroidDeployQtStep::slotAskForUninstall(DeployErrorCode errorCode)
|
|||||||
void AndroidDeployQtStep::runImpl(QFutureInterface<bool> &fi)
|
void AndroidDeployQtStep::runImpl(QFutureInterface<bool> &fi)
|
||||||
{
|
{
|
||||||
if (!m_avdName.isEmpty()) {
|
if (!m_avdName.isEmpty()) {
|
||||||
QString serialNumber = AndroidAvdManager().waitForAvd(m_avdName, fi);
|
const QString serialNumber = AndroidAvdManager().waitForAvd(m_avdName,
|
||||||
|
QFuture<void>(fi.future()));
|
||||||
qCDebug(deployStepLog) << "Deploying to AVD:" << m_avdName << serialNumber;
|
qCDebug(deployStepLog) << "Deploying to AVD:" << m_avdName << serialNumber;
|
||||||
if (serialNumber.isEmpty()) {
|
if (serialNumber.isEmpty()) {
|
||||||
reportWarningOrError(Tr::tr("The deployment AVD \"%1\" cannot be started.")
|
reportWarningOrError(Tr::tr("The deployment AVD \"%1\" cannot be started.")
|
||||||
|
|||||||
Reference in New Issue
Block a user