forked from qt-creator/qt-creator
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: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -35,6 +35,8 @@
|
|||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
#include <projectexplorer/devicesupport/devicemanager.h>
|
#include <projectexplorer/devicesupport/devicemanager.h>
|
||||||
#include <projectexplorer/devicesupport/idevicewidget.h>
|
#include <projectexplorer/devicesupport/idevicewidget.h>
|
||||||
#include <projectexplorer/kitinformation.h>
|
#include <projectexplorer/kitinformation.h>
|
||||||
@@ -594,6 +596,8 @@ void AndroidDeviceManager::setupDevicesWatcher()
|
|||||||
m_adbDeviceWatcherProcess->setCommand(command);
|
m_adbDeviceWatcherProcess->setCommand(command);
|
||||||
m_adbDeviceWatcherProcess->setEnvironment(AndroidConfigurations::toolsEnvironment(m_androidConfig));
|
m_adbDeviceWatcherProcess->setEnvironment(AndroidConfigurations::toolsEnvironment(m_androidConfig));
|
||||||
m_adbDeviceWatcherProcess->start();
|
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,
|
// Setup AVD filesystem watcher to listen for changes when an avd is created/deleted,
|
||||||
// or started/stopped
|
// or started/stopped
|
||||||
@@ -617,6 +621,28 @@ void AndroidDeviceManager::setupDevicesWatcher()
|
|||||||
updateAvdsList();
|
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()
|
void AndroidDeviceManager::HandleAvdsListChange()
|
||||||
{
|
{
|
||||||
DeviceManager *const devMgr = DeviceManager::instance();
|
DeviceManager *const devMgr = DeviceManager::instance();
|
||||||
@@ -761,16 +787,6 @@ AndroidDeviceManager::AndroidDeviceManager(QObject *parent)
|
|||||||
m_androidConfig(AndroidConfigurations::currentConfig()),
|
m_androidConfig(AndroidConfigurations::currentConfig()),
|
||||||
m_avdManager(m_androidConfig)
|
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,
|
connect(&m_removeAvdFutureWatcher, &QFutureWatcherBase::finished,
|
||||||
this, &AndroidDeviceManager::handleAvdRemoved);
|
this, &AndroidDeviceManager::handleAvdRemoved);
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,8 @@
|
|||||||
#include "androidconfigurations.h"
|
#include "androidconfigurations.h"
|
||||||
#include "androiddeviceinfo.h"
|
#include "androiddeviceinfo.h"
|
||||||
|
|
||||||
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
#include <projectexplorer/devicesupport/idevice.h>
|
#include <projectexplorer/devicesupport/idevice.h>
|
||||||
#include <projectexplorer/devicesupport/idevicefactory.h>
|
#include <projectexplorer/devicesupport/idevicefactory.h>
|
||||||
|
|
||||||
@@ -98,9 +100,13 @@ private:
|
|||||||
|
|
||||||
class AndroidDeviceManager : public QObject
|
class AndroidDeviceManager : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static AndroidDeviceManager *instance();
|
static AndroidDeviceManager *instance();
|
||||||
void setupDevicesWatcher();
|
void setupDevicesWatcher();
|
||||||
|
void shutdownDevicesWatcher();
|
||||||
|
ExtensionSystem::IPlugin::ShutdownFlag devicesShutdownFlag() const;
|
||||||
void updateAvdsList();
|
void updateAvdsList();
|
||||||
IDevice::DeviceState getDeviceState(const QString &serial, IDevice::MachineType type) const;
|
IDevice::DeviceState getDeviceState(const QString &serial, IDevice::MachineType type) const;
|
||||||
void updateDeviceState(const ProjectExplorer::IDevice::ConstPtr &device);
|
void updateDeviceState(const ProjectExplorer::IDevice::ConstPtr &device);
|
||||||
@@ -112,6 +118,9 @@ public:
|
|||||||
|
|
||||||
QString getRunningAvdsSerialNumber(const QString &name) const;
|
QString getRunningAvdsSerialNumber(const QString &name) const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void devicesWatcherShutdownFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AndroidDeviceManager(QObject *parent = nullptr);
|
AndroidDeviceManager(QObject *parent = nullptr);
|
||||||
void HandleDevicesListChange(const QString &serialNumber);
|
void HandleDevicesListChange(const QString &serialNumber);
|
||||||
|
@@ -160,6 +160,19 @@ bool AndroidPlugin::initialize(const QStringList &arguments, QString *errorMessa
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AndroidPlugin::ShutdownFlag AndroidPlugin::aboutToShutdown()
|
||||||
|
{
|
||||||
|
AndroidDeviceManager *dm = AndroidDeviceManager::instance();
|
||||||
|
const IPlugin::ShutdownFlag sf = dm->devicesShutdownFlag();
|
||||||
|
|
||||||
|
if (sf == AsynchronousShutdown)
|
||||||
|
connect(dm, &AndroidDeviceManager::devicesWatcherShutdownFinished,
|
||||||
|
this, &ExtensionSystem::IPlugin::asynchronousShutdownFinished);
|
||||||
|
|
||||||
|
dm->shutdownDevicesWatcher();
|
||||||
|
return sf;
|
||||||
|
}
|
||||||
|
|
||||||
void AndroidPlugin::kitsRestored()
|
void AndroidPlugin::kitsRestored()
|
||||||
{
|
{
|
||||||
const bool qtForAndroidInstalled
|
const bool qtForAndroidInstalled
|
||||||
|
@@ -44,6 +44,9 @@ class AndroidPlugin final : public ExtensionSystem::IPlugin
|
|||||||
|
|
||||||
class AndroidPluginPrivate *d = nullptr;
|
class AndroidPluginPrivate *d = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ShutdownFlag aboutToShutdown() final;
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
private slots:
|
private slots:
|
||||||
void testAndroidSdkManagerProgressParser_data();
|
void testAndroidSdkManagerProgressParser_data();
|
||||||
|
Reference in New Issue
Block a user