Android: Introduce devicesCommandOutput() helper and reuse it

Change-Id: I098aa17328efcf66a3fb80416e65a2f82d190edc
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Jarek Kobus
2024-05-29 12:35:23 +02:00
parent f450610a6f
commit c40dceced7
4 changed files with 12 additions and 19 deletions

View File

@@ -674,17 +674,22 @@ FilePath keytoolPath()
return openJDKBinPath().pathAppended(keytoolName).withExecutableSuffix();
}
bool isConnected(const QString &serialNumber)
QStringList devicesCommandOutput()
{
Process adbProcess;
adbProcess.setCommand({adbToolPath(), {"devices"}});
adbProcess.runBlocking();
if (adbProcess.result() != ProcessResult::FinishedWithSuccess)
return false;
return {};
// mid(1) - remove "List of devices attached" header line.
// Example output: "List of devices attached\nemulator-5554\tdevice\n\n".
const QStringList lines = adbProcess.allOutput().split('\n', Qt::SkipEmptyParts).mid(1);
return adbProcess.allOutput().split('\n', Qt::SkipEmptyParts).mid(1);
}
bool isConnected(const QString &serialNumber)
{
const QStringList lines = devicesCommandOutput();
for (const QString &line : lines) {
// skip the daemon logs
if (!line.startsWith("* daemon") && line.left(line.indexOf('\t')).trimmed() == serialNumber)