forked from qt-creator/qt-creator
Android: Reduce time to open settings widget
Two major areas of improvement: - Make connections last, so that the initial setup does not trigger any unnecessary checks. - Make fetching the list of android virtual devices a background operation. Together they reduce the time needed to open the settings for me by roughly 10 times. Task-number: QTCREATORBUG-13735 Change-Id: I0839853dcdbdfe20a183a27888e55d3c56a9b815 Reviewed-by: BogDan Vatra <bogdan@kde.org>
This commit is contained in:
@@ -600,12 +600,22 @@ bool AndroidConfig::removeAVD(const QString &name) const
|
||||
return !proc.exitCode();
|
||||
}
|
||||
|
||||
QFuture<QVector<AndroidDeviceInfo>> AndroidConfig::androidVirtualDevicesFuture()
|
||||
{
|
||||
return QtConcurrent::run(&AndroidConfig::androidVirtualDevicesImpl, androidToolPath(), androidToolEnvironment());
|
||||
}
|
||||
|
||||
QVector<AndroidDeviceInfo> AndroidConfig::androidVirtualDevices() const
|
||||
{
|
||||
return androidVirtualDevicesImpl(androidToolPath(), androidToolEnvironment());
|
||||
}
|
||||
|
||||
QVector<AndroidDeviceInfo> AndroidConfig::androidVirtualDevicesImpl(const Utils::FileName &androidTool, const Utils::Environment &environment)
|
||||
{
|
||||
QVector<AndroidDeviceInfo> devices;
|
||||
QProcess proc;
|
||||
proc.setProcessEnvironment(androidToolEnvironment().toProcessEnvironment());
|
||||
proc.start(androidToolPath().toString(),
|
||||
proc.setProcessEnvironment(environment.toProcessEnvironment());
|
||||
proc.start(androidTool.toString(),
|
||||
QStringList() << QLatin1String("list") << QLatin1String("avd")); // list available AVDs
|
||||
if (!proc.waitForFinished(5000)) {
|
||||
proc.terminate();
|
||||
|
@@ -146,7 +146,10 @@ public:
|
||||
bool removeAVD(const QString &name) const;
|
||||
|
||||
QVector<AndroidDeviceInfo> connectedDevices(QString *error = 0) const;
|
||||
|
||||
QFuture<QVector<AndroidDeviceInfo> > androidVirtualDevicesFuture();
|
||||
QVector<AndroidDeviceInfo> androidVirtualDevices() const;
|
||||
|
||||
QString startAVD(const QString &name, int apiLevel, QString cpuAbi) const;
|
||||
bool startAVDAsync(const QString &avdName) const;
|
||||
QString findAvd(int apiLevel, const QString &cpuAbi) const;
|
||||
@@ -165,6 +168,7 @@ public:
|
||||
SdkPlatform highestAndroidSdk() const;
|
||||
private:
|
||||
static CreateAvdInfo createAVDImpl(CreateAvdInfo info, Utils::FileName androidToolPath, Utils::Environment env);
|
||||
static QVector<AndroidDeviceInfo> androidVirtualDevicesImpl(const Utils::FileName &androidTool, const Utils::Environment &environment);
|
||||
|
||||
Utils::FileName toolPath(ProjectExplorer::Abi::Architecture architecture, const QString &ndkToolChainVersion) const;
|
||||
Utils::FileName openJDKBinPath() const;
|
||||
|
@@ -170,7 +170,6 @@ AndroidSettingsWidget::AndroidSettingsWidget(QWidget *parent)
|
||||
m_ui->DataPartitionSizeSpinBox->setValue(m_androidConfig.partitionSize());
|
||||
m_ui->CreateKitCheckBox->setChecked(m_androidConfig.automaticKitCreation());
|
||||
m_ui->AVDTableView->setModel(&m_AVDModel);
|
||||
m_AVDModel.setAvdList(m_androidConfig.androidVirtualDevices());
|
||||
m_ui->AVDTableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
m_ui->AVDTableView->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
||||
|
||||
@@ -180,11 +179,20 @@ AndroidSettingsWidget::AndroidSettingsWidget(QWidget *parent)
|
||||
connect(m_ui->gdbWarningLabel, SIGNAL(linkActivated(QString)),
|
||||
this, SLOT(showGdbWarningDialog()));
|
||||
|
||||
connect(&m_virtualDevicesWatcher, SIGNAL(finished()),
|
||||
this, SLOT(updateAvds()));
|
||||
|
||||
check(All);
|
||||
applyToUi(All);
|
||||
|
||||
connect(&m_futureWatcher, SIGNAL(finished()),
|
||||
this, SLOT(avdAdded()));
|
||||
|
||||
connect(m_ui->NDKLocationPathChooser, SIGNAL(changed(QString)), this, SLOT(ndkLocationEditingFinished()));
|
||||
connect(m_ui->SDKLocationPathChooser, SIGNAL(changed(QString)), this, SLOT(sdkLocationEditingFinished()));
|
||||
connect(m_ui->AntLocationPathChooser, SIGNAL(changed(QString)), this, SLOT(antLocationEditingFinished()));
|
||||
connect(m_ui->OpenJDKLocationPathChooser, SIGNAL(changed(QString)), this, SLOT(openJDKLocationEditingFinished()));
|
||||
|
||||
}
|
||||
|
||||
AndroidSettingsWidget::~AndroidSettingsWidget()
|
||||
@@ -397,10 +405,41 @@ void AndroidSettingsWidget::applyToUi(AndroidSettingsWidget::Mode mode)
|
||||
m_ui->AVDManagerFrame->setEnabled(false);
|
||||
}
|
||||
|
||||
m_AVDModel.setAvdList(m_androidConfig.androidVirtualDevices());
|
||||
startUpdateAvd();
|
||||
}
|
||||
}
|
||||
|
||||
void AndroidSettingsWidget::disableAvdControls()
|
||||
{
|
||||
m_ui->AVDAddPushButton->setEnabled(false);
|
||||
m_ui->AVDTableView->setEnabled(false);
|
||||
m_ui->AVDRemovePushButton->setEnabled(false);
|
||||
m_ui->AVDStartPushButton->setEnabled(false);
|
||||
}
|
||||
|
||||
void AndroidSettingsWidget::enableAvdControls()
|
||||
{
|
||||
m_ui->AVDTableView->setEnabled(true);
|
||||
m_ui->AVDAddPushButton->setEnabled(true);
|
||||
avdActivated(m_ui->AVDTableView->currentIndex());
|
||||
}
|
||||
|
||||
void AndroidSettingsWidget::startUpdateAvd()
|
||||
{
|
||||
disableAvdControls();
|
||||
m_virtualDevicesWatcher.setFuture(m_androidConfig.androidVirtualDevicesFuture());
|
||||
}
|
||||
|
||||
void AndroidSettingsWidget::updateAvds()
|
||||
{
|
||||
m_AVDModel.setAvdList(m_virtualDevicesWatcher.result());
|
||||
if (!m_lastAddedAvd.isEmpty()) {
|
||||
m_ui->AVDTableView->setCurrentIndex(m_AVDModel.indexForAvdName(m_lastAddedAvd));
|
||||
m_lastAddedAvd.clear();
|
||||
}
|
||||
enableAvdControls();
|
||||
}
|
||||
|
||||
bool AndroidSettingsWidget::sdkLocationIsValid() const
|
||||
{
|
||||
Utils::FileName androidExe = m_androidConfig.sdkLocation();
|
||||
@@ -519,11 +558,11 @@ void AndroidSettingsWidget::openOpenJDKDownloadUrl()
|
||||
|
||||
void AndroidSettingsWidget::addAVD()
|
||||
{
|
||||
m_ui->AVDAddPushButton->setEnabled(false);
|
||||
disableAvdControls();
|
||||
AndroidConfig::CreateAvdInfo info = m_androidConfig.gatherCreateAVDInfo(this);
|
||||
|
||||
if (info.target.isEmpty()) {
|
||||
m_ui->AVDAddPushButton->setEnabled(true);
|
||||
enableAvdControls();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -532,29 +571,31 @@ void AndroidSettingsWidget::addAVD()
|
||||
|
||||
void AndroidSettingsWidget::avdAdded()
|
||||
{
|
||||
m_ui->AVDAddPushButton->setEnabled(true);
|
||||
AndroidConfig::CreateAvdInfo info = m_futureWatcher.result();
|
||||
if (!info.error.isEmpty()) {
|
||||
enableAvdControls();
|
||||
QMessageBox::critical(this, QApplication::translate("AndroidConfig", "Error Creating AVD"), info.error);
|
||||
return;
|
||||
}
|
||||
|
||||
m_AVDModel.setAvdList(m_androidConfig.androidVirtualDevices());
|
||||
m_ui->AVDTableView->setCurrentIndex(m_AVDModel.indexForAvdName(info.name));
|
||||
startUpdateAvd();
|
||||
m_lastAddedAvd = info.name;
|
||||
}
|
||||
|
||||
void AndroidSettingsWidget::removeAVD()
|
||||
{
|
||||
disableAvdControls();
|
||||
QString avdName = m_AVDModel.avdName(m_ui->AVDTableView->currentIndex());
|
||||
if (QMessageBox::question(this, tr("Remove Android Virtual Device"),
|
||||
tr("Remove device \"%1\"? This cannot be undone.").arg(avdName),
|
||||
QMessageBox::Yes | QMessageBox::No)
|
||||
== QMessageBox::No)
|
||||
== QMessageBox::No) {
|
||||
enableAvdControls();
|
||||
return;
|
||||
}
|
||||
|
||||
m_androidConfig.removeAVD(avdName);
|
||||
m_AVDModel.setAvdList(m_androidConfig.androidVirtualDevices());
|
||||
avdActivated(m_ui->AVDTableView->currentIndex());
|
||||
startUpdateAvd();
|
||||
}
|
||||
|
||||
void AndroidSettingsWidget::startAVD()
|
||||
|
@@ -96,6 +96,7 @@ private slots:
|
||||
|
||||
void checkGdbFinished();
|
||||
void showGdbWarningDialog();
|
||||
void updateAvds();
|
||||
|
||||
private:
|
||||
enum Mode { Sdk = 1, Ndk = 2, Java = 4, All = Sdk | Ndk | Java };
|
||||
@@ -104,6 +105,9 @@ private:
|
||||
void applyToUi(Mode mode);
|
||||
bool sdkLocationIsValid() const;
|
||||
bool sdkPlatformToolsInstalled() const;
|
||||
void startUpdateAvd();
|
||||
void enableAvdControls();
|
||||
void disableAvdControls();
|
||||
|
||||
State m_sdkState;
|
||||
State m_ndkState;
|
||||
@@ -118,6 +122,9 @@ private:
|
||||
QFutureWatcher<AndroidConfig::CreateAvdInfo> m_futureWatcher;
|
||||
QFutureWatcher<QPair<QStringList, bool>> m_checkGdbWatcher;
|
||||
QStringList m_gdbCheckPaths;
|
||||
|
||||
QFutureWatcher<QVector<AndroidDeviceInfo>> m_virtualDevicesWatcher;
|
||||
QString m_lastAddedAvd;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -476,74 +476,10 @@
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="android.qrc"/>
|
||||
<include location="../coreplugin/core.qrc"/>
|
||||
<include location="android.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>NDKLocationPathChooser</sender>
|
||||
<signal>changed(QString)</signal>
|
||||
<receiver>AndroidSettingsWidget</receiver>
|
||||
<slot>ndkLocationEditingFinished()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>605</x>
|
||||
<y>143</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>352</x>
|
||||
<y>210</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>SDKLocationPathChooser</sender>
|
||||
<signal>changed(QString)</signal>
|
||||
<receiver>AndroidSettingsWidget</receiver>
|
||||
<slot>sdkLocationEditingFinished()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>605</x>
|
||||
<y>82</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>352</x>
|
||||
<y>210</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>AntLocationPathChooser</sender>
|
||||
<signal>changed(QString)</signal>
|
||||
<receiver>AndroidSettingsWidget</receiver>
|
||||
<slot>antLocationEditingFinished()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>605</x>
|
||||
<y>315</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>352</x>
|
||||
<y>210</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>OpenJDKLocationPathChooser</sender>
|
||||
<signal>changed(QString)</signal>
|
||||
<receiver>AndroidSettingsWidget</receiver>
|
||||
<slot>openJDKLocationEditingFinished()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>605</x>
|
||||
<y>31</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>352</x>
|
||||
<y>210</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>AVDAddPushButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
|
Reference in New Issue
Block a user