Skip to content

Commit

Permalink
fix: Tune retrieval of package launch info (#975)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Dec 27, 2024
1 parent 2db9f60 commit bbdcc18
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 40 deletions.
26 changes: 13 additions & 13 deletions lib/commands/device/common.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import semver from 'semver';
import _ from 'lodash';
import B from 'bluebird';
import path from 'node:path';
import {setMockLocationApp} from '../geolocation';
import {SETTINGS_HELPER_ID} from 'io.appium.settings';
import {hideKeyboardCompletely, initUnicodeKeyboard} from '../keyboard';
import {
createBaseADB,
prepareEmulator,
validatePackageActivityNames,
pushSettingsApp,
} from './utils';
import {adjustTimeZone} from '../time';
Expand Down Expand Up @@ -151,34 +151,34 @@ export async function createADB() {
* @returns {Promise<import('../types').ADBLaunchInfo | undefined>}
*/
export async function getLaunchInfo() {
if (!this.opts.app) {
this.log.warn('No app sent in, not parsing package/activity');
let {appPackage, appActivity, appWaitPackage, appWaitActivity, app} = this.opts;
if (appPackage && appActivity || (!app && !appPackage)) {
return;
}
let {appPackage, appActivity, appWaitPackage, appWaitActivity} = this.opts;
const {app} = this.opts;

validatePackageActivityNames.bind(this)();

if (appPackage && appActivity) {
return;
let apkPackage;
let apkActivity;
if (app) {
this.log.debug(`Parsing package and activity from the '${path.basename(app)}' file manifest`);
({apkPackage, apkActivity} = await this.adb.packageAndLaunchActivityFromManifest(app));
} else if (appPackage) {
this.log.debug(`Parsing activity from the installed '${appPackage}' package manifest`);
apkActivity = await this.adb.resolveLaunchableActivity(appPackage);
}

this.log.debug('Parsing package and activity from app manifest');
const {apkPackage, apkActivity} = await this.adb.packageAndLaunchActivityFromManifest(app);
if (apkPackage && !appPackage) {
appPackage = apkPackage;
}
if (!appWaitPackage) {
appWaitPackage = appPackage;
}
this.log.debug(`Resolved launch package/activity: ${apkPackage}/${apkActivity}`);
if (apkActivity && !appActivity) {
appActivity = apkActivity;
}
if (!appWaitActivity) {
appWaitActivity = appActivity;
}
this.log.debug(`Parsed package and activity are: ${apkPackage}/${apkActivity}`);
this.log.debug(`Resolved wait package/activity: ${appWaitPackage}/${appWaitActivity}`);
return {appPackage, appWaitPackage, appActivity, appWaitActivity};
}

Expand Down
27 changes: 0 additions & 27 deletions lib/commands/device/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,6 @@ export function requireEmulator(errMsg) {
}
}

/**
* @this {import('../../driver').AndroidDriver}
* @returns {void}
*/
export function validatePackageActivityNames() {
for (const key of ['appPackage', 'appActivity', 'appWaitPackage', 'appWaitActivity']) {
const name = this.opts[key];
if (!name) {
continue;
}

const match = /([^\w.*,])+/.exec(String(name));
if (!match) {
continue;
}

this.log.warn(
`Capability '${key}' is expected to only include latin letters, digits, underscore, dot, comma and asterisk characters.`,
);
this.log.warn(
`Current value '${name}' has non-matching character at index ${match.index}: '${String(
name,
).substring(0, match.index + 1)}'`,
);
}
}

/**
* @this {import('../../driver').AndroidDriver}
* @param {string} networkSpeed
Expand Down

0 comments on commit bbdcc18

Please sign in to comment.