Android: Do some refactoring for AvdDialog class

Move some logic for avd creation to the AvdDialog, and some
refactoring and simplification.

Change-Id: Id65e586ab1c0e9e898a04f07d7707371f20da649
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Assam Boudjelthia
2021-09-26 16:57:59 +03:00
parent 50e587fd99
commit ba672d1334
3 changed files with 116 additions and 124 deletions

View File

@@ -604,50 +604,20 @@ AndroidDeviceFactory::AndroidDeviceFactory()
IDevice::Ptr AndroidDeviceFactory::create() const
{
AndroidSdkManager sdkManager = AndroidSdkManager(m_androidConfig);
const CreateAvdInfo info = AvdDialog::gatherCreateAVDInfo(Core::ICore::dialogParent(),
&sdkManager, m_androidConfig);
if (!info.isValid()) {
if (!info.cancelled) {
AndroidDeviceWidget::criticalDialog(
QObject::tr("The returned device info is invalid."));
}
return nullptr;
AvdDialog dialog = AvdDialog(m_androidConfig, Core::ICore::dialogParent());
if (dialog.exec() != QDialog::Accepted)
return ProjectExplorer::IDevice::Ptr();
const ProjectExplorer::IDevice::Ptr dev = dialog.device();
const AndroidDevice *androidDev = static_cast<AndroidDevice*>(dev.data());
if (androidDev) {
qCDebug(androidDeviceLog, "Created new Android AVD id \"%s\".",
qPrintable(androidDev->avdName()));
} else {
AndroidDeviceWidget::criticalDialog(
QObject::tr("The device info returned from AvdDialog is invalid."));
}
const AndroidAvdManager avdManager = AndroidAvdManager(m_androidConfig);
QFutureWatcher<CreateAvdInfo> createAvdFutureWatcher;
createAvdFutureWatcher.setFuture(avdManager.createAvd(info));
QEventLoop loop;
QObject::connect(&createAvdFutureWatcher, &QFutureWatcher<CreateAvdInfo>::finished,
&loop, &QEventLoop::quit);
QObject::connect(&createAvdFutureWatcher, &QFutureWatcher<CreateAvdInfo>::canceled,
&loop, &QEventLoop::quit);
loop.exec(QEventLoop::ExcludeUserInputEvents);
QFuture<CreateAvdInfo> future = createAvdFutureWatcher.future();
if (!(future.isResultReadyAt(0) && future.result().isValid())) {
AndroidDeviceWidget::criticalDialog(QObject::tr("The device info returned by "
"avdmanager tool is invalid for the device name \"%1\".").arg(info.name));
return nullptr;
}
const CreateAvdInfo newAvdInfo = createAvdFutureWatcher.result();
AndroidDevice *dev = new AndroidDevice();
const Utils::Id deviceId = AndroidDevice::idFromAvdInfo(newAvdInfo);
dev->setupId(IDevice::AutoDetected, deviceId);
dev->setMachineType(IDevice::Emulator);
dev->setDisplayName(newAvdInfo.name);
dev->setDeviceState(IDevice::DeviceConnected);
dev->setExtraData(Constants::AndroidAvdName, newAvdInfo.name);
dev->setExtraData(Constants::AndroidCpuAbi, {newAvdInfo.abi});
dev->setExtraData(Constants::AndroidSdk, newAvdInfo.systemImage->apiLevel());
dev->setExtraData(Constants::AndroidAvdSdcard, QString("%1 MB").arg(newAvdInfo.sdcardSize));
dev->setExtraData(Constants::AndroidAvdDevice, newAvdInfo.deviceDefinition);
qCDebug(androidDeviceLog, "Created new Android AVD id \"%s\".", qPrintable(newAvdInfo.name));
return IDevice::Ptr(dev);
}