aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/android/androiddevice.cpp
diff options
context:
space:
mode:
authorJarek Kobus <[email protected]>2023-10-05 11:50:59 +0200
committerJarek Kobus <[email protected]>2023-10-06 15:27:28 +0000
commitfbe23282fc39e4084699d5ce5079d7f700b19369 (patch)
treeb90565a8c678e8a5c0d731ddc35b55ca4967d54a /src/plugins/android/androiddevice.cpp
parent162f9f59d778697357e2aae80706fc920787abcf (diff)
AndroidDeviceManager: Execute avd removal in main thread
Instead of executing it blocking in a separate thread. Change-Id: I0d847f22917edc9782467f173728c13287844acb Reviewed-by: Alessandro Portale <[email protected]> Reviewed-by: <[email protected]>
Diffstat (limited to 'src/plugins/android/androiddevice.cpp')
-rw-r--r--src/plugins/android/androiddevice.cpp46
1 files changed, 21 insertions, 25 deletions
diff --git a/src/plugins/android/androiddevice.cpp b/src/plugins/android/androiddevice.cpp
index 08dc2ca0d15..23cfa76592f 100644
--- a/src/plugins/android/androiddevice.cpp
+++ b/src/plugins/android/androiddevice.cpp
@@ -474,14 +474,27 @@ void AndroidDeviceManager::eraseAvd(const IDevice::Ptr &device, QWidget *parent)
return;
qCDebug(androidDeviceLog) << QString("Erasing Android AVD \"%1\" from the system.").arg(name);
- m_removeAvdFutureWatcher.setFuture(Utils::asyncRun([this, name, device] {
- QPair<IDevice::ConstPtr, bool> pair;
- pair.first = device;
- pair.second = false;
- if (m_avdManager.removeAvd(name))
- pair.second = true;
- return pair;
- }));
+ m_removeAvdProcess.reset(new Process);
+ const AndroidConfig &config = m_avdManager.config();
+ const CommandLine command(config.avdManagerToolPath(), {"delete", "avd", "-n", name});
+ qCDebug(androidDeviceLog).noquote() << "Running command (removeAvd):" << command.toUserOutput();
+ m_removeAvdProcess->setTimeoutS(5);
+ m_removeAvdProcess->setEnvironment(config.toolsEnvironment());
+ m_removeAvdProcess->setCommand(command);
+ connect(m_removeAvdProcess.get(), &Process::done, this, [this, device] {
+ const QString name = device->displayName();
+ if (m_removeAvdProcess->result() == ProcessResult::FinishedWithSuccess) {
+ qCDebug(androidDeviceLog, "Android AVD id \"%s\" removed from the system.",
+ qPrintable(name));
+ // Remove the device from QtC after it's been removed using avdmanager.
+ DeviceManager::instance()->removeDevice(device->id());
+ } else {
+ AndroidDeviceWidget::criticalDialog(Tr::tr("An error occurred while removing the "
+ "Android AVD \"%1\" using avdmanager tool.").arg(name));
+ }
+ m_removeAvdProcess.release()->deleteLater();
+ });
+ m_removeAvdProcess->start();
}
void AndroidDeviceManager::setupWifiForDevice(const IDevice::Ptr &device, QWidget *parent)
@@ -544,20 +557,6 @@ void AndroidDeviceManager::setupWifiForDevice(const IDevice::Ptr &device, QWidge
});
}
-void AndroidDeviceManager::handleAvdRemoved()
-{
- const QPair<IDevice::ConstPtr, bool> result = m_removeAvdFutureWatcher.result();
- const QString name = result.first->displayName();
- if (result.second) {
- qCDebug(androidDeviceLog, "Android AVD id \"%s\" removed from the system.", qPrintable(name));
- // Remove the device from QtC after it's been removed using avdmanager.
- DeviceManager::instance()->removeDevice(result.first->id());
- } else {
- AndroidDeviceWidget::criticalDialog(Tr::tr("An error occurred while removing the "
- "Android AVD \"%1\" using avdmanager tool.").arg(name));
- }
-}
-
QString AndroidDeviceManager::emulatorName(const QString &serialNumber) const
{
QStringList args = AndroidDeviceInfo::adbSelector(serialNumber);
@@ -819,8 +818,6 @@ AndroidDeviceManager::AndroidDeviceManager(QObject *parent)
m_androidConfig(AndroidConfigurations::currentConfig()),
m_avdManager(m_androidConfig)
{
- connect(&m_removeAvdFutureWatcher, &QFutureWatcherBase::finished,
- this, &AndroidDeviceManager::handleAvdRemoved);
QTC_ASSERT(!s_instance, return);
s_instance = this;
}
@@ -828,7 +825,6 @@ AndroidDeviceManager::AndroidDeviceManager(QObject *parent)
AndroidDeviceManager::~AndroidDeviceManager()
{
m_avdsFutureWatcher.waitForFinished();
- m_removeAvdFutureWatcher.waitForFinished();
QTC_ASSERT(s_instance == this, return);
s_instance = nullptr;
}