Commit e79cdc16 authored by Daniel Teske's avatar Daniel Teske

Android: Rewrite waitForAvd()

Now takes a QFutureInterface to enable canceling and beautify the code
by splitting it up.

Change-Id: Ifedf19c3ad1a37a9b7cb6b7db8ec799ceebc5392
Reviewed-by: default avatarEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
parent adc25d1e
......@@ -659,32 +659,45 @@ QString AndroidConfigurations::findAvd(int apiLevel, const QString &cpuAbi) cons
return QString();
}
QString AndroidConfigurations::waitForAvd(int apiLevel, const QString &cpuAbi) const
bool AndroidConfigurations::isConnected(const QString &serialNumber) const
{
// we cannot use adb -e wait-for-device, since that doesn't work if a emulator is already running
QVector<AndroidDeviceInfo> devices = connectedDevices();
foreach (AndroidDeviceInfo device, devices) {
if (device.serialNumber == serialNumber)
return true;
}
return false;
}
bool AndroidConfigurations::waitForBooted(const QString &serialNumber, const QFutureInterface<bool> &fi) const
{
// found a serial number, now wait until it's done booting...
for (int i = 0; i < 60; ++i) {
if (fi.isCanceled())
return false;
if (hasFinishedBooting(serialNumber)) {
return true;
} else {
Utils::sleep(2000);
if (!isConnected(serialNumber)) // device was disconnected
return false;
}
}
return false;
}
// 15 rounds of 8s sleeping, a minute for the avd to start
QString AndroidConfigurations::waitForAvd(int apiLevel, const QString &cpuAbi, const QFutureInterface<bool> &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 < 15; ++i) {
QVector<AndroidDeviceInfo> devices = connectedDevices();
foreach (AndroidDeviceInfo device, devices) {
if (!device.serialNumber.startsWith(QLatin1String("emulator")))
continue;
if (!device.cpuAbi.contains(cpuAbi))
continue;
if (device.sdk != apiLevel)
continue;
serialNumber = device.serialNumber;
// found a serial number, now wait until it's done booting...
for (int i = 0; i < 15; ++i) {
if (hasFinishedBooting(serialNumber))
return serialNumber;
else
Utils::sleep(8000);
}
for (int i = 0; i < 60; ++i) {
if (fi.isCanceled())
return QString();
}
Utils::sleep(8000);
serialNumber = findAvd(apiLevel, cpuAbi);
if (!serialNumber.isEmpty())
return waitForBooted(serialNumber, fi) ? serialNumber : QString();
Utils::sleep(2000);
}
return QString();
}
......
......@@ -36,6 +36,7 @@
#include <QVector>
#include <QHash>
#include <QMap>
#include <QFutureInterface>
#include <projectexplorer/abi.h>
#include <utils/fileutils.h>
......@@ -107,7 +108,8 @@ public:
QString startAVD(const QString &name, int apiLevel, QString cpuAbi) const;
bool startAVDAsync(const QString &avdName) const;
QString findAvd(int apiLevel, const QString &cpuAbi) const;
QString waitForAvd(int apiLevel, const QString &cpuAbi) const;
QString waitForAvd(int apiLevel, const QString &cpuAbi, const QFutureInterface<bool> &fi = QFutureInterface<bool>()) const;
// special version for AndroidDeployQt::run
QString bestNdkPlatformMatch(const QString &targetAPI) const;
QStringList makeExtraSearchDirectories() const;
......@@ -121,6 +123,8 @@ public:
QString getProductModel(const QString &device) const;
bool hasFinishedBooting(const QString &device) const;
bool waitForBooted(const QString &serialNumber, const QFutureInterface<bool> &fi) const;
bool isConnected(const QString &serialNumber) const;
AndroidDeviceInfo showDeviceDialog(ProjectExplorer::Project *project, int apiLevel, const QString &abi);
void setDefaultDevice(ProjectExplorer::Project *project, const QString &abi, const QString &serialNumber); // serial number or avd name
......
......@@ -295,7 +295,7 @@ bool AndroidDeployQtStep::init()
void AndroidDeployQtStep::run(QFutureInterface<bool> &fi)
{
if (!m_avdName.isEmpty()) {
QString serialNumber = AndroidConfigurations::instance().waitForAvd(m_deviceAPILevel, m_targetArch);
QString serialNumber = AndroidConfigurations::instance().waitForAvd(m_deviceAPILevel, m_targetArch, fi);
if (serialNumber.isEmpty()) {
fi.reportResult(false);
return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment