1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 BogDan Vatra <bog_dan_ro@yahoo.com>
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25
26 #include "androidrunconfiguration.h"
27
28 #include "androidconstants.h"
29 #include "androidglobal.h"
30 #include "androidtoolchain.h"
31 #include "androidmanager.h"
32
33 #include <app/app_version.h>
34
35 #include <projectexplorer/buildsystem.h>
36 #include <projectexplorer/kitinformation.h>
37 #include <projectexplorer/project.h>
38 #include <projectexplorer/runconfigurationaspects.h>
39 #include <projectexplorer/target.h>
40
41 #include <qtsupport/qtkitinformation.h>
42
43 #include <utils/detailswidget.h>
44 #include <utils/qtcassert.h>
45 #include <utils/qtcprocess.h>
46 #include <utils/utilsicons.h>
47
48 using namespace ProjectExplorer;
49 using namespace Utils;
50
51 namespace Android {
52
53 class BaseStringListAspect final : public Utils::StringAspect
54 {
55 public:
56 explicit BaseStringListAspect() = default;
57 ~BaseStringListAspect() final = default;
58
fromMap(const QVariantMap & map)59 void fromMap(const QVariantMap &map) final
60 {
61 // Pre Qt Creator 5.0 hack: Reads QStringList as QString
62 setValue(map.value(settingsKey()).toStringList().join('\n'));
63 }
64
toMap(QVariantMap & map) const65 void toMap(QVariantMap &map) const final
66 {
67 // Pre Qt Creator 5.0 hack: Writes QString as QStringList
68 map.insert(settingsKey(), value().split('\n'));
69 }
70 };
71
AndroidRunConfiguration(Target * target,Utils::Id id)72 AndroidRunConfiguration::AndroidRunConfiguration(Target *target, Utils::Id id)
73 : RunConfiguration(target, id)
74 {
75 auto envAspect = addAspect<EnvironmentAspect>();
76 envAspect->addSupportedBaseEnvironment(tr("Clean Environment"), {});
77
78 auto extraAppArgsAspect = addAspect<ArgumentsAspect>();
79
80 connect(extraAppArgsAspect, &BaseAspect::changed,
81 this, [target, extraAppArgsAspect]() {
82 if (target->buildConfigurations().first()->buildType() == BuildConfiguration::BuildType::Release) {
83 const QString buildKey = target->activeBuildKey();
84 target->buildSystem()->setExtraData(buildKey,
85 Android::Constants::ANDROID_APPLICATION_ARGUMENTS,
86 extraAppArgsAspect->arguments(target->macroExpander()));
87 }
88 });
89
90 auto amStartArgsAspect = addAspect<StringAspect>();
91 amStartArgsAspect->setId(Constants::ANDROID_AMSTARTARGS);
92 amStartArgsAspect->setSettingsKey("Android.AmStartArgsKey");
93 amStartArgsAspect->setLabelText(tr("Activity manager start options:"));
94 amStartArgsAspect->setDisplayStyle(StringAspect::LineEditDisplay);
95 amStartArgsAspect->setHistoryCompleter("Android.AmStartArgs.History");
96
97 auto warning = addAspect<StringAspect>();
98 warning->setDisplayStyle(StringAspect::LabelDisplay);
99 warning->setLabelPixmap(Icons::WARNING.pixmap());
100 warning->setValue(tr("If the \"am start\" options conflict, the application might not start.\n"
101 "%1 uses: am start -n <package_name>/<Activity_name> [-D].")
102 .arg(Core::Constants::IDE_DISPLAY_NAME));
103
104 auto preStartShellCmdAspect = addAspect<BaseStringListAspect>();
105 preStartShellCmdAspect->setDisplayStyle(StringAspect::TextEditDisplay);
106 preStartShellCmdAspect->setId(Constants::ANDROID_PRESTARTSHELLCMDLIST);
107 preStartShellCmdAspect->setSettingsKey("Android.PreStartShellCmdListKey");
108 preStartShellCmdAspect->setLabelText(tr("Pre-launch on-device shell commands:"));
109
110 auto postStartShellCmdAspect = addAspect<BaseStringListAspect>();
111 postStartShellCmdAspect->setDisplayStyle(StringAspect::TextEditDisplay);
112 postStartShellCmdAspect->setId(Constants::ANDROID_POSTFINISHSHELLCMDLIST);
113 postStartShellCmdAspect->setSettingsKey("Android.PostStartShellCmdListKey");
114 postStartShellCmdAspect->setLabelText(tr("Post-quit on-device shell commands:"));
115
116 setUpdater([this, target] {
117 const BuildTargetInfo bti = buildTargetInfo();
118 setDisplayName(bti.displayName);
119 setDefaultDisplayName(bti.displayName);
120 AndroidManager::updateGradleProperties(target, buildKey());
121 });
122
123 connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update);
124 }
125
126 } // namespace Android
127