Android: Add locking mechanism when creating avd

Lock avd file system watcher changes when executing create avd command.
Otherwise the avd file system watcher sends notifications during
create avd command execution and subsequent avd list command
doesn't report the device which is being added, yet.

Change-Id: I1a0123d1bf14cf76e3a90e7f19416eb634e9c4a6
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Jarek Kobus
2024-05-13 19:45:38 +02:00
parent e8060ba97e
commit 1ddcd8ad70
2 changed files with 7 additions and 2 deletions

View File

@@ -478,7 +478,7 @@ expected_str<void> AndroidDeviceManager::createAvd(const CreateAvdInfo &info, bo
}
});
using namespace std::chrono_literals;
GuardLocker locker(m_avdPathGuard);
process.runBlocking();
if (process.result() != ProcessResult::FinishedWithSuccess)
return Utils::make_unexpected(process.exitMessage());
@@ -696,8 +696,10 @@ void AndroidDeviceManager::setupDevicesWatcher()
const FilePath avdPath = FilePath::fromUserInput(avdEnvVar);
m_avdFileSystemWatcher.addPath(avdPath.toString());
connect(&m_avdsFutureWatcher, &QFutureWatcherBase::finished,
this, &AndroidDeviceManager::HandleAvdsListChange);
this, &AndroidDeviceManager::HandleAvdsListChange);
connect(&m_avdFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, [this] {
if (m_avdPathGuard.isLocked())
return;
// If the avd list upate command is running no need to call it again.
if (!m_avdsFutureWatcher.isRunning())
updateAvdsList();

View File

@@ -11,6 +11,8 @@
#include <projectexplorer/devicesupport/idevice.h>
#include <projectexplorer/devicesupport/idevicefactory.h>
#include <utils/guard.h>
#include <QFutureWatcher>
#include <QFileSystemWatcher>
#include <QSettings>
@@ -99,6 +101,7 @@ private:
QFutureWatcher<AndroidDeviceInfoList> m_avdsFutureWatcher;
std::unique_ptr<Utils::Process> m_removeAvdProcess;
QFileSystemWatcher m_avdFileSystemWatcher;
Utils::Guard m_avdPathGuard;
std::unique_ptr<Utils::Process> m_adbDeviceWatcherProcess;
AndroidAvdManager m_avdManager;