Commit 04ea1898 authored by Daniel Teske's avatar Daniel Teske

Android: Search for a suitable emulator before starting a new avd

Note, that we don't know the names of the started avds, so we look
for a avd that has the same abi and apiLevel.

Task-number: QTCREATORBUG-10411
Change-Id: I5f6ff3ee0dddcf2bb8fca981ccedf437e32da677
Reviewed-by: default avatarBogDan Vatra <bogdan@kde.org>
parent 3e789de3
......@@ -621,7 +621,7 @@ QVector<AndroidDeviceInfo> AndroidConfigurations::androidVirtualDevices() const
QString AndroidConfigurations::startAVD(const QString &name, int apiLevel, QString cpuAbi) const
{
if (startAVDAsync(name))
if (findAvd(apiLevel, cpuAbi) || startAVDAsync(name))
return waitForAvd(apiLevel, cpuAbi);
return QString();
}
......@@ -643,6 +643,21 @@ bool AndroidConfigurations::startAVDAsync(const QString &avdName) const
return true;
}
bool AndroidConfigurations::findAvd(int apiLevel, const QString &cpuAbi) const
{
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;
return true;
}
return false;
}
QString AndroidConfigurations::waitForAvd(int apiLevel, const QString &cpuAbi) const
{
// we cannot use adb -e wait-for-device, since that doesn't work if a emulator is already running
......
......@@ -106,6 +106,7 @@ public:
QVector<AndroidDeviceInfo> androidVirtualDevices() const;
QString startAVD(const QString &name, int apiLevel, QString cpuAbi) const;
bool startAVDAsync(const QString &avdName) const;
bool findAvd(int apiLevel, const QString &cpuAbi) const;
QString waitForAvd(int apiLevel, const QString &cpuAbi) const;
QString bestNdkPlatformMatch(const QString &targetAPI) const;
......
......@@ -287,7 +287,8 @@ bool AndroidDeployQtStep::init()
if (!result)
return false;
AndroidConfigurations::instance().startAVDAsync(m_avdName);
if (!AndroidConfigurations::instance().findAvd(m_deviceAPILevel, m_targetArch))
AndroidConfigurations::instance().startAVDAsync(m_avdName);
return true;
}
......
......@@ -389,7 +389,8 @@ void AndroidDeployStep::deployFiles(QProcess *process, const QList<DeployItem> &
bool AndroidDeployStep::deployPackage()
{
if (!m_avdName.isEmpty()) {
if (!AndroidConfigurations::instance().startAVDAsync(m_avdName))
if (!AndroidConfigurations::instance().findAvd(m_deviceAPILevel, m_targetArch)
&& !AndroidConfigurations::instance().startAVDAsync(m_avdName))
return false;
m_deviceSerialNumber = AndroidConfigurations::instance().waitForAvd(m_deviceAPILevel, m_targetArch);
}
......
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