Android: avoid blocking call to show avd selection for default device

If a user already chose a default device to run, we don't need to create
the whole AVD selection dialog, but rather straightforward to get the
device info if it's already connected, otherwise the dialog opens for
selection as usual.

Change-Id: I5fee9411d755e89da23a8d365f284e8b52808a07
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Assam Boudjelthia
2021-05-30 19:23:39 +03:00
parent dfb0edf4ce
commit 45611e841b
3 changed files with 42 additions and 22 deletions

View File

@@ -1066,13 +1066,20 @@ AndroidDeviceInfo AndroidConfigurations::showDeviceDialog(Project *project,
if (!serialNumber.isEmpty())
break;
}
const AndroidDeviceInfo defaultDevice = AndroidDeviceDialog::defaultDeviceInfo(serialNumber);
if (defaultDevice.isValid())
return defaultDevice;
AndroidDeviceDialog dialog(apiLevel, abis, serialNumber, Core::ICore::dialogParent());
AndroidDeviceInfo info = dialog.device();
AndroidDeviceInfo info = dialog.showAndGetSelectedDevice();
if (dialog.saveDeviceSelection() && info.isValid()) {
const QString serialNumber = info.type == AndroidDeviceInfo::Hardware ?
const QString newSerialNumber = info.type == AndroidDeviceInfo::Hardware ?
info.serialNumber : info.avdname;
if (!serialNumber.isEmpty())
AndroidConfigurations::setDefaultDevice(project, AndroidManager::devicePreferredAbi(info.cpuAbi, abis), serialNumber);
if (!newSerialNumber.isEmpty()) {
const QString preferredAbi = AndroidManager::devicePreferredAbi(info.cpuAbi, abis);
AndroidConfigurations::setDefaultDevice(project, preferredAbi, newSerialNumber);
}
}
return info;
}

View File

@@ -44,6 +44,8 @@ using namespace Android::Internal;
namespace Android {
namespace Internal {
QVector<AndroidDeviceInfo> AndroidDeviceDialog::m_connectedDevices = {};
// yeah, writing tree models is fun!
class AndroidDeviceModelNode
{
@@ -481,26 +483,30 @@ AndroidDeviceDialog::~AndroidDeviceDialog()
delete m_ui;
}
AndroidDeviceInfo AndroidDeviceDialog::device()
AndroidDeviceInfo AndroidDeviceDialog::defaultDeviceInfo(const QString &serialNumber)
{
refreshDeviceList();
AndroidDeviceDialog::updateConnectedDevicesList();
if (!m_defaultDevice.isEmpty()) {
auto device = std::find_if(m_connectedDevices.cbegin(),
m_connectedDevices.cend(),
[this](const AndroidDeviceInfo &info) {
return info.serialNumber == m_defaultDevice ||
info.avdname == m_defaultDevice;
if (serialNumber.isEmpty())
return {};
return Utils::findOrDefault(m_connectedDevices, [serialNumber](const AndroidDeviceInfo &info) {
return info.serialNumber == serialNumber || info.avdname == serialNumber;
});
if (device != m_connectedDevices.cend())
return *device;
m_defaultDevice.clear();
}
AndroidDeviceInfo AndroidDeviceDialog::showAndGetSelectedDevice()
{
auto dev = defaultDeviceInfo(m_defaultDevice);
if (dev.isValid())
return dev;
refreshDeviceList();
if (exec() == QDialog::Accepted)
return m_model->device(m_ui->deviceView->currentIndex());
return AndroidDeviceInfo();
return {};
}
bool AndroidDeviceDialog::saveDeviceSelection() const
@@ -508,11 +514,16 @@ bool AndroidDeviceDialog::saveDeviceSelection() const
return m_ui->defaultDeviceCheckBox->isChecked();
}
void AndroidDeviceDialog::updateConnectedDevicesList()
{
m_connectedDevices = AndroidConfig::connectedDevices(AndroidConfigurations::currentConfig()
.adbToolPath());
}
void AndroidDeviceDialog::refreshDeviceList()
{
m_ui->refreshDevicesButton->setEnabled(false);
m_progressIndicator->show();
m_connectedDevices = AndroidConfig::connectedDevices(AndroidConfigurations::currentConfig().adbToolPath());
m_futureWatcherRefreshDevices.setFuture(m_avdManager->avdList());
}

View File

@@ -56,7 +56,8 @@ public:
const QString &serialNumber, QWidget *parent = nullptr);
~AndroidDeviceDialog() override;
AndroidDeviceInfo device();
AndroidDeviceInfo showAndGetSelectedDevice();
static AndroidDeviceInfo defaultDeviceInfo(const QString &serialNumber);
bool saveDeviceSelection() const;
@@ -68,6 +69,7 @@ private:
void devicesRefreshed();
void enableOkayButton();
void defaultDeviceClear();
static void updateConnectedDevicesList();
AndroidDeviceModel *m_model;
Ui::AndroidDeviceDialog *m_ui;
@@ -76,8 +78,8 @@ private:
QStringList m_abis;
QString m_avdNameFromAdd;
QString m_defaultDevice;
static QVector<AndroidDeviceInfo> m_connectedDevices;
std::unique_ptr<AndroidAvdManager> m_avdManager;
QVector<AndroidDeviceInfo> m_connectedDevices;
QFutureWatcher<CreateAvdInfo> m_futureWatcherAddDevice;
QFutureWatcher<AndroidDeviceInfoList> m_futureWatcherRefreshDevices;
};