From a141d56991f6e91efe1d43e3e1c438d9dc8ecc3c Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Sat, 5 Mar 2022 16:59:01 +0200 Subject: Android: Don't call getDeviceState() on empty serial number Avoid calling getDeviceState() if the serial is empty, which won't give any useful info for emulators. This will avoid multiple state checks at QC start as well. Also, set the default new AndroidDevice state as Disconnected, which reflects better the state of an empty newsly constructed device which we don't know the state of. Change-Id: I854e95e28b150f09c3eff6b8a75b2df6bd4aa1ce Reviewed-by: Alessandro Portale --- src/plugins/android/androiddevice.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/plugins/android/androiddevice.cpp') diff --git a/src/plugins/android/androiddevice.cpp b/src/plugins/android/androiddevice.cpp index 3e78f43b329..3c2d4fd5d1a 100644 --- a/src/plugins/android/androiddevice.cpp +++ b/src/plugins/android/androiddevice.cpp @@ -162,7 +162,7 @@ AndroidDevice::AndroidDevice() setDisplayType(tr("Android")); setMachineType(IDevice::Hardware); setOsType(OsType::OsTypeOtherUnix); - setDeviceState(DeviceConnected); + setDeviceState(DeviceDisconnected); addDeviceAction({tr("Refresh"), [](const IDevice::Ptr &device, QWidget *parent) { Q_UNUSED(parent) @@ -441,12 +441,10 @@ void AndroidDeviceManager::updateDeviceState(const ProjectExplorer::IDevice::Con const QString serial = dev->serialNumber(); DeviceManager *const devMgr = DeviceManager::instance(); const Utils::Id id = dev->id(); - if (serial.isEmpty() && dev->machineType() == IDevice::Emulator) { + if (!serial.isEmpty()) + devMgr->setDeviceState(id, getDeviceState(serial, dev->machineType())); + else if (dev->machineType() == IDevice::Emulator) devMgr->setDeviceState(id, IDevice::DeviceConnected); - return; - } - - devMgr->setDeviceState(id, getDeviceState(serial, dev->machineType())); } void AndroidDeviceManager::startAvd(const ProjectExplorer::IDevice::Ptr &device, QWidget *parent) @@ -641,11 +639,15 @@ void AndroidDeviceManager::HandleAvdsListChange() } else { // Find the state of the AVD retrieved from the AVD watcher const QString serial = getRunningAvdsSerialNumber(item.avdName); - const IDevice::DeviceState state = getDeviceState(serial, IDevice::Emulator); - if (dev->deviceState() != state) { - devMgr->setDeviceState(dev->id(), state); - qCDebug(androidDeviceLog, "Device id \"%s\" changed its state.", - dev->id().toString().toUtf8().data()); + if (!serial.isEmpty()) { + const IDevice::DeviceState state = getDeviceState(serial, IDevice::Emulator); + if (dev->deviceState() != state) { + devMgr->setDeviceState(dev->id(), state); + qCDebug(androidDeviceLog, "Device id \"%s\" changed its state.", + dev->id().toString().toUtf8().data()); + } + } else { + devMgr->setDeviceState(dev->id(), IDevice::DeviceConnected); } connectedDevs.append(dev->id()); continue; -- cgit v1.2.3