From 6dd6342864806fcb28318da38a01ce21fcb4c96a Mon Sep 17 00:00:00 2001 From: Bartlomiej Moskal Date: Wed, 13 Oct 2021 13:03:16 +0200 Subject: [PATCH] androidtestrunner: make sure that system-user is used It happens on Android Automotive emulator, that output file is in other directory. According android spec [1]: "If a default user isn't specified, each adb subcommand has a different user. The best practice is to retrieve the user ID with am get-current-user and then explicitly use --user for any command that supports it." That is the reason why output file can be found in /data/user/USER_ID/PACKAGE_NAME directory. Checking path related to current user was added as backup solution. [1]https://source.android.com/devices/tech/admin/multi-user-testing Pick-to: 6.2 Change-Id: Id7e6ddef74f4f20b7469a07bba6a71d3622c4e20 Reviewed-by: Assam Boudjelthia Reviewed-by: Qt CI Bot --- src/tools/androidtestrunner/main.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/tools/androidtestrunner/main.cpp b/src/tools/androidtestrunner/main.cpp index 3e59148cff7..aa3c390563c 100644 --- a/src/tools/androidtestrunner/main.cpp +++ b/src/tools/androidtestrunner/main.cpp @@ -420,7 +420,16 @@ static bool pullFiles() QByteArray output; if (!execCommand(QStringLiteral("%1 shell run-as %2 cat files/output.%3") .arg(g_options.adbCommand, g_options.package, it.key()), &output)) { - return false; + // Cannot find output file. Check in path related to current user + QByteArray userId; + execCommand(QStringLiteral("%1 shell cmd activity get-current-user") + .arg(g_options.adbCommand), &userId); + const QString userIdSimplified(QString::fromUtf8(userId).simplified()); + if (!execCommand(QStringLiteral("%1 shell run-as %2 --user %3 cat files/output.%4") + .arg(g_options.adbCommand, g_options.package, userIdSimplified, it.key()), + &output)) { + return false; + } } auto checkerIt = g_options.checkFiles.find(it.key()); ret = ret && checkerIt != g_options.checkFiles.end() && checkerIt.value()(output);