forked from qt-creator/qt-creator
Android: check forward port exist before removing it
Task-number: QTCREATORBUG-24155 Change-Id: I3675a63d5aa85b8d11be9021d1a79fac1390b26e Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -579,7 +579,7 @@ void AndroidRunnerWorker::asyncStartHelper()
|
||||
// currently forward to same port on device and host
|
||||
const QString port = QString("tcp:%1").arg(m_qmlServer.port());
|
||||
QStringList removeForward{{"forward", "--remove", port}};
|
||||
runAdb(removeForward);
|
||||
removeForwardPort(port);
|
||||
if (!runAdb({"forward", port, port})) {
|
||||
emit remoteProcessFinished(tr("Failed to forward QML debugging ports."));
|
||||
return;
|
||||
@@ -662,9 +662,10 @@ bool AndroidRunnerWorker::startDebuggerServer(const QString &packageDir,
|
||||
qCDebug(androidRunWorkerLog) << "Debugger process started";
|
||||
m_debugServerProcess->setObjectName("AndroidDebugServerProcess");
|
||||
|
||||
QStringList removeForward{"forward", "--remove", "tcp:" + m_localDebugServerPort.toString()};
|
||||
runAdb(removeForward);
|
||||
if (!runAdb({"forward", "tcp:" + m_localDebugServerPort.toString(),
|
||||
const QString port = "tcp:" + m_localDebugServerPort.toString();
|
||||
const QStringList removeForward{"forward", "--remove", port};
|
||||
removeForwardPort(port);
|
||||
if (!runAdb({"forward", port,
|
||||
"localfilesystem:" + gdbServerSocket})) {
|
||||
if (errorStr)
|
||||
*errorStr = tr("Failed to forward C++ debugging ports.");
|
||||
@@ -698,9 +699,10 @@ void AndroidRunnerWorker::asyncStop()
|
||||
|
||||
void AndroidRunnerWorker::handleJdbWaiting()
|
||||
{
|
||||
QStringList removeForward{"forward", "--remove", "tcp:" + m_localJdbServerPort.toString()};
|
||||
runAdb(removeForward);
|
||||
if (!runAdb({"forward", "tcp:" + m_localJdbServerPort.toString(),
|
||||
const QString port = "tcp:" + m_localJdbServerPort.toString();
|
||||
const QStringList removeForward{"forward", "--remove", port};
|
||||
removeForwardPort(port);
|
||||
if (!runAdb({"forward", port,
|
||||
"jdwp:" + QString::number(m_processPID)})) {
|
||||
emit remoteProcessFinished(tr("Failed to forward JDB debugging ports."));
|
||||
return;
|
||||
@@ -761,6 +763,25 @@ void AndroidRunnerWorker::handleJdbSettled()
|
||||
emit remoteProcessFinished(tr("Cannot attach JDB to the running application."));
|
||||
}
|
||||
|
||||
void AndroidRunnerWorker::removeForwardPort(const QString &port)
|
||||
{
|
||||
bool found = false;
|
||||
SdkToolResult result = AndroidManager::runAdbCommand({"forward", "--list"});
|
||||
|
||||
QString string = result.stdOut();
|
||||
for (const QString &line : string.split('\n')) {
|
||||
if (line.contains(port)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
QStringList removeForward{"forward", "--remove", port};
|
||||
runAdb(removeForward);
|
||||
}
|
||||
}
|
||||
|
||||
void AndroidRunnerWorker::onProcessIdChanged(qint64 pid)
|
||||
{
|
||||
// Don't write to m_psProc from a different thread
|
||||
|
@@ -63,6 +63,8 @@ public:
|
||||
void handleJdbWaiting();
|
||||
void handleJdbSettled();
|
||||
|
||||
void removeForwardPort(const QString &port);
|
||||
|
||||
signals:
|
||||
void remoteProcessStarted(Utils::Port debugServerPort, const QUrl &qmlServer, qint64 pid);
|
||||
void remoteProcessFinished(const QString &errString = QString());
|
||||
|
Reference in New Issue
Block a user