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
|
// currently forward to same port on device and host
|
||||||
const QString port = QString("tcp:%1").arg(m_qmlServer.port());
|
const QString port = QString("tcp:%1").arg(m_qmlServer.port());
|
||||||
QStringList removeForward{{"forward", "--remove", port}};
|
QStringList removeForward{{"forward", "--remove", port}};
|
||||||
runAdb(removeForward);
|
removeForwardPort(port);
|
||||||
if (!runAdb({"forward", port, port})) {
|
if (!runAdb({"forward", port, port})) {
|
||||||
emit remoteProcessFinished(tr("Failed to forward QML debugging ports."));
|
emit remoteProcessFinished(tr("Failed to forward QML debugging ports."));
|
||||||
return;
|
return;
|
||||||
@@ -662,9 +662,10 @@ bool AndroidRunnerWorker::startDebuggerServer(const QString &packageDir,
|
|||||||
qCDebug(androidRunWorkerLog) << "Debugger process started";
|
qCDebug(androidRunWorkerLog) << "Debugger process started";
|
||||||
m_debugServerProcess->setObjectName("AndroidDebugServerProcess");
|
m_debugServerProcess->setObjectName("AndroidDebugServerProcess");
|
||||||
|
|
||||||
QStringList removeForward{"forward", "--remove", "tcp:" + m_localDebugServerPort.toString()};
|
const QString port = "tcp:" + m_localDebugServerPort.toString();
|
||||||
runAdb(removeForward);
|
const QStringList removeForward{"forward", "--remove", port};
|
||||||
if (!runAdb({"forward", "tcp:" + m_localDebugServerPort.toString(),
|
removeForwardPort(port);
|
||||||
|
if (!runAdb({"forward", port,
|
||||||
"localfilesystem:" + gdbServerSocket})) {
|
"localfilesystem:" + gdbServerSocket})) {
|
||||||
if (errorStr)
|
if (errorStr)
|
||||||
*errorStr = tr("Failed to forward C++ debugging ports.");
|
*errorStr = tr("Failed to forward C++ debugging ports.");
|
||||||
@@ -698,9 +699,10 @@ void AndroidRunnerWorker::asyncStop()
|
|||||||
|
|
||||||
void AndroidRunnerWorker::handleJdbWaiting()
|
void AndroidRunnerWorker::handleJdbWaiting()
|
||||||
{
|
{
|
||||||
QStringList removeForward{"forward", "--remove", "tcp:" + m_localJdbServerPort.toString()};
|
const QString port = "tcp:" + m_localJdbServerPort.toString();
|
||||||
runAdb(removeForward);
|
const QStringList removeForward{"forward", "--remove", port};
|
||||||
if (!runAdb({"forward", "tcp:" + m_localJdbServerPort.toString(),
|
removeForwardPort(port);
|
||||||
|
if (!runAdb({"forward", port,
|
||||||
"jdwp:" + QString::number(m_processPID)})) {
|
"jdwp:" + QString::number(m_processPID)})) {
|
||||||
emit remoteProcessFinished(tr("Failed to forward JDB debugging ports."));
|
emit remoteProcessFinished(tr("Failed to forward JDB debugging ports."));
|
||||||
return;
|
return;
|
||||||
@@ -761,6 +763,25 @@ void AndroidRunnerWorker::handleJdbSettled()
|
|||||||
emit remoteProcessFinished(tr("Cannot attach JDB to the running application."));
|
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)
|
void AndroidRunnerWorker::onProcessIdChanged(qint64 pid)
|
||||||
{
|
{
|
||||||
// Don't write to m_psProc from a different thread
|
// Don't write to m_psProc from a different thread
|
||||||
|
@@ -63,6 +63,8 @@ public:
|
|||||||
void handleJdbWaiting();
|
void handleJdbWaiting();
|
||||||
void handleJdbSettled();
|
void handleJdbSettled();
|
||||||
|
|
||||||
|
void removeForwardPort(const QString &port);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void remoteProcessStarted(Utils::Port debugServerPort, const QUrl &qmlServer, qint64 pid);
|
void remoteProcessStarted(Utils::Port debugServerPort, const QUrl &qmlServer, qint64 pid);
|
||||||
void remoteProcessFinished(const QString &errString = QString());
|
void remoteProcessFinished(const QString &errString = QString());
|
||||||
|
Reference in New Issue
Block a user