forked from qt-creator/qt-creator
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:
@@ -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;
|
||||
}
|
||||
|
@@ -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)
|
||||
{
|
||||
AndroidDeviceDialog::updateConnectedDevicesList();
|
||||
|
||||
if (serialNumber.isEmpty())
|
||||
return {};
|
||||
|
||||
return Utils::findOrDefault(m_connectedDevices, [serialNumber](const AndroidDeviceInfo &info) {
|
||||
return info.serialNumber == serialNumber || info.avdname == serialNumber;
|
||||
});
|
||||
}
|
||||
|
||||
AndroidDeviceInfo AndroidDeviceDialog::showAndGetSelectedDevice()
|
||||
{
|
||||
auto dev = defaultDeviceInfo(m_defaultDevice);
|
||||
if (dev.isValid())
|
||||
return dev;
|
||||
|
||||
refreshDeviceList();
|
||||
|
||||
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 (device != m_connectedDevices.cend())
|
||||
return *device;
|
||||
m_defaultDevice.clear();
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user