From d55373cab2eeb1f487c798fb72383d5bb1abcb10 Mon Sep 17 00:00:00 2001 From: Vikas Pachdha Date: Thu, 2 Aug 2018 11:00:06 +0200 Subject: [PATCH] Android: Enable setting environment variables for android apps Change-Id: Id4625f081d6997dcabad9b01fb09d6c9c6ef7477 Reviewed-by: BogDan Vatra --- src/plugins/android/android.pro | 6 ++- src/plugins/android/android.qbs | 2 + src/plugins/android/androiddebugsupport.cpp | 5 +- src/plugins/android/androiddebugsupport.h | 3 +- .../android/androidqmltoolingsupport.cpp | 5 +- .../android/androidqmltoolingsupport.h | 5 +- .../android/androidrunconfiguration.cpp | 3 ++ src/plugins/android/androidruncontrol.cpp | 5 +- src/plugins/android/androidruncontrol.h | 3 +- .../android/androidrunenvironmentaspect.cpp | 48 +++++++++++++++++++ .../android/androidrunenvironmentaspect.h | 42 ++++++++++++++++ src/plugins/android/androidrunner.cpp | 5 +- src/plugins/android/androidrunner.h | 3 +- src/plugins/android/androidrunnerworker.cpp | 12 ++--- src/plugins/android/androidrunnerworker.h | 1 - 15 files changed, 116 insertions(+), 32 deletions(-) create mode 100644 src/plugins/android/androidrunenvironmentaspect.cpp create mode 100644 src/plugins/android/androidrunenvironmentaspect.h diff --git a/src/plugins/android/android.pro b/src/plugins/android/android.pro index 11a209a7cfb..d6ee2f56fc5 100644 --- a/src/plugins/android/android.pro +++ b/src/plugins/android/android.pro @@ -55,7 +55,8 @@ HEADERS += \ androidsdkmanagerwidget.h \ androidpackageinstallationstep.h \ androidextralibrarylistmodel.h \ - createandroidmanifestwizard.h + createandroidmanifestwizard.h \ + androidrunenvironmentaspect.h SOURCES += \ androidconfigurations.cpp \ @@ -103,7 +104,8 @@ SOURCES += \ androidsdkmanagerwidget.cpp \ androidpackageinstallationstep.cpp \ androidextralibrarylistmodel.cpp \ - createandroidmanifestwizard.cpp + createandroidmanifestwizard.cpp \ + androidrunenvironmentaspect.cpp FORMS += \ androidsettingswidget.ui \ diff --git a/src/plugins/android/android.qbs b/src/plugins/android/android.qbs index 66aa72916e8..cc5e62d97bf 100644 --- a/src/plugins/android/android.qbs +++ b/src/plugins/android/android.qbs @@ -85,6 +85,8 @@ Project { "androidqtversionfactory.h", "androidrunconfiguration.cpp", "androidrunconfiguration.h", + "androidrunenvironmentaspect.h", + "androidrunenvironmentaspect.cpp", "androidruncontrol.cpp", "androidruncontrol.h", "androidrunner.cpp", diff --git a/src/plugins/android/androiddebugsupport.cpp b/src/plugins/android/androiddebugsupport.cpp index 7b0eafb6689..0cb44f0a4be 100644 --- a/src/plugins/android/androiddebugsupport.cpp +++ b/src/plugins/android/androiddebugsupport.cpp @@ -99,12 +99,11 @@ static QString toNdkArch(const QString &arch) return QLatin1String("arch-") + arch; } -AndroidDebugSupport::AndroidDebugSupport(RunControl *runControl, const QString &intentName, - const Utils::Environment &extraEnvVars) +AndroidDebugSupport::AndroidDebugSupport(RunControl *runControl, const QString &intentName) : Debugger::DebuggerRunTool(runControl) { setDisplayName("AndroidDebugger"); - m_runner = new AndroidRunner(runControl, intentName, extraEnvVars); + m_runner = new AndroidRunner(runControl, intentName); addStartDependency(m_runner); } diff --git a/src/plugins/android/androiddebugsupport.h b/src/plugins/android/androiddebugsupport.h index 9f6aa3981e7..43a5f1f724a 100644 --- a/src/plugins/android/androiddebugsupport.h +++ b/src/plugins/android/androiddebugsupport.h @@ -37,8 +37,7 @@ class AndroidDebugSupport : public Debugger::DebuggerRunTool public: AndroidDebugSupport(ProjectExplorer::RunControl *runControl, - const QString &intentName = QString(), - const Utils::Environment &extraEnvVars = Utils::Environment()); + const QString &intentName = QString()); void start() override; void stop() override; diff --git a/src/plugins/android/androidqmltoolingsupport.cpp b/src/plugins/android/androidqmltoolingsupport.cpp index 0dbfe82a698..001ad3d2d70 100644 --- a/src/plugins/android/androidqmltoolingsupport.cpp +++ b/src/plugins/android/androidqmltoolingsupport.cpp @@ -32,13 +32,12 @@ namespace Android { namespace Internal { AndroidQmlToolingSupport::AndroidQmlToolingSupport(RunControl *runControl, - const QString &intentName, - const Utils::Environment &extraEnvVars) + const QString &intentName) : RunWorker(runControl) { setDisplayName("AndroidQmlToolingSupport"); - auto runner = new AndroidRunner(runControl, intentName, extraEnvVars); + auto runner = new AndroidRunner(runControl, intentName); addStartDependency(runner); auto profiler = runControl->createWorker(runControl->runMode()); diff --git a/src/plugins/android/androidqmltoolingsupport.h b/src/plugins/android/androidqmltoolingsupport.h index e8cb911a530..5e1d00aa3ba 100644 --- a/src/plugins/android/androidqmltoolingsupport.h +++ b/src/plugins/android/androidqmltoolingsupport.h @@ -36,9 +36,8 @@ class AndroidQmlToolingSupport : public ProjectExplorer::RunWorker Q_OBJECT public: - explicit AndroidQmlToolingSupport( - ProjectExplorer::RunControl *runControl, const QString &intentName = QString(), - const Utils::Environment &extraEnvVars = Utils::Environment()); + explicit AndroidQmlToolingSupport(ProjectExplorer::RunControl *runControl, + const QString &intentName = QString()); private: void start() override; diff --git a/src/plugins/android/androidrunconfiguration.cpp b/src/plugins/android/androidrunconfiguration.cpp index c3d394eb563..9948f69b5d7 100644 --- a/src/plugins/android/androidrunconfiguration.cpp +++ b/src/plugins/android/androidrunconfiguration.cpp @@ -30,6 +30,7 @@ #include "androidtoolchain.h" #include "androidmanager.h" #include "adbcommandswidget.h" +#include "androidrunenvironmentaspect.h" #include #include @@ -110,6 +111,7 @@ void BaseStringListAspect::setLabel(const QString &label) AndroidRunConfiguration::AndroidRunConfiguration(Target *target, Core::Id id) : RunConfiguration(target, id) { + addExtraAspect(new AndroidRunEnvironmentAspect(this)); addExtraAspect(new ArgumentsAspect(this)); auto amStartArgsAspect = new BaseStringAspect(this); @@ -154,6 +156,7 @@ QWidget *AndroidRunConfiguration::createConfigurationWidget() extraAspect(Constants::ANDROID_PRESTARTSHELLCMDLIST)->addToConfigurationLayout(layout); extraAspect(Constants::ANDROID_POSTFINISHSHELLCMDLIST)->addToConfigurationLayout(layout); + extraAspect()->addToConfigurationLayout(layout); auto wrapped = wrapWidget(widget); auto detailsWidget = qobject_cast(wrapped); diff --git a/src/plugins/android/androidruncontrol.cpp b/src/plugins/android/androidruncontrol.cpp index d247754eeb4..9f6db540437 100644 --- a/src/plugins/android/androidruncontrol.cpp +++ b/src/plugins/android/androidruncontrol.cpp @@ -38,9 +38,8 @@ using namespace ProjectExplorer; namespace Android { namespace Internal { -AndroidRunSupport::AndroidRunSupport(RunControl *runControl, const QString &intentName, - const Utils::Environment &extraEnvVars) - : AndroidRunner(runControl, intentName, extraEnvVars) +AndroidRunSupport::AndroidRunSupport(RunControl *runControl, const QString &intentName) + : AndroidRunner(runControl, intentName) { runControl->setIcon(Utils::Icons::RUN_SMALL_TOOLBAR); } diff --git a/src/plugins/android/androidruncontrol.h b/src/plugins/android/androidruncontrol.h index ddaa07aa8a8..3fa963812e4 100644 --- a/src/plugins/android/androidruncontrol.h +++ b/src/plugins/android/androidruncontrol.h @@ -40,8 +40,7 @@ class AndroidRunSupport : public AndroidRunner public: explicit AndroidRunSupport(ProjectExplorer::RunControl *runControl, - const QString &intentName = QString(), - const Utils::Environment &extraEnvVars = Utils::Environment()); + const QString &intentName = QString()); ~AndroidRunSupport() override; void start() override; diff --git a/src/plugins/android/androidrunenvironmentaspect.cpp b/src/plugins/android/androidrunenvironmentaspect.cpp new file mode 100644 index 00000000000..d2949de6b9d --- /dev/null +++ b/src/plugins/android/androidrunenvironmentaspect.cpp @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** 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 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. +** +** 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. +** +****************************************************************************/ +#include "androidrunenvironmentaspect.h" + +namespace { +enum BaseEnvironmentBase { + CleanEnvironmentBase +}; +} + +namespace Android { + +AndroidRunEnvironmentAspect::AndroidRunEnvironmentAspect(ProjectExplorer::RunConfiguration *rc) : + ProjectExplorer::EnvironmentAspect (rc) +{ + addSupportedBaseEnvironment(CleanEnvironmentBase, tr("Clean Environment")); +} + +Utils::Environment AndroidRunEnvironmentAspect::baseEnvironment() const +{ + // Clean Environment + return Utils::Environment(); +} + +} // namespace Android + diff --git a/src/plugins/android/androidrunenvironmentaspect.h b/src/plugins/android/androidrunenvironmentaspect.h new file mode 100644 index 00000000000..2b91bfafa15 --- /dev/null +++ b/src/plugins/android/androidrunenvironmentaspect.h @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** 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 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. +** +** 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. +** +****************************************************************************/ +#pragma once + +#include + +namespace Android { + +class AndroidRunEnvironmentAspect : public ProjectExplorer::EnvironmentAspect +{ + Q_OBJECT + +public: + AndroidRunEnvironmentAspect(ProjectExplorer::RunConfiguration *rc); + + Utils::Environment baseEnvironment() const override; +}; + +} // namespace Android + diff --git a/src/plugins/android/androidrunner.cpp b/src/plugins/android/androidrunner.cpp index 0c89b8a4909..a70c9f04dc2 100644 --- a/src/plugins/android/androidrunner.cpp +++ b/src/plugins/android/androidrunner.cpp @@ -118,9 +118,7 @@ using namespace Utils; namespace Android { namespace Internal { -AndroidRunner::AndroidRunner(RunControl *runControl, - const QString &intentName, - const Utils::Environment &extraEnvVars) +AndroidRunner::AndroidRunner(RunControl *runControl, const QString &intentName) : RunWorker(runControl), m_target(runControl->runConfiguration()->target()) { setDisplayName("AndroidRunner"); @@ -144,7 +142,6 @@ AndroidRunner::AndroidRunner(RunControl *runControl, m_worker.reset(new AndroidRunnerWorker(this, m_packageName)); m_worker->setIntentName(intent); m_worker->setIsPreNougat(apiLevel <= 23); - m_worker->setExtraEnvVars(extraEnvVars); m_worker->moveToThread(&m_thread); diff --git a/src/plugins/android/androidrunner.h b/src/plugins/android/androidrunner.h index c4a5763cb63..d56b59c0011 100644 --- a/src/plugins/android/androidrunner.h +++ b/src/plugins/android/androidrunner.h @@ -50,8 +50,7 @@ class AndroidRunner : public ProjectExplorer::RunWorker public: explicit AndroidRunner(ProjectExplorer::RunControl *runControl, - const QString &intentName = QString(), - const Utils::Environment &extraEnvVars = Utils::Environment()); + const QString &intentName = QString()); ~AndroidRunner() override; Utils::Port gdbServerPort() const { return m_gdbServerPort; } diff --git a/src/plugins/android/androidrunnerworker.cpp b/src/plugins/android/androidrunnerworker.cpp index 794aead4fcb..4f08f4f069f 100644 --- a/src/plugins/android/androidrunnerworker.cpp +++ b/src/plugins/android/androidrunnerworker.cpp @@ -31,6 +31,7 @@ #include "androidrunconfiguration.h" #include +#include #include #include #include @@ -193,6 +194,10 @@ AndroidRunnerWorker::AndroidRunnerWorker(RunWorker *runner, const QString &packa m_deviceSerialNumber = AndroidManager::deviceSerialNumber(target); m_apiLevel = AndroidManager::deviceApiLevel(target); + m_extraEnvVars = runConfig->extraAspect()->environment(); + qCDebug(androidRunWorkerLog) << "Environment variables for the app" + << m_extraEnvVars.toStringList(); + m_extraAppParams = runConfig->runnable().commandLineArguments; if (auto aspect = runConfig->extraAspect(Constants::ANDROID_AMSTARTARGS)) @@ -607,12 +612,5 @@ void AndroidRunnerWorker::onProcessIdChanged(qint64 pid) } } -void AndroidRunnerWorker::setExtraEnvVars(const Utils::Environment &extraEnvVars) -{ - m_extraEnvVars = extraEnvVars; - qCDebug(androidRunWorkerLog) << "Settings extra env:" - << extraEnvVars.toStringList(); -} - } // namespace Internal } // namespace Android diff --git a/src/plugins/android/androidrunnerworker.h b/src/plugins/android/androidrunnerworker.h index 737a0963fb9..c9714724ccf 100644 --- a/src/plugins/android/androidrunnerworker.h +++ b/src/plugins/android/androidrunnerworker.h @@ -55,7 +55,6 @@ public: void logcatReadStandardOutput(); void logcatProcess(const QByteArray &text, QByteArray &buffer, bool onlyError); void setAndroidDeviceInfo(const AndroidDeviceInfo &info); - void setExtraEnvVars(const Utils::Environment &extraEnvVars); void setIsPreNougat(bool isPreNougat) { m_isPreNougat = isPreNougat; } void setIntentName(const QString &intentName) { m_intentName = intentName; }