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 <userId> 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 <assam.boudjelthia@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Bartlomiej Moskal 2021-10-13 13:03:16 +02:00
parent aa82d295c8
commit 6dd6342864

View File

@ -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);