Android: Enforce portable/clean Android SDK path

When reading a path from file chooser, settings or environment variable,
make sure it is portable and "clean".

Avoids extra compiler registrations, invalid Kits and similar issues.

Fixes: QTCREATORBUG-26092
Change-Id: I2a11563f40973d5f595bf00e37ff045a503aa9f7
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Alessandro Portale
2021-08-12 19:22:41 +02:00
parent 14d1726c95
commit 99700bb009
2 changed files with 9 additions and 8 deletions

View File

@@ -227,7 +227,7 @@ void AndroidConfig::load(const QSettings &settings)
// user settings // user settings
m_emulatorArgs = settings.value(EmulatorArgsKey, m_emulatorArgs = settings.value(EmulatorArgsKey,
QStringList({"-netdelay", "none", "-netspeed", "full"})).toStringList(); QStringList({"-netdelay", "none", "-netspeed", "full"})).toStringList();
m_sdkLocation = FilePath::fromString(settings.value(SDKLocationKey).toString()); m_sdkLocation = FilePath::fromUserInput(settings.value(SDKLocationKey).toString()).cleanPath();
m_customNdkList = settings.value(CustomNdkLocationsKey).toStringList(); m_customNdkList = settings.value(CustomNdkLocationsKey).toStringList();
m_sdkManagerToolArgs = settings.value(SDKManagerToolArgsKey).toStringList(); m_sdkManagerToolArgs = settings.value(SDKManagerToolArgsKey).toStringList();
m_openJDKLocation = FilePath::fromString(settings.value(OpenJDKLocationKey).toString()); m_openJDKLocation = FilePath::fromString(settings.value(OpenJDKLocationKey).toString());
@@ -239,7 +239,7 @@ void AndroidConfig::load(const QSettings &settings)
if (reader.load(FilePath::fromString(sdkSettingsFileName())) if (reader.load(FilePath::fromString(sdkSettingsFileName()))
&& settings.value(changeTimeStamp).toInt() != QFileInfo(sdkSettingsFileName()).lastModified().toMSecsSinceEpoch() / 1000) { && settings.value(changeTimeStamp).toInt() != QFileInfo(sdkSettingsFileName()).lastModified().toMSecsSinceEpoch() / 1000) {
// persisten settings // persisten settings
m_sdkLocation = FilePath::fromString(reader.restoreValue(SDKLocationKey, m_sdkLocation.toString()).toString()); m_sdkLocation = FilePath::fromUserInput(reader.restoreValue(SDKLocationKey, m_sdkLocation.toString()).toString()).cleanPath();
m_customNdkList = reader.restoreValue(CustomNdkLocationsKey).toStringList(); m_customNdkList = reader.restoreValue(CustomNdkLocationsKey).toStringList();
m_sdkManagerToolArgs = reader.restoreValue(SDKManagerToolArgsKey, m_sdkManagerToolArgs).toStringList(); m_sdkManagerToolArgs = reader.restoreValue(SDKManagerToolArgsKey, m_sdkManagerToolArgs).toStringList();
m_openJDKLocation = FilePath::fromString(reader.restoreValue(OpenJDKLocationKey, m_openJDKLocation.toString()).toString()); m_openJDKLocation = FilePath::fromString(reader.restoreValue(OpenJDKLocationKey, m_openJDKLocation.toString()).toString());
@@ -1024,7 +1024,7 @@ FilePath AndroidConfig::defaultSdkPath()
{ {
QString sdkFromEnvVar = QString::fromLocal8Bit(getenv("ANDROID_SDK_ROOT")); QString sdkFromEnvVar = QString::fromLocal8Bit(getenv("ANDROID_SDK_ROOT"));
if (!sdkFromEnvVar.isEmpty()) if (!sdkFromEnvVar.isEmpty())
return Utils::FilePath::fromString(sdkFromEnvVar); return FilePath::fromUserInput(sdkFromEnvVar).cleanPath();
// Set default path of SDK as used by Android Studio // Set default path of SDK as used by Android Studio
if (Utils::HostOsInfo::isMacHost()) { if (Utils::HostOsInfo::isMacHost()) {

View File

@@ -596,7 +596,7 @@ void AndroidSettingsWidget::validateOpenSsl()
void AndroidSettingsWidget::onSdkPathChanged() void AndroidSettingsWidget::onSdkPathChanged()
{ {
const FilePath sdkPath = m_ui.SDKLocationPathChooser->filePath(); const FilePath sdkPath = m_ui.SDKLocationPathChooser->filePath().cleanPath();
m_androidConfig.setSdkLocation(sdkPath); m_androidConfig.setSdkLocation(sdkPath);
FilePath currentOpenSslPath = m_androidConfig.openSslLocation(); FilePath currentOpenSslPath = m_androidConfig.openSslLocation();
if (currentOpenSslPath.isEmpty() || !currentOpenSslPath.exists()) if (currentOpenSslPath.isEmpty() || !currentOpenSslPath.exists())
@@ -608,7 +608,7 @@ void AndroidSettingsWidget::onSdkPathChanged()
void AndroidSettingsWidget::validateSdk() void AndroidSettingsWidget::validateSdk()
{ {
const FilePath sdkPath = m_ui.SDKLocationPathChooser->filePath(); const FilePath sdkPath = m_ui.SDKLocationPathChooser->filePath().cleanPath();
m_androidConfig.setSdkLocation(sdkPath); m_androidConfig.setSdkLocation(sdkPath);
m_androidSummary->setPointValid(SdkPathExistsRow, m_androidConfig.sdkLocation().exists()); m_androidSummary->setPointValid(SdkPathExistsRow, m_androidConfig.sdkLocation().exists());
@@ -865,14 +865,15 @@ void AndroidSettingsWidget::downloadSdk()
} }
const QString message = tr("Download and install Android SDK Tools to: %1?") const QString message = tr("Download and install Android SDK Tools to: %1?")
.arg(m_ui.SDKLocationPathChooser->filePath().toUserOutput()); .arg(m_ui.SDKLocationPathChooser->filePath().cleanPath().toUserOutput());
auto userInput = QMessageBox::information(this, AndroidSdkDownloader::dialogTitle(), auto userInput = QMessageBox::information(this, AndroidSdkDownloader::dialogTitle(),
message, QMessageBox::Yes | QMessageBox::No); message, QMessageBox::Yes | QMessageBox::No);
if (userInput == QMessageBox::Yes) { if (userInput == QMessageBox::Yes) {
if (m_javaSummary->allRowsOk()) { if (m_javaSummary->allRowsOk()) {
auto javaPath = m_ui.OpenJDKLocationPathChooser->filePath(); auto javaPath = m_ui.OpenJDKLocationPathChooser->filePath();
m_sdkDownloader.downloadAndExtractSdk(javaPath.toString(), m_sdkDownloader.downloadAndExtractSdk(
m_ui.SDKLocationPathChooser->filePath().toString()); javaPath.toString(),
m_ui.SDKLocationPathChooser->filePath().cleanPath().toString());
} }
} }
} }