2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 BogDan Vatra <bog_dan_ro@yahoo.com>
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
#include "androidconfigurations.h"
|
|
|
|
#include "androidconstants.h"
|
2013-02-14 15:51:59 +01:00
|
|
|
#include "androidtoolchain.h"
|
|
|
|
#include "androiddevice.h"
|
|
|
|
#include "androidgdbserverkitinformation.h"
|
2013-08-01 12:49:47 +02:00
|
|
|
#include "androidqtversion.h"
|
2013-09-10 19:19:31 +02:00
|
|
|
#include "androiddevicedialog.h"
|
2014-03-24 16:31:28 +01:00
|
|
|
#include "avddialog.h"
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
2013-11-22 16:40:41 +01:00
|
|
|
#include <coreplugin/messagemanager.h>
|
2013-02-14 15:51:59 +01:00
|
|
|
#include <projectexplorer/kitmanager.h>
|
|
|
|
#include <projectexplorer/kitinformation.h>
|
|
|
|
#include <projectexplorer/devicesupport/devicemanager.h>
|
2016-04-29 23:06:26 +02:00
|
|
|
#include <projectexplorer/project.h>
|
2013-02-14 15:51:59 +01:00
|
|
|
#include <projectexplorer/toolchainmanager.h>
|
2013-09-10 19:19:31 +02:00
|
|
|
#include <projectexplorer/session.h>
|
2013-10-25 13:47:08 +02:00
|
|
|
#include <debugger/debuggeritemmanager.h>
|
2015-02-26 15:29:28 +01:00
|
|
|
#include <debugger/debuggeritem.h>
|
2013-02-14 15:51:59 +01:00
|
|
|
#include <debugger/debuggerkitinformation.h>
|
|
|
|
#include <qtsupport/baseqtversion.h>
|
|
|
|
#include <qtsupport/qtkitinformation.h>
|
|
|
|
#include <qtsupport/qtversionmanager.h>
|
2014-06-16 18:25:52 +04:00
|
|
|
#include <utils/algorithm.h>
|
2013-04-17 11:52:16 +02:00
|
|
|
#include <utils/environment.h>
|
2016-04-29 23:06:26 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
|
|
|
#include <utils/persistentsettings.h>
|
2016-04-29 16:52:58 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2016-02-05 15:06:15 +01:00
|
|
|
#include <utils/runextensions.h>
|
2016-04-29 16:52:58 +02:00
|
|
|
#include <utils/synchronousprocess.h>
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2016-04-29 23:06:26 +02:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QDirIterator>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QHostAddress>
|
|
|
|
#include <QProcess>
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <QSettings>
|
|
|
|
#include <QStringList>
|
2015-04-23 16:25:44 +02:00
|
|
|
#include <QTcpSocket>
|
2016-09-20 11:22:05 +03:00
|
|
|
#include <QThread>
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2014-06-19 14:16:45 +02:00
|
|
|
#include <functional>
|
|
|
|
|
2012-08-09 01:56:51 +02:00
|
|
|
using namespace ProjectExplorer;
|
2012-04-18 20:30:57 +03:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
namespace Android {
|
2014-06-25 15:42:11 +02:00
|
|
|
using namespace Internal;
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
const QLatin1String SettingsGroup("AndroidConfigurations");
|
|
|
|
const QLatin1String SDKLocationKey("SDKLocation");
|
|
|
|
const QLatin1String NDKLocationKey("NDKLocation");
|
|
|
|
const QLatin1String AntLocationKey("AntLocation");
|
|
|
|
const QLatin1String OpenJDKLocationKey("OpenJDKLocation");
|
|
|
|
const QLatin1String KeystoreLocationKey("KeystoreLocation");
|
2013-02-14 15:51:59 +01:00
|
|
|
const QLatin1String AutomaticKitCreationKey("AutomatiKitCreation");
|
2014-09-22 16:20:51 +03:00
|
|
|
const QLatin1String UseGradleKey("UseGradle");
|
2013-05-16 15:49:24 +02:00
|
|
|
const QLatin1String MakeExtraSearchDirectory("MakeExtraSearchDirectory");
|
2012-04-18 20:30:57 +03:00
|
|
|
const QLatin1String PartitionSizeKey("PartitionSize");
|
2013-04-04 01:29:47 -07:00
|
|
|
const QLatin1String ToolchainHostKey("ToolchainHost");
|
2014-11-18 18:37:05 +01:00
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
const QLatin1String ArmToolchainPrefix("arm-linux-androideabi");
|
|
|
|
const QLatin1String X86ToolchainPrefix("x86");
|
2013-02-16 18:05:11 +02:00
|
|
|
const QLatin1String MipsToolchainPrefix("mipsel-linux-android");
|
2014-11-18 18:37:05 +01:00
|
|
|
const QLatin1String AArch64ToolchainPrefix("aarch64-linux-android");
|
|
|
|
const QLatin1String X86_64ToolchainPrefix("x86_64");
|
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
const QLatin1String ArmToolsPrefix("arm-linux-androideabi");
|
2013-02-16 18:04:00 +02:00
|
|
|
const QLatin1String X86ToolsPrefix("i686-linux-android");
|
2013-02-16 18:05:11 +02:00
|
|
|
const QLatin1String MipsToolsPrefix("mipsel-linux-android");
|
2014-11-18 18:37:05 +01:00
|
|
|
const QLatin1String AArch64ToolsPrefix("aarch64-linux-android");
|
|
|
|
const QLatin1String X86_64ToolsPrefix("x86_64-linux-android");
|
|
|
|
|
|
|
|
const QLatin1String ArmToolsDisplayName("arm");
|
|
|
|
const QLatin1String X86ToolsDisplayName("i686");
|
|
|
|
const QLatin1String MipsToolsDisplayName("mipsel");
|
|
|
|
const QLatin1String AArch64ToolsDisplayName("aarch64");
|
|
|
|
const QLatin1String X86_64ToolsDisplayName("x86_64");
|
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
const QLatin1String Unknown("unknown");
|
|
|
|
const QLatin1String keytoolName("keytool");
|
|
|
|
const QLatin1String changeTimeStamp("ChangeTimeStamp");
|
|
|
|
|
2012-12-07 19:52:47 +02:00
|
|
|
static QString sdkSettingsFileName()
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2013-02-20 16:17:48 +01:00
|
|
|
return QFileInfo(Core::ICore::settings(QSettings::SystemScope)->fileName()).absolutePath()
|
|
|
|
+ QLatin1String("/qtcreator/android.xml");
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-07-03 16:57:44 +03:00
|
|
|
bool androidDevicesLessThan(const AndroidDeviceInfo &dev1, const AndroidDeviceInfo &dev2)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2014-10-22 11:41:53 +02:00
|
|
|
if (dev1.serialNumber.contains(QLatin1String("????")) != dev2.serialNumber.contains(QLatin1String("????")))
|
2013-08-28 14:59:51 +02:00
|
|
|
return !dev1.serialNumber.contains(QLatin1String("????"));
|
2013-09-10 19:19:31 +02:00
|
|
|
if (dev1.type != dev2.type)
|
|
|
|
return dev1.type == AndroidDeviceInfo::Hardware;
|
2013-08-28 12:33:57 +02:00
|
|
|
if (dev1.sdk != dev2.sdk)
|
|
|
|
return dev1.sdk < dev2.sdk;
|
2015-04-23 16:25:44 +02:00
|
|
|
if (dev1.avdname != dev2.avdname)
|
|
|
|
return dev1.avdname < dev2.avdname;
|
2013-09-10 19:19:31 +02:00
|
|
|
|
2013-08-28 12:33:57 +02:00
|
|
|
return dev1.serialNumber < dev2.serialNumber;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
2014-04-10 15:52:02 +02:00
|
|
|
|
|
|
|
static QStringList cleanAndroidABIs(const QStringList &abis)
|
|
|
|
{
|
|
|
|
QStringList res;
|
|
|
|
foreach (const QString &abi, abis) {
|
|
|
|
int index = abi.lastIndexOf(QLatin1Char('/'));
|
|
|
|
if (index == -1)
|
|
|
|
res << abi;
|
|
|
|
else
|
|
|
|
res << abi.mid(index + 1);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2014-10-31 16:09:34 +01:00
|
|
|
|
|
|
|
static bool is32BitUserSpace()
|
|
|
|
{
|
|
|
|
// Do the exact same check as android's emulator is doing:
|
2015-02-03 23:50:37 +02:00
|
|
|
if (HostOsInfo::isLinuxHost()) {
|
2014-10-31 16:09:34 +01:00
|
|
|
if (QSysInfo::WordSize == 32 ) {
|
2015-02-03 23:50:37 +02:00
|
|
|
Environment env = Environment::systemEnvironment();
|
2014-10-31 16:09:34 +01:00
|
|
|
QString executable = env.searchInPath(QLatin1String("file")).toString();
|
|
|
|
QString shell = env.value(QLatin1String("SHELL"));
|
|
|
|
if (executable.isEmpty() || shell.isEmpty())
|
|
|
|
return true; // we can't detect, but creator is 32bit so assume 32bit
|
|
|
|
|
2016-04-29 16:52:58 +02:00
|
|
|
SynchronousProcess proc;
|
2014-10-31 16:09:34 +01:00
|
|
|
proc.setProcessChannelMode(QProcess::MergedChannels);
|
2016-04-29 16:52:58 +02:00
|
|
|
proc.setTimeoutS(30);
|
2016-06-10 13:33:40 +03:00
|
|
|
SynchronousProcessResponse response = proc.runBlocking(executable, QStringList() << shell);
|
2016-04-29 16:52:58 +02:00
|
|
|
if (response.result != SynchronousProcessResponse::Finished)
|
2014-10-31 16:09:34 +01:00
|
|
|
return true;
|
2016-04-29 16:52:58 +02:00
|
|
|
return !response.allOutput().contains("x86-64");
|
2014-10-31 16:09:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-11 12:35:23 +02:00
|
|
|
// Some preview sdks use a non integer version
|
|
|
|
int apiLevelFromAndroidList(const QString &string)
|
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
int result = string.toInt(&ok);
|
|
|
|
if (ok)
|
|
|
|
return result;
|
|
|
|
Utils::FileName sdkLocation = AndroidConfigurations::currentConfig().sdkLocation();
|
|
|
|
sdkLocation.appendPath(QLatin1String("/platforms/android-") + string + QLatin1String("/source.properties"));
|
|
|
|
result = QSettings(sdkLocation.toString(), QSettings::IniFormat).value(QLatin1String("AndroidVersion.ApiLevel")).toInt(&ok);
|
|
|
|
if (ok)
|
|
|
|
return result;
|
|
|
|
if (string == QLatin1String("L"))
|
|
|
|
return 21;
|
|
|
|
if (string == QLatin1String("MNC"))
|
|
|
|
return 22;
|
|
|
|
return 23; // At least
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
//////////////////////////////////
|
|
|
|
// AndroidConfig
|
|
|
|
//////////////////////////////////
|
|
|
|
|
2014-11-18 18:37:05 +01:00
|
|
|
Abi AndroidConfig::abiForToolChainPrefix(const QString &toolchainPrefix)
|
|
|
|
{
|
|
|
|
Abi::Architecture arch = Abi::UnknownArchitecture;
|
|
|
|
unsigned char wordWidth = 32;
|
|
|
|
if (toolchainPrefix == ArmToolchainPrefix) {
|
|
|
|
arch = Abi::ArmArchitecture;
|
|
|
|
} else if (toolchainPrefix == X86ToolchainPrefix) {
|
|
|
|
arch = Abi::X86Architecture;
|
|
|
|
} else if (toolchainPrefix == MipsToolchainPrefix) {
|
|
|
|
arch = Abi::MipsArchitecture;
|
|
|
|
} else if (toolchainPrefix == AArch64ToolchainPrefix) {
|
|
|
|
arch = Abi::ArmArchitecture;
|
|
|
|
wordWidth = 64;
|
|
|
|
} else if (toolchainPrefix == X86_64ToolchainPrefix) {
|
|
|
|
arch = Abi::X86Architecture;
|
|
|
|
wordWidth = 64;
|
|
|
|
}
|
|
|
|
|
2016-04-29 23:06:26 +02:00
|
|
|
return Abi(arch, Abi::LinuxOS, Abi::AndroidLinuxFlavor, Abi::ElfFormat, wordWidth);
|
2013-01-25 16:49:22 +01:00
|
|
|
}
|
|
|
|
|
2014-11-18 18:37:05 +01:00
|
|
|
QLatin1String AndroidConfig::toolchainPrefix(const Abi &abi)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2014-11-18 18:37:05 +01:00
|
|
|
switch (abi.architecture()) {
|
2012-08-09 01:56:51 +02:00
|
|
|
case Abi::ArmArchitecture:
|
2014-11-18 18:37:05 +01:00
|
|
|
if (abi.wordWidth() == 64)
|
|
|
|
return AArch64ToolchainPrefix;
|
2012-04-18 20:30:57 +03:00
|
|
|
return ArmToolchainPrefix;
|
2012-08-09 01:56:51 +02:00
|
|
|
case Abi::X86Architecture:
|
2014-11-18 18:37:05 +01:00
|
|
|
if (abi.wordWidth() == 64)
|
|
|
|
return X86_64ToolchainPrefix;
|
2012-04-18 20:30:57 +03:00
|
|
|
return X86ToolchainPrefix;
|
2013-02-16 18:05:11 +02:00
|
|
|
case Abi::MipsArchitecture:
|
|
|
|
return MipsToolchainPrefix;
|
2012-04-18 20:30:57 +03:00
|
|
|
default:
|
|
|
|
return Unknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-18 18:37:05 +01:00
|
|
|
QLatin1String AndroidConfig::toolsPrefix(const Abi &abi)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2014-11-18 18:37:05 +01:00
|
|
|
switch (abi.architecture()) {
|
2012-08-09 01:56:51 +02:00
|
|
|
case Abi::ArmArchitecture:
|
2014-11-18 18:37:05 +01:00
|
|
|
if (abi.wordWidth() == 64)
|
|
|
|
return AArch64ToolsPrefix;
|
2012-04-18 20:30:57 +03:00
|
|
|
return ArmToolsPrefix;
|
2012-08-09 01:56:51 +02:00
|
|
|
case Abi::X86Architecture:
|
2014-11-18 18:37:05 +01:00
|
|
|
if (abi.wordWidth() == 64)
|
|
|
|
return X86_64ToolsPrefix;
|
2012-04-18 20:30:57 +03:00
|
|
|
return X86ToolsPrefix;
|
2013-02-16 18:05:11 +02:00
|
|
|
case Abi::MipsArchitecture:
|
|
|
|
return MipsToolsPrefix;
|
2012-04-18 20:30:57 +03:00
|
|
|
default:
|
|
|
|
return Unknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-18 18:37:05 +01:00
|
|
|
QLatin1String AndroidConfig::displayName(const Abi &abi)
|
|
|
|
{
|
|
|
|
switch (abi.architecture()) {
|
|
|
|
case Abi::ArmArchitecture:
|
|
|
|
if (abi.wordWidth() == 64)
|
|
|
|
return AArch64ToolsDisplayName;
|
|
|
|
return ArmToolsDisplayName;
|
|
|
|
case Abi::X86Architecture:
|
|
|
|
if (abi.wordWidth() == 64)
|
|
|
|
return X86_64ToolsDisplayName;
|
|
|
|
return X86ToolsDisplayName;
|
|
|
|
case Abi::MipsArchitecture:
|
|
|
|
return MipsToolsDisplayName;
|
|
|
|
default:
|
|
|
|
return Unknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
void AndroidConfig::load(const QSettings &settings)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
|
|
|
// user settings
|
2013-12-16 20:19:07 +01:00
|
|
|
m_partitionSize = settings.value(PartitionSizeKey, 1024).toInt();
|
|
|
|
m_sdkLocation = FileName::fromString(settings.value(SDKLocationKey).toString());
|
|
|
|
m_ndkLocation = FileName::fromString(settings.value(NDKLocationKey).toString());
|
|
|
|
m_antLocation = FileName::fromString(settings.value(AntLocationKey).toString());
|
2014-11-20 16:22:59 +01:00
|
|
|
m_useGradle = settings.value(UseGradleKey, false).toBool();
|
2013-12-16 20:19:07 +01:00
|
|
|
m_openJDKLocation = FileName::fromString(settings.value(OpenJDKLocationKey).toString());
|
|
|
|
m_keystoreLocation = FileName::fromString(settings.value(KeystoreLocationKey).toString());
|
|
|
|
m_toolchainHost = settings.value(ToolchainHostKey).toString();
|
|
|
|
m_automaticKitCreation = settings.value(AutomaticKitCreationKey, true).toBool();
|
2013-05-16 15:49:24 +02:00
|
|
|
QString extraDirectory = settings.value(MakeExtraSearchDirectory).toString();
|
2013-12-16 20:19:07 +01:00
|
|
|
m_makeExtraSearchDirectories.clear();
|
2013-12-04 12:49:25 +01:00
|
|
|
if (!extraDirectory.isEmpty())
|
2013-12-16 20:19:07 +01:00
|
|
|
m_makeExtraSearchDirectories << extraDirectory;
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
PersistentSettingsReader reader;
|
2012-12-07 19:52:47 +02:00
|
|
|
if (reader.load(FileName::fromString(sdkSettingsFileName()))
|
|
|
|
&& settings.value(changeTimeStamp).toInt() != QFileInfo(sdkSettingsFileName()).lastModified().toMSecsSinceEpoch() / 1000) {
|
2012-04-18 20:30:57 +03:00
|
|
|
// persisten settings
|
2014-12-16 15:50:02 +01:00
|
|
|
m_sdkLocation = FileName::fromString(reader.restoreValue(SDKLocationKey, m_sdkLocation.toString()).toString());
|
|
|
|
m_ndkLocation = FileName::fromString(reader.restoreValue(NDKLocationKey, m_ndkLocation.toString()).toString());
|
|
|
|
m_antLocation = FileName::fromString(reader.restoreValue(AntLocationKey, m_antLocation.toString()).toString());
|
|
|
|
m_openJDKLocation = FileName::fromString(reader.restoreValue(OpenJDKLocationKey, m_openJDKLocation.toString()).toString());
|
|
|
|
m_keystoreLocation = FileName::fromString(reader.restoreValue(KeystoreLocationKey, m_keystoreLocation.toString()).toString());
|
|
|
|
m_toolchainHost = reader.restoreValue(ToolchainHostKey, m_toolchainHost).toString();
|
|
|
|
m_automaticKitCreation = reader.restoreValue(AutomaticKitCreationKey, m_automaticKitCreation).toBool();
|
2013-05-16 15:49:24 +02:00
|
|
|
QString extraDirectory = reader.restoreValue(MakeExtraSearchDirectory).toString();
|
2013-12-16 20:19:07 +01:00
|
|
|
m_makeExtraSearchDirectories.clear();
|
2013-12-04 12:49:25 +01:00
|
|
|
if (!extraDirectory.isEmpty())
|
2013-12-16 20:19:07 +01:00
|
|
|
m_makeExtraSearchDirectories << extraDirectory;
|
2012-04-18 20:30:57 +03:00
|
|
|
// persistent settings
|
|
|
|
}
|
2013-12-16 20:19:07 +01:00
|
|
|
m_availableSdkPlatformsUpToDate = false;
|
|
|
|
m_NdkInformationUpToDate = false;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
AndroidConfig::AndroidConfig()
|
2014-11-20 16:22:59 +01:00
|
|
|
: m_useGradle(false),
|
2014-09-22 16:20:51 +03:00
|
|
|
m_availableSdkPlatformsUpToDate(false),
|
2013-12-16 20:19:07 +01:00
|
|
|
m_NdkInformationUpToDate(false)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2013-12-16 20:19:07 +01:00
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidConfig::save(QSettings &settings) const
|
|
|
|
{
|
2012-12-07 19:52:47 +02:00
|
|
|
QFileInfo fileInfo(sdkSettingsFileName());
|
2012-04-18 20:30:57 +03:00
|
|
|
if (fileInfo.exists())
|
|
|
|
settings.setValue(changeTimeStamp, fileInfo.lastModified().toMSecsSinceEpoch() / 1000);
|
|
|
|
|
|
|
|
// user settings
|
2013-12-16 20:19:07 +01:00
|
|
|
settings.setValue(SDKLocationKey, m_sdkLocation.toString());
|
|
|
|
settings.setValue(NDKLocationKey, m_ndkLocation.toString());
|
|
|
|
settings.setValue(AntLocationKey, m_antLocation.toString());
|
2014-09-22 16:20:51 +03:00
|
|
|
settings.setValue(UseGradleKey, m_useGradle);
|
2013-12-16 20:19:07 +01:00
|
|
|
settings.setValue(OpenJDKLocationKey, m_openJDKLocation.toString());
|
|
|
|
settings.setValue(KeystoreLocationKey, m_keystoreLocation.toString());
|
|
|
|
settings.setValue(PartitionSizeKey, m_partitionSize);
|
|
|
|
settings.setValue(AutomaticKitCreationKey, m_automaticKitCreation);
|
|
|
|
settings.setValue(ToolchainHostKey, m_toolchainHost);
|
2013-06-04 11:45:19 +02:00
|
|
|
settings.setValue(MakeExtraSearchDirectory,
|
2013-12-16 20:19:07 +01:00
|
|
|
m_makeExtraSearchDirectories.isEmpty() ? QString()
|
|
|
|
: m_makeExtraSearchDirectories.at(0));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
void AndroidConfig::updateNdkInformation() const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2013-12-16 20:19:07 +01:00
|
|
|
if (m_NdkInformationUpToDate)
|
|
|
|
return;
|
2013-10-17 13:12:45 +02:00
|
|
|
m_availableNdkPlatforms.clear();
|
2013-12-16 20:19:07 +01:00
|
|
|
FileName path = ndkLocation();
|
2012-06-23 12:24:44 +03:00
|
|
|
QDirIterator it(path.appendPath(QLatin1String("platforms")).toString(), QStringList() << QLatin1String("android-*"), QDir::Dirs);
|
2012-04-18 20:30:57 +03:00
|
|
|
while (it.hasNext()) {
|
|
|
|
const QString &fileName = it.next();
|
2016-02-03 13:49:53 +01:00
|
|
|
m_availableNdkPlatforms.push_back(fileName.midRef(fileName.lastIndexOf(QLatin1Char('-')) + 1).toInt());
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
2014-06-16 18:25:52 +04:00
|
|
|
Utils::sort(m_availableNdkPlatforms, std::greater<int>());
|
2013-12-16 20:19:07 +01:00
|
|
|
|
|
|
|
// detect toolchain host
|
|
|
|
QStringList hostPatterns;
|
|
|
|
switch (HostOsInfo::hostOs()) {
|
|
|
|
case OsTypeLinux:
|
|
|
|
hostPatterns << QLatin1String("linux*");
|
|
|
|
break;
|
|
|
|
case OsTypeWindows:
|
|
|
|
hostPatterns << QLatin1String("windows*");
|
|
|
|
break;
|
|
|
|
case OsTypeMac:
|
|
|
|
hostPatterns << QLatin1String("darwin*");
|
|
|
|
break;
|
|
|
|
default: /* unknown host */ return;
|
|
|
|
}
|
|
|
|
|
2014-02-20 15:08:52 +01:00
|
|
|
path = ndkLocation();
|
2013-12-16 20:19:07 +01:00
|
|
|
QDirIterator jt(path.appendPath(QLatin1String("prebuilt")).toString(), hostPatterns, QDir::Dirs);
|
|
|
|
if (jt.hasNext()) {
|
|
|
|
jt.next();
|
|
|
|
m_toolchainHost = jt.fileName();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_NdkInformationUpToDate = true;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2014-03-24 16:31:28 +01:00
|
|
|
bool AndroidConfig::sortSdkPlatformByApiLevel(const SdkPlatform &a, const SdkPlatform &b)
|
|
|
|
{
|
|
|
|
if (a.apiLevel != b.apiLevel)
|
|
|
|
return a.apiLevel > b.apiLevel;
|
|
|
|
if (a.name != b.name)
|
|
|
|
return a.name < b.name;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
void AndroidConfig::updateAvailableSdkPlatforms() const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2013-12-16 20:19:07 +01:00
|
|
|
if (m_availableSdkPlatformsUpToDate)
|
|
|
|
return;
|
2013-10-17 13:23:08 +02:00
|
|
|
m_availableSdkPlatforms.clear();
|
|
|
|
|
2016-04-29 16:52:58 +02:00
|
|
|
SynchronousProcess proc;
|
2013-11-19 17:25:32 +01:00
|
|
|
proc.setProcessEnvironment(androidToolEnvironment().toProcessEnvironment());
|
2016-04-29 16:52:58 +02:00
|
|
|
SynchronousProcessResponse response
|
2016-05-26 12:12:01 +02:00
|
|
|
= proc.runBlocking(androidToolPath().toString(),
|
|
|
|
QStringList() << QLatin1String("list") << QLatin1String("target")); // list avaialbe AVDs
|
2016-05-20 10:23:28 +02:00
|
|
|
if (response.result != SynchronousProcessResponse::Finished)
|
2013-10-17 13:23:08 +02:00
|
|
|
return;
|
2014-03-24 16:31:28 +01:00
|
|
|
|
|
|
|
SdkPlatform platform;
|
2016-04-29 16:52:58 +02:00
|
|
|
foreach (const QString &l, response.allOutput().split('\n')) {
|
|
|
|
const QString line = l.trimmed();
|
2014-03-24 16:31:28 +01:00
|
|
|
if (line.startsWith(QLatin1String("id:")) && line.contains(QLatin1String("android-"))) {
|
|
|
|
int index = line.indexOf(QLatin1String("\"android-"));
|
|
|
|
if (index == -1)
|
|
|
|
continue;
|
|
|
|
QString androidTarget = line.mid(index + 1, line.length() - index - 2);
|
2015-06-11 12:35:23 +02:00
|
|
|
const QString tmp = androidTarget.mid(androidTarget.lastIndexOf(QLatin1Char('-')) + 1);
|
|
|
|
platform.apiLevel = apiLevelFromAndroidList(tmp);
|
2014-03-24 16:31:28 +01:00
|
|
|
} else if (line.startsWith(QLatin1String("Name:"))) {
|
|
|
|
platform.name = line.mid(6);
|
2014-04-10 15:52:02 +02:00
|
|
|
} else if (line.startsWith(QLatin1String("Tag/ABIs :"))) {
|
|
|
|
platform.abis = cleanAndroidABIs(line.mid(10).trimmed().split(QLatin1String(", ")));
|
2014-03-24 16:31:28 +01:00
|
|
|
} else if (line.startsWith(QLatin1String("ABIs"))) {
|
2014-04-10 15:52:02 +02:00
|
|
|
platform.abis = cleanAndroidABIs(line.mid(6).trimmed().split(QLatin1String(", ")));
|
2014-03-24 16:31:28 +01:00
|
|
|
} else if (line.startsWith(QLatin1String("---")) || line.startsWith(QLatin1String("==="))) {
|
|
|
|
if (platform.apiLevel == -1)
|
|
|
|
continue;
|
2016-08-03 23:29:58 +03:00
|
|
|
auto it = std::lower_bound(m_availableSdkPlatforms.begin(), m_availableSdkPlatforms.end(),
|
|
|
|
platform, sortSdkPlatformByApiLevel);
|
2014-03-24 16:31:28 +01:00
|
|
|
m_availableSdkPlatforms.insert(it, platform);
|
|
|
|
platform = SdkPlatform();
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
2014-04-10 15:52:22 +02:00
|
|
|
|
|
|
|
if (platform.apiLevel != -1) {
|
2016-08-03 23:29:58 +03:00
|
|
|
auto it = std::lower_bound(m_availableSdkPlatforms.begin(), m_availableSdkPlatforms.end(),
|
|
|
|
platform, sortSdkPlatformByApiLevel);
|
2014-04-10 15:52:22 +02:00
|
|
|
m_availableSdkPlatforms.insert(it, platform);
|
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
m_availableSdkPlatformsUpToDate = true;
|
2013-10-17 13:23:08 +02:00
|
|
|
}
|
|
|
|
|
2014-03-24 16:31:28 +01:00
|
|
|
QStringList AndroidConfig::apiLevelNamesFor(const QList<SdkPlatform> &platforms)
|
|
|
|
{
|
2014-07-16 12:35:29 +02:00
|
|
|
return Utils::transform(platforms, AndroidConfig::apiLevelNameFor);
|
2014-03-24 16:31:28 +01:00
|
|
|
}
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
QString AndroidConfig::apiLevelNameFor(const SdkPlatform &platform)
|
|
|
|
{
|
|
|
|
return QLatin1String("android-") + QString::number(platform.apiLevel);
|
|
|
|
}
|
|
|
|
|
2014-03-24 16:31:28 +01:00
|
|
|
QList<SdkPlatform> AndroidConfig::sdkTargets(int minApiLevel) const
|
2013-10-17 13:23:08 +02:00
|
|
|
{
|
2013-12-16 20:19:07 +01:00
|
|
|
updateAvailableSdkPlatforms();
|
2014-03-24 16:31:28 +01:00
|
|
|
QList<SdkPlatform> result;
|
2013-10-17 13:23:08 +02:00
|
|
|
for (int i = 0; i < m_availableSdkPlatforms.size(); ++i) {
|
2014-03-24 16:31:28 +01:00
|
|
|
if (m_availableSdkPlatforms.at(i).apiLevel >= minApiLevel)
|
|
|
|
result << m_availableSdkPlatforms.at(i);
|
2013-10-17 13:23:08 +02:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
FileName AndroidConfig::adbToolPath() const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2015-02-03 23:50:37 +02:00
|
|
|
FileName path = m_sdkLocation;
|
2012-08-31 16:39:20 +02:00
|
|
|
return path.appendPath(QLatin1String("platform-tools/adb" QTC_HOST_EXE_SUFFIX));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2015-02-03 23:50:37 +02:00
|
|
|
Environment AndroidConfig::androidToolEnvironment() const
|
2013-11-19 17:25:32 +01:00
|
|
|
{
|
2015-02-03 23:50:37 +02:00
|
|
|
Environment env = Environment::systemEnvironment();
|
2015-09-09 16:40:12 +02:00
|
|
|
if (!m_openJDKLocation.isEmpty()) {
|
2013-12-16 20:19:07 +01:00
|
|
|
env.set(QLatin1String("JAVA_HOME"), m_openJDKLocation.toUserOutput());
|
2015-09-09 16:40:12 +02:00
|
|
|
Utils::FileName binPath = m_openJDKLocation;
|
|
|
|
binPath.appendPath(QLatin1String("bin"));
|
|
|
|
env.prependOrSetPath(binPath.toUserOutput());
|
|
|
|
}
|
2013-11-19 17:25:32 +01:00
|
|
|
return env;
|
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
FileName AndroidConfig::androidToolPath() const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-08-23 15:53:58 +02:00
|
|
|
if (HostOsInfo::isWindowsHost()) {
|
|
|
|
// I want to switch from using android.bat to using an executable. All it really does is call
|
|
|
|
// Java and I've made some progress on it. So if android.exe exists, return that instead.
|
2013-12-16 20:19:07 +01:00
|
|
|
FileName path = m_sdkLocation;
|
2012-08-31 16:39:20 +02:00
|
|
|
path.appendPath(QLatin1String("tools/android" QTC_HOST_EXE_SUFFIX));
|
2014-10-24 13:15:54 +02:00
|
|
|
if (path.exists())
|
2012-08-23 15:53:58 +02:00
|
|
|
return path;
|
2013-12-16 20:19:07 +01:00
|
|
|
path = m_sdkLocation;
|
2012-09-04 13:45:03 +02:00
|
|
|
return path.appendPath(QLatin1String("tools/android" ANDROID_BAT_SUFFIX));
|
2012-08-23 15:53:58 +02:00
|
|
|
} else {
|
2013-12-16 20:19:07 +01:00
|
|
|
FileName path = m_sdkLocation;
|
2012-08-23 15:53:58 +02:00
|
|
|
return path.appendPath(QLatin1String("tools/android"));
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
FileName AndroidConfig::antToolPath() const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2013-12-16 20:19:07 +01:00
|
|
|
if (!m_antLocation.isEmpty())
|
|
|
|
return m_antLocation;
|
2012-04-18 20:30:57 +03:00
|
|
|
else
|
2014-02-07 15:46:36 +01:00
|
|
|
return FileName::fromLatin1("ant");
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
FileName AndroidConfig::emulatorToolPath() const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2013-12-16 20:19:07 +01:00
|
|
|
FileName path = m_sdkLocation;
|
2012-08-31 16:39:20 +02:00
|
|
|
return path.appendPath(QLatin1String("tools/emulator" QTC_HOST_EXE_SUFFIX));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2014-11-18 18:37:05 +01:00
|
|
|
FileName AndroidConfig::toolPath(const Abi &abi, const QString &ndkToolChainVersion) const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2013-12-16 20:19:07 +01:00
|
|
|
FileName path = m_ndkLocation;
|
2012-04-24 15:49:09 +02:00
|
|
|
return path.appendPath(QString::fromLatin1("toolchains/%1-%2/prebuilt/%3/bin/%4")
|
2014-11-18 18:37:05 +01:00
|
|
|
.arg(toolchainPrefix(abi))
|
2013-01-25 16:49:22 +01:00
|
|
|
.arg(ndkToolChainVersion)
|
2013-12-16 20:19:07 +01:00
|
|
|
.arg(toolchainHost())
|
2014-11-18 18:37:05 +01:00
|
|
|
.arg(toolsPrefix(abi)));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2014-11-18 18:37:05 +01:00
|
|
|
FileName AndroidConfig::gccPath(const Abi &abi, const QString &ndkToolChainVersion) const
|
2013-04-04 01:29:47 -07:00
|
|
|
{
|
2014-11-18 18:37:05 +01:00
|
|
|
return toolPath(abi, ndkToolChainVersion).appendString(QLatin1String("-gcc" QTC_HOST_EXE_SUFFIX));
|
2013-04-04 01:29:47 -07:00
|
|
|
}
|
|
|
|
|
2014-11-18 18:37:05 +01:00
|
|
|
FileName AndroidConfig::gdbPath(const Abi &abi, const QString &ndkToolChainVersion) const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2016-03-14 15:43:03 +02:00
|
|
|
const auto gdbPath = QString::fromLatin1("%1/prebuilt/%2/bin/gdb" QTC_HOST_EXE_SUFFIX).arg(m_ndkLocation.toString()).arg(toolchainHost());
|
|
|
|
if (QFile::exists(gdbPath))
|
|
|
|
return FileName::fromString(gdbPath);
|
|
|
|
|
2014-11-18 18:37:05 +01:00
|
|
|
return toolPath(abi, ndkToolChainVersion).appendString(QLatin1String("-gdb" QTC_HOST_EXE_SUFFIX));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
FileName AndroidConfig::openJDKBinPath() const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2013-12-16 20:19:07 +01:00
|
|
|
FileName path = m_openJDKLocation;
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!path.isEmpty())
|
|
|
|
return path.appendPath(QLatin1String("bin"));
|
|
|
|
return path;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
FileName AndroidConfig::keytoolPath() const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return openJDKBinPath().appendPath(keytoolName);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
QVector<AndroidDeviceInfo> AndroidConfig::connectedDevices(QString *error) const
|
2015-04-10 18:08:51 +02:00
|
|
|
{
|
|
|
|
return connectedDevices(adbToolPath().toString(), error);
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector<AndroidDeviceInfo> AndroidConfig::connectedDevices(const QString &adbToolPath, QString *error)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-07-03 16:57:44 +03:00
|
|
|
QVector<AndroidDeviceInfo> devices;
|
2016-04-29 16:52:58 +02:00
|
|
|
SynchronousProcess adbProc;
|
|
|
|
adbProc.setTimeoutS(30);
|
|
|
|
SynchronousProcessResponse response
|
2016-06-10 13:33:40 +03:00
|
|
|
= adbProc.runBlocking(adbToolPath, QStringList() << QLatin1String("devices"));
|
2016-04-29 16:52:58 +02:00
|
|
|
if (response.result != SynchronousProcessResponse::Finished) {
|
2013-07-03 17:58:48 +02:00
|
|
|
if (error)
|
2013-12-16 20:19:07 +01:00
|
|
|
*error = QApplication::translate("AndroidConfiguration",
|
|
|
|
"Could not run: %1")
|
2015-04-10 18:08:51 +02:00
|
|
|
.arg(adbToolPath + QLatin1String(" devices"));
|
2012-04-18 20:30:57 +03:00
|
|
|
return devices;
|
|
|
|
}
|
2016-06-10 11:34:18 +03:00
|
|
|
QStringList adbDevs = response.allOutput().split('\n', QString::SkipEmptyParts);
|
2013-10-22 13:51:17 +03:00
|
|
|
if (adbDevs.empty())
|
|
|
|
return devices;
|
|
|
|
|
|
|
|
while (adbDevs.first().startsWith("* daemon"))
|
|
|
|
adbDevs.removeFirst(); // remove the daemon logs
|
|
|
|
adbDevs.removeFirst(); // remove "List of devices attached" header line
|
2013-02-24 18:04:36 +04:00
|
|
|
|
|
|
|
// workaround for '????????????' serial numbers:
|
|
|
|
// can use "adb -d" when only one usb device attached
|
2016-04-29 16:52:58 +02:00
|
|
|
foreach (const QString &device, adbDevs) {
|
|
|
|
const QString serialNo = device.left(device.indexOf('\t')).trimmed();
|
|
|
|
const QString deviceType = device.mid(device.indexOf('\t')).trimmed();
|
2015-04-10 18:08:51 +02:00
|
|
|
if (isBootToQt(adbToolPath, serialNo))
|
2013-11-15 16:29:53 +01:00
|
|
|
continue;
|
2013-08-28 12:50:32 +02:00
|
|
|
AndroidDeviceInfo dev;
|
2013-02-24 18:04:36 +04:00
|
|
|
dev.serialNumber = serialNo;
|
2013-09-10 19:19:31 +02:00
|
|
|
dev.type = serialNo.startsWith(QLatin1String("emulator")) ? AndroidDeviceInfo::Emulator : AndroidDeviceInfo::Hardware;
|
2015-04-10 18:08:51 +02:00
|
|
|
dev.sdk = getSDKVersion(adbToolPath, dev.serialNumber);
|
|
|
|
dev.cpuAbi = getAbis(adbToolPath, dev.serialNumber);
|
2014-03-10 15:18:46 +01:00
|
|
|
if (deviceType == QLatin1String("unauthorized"))
|
|
|
|
dev.state = AndroidDeviceInfo::UnAuthorizedState;
|
|
|
|
else if (deviceType == QLatin1String("offline"))
|
|
|
|
dev.state = AndroidDeviceInfo::OfflineState;
|
|
|
|
else
|
|
|
|
dev.state = AndroidDeviceInfo::OkState;
|
2015-04-23 16:25:44 +02:00
|
|
|
|
2016-05-05 17:34:22 +03:00
|
|
|
if (dev.type == AndroidDeviceInfo::Emulator) {
|
2015-04-23 16:25:44 +02:00
|
|
|
dev.avdname = getAvdName(dev.serialNumber);
|
2016-05-05 17:34:22 +03:00
|
|
|
if (dev.avdname.isEmpty())
|
|
|
|
dev.avdname = serialNo;
|
|
|
|
}
|
2015-04-23 16:25:44 +02:00
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
devices.push_back(dev);
|
|
|
|
}
|
2013-08-28 12:50:32 +02:00
|
|
|
|
2014-06-16 18:25:52 +04:00
|
|
|
Utils::sort(devices, androidDevicesLessThan);
|
2013-07-03 17:58:48 +02:00
|
|
|
if (devices.isEmpty() && error)
|
2013-12-16 20:19:07 +01:00
|
|
|
*error = QApplication::translate("AndroidConfiguration",
|
|
|
|
"No devices found in output of: %1")
|
2015-04-10 18:08:51 +02:00
|
|
|
.arg(adbToolPath + QLatin1String(" devices"));
|
2012-04-18 20:30:57 +03:00
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
|
2014-04-11 13:31:01 +02:00
|
|
|
AndroidConfig::CreateAvdInfo AndroidConfig::gatherCreateAVDInfo(QWidget *parent, int minApiLevel, QString targetArch) const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2014-04-11 13:31:01 +02:00
|
|
|
CreateAvdInfo result;
|
2014-03-24 16:31:28 +01:00
|
|
|
AvdDialog d(minApiLevel, targetArch, this, parent);
|
|
|
|
if (d.exec() != QDialog::Accepted || !d.isValid())
|
2014-04-11 13:31:01 +02:00
|
|
|
return result;
|
2014-03-24 16:31:28 +01:00
|
|
|
|
2014-04-11 13:31:01 +02:00
|
|
|
result.target = d.target();
|
|
|
|
result.name = d.name();
|
|
|
|
result.abi = d.abi();
|
|
|
|
result.sdcardSize = d.sdcardSize();
|
|
|
|
return result;
|
|
|
|
}
|
2014-03-24 11:56:26 +01:00
|
|
|
|
2014-04-11 13:31:01 +02:00
|
|
|
QFuture<AndroidConfig::CreateAvdInfo> AndroidConfig::createAVD(CreateAvdInfo info) const
|
|
|
|
{
|
2016-02-05 15:06:15 +01:00
|
|
|
return Utils::runAsync(&AndroidConfig::createAVDImpl, info,
|
|
|
|
androidToolPath(), androidToolEnvironment());
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2015-02-03 23:50:37 +02:00
|
|
|
AndroidConfig::CreateAvdInfo AndroidConfig::createAVDImpl(CreateAvdInfo info, FileName androidToolPath, Environment env)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
|
|
|
QProcess proc;
|
2014-04-11 13:31:01 +02:00
|
|
|
proc.setProcessEnvironment(env.toProcessEnvironment());
|
|
|
|
QStringList arguments;
|
|
|
|
arguments << QLatin1String("create") << QLatin1String("avd")
|
|
|
|
<< QLatin1String("-t") << info.target
|
|
|
|
<< QLatin1String("-n") << info.name
|
2015-04-14 13:24:33 +02:00
|
|
|
<< QLatin1String("-b") << info.abi;
|
|
|
|
if (info.sdcardSize > 0)
|
|
|
|
arguments << QLatin1String("-c") << QString::fromLatin1("%1M").arg(info.sdcardSize);
|
2014-04-11 13:31:01 +02:00
|
|
|
proc.start(androidToolPath.toString(), arguments);
|
|
|
|
if (!proc.waitForStarted()) {
|
|
|
|
info.error = QApplication::translate("AndroidConfig", "Could not start process \"%1 %2\"")
|
2014-08-23 01:19:53 +02:00
|
|
|
.arg(androidToolPath.toString(), arguments.join(QLatin1Char(' ')));
|
2014-04-11 13:31:01 +02:00
|
|
|
return info;
|
|
|
|
}
|
2016-04-29 16:52:58 +02:00
|
|
|
QTC_CHECK(proc.state() == QProcess::Running);
|
2013-10-10 17:19:28 +02:00
|
|
|
proc.write(QByteArray("yes\n")); // yes to "Do you wish to create a custom hardware profile"
|
|
|
|
|
|
|
|
QByteArray question;
|
|
|
|
while (true) {
|
|
|
|
proc.waitForReadyRead(500);
|
|
|
|
question += proc.readAllStandardOutput();
|
|
|
|
if (question.endsWith(QByteArray("]:"))) {
|
|
|
|
// truncate to last line
|
|
|
|
int index = question.lastIndexOf(QByteArray("\n"));
|
|
|
|
if (index != -1)
|
|
|
|
question = question.mid(index);
|
|
|
|
if (question.contains("hw.gpu.enabled"))
|
|
|
|
proc.write(QByteArray("yes\n"));
|
|
|
|
else
|
|
|
|
proc.write(QByteArray("\n"));
|
|
|
|
question.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (proc.state() != QProcess::Running)
|
|
|
|
break;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
2016-04-29 16:52:58 +02:00
|
|
|
QTC_CHECK(proc.state() == QProcess::NotRunning);
|
2013-10-10 17:19:28 +02:00
|
|
|
|
2014-03-24 11:56:26 +01:00
|
|
|
QString errorOutput = QString::fromLocal8Bit(proc.readAllStandardError());
|
|
|
|
// The exit code is always 0, so we need to check stderr
|
|
|
|
// For now assume that any output at all indicates a error
|
|
|
|
if (!errorOutput.isEmpty()) {
|
2014-04-11 13:31:01 +02:00
|
|
|
info.error = errorOutput;
|
2014-03-24 11:56:26 +01:00
|
|
|
}
|
|
|
|
|
2014-04-11 13:31:01 +02:00
|
|
|
return info;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
bool AndroidConfig::removeAVD(const QString &name) const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2016-04-29 16:52:58 +02:00
|
|
|
SynchronousProcess proc;
|
|
|
|
proc.setTimeoutS(5);
|
2013-11-19 17:25:32 +01:00
|
|
|
proc.setProcessEnvironment(androidToolEnvironment().toProcessEnvironment());
|
2016-04-29 16:52:58 +02:00
|
|
|
SynchronousProcessResponse response
|
2016-05-26 12:12:01 +02:00
|
|
|
= proc.runBlocking(androidToolPath().toString(),
|
|
|
|
QStringList() << QLatin1String("delete") << QLatin1String("avd")
|
|
|
|
<< QLatin1String("-n") << name);
|
2016-04-29 16:52:58 +02:00
|
|
|
return response.result == SynchronousProcessResponse::Finished && response.exitCode == 0;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2015-12-04 10:03:45 +02:00
|
|
|
QFuture<QVector<AndroidDeviceInfo>> AndroidConfig::androidVirtualDevicesFuture() const
|
2015-01-08 17:05:09 +01:00
|
|
|
{
|
2016-02-05 15:06:15 +01:00
|
|
|
return Utils::runAsync(&AndroidConfig::androidVirtualDevices,
|
|
|
|
androidToolPath().toString(), androidToolEnvironment());
|
2015-01-08 17:05:09 +01:00
|
|
|
}
|
|
|
|
|
2015-04-10 18:08:51 +02:00
|
|
|
QVector<AndroidDeviceInfo> AndroidConfig::androidVirtualDevices(const QString &androidTool, const Environment &environment)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-07-03 16:57:44 +03:00
|
|
|
QVector<AndroidDeviceInfo> devices;
|
2016-04-29 16:52:58 +02:00
|
|
|
SynchronousProcess proc;
|
|
|
|
proc.setTimeoutS(20);
|
2015-01-08 17:05:09 +01:00
|
|
|
proc.setProcessEnvironment(environment.toProcessEnvironment());
|
2016-04-29 16:52:58 +02:00
|
|
|
SynchronousProcessResponse response
|
|
|
|
= proc.run(androidTool,
|
|
|
|
QStringList() << QLatin1String("list") << QLatin1String("avd")); // list available AVDs
|
|
|
|
if (response.result != SynchronousProcessResponse::Finished)
|
2012-04-18 20:30:57 +03:00
|
|
|
return devices;
|
2016-04-29 16:52:58 +02:00
|
|
|
|
|
|
|
QStringList avds = response.allOutput().split('\n');
|
2013-10-22 13:51:17 +03:00
|
|
|
if (avds.empty())
|
|
|
|
return devices;
|
|
|
|
|
2016-04-29 16:52:58 +02:00
|
|
|
while (avds.first().startsWith(QLatin1String("* daemon")))
|
2013-10-22 13:51:17 +03:00
|
|
|
avds.removeFirst(); // remove the daemon logs
|
|
|
|
avds.removeFirst(); // remove "List of devices attached" header line
|
|
|
|
|
2015-04-10 15:13:25 +02:00
|
|
|
bool nextLineIsTargetLine = false;
|
|
|
|
|
2012-07-03 16:57:44 +03:00
|
|
|
AndroidDeviceInfo dev;
|
2012-04-18 20:30:57 +03:00
|
|
|
for (int i = 0; i < avds.size(); i++) {
|
2016-04-29 16:52:58 +02:00
|
|
|
QString line = avds.at(i);
|
2012-04-18 20:30:57 +03:00
|
|
|
if (!line.contains(QLatin1String("Name:")))
|
|
|
|
continue;
|
|
|
|
|
2014-09-24 12:22:14 +02:00
|
|
|
int index = line.indexOf(QLatin1Char(':')) + 2;
|
|
|
|
if (index >= line.size())
|
|
|
|
break;
|
2015-04-23 16:25:44 +02:00
|
|
|
dev.avdname = line.mid(index).trimmed();
|
2014-09-24 12:22:14 +02:00
|
|
|
dev.sdk = -1;
|
|
|
|
dev.cpuAbi.clear();
|
2012-04-18 20:30:57 +03:00
|
|
|
++i;
|
|
|
|
for (; i < avds.size(); ++i) {
|
2016-04-29 16:52:58 +02:00
|
|
|
line = avds.at(i);
|
2012-04-18 20:30:57 +03:00
|
|
|
if (line.contains(QLatin1String("---------")))
|
|
|
|
break;
|
2015-04-10 15:13:25 +02:00
|
|
|
|
|
|
|
if (line.contains(QLatin1String("Target:")) || nextLineIsTargetLine) {
|
|
|
|
if (line.contains(QLatin1String("Google APIs"))) {
|
|
|
|
nextLineIsTargetLine = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nextLineIsTargetLine = false;
|
|
|
|
|
2014-09-24 12:22:14 +02:00
|
|
|
int lastIndex = line.lastIndexOf(QLatin1Char(' '));
|
|
|
|
if (lastIndex == -1) // skip line
|
|
|
|
break;
|
|
|
|
QString tmp = line.mid(lastIndex).remove(QLatin1Char(')')).trimmed();
|
2015-06-11 12:35:23 +02:00
|
|
|
dev.sdk = apiLevelFromAndroidList(tmp);
|
2014-07-16 17:36:52 +02:00
|
|
|
}
|
2014-09-24 12:22:14 +02:00
|
|
|
if (line.contains(QLatin1String("Tag/ABI:"))) {
|
|
|
|
int lastIndex = line.lastIndexOf(QLatin1Char('/')) + 1;
|
|
|
|
if (lastIndex >= line.size())
|
|
|
|
break;
|
|
|
|
dev.cpuAbi = QStringList() << line.mid(lastIndex);
|
|
|
|
} else if (line.contains(QLatin1String("ABI:"))) {
|
|
|
|
int lastIndex = line.lastIndexOf(QLatin1Char(' ')) + 1;
|
|
|
|
if (lastIndex >= line.size())
|
|
|
|
break;
|
|
|
|
dev.cpuAbi = QStringList() << line.mid(lastIndex).trimmed();
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
2013-07-05 18:54:42 +02:00
|
|
|
// armeabi-v7a devices can also run armeabi code
|
|
|
|
if (dev.cpuAbi == QStringList(QLatin1String("armeabi-v7a")))
|
|
|
|
dev.cpuAbi << QLatin1String("armeabi");
|
2014-03-10 15:18:46 +01:00
|
|
|
dev.state = AndroidDeviceInfo::OkState;
|
2013-09-10 19:19:31 +02:00
|
|
|
dev.type = AndroidDeviceInfo::Emulator;
|
2014-09-24 12:22:14 +02:00
|
|
|
if (dev.cpuAbi.isEmpty() || dev.sdk == -1)
|
|
|
|
continue;
|
2012-04-18 20:30:57 +03:00
|
|
|
devices.push_back(dev);
|
|
|
|
}
|
2014-06-16 18:25:52 +04:00
|
|
|
Utils::sort(devices, androidDevicesLessThan);
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
|
2015-04-23 16:25:44 +02:00
|
|
|
QString AndroidConfig::startAVD(const QString &name) const
|
2013-07-05 18:54:42 +02:00
|
|
|
{
|
2015-04-23 16:25:44 +02:00
|
|
|
if (!findAvd(name).isEmpty() || startAVDAsync(name))
|
|
|
|
return waitForAvd(name);
|
2013-07-05 18:54:42 +02:00
|
|
|
return QString();
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
bool AndroidConfig::startAVDAsync(const QString &avdName) const
|
2013-07-05 18:54:42 +02:00
|
|
|
{
|
|
|
|
QProcess *avdProcess = new QProcess();
|
2016-06-26 22:52:59 +03:00
|
|
|
QObject::connect(avdProcess, static_cast<void (QProcess::*)(int)>(&QProcess::finished),
|
|
|
|
avdProcess, &QObject::deleteLater);
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
// start the emulator
|
2014-10-31 16:09:34 +01:00
|
|
|
QStringList arguments;
|
|
|
|
if (AndroidConfigurations::force32bitEmulator())
|
|
|
|
arguments << QLatin1String("-force-32bit");
|
|
|
|
|
|
|
|
arguments << QLatin1String("-partition-size") << QString::number(partitionSize())
|
|
|
|
<< QLatin1String("-avd") << avdName;
|
|
|
|
avdProcess->start(emulatorToolPath().toString(), arguments);
|
2012-10-24 10:03:11 +02:00
|
|
|
if (!avdProcess->waitForStarted(-1)) {
|
|
|
|
delete avdProcess;
|
2013-07-05 18:54:42 +02:00
|
|
|
return false;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
2013-07-05 18:54:42 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-23 16:25:44 +02:00
|
|
|
QString AndroidConfig::findAvd(const QString &avdName) const
|
2013-10-17 17:40:56 +02:00
|
|
|
{
|
|
|
|
QVector<AndroidDeviceInfo> devices = connectedDevices();
|
|
|
|
foreach (AndroidDeviceInfo device, devices) {
|
2015-04-23 16:25:44 +02:00
|
|
|
if (device.type != AndroidDeviceInfo::Emulator)
|
2013-10-17 17:40:56 +02:00
|
|
|
continue;
|
2015-04-23 16:25:44 +02:00
|
|
|
if (device.avdname == avdName)
|
|
|
|
return device.serialNumber;
|
2013-10-17 17:40:56 +02:00
|
|
|
}
|
2013-11-13 16:32:38 +01:00
|
|
|
return QString();
|
2013-10-17 17:40:56 +02:00
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
bool AndroidConfig::isConnected(const QString &serialNumber) const
|
2013-07-05 18:54:42 +02:00
|
|
|
{
|
2013-11-13 16:35:29 +01:00
|
|
|
QVector<AndroidDeviceInfo> devices = connectedDevices();
|
|
|
|
foreach (AndroidDeviceInfo device, devices) {
|
|
|
|
if (device.serialNumber == serialNumber)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-05 18:54:42 +02:00
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
bool AndroidConfig::waitForBooted(const QString &serialNumber, const QFutureInterface<bool> &fi) const
|
2013-11-13 16:35:29 +01:00
|
|
|
{
|
|
|
|
// found a serial number, now wait until it's done booting...
|
|
|
|
for (int i = 0; i < 60; ++i) {
|
|
|
|
if (fi.isCanceled())
|
|
|
|
return false;
|
|
|
|
if (hasFinishedBooting(serialNumber)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
2016-09-20 11:22:05 +03:00
|
|
|
QThread::sleep(2);
|
2013-11-13 16:35:29 +01:00
|
|
|
if (!isConnected(serialNumber)) // device was disconnected
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-23 16:25:44 +02:00
|
|
|
QString AndroidConfig::waitForAvd(const QString &avdName, const QFutureInterface<bool> &fi) const
|
2013-11-13 16:35:29 +01:00
|
|
|
{
|
|
|
|
// we cannot use adb -e wait-for-device, since that doesn't work if a emulator is already running
|
|
|
|
// 60 rounds of 2s sleeping, two minutes for the avd to start
|
2013-07-05 18:54:42 +02:00
|
|
|
QString serialNumber;
|
2013-11-13 16:35:29 +01:00
|
|
|
for (int i = 0; i < 60; ++i) {
|
|
|
|
if (fi.isCanceled())
|
2012-10-24 10:03:11 +02:00
|
|
|
return QString();
|
2015-04-23 16:25:44 +02:00
|
|
|
serialNumber = findAvd(avdName);
|
2013-11-13 16:35:29 +01:00
|
|
|
if (!serialNumber.isEmpty())
|
|
|
|
return waitForBooted(serialNumber, fi) ? serialNumber : QString();
|
2016-09-20 11:22:05 +03:00
|
|
|
QThread::sleep(2);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
bool AndroidConfig::isBootToQt(const QString &device) const
|
2015-04-10 18:08:51 +02:00
|
|
|
{
|
|
|
|
return isBootToQt(adbToolPath().toString(), device);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AndroidConfig::isBootToQt(const QString &adbToolPath, const QString &device)
|
2013-11-15 16:29:53 +01:00
|
|
|
{
|
|
|
|
// workaround for '????????????' serial numbers
|
|
|
|
QStringList arguments = AndroidDeviceInfo::adbSelector(device);
|
|
|
|
arguments << QLatin1String("shell")
|
|
|
|
<< QLatin1String("ls -l /system/bin/appcontroller || ls -l /usr/bin/appcontroller && echo Boot2Qt");
|
|
|
|
|
2016-04-29 16:52:58 +02:00
|
|
|
SynchronousProcess adbProc;
|
|
|
|
adbProc.setTimeoutS(10);
|
2016-06-10 13:33:40 +03:00
|
|
|
SynchronousProcessResponse response = adbProc.runBlocking(adbToolPath, arguments);
|
2016-04-29 16:52:58 +02:00
|
|
|
return response.result == SynchronousProcessResponse::Finished
|
|
|
|
&& response.allOutput().contains(QLatin1String("Boot2Qt"));
|
2013-11-15 16:29:53 +01:00
|
|
|
}
|
|
|
|
|
2015-04-10 18:08:51 +02:00
|
|
|
|
|
|
|
QString AndroidConfig::getDeviceProperty(const QString &adbToolPath, const QString &device, const QString &property)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2013-02-24 18:04:36 +04:00
|
|
|
// workaround for '????????????' serial numbers
|
|
|
|
QStringList arguments = AndroidDeviceInfo::adbSelector(device);
|
2016-04-29 16:52:58 +02:00
|
|
|
arguments << QLatin1String("shell") << QLatin1String("getprop") << property;
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2016-04-29 16:52:58 +02:00
|
|
|
SynchronousProcess adbProc;
|
|
|
|
adbProc.setTimeoutS(10);
|
2016-05-26 12:12:01 +02:00
|
|
|
SynchronousProcessResponse response = adbProc.runBlocking(adbToolPath, arguments);
|
2016-04-29 16:52:58 +02:00
|
|
|
if (response.result != SynchronousProcessResponse::Finished)
|
2015-04-10 16:46:30 +02:00
|
|
|
return QString();
|
|
|
|
|
2016-04-29 16:52:58 +02:00
|
|
|
return response.allOutput();
|
2015-04-10 16:46:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int AndroidConfig::getSDKVersion(const QString &device) const
|
|
|
|
{
|
2015-04-10 18:08:51 +02:00
|
|
|
return getSDKVersion(adbToolPath().toString(), device);
|
|
|
|
}
|
|
|
|
|
|
|
|
int AndroidConfig::getSDKVersion(const QString &adbToolPath, const QString &device)
|
|
|
|
{
|
|
|
|
QString tmp = getDeviceProperty(adbToolPath, device, QLatin1String("ro.build.version.sdk"));
|
2015-04-10 16:46:30 +02:00
|
|
|
if (tmp.isEmpty())
|
2012-04-18 20:30:57 +03:00
|
|
|
return -1;
|
2015-04-10 16:46:30 +02:00
|
|
|
return tmp.trimmed().toInt();
|
|
|
|
}
|
|
|
|
|
2015-04-23 16:25:44 +02:00
|
|
|
QString AndroidConfig::getAvdName(const QString &serialnumber)
|
|
|
|
{
|
|
|
|
int index = serialnumber.indexOf(QLatin1String("-"));
|
|
|
|
if (index == -1)
|
|
|
|
return QString();
|
|
|
|
bool ok;
|
2016-02-03 13:49:53 +01:00
|
|
|
int port = serialnumber.midRef(index + 1).toInt(&ok);
|
2015-04-23 16:25:44 +02:00
|
|
|
if (!ok)
|
|
|
|
return QString();
|
|
|
|
|
2016-04-29 08:54:00 +02:00
|
|
|
const QByteArray avdName = "avd name\n";
|
2015-04-23 16:25:44 +02:00
|
|
|
|
|
|
|
QTcpSocket tcpSocket;
|
|
|
|
tcpSocket.connectToHost(QHostAddress(QHostAddress::LocalHost), port);
|
2016-05-05 17:34:22 +03:00
|
|
|
if (!tcpSocket.waitForConnected(100)) // Don't wait more than 100ms for a local connection
|
|
|
|
return QString{};
|
|
|
|
|
2015-04-23 16:25:44 +02:00
|
|
|
tcpSocket.write(avdName + "exit\n");
|
2016-05-05 17:34:22 +03:00
|
|
|
tcpSocket.waitForDisconnected(500);
|
2015-04-23 16:25:44 +02:00
|
|
|
|
2016-04-29 08:54:00 +02:00
|
|
|
QByteArray name;
|
|
|
|
const QByteArrayList response = tcpSocket.readAll().split('\n');
|
|
|
|
// The input "avd name" might not be echoed as-is, but contain ASCII
|
|
|
|
// control sequences.
|
|
|
|
for (int i = response.size() - 1; i > 1; --i) {
|
2016-08-25 15:46:50 +03:00
|
|
|
if (response.at(i).startsWith("OK")) {
|
2016-04-29 08:54:00 +02:00
|
|
|
name = response.at(i - 1);
|
2016-08-25 15:46:50 +03:00
|
|
|
break;
|
|
|
|
}
|
2016-04-29 08:54:00 +02:00
|
|
|
}
|
|
|
|
return QString::fromLatin1(name).trimmed();
|
2015-04-23 16:25:44 +02:00
|
|
|
}
|
|
|
|
|
2015-04-10 16:46:30 +02:00
|
|
|
AndroidConfig::OpenGl AndroidConfig::getOpenGLEnabled(const QString &emulator) const
|
|
|
|
{
|
|
|
|
QDir dir = QDir::home();
|
|
|
|
if (!dir.cd(QLatin1String(".android")))
|
|
|
|
return OpenGl::Unknown;
|
|
|
|
if (!dir.cd(QLatin1String("avd")))
|
|
|
|
return OpenGl::Unknown;
|
|
|
|
if (!dir.cd(emulator + QLatin1String(".avd")))
|
|
|
|
return OpenGl::Unknown;
|
|
|
|
QFile file(dir.filePath(QLatin1String("config.ini")));
|
|
|
|
if (!file.exists())
|
|
|
|
return OpenGl::Unknown;
|
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
|
|
|
return OpenGl::Unknown;
|
|
|
|
while (!file.atEnd()) {
|
|
|
|
QByteArray line = file.readLine();
|
|
|
|
if (line.contains("hw.gpu.enabled") && line.contains("yes"))
|
|
|
|
return OpenGl::Enabled;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
2015-04-10 16:46:30 +02:00
|
|
|
return OpenGl::Disabled;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2013-07-03 17:58:48 +02:00
|
|
|
//!
|
|
|
|
//! \brief AndroidConfigurations::getProductModel
|
|
|
|
//! \param device serial number
|
|
|
|
//! \return the produce model of the device or if that cannot be read the serial number
|
|
|
|
//!
|
2013-12-16 20:19:07 +01:00
|
|
|
QString AndroidConfig::getProductModel(const QString &device) const
|
2013-07-03 17:58:48 +02:00
|
|
|
{
|
2013-09-10 19:19:31 +02:00
|
|
|
if (m_serialNumberToDeviceName.contains(device))
|
|
|
|
return m_serialNumberToDeviceName.value(device);
|
2013-07-03 17:58:48 +02:00
|
|
|
|
2015-04-10 18:08:51 +02:00
|
|
|
QString model = getDeviceProperty(adbToolPath().toString(), device, QLatin1String("ro.product.model")).trimmed();
|
2013-07-03 17:58:48 +02:00
|
|
|
if (model.isEmpty())
|
|
|
|
return device;
|
2015-04-10 16:46:30 +02:00
|
|
|
|
2013-09-10 19:19:31 +02:00
|
|
|
if (!device.startsWith(QLatin1String("????")))
|
|
|
|
m_serialNumberToDeviceName.insert(device, model);
|
2013-07-03 17:58:48 +02:00
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
bool AndroidConfig::hasFinishedBooting(const QString &device) const
|
2013-07-05 18:54:42 +02:00
|
|
|
{
|
|
|
|
QStringList arguments = AndroidDeviceInfo::adbSelector(device);
|
|
|
|
arguments << QLatin1String("shell") << QLatin1String("getprop")
|
|
|
|
<< QLatin1String("init.svc.bootanim");
|
|
|
|
|
2016-04-29 16:52:58 +02:00
|
|
|
SynchronousProcess adbProc;
|
|
|
|
adbProc.setTimeoutS(10);
|
2016-06-10 13:33:40 +03:00
|
|
|
SynchronousProcessResponse response = adbProc.runBlocking(adbToolPath().toString(), arguments);
|
2016-04-29 16:52:58 +02:00
|
|
|
if (response.result != SynchronousProcessResponse::Finished)
|
2013-07-05 18:54:42 +02:00
|
|
|
return false;
|
2016-04-29 16:52:58 +02:00
|
|
|
QString value = response.allOutput().trimmed();
|
|
|
|
return value == QLatin1String("stopped");
|
2013-07-05 18:54:42 +02:00
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
QStringList AndroidConfig::getAbis(const QString &device) const
|
2015-04-10 18:08:51 +02:00
|
|
|
{
|
|
|
|
return getAbis(adbToolPath().toString(), device);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList AndroidConfig::getAbis(const QString &adbToolPath, const QString &device)
|
2013-05-03 15:10:21 +02:00
|
|
|
{
|
|
|
|
QStringList result;
|
2014-11-18 12:55:21 +01:00
|
|
|
// First try via ro.product.cpu.abilist
|
|
|
|
QStringList arguments = AndroidDeviceInfo::adbSelector(device);
|
2016-04-29 16:52:58 +02:00
|
|
|
arguments << QLatin1String("shell") << QLatin1String("getprop") << QLatin1String("ro.product.cpu.abilist");
|
|
|
|
SynchronousProcess adbProc;
|
|
|
|
adbProc.setTimeoutS(10);
|
2016-06-10 13:33:40 +03:00
|
|
|
SynchronousProcessResponse response = adbProc.runBlocking(adbToolPath, arguments);
|
2016-04-29 16:52:58 +02:00
|
|
|
if (response.result != SynchronousProcessResponse::Finished)
|
2014-11-18 12:55:21 +01:00
|
|
|
return result;
|
2016-04-29 16:52:58 +02:00
|
|
|
|
|
|
|
QString output = response.allOutput().trimmed();
|
2014-11-18 12:55:21 +01:00
|
|
|
if (!output.isEmpty()) {
|
|
|
|
QStringList result = output.split(QLatin1Char(','));
|
|
|
|
if (!result.isEmpty())
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fall back to ro.product.cpu.abi, ro.product.cpu.abi2 ...
|
2013-11-15 16:45:55 +01:00
|
|
|
for (int i = 1; i < 6; ++i) {
|
2013-05-03 15:10:21 +02:00
|
|
|
QStringList arguments = AndroidDeviceInfo::adbSelector(device);
|
|
|
|
arguments << QLatin1String("shell") << QLatin1String("getprop");
|
|
|
|
if (i == 1)
|
|
|
|
arguments << QLatin1String("ro.product.cpu.abi");
|
|
|
|
else
|
|
|
|
arguments << QString::fromLatin1("ro.product.cpu.abi%1").arg(i);
|
|
|
|
|
2016-04-29 16:52:58 +02:00
|
|
|
SynchronousProcess abiProc;
|
|
|
|
abiProc.setTimeoutS(10);
|
2016-06-10 13:33:40 +03:00
|
|
|
SynchronousProcessResponse abiResponse = abiProc.runBlocking(adbToolPath, arguments);
|
2016-04-29 16:52:58 +02:00
|
|
|
if (abiResponse.result != SynchronousProcessResponse::Finished)
|
2013-05-03 15:10:21 +02:00
|
|
|
return result;
|
2016-04-29 16:52:58 +02:00
|
|
|
|
|
|
|
QString abi = abiResponse.allOutput().trimmed();
|
2013-05-03 15:10:21 +02:00
|
|
|
if (abi.isEmpty())
|
|
|
|
break;
|
|
|
|
result << abi;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-03-24 16:31:28 +01:00
|
|
|
SdkPlatform AndroidConfig::highestAndroidSdk() const
|
2013-09-17 18:24:57 +02:00
|
|
|
{
|
2013-12-16 20:19:07 +01:00
|
|
|
updateAvailableSdkPlatforms();
|
2013-10-17 13:23:08 +02:00
|
|
|
if (m_availableSdkPlatforms.isEmpty())
|
2014-03-24 16:31:28 +01:00
|
|
|
return SdkPlatform();
|
|
|
|
return m_availableSdkPlatforms.first();
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
2014-06-25 15:41:32 +02:00
|
|
|
QString AndroidConfig::bestNdkPlatformMatch(int target) const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2014-04-16 17:27:04 +02:00
|
|
|
target = std::max(9, target);
|
2014-06-25 15:41:32 +02:00
|
|
|
updateNdkInformation();
|
2013-10-17 13:12:45 +02:00
|
|
|
foreach (int apiLevel, m_availableNdkPlatforms) {
|
2012-04-18 20:30:57 +03:00
|
|
|
if (apiLevel <= target)
|
|
|
|
return QString::fromLatin1("android-%1").arg(apiLevel);
|
|
|
|
}
|
2014-05-07 15:03:43 +03:00
|
|
|
return QLatin1String("android-9");
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
FileName AndroidConfig::sdkLocation() const
|
2013-05-16 15:49:24 +02:00
|
|
|
{
|
2013-12-16 20:19:07 +01:00
|
|
|
return m_sdkLocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidConfig::setSdkLocation(const FileName &sdkLocation)
|
|
|
|
{
|
|
|
|
m_sdkLocation = sdkLocation;
|
|
|
|
m_availableSdkPlatformsUpToDate = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileName AndroidConfig::ndkLocation() const
|
|
|
|
{
|
|
|
|
return m_ndkLocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidConfig::setNdkLocation(const FileName &ndkLocation)
|
|
|
|
{
|
|
|
|
m_ndkLocation = ndkLocation;
|
|
|
|
m_NdkInformationUpToDate = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileName AndroidConfig::antLocation() const
|
|
|
|
{
|
|
|
|
return m_antLocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidConfig::setAntLocation(const FileName &antLocation)
|
|
|
|
{
|
|
|
|
m_antLocation = antLocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileName AndroidConfig::openJDKLocation() const
|
|
|
|
{
|
|
|
|
return m_openJDKLocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidConfig::setOpenJDKLocation(const FileName &openJDKLocation)
|
|
|
|
{
|
|
|
|
m_openJDKLocation = openJDKLocation;
|
|
|
|
m_availableSdkPlatformsUpToDate = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileName AndroidConfig::keystoreLocation() const
|
|
|
|
{
|
|
|
|
return m_keystoreLocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidConfig::setKeystoreLocation(const FileName &keystoreLocation)
|
|
|
|
{
|
|
|
|
m_keystoreLocation = keystoreLocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AndroidConfig::toolchainHost() const
|
|
|
|
{
|
|
|
|
updateNdkInformation();
|
|
|
|
return m_toolchainHost;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList AndroidConfig::makeExtraSearchDirectories() const
|
|
|
|
{
|
|
|
|
return m_makeExtraSearchDirectories;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned AndroidConfig::partitionSize() const
|
|
|
|
{
|
|
|
|
return m_partitionSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidConfig::setPartitionSize(unsigned partitionSize)
|
|
|
|
{
|
|
|
|
m_partitionSize = partitionSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AndroidConfig::automaticKitCreation() const
|
|
|
|
{
|
|
|
|
return m_automaticKitCreation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidConfig::setAutomaticKitCreation(bool b)
|
|
|
|
{
|
|
|
|
m_automaticKitCreation = b;
|
|
|
|
}
|
|
|
|
|
2014-09-22 16:20:51 +03:00
|
|
|
bool AndroidConfig::useGrandle() const
|
|
|
|
{
|
|
|
|
return m_useGradle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidConfig::setUseGradle(bool b)
|
|
|
|
{
|
|
|
|
m_useGradle = b;
|
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
///////////////////////////////////
|
|
|
|
// AndroidConfigurations
|
|
|
|
///////////////////////////////////
|
|
|
|
void AndroidConfigurations::setConfig(const AndroidConfig &devConfigs)
|
|
|
|
{
|
|
|
|
m_instance->m_config = devConfigs;
|
|
|
|
|
|
|
|
m_instance->save();
|
|
|
|
m_instance->updateAndroidDevice();
|
2015-04-22 17:42:23 +02:00
|
|
|
m_instance->registerNewToolChains();
|
2014-03-11 13:05:36 +01:00
|
|
|
m_instance->updateAutomaticKitList();
|
2015-04-22 17:42:23 +02:00
|
|
|
m_instance->removeOldToolChains();
|
2013-12-16 20:19:07 +01:00
|
|
|
emit m_instance->updated();
|
|
|
|
}
|
|
|
|
|
2015-02-03 23:50:37 +02:00
|
|
|
AndroidDeviceInfo AndroidConfigurations::showDeviceDialog(Project *project,
|
2014-11-17 16:22:28 +01:00
|
|
|
int apiLevel, const QString &abi,
|
|
|
|
Options options)
|
2013-12-16 20:19:07 +01:00
|
|
|
{
|
|
|
|
QString serialNumber = defaultDevice(project, abi);
|
2015-04-29 15:21:37 +02:00
|
|
|
AndroidDeviceDialog dialog(apiLevel, abi, options, serialNumber, Core::ICore::mainWindow());
|
2015-12-04 10:03:45 +02:00
|
|
|
AndroidDeviceInfo info = dialog.device();
|
|
|
|
if (dialog.saveDeviceSelection() && info.isValid()) {
|
|
|
|
const QString serialNumber = info.type == AndroidDeviceInfo::Hardware ?
|
|
|
|
info.serialNumber : info.avdname;
|
|
|
|
if (!serialNumber.isEmpty())
|
|
|
|
AndroidConfigurations::setDefaultDevice(project, abi, serialNumber);
|
2013-12-16 20:19:07 +01:00
|
|
|
}
|
2015-12-04 10:03:45 +02:00
|
|
|
return info;
|
2013-12-16 20:19:07 +01:00
|
|
|
}
|
|
|
|
|
2015-02-03 23:50:37 +02:00
|
|
|
void AndroidConfigurations::clearDefaultDevices(Project *project)
|
2013-12-16 20:19:07 +01:00
|
|
|
{
|
|
|
|
if (m_instance->m_defaultDeviceForAbi.contains(project))
|
|
|
|
m_instance->m_defaultDeviceForAbi.remove(project);
|
|
|
|
}
|
|
|
|
|
2015-02-03 23:50:37 +02:00
|
|
|
void AndroidConfigurations::setDefaultDevice(Project *project, const QString &abi, const QString &serialNumber)
|
2013-12-16 20:19:07 +01:00
|
|
|
{
|
|
|
|
m_instance->m_defaultDeviceForAbi[project][abi] = serialNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AndroidConfigurations::defaultDevice(Project *project, const QString &abi)
|
|
|
|
{
|
|
|
|
if (!m_instance->m_defaultDeviceForAbi.contains(project))
|
|
|
|
return QString();
|
|
|
|
const QMap<QString, QString> &map = m_instance->m_defaultDeviceForAbi.value(project);
|
|
|
|
if (!map.contains(abi))
|
|
|
|
return QString();
|
|
|
|
return map.value(abi);
|
2013-05-16 15:49:24 +02:00
|
|
|
}
|
|
|
|
|
2013-08-08 19:15:23 +03:00
|
|
|
static bool equalKits(Kit *a, Kit *b)
|
2013-02-14 15:51:59 +01:00
|
|
|
{
|
2015-04-22 17:42:23 +02:00
|
|
|
if (QtSupport::QtKitInformation::qtVersion(a) != QtSupport::QtKitInformation::qtVersion(b))
|
|
|
|
return false;
|
2016-07-12 16:27:45 +02:00
|
|
|
ToolChain *atc = ToolChainKitInformation::toolChain(a, ToolChain::Language::Cxx);
|
|
|
|
ToolChain *btc = ToolChainKitInformation::toolChain(b, ToolChain::Language::Cxx);
|
2015-04-22 17:42:23 +02:00
|
|
|
if (atc == btc)
|
|
|
|
return true;
|
2015-07-15 16:16:41 +02:00
|
|
|
if (!atc || atc->typeId() != Constants::ANDROID_TOOLCHAIN_ID)
|
2015-04-22 17:42:23 +02:00
|
|
|
return false;
|
2015-07-15 16:16:41 +02:00
|
|
|
if (!btc || btc->typeId() != Constants::ANDROID_TOOLCHAIN_ID)
|
2015-04-22 17:42:23 +02:00
|
|
|
return false;
|
|
|
|
AndroidToolChain *aatc = static_cast<AndroidToolChain *>(atc);
|
|
|
|
AndroidToolChain *bbtc = static_cast<AndroidToolChain *>(btc);
|
|
|
|
if (aatc->ndkToolChainVersion() == bbtc->ndkToolChainVersion()
|
|
|
|
&& aatc->targetAbi() == bbtc->targetAbi())
|
|
|
|
return true;
|
|
|
|
return false;
|
2013-02-14 15:51:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-22 17:42:23 +02:00
|
|
|
void AndroidConfigurations::registerNewToolChains()
|
2014-03-11 13:05:36 +01:00
|
|
|
{
|
2015-10-15 16:01:40 +02:00
|
|
|
const QList<ToolChain *> existingAndroidToolChains
|
|
|
|
= Utils::filtered(ToolChainManager::toolChains(),
|
|
|
|
Utils::equal(&ToolChain::typeId, Core::Id(Constants::ANDROID_TOOLCHAIN_ID)));
|
|
|
|
|
|
|
|
const QList<ToolChain *> newToolchains
|
|
|
|
= AndroidToolChainFactory::autodetectToolChainsForNdk(AndroidConfigurations::currentConfig().ndkLocation(),
|
|
|
|
existingAndroidToolChains);
|
|
|
|
foreach (ToolChain *tc, newToolchains)
|
2014-03-11 13:05:36 +01:00
|
|
|
ToolChainManager::registerToolChain(tc);
|
2015-04-22 17:42:23 +02:00
|
|
|
}
|
2014-03-11 13:05:36 +01:00
|
|
|
|
2015-04-22 17:42:23 +02:00
|
|
|
void AndroidConfigurations::removeOldToolChains()
|
|
|
|
{
|
|
|
|
foreach (ToolChain *tc, ToolChainManager::toolChains()) {
|
2015-07-15 16:16:41 +02:00
|
|
|
if (tc->typeId() == Constants::ANDROID_TOOLCHAIN_ID) {
|
2014-03-11 13:05:36 +01:00
|
|
|
if (!tc->isValid())
|
|
|
|
ToolChainManager::deregisterToolChain(tc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 15:51:59 +01:00
|
|
|
void AndroidConfigurations::updateAutomaticKitList()
|
|
|
|
{
|
|
|
|
QList<AndroidToolChain *> toolchains;
|
2013-12-16 20:19:07 +01:00
|
|
|
if (AndroidConfigurations::currentConfig().automaticKitCreation()) {
|
2013-02-14 15:51:59 +01:00
|
|
|
// having a empty toolchains list will remove all autodetected kits for android
|
|
|
|
// exactly what we want in that case
|
2013-08-29 13:14:19 +02:00
|
|
|
foreach (ToolChain *tc, ToolChainManager::toolChains()) {
|
2013-02-14 15:51:59 +01:00
|
|
|
if (!tc->isAutoDetected())
|
|
|
|
continue;
|
2015-07-15 16:16:41 +02:00
|
|
|
if (tc->typeId() != Constants::ANDROID_TOOLCHAIN_ID)
|
2013-02-14 15:51:59 +01:00
|
|
|
continue;
|
2015-04-22 17:42:23 +02:00
|
|
|
if (!tc->isValid()) // going to be deleted
|
|
|
|
continue;
|
2013-02-14 15:51:59 +01:00
|
|
|
toolchains << static_cast<AndroidToolChain *>(tc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<Kit *> existingKits;
|
|
|
|
|
2013-08-23 09:21:18 +02:00
|
|
|
foreach (Kit *k, KitManager::kits()) {
|
2014-03-27 16:35:17 +01:00
|
|
|
if (DeviceTypeKitInformation::deviceTypeId(k) != Core::Id(Constants::ANDROID_DEVICE_TYPE))
|
2013-02-14 15:51:59 +01:00
|
|
|
continue;
|
|
|
|
if (!k->isAutoDetected())
|
|
|
|
continue;
|
2013-02-20 17:05:00 +01:00
|
|
|
if (k->isSdkProvided())
|
|
|
|
continue;
|
2013-02-14 15:51:59 +01:00
|
|
|
|
2013-10-23 13:24:36 +02:00
|
|
|
// Update code for 3.0 beta, which shipped with a bug for the debugger settings
|
2016-07-12 16:27:45 +02:00
|
|
|
ToolChain *tc = ToolChainKitInformation::toolChain(k, ToolChain::Language::Cxx);
|
2016-07-29 15:55:15 +02:00
|
|
|
if (tc && Debugger::DebuggerKitInformation::runnable(k).executable != tc->suggestedDebugger().toString()) {
|
2013-10-23 13:24:36 +02:00
|
|
|
Debugger::DebuggerItem debugger;
|
|
|
|
debugger.setCommand(tc->suggestedDebugger());
|
|
|
|
debugger.setEngineType(Debugger::GdbEngineType);
|
2015-03-03 16:49:59 +01:00
|
|
|
debugger.setUnexpandedDisplayName(tr("Android Debugger for %1").arg(tc->displayName()));
|
2013-10-23 13:24:36 +02:00
|
|
|
debugger.setAutoDetected(true);
|
|
|
|
debugger.setAbi(tc->targetAbi());
|
2016-04-29 19:05:08 +02:00
|
|
|
debugger.reinitializeFromFile();
|
2013-10-23 13:24:36 +02:00
|
|
|
QVariant id = Debugger::DebuggerItemManager::registerDebugger(debugger);
|
|
|
|
Debugger::DebuggerKitInformation::setDebugger(k, id);
|
|
|
|
}
|
2013-02-14 15:51:59 +01:00
|
|
|
existingKits << k;
|
|
|
|
}
|
|
|
|
|
2014-11-18 18:37:05 +01:00
|
|
|
QHash<Abi, QList<QtSupport::BaseQtVersion *> > qtVersionsForArch;
|
2015-07-13 13:09:45 +02:00
|
|
|
foreach (QtSupport::BaseQtVersion *qtVersion, QtSupport::QtVersionManager::unsortedVersions()) {
|
2013-02-14 15:51:59 +01:00
|
|
|
if (qtVersion->type() != QLatin1String(Constants::ANDROIDQT))
|
|
|
|
continue;
|
2013-08-23 09:21:18 +02:00
|
|
|
QList<Abi> qtAbis = qtVersion->qtAbis();
|
2013-02-25 09:17:43 +02:00
|
|
|
if (qtAbis.empty())
|
|
|
|
continue;
|
2014-11-18 18:37:05 +01:00
|
|
|
qtVersionsForArch[qtAbis.first()].append(qtVersion);
|
2013-02-14 15:51:59 +01:00
|
|
|
}
|
|
|
|
|
2013-08-23 09:21:18 +02:00
|
|
|
DeviceManager *dm = DeviceManager::instance();
|
2013-10-30 17:02:28 +01:00
|
|
|
IDevice::ConstPtr device = dm->find(Core::Id(Constants::ANDROID_DEVICE_ID));
|
|
|
|
if (device.isNull()) {
|
|
|
|
// no device, means no sdk path
|
|
|
|
foreach (Kit *k, existingKits)
|
|
|
|
KitManager::deregisterKit(k);
|
|
|
|
return;
|
|
|
|
}
|
2013-02-14 15:51:59 +01:00
|
|
|
|
|
|
|
// register new kits
|
|
|
|
QList<Kit *> newKits;
|
|
|
|
foreach (AndroidToolChain *tc, toolchains) {
|
2013-10-11 11:29:06 +02:00
|
|
|
if (tc->isSecondaryToolChain())
|
2013-10-10 18:04:27 +02:00
|
|
|
continue;
|
2014-11-18 18:37:05 +01:00
|
|
|
QList<QtSupport::BaseQtVersion *> qtVersions = qtVersionsForArch.value(tc->targetAbi());
|
2013-02-14 15:51:59 +01:00
|
|
|
foreach (QtSupport::BaseQtVersion *qt, qtVersions) {
|
|
|
|
Kit *newKit = new Kit;
|
|
|
|
newKit->setAutoDetected(true);
|
|
|
|
DeviceTypeKitInformation::setDeviceTypeId(newKit, Core::Id(Constants::ANDROID_DEVICE_TYPE));
|
|
|
|
ToolChainKitInformation::setToolChain(newKit, tc);
|
|
|
|
QtSupport::QtKitInformation::setQtVersion(newKit, qt);
|
|
|
|
DeviceKitInformation::setDevice(newKit, device);
|
2013-10-10 18:02:56 +02:00
|
|
|
|
|
|
|
Debugger::DebuggerItem debugger;
|
|
|
|
debugger.setCommand(tc->suggestedDebugger());
|
|
|
|
debugger.setEngineType(Debugger::GdbEngineType);
|
2015-03-03 16:49:59 +01:00
|
|
|
debugger.setUnexpandedDisplayName(tr("Android Debugger for %1").arg(tc->displayName()));
|
2013-10-10 18:02:56 +02:00
|
|
|
debugger.setAutoDetected(true);
|
|
|
|
debugger.setAbi(tc->targetAbi());
|
2016-04-29 19:05:08 +02:00
|
|
|
debugger.reinitializeFromFile();
|
2013-10-18 19:27:31 +02:00
|
|
|
QVariant id = Debugger::DebuggerItemManager::registerDebugger(debugger);
|
|
|
|
Debugger::DebuggerKitInformation::setDebugger(newKit, id);
|
2013-10-10 18:02:56 +02:00
|
|
|
|
2013-02-14 15:51:59 +01:00
|
|
|
AndroidGdbServerKitInformation::setGdbSever(newKit, tc->suggestedGdbServer());
|
2013-08-01 14:43:32 +02:00
|
|
|
newKit->makeSticky();
|
2013-02-14 15:51:59 +01:00
|
|
|
newKits << newKit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = existingKits.count() - 1; i >= 0; --i) {
|
|
|
|
Kit *existingKit = existingKits.at(i);
|
|
|
|
for (int j = 0; j < newKits.count(); ++j) {
|
|
|
|
Kit *newKit = newKits.at(j);
|
|
|
|
if (equalKits(existingKit, newKit)) {
|
|
|
|
// Kit is already registered, nothing to do
|
|
|
|
newKits.removeAt(j);
|
2013-08-29 14:42:07 +02:00
|
|
|
existingKits.at(i)->makeSticky();
|
2013-02-14 15:51:59 +01:00
|
|
|
existingKits.removeAt(i);
|
2016-07-12 16:27:45 +02:00
|
|
|
ToolChainKitInformation::setToolChain(existingKit, ToolChainKitInformation::toolChain(newKit, ToolChain::Language::Cxx));
|
2013-02-14 15:51:59 +01:00
|
|
|
KitManager::deleteKit(newKit);
|
|
|
|
j = newKits.count();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-28 13:34:24 +02:00
|
|
|
foreach (Kit *k, existingKits) {
|
2016-07-12 16:27:45 +02:00
|
|
|
ToolChain *tc = ToolChainKitInformation::toolChain(k, ToolChain::Language::Cxx);
|
2013-10-08 16:32:00 +02:00
|
|
|
QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(k);
|
2015-07-15 16:16:41 +02:00
|
|
|
if (tc && tc->typeId() == Constants::ANDROID_TOOLCHAIN_ID
|
2015-04-22 17:42:23 +02:00
|
|
|
&& tc->isValid()
|
2013-10-08 16:32:00 +02:00
|
|
|
&& qtVersion && qtVersion->type() == QLatin1String(Constants::ANDROIDQT)) {
|
2013-08-28 13:34:24 +02:00
|
|
|
k->makeUnSticky();
|
|
|
|
k->setAutoDetected(false);
|
|
|
|
} else {
|
|
|
|
KitManager::deregisterKit(k);
|
|
|
|
}
|
|
|
|
}
|
2013-02-14 15:51:59 +01:00
|
|
|
|
2013-02-27 13:08:54 +01:00
|
|
|
foreach (Kit *kit, newKits) {
|
2016-07-12 16:27:45 +02:00
|
|
|
AndroidToolChain *tc = static_cast<AndroidToolChain *>(ToolChainKitInformation::toolChain(kit, ToolChain::Language::Cxx));
|
2013-08-01 12:49:47 +02:00
|
|
|
AndroidQtVersion *qt = static_cast<AndroidQtVersion *>(QtSupport::QtKitInformation::qtVersion(kit));
|
2014-07-09 15:31:09 +02:00
|
|
|
kit->setUnexpandedDisplayName(tr("Android for %1 (GCC %2, Qt %3)")
|
2013-08-01 12:49:47 +02:00
|
|
|
.arg(qt->targetArch())
|
2013-02-27 13:08:54 +01:00
|
|
|
.arg(tc->ndkToolChainVersion())
|
|
|
|
.arg(qt->qtVersionString()));
|
2013-08-21 12:48:46 +02:00
|
|
|
KitManager::registerKit(kit);
|
2013-02-27 13:08:54 +01:00
|
|
|
}
|
2013-02-14 15:51:59 +01:00
|
|
|
}
|
|
|
|
|
2014-10-31 16:09:34 +01:00
|
|
|
bool AndroidConfigurations::force32bitEmulator()
|
|
|
|
{
|
|
|
|
return m_instance->m_force32bit;
|
|
|
|
}
|
|
|
|
|
2013-02-24 18:04:36 +04:00
|
|
|
/**
|
|
|
|
* Workaround for '????????????' serial numbers
|
|
|
|
* @return ("-d") for buggy devices, ("-s", <serial no>) for normal
|
|
|
|
*/
|
|
|
|
QStringList AndroidDeviceInfo::adbSelector(const QString &serialNumber)
|
|
|
|
{
|
|
|
|
if (serialNumber.startsWith(QLatin1String("????")))
|
|
|
|
return QStringList() << QLatin1String("-d");
|
|
|
|
return QStringList() << QLatin1String("-s") << serialNumber;
|
|
|
|
}
|
|
|
|
|
2014-03-07 13:44:20 +01:00
|
|
|
const AndroidConfig &AndroidConfigurations::currentConfig()
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2013-12-16 20:19:07 +01:00
|
|
|
return m_instance->m_config; // ensure that m_instance is initialized
|
|
|
|
}
|
|
|
|
|
|
|
|
AndroidConfigurations *AndroidConfigurations::instance()
|
|
|
|
{
|
|
|
|
return m_instance;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidConfigurations::save()
|
|
|
|
{
|
2013-09-20 23:17:22 +02:00
|
|
|
QSettings *settings = Core::ICore::settings();
|
2012-04-18 20:30:57 +03:00
|
|
|
settings->beginGroup(SettingsGroup);
|
|
|
|
m_config.save(*settings);
|
|
|
|
settings->endGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
AndroidConfigurations::AndroidConfigurations(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
{
|
|
|
|
load();
|
2013-09-10 19:19:31 +02:00
|
|
|
|
2016-04-29 23:06:26 +02:00
|
|
|
connect(SessionManager::instance(), &SessionManager::projectRemoved,
|
|
|
|
this, &AndroidConfigurations::clearDefaultDevices);
|
2013-12-16 20:19:07 +01:00
|
|
|
|
2014-10-31 16:09:34 +01:00
|
|
|
m_force32bit = is32BitUserSpace();
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
m_instance = this;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2014-07-15 23:32:11 +03:00
|
|
|
static FileName javaHomeForJavac(const FileName &location)
|
2013-10-08 15:25:34 +02:00
|
|
|
{
|
2014-07-15 23:32:11 +03:00
|
|
|
QFileInfo fileInfo = location.toFileInfo();
|
2013-10-08 15:25:34 +02:00
|
|
|
int tries = 5;
|
|
|
|
while (tries > 0) {
|
|
|
|
QDir dir = fileInfo.dir();
|
|
|
|
dir.cdUp();
|
2014-10-24 10:28:28 +02:00
|
|
|
if (QFileInfo::exists(dir.filePath(QLatin1String("lib/tools.jar"))))
|
2014-07-15 23:32:11 +03:00
|
|
|
return FileName::fromString(dir.path());
|
2013-10-08 15:25:34 +02:00
|
|
|
if (fileInfo.isSymLink())
|
|
|
|
fileInfo.setFile(fileInfo.symLinkTarget());
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
--tries;
|
|
|
|
}
|
2014-07-15 23:32:11 +03:00
|
|
|
return FileName();
|
2013-10-08 15:25:34 +02:00
|
|
|
}
|
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
void AndroidConfigurations::load()
|
|
|
|
{
|
2013-06-10 18:19:08 +02:00
|
|
|
bool saveSettings = false;
|
2013-09-20 23:17:22 +02:00
|
|
|
QSettings *settings = Core::ICore::settings();
|
2012-04-18 20:30:57 +03:00
|
|
|
settings->beginGroup(SettingsGroup);
|
2013-12-16 20:19:07 +01:00
|
|
|
m_config.load(*settings);
|
2013-04-17 11:52:16 +02:00
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
if (m_config.antLocation().isEmpty()) {
|
2013-08-23 09:21:18 +02:00
|
|
|
Environment env = Environment::systemEnvironment();
|
2014-07-15 23:32:11 +03:00
|
|
|
FileName location = env.searchInPath(QLatin1String("ant"));
|
|
|
|
QFileInfo fi = location.toFileInfo();
|
2013-06-10 18:19:08 +02:00
|
|
|
if (fi.exists() && fi.isExecutable() && !fi.isDir()) {
|
2014-07-15 23:32:11 +03:00
|
|
|
m_config.setAntLocation(location);
|
2013-06-10 18:19:08 +02:00
|
|
|
saveSettings = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
if (m_config.openJDKLocation().isEmpty()) {
|
2013-10-08 15:25:34 +02:00
|
|
|
if (HostOsInfo::isLinuxHost()) {
|
|
|
|
Environment env = Environment::systemEnvironment();
|
2014-07-15 23:32:11 +03:00
|
|
|
FileName location = env.searchInPath(QLatin1String("javac"));
|
|
|
|
QFileInfo fi = location.toFileInfo();
|
2013-10-08 15:25:34 +02:00
|
|
|
if (fi.exists() && fi.isExecutable() && !fi.isDir()) {
|
2013-12-16 20:19:07 +01:00
|
|
|
m_config.setOpenJDKLocation(javaHomeForJavac(location));
|
2013-10-08 15:25:34 +02:00
|
|
|
saveSettings = true;
|
|
|
|
}
|
|
|
|
} else if (HostOsInfo::isMacHost()) {
|
2015-10-01 16:38:08 +02:00
|
|
|
QFileInfo javaHomeExec(QLatin1String("/usr/libexec/java_home"));
|
|
|
|
if (javaHomeExec.isExecutable() && !javaHomeExec.isDir()) {
|
2016-04-29 16:52:58 +02:00
|
|
|
SynchronousProcess proc;
|
|
|
|
proc.setTimeoutS(2);
|
2015-10-01 16:38:08 +02:00
|
|
|
proc.setProcessChannelMode(QProcess::MergedChannels);
|
2016-05-26 12:12:01 +02:00
|
|
|
SynchronousProcessResponse response = proc.runBlocking(javaHomeExec.absoluteFilePath(), QStringList());
|
2016-04-29 16:52:58 +02:00
|
|
|
if (response.result == SynchronousProcessResponse::Finished) {
|
|
|
|
const QString &javaHome = response.allOutput().trimmed();
|
2015-10-01 16:38:08 +02:00
|
|
|
if (!javaHome.isEmpty() && QFileInfo::exists(javaHome))
|
|
|
|
m_config.setOpenJDKLocation(FileName::fromString(javaHome));
|
|
|
|
}
|
|
|
|
}
|
2013-08-23 09:21:18 +02:00
|
|
|
} else if (HostOsInfo::isWindowsHost()) {
|
2013-06-10 18:19:08 +02:00
|
|
|
QSettings settings(QLatin1String("HKEY_LOCAL_MACHINE\\SOFTWARE\\Javasoft\\Java Development Kit"), QSettings::NativeFormat);
|
|
|
|
QStringList allVersions = settings.childGroups();
|
|
|
|
QString javaHome;
|
|
|
|
int major = -1;
|
|
|
|
int minor = -1;
|
|
|
|
foreach (const QString &version, allVersions) {
|
2014-08-29 14:00:18 +02:00
|
|
|
QStringList parts = version.split(QLatin1Char('.'));
|
2013-06-10 18:19:08 +02:00
|
|
|
if (parts.size() != 2) // not interested in 1.7.0_u21
|
|
|
|
continue;
|
|
|
|
bool okMajor, okMinor;
|
|
|
|
int tmpMajor = parts.at(0).toInt(&okMajor);
|
|
|
|
int tmpMinor = parts.at(1).toInt(&okMinor);
|
|
|
|
if (!okMajor || !okMinor)
|
|
|
|
continue;
|
|
|
|
if (tmpMajor > major
|
|
|
|
|| (tmpMajor == major
|
|
|
|
&& tmpMinor > minor)) {
|
|
|
|
settings.beginGroup(version);
|
|
|
|
QString tmpJavaHome = settings.value(QLatin1String("JavaHome")).toString();
|
|
|
|
settings.endGroup();
|
2014-10-24 10:28:28 +02:00
|
|
|
if (!QFileInfo::exists(tmpJavaHome))
|
2013-06-10 18:19:08 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
major = tmpMajor;
|
|
|
|
minor = tmpMinor;
|
|
|
|
javaHome = tmpJavaHome;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!javaHome.isEmpty()) {
|
2013-12-16 20:19:07 +01:00
|
|
|
m_config.setOpenJDKLocation(FileName::fromString(javaHome));
|
2013-06-10 18:19:08 +02:00
|
|
|
saveSettings = true;
|
|
|
|
}
|
|
|
|
}
|
2013-04-17 11:52:16 +02:00
|
|
|
}
|
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
settings->endGroup();
|
2013-06-10 18:19:08 +02:00
|
|
|
|
|
|
|
if (saveSettings)
|
|
|
|
save();
|
2013-03-27 15:49:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidConfigurations::updateAndroidDevice()
|
|
|
|
{
|
2013-08-23 09:21:18 +02:00
|
|
|
DeviceManager * const devMgr = DeviceManager::instance();
|
2014-10-24 13:15:54 +02:00
|
|
|
if (m_instance->m_config.adbToolPath().exists())
|
2015-02-03 23:50:37 +02:00
|
|
|
devMgr->addDevice(IDevice::Ptr(new AndroidDevice));
|
2013-04-10 11:05:33 +02:00
|
|
|
else if (devMgr->find(Constants::ANDROID_DEVICE_ID))
|
|
|
|
devMgr->removeDevice(Core::Id(Constants::ANDROID_DEVICE_ID));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
AndroidConfigurations *AndroidConfigurations::m_instance = 0;
|
|
|
|
|
|
|
|
} // namespace Android
|