From 80eba25971185df76dfead65e2c8f196e3503b14 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Sun, 20 Oct 2024 16:52:54 +0300 Subject: [PATCH] AndroidTestRunner: check if any device is running at start Check if any or specified device is running and fail with appropriate message instead of attempting to run other adb commands that might fail with other reasons that hide the actual root cause. Change-Id: I61078ca988f381e834b41140e36b0e4a5f77714f Reviewed-by: Ville Voutilainen (cherry picked from commit d5491ec2ab5630c95c25c0e4142ddf4af398f083) Reviewed-by: Qt Cherry-pick Bot --- src/tools/androidtestrunner/main.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/tools/androidtestrunner/main.cpp b/src/tools/androidtestrunner/main.cpp index 5e867ce2f07..5bc1466b3cd 100644 --- a/src/tools/androidtestrunner/main.cpp +++ b/src/tools/androidtestrunner/main.cpp @@ -509,6 +509,20 @@ static void obtainSdkVersion() qCritical() << "Unable to obtain the SDK version of the target."; } +static QStringList runningDevices() +{ + QByteArray output; + execAdbCommand({ "devices"_L1 }, &output, false); + + QStringList devices; + for (const QByteArray &line : output.split(u'\n')) { + if (line.contains("\tdevice"_L1)) + devices.append(QString::fromUtf8(line.split(u'\t').first())); + } + + return devices; +} + static bool pullFiles() { bool ret = true; @@ -755,6 +769,16 @@ int main(int argc, char *argv[]) return 1; } + const QStringList devices = runningDevices(); + if (devices.isEmpty()) { + qCritical("No connected devices or running emulators can be found."); + return 1; + } else if (!g_options.serial.isEmpty() && !devices.contains(g_options.serial)) { + qCritical("No connected device or running emulator with serial '%s' can be found.", + qPrintable(g_options.serial)); + return 1; + } + obtainSdkVersion(); QString manifest = g_options.buildPath + "/AndroidManifest.xml"_L1;