forked from qt-creator/qt-creator
Android: Prevent deadlock
when emulator is closed before deployment is done Change-Id: I706f4c903dc229cffe2caef94f9e8cf89610ba4a Reviewed-by: BogDan Vatra <bog_dan_ro@yahoo.com> Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
committed by
Eike Ziller
parent
f542911896
commit
e29f800c07
@@ -520,9 +520,9 @@ QVector<AndroidDeviceInfo> AndroidConfigurations::androidVirtualDevices() const
|
|||||||
|
|
||||||
QString AndroidConfigurations::startAVD(int *apiLevel, const QString &name) const
|
QString AndroidConfigurations::startAVD(int *apiLevel, const QString &name) const
|
||||||
{
|
{
|
||||||
QProcess *m_avdProcess = new QProcess();
|
QProcess *avdProcess = new QProcess();
|
||||||
connect(this, SIGNAL(destroyed()), m_avdProcess, SLOT(deleteLater()));
|
connect(this, SIGNAL(destroyed()), avdProcess, SLOT(deleteLater()));
|
||||||
connect(m_avdProcess, SIGNAL(finished(int)), m_avdProcess, SLOT(deleteLater()));
|
connect(avdProcess, SIGNAL(finished(int)), avdProcess, SLOT(deleteLater()));
|
||||||
|
|
||||||
QString avdName = name;
|
QString avdName = name;
|
||||||
QVector<AndroidDeviceInfo> devices;
|
QVector<AndroidDeviceInfo> devices;
|
||||||
@@ -530,7 +530,7 @@ QString AndroidConfigurations::startAVD(int *apiLevel, const QString &name) cons
|
|||||||
while (true) {
|
while (true) {
|
||||||
if (avdName.isEmpty()) {
|
if (avdName.isEmpty()) {
|
||||||
devices = androidVirtualDevices();
|
devices = androidVirtualDevices();
|
||||||
foreach (AndroidDeviceInfo device, devices)
|
foreach (const AndroidDeviceInfo &device, devices)
|
||||||
if (device.sdk >= *apiLevel) { // take first emulator how supports this package
|
if (device.sdk >= *apiLevel) { // take first emulator how supports this package
|
||||||
*apiLevel = device.sdk;
|
*apiLevel = device.sdk;
|
||||||
avdName = device.serialNumber;
|
avdName = device.serialNumber;
|
||||||
@@ -551,20 +551,23 @@ QString AndroidConfigurations::startAVD(int *apiLevel, const QString &name) cons
|
|||||||
return avdName;
|
return avdName;
|
||||||
|
|
||||||
// start the emulator
|
// start the emulator
|
||||||
m_avdProcess->start(emulatorToolPath().toString(),
|
avdProcess->start(emulatorToolPath().toString(),
|
||||||
QStringList() << QLatin1String("-partition-size") << QString::number(config().partitionSize)
|
QStringList() << QLatin1String("-partition-size") << QString::number(config().partitionSize)
|
||||||
<< QLatin1String("-avd") << avdName);
|
<< QLatin1String("-avd") << avdName);
|
||||||
if (!m_avdProcess->waitForStarted(-1)) {
|
if (!avdProcess->waitForStarted(-1)) {
|
||||||
delete m_avdProcess;
|
delete avdProcess;
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait until the emulator is online
|
// wait until the emulator is online
|
||||||
QProcess proc;
|
QProcess proc;
|
||||||
proc.start(adbToolPath().toString(), QStringList() << QLatin1String("-e") << QLatin1String("wait-for-device"));
|
proc.start(adbToolPath().toString(), QStringList() << QLatin1String("-e") << QLatin1String("wait-for-device"));
|
||||||
if (!proc.waitForFinished(-1)) {
|
while (!proc.waitForFinished(500)) {
|
||||||
proc.terminate();
|
if (avdProcess->waitForFinished(0)) {
|
||||||
return QString();
|
proc.terminate();
|
||||||
|
proc.waitForFinished(-1);
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sleep(5);// wait for pm to start
|
sleep(5);// wait for pm to start
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user