Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Enforce '--user 0' argument if cmd package list packages throws an access error #761

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/tools/apk-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ const RESOLVER_ACTIVITY_NAME = 'android/com.android.internal.app.ResolverActivit
*/
apkUtilsMethods.isAppInstalled = async function isAppInstalled (pkg, opts = {}) {
const {
user
user,
} = opts;

log.debug(`Getting install status for ${pkg}`);
/** @type {boolean} */
let isInstalled;
if (await this.getApiLevel() < 26) {
try {
Expand All @@ -66,7 +67,18 @@ apkUtilsMethods.isAppInstalled = async function isAppInstalled (pkg, opts = {})
if (util.hasValue(user)) {
cmd.push('--user', user);
}
const stdout = await this.shell(cmd);
/** @type {string} */
let stdout;
try {
stdout = await this.shell(cmd);
} catch (e) {
// https://github.com/appium/appium-uiautomator2-driver/issues/810
if (_.includes(e.stderr || e.stdout || e.message, 'access user') && _.isEmpty(user)) {
stdout = await this.shell([...cmd, '--user', '0']);
} else {
throw e;
}
}
isInstalled = new RegExp(`^package:${_.escapeRegExp(pkg)}$`, 'm').test(stdout);
}
log.debug(`'${pkg}' is${!isInstalled ? ' not' : ''} installed`);
Expand Down
Loading