From 1e693bcc6737b078557cca03ae677da19d4676a2 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 10 Nov 2021 22:38:59 +0100 Subject: [PATCH] Android: Skip device list update no Android Kit is active This adds workaround to reduce the load added by the update of the Android device list, which currently happens in a polling style. Skip an update if (*): - The current open project is configured with a non-Android kit - No project is open - the current project target is null To summarize the timeline of the timer used here: - AndroidDeviceManager::setupDevicesWatcher() is called when Creator is started or when settings are changed. The setup makes the connections for the timeout and for AVD list future watcher. This will be done once. If the timer is active it won't be done again, so no duplicate connections. - In the setup, the list of devices in updated once. - On timer timeout, we attempt to update the list, however with conditions listed in (*) as well as only when an Android adb path is found. Fixes: QTCREATORBUG-26547 Change-Id: I13312c4b507ce4e4064adb1c1342f4648f915394 Reviewed-by: Alessandro Portale Reviewed-by: Assam Boudjelthia --- src/plugins/android/androiddevice.cpp | 35 ++++++++++++++++++++------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/plugins/android/androiddevice.cpp b/src/plugins/android/androiddevice.cpp index 7638d0b402f..a062299aab9 100644 --- a/src/plugins/android/androiddevice.cpp +++ b/src/plugins/android/androiddevice.cpp @@ -37,7 +37,10 @@ #include #include +#include #include +#include +#include #include #include @@ -418,11 +421,19 @@ QUrl AndroidDevice::toolControlChannel(const ControlChannelHint &) const void AndroidDeviceManager::updateDevicesList() { - connect(&m_devicesUpdaterTimer, &QTimer::timeout, this, [this]() { - updateDevicesListOnce(); - }); + // If a non-Android Kit is currently active, skip the device list update + const Target *startupTarget = SessionManager::startupTarget(); + if (!startupTarget) + return; + + const Kit *kit = startupTarget->kit(); + if (!kit) + return; + + if (DeviceTypeKitAspect::deviceTypeId(kit) != Constants::ANDROID_DEVICE_TYPE) + return; + updateDevicesListOnce(); - m_devicesUpdaterTimer.start(deviceUpdaterMsInterval); } void AndroidDeviceManager::updateDevicesListOnce() @@ -537,11 +548,17 @@ void AndroidDeviceManager::setEmulatorArguments(QWidget *parent) void AndroidDeviceManager::setupDevicesWatcher() { - // The call to avdmanager is always slower than the call to adb devices, - // so connecting the slot to the slower call should be enough. - connect(&m_avdsFutureWatcher, &QFutureWatcherBase::finished, - this, &AndroidDeviceManager::devicesListUpdated); - updateDevicesList(); + if (!m_devicesUpdaterTimer.isActive()) { + // The call to avdmanager is always slower than the call to adb devices, + // so connecting the slot to the slower call should be enough. + connect(&m_avdsFutureWatcher, &QFutureWatcherBase::finished, + this, &AndroidDeviceManager::devicesListUpdated); + connect(&m_devicesUpdaterTimer, &QTimer::timeout, this, [this]() { + updateDevicesList(); + }); + m_devicesUpdaterTimer.start(deviceUpdaterMsInterval); + } + updateDevicesListOnce(); } void AndroidDeviceManager::devicesListUpdated()