From e45e16d904f704920bd457fdf3302f3ae7061459 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Fri, 25 Feb 2022 21:49:11 +0100 Subject: Android: Make the device watcher process terminate on shutdown Terminate on IPlugin::aboutToShutdown instead of QCoreApplication::aboutToQuit. If needed synchronously. Added "ADB device watcher started" logging. Fixes: QTCREATORBUG-27118 Change-Id: I483659b018c74d179b64a5a4f17cc2c27c9598a8 Reviewed-by: Reviewed-by: Jarek Kobus --- src/plugins/android/androiddevice.cpp | 36 +++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'src/plugins/android/androiddevice.cpp') diff --git a/src/plugins/android/androiddevice.cpp b/src/plugins/android/androiddevice.cpp index 4c550ef643b..dac30fd1446 100644 --- a/src/plugins/android/androiddevice.cpp +++ b/src/plugins/android/androiddevice.cpp @@ -35,6 +35,8 @@ #include +#include + #include #include #include @@ -594,6 +596,8 @@ void AndroidDeviceManager::setupDevicesWatcher() m_adbDeviceWatcherProcess->setCommand(command); m_adbDeviceWatcherProcess->setEnvironment(AndroidConfigurations::toolsEnvironment(m_androidConfig)); m_adbDeviceWatcherProcess->start(); + qCDebug(androidDeviceLog).noquote() << "ADB device watcher started:" + << command.toUserOutput(); // Setup AVD filesystem watcher to listen for changes when an avd is created/deleted, // or started/stopped @@ -617,6 +621,28 @@ void AndroidDeviceManager::setupDevicesWatcher() updateAvdsList(); } +void AndroidDeviceManager::shutdownDevicesWatcher() +{ + m_avdsFutureWatcher.waitForFinished(); + m_removeAvdFutureWatcher.waitForFinished(); + + if (m_adbDeviceWatcherProcess) { + m_adbDeviceWatcherProcess->terminate(); + m_adbDeviceWatcherProcess->waitForFinished(); + m_adbDeviceWatcherProcess.reset(); + + // Despite terminate/waitForFinished, the process may still + // be around and remain if Qt Creator finishes too early. + QTimer::singleShot(1000, this, [this] { emit devicesWatcherShutdownFinished(); }); + } +} + +ExtensionSystem::IPlugin::ShutdownFlag AndroidDeviceManager::devicesShutdownFlag() const +{ + return m_adbDeviceWatcherProcess ? ExtensionSystem::IPlugin::AsynchronousShutdown + : ExtensionSystem::IPlugin::SynchronousShutdown; +} + void AndroidDeviceManager::HandleAvdsListChange() { DeviceManager *const devMgr = DeviceManager::instance(); @@ -761,16 +787,6 @@ 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); } -- cgit v1.2.3