androidconfigurations.h 6.61 KB
Newer Older
BogDan Vatra's avatar
BogDan Vatra committed
1 2
/**************************************************************************
**
3
** Copyright (c) 2014 BogDan Vatra <bog_dan_ro@yahoo.com>
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
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 12 13 14
** 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
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
BogDan Vatra's avatar
BogDan Vatra committed
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
BogDan Vatra's avatar
BogDan Vatra committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
BogDan Vatra's avatar
BogDan Vatra committed
29 30 31 32 33 34

#ifndef ANDROIDCONFIGURATIONS_H
#define ANDROIDCONFIGURATIONS_H

#include <QObject>
#include <QString>
35
#include <QStringList>
BogDan Vatra's avatar
BogDan Vatra committed
36
#include <QVector>
37 38
#include <QHash>
#include <QMap>
Daniel Teske's avatar
Daniel Teske committed
39
#include <QFutureInterface>
BogDan Vatra's avatar
BogDan Vatra committed
40
#include <projectexplorer/abi.h>
41
#include <utils/fileutils.h>
42
#include <utils/environment.h>
BogDan Vatra's avatar
BogDan Vatra committed
43 44 45 46 47

QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE

48 49
namespace ProjectExplorer { class Project; }

BogDan Vatra's avatar
BogDan Vatra committed
50 51 52 53 54 55 56 57 58 59
namespace Android {
namespace Internal {

class AndroidConfig
{
public:
    AndroidConfig();
    AndroidConfig(const QSettings &settings);
    void save(QSettings &settings) const;

Tobias Hunger's avatar
Tobias Hunger committed
60 61 62 63 64
    Utils::FileName sdkLocation;
    Utils::FileName ndkLocation;
    Utils::FileName antLocation;
    Utils::FileName openJDKLocation;
    Utils::FileName keystoreLocation;
65
    QString toolchainHost;
66
    QStringList makeExtraSearchDirectories;
BogDan Vatra's avatar
BogDan Vatra committed
67
    unsigned partitionSize;
Daniel Teske's avatar
Daniel Teske committed
68
    bool automaticKitCreation;
BogDan Vatra's avatar
BogDan Vatra committed
69 70
};

hjk's avatar
hjk committed
71 72
struct AndroidDeviceInfo
{
BogDan Vatra's avatar
BogDan Vatra committed
73
    QString serialNumber;
74
    QStringList cpuAbi;
BogDan Vatra's avatar
BogDan Vatra committed
75
    int sdk;
76
    bool unauthorized;
77 78
    enum AndroidDeviceType { Hardware, Emulator };
    AndroidDeviceType type;
79 80

    static QStringList adbSelector(const QString &serialNumber);
BogDan Vatra's avatar
BogDan Vatra committed
81 82 83 84 85 86
};

class AndroidConfigurations : public QObject
{
    Q_OBJECT

hjk's avatar
hjk committed
87
public:
BogDan Vatra's avatar
BogDan Vatra committed
88 89 90 91
    static AndroidConfigurations &instance(QObject *parent = 0);
    AndroidConfig config() const { return m_config; }
    void setConfig(const AndroidConfig &config);
    QStringList sdkTargets(int minApiLevel = 0) const;
Tobias Hunger's avatar
Tobias Hunger committed
92 93
    Utils::FileName adbToolPath() const;
    Utils::FileName androidToolPath() const;
94
    Utils::Environment androidToolEnvironment() const;
Tobias Hunger's avatar
Tobias Hunger committed
95 96
    Utils::FileName antToolPath() const;
    Utils::FileName emulatorToolPath() const;
97
    Utils::FileName gccPath(ProjectExplorer::Abi::Architecture architecture, const QString &ndkToolChainVersion) const;
98
    Utils::FileName gdbPath(ProjectExplorer::Abi::Architecture architecture, const QString &ndkToolChainVersion) const;
Tobias Hunger's avatar
Tobias Hunger committed
99 100 101
    Utils::FileName openJDKPath() const;
    Utils::FileName keytoolPath() const;
    Utils::FileName jarsignerPath() const;
102
    Utils::FileName zipalignPath() const;
103 104
    Utils::FileName stripPath(ProjectExplorer::Abi::Architecture architecture, const QString &ndkToolChainVersion) const;
    Utils::FileName readelfPath(ProjectExplorer::Abi::Architecture architecture, const QString &ndkToolChainVersion) const;
105
    QString createAVD(QWidget *parent, int minApiLevel = 0, QString targetArch = QString()) const;
106
    QString createAVD(const QString &target, const QString &name, const QString &abi, int sdcardSize) const;
BogDan Vatra's avatar
BogDan Vatra committed
107
    bool removeAVD(const QString &name) const;
108
    QVector<AndroidDeviceInfo> connectedDevices(QString *error = 0) const;
109
    QVector<AndroidDeviceInfo> androidVirtualDevices() const;
110 111
    QString startAVD(const QString &name, int apiLevel, QString cpuAbi) const;
    bool startAVDAsync(const QString &avdName) const;
112
    QString findAvd(int apiLevel, const QString &cpuAbi) const;
Daniel Teske's avatar
Daniel Teske committed
113 114
    QString waitForAvd(int apiLevel, const QString &cpuAbi, const QFutureInterface<bool> &fi = QFutureInterface<bool>()) const;
    // special version for AndroidDeployQt::run
115
    QString bestNdkPlatformMatch(const QString &targetAPI) const;
BogDan Vatra's avatar
BogDan Vatra committed
116

117 118
    QStringList makeExtraSearchDirectories() const;

119
    static ProjectExplorer::Abi::Architecture architectureForToolChainPrefix(const QString &toolchainprefix);
BogDan Vatra's avatar
BogDan Vatra committed
120 121 122
    static QLatin1String toolchainPrefix(ProjectExplorer::Abi::Architecture architecture);
    static QLatin1String toolsPrefix(ProjectExplorer::Abi::Architecture architecture);

123 124 125
    // called from AndroidPlugin
    void updateAndroidDevice();

126
    QString getProductModel(const QString &device) const;
127
    bool hasFinishedBooting(const QString &device) const;
Daniel Teske's avatar
Daniel Teske committed
128 129
    bool waitForBooted(const QString &serialNumber, const QFutureInterface<bool> &fi) const;
    bool isConnected(const QString &serialNumber) const;
130

131 132 133
    AndroidDeviceInfo showDeviceDialog(ProjectExplorer::Project *project, int apiLevel, const QString &abi);
    void setDefaultDevice(ProjectExplorer::Project *project, const QString &abi, const QString &serialNumber); // serial number or avd name
    QString defaultDevice(ProjectExplorer::Project *project, const QString &abi) const; // serial number or avd name
134
    QString highestAndroidSdk() const;
135 136 137
public slots:
    void clearDefaultDevices(ProjectExplorer::Project *project);

BogDan Vatra's avatar
BogDan Vatra committed
138 139 140 141
signals:
    void updated();

public slots:
Daniel Teske's avatar
Daniel Teske committed
142
    void updateAutomaticKitList();
BogDan Vatra's avatar
BogDan Vatra committed
143 144

private:
145
    Utils::FileName toolPath(ProjectExplorer::Abi::Architecture architecture, const QString &ndkToolChainVersion) const;
Tobias Hunger's avatar
Tobias Hunger committed
146
    Utils::FileName openJDKBinPath() const;
147
    void detectToolchainHost();
BogDan Vatra's avatar
BogDan Vatra committed
148 149 150 151 152 153

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

    int getSDKVersion(const QString &device) const;
154
    QStringList getAbis(const QString &device) const;
155
    bool isBootToQt(const QString &device) const;
156
    void updateAvailableNdkPlatforms();
157
    void updateAvailableSdkPlatforms();
BogDan Vatra's avatar
BogDan Vatra committed
158 159 160 161


    static AndroidConfigurations *m_instance;
    AndroidConfig m_config;
162
    QVector<int> m_availableNdkPlatforms;
163 164
    QVector<int> m_availableSdkPlatforms;

165 166 167
    mutable QHash<QString, QString> m_serialNumberToDeviceName;

    QMap<ProjectExplorer::Project *, QMap<QString, QString> > m_defaultDeviceForAbi;
BogDan Vatra's avatar
BogDan Vatra committed
168 169 170 171 172 173
};

} // namespace Internal
} // namespace Android

#endif // ANDROIDCONFIGURATIONS_H