forked from qt-creator/qt-creator
Android: Avoid code repetition
Add extra args to removeForwardPort(). Change-Id: I3aed7974aff327f29db9f62e4714ba2696b81dd6 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -452,14 +452,9 @@ void AndroidRunnerWorker::asyncStartHelper()
|
|||||||
|
|
||||||
if (m_qmlDebugServices != QmlDebug::NoQmlDebugServices) {
|
if (m_qmlDebugServices != QmlDebug::NoQmlDebugServices) {
|
||||||
// currently forward to same port on device and host
|
// currently forward to same port on device and host
|
||||||
const QString port = QString("tcp:%1").arg(m_qmlServer.port());
|
const QString port = "tcp:" + QString::number(m_qmlServer.port());
|
||||||
QStringList removeForward{{"forward", "--remove", port}};
|
if (!removeForwardPort(port, port, "QML"))
|
||||||
removeForwardPort(port);
|
|
||||||
if (!runAdb({"forward", port, port})) {
|
|
||||||
emit remoteProcessFinished(Tr::tr("Failed to forward QML debugging ports."));
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
m_afterFinishAdbCommands.push_back(removeForward.join(' '));
|
|
||||||
|
|
||||||
const QString qmljsdebugger = QString("port:%1,block,services:%2")
|
const QString qmljsdebugger = QString("port:%1,block,services:%2")
|
||||||
.arg(m_qmlServer.port()).arg(QmlDebug::qmlDebugServices(m_qmlDebugServices));
|
.arg(m_qmlServer.port()).arg(QmlDebug::qmlDebugServices(m_qmlDebugServices));
|
||||||
@@ -601,16 +596,8 @@ void AndroidRunnerWorker::startDebuggerServer(const QString &packageDir,
|
|||||||
qCDebug(androidRunWorkerLog) << "Debugger process started";
|
qCDebug(androidRunWorkerLog) << "Debugger process started";
|
||||||
m_debugServerProcess->setObjectName("AndroidDebugServerProcess");
|
m_debugServerProcess->setObjectName("AndroidDebugServerProcess");
|
||||||
|
|
||||||
// TODO: Repeats 3 times, refactor...
|
removeForwardPort("tcp:" + m_localDebugServerPort.toString(),
|
||||||
const QString port = "tcp:" + m_localDebugServerPort.toString();
|
"localfilesystem:" + gdbServerSocket, "C++");
|
||||||
const QStringList removeForward{"forward", "--remove", port};
|
|
||||||
removeForwardPort(port);
|
|
||||||
if (!runAdb({"forward", port,
|
|
||||||
"localfilesystem:" + gdbServerSocket})) {
|
|
||||||
emit remoteProcessFinished(Tr::tr("Failed to forward C++ debugging ports."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_afterFinishAdbCommands.push_back(removeForward.join(' '));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -690,15 +677,9 @@ void AndroidRunnerWorker::asyncStop()
|
|||||||
|
|
||||||
void AndroidRunnerWorker::handleJdbWaiting()
|
void AndroidRunnerWorker::handleJdbWaiting()
|
||||||
{
|
{
|
||||||
const QString port = "tcp:" + m_localJdbServerPort.toString();
|
if (!removeForwardPort("tcp:" + m_localJdbServerPort.toString(),
|
||||||
const QStringList removeForward{"forward", "--remove", port};
|
"jdwp:" + QString::number(m_processPID), "JDB"))
|
||||||
removeForwardPort(port);
|
|
||||||
if (!runAdb({"forward", port,
|
|
||||||
"jdwp:" + QString::number(m_processPID)})) {
|
|
||||||
emit remoteProcessFinished(Tr::tr("Failed to forward JDB debugging ports."));
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
m_afterFinishAdbCommands.push_back(removeForward.join(' '));
|
|
||||||
|
|
||||||
const FilePath jdbPath = AndroidConfig::openJDKLocation()
|
const FilePath jdbPath = AndroidConfig::openJDKLocation()
|
||||||
.pathAppended("bin/jdb").withExecutableSuffix();
|
.pathAppended("bin/jdb").withExecutableSuffix();
|
||||||
@@ -759,11 +740,18 @@ void AndroidRunnerWorker::handleJdbSettled()
|
|||||||
emit remoteProcessFinished(Tr::tr("Cannot attach JDB to the running application."));
|
emit remoteProcessFinished(Tr::tr("Cannot attach JDB to the running application."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AndroidRunnerWorker::removeForwardPort(const QString &port)
|
bool AndroidRunnerWorker::removeForwardPort(const QString &port, const QString &adbArg,
|
||||||
|
const QString &portType)
|
||||||
{
|
{
|
||||||
const SdkToolResult result = AndroidManager::runAdbCommand({"forward", "--list"});
|
const SdkToolResult result = AndroidManager::runAdbCommand({"forward", "--list"});
|
||||||
if (result.stdOut().contains(port))
|
if (result.stdOut().contains(port))
|
||||||
runAdb({"forward", "--remove", port});
|
runAdb({"forward", "--remove", port});
|
||||||
|
if (runAdb({"forward", port, adbArg})) {
|
||||||
|
m_afterFinishAdbCommands.push_back("forward --remove " + port);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
emit remoteProcessFinished(Tr::tr("Failed to forward %1 debugging ports.").arg(portType));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AndroidRunnerWorker::onProcessIdChanged(const PidUserPair &pidUser)
|
void AndroidRunnerWorker::onProcessIdChanged(const PidUserPair &pidUser)
|
||||||
|
@@ -58,7 +58,7 @@ private:
|
|||||||
void handleJdbWaiting();
|
void handleJdbWaiting();
|
||||||
void handleJdbSettled();
|
void handleJdbSettled();
|
||||||
|
|
||||||
void removeForwardPort(const QString &port);
|
bool removeForwardPort(const QString &port, const QString &adbArg, const QString &portType);
|
||||||
|
|
||||||
void asyncStartHelper();
|
void asyncStartHelper();
|
||||||
void startNativeDebugging();
|
void startNativeDebugging();
|
||||||
|
Reference in New Issue
Block a user