diff options
author | Jarek Kobus <[email protected]> | 2022-03-14 22:12:21 +0100 |
---|---|---|
committer | Jarek Kobus <[email protected]> | 2022-03-28 11:54:51 +0000 |
commit | 9f3941cda3443f6c3a3f2829b9c62081855e7a23 (patch) | |
tree | 886ddff713ef97d41611516a6773c03812efda2d /src | |
parent | c8cee1a2341c41eff7b076ed35a11e80bfc23810 (diff) |
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: <[email protected]>
Reviewed-by: Assam Boudjelthia <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/android/androiddevice.cpp | 25 | ||||
-rw-r--r-- | src/plugins/android/androiddevice.h | 3 | ||||
-rw-r--r-- | src/plugins/android/androidplugin.cpp | 1 |
3 files changed, 17 insertions, 12 deletions
diff --git a/src/plugins/android/androiddevice.cpp b/src/plugins/android/androiddevice.cpp index 6e6b83eef7e..c8534d1337f 100644 --- a/src/plugins/android/androiddevice.cpp +++ b/src/plugins/android/androiddevice.cpp @@ -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 diff --git a/src/plugins/android/androiddevice.h b/src/plugins/android/androiddevice.h index e9283df7efe..b3390a9d65e 100644 --- a/src/plugins/android/androiddevice.h +++ b/src/plugins/android/androiddevice.h @@ -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 diff --git a/src/plugins/android/androidplugin.cpp b/src/plugins/android/androidplugin.cpp index 3207b0c38a4..fad354094d6 100644 --- a/src/plugins/android/androidplugin.cpp +++ b/src/plugins/android/androidplugin.cpp @@ -136,6 +136,7 @@ public: }; AndroidBuildApkStepFactory buildApkStepFactory; + AndroidDeviceManager deviceManager; }; AndroidPlugin::~AndroidPlugin() |