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
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
#include "android_global.h"
|
|
|
|
|
|
2016-10-24 15:53:37 +02:00
|
|
|
#include <projectexplorer/toolchain.h>
|
|
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <QObject>
|
|
|
|
|
#include <QString>
|
2013-05-03 15:10:21 +02:00
|
|
|
#include <QStringList>
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <QVector>
|
2013-09-10 19:19:31 +02:00
|
|
|
#include <QHash>
|
|
|
|
|
#include <QMap>
|
2013-11-13 16:35:29 +01:00
|
|
|
#include <QFutureInterface>
|
2017-03-30 14:47:34 +02:00
|
|
|
#include <QVersionNumber>
|
2014-06-25 15:42:11 +02:00
|
|
|
|
2013-03-25 17:13:18 +01:00
|
|
|
#include <utils/fileutils.h>
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QSettings;
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
2015-03-05 11:56:15 +01:00
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
class Abi;
|
|
|
|
|
class Project;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace Utils { class Environment; }
|
2013-09-10 19:19:31 +02:00
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
namespace Android {
|
2013-12-16 20:19:07 +01:00
|
|
|
class AndroidPlugin;
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2015-11-13 12:53:09 +01:00
|
|
|
class AndroidDeviceInfo
|
2012-08-09 01:56:51 +02:00
|
|
|
{
|
2015-11-13 12:53:09 +01:00
|
|
|
public:
|
2012-04-18 20:30:57 +03:00
|
|
|
QString serialNumber;
|
2015-04-23 16:25:44 +02:00
|
|
|
QString avdname;
|
2013-07-04 12:43:26 +02:00
|
|
|
QStringList cpuAbi;
|
2015-11-13 12:53:09 +01:00
|
|
|
int sdk = -1;
|
2014-03-10 15:18:46 +01:00
|
|
|
enum State { OkState, UnAuthorizedState, OfflineState };
|
2015-11-13 12:53:09 +01:00
|
|
|
State state = OfflineState;
|
|
|
|
|
bool unauthorized = false;
|
2013-09-10 19:19:31 +02:00
|
|
|
enum AndroidDeviceType { Hardware, Emulator };
|
2015-11-13 12:53:09 +01:00
|
|
|
AndroidDeviceType type = Emulator;
|
2013-02-24 18:04:36 +04:00
|
|
|
|
|
|
|
|
static QStringList adbSelector(const QString &serialNumber);
|
2015-11-13 12:53:09 +01:00
|
|
|
|
2017-03-30 14:43:13 +02:00
|
|
|
bool isValid() const { return !serialNumber.isEmpty() || !avdname.isEmpty(); }
|
|
|
|
|
bool operator<(const AndroidDeviceInfo &other) const;
|
2012-04-18 20:30:57 +03:00
|
|
|
};
|
2017-04-03 11:11:17 +02:00
|
|
|
using AndroidDeviceInfoList = QList<AndroidDeviceInfo>;
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2017-04-04 07:20:01 +02:00
|
|
|
//! Defines an Android system image.
|
|
|
|
|
class SystemImage
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
bool isValid() const { return (apiLevel != -1) && !abiName.isEmpty(); }
|
|
|
|
|
int apiLevel = -1;
|
|
|
|
|
QString abiName;
|
2017-03-30 14:47:34 +02:00
|
|
|
QString package;
|
|
|
|
|
Utils::FileName installedLocation;
|
2017-04-04 07:20:01 +02:00
|
|
|
};
|
|
|
|
|
using SystemImageList = QList<SystemImage>;
|
|
|
|
|
|
|
|
|
|
|
2014-03-24 16:31:28 +01:00
|
|
|
class SdkPlatform
|
|
|
|
|
{
|
|
|
|
|
public:
|
2017-04-03 11:11:17 +02:00
|
|
|
bool isValid() const { return !name.isEmpty() && apiLevel != -1; }
|
2017-03-30 14:47:34 +02:00
|
|
|
bool operator <(const SdkPlatform &other) const;
|
2017-03-30 14:43:13 +02:00
|
|
|
int apiLevel = -1;
|
2014-03-24 16:31:28 +01:00
|
|
|
QString name;
|
2017-03-30 14:47:34 +02:00
|
|
|
QString package;
|
2017-03-30 14:43:13 +02:00
|
|
|
Utils::FileName installedLocation;
|
2017-04-04 07:20:01 +02:00
|
|
|
SystemImageList systemImages;
|
2014-03-24 16:31:28 +01:00
|
|
|
};
|
2017-03-30 14:43:13 +02:00
|
|
|
using SdkPlatformList = QList<SdkPlatform>;
|
2014-03-24 16:31:28 +01:00
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
class ANDROID_EXPORT AndroidConfig
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-08-09 01:56:51 +02:00
|
|
|
public:
|
2013-12-16 20:19:07 +01:00
|
|
|
void load(const QSettings &settings);
|
|
|
|
|
void save(QSettings &settings) const;
|
|
|
|
|
|
2014-03-24 16:31:28 +01:00
|
|
|
static QStringList apiLevelNamesFor(const QList<SdkPlatform> &platforms);
|
2014-06-25 15:42:11 +02:00
|
|
|
static QString apiLevelNameFor(const SdkPlatform &platform);
|
2014-03-24 16:31:28 +01:00
|
|
|
QList<SdkPlatform> sdkTargets(int minApiLevel = 0) const;
|
2013-12-16 20:19:07 +01:00
|
|
|
|
|
|
|
|
Utils::FileName sdkLocation() const;
|
|
|
|
|
void setSdkLocation(const Utils::FileName &sdkLocation);
|
2017-03-30 14:47:34 +02:00
|
|
|
QVersionNumber sdkToolsVersion() const;
|
2017-09-04 14:54:50 +02:00
|
|
|
QVersionNumber buildToolsVersion() const;
|
2013-12-16 20:19:07 +01:00
|
|
|
|
|
|
|
|
Utils::FileName ndkLocation() const;
|
2017-05-05 12:26:23 +02:00
|
|
|
QVersionNumber ndkVersion() const;
|
2013-12-16 20:19:07 +01:00
|
|
|
void setNdkLocation(const Utils::FileName &ndkLocation);
|
|
|
|
|
|
|
|
|
|
Utils::FileName antLocation() const;
|
|
|
|
|
void setAntLocation(const Utils::FileName &antLocation);
|
|
|
|
|
|
|
|
|
|
Utils::FileName openJDKLocation() const;
|
|
|
|
|
void setOpenJDKLocation(const Utils::FileName &openJDKLocation);
|
|
|
|
|
|
|
|
|
|
Utils::FileName keystoreLocation() const;
|
|
|
|
|
void setKeystoreLocation(const Utils::FileName &keystoreLocation);
|
|
|
|
|
|
|
|
|
|
QString toolchainHost() const;
|
|
|
|
|
QStringList makeExtraSearchDirectories() const;
|
|
|
|
|
|
|
|
|
|
unsigned partitionSize() const;
|
|
|
|
|
void setPartitionSize(unsigned partitionSize);
|
|
|
|
|
|
|
|
|
|
bool automaticKitCreation() const;
|
|
|
|
|
void setAutomaticKitCreation(bool b);
|
|
|
|
|
|
2017-04-12 14:08:17 +02:00
|
|
|
bool antScriptsAvailable() const;
|
|
|
|
|
|
2014-09-22 16:20:51 +03:00
|
|
|
bool useGrandle() const;
|
|
|
|
|
void setUseGradle(bool b);
|
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
Utils::FileName adbToolPath() const;
|
|
|
|
|
Utils::FileName androidToolPath() const;
|
|
|
|
|
Utils::FileName antToolPath() const;
|
|
|
|
|
Utils::FileName emulatorToolPath() const;
|
2017-03-30 14:47:34 +02:00
|
|
|
Utils::FileName sdkManagerToolPath() const;
|
2017-04-03 11:11:17 +02:00
|
|
|
Utils::FileName avdManagerToolPath() const;
|
2013-12-16 20:19:07 +01:00
|
|
|
|
2016-12-16 00:43:14 +01:00
|
|
|
Utils::FileName gccPath(const ProjectExplorer::Abi &abi, Core::Id lang,
|
2016-10-24 15:53:37 +02:00
|
|
|
const QString &ndkToolChainVersion) const;
|
2017-03-30 14:43:13 +02:00
|
|
|
|
2014-11-18 18:37:05 +01:00
|
|
|
Utils::FileName gdbPath(const ProjectExplorer::Abi &abi, const QString &ndkToolChainVersion) const;
|
2013-12-16 20:19:07 +01:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
Utils::FileName keytoolPath() const;
|
2013-12-16 20:19:07 +01:00
|
|
|
|
2014-04-11 13:31:01 +02:00
|
|
|
class CreateAvdInfo
|
|
|
|
|
{
|
|
|
|
|
public:
|
2017-04-03 11:11:17 +02:00
|
|
|
bool isValid() const { return target.isValid() && !name.isEmpty(); }
|
|
|
|
|
SdkPlatform target;
|
2014-04-11 13:31:01 +02:00
|
|
|
QString name;
|
|
|
|
|
QString abi;
|
2016-11-29 13:03:23 +01:00
|
|
|
int sdcardSize = 0;
|
2014-04-11 13:31:01 +02:00
|
|
|
QString error; // only used in the return value of createAVD
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CreateAvdInfo gatherCreateAVDInfo(QWidget *parent, int minApiLevel = 0, QString targetArch = QString()) const;
|
2013-12-16 20:19:07 +01:00
|
|
|
|
2013-07-03 17:58:48 +02:00
|
|
|
QVector<AndroidDeviceInfo> connectedDevices(QString *error = 0) const;
|
2015-04-10 18:08:51 +02:00
|
|
|
static QVector<AndroidDeviceInfo> connectedDevices(const QString &adbToolPath, QString *error = 0);
|
2015-01-08 17:05:09 +01:00
|
|
|
|
2014-06-25 15:41:32 +02:00
|
|
|
QString bestNdkPlatformMatch(int target) const;
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2014-11-18 18:37:05 +01:00
|
|
|
static ProjectExplorer::Abi abiForToolChainPrefix(const QString &toolchainPrefix);
|
|
|
|
|
static QLatin1String toolchainPrefix(const ProjectExplorer::Abi &abi);
|
|
|
|
|
static QLatin1String toolsPrefix(const ProjectExplorer::Abi &abi);
|
|
|
|
|
static QLatin1String displayName(const ProjectExplorer::Abi &abi);
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2013-07-03 17:58:48 +02:00
|
|
|
QString getProductModel(const QString &device) const;
|
2015-04-10 16:46:30 +02:00
|
|
|
enum class OpenGl { Enabled, Disabled, Unknown };
|
|
|
|
|
OpenGl getOpenGLEnabled(const QString &emulator) const;
|
2013-11-13 16:35:29 +01:00
|
|
|
bool isConnected(const QString &serialNumber) const;
|
2013-07-03 17:58:48 +02:00
|
|
|
|
2014-03-24 16:31:28 +01:00
|
|
|
SdkPlatform highestAndroidSdk() const;
|
2013-12-16 20:19:07 +01:00
|
|
|
private:
|
2015-04-10 18:08:51 +02:00
|
|
|
static QString getDeviceProperty(const QString &adbToolPath, const QString &device, const QString &property);
|
2014-04-11 13:31:01 +02:00
|
|
|
|
2014-11-18 18:37:05 +01:00
|
|
|
Utils::FileName toolPath(const ProjectExplorer::Abi &abi, const QString &ndkToolChainVersion) const;
|
2013-12-16 20:19:07 +01:00
|
|
|
Utils::FileName openJDKBinPath() const;
|
|
|
|
|
int getSDKVersion(const QString &device) const;
|
2015-04-10 18:08:51 +02:00
|
|
|
static int getSDKVersion(const QString &adbToolPath, const QString &device);
|
2013-12-16 20:19:07 +01:00
|
|
|
QStringList getAbis(const QString &device) const;
|
2015-04-10 18:08:51 +02:00
|
|
|
static QStringList getAbis(const QString &adbToolPath, const QString &device);
|
|
|
|
|
static bool isBootToQt(const QString &adbToolPath, const QString &device);
|
2013-12-16 20:19:07 +01:00
|
|
|
bool isBootToQt(const QString &device) const;
|
2015-04-23 16:25:44 +02:00
|
|
|
static QString getAvdName(const QString &serialnumber);
|
2013-12-16 20:19:07 +01:00
|
|
|
|
|
|
|
|
void updateAvailableSdkPlatforms() const;
|
|
|
|
|
void updateNdkInformation() const;
|
|
|
|
|
|
|
|
|
|
Utils::FileName m_sdkLocation;
|
|
|
|
|
Utils::FileName m_ndkLocation;
|
|
|
|
|
Utils::FileName m_antLocation;
|
|
|
|
|
Utils::FileName m_openJDKLocation;
|
|
|
|
|
Utils::FileName m_keystoreLocation;
|
|
|
|
|
QStringList m_makeExtraSearchDirectories;
|
2016-12-05 14:04:54 +01:00
|
|
|
unsigned m_partitionSize = 1024;
|
|
|
|
|
bool m_automaticKitCreation = true;
|
2017-04-12 14:08:17 +02:00
|
|
|
bool m_useGradle = true; // Ant builds are deprecated.
|
2013-12-16 20:19:07 +01:00
|
|
|
|
|
|
|
|
//caches
|
2016-12-05 14:04:54 +01:00
|
|
|
mutable bool m_availableSdkPlatformsUpToDate = false;
|
2017-03-30 14:43:13 +02:00
|
|
|
mutable SdkPlatformList m_availableSdkPlatforms;
|
2013-12-16 20:19:07 +01:00
|
|
|
|
2016-12-05 14:04:54 +01:00
|
|
|
mutable bool m_NdkInformationUpToDate = false;
|
2013-12-16 20:19:07 +01:00
|
|
|
mutable QString m_toolchainHost;
|
|
|
|
|
mutable QVector<int> m_availableNdkPlatforms;
|
|
|
|
|
|
|
|
|
|
mutable QHash<QString, QString> m_serialNumberToDeviceName;
|
|
|
|
|
};
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
class ANDROID_EXPORT AndroidConfigurations : public QObject
|
2013-12-16 20:19:07 +01:00
|
|
|
{
|
|
|
|
|
friend class Android::AndroidPlugin;
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2014-03-07 13:44:20 +01:00
|
|
|
static const AndroidConfig ¤tConfig();
|
2013-12-16 20:19:07 +01:00
|
|
|
static void setConfig(const AndroidConfig &config);
|
|
|
|
|
static AndroidConfigurations *instance();
|
|
|
|
|
|
|
|
|
|
static void updateAndroidDevice();
|
2014-11-17 16:22:28 +01:00
|
|
|
enum Options { None, FilterAndroid5 };
|
|
|
|
|
static AndroidDeviceInfo showDeviceDialog(ProjectExplorer::Project *project, int apiLevel, const QString &abi, Options options);
|
2013-12-16 20:19:07 +01:00
|
|
|
static void setDefaultDevice(ProjectExplorer::Project *project, const QString &abi, const QString &serialNumber); // serial number or avd name
|
|
|
|
|
static QString defaultDevice(ProjectExplorer::Project *project, const QString &abi); // serial number or avd name
|
|
|
|
|
static void clearDefaultDevices(ProjectExplorer::Project *project);
|
2015-04-22 17:42:23 +02:00
|
|
|
static void registerNewToolChains();
|
|
|
|
|
static void removeOldToolChains();
|
2013-12-16 20:19:07 +01:00
|
|
|
static void updateAutomaticKitList();
|
2014-10-31 16:09:34 +01:00
|
|
|
static bool force32bitEmulator();
|
2013-09-10 19:19:31 +02:00
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
signals:
|
|
|
|
|
void updated();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
AndroidConfigurations(QObject *parent);
|
|
|
|
|
void load();
|
|
|
|
|
void save();
|
|
|
|
|
|
|
|
|
|
static AndroidConfigurations *m_instance;
|
|
|
|
|
AndroidConfig m_config;
|
2013-09-10 19:19:31 +02:00
|
|
|
|
|
|
|
|
QMap<ProjectExplorer::Project *, QMap<QString, QString> > m_defaultDeviceForAbi;
|
2014-10-31 16:09:34 +01:00
|
|
|
bool m_force32bit;
|
2012-04-18 20:30:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Android
|
2017-04-03 11:11:17 +02:00
|
|
|
Q_DECLARE_METATYPE(Android::SdkPlatform)
|
|
|
|
|
|