androidconfigurations.h 8.6 KB
Newer Older
1
/****************************************************************************
BogDan Vatra's avatar
BogDan Vatra committed
2
**
3 4
** Copyright (C) 2016 BogDan Vatra <bog_dan_ro@yahoo.com>
** Contact: https://www.qt.io/licensing/
BogDan Vatra's avatar
BogDan Vatra committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
BogDan Vatra's avatar
BogDan Vatra committed
7
**
hjk's avatar
hjk committed
8 9 10 11
** 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
12 13 14
** 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.
BogDan Vatra's avatar
BogDan Vatra committed
15
**
16 17 18 19 20 21 22
** 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.
BogDan Vatra's avatar
BogDan Vatra committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
BogDan Vatra's avatar
BogDan Vatra committed
25

hjk's avatar
hjk committed
26
#pragma once
BogDan Vatra's avatar
BogDan Vatra committed
27

28 29
#include "android_global.h"

BogDan Vatra's avatar
BogDan Vatra committed
30 31
#include <QObject>
#include <QString>
32
#include <QStringList>
BogDan Vatra's avatar
BogDan Vatra committed
33
#include <QVector>
34 35
#include <QHash>
#include <QMap>
Daniel Teske's avatar
Daniel Teske committed
36
#include <QFutureInterface>
37

38
#include <utils/fileutils.h>
BogDan Vatra's avatar
BogDan Vatra committed
39 40 41 42 43

QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE

44 45 46 47 48 49
namespace ProjectExplorer {
class Abi;
class Project;
}

namespace Utils { class Environment; }
50

BogDan Vatra's avatar
BogDan Vatra committed
51
namespace Android {
52
class AndroidPlugin;
BogDan Vatra's avatar
BogDan Vatra committed
53

54
class AndroidDeviceInfo
hjk's avatar
hjk committed
55
{
56
public:
BogDan Vatra's avatar
BogDan Vatra committed
57
    QString serialNumber;
58
    QString avdname;
59
    QStringList cpuAbi;
60
    int sdk = -1;
Daniel Teske's avatar
Daniel Teske committed
61
    enum State { OkState, UnAuthorizedState, OfflineState };
62 63
    State state = OfflineState;
    bool unauthorized = false;
64
    enum AndroidDeviceType { Hardware, Emulator };
65
    AndroidDeviceType type = Emulator;
66 67

    static QStringList adbSelector(const QString &serialNumber);
68

69
    bool isValid() { return !serialNumber.isEmpty() || !avdname.isEmpty(); }
BogDan Vatra's avatar
BogDan Vatra committed
70 71
};

72 73 74 75 76 77 78 79 80 81 82
class SdkPlatform
{
public:
    SdkPlatform()
        : apiLevel(-1)
    {}
    int apiLevel;
    QString name;
    QStringList abis;
};

83
class ANDROID_EXPORT AndroidConfig
BogDan Vatra's avatar
BogDan Vatra committed
84
{
hjk's avatar
hjk committed
85
public:
86 87 88 89 90
    AndroidConfig();

    void load(const QSettings &settings);
    void save(QSettings &settings) const;

91
    static QStringList apiLevelNamesFor(const QList<SdkPlatform> &platforms);
92
    static QString apiLevelNameFor(const SdkPlatform &platform);
93
    QList<SdkPlatform> sdkTargets(int minApiLevel = 0) const;
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118

    Utils::FileName sdkLocation() const;
    void setSdkLocation(const Utils::FileName &sdkLocation);

    Utils::FileName ndkLocation() const;
    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);

BogDan Vatra's avatar
BogDan Vatra committed
119 120 121
    bool useGrandle() const;
    void setUseGradle(bool b);

Tobias Hunger's avatar
Tobias Hunger committed
122 123
    Utils::FileName adbToolPath() const;
    Utils::FileName androidToolPath() const;
124
    Utils::Environment androidToolEnvironment() const;
Tobias Hunger's avatar
Tobias Hunger committed
125 126
    Utils::FileName antToolPath() const;
    Utils::FileName emulatorToolPath() const;
127 128


Daniel Teske's avatar
Daniel Teske committed
129 130
    Utils::FileName gccPath(const ProjectExplorer::Abi &abi, const QString &ndkToolChainVersion) const;
    Utils::FileName gdbPath(const ProjectExplorer::Abi &abi, const QString &ndkToolChainVersion) const;
131

Tobias Hunger's avatar
Tobias Hunger committed
132
    Utils::FileName keytoolPath() const;
133

134 135 136 137 138 139 140 141 142 143 144 145
    class CreateAvdInfo
    {
    public:
        QString target;
        QString name;
        QString abi;
        int sdcardSize;
        QString error; // only used in the return value of createAVD
    };

    CreateAvdInfo gatherCreateAVDInfo(QWidget *parent, int minApiLevel = 0, QString targetArch = QString()) const;
    QFuture<CreateAvdInfo> createAVD(CreateAvdInfo info) const;
BogDan Vatra's avatar
BogDan Vatra committed
146
    bool removeAVD(const QString &name) const;
147

148
    QVector<AndroidDeviceInfo> connectedDevices(QString *error = 0) const;
149
    static QVector<AndroidDeviceInfo> connectedDevices(const QString &adbToolPath, QString *error = 0);
150

151
    QFuture<QVector<AndroidDeviceInfo> > androidVirtualDevicesFuture() const;
152
    static QVector<AndroidDeviceInfo> androidVirtualDevices(const QString &androidTool, const Utils::Environment &environment);
153

154
    QString startAVD(const QString &name) const;
155
    bool startAVDAsync(const QString &avdName) const;
156 157
    QString findAvd(const QString &avdName) const;
    QString waitForAvd(const QString &avdName, const QFutureInterface<bool> &fi = QFutureInterface<bool>()) const;
158
    QString bestNdkPlatformMatch(int target) const;
BogDan Vatra's avatar
BogDan Vatra committed
159

Daniel Teske's avatar
Daniel Teske committed
160 161 162 163
    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);
BogDan Vatra's avatar
BogDan Vatra committed
164

165
    QString getProductModel(const QString &device) const;
166 167
    enum class OpenGl { Enabled, Disabled, Unknown };
    OpenGl getOpenGLEnabled(const QString &emulator) const;
168
    bool hasFinishedBooting(const QString &device) const;
Daniel Teske's avatar
Daniel Teske committed
169 170
    bool waitForBooted(const QString &serialNumber, const QFutureInterface<bool> &fi) const;
    bool isConnected(const QString &serialNumber) const;
171

172
    SdkPlatform highestAndroidSdk() const;
173
private:
174
    static CreateAvdInfo createAVDImpl(CreateAvdInfo info, Utils::FileName androidToolPath, Utils::Environment env);
175
    static QString getDeviceProperty(const QString &adbToolPath, const QString &device, const QString &property);
176

Daniel Teske's avatar
Daniel Teske committed
177
    Utils::FileName toolPath(const ProjectExplorer::Abi &abi, const QString &ndkToolChainVersion) const;
178 179
    Utils::FileName openJDKBinPath() const;
    int getSDKVersion(const QString &device) const;
180
    static int getSDKVersion(const QString &adbToolPath, const QString &device);
181
    QStringList getAbis(const QString &device) const;
182 183
    static QStringList getAbis(const QString &adbToolPath, const QString &device);
    static bool isBootToQt(const QString &adbToolPath, const QString &device);
184
    bool isBootToQt(const QString &device) const;
185
    static QString getAvdName(const QString &serialnumber);
186 187 188 189 190 191 192 193 194 195 196 197

    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;
    unsigned m_partitionSize;
    bool m_automaticKitCreation;
BogDan Vatra's avatar
BogDan Vatra committed
198
    bool m_useGradle;
199 200 201

    //caches
    mutable bool m_availableSdkPlatformsUpToDate;
202 203
    mutable QVector<SdkPlatform> m_availableSdkPlatforms;
    static bool sortSdkPlatformByApiLevel(const SdkPlatform &a, const SdkPlatform &b);
204 205 206 207 208 209 210 211

    mutable bool m_NdkInformationUpToDate;
    mutable QString m_toolchainHost;
    mutable QVector<int> m_availableNdkPlatforms;

    mutable QHash<QString, QString> m_serialNumberToDeviceName;
};

212
class ANDROID_EXPORT AndroidConfigurations : public QObject
213 214 215 216 217
{
    friend class Android::AndroidPlugin;
    Q_OBJECT

public:
hjk's avatar
hjk committed
218
    static const AndroidConfig &currentConfig();
219 220 221 222
    static void setConfig(const AndroidConfig &config);
    static AndroidConfigurations *instance();

    static void updateAndroidDevice();
223 224
    enum Options { None, FilterAndroid5 };
    static AndroidDeviceInfo showDeviceDialog(ProjectExplorer::Project *project, int apiLevel, const QString &abi, Options options);
225 226
    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
227
public slots:
228
    static void clearDefaultDevices(ProjectExplorer::Project *project);
229 230
    static void registerNewToolChains();
    static void removeOldToolChains();
231
    static void updateAutomaticKitList();
232
    static bool force32bitEmulator();
233

BogDan Vatra's avatar
BogDan Vatra committed
234 235 236 237 238 239 240 241 242 243
signals:
    void updated();

private:
    AndroidConfigurations(QObject *parent);
    void load();
    void save();

    static AndroidConfigurations *m_instance;
    AndroidConfig m_config;
244 245

    QMap<ProjectExplorer::Project *, QMap<QString, QString> > m_defaultDeviceForAbi;
246
    bool m_force32bit;
BogDan Vatra's avatar
BogDan Vatra committed
247 248 249
};

} // namespace Android