Android: Simplify removeForwardPort()

There is no need to split the output into separate lines
and search for port number in each line afterwards.
Search for port number in the whole output instead.

Change-Id: Id020bd5a73080be30b6cef47853e027235105ae3
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Jarek Kobus
2024-07-23 06:19:53 +02:00
parent e57b635a6e
commit 6c15cc6bf9

View File

@@ -761,22 +761,9 @@ void AndroidRunnerWorker::handleJdbSettled()
void AndroidRunnerWorker::removeForwardPort(const QString &port)
{
bool found = false;
SdkToolResult result = AndroidManager::runAdbCommand({"forward", "--list"});
QString string = result.stdOut();
const auto lines = string.split('\n');
for (const QString &line : lines) {
if (line.contains(port)) {
found = true;
break;
}
}
if (found) {
QStringList removeForward{"forward", "--remove", port};
runAdb(removeForward);
}
const SdkToolResult result = AndroidManager::runAdbCommand({"forward", "--list"});
if (result.stdOut().contains(port))
runAdb({"forward", "--remove", port});
}
void AndroidRunnerWorker::onProcessIdChanged(const PidUserPair &pidUser)