forked from qt-creator/qt-creator
AndroidManager: Use Utils::Process for startAdbProcess()
Change-Id: I675d0103bee854af67d379d08a7e0ddbc6654e8d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -264,7 +264,7 @@ FilePath AndroidManager::buildDirectory(const Target *target)
|
|||||||
if (isQt5CmakeProject(target)) {
|
if (isQt5CmakeProject(target)) {
|
||||||
// Return the main build dir and not the android libs dir
|
// Return the main build dir and not the android libs dir
|
||||||
const QString libsDir = QString(Constants::ANDROID_BUILD_DIRECTORY) + "/libs";
|
const QString libsDir = QString(Constants::ANDROID_BUILD_DIRECTORY) + "/libs";
|
||||||
Utils::FilePath parentDuildDir = buildDir.parentDir();
|
FilePath parentDuildDir = buildDir.parentDir();
|
||||||
if (parentDuildDir.endsWith(libsDir) || libsDir.endsWith(libsDir + "/"))
|
if (parentDuildDir.endsWith(libsDir) || libsDir.endsWith(libsDir + "/"))
|
||||||
return parentDuildDir.parentDir().parentDir();
|
return parentDuildDir.parentDir().parentDir();
|
||||||
}
|
}
|
||||||
@@ -612,10 +612,10 @@ void AndroidManager::installQASIPackage(Target *target, const FilePath &packageP
|
|||||||
QStringList arguments = AndroidDeviceInfo::adbSelector(deviceSerialNumber);
|
QStringList arguments = AndroidDeviceInfo::adbSelector(deviceSerialNumber);
|
||||||
arguments << "install" << "-r " << packagePath.path();
|
arguments << "install" << "-r " << packagePath.path();
|
||||||
QString error;
|
QString error;
|
||||||
QProcess *process = startAdbProcess(arguments, &error);
|
Process *process = startAdbProcess(arguments, &error);
|
||||||
if (process) {
|
if (process) {
|
||||||
// TODO: Potential leak when the process is still running on Creator shutdown.
|
// TODO: Potential leak when the process is still running on Creator shutdown.
|
||||||
QObject::connect(process, &QProcess::finished, process, &QObject::deleteLater);
|
QObject::connect(process, &Process::done, process, &QObject::deleteLater);
|
||||||
} else {
|
} else {
|
||||||
Core::MessageManager::writeDisrupting(
|
Core::MessageManager::writeDisrupting(
|
||||||
Tr::tr("Android package installation failed.\n%1").arg(error));
|
Tr::tr("Android package installation failed.\n%1").arg(error));
|
||||||
@@ -671,20 +671,20 @@ bool AndroidManager::checkCertificateExists(const FilePath &keystorePath,
|
|||||||
return proc.result() == ProcessResult::FinishedWithSuccess;
|
return proc.result() == ProcessResult::FinishedWithSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
QProcess *AndroidManager::startAdbProcess(const QStringList &args, QString *err)
|
Process *AndroidManager::startAdbProcess(const QStringList &args, QString *err)
|
||||||
{
|
{
|
||||||
std::unique_ptr<QProcess> p(new QProcess);
|
std::unique_ptr<Process> process(new Process);
|
||||||
const FilePath adb = AndroidConfigurations::currentConfig().adbToolPath();
|
const FilePath adb = AndroidConfigurations::currentConfig().adbToolPath();
|
||||||
qCDebug(androidManagerLog).noquote() << "Running command (async):"
|
const CommandLine command{adb, args};
|
||||||
<< CommandLine(adb, args).toUserOutput();
|
qCDebug(androidManagerLog).noquote() << "Running command (async):" << command.toUserOutput();
|
||||||
p->start(adb.toString(), args);
|
process->setCommand(command);
|
||||||
if (p->waitForStarted(500) && p->state() == QProcess::Running)
|
process->start();
|
||||||
return p.release();
|
if (process->waitForStarted(500) && process->state() == QProcess::Running)
|
||||||
|
return process.release();
|
||||||
|
|
||||||
QString errorStr = QString::fromUtf8(p->readAllStandardError());
|
const QString errorStr = process->readAllStandardError();
|
||||||
qCDebug(androidManagerLog).noquote() << "Running command (async) failed:"
|
qCDebug(androidManagerLog).noquote() << "Running command (async) failed:"
|
||||||
<< CommandLine(adb, args).toUserOutput()
|
<< command.toUserOutput() << "Output:" << errorStr;
|
||||||
<< "Output:" << errorStr;
|
|
||||||
if (err)
|
if (err)
|
||||||
*err = errorStr;
|
*err = errorStr;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@@ -12,10 +12,6 @@
|
|||||||
#include <qtsupport/baseqtversion.h>
|
#include <qtsupport/baseqtversion.h>
|
||||||
#include <projectexplorer/abi.h>
|
#include <projectexplorer/abi.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QProcess;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
class Kit;
|
class Kit;
|
||||||
class Target;
|
class Target;
|
||||||
@@ -24,6 +20,7 @@ class Target;
|
|||||||
namespace Utils {
|
namespace Utils {
|
||||||
class CommandLine;
|
class CommandLine;
|
||||||
class FilePath;
|
class FilePath;
|
||||||
|
class Process;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Android {
|
namespace Android {
|
||||||
@@ -97,7 +94,7 @@ public:
|
|||||||
static bool checkCertificateExists(const Utils::FilePath &keystorePath,
|
static bool checkCertificateExists(const Utils::FilePath &keystorePath,
|
||||||
const QString &keystorePasswd, const QString &alias);
|
const QString &keystorePasswd, const QString &alias);
|
||||||
|
|
||||||
static QProcess *startAdbProcess(const QStringList &args, QString *err = nullptr);
|
static Utils::Process *startAdbProcess(const QStringList &args, QString *err = nullptr);
|
||||||
static SdkToolResult runAdbCommand(const QStringList &args, const QByteArray &writeData = {},
|
static SdkToolResult runAdbCommand(const QStringList &args, const QByteArray &writeData = {},
|
||||||
int timeoutS = 30);
|
int timeoutS = 30);
|
||||||
|
|
||||||
|
@@ -141,18 +141,6 @@ static void findProcessPIDAndUser(QPromise<PidUserPair> &promise,
|
|||||||
promise.addResult(PidUserPair(processPID, processUser));
|
promise.addResult(PidUserPair(processPID, processUser));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void deleter(QProcess *p)
|
|
||||||
{
|
|
||||||
qCDebug(androidRunWorkerLog) << "Killing process:" << p->objectName();
|
|
||||||
p->terminate();
|
|
||||||
if (!p->waitForFinished(1000)) {
|
|
||||||
p->kill();
|
|
||||||
p->waitForFinished();
|
|
||||||
}
|
|
||||||
// Might get deleted from its own signal handler.
|
|
||||||
p->deleteLater();
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString gdbServerArch(const QString &androidAbi)
|
static QString gdbServerArch(const QString &androidAbi)
|
||||||
{
|
{
|
||||||
if (androidAbi == ProjectExplorer::Constants::ANDROID_ABI_ARM64_V8A)
|
if (androidAbi == ProjectExplorer::Constants::ANDROID_ABI_ARM64_V8A)
|
||||||
@@ -214,11 +202,8 @@ static FilePath debugServer(bool useLldb, const Target *target)
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AndroidRunnerWorker::AndroidRunnerWorker(RunWorker *runner, const QString &packageName)
|
AndroidRunnerWorker::AndroidRunnerWorker(RunWorker *runner, const QString &packageName)
|
||||||
: m_packageName(packageName)
|
: m_packageName(packageName)
|
||||||
, m_psIsAlive(nullptr, deleter)
|
|
||||||
, m_debugServerProcess(nullptr, deleter)
|
|
||||||
{
|
{
|
||||||
auto runControl = runner->runControl();
|
auto runControl = runner->runControl();
|
||||||
m_useLldb = Debugger::DebuggerKitAspect::engineType(runControl->kit())
|
m_useLldb = Debugger::DebuggerKitAspect::engineType(runControl->kit())
|
||||||
@@ -865,8 +850,7 @@ void AndroidRunnerWorker::onProcessIdChanged(PidUserPair pidUser)
|
|||||||
QTC_ASSERT(m_psIsAlive, return);
|
QTC_ASSERT(m_psIsAlive, return);
|
||||||
m_psIsAlive->setObjectName("IsAliveProcess");
|
m_psIsAlive->setObjectName("IsAliveProcess");
|
||||||
m_psIsAlive->setProcessChannelMode(QProcess::MergedChannels);
|
m_psIsAlive->setProcessChannelMode(QProcess::MergedChannels);
|
||||||
connect(m_psIsAlive.get(), &QProcess::finished,
|
connect(m_psIsAlive.get(), &Process::done, this, [this] { onProcessIdChanged({-1, -1}); });
|
||||||
this, bind(&AndroidRunnerWorker::onProcessIdChanged, this, PidUserPair(-1, -1)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,10 +12,6 @@
|
|||||||
#include <QFuture>
|
#include <QFuture>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QProcess;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
class FilePath;
|
class FilePath;
|
||||||
class Process;
|
class Process;
|
||||||
@@ -80,7 +76,6 @@ private:
|
|||||||
Settled
|
Settled
|
||||||
};
|
};
|
||||||
void onProcessIdChanged(PidUserPair pidUser);
|
void onProcessIdChanged(PidUserPair pidUser);
|
||||||
using Deleter = void (*)(QProcess *);
|
|
||||||
|
|
||||||
// Create the processes and timer in the worker thread, for correct thread affinity
|
// Create the processes and timer in the worker thread, for correct thread affinity
|
||||||
bool m_isPreNougat = false;
|
bool m_isPreNougat = false;
|
||||||
@@ -92,7 +87,7 @@ private:
|
|||||||
qint64 m_processPID = -1;
|
qint64 m_processPID = -1;
|
||||||
qint64 m_processUser = -1;
|
qint64 m_processUser = -1;
|
||||||
std::unique_ptr<Utils::Process> m_adbLogcatProcess;
|
std::unique_ptr<Utils::Process> m_adbLogcatProcess;
|
||||||
std::unique_ptr<QProcess, Deleter> m_psIsAlive;
|
std::unique_ptr<Utils::Process> m_psIsAlive;
|
||||||
QByteArray m_stdoutBuffer;
|
QByteArray m_stdoutBuffer;
|
||||||
QByteArray m_stderrBuffer;
|
QByteArray m_stderrBuffer;
|
||||||
QFuture<PidUserPair> m_pidFinder;
|
QFuture<PidUserPair> m_pidFinder;
|
||||||
@@ -103,7 +98,7 @@ private:
|
|||||||
QUrl m_qmlServer;
|
QUrl m_qmlServer;
|
||||||
JDBState m_jdbState = JDBState::Idle;
|
JDBState m_jdbState = JDBState::Idle;
|
||||||
Utils::Port m_localJdbServerPort;
|
Utils::Port m_localJdbServerPort;
|
||||||
std::unique_ptr<QProcess, Deleter> m_debugServerProcess; // gdbserver or lldb-server
|
std::unique_ptr<Utils::Process> m_debugServerProcess; // gdbserver or lldb-server
|
||||||
std::unique_ptr<Utils::Process> m_jdbProcess;
|
std::unique_ptr<Utils::Process> m_jdbProcess;
|
||||||
QString m_deviceSerialNumber;
|
QString m_deviceSerialNumber;
|
||||||
int m_apiLevel = -1;
|
int m_apiLevel = -1;
|
||||||
|
Reference in New Issue
Block a user