From 1ddcd8ad705f4a075564e749ce16e55d5354a2f4 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 13 May 2024 19:45:38 +0200 Subject: [PATCH] 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: Reviewed-by: Alessandro Portale --- src/plugins/android/androiddevice.cpp | 6 ++++-- src/plugins/android/androiddevice.h | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/plugins/android/androiddevice.cpp b/src/plugins/android/androiddevice.cpp index 25ea819a422..0c1b29b46b6 100644 --- a/src/plugins/android/androiddevice.cpp +++ b/src/plugins/android/androiddevice.cpp @@ -478,7 +478,7 @@ expected_str 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(); diff --git a/src/plugins/android/androiddevice.h b/src/plugins/android/androiddevice.h index 739e9c2753f..70729533f64 100644 --- a/src/plugins/android/androiddevice.h +++ b/src/plugins/android/androiddevice.h @@ -11,6 +11,8 @@ #include #include +#include + #include #include #include @@ -99,6 +101,7 @@ private: QFutureWatcher m_avdsFutureWatcher; std::unique_ptr m_removeAvdProcess; QFileSystemWatcher m_avdFileSystemWatcher; + Utils::Guard m_avdPathGuard; std::unique_ptr m_adbDeviceWatcherProcess; AndroidAvdManager m_avdManager;