AndroidDeviceManager: Remove the instance from plugin destructor

Delete the AndroidDeviceManager instance on shutdown from inside
android plugin destructor.

Implement AndroidDeviceManager destructor and wait for
futures currently running to finish. Don't do any special
handling for possibly still running m_adbDeviceWatcherProcess,
as it will be deleted automatically by the std::unique_ptr
and this will automatically initiate a proper termination of the
process running.

Change-Id: I5aad6f4fcfca23a0a37c3709efcdffad43a88203
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
Jarek Kobus
2022-03-14 22:12:21 +01:00
parent c8cee1a234
commit 9f3941cda3
3 changed files with 17 additions and 12 deletions

View File

@@ -836,10 +836,11 @@ void AndroidDeviceManager::HandleDevicesListChange(const QString &serialNumber)
}
}
static AndroidDeviceManager *s_instance = nullptr;
AndroidDeviceManager *AndroidDeviceManager::instance()
{
static AndroidDeviceManager obj;
return &obj;
return s_instance;
}
AndroidDeviceManager::AndroidDeviceManager(QObject *parent)
@@ -847,18 +848,18 @@ AndroidDeviceManager::AndroidDeviceManager(QObject *parent)
m_androidConfig(AndroidConfigurations::currentConfig()),
m_avdManager(m_androidConfig)
{
connect(qApp, &QCoreApplication::aboutToQuit, this, [this]() {
if (m_adbDeviceWatcherProcess) {
m_adbDeviceWatcherProcess->terminate();
m_adbDeviceWatcherProcess->waitForFinished();
m_adbDeviceWatcherProcess.reset();
}
m_avdsFutureWatcher.waitForFinished();
m_removeAvdFutureWatcher.waitForFinished();
});
connect(&m_removeAvdFutureWatcher, &QFutureWatcherBase::finished,
this, &AndroidDeviceManager::handleAvdRemoved);
QTC_ASSERT(!s_instance, return);
s_instance = this;
}
AndroidDeviceManager::~AndroidDeviceManager()
{
m_avdsFutureWatcher.waitForFinished();
m_removeAvdFutureWatcher.waitForFinished();
QTC_ASSERT(s_instance == this, return);
s_instance = nullptr;
}
// Factory

View File

@@ -123,6 +123,7 @@ public:
private:
AndroidDeviceManager(QObject *parent = nullptr);
~AndroidDeviceManager();
void HandleDevicesListChange(const QString &serialNumber);
void HandleAvdsListChange();
void handleAvdRemoved();
@@ -135,6 +136,8 @@ private:
std::unique_ptr<Utils::QtcProcess> m_adbDeviceWatcherProcess;
AndroidConfig &m_androidConfig;
AndroidAvdManager m_avdManager;
friend class AndroidPluginPrivate;
};
} // namespace Internal

View File

@@ -136,6 +136,7 @@ public:
};
AndroidBuildApkStepFactory buildApkStepFactory;
AndroidDeviceManager deviceManager;
};
AndroidPlugin::~AndroidPlugin()