Android: Simplify 32bit detection logic

Change-Id: I379e8903294dce644bd9f0214b596b56e5d7d81e
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
hjk
2022-11-25 16:35:16 +01:00
parent aed633712f
commit 3c8c5b08a8
3 changed files with 18 additions and 32 deletions

View File

@@ -234,6 +234,23 @@ QString AndroidAvdManager::startAvd(const QString &name) const
return QString();
}
static bool is32BitUserSpace()
{
// Do a similar check as android's emulator is doing:
if (HostOsInfo::isLinuxHost()) {
if (QSysInfo::WordSize == 32) {
QtcProcess proc;
proc.setTimeoutS(3);
proc.setCommand({"getconf", {"LONG_BIT"}});
proc.runBlocking();
if (proc.result() != ProcessResult::FinishedWithSuccess)
return true;
return proc.allOutput().trimmed() == "32";
}
}
return false;
}
bool AndroidAvdManager::startAvdAsync(const QString &avdName) const
{
const FilePath emulator = m_config.emulatorToolPath();
@@ -267,7 +284,7 @@ bool AndroidAvdManager::startAvdAsync(const QString &avdName) const
// start the emulator
CommandLine cmd(m_config.emulatorToolPath());
if (AndroidConfigurations::force32bitEmulator())
if (is32BitUserSpace())
cmd.addArg("-force-32bit");
cmd.addArgs(m_config.emulatorArgs(), CommandLine::Raw);

View File

@@ -123,30 +123,6 @@ namespace {
{
return Core::ICore::installerResourcePath("android.xml").toString();
}
static bool is32BitUserSpace()
{
// Do the exact same check as android's emulator is doing:
if (HostOsInfo::isLinuxHost()) {
if (QSysInfo::WordSize == 32 ) {
Environment env = Environment::systemEnvironment();
FilePath executable = env.searchInPath("file");
QString shell = env.value(QLatin1String("SHELL"));
if (executable.isEmpty() || shell.isEmpty())
return true; // we can't detect, but creator is 32bit so assume 32bit
QtcProcess proc;
proc.setProcessChannelMode(QProcess::MergedChannels);
proc.setTimeoutS(30);
proc.setCommand({executable, {shell}});
proc.runBlocking();
if (proc.result() != ProcessResult::FinishedWithSuccess)
return true;
return !proc.allOutput().contains("x86-64");
}
}
return false;
}
}
//////////////////////////////////
@@ -1403,11 +1379,6 @@ void AndroidConfigurations::updateAutomaticKitList()
KitManager::deregisterKit(k);
}
bool AndroidConfigurations::force32bitEmulator()
{
return m_instance->m_force32bit;
}
Environment AndroidConfigurations::toolsEnvironment(const AndroidConfig &config)
{
Environment env = Environment::systemEnvironment();
@@ -1449,7 +1420,6 @@ AndroidConfigurations::AndroidConfigurations()
connect(DeviceManager::instance(), &DeviceManager::devicesLoaded,
this, &AndroidConfigurations::updateAndroidDevice);
m_force32bit = is32BitUserSpace();
m_instance = this;
}

View File

@@ -215,7 +215,6 @@ private:
static AndroidConfigurations *m_instance;
AndroidConfig m_config;
std::unique_ptr<Internal::AndroidSdkManager> m_sdkManager;
bool m_force32bit;
};
} // namespace Android