Skip to content

Commit

Permalink
chore: Switch to dumpsys usage if main app activity resolves to andro…
Browse files Browse the repository at this point in the history
…id/com.android.internal.app.ResolverActivity (#750)
  • Loading branch information
mykola-mokhnach authored Jul 4, 2022
1 parent 1b2b8fc commit 80f482d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/commands/app-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { APP_STATE } from '../android-helpers';
import { errors } from 'appium/driver';

const APP_EXTENSIONS = ['.apk', '.apks'];
const RESOLVER_ACTIVITY_NAME = 'android/com.android.internal.app.ResolverActivity';

let commands = {};

Expand Down Expand Up @@ -77,6 +78,16 @@ commands.activateApp = async function activateApp (appId) {
return;
}

let activityName = await this.adb.resolveLaunchableActivity(appId);
if (activityName === RESOLVER_ACTIVITY_NAME) {
// https://github.com/appium/appium/issues/17128
this.log.debug(
`The launchable activity name of '${appId}' was resolved to '${activityName}'. ` +
`Switching the resolver to not use cmd`
);
activityName = await this.adb.resolveLaunchableActivity(appId, {preferCmd: false});
}

const stdout = await this.adb.shell([
'am', (apiLevel < 26) ? 'start' : 'start-activity',
'-a', 'android.intent.action.MAIN',
Expand All @@ -85,7 +96,7 @@ commands.activateApp = async function activateApp (appId) {
// https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_NEW_TASK
// https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
'-f', '0x10200000',
'-n', await this.adb.resolveLaunchableActivity(appId),
'-n', activityName,
]);
this.log.debug(stdout);
if (/^error:/mi.test(stdout)) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
],
"dependencies": {
"@babel/runtime": "^7.0.0",
"appium-adb": "^9.6.0",
"appium-adb": "^9.9.0",
"appium-chromedriver": "^5.0.1",
"asyncbox": "^2.8.0",
"axios": "^0.x",
Expand Down

0 comments on commit 80f482d

Please sign in to comment.