appium-adb 9.10.13 → 9.10.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"apk-utils.js","names":["apkUtilsMethods","APP_INSTALL_STATE","UNKNOWN","NOT_INSTALLED","NEWER_VERSION_INSTALLED","SAME_VERSION_INSTALLED","OLDER_VERSION_INSTALLED","REMOTE_CACHE_ROOT","isAppInstalled","pkg","log","debug","installedPattern","RegExp","_","escapeRegExp","stdout","shell","isInstalled","test","e","Error","message","startUri","uri","opts","waitForLaunch","args","push","escapeShellArg","res","toLowerCase","includes","startApp","startAppOptions","activity","action","clone","replace","defaults","waitPkg","waitActivity","retry","stopApp","apiLevel","getApiLevel","cmd","buildStartCmd","intentName","optionalIntentArguments","shellOpts","isInteger","waitDuration","timeout","startsWith","waitForActivity","appDescriptor","dumpWindows","dumpsysArg","getFocusedPackageAndActivity","nullFocusedAppRe","focusedAppRe","nullCurrentFocusRe","currentFocusAppRe","focusedAppCandidates","currentFocusAppCandidates","candidates","pattern","match","exec","appPackage","trim","appActivity","length","intersectionWith","isEqual","waitForActivityOrNot","waitForStop","waitMs","splitNames","names","split","map","name","allPackages","allActivities","possibleActivityNames","oneActivity","currentPkg","join","possibleActivityPatterns","actName","conditionFunc","fullyQualifiedActivity","isActivityFound","some","p","waitForCondition","parseInt","intervalMs","act","waitForNotActivity","uninstallApk","options","info","keepData","forceStop","adbExec","installFromDevicePath","apkPathOnDevice","indexOf","cacheApk","apkPath","appHash","fs","hash","remotePath","path","posix","remoteCachedFiles","errorMarker","lsOutput","_areExtendedLsOptionsSupported","isBoolean","isString","substring","x","filter","Boolean","toHash","parse","catch","timer","timing","Timer","start","size","stat","basename","util","toReadableSizeString","getDuration","asMilliSeconds","toFixed","remoteAppsCache","LRU","max","remoteAppsCacheLimit","difference","keys","forEach","del","set","entriesToCleanup","has","slice","isEmpty","warn","install","appPath","endsWith","APKS_EXTENSION","installApks","cloneDeep","adbExecTimeout","DEFAULT_ADB_EXEC_TIMEOUT","APK_INSTALL_TIMEOUT","timeoutCapName","installArgs","buildInstallArgs","noIncremental","isIncrementalInstallSupported","installOpts","installCmd","performAppInstall","shouldCacheApp","isStreamedInstallSupported","clearCache","cacheApp","cachedAppPath","pmInstallCmdByRemotePath","output","newCachedAppPath","truncatedOutput","substr","isTestPackageOnlyError","msg","err","getApplicationInstallState","apkInfo","getApkInfo","versionCode","pkgVersionCode","versionName","pkgVersionNameStr","getPackageInfo","pkgVersionName","semver","valid","coerce","apkVersionCode","apkVersionNameStr","apkVersionName","satisfies","installOrUpgrade","enforceCurrentBuild","appState","wasUninstalled","uninstallPackage","Object","assign","extractStringsFromApk","language","out","originalAppPath","extractLanguageApk","apkStrings","configMarker","initAapt","formatConfigMarker","binaries","aapt","uniq","os","EOL","parseAaptStrings","stderr","initAapt2","aapt2","parseAapt2Strings","localPath","resolve","mkdirp","writeFile","JSON","stringify","getDeviceLanguage","getDeviceSysLanguage","getDeviceProductLanguage","getDeviceLocale","getDeviceCountry","country","getDeviceSysCountry","getDeviceProductCountry","locale","getDeviceSysLocale","getDeviceProductLocale","setDeviceLocale","validateLocale","split_locale","setDeviceLanguageCountry","ensureCurrentLocale","script","hasLanguage","hasCountry","retryInterval","curLanguage","curCountry","curLocale","localeCode","error","reconnect","ign","restartAdb","toUpperCase","setDeviceSysLocaleViaSettingApp","exists","extractBaseApk","apkReader","ApkReader","open","manifest","readManifest","parseManifest","result","versionNameMatch","versionCodeMatch","pullApk","tmpDir","packageMarker","tmpApp","pull"],"sources":["../../../lib/tools/apk-utils.js"],"sourcesContent":["import {\n buildStartCmd, APKS_EXTENSION, buildInstallArgs,\n APK_INSTALL_TIMEOUT, DEFAULT_ADB_EXEC_TIMEOUT,\n parseManifest, parseAaptStrings, parseAapt2Strings, formatConfigMarker,\n escapeShellArg,\n} from '../helpers.js';\nimport { exec } from 'teen_process';\nimport log from '../logger.js';\nimport path from 'path';\nimport _ from 'lodash';\nimport { retryInterval, waitForCondition } from 'asyncbox';\nimport { fs, util, mkdirp, timing } from '@appium/support';\nimport semver from 'semver';\nimport os from 'os';\nimport LRU from 'lru-cache';\nimport ApkReader from 'adbkit-apkreader';\n\nconst apkUtilsMethods = {};\n\napkUtilsMethods.APP_INSTALL_STATE = {\n UNKNOWN: 'unknown',\n NOT_INSTALLED: 'notInstalled',\n NEWER_VERSION_INSTALLED: 'newerVersionInstalled',\n SAME_VERSION_INSTALLED: 'sameVersionInstalled',\n OLDER_VERSION_INSTALLED: 'olderVersionInstalled',\n};\nconst REMOTE_CACHE_ROOT = '/data/local/tmp/appium_cache';\n\n\n/**\n * Check whether the particular package is present on the device under test.\n *\n * @param {string} pkg - The name of the package to check.\n * @return {boolean} True if the package is installed.\n * @throws {Error} If there was an error while detecting application state\n */\napkUtilsMethods.isAppInstalled = async function isAppInstalled (pkg) {\n log.debug(`Getting install status for ${pkg}`);\n const installedPattern = new RegExp(`^\\\\s*Package\\\\s+\\\\[${_.escapeRegExp(pkg)}\\\\][^:]+:$`, 'm');\n try {\n const stdout = await this.shell(['dumpsys', 'package', pkg]);\n const isInstalled = installedPattern.test(stdout);\n log.debug(`'${pkg}' is${!isInstalled ? ' not' : ''} installed`);\n return isInstalled;\n } catch (e) {\n throw new Error(`Error finding if '${pkg}' is installed. Original error: ${e.message}`);\n }\n};\n\n/**\n * @typedef {Object} StartUriOptions\n * @property {?boolean} waitForLaunch [true] - if `false` then adb won't wait\n * for the started activity to return the control\n */\n\n/**\n * Start the particular URI on the device under test.\n *\n * @param {string} uri - The name of URI to start.\n * @param {string} pkg - The name of the package to start the URI with.\n * @param {StartUriOptions} opts\n */\napkUtilsMethods.startUri = async function startUri (uri, pkg, opts = {}) {\n const {\n waitForLaunch = true,\n } = opts;\n\n if (!uri || !pkg) {\n throw new Error('URI and package arguments are required');\n }\n\n const args = ['am', 'start'];\n if (waitForLaunch) {\n args.push('-W');\n }\n args.push('-a', 'android.intent.action.VIEW',\n '-d', escapeShellArg(uri),\n pkg);\n\n try {\n const res = await this.shell(args);\n if (res.toLowerCase().includes('unable to resolve intent')) {\n throw new Error(res);\n }\n } catch (e) {\n throw new Error(`Error attempting to start URI. Original error: ${e}`);\n }\n};\n\n/**\n * @typedef {Object} StartAppOptions\n * @property {!string} pkg - The name of the application package\n * @property {?string} activity - The name of the main application activity.\n * This or action is required in order to be able to launch an app.\n * @property {?string} action - The name of the intent action that will launch the required app.\n * This or activity is required in order to be able to launch an app.\n * @property {?boolean} retry [true] - If this property is set to `true`\n * and the activity name does not start with '.' then the method\n * will try to add the missing dot and start the activity once more\n * if the first startup try fails.\n * @property {?boolean} stopApp [true] - Set it to `true` in order to forcefully\n * stop the activity if it is already running.\n * @property {?string} waitPkg - The name of the package to wait to on\n * startup (this only makes sense if this name is different from the one, which is set as `pkg`)\n * @property {?string} waitActivity - The name of the activity to wait to on\n * startup (this only makes sense if this name is different from the one, which is set as `activity`)\n * @property {?number} waitDuration - The number of milliseconds to wait until the\n * `waitActivity` is focused\n * @property {?string|number} user - The number of the user profile to start\n * the given activity with. The default OS user profile (usually zero) is used\n * when this property is unset\n * @property {?boolean} waitForLaunch [true] - if `false` then adb won't wait\n * for the started activity to return the control\n */\n\n/**\n * Start the particular package/activity on the device under test.\n *\n * @param {StartAppOptions} startAppOptions [{}] - Startup options mapping.\n * @return {string} The output of the corresponding adb command.\n * @throws {Error} If there is an error while executing the activity\n */\napkUtilsMethods.startApp = async function startApp (startAppOptions = {}) {\n if (!startAppOptions.pkg || !(startAppOptions.activity || startAppOptions.action)) {\n throw new Error('pkg, and activity or intent action, are required to start an application');\n }\n\n startAppOptions = _.clone(startAppOptions);\n if (startAppOptions.activity) {\n startAppOptions.activity = startAppOptions.activity.replace('$', '\\\\$');\n }\n // initializing defaults\n _.defaults(startAppOptions, {\n waitPkg: startAppOptions.pkg,\n waitForLaunch: true,\n waitActivity: false,\n retry: true,\n stopApp: true\n });\n // preventing null waitpkg\n startAppOptions.waitPkg = startAppOptions.waitPkg || startAppOptions.pkg;\n\n const apiLevel = await this.getApiLevel();\n const cmd = buildStartCmd(startAppOptions, apiLevel);\n const intentName = `${startAppOptions.action}${startAppOptions.optionalIntentArguments ? ' ' + startAppOptions.optionalIntentArguments : ''}`;\n try {\n const shellOpts = {};\n if (_.isInteger(startAppOptions.waitDuration) && startAppOptions.waitDuration >= 0) {\n shellOpts.timeout = startAppOptions.waitDuration;\n }\n const stdout = await this.shell(cmd, shellOpts);\n if (stdout.includes('Error: Activity class') && stdout.includes('does not exist')) {\n if (startAppOptions.retry && !startAppOptions.activity.startsWith('.')) {\n log.debug(`We tried to start an activity that doesn't exist, ` +\n `retrying with '.${startAppOptions.activity}' activity name`);\n startAppOptions.activity = `.${startAppOptions.activity}`;\n startAppOptions.retry = false;\n return await this.startApp(startAppOptions);\n }\n throw new Error(`Activity name '${startAppOptions.activity}' used to start the app doesn't ` +\n `exist or cannot be launched! Make sure it exists and is a launchable activity`);\n } else if (stdout.includes('Error: Intent does not match any activities') || stdout.includes('Error: Activity not started, unable to resolve Intent')) {\n throw new Error(`Activity for intent '${intentName}' used to start the app doesn't ` +\n `exist or cannot be launched! Make sure it exists and is a launchable activity`);\n } else if (stdout.includes('java.lang.SecurityException')) {\n // if the app is disabled on a real device it will throw a security exception\n throw new Error(`The permission to start '${startAppOptions.activity}' activity has been denied.` +\n `Make sure the activity/package names are correct.`);\n }\n if (startAppOptions.waitActivity) {\n await this.waitForActivity(startAppOptions.waitPkg, startAppOptions.waitActivity, startAppOptions.waitDuration);\n }\n return stdout;\n } catch (e) {\n const appDescriptor = startAppOptions.pkg || intentName;\n throw new Error(`Cannot start the '${appDescriptor}' application. ` +\n `Consider checking the driver's troubleshooting documentation. ` +\n `Original error: ${e.message}`);\n }\n};\n\n/**\n * Helper method to call `adb dumpsys window windows/displays`\n */\napkUtilsMethods.dumpWindows = async function dumpWindows () {\n const apiLevel = await this.getApiLevel();\n\n // With version 29, Android changed the dumpsys syntax\n const dumpsysArg = apiLevel >= 29 ? 'displays' : 'windows';\n const cmd = ['dumpsys', 'window', dumpsysArg];\n\n return await this.shell(cmd);\n};\n\n/**\n * @typedef {Object} PackageActivityInfo\n * @property {?string} appPackage - The name of application package,\n * for example 'com.acme.app'.\n * @property {?string} appActivity - The name of main application activity.\n */\n\n/**\n * Get the name of currently focused package and activity.\n *\n * @return {PackageActivityInfo} The mapping, where property names are 'appPackage' and 'appActivity'.\n * @throws {Error} If there is an error while parsing the data.\n */\napkUtilsMethods.getFocusedPackageAndActivity = async function getFocusedPackageAndActivity () {\n log.debug('Getting focused package and activity');\n let stdout;\n try {\n stdout = await this.dumpWindows();\n } catch (e) {\n throw new Error(\n `Could not retrieve the currently focused package and activity. Original error: ${e.message}`\n );\n }\n\n const nullFocusedAppRe = /^\\s*mFocusedApp=null/m;\n // https://regex101.com/r/xZ8vF7/1\n const focusedAppRe = new RegExp(\n '^\\\\s*mFocusedApp.+Record\\\\{.*\\\\s([^\\\\s\\\\/\\\\}]+)\\\\/([^\\\\s\\\\/\\\\}\\\\,]+)\\\\,?(\\\\s[^\\\\s\\\\/\\\\}]+)*\\\\}',\n 'mg'\n );\n const nullCurrentFocusRe = /^\\s*mCurrentFocus=null/m;\n const currentFocusAppRe = new RegExp('^\\\\s*mCurrentFocus.+\\\\{.+\\\\s([^\\\\s\\\\/]+)\\\\/([^\\\\s]+)\\\\b', 'mg');\n\n const focusedAppCandidates = [];\n const currentFocusAppCandidates = [];\n for (const [candidates, pattern] of [\n [focusedAppCandidates, focusedAppRe],\n [currentFocusAppCandidates, currentFocusAppRe]\n ]) {\n let match;\n while ((match = pattern.exec(stdout))) {\n candidates.push({\n appPackage: match[1].trim(),\n appActivity: match[2].trim()\n });\n }\n }\n if (focusedAppCandidates.length > 1 && currentFocusAppCandidates.length > 0) {\n // https://github.com/appium/appium/issues/17106\n return _.intersectionWith(focusedAppCandidates, currentFocusAppCandidates, _.isEqual)[0]\n ?? focusedAppCandidates[0];\n }\n if (focusedAppCandidates.length > 0 || currentFocusAppCandidates.length > 0) {\n return focusedAppCandidates[0] ?? currentFocusAppCandidates[0];\n }\n\n for (const pattern of [nullFocusedAppRe, nullCurrentFocusRe]) {\n if (pattern.exec(stdout)) {\n return {\n appPackage: null,\n appActivity: null\n };\n }\n }\n\n log.debug(stdout);\n throw new Error('Could not retrieve the currently focused package and activity');\n};\n\n/**\n * Wait for the given activity to be focused/non-focused.\n *\n * @param {string} pkg - The name of the package to wait for.\n * @param {string} activity - The name of the activity, belonging to that package,\n * to wait for.\n * @param {boolean} waitForStop - Whether to wait until the activity is focused (true)\n * or is not focused (false).\n * @param {number} waitMs [20000] - Number of milliseconds to wait before timeout occurs.\n * @throws {error} If timeout happens.\n */\napkUtilsMethods.waitForActivityOrNot = async function waitForActivityOrNot (pkg, activity, waitForStop, waitMs = 20000) {\n if (!pkg || !activity) {\n throw new Error('Package and activity required.');\n }\n log.debug(`Waiting up to ${waitMs}ms for activity matching pkg: '${pkg}' and ` +\n `activity: '${activity}' to${waitForStop ? ' not' : ''} be focused`);\n\n const splitNames = (names) => names.split(',').map((name) => name.trim());\n const allPackages = splitNames(pkg);\n const allActivities = splitNames(activity);\n\n const possibleActivityNames = [];\n for (const oneActivity of allActivities) {\n if (oneActivity.startsWith('.')) {\n // add the package name if activity is not full qualified\n for (const currentPkg of allPackages) {\n possibleActivityNames.push(`${currentPkg}${oneActivity}`.replace(/\\.+/g, '.'));\n }\n } else {\n // accept fully qualified activity name.\n possibleActivityNames.push(oneActivity);\n possibleActivityNames.push(`${pkg}.${oneActivity}`);\n }\n }\n log.debug(`Possible activities, to be checked: ${possibleActivityNames.map((name) => `'${name}'`).join(', ')}`);\n\n const possibleActivityPatterns = possibleActivityNames.map(\n (actName) => new RegExp(`^${actName.replace(/\\./g, '\\\\.').replace(/\\*/g, '.*?').replace(/\\$/g, '\\\\$')}$`)\n );\n\n const conditionFunc = async () => {\n let appPackage;\n let appActivity;\n try {\n ({appPackage, appActivity} = await this.getFocusedPackageAndActivity());\n } catch (e) {\n log.debug(e.message);\n return false;\n }\n if (appActivity && appPackage) {\n const fullyQualifiedActivity = appActivity.startsWith('.') ? `${appPackage}${appActivity}` : appActivity;\n log.debug(`Found package: '${appPackage}' and fully qualified activity name : '${fullyQualifiedActivity}'`);\n const isActivityFound = _.includes(allPackages, appPackage)\n && possibleActivityPatterns.some((p) => p.test(fullyQualifiedActivity));\n if ((!waitForStop && isActivityFound) || (waitForStop && !isActivityFound)) {\n return true;\n }\n }\n log.debug('Incorrect package and activity. Retrying.');\n return false;\n };\n\n try {\n await waitForCondition(conditionFunc, {\n waitMs: parseInt(waitMs, 10),\n intervalMs: 500,\n });\n } catch (e) {\n throw new Error(`${possibleActivityNames.map((name) => `'${name}'`).join(' or ')} never ${waitForStop ? 'stopped' : 'started'}. ` +\n `Consider checking the driver's troubleshooting documentation.`);\n }\n};\n\n/**\n * Wait for the given activity to be focused\n *\n * @param {string} pkg - The name of the package to wait for.\n * @param {string} activity - The name of the activity, belonging to that package,\n * to wait for.\n * @param {number} waitMs [20000] - Number of milliseconds to wait before timeout occurs.\n * @throws {error} If timeout happens.\n */\napkUtilsMethods.waitForActivity = async function waitForActivity (pkg, act, waitMs = 20000) {\n await this.waitForActivityOrNot(pkg, act, false, waitMs);\n};\n\n/**\n * Wait for the given activity to be non-focused.\n *\n * @param {string} pkg - The name of the package to wait for.\n * @param {string} activity - The name of the activity, belonging to that package,\n * to wait for.\n * @param {number} waitMs [20000] - Number of milliseconds to wait before timeout occurs.\n * @throws {error} If timeout happens.\n */\napkUtilsMethods.waitForNotActivity = async function waitForNotActivity (pkg, act, waitMs = 20000) {\n await this.waitForActivityOrNot(pkg, act, true, waitMs);\n};\n\n/**\n * @typedef {Object} UninstallOptions\n * @property {number} timeout [adbExecTimeout] - The count of milliseconds to wait until the\n * app is uninstalled.\n * @property {boolean} keepData [false] - Set to true in order to keep the\n * application data and cache folders after uninstall.\n */\n\n/**\n * Uninstall the given package from the device under test.\n *\n * @param {string} pkg - The name of the package to be uninstalled.\n * @param {?UninstallOptions} options - The set of uninstall options.\n * @return {boolean} True if the package was found on the device and\n * successfully uninstalled.\n */\napkUtilsMethods.uninstallApk = async function uninstallApk (pkg, options = {}) {\n log.debug(`Uninstalling ${pkg}`);\n if (!await this.isAppInstalled(pkg)) {\n log.info(`${pkg} was not uninstalled, because it was not present on the device`);\n return false;\n }\n\n const cmd = ['uninstall'];\n if (options.keepData) {\n cmd.push('-k');\n }\n cmd.push(pkg);\n\n let stdout;\n try {\n await this.forceStop(pkg);\n stdout = (await this.adbExec(cmd, {timeout: options.timeout})).trim();\n } catch (e) {\n throw new Error(`Unable to uninstall APK. Original error: ${e.message}`);\n }\n log.debug(`'adb ${cmd.join(' ')}' command output: ${stdout}`);\n if (stdout.includes('Success')) {\n log.info(`${pkg} was successfully uninstalled`);\n return true;\n }\n log.info(`${pkg} was not uninstalled`);\n return false;\n};\n\n/**\n * Install the package after it was pushed to the device under test.\n *\n * @param {string} apkPathOnDevice - The full path to the package on the device file system.\n * @param {object} opts [{}] - Additional exec options. See {@link https://github.com/appium/node-teen_process}\n * for more details on this parameter.\n * @throws {error} If there was a failure during application install.\n */\napkUtilsMethods.installFromDevicePath = async function installFromDevicePath (apkPathOnDevice, opts = {}) {\n let stdout = await this.shell(['pm', 'install', '-r', apkPathOnDevice], opts);\n if (stdout.indexOf('Failure') !== -1) {\n throw new Error(`Remote install failed: ${stdout}`);\n }\n};\n\n/**\n * @typedef {Object} CachingOptions\n * @property {?number} timeout [adbExecTimeout] - The count of milliseconds to wait until the\n * app is uploaded to the remote location.\n */\n\n/**\n * Caches the given APK at a remote location to speed up further APK deployments.\n *\n * @param {string} apkPath - Full path to the apk on the local FS\n * @param {?CachingOptions} options - Caching options\n * @returns {string} - Full path to the cached apk on the remote file system\n * @throws {Error} if there was a failure while caching the app\n */\napkUtilsMethods.cacheApk = async function cacheApk (apkPath, options = {}) {\n const appHash = await fs.hash(apkPath);\n const remotePath = path.posix.join(REMOTE_CACHE_ROOT, `${appHash}.apk`);\n const remoteCachedFiles = [];\n // Get current contents of the remote cache or create it for the first time\n try {\n const errorMarker = '_ERROR_';\n let lsOutput = null;\n if (this._areExtendedLsOptionsSupported === true || !_.isBoolean(this._areExtendedLsOptionsSupported)) {\n lsOutput = await this.shell([`ls -t -1 ${REMOTE_CACHE_ROOT} 2>&1 || echo ${errorMarker}`]);\n }\n if (!_.isString(lsOutput) || (lsOutput.includes(errorMarker) && !lsOutput.includes(REMOTE_CACHE_ROOT))) {\n if (!_.isBoolean(this._areExtendedLsOptionsSupported)) {\n log.debug('The current Android API does not support extended ls options. ' +\n 'Defaulting to no-options call');\n }\n lsOutput = await this.shell([`ls ${REMOTE_CACHE_ROOT} 2>&1 || echo ${errorMarker}`]);\n this._areExtendedLsOptionsSupported = false;\n } else {\n this._areExtendedLsOptionsSupported = true;\n }\n if (lsOutput.includes(errorMarker)) {\n throw new Error(lsOutput.substring(0, lsOutput.indexOf(errorMarker)));\n }\n remoteCachedFiles.push(...(\n lsOutput.split('\\n')\n .map((x) => x.trim())\n .filter(Boolean)\n ));\n } catch (e) {\n log.debug(`Got an error '${e.message.trim()}' while getting the list of files in the cache. ` +\n `Assuming the cache does not exist yet`);\n await this.shell(['mkdir', '-p', REMOTE_CACHE_ROOT]);\n }\n log.debug(`The count of applications in the cache: ${remoteCachedFiles.length}`);\n const toHash = (remotePath) => path.posix.parse(remotePath).name;\n // Push the apk to the remote cache if needed\n if (remoteCachedFiles.some((x) => toHash(x) === appHash)) {\n log.info(`The application at '${apkPath}' is already cached to '${remotePath}'`);\n // Update the application timestamp asynchronously in order to bump its position\n // in the sorted ls output\n // eslint-disable-next-line promise/prefer-await-to-then\n this.shell(['touch', '-am', remotePath]).catch(() => {});\n } else {\n log.info(`Caching the application at '${apkPath}' to '${remotePath}'`);\n const timer = new timing.Timer().start();\n await this.push(apkPath, remotePath, {timeout: options.timeout});\n const {size} = await fs.stat(apkPath);\n log.info(`The upload of '${path.basename(apkPath)}' (${util.toReadableSizeString(size)}) ` +\n `took ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`);\n }\n if (!this.remoteAppsCache) {\n this.remoteAppsCache = new LRU({\n max: this.remoteAppsCacheLimit,\n });\n }\n // Cleanup the invalid entries from the cache\n _.difference([...this.remoteAppsCache.keys()], remoteCachedFiles.map(toHash))\n .forEach((hash) => this.remoteAppsCache.del(hash));\n // Bump the cache record for the recently cached item\n this.remoteAppsCache.set(appHash, remotePath);\n // If the remote cache exceeds this.remoteAppsCacheLimit, remove the least recently used entries\n const entriesToCleanup = remoteCachedFiles\n .map((x) => path.posix.join(REMOTE_CACHE_ROOT, x))\n .filter((x) => !this.remoteAppsCache.has(toHash(x)))\n .slice(this.remoteAppsCacheLimit - [...this.remoteAppsCache.keys()].length);\n if (!_.isEmpty(entriesToCleanup)) {\n try {\n await this.shell(['rm', '-f', ...entriesToCleanup]);\n log.debug(`Deleted ${entriesToCleanup.length} expired application cache entries`);\n } catch (e) {\n log.warn(`Cannot delete ${entriesToCleanup.length} expired application cache entries. ` +\n `Original error: ${e.message}`);\n }\n }\n return remotePath;\n};\n\n/**\n * @typedef {Object} InstallOptions\n * @property {number} timeout [60000] - The count of milliseconds to wait until the\n * app is installed.\n * @property {string} timeoutCapName [androidInstallTimeout] - The timeout option name\n * users can increase the timeout.\n * @property {boolean} allowTestPackages [false] - Set to true in order to allow test\n * packages installation.\n * @property {boolean} useSdcard [false] - Set to true to install the app on sdcard\n * instead of the device memory.\n * @property {boolean} grantPermissions [false] - Set to true in order to grant all the\n * permissions requested in the application's manifest\n * automatically after the installation is completed\n * under Android 6+.\n * @property {boolean} replace [true] - Set it to false if you don't want\n * the application to be upgraded/reinstalled\n * if it is already present on the device.\n * @property {boolean} noIncremental [false] - Forcefully disables incremental installs if set to `true`.\n * Read https://developer.android.com/preview/features#incremental\n * for more details.\n */\n\n/**\n * Install the package from the local file system.\n *\n * @param {string} appPath - The full path to the local package.\n * @param {?InstallOptions} options - The set of installation options.\n * @throws {Error} If an unexpected error happens during install.\n */\napkUtilsMethods.install = async function install (appPath, options = {}) {\n if (appPath.endsWith(APKS_EXTENSION)) {\n return await this.installApks(appPath, options);\n }\n\n options = _.cloneDeep(options);\n _.defaults(options, {\n replace: true,\n timeout: this.adbExecTimeout === DEFAULT_ADB_EXEC_TIMEOUT ? APK_INSTALL_TIMEOUT : this.adbExecTimeout,\n timeoutCapName: 'androidInstallTimeout',\n });\n\n const installArgs = buildInstallArgs(await this.getApiLevel(), options);\n if (options.noIncremental && await this.isIncrementalInstallSupported()) {\n // Adb throws an error if it does not know about an arg,\n // which is the case here for older adb versions.\n installArgs.push('--no-incremental');\n }\n const installOpts = {\n timeout: options.timeout,\n timeoutCapName: options.timeoutCapName,\n };\n const installCmd = [\n 'install',\n ...installArgs,\n appPath,\n ];\n let performAppInstall = async () => await this.adbExec(installCmd, installOpts);\n // this.remoteAppsCacheLimit <= 0 means no caching should be applied\n let shouldCacheApp = this.remoteAppsCacheLimit > 0;\n if (shouldCacheApp) {\n shouldCacheApp = !(await this.isStreamedInstallSupported());\n if (!shouldCacheApp) {\n log.info(`The application at '${appPath}' will not be cached, because the device under test has ` +\n `confirmed the support of streamed installs`);\n }\n }\n if (shouldCacheApp) {\n const clearCache = async () => {\n log.info(`Clearing the cache at '${REMOTE_CACHE_ROOT}'`);\n await this.shell(['rm', '-rf', `${REMOTE_CACHE_ROOT}/*`]);\n };\n const cacheApp = async () => await this.cacheApk(appPath, {\n timeout: options.timeout,\n });\n try {\n const cachedAppPath = await cacheApp();\n performAppInstall = async () => {\n const pmInstallCmdByRemotePath = (remotePath) => [\n 'pm', 'install',\n ...installArgs,\n remotePath,\n ];\n const output = await this.shell(pmInstallCmdByRemotePath(cachedAppPath), installOpts);\n // https://github.com/appium/appium/issues/13970\n if (/\\bINSTALL_FAILED_INSUFFICIENT_STORAGE\\b/.test(output)) {\n log.warn(`There was a failure while installing '${appPath}' ` +\n `because of the insufficient device storage space`);\n await clearCache();\n log.info(`Consider decreasing the maximum amount of cached apps ` +\n `(currently ${this.remoteAppsCacheLimit}) to avoid such issues in the future`);\n const newCachedAppPath = await cacheApp();\n return await this.shell(pmInstallCmdByRemotePath(newCachedAppPath), installOpts);\n }\n return output;\n };\n } catch (e) {\n log.debug(e);\n log.warn(`There was a failure while caching '${appPath}': ${e.message}`);\n log.warn('Falling back to the default installation procedure');\n await clearCache();\n }\n }\n try {\n const timer = new timing.Timer().start();\n const output = await performAppInstall();\n log.info(`The installation of '${path.basename(appPath)}' took ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`);\n const truncatedOutput = (!_.isString(output) || output.length <= 300) ?\n output : `${output.substr(0, 150)}...${output.substr(output.length - 150)}`;\n log.debug(`Install command stdout: ${truncatedOutput}`);\n if (/\\[INSTALL[A-Z_]+FAILED[A-Z_]+\\]/.test(output)) {\n if (this.isTestPackageOnlyError(output)) {\n const msg = `Set 'allowTestPackages' capability to true in order to allow test packages installation.`;\n log.warn(msg);\n throw new Error(`${output}\\n${msg}`);\n }\n throw new Error(output);\n }\n } catch (err) {\n // on some systems this will throw an error if the app already\n // exists\n if (!err.message.includes('INSTALL_FAILED_ALREADY_EXISTS')) {\n throw err;\n }\n log.debug(`Application '${appPath}' already installed. Continuing.`);\n }\n};\n\n/**\n * Retrieves the current installation state of the particular application\n *\n * @param {string} appPath - Full path to the application\n * @param {?string} pkg - Package identifier. If omitted then the script will\n * try to extract it on its own\n * @returns {string}]One of `APP_INSTALL_STATE` constants\n */\napkUtilsMethods.getApplicationInstallState = async function getApplicationInstallState (appPath, pkg = null) {\n let apkInfo = null;\n if (!pkg) {\n apkInfo = await this.getApkInfo(appPath);\n pkg = apkInfo.name;\n }\n if (!pkg) {\n log.warn(`Cannot read the package name of '${appPath}'`);\n return this.APP_INSTALL_STATE.UNKNOWN;\n }\n\n if (!await this.isAppInstalled(pkg)) {\n log.debug(`App '${appPath}' is not installed`);\n return this.APP_INSTALL_STATE.NOT_INSTALLED;\n }\n\n const {versionCode: pkgVersionCode, versionName: pkgVersionNameStr} = await this.getPackageInfo(pkg);\n const pkgVersionName = semver.valid(semver.coerce(pkgVersionNameStr));\n if (!apkInfo) {\n apkInfo = await this.getApkInfo(appPath);\n }\n const {versionCode: apkVersionCode, versionName: apkVersionNameStr} = apkInfo;\n const apkVersionName = semver.valid(semver.coerce(apkVersionNameStr));\n\n if (!_.isInteger(apkVersionCode) || !_.isInteger(pkgVersionCode)) {\n log.warn(`Cannot read version codes of '${appPath}' and/or '${pkg}'`);\n if (!_.isString(apkVersionName) || !_.isString(pkgVersionName)) {\n log.warn(`Cannot read version names of '${appPath}' and/or '${pkg}'`);\n return this.APP_INSTALL_STATE.UNKNOWN;\n }\n }\n if (_.isInteger(apkVersionCode) && _.isInteger(pkgVersionCode)) {\n if (pkgVersionCode > apkVersionCode) {\n log.debug(`The version code of the installed '${pkg}' is greater than the application version code (${pkgVersionCode} > ${apkVersionCode})`);\n return this.APP_INSTALL_STATE.NEWER_VERSION_INSTALLED;\n }\n // Version codes might not be maintained. Check version names.\n if (pkgVersionCode === apkVersionCode) {\n if (_.isString(apkVersionName) && _.isString(pkgVersionName) && semver.satisfies(pkgVersionName, `>=${apkVersionName}`)) {\n log.debug(`The version name of the installed '${pkg}' is greater or equal to the application version name ('${pkgVersionName}' >= '${apkVersionName}')`);\n return semver.satisfies(pkgVersionName, `>${apkVersionName}`)\n ? this.APP_INSTALL_STATE.NEWER_VERSION_INSTALLED\n : this.APP_INSTALL_STATE.SAME_VERSION_INSTALLED;\n }\n if (!_.isString(apkVersionName) || !_.isString(pkgVersionName)) {\n log.debug(`The version name of the installed '${pkg}' is equal to application version name (${pkgVersionCode} === ${apkVersionCode})`);\n return this.APP_INSTALL_STATE.SAME_VERSION_INSTALLED;\n }\n }\n } else if (_.isString(apkVersionName) && _.isString(pkgVersionName) && semver.satisfies(pkgVersionName, `>=${apkVersionName}`)) {\n log.debug(`The version name of the installed '${pkg}' is greater or equal to the application version name ('${pkgVersionName}' >= '${apkVersionName}')`);\n return semver.satisfies(pkgVersionName, `>${apkVersionName}`)\n ? this.APP_INSTALL_STATE.NEWER_VERSION_INSTALLED\n : this.APP_INSTALL_STATE.SAME_VERSION_INSTALLED;\n }\n\n log.debug(`The installed '${pkg}' package is older than '${appPath}' (${pkgVersionCode} < ${apkVersionCode} or '${pkgVersionName}' < '${apkVersionName}')'`);\n return this.APP_INSTALL_STATE.OLDER_VERSION_INSTALLED;\n};\n\n/**\n * @typedef {Object} InstallOrUpgradeOptions\n * @property {number} timeout [60000] - The count of milliseconds to wait until the\n * app is installed.\n * @property {boolean} allowTestPackages [false] - Set to true in order to allow test\n * packages installation.\n * @property {boolean} useSdcard [false] - Set to true to install the app on SDCard\n * instead of the device memory.\n * @property {boolean} grantPermissions [false] - Set to true in order to grant all the\n * permissions requested in the application's manifest\n * automatically after the installation is completed\n * under Android 6+.\n * @property {boolean} enforceCurrentBuild [false] - Set to `true` in order to always prefer\n * the current build over any installed packages having\n * the same identifier\n */\n\n/**\n * @typedef {Object} InstallOrUpgradeResult\n * @property {boolean} wasUninstalled - Equals to `true` if the target app has been uninstalled\n * before being installed\n * @property {APP_INSTALL_STATE} appState - One of `adb.APP_INSTALL_STATE` states, which reflects\n * the state of the application before being installed.\n */\n\n/**\n * Install the package from the local file system or upgrade it if an older\n * version of the same package is already installed.\n *\n * @param {string} appPath - The full path to the local package.\n * @param {?string} pkg - The name of the installed package. The method will\n * perform faster if it is set.\n * @param {?InstallOrUpgradeOptions} options - Set of install options.\n * @throws {Error} If an unexpected error happens during install.\n * @returns {InstallOrUpgradeResult}\n */\napkUtilsMethods.installOrUpgrade = async function installOrUpgrade (appPath, pkg = null, options = {}) {\n if (!pkg) {\n const apkInfo = await this.getApkInfo(appPath);\n pkg = apkInfo.name;\n }\n\n const {\n enforceCurrentBuild,\n } = options;\n const appState = await this.getApplicationInstallState(appPath, pkg);\n let wasUninstalled = false;\n const uninstallPackage = async () => {\n if (!await this.uninstallApk(pkg)) {\n throw new Error(`'${pkg}' package cannot be uninstalled`);\n }\n wasUninstalled = true;\n };\n switch (appState) {\n case this.APP_INSTALL_STATE.NOT_INSTALLED:\n log.debug(`Installing '${appPath}'`);\n await this.install(appPath, Object.assign({}, options, {replace: false}));\n return {\n appState,\n wasUninstalled,\n };\n case this.APP_INSTALL_STATE.NEWER_VERSION_INSTALLED:\n if (enforceCurrentBuild) {\n log.info(`Downgrading '${pkg}' as requested`);\n await uninstallPackage();\n break;\n }\n log.debug(`There is no need to downgrade '${pkg}'`);\n return {\n appState,\n wasUninstalled,\n };\n case this.APP_INSTALL_STATE.SAME_VERSION_INSTALLED:\n if (enforceCurrentBuild) {\n break;\n }\n log.debug(`There is no need to install/upgrade '${appPath}'`);\n return {\n appState,\n wasUninstalled,\n };\n case this.APP_INSTALL_STATE.OLDER_VERSION_INSTALLED:\n log.debug(`Executing upgrade of '${appPath}'`);\n break;\n default:\n log.debug(`The current install state of '${appPath}' is unknown. Installing anyway`);\n break;\n }\n\n try {\n await this.install(appPath, Object.assign({}, options, {replace: true}));\n } catch (err) {\n log.warn(`Cannot install/upgrade '${pkg}' because of '${err.message}'. Trying full reinstall`);\n await uninstallPackage();\n await this.install(appPath, Object.assign({}, options, {replace: false}));\n }\n return {\n appState,\n wasUninstalled,\n };\n};\n\n/**\n * Extract string resources from the given package on local file system.\n *\n * @param {string} appPath - The full path to the .apk(s) package.\n * @param {?string} language - The name of the language to extract the resources for.\n * The default language is used if this equals to `null`/`undefined`\n * @param {string} out - The name of the destination folder on the local file system to\n * store the extracted file to.\n * @return {Object} A mapping object, where properties are: 'apkStrings', containing\n * parsed resource file represented as JSON object, and 'localPath',\n * containing the path to the extracted file on the local file system.\n */\napkUtilsMethods.extractStringsFromApk = async function extractStringsFromApk (appPath, language, out) {\n log.debug(`Extracting strings from for language: ${language || 'default'}`);\n const originalAppPath = appPath;\n if (appPath.endsWith(APKS_EXTENSION)) {\n appPath = await this.extractLanguageApk(appPath, language);\n }\n\n let apkStrings = {};\n let configMarker;\n try {\n await this.initAapt();\n\n configMarker = await formatConfigMarker(async () => {\n const {stdout} = await exec(this.binaries.aapt, [\n 'd', 'configurations', appPath,\n ]);\n return _.uniq(stdout.split(os.EOL));\n }, language, '(default)');\n\n const {stdout} = await exec(this.binaries.aapt, [\n 'd', '--values', 'resources', appPath,\n ]);\n apkStrings = parseAaptStrings(stdout, configMarker);\n } catch (e) {\n log.debug('Cannot extract resources using aapt. Trying aapt2. ' +\n `Original error: ${e.stderr || e.message}`);\n\n await this.initAapt2();\n\n configMarker = await formatConfigMarker(async () => {\n const {stdout} = await exec(this.binaries.aapt2, [\n 'd', 'configurations', appPath,\n ]);\n return _.uniq(stdout.split(os.EOL));\n }, language, '');\n\n try {\n const {stdout} = await exec(this.binaries.aapt2, [\n 'd', 'resources', appPath,\n ]);\n apkStrings = parseAapt2Strings(stdout, configMarker);\n } catch (e) {\n throw new Error(`Cannot extract resources from '${originalAppPath}'. ` +\n `Original error: ${e.message}`);\n }\n }\n\n if (_.isEmpty(apkStrings)) {\n log.warn(`No strings have been found in '${originalAppPath}' resources ` +\n `for '${configMarker || 'default'}' configuration`);\n } else {\n log.info(`Successfully extracted ${_.keys(apkStrings).length} strings from ` +\n `'${originalAppPath}' resources for '${configMarker || 'default'}' configuration`);\n }\n\n const localPath = path.resolve(out, 'strings.json');\n await mkdirp(out);\n await fs.writeFile(localPath, JSON.stringify(apkStrings, null, 2), 'utf-8');\n return {apkStrings, localPath};\n};\n\n/**\n * Get the language name of the device under test.\n *\n * @return {string} The name of device language.\n */\napkUtilsMethods.getDeviceLanguage = async function getDeviceLanguage () {\n let language;\n if (await this.getApiLevel() < 23) {\n language = await this.getDeviceSysLanguage();\n if (!language) {\n language = await this.getDeviceProductLanguage();\n }\n } else {\n language = (await this.getDeviceLocale()).split('-')[0];\n }\n return language;\n};\n\n/**\n * Get the country name of the device under test.\n *\n * @return {string} The name of device country.\n */\napkUtilsMethods.getDeviceCountry = async function getDeviceCountry () {\n // this method is only used in API < 23\n let country = await this.getDeviceSysCountry();\n if (!country) {\n country = await this.getDeviceProductCountry();\n }\n return country;\n};\n\n/**\n * Get the locale name of the device under test.\n *\n * @return {string} The name of device locale.\n */\napkUtilsMethods.getDeviceLocale = async function getDeviceLocale () {\n // this method is only used in API >= 23\n let locale = await this.getDeviceSysLocale();\n if (!locale) {\n locale = await this.getDeviceProductLocale();\n }\n return locale;\n};\n\n/**\n * Set the locale name of the device under test and the format of the locale is en-US, for example.\n * This method call setDeviceLanguageCountry, so, please use setDeviceLanguageCountry as possible.\n *\n * @param {string} locale - Names of the device language and the country connected with `-`. e.g. en-US.\n */\napkUtilsMethods.setDeviceLocale = async function setDeviceLocale (locale) {\n const validateLocale = new RegExp(/[a-zA-Z]+-[a-zA-Z0-9]+/);\n if (!validateLocale.test(locale)) {\n log.warn(`setDeviceLocale requires the following format: en-US or ja-JP`);\n return;\n }\n\n let split_locale = locale.split('-');\n await this.setDeviceLanguageCountry(split_locale[0], split_locale[1]);\n};\n\n/**\n * Make sure current device locale is expected or not.\n *\n * @param {string} language - Language. The language field is case insensitive, but Locale always canonicalizes to lower case.\n * @param {string} country - Country. The language field is case insensitive, but Locale always canonicalizes to lower case.\n * @param {?string} script - Script. The script field is case insensitive but Locale always canonicalizes to title case.\n *\n * @return {boolean} If current locale is language and country as arguments, return true.\n */\napkUtilsMethods.ensureCurrentLocale = async function ensureCurrentLocale (language, country, script = null) {\n const hasLanguage = _.isString(language);\n const hasCountry = _.isString(country);\n\n if (!hasLanguage && !hasCountry) {\n log.warn('ensureCurrentLocale requires language or country');\n return false;\n }\n\n // get lower case versions of the strings\n language = (language || '').toLowerCase();\n country = (country || '').toLowerCase();\n\n const apiLevel = await this.getApiLevel();\n\n return await retryInterval(5, 1000, async () => {\n try {\n if (apiLevel < 23) {\n let curLanguage, curCountry;\n if (hasLanguage) {\n curLanguage = (await this.getDeviceLanguage()).toLowerCase();\n if (!hasCountry && language === curLanguage) {\n return true;\n }\n }\n if (hasCountry) {\n curCountry = (await this.getDeviceCountry()).toLowerCase();\n if (!hasLanguage && country === curCountry) {\n return true;\n }\n }\n if (language === curLanguage && country === curCountry) {\n return true;\n }\n } else {\n const curLocale = (await this.getDeviceLocale()).toLowerCase();\n // zh-hans-cn : zh-cn\n const localeCode = script ? `${language}-${script.toLowerCase()}-${country}` : `${language}-${country}`;\n\n if (localeCode === curLocale) {\n log.debug(`Requested locale is equal to current locale: '${curLocale}'`);\n return true;\n }\n }\n return false;\n } catch (err) {\n // if there has been an error, restart adb and retry\n log.error(`Unable to check device localization: ${err.message}`);\n try {\n await this.reconnect();\n } catch (ign) {\n await this.restartAdb();\n }\n throw err;\n }\n });\n};\n\n/**\n * Set the locale name of the device under test.\n *\n * @param {string} language - Language. The language field is case insensitive, but Locale always canonicalizes to lower case.\n * format: [a-zA-Z]{2,8}. e.g. en, ja : https://developer.android.com/reference/java/util/Locale.html\n * @param {string} country - Country. The country (region) field is case insensitive, but Locale always canonicalizes to upper case.\n * format: [a-zA-Z]{2} | [0-9]{3}. e.g. US, JP : https://developer.android.com/reference/java/util/Locale.html\n * @param {?string} script - Script. The script field is case insensitive but Locale always canonicalizes to title case.\n * format: [a-zA-Z]{4}. e.g. Hans in zh-Hans-CN : https://developer.android.com/reference/java/util/Locale.html\n */\napkUtilsMethods.setDeviceLanguageCountry = async function setDeviceLanguageCountry (language, country, script = null) {\n let hasLanguage = language && _.isString(language);\n let hasCountry = country && _.isString(country);\n if (!hasLanguage || !hasCountry) {\n log.warn(`setDeviceLanguageCountry requires language and country at least`);\n log.warn(`Got language: '${language}' and country: '${country}'`);\n return;\n }\n let apiLevel = await this.getApiLevel();\n\n language = (language || '').toLowerCase();\n country = (country || '').toUpperCase();\n\n if (apiLevel < 23) {\n let curLanguage = (await this.getDeviceLanguage()).toLowerCase();\n let curCountry = (await this.getDeviceCountry()).toUpperCase();\n\n if (language !== curLanguage || country !== curCountry) {\n await this.setDeviceSysLocaleViaSettingApp(language, country);\n }\n } else {\n let curLocale = await this.getDeviceLocale();\n\n // zh-Hans-CN : zh-CN\n const localeCode = script ? `${language}-${script}-${country}` : `${language}-${country}`;\n log.debug(`Current locale: '${curLocale}'; requested locale: '${localeCode}'`);\n if (localeCode.toLowerCase() !== curLocale.toLowerCase()) {\n await this.setDeviceSysLocaleViaSettingApp(language, country, script);\n }\n }\n};\n\n/**\n * @typedef {Object} AppInfo\n * @property {string} name - Package name, for example 'com.acme.app'.\n * @property {number} versionCode - Version code.\n * @property {string} versionName - Version name, for example '1.0'.\n */\n\n/**\n * Get the package info from local apk file.\n *\n * @param {string} appPath - The full path to existing .apk(s) package on the local\n * file system.\n * @return {?AppInfo} The parsed application information.\n */\napkUtilsMethods.getApkInfo = async function getApkInfo (appPath) {\n if (!await fs.exists(appPath)) {\n throw new Error(`The file at path ${appPath} does not exist or is not accessible`);\n }\n\n if (appPath.endsWith(APKS_EXTENSION)) {\n appPath = await this.extractBaseApk(appPath);\n }\n\n try {\n const apkReader = await ApkReader.open(appPath);\n const manifest = await apkReader.readManifest();\n const {pkg, versionName, versionCode} = parseManifest(manifest);\n return {\n name: pkg,\n versionCode,\n versionName,\n };\n } catch (e) {\n log.warn(`Error '${e.message}' while getting badging info`);\n }\n return {};\n};\n\n/**\n * Get the package info from the installed application.\n *\n * @param {string} pkg - The name of the installed package.\n * @return {?AppInfo} The parsed application information.\n */\napkUtilsMethods.getPackageInfo = async function getPackageInfo (pkg) {\n log.debug(`Getting package info for '${pkg}'`);\n let result = {name: pkg};\n try {\n const stdout = await this.shell(['dumpsys', 'package', pkg]);\n const versionNameMatch = new RegExp(/versionName=([\\d+.]+)/).exec(stdout);\n if (versionNameMatch) {\n result.versionName = versionNameMatch[1];\n }\n const versionCodeMatch = new RegExp(/versionCode=(\\d+)/).exec(stdout);\n if (versionCodeMatch) {\n result.versionCode = parseInt(versionCodeMatch[1], 10);\n }\n return result;\n } catch (err) {\n log.warn(`Error '${err.message}' while dumping package info`);\n }\n return result;\n};\n\n/**\n * Fetches base.apk of the given package to the local file system\n *\n * @param {string} pkg The package identifier (must be already installed on the device)\n * @param {string} tmpDir The destination folder path\n * @returns {string} Full path to the downloaded file\n * @throws {Error} If there was an error while fetching the .apk\n */\napkUtilsMethods.pullApk = async function pullApk (pkg, tmpDir) {\n const stdout = _.trim(await this.shell(['pm', 'path', pkg]));\n const packageMarker = 'package:';\n if (!_.startsWith(stdout, packageMarker)) {\n throw new Error(`Cannot pull the .apk package for '${pkg}'. Original error: ${stdout}`);\n }\n\n const remotePath = stdout.replace(packageMarker, '');\n const tmpApp = path.resolve(tmpDir, `${pkg}.apk`);\n await this.pull(remotePath, tmpApp);\n log.debug(`Pulled app for package '${pkg}' to '${tmpApp}'`);\n return tmpApp;\n};\n\nexport { REMOTE_CACHE_ROOT };\nexport default apkUtilsMethods;\n"],"mappings":";;;;;;;;AAAA;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAMA,eAAe,GAAG,CAAC,CAAC;AAE1BA,eAAe,CAACC,iBAAiB,GAAG;EAClCC,OAAO,EAAE,SAAS;EAClBC,aAAa,EAAE,cAAc;EAC7BC,uBAAuB,EAAE,uBAAuB;EAChDC,sBAAsB,EAAE,sBAAsB;EAC9CC,uBAAuB,EAAE;AAC3B,CAAC;AACD,MAAMC,iBAAiB,GAAG,8BAA8B;;AAAC;AAUzDP,eAAe,CAACQ,cAAc,GAAG,eAAeA,cAAc,CAAEC,GAAG,EAAE;EACnEC,eAAG,CAACC,KAAK,CAAE,8BAA6BF,GAAI,EAAC,CAAC;EAC9C,MAAMG,gBAAgB,GAAG,IAAIC,MAAM,CAAE,sBAAqBC,eAAC,CAACC,YAAY,CAACN,GAAG,CAAE,YAAW,EAAE,GAAG,CAAC;EAC/F,IAAI;IACF,MAAMO,MAAM,GAAG,MAAM,IAAI,CAACC,KAAK,CAAC,CAAC,SAAS,EAAE,SAAS,EAAER,GAAG,CAAC,CAAC;IAC5D,MAAMS,WAAW,GAAGN,gBAAgB,CAACO,IAAI,CAACH,MAAM,CAAC;IACjDN,eAAG,CAACC,KAAK,CAAE,IAAG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,MAAM,GAAGF,eAAC,CAACyD,IAAI,CAAC,MAAM,IAAI,CAACtD,KAAK,CAAC,CAAC,IAAI,EAAE,MAAM,EAAER,GAAG,CAAC,CAAC,CAAC;EAC5D,MAAM8Q,aAAa,GAAG,UAAU;EAChC,IAAI,CAACzQ,eAAC,CAACwC,UAAU,CAACtC,MAAM,EAAEuQ,aAAa,CAAC,EAAE;IACxC,MAAM,IAAIlQ,KAAK,CAAE,qCAAoCZ,GAAI,sBAAqBO,MAAO,EAAC,CAAC;EACzF;EAEA,MAAMoG,UAAU,GAAGpG,MAAM,CAACsB,OAAO,CAACiP,aAAa,EAAE,EAAE,CAAC;EACpD,MAAMC,MAAM,GAAGnK,aAAI,CAACkH,OAAO,CAAC+C,MAAM,EAAG,GAAE7Q,GAAI,MAAK,CAAC;EACjD,MAAM,IAAI,CAACgR,IAAI,CAACrK,UAAU,EAAEoK,MAAM,CAAC;EACnC9Q,eAAG,CAACC,KAAK,CAAE,2BAA0BF,GAAI,SAAQ+Q,MAAO,GAAE,CAAC;EAC3D,OAAOA,MAAM;AACf,CAAC;AAAC,eAGaxR,eAAe;AAAA"}
1
+ {"version":3,"file":"apk-utils.js","names":["apkUtilsMethods","APP_INSTALL_STATE","UNKNOWN","NOT_INSTALLED","NEWER_VERSION_INSTALLED","SAME_VERSION_INSTALLED","OLDER_VERSION_INSTALLED","REMOTE_CACHE_ROOT","RESOLVER_ACTIVITY_NAME","isAppInstalled","pkg","log","debug","installedPattern","RegExp","_","escapeRegExp","stdout","shell","isInstalled","test","e","Error","message","startUri","uri","opts","waitForLaunch","args","push","escapeShellArg","res","toLowerCase","includes","startApp","startAppOptions","activity","action","clone","replace","defaults","waitPkg","waitActivity","retry","stopApp","apiLevel","getApiLevel","cmd","buildStartCmd","intentName","optionalIntentArguments","shellOpts","isInteger","waitDuration","timeout","startsWith","waitForActivity","appDescriptor","dumpWindows","dumpsysArg","getFocusedPackageAndActivity","nullFocusedAppRe","focusedAppRe","nullCurrentFocusRe","currentFocusAppRe","focusedAppCandidates","currentFocusAppCandidates","candidates","pattern","match","exec","appPackage","trim","appActivity","length","intersectionWith","isEqual","waitForActivityOrNot","waitForStop","waitMs","splitNames","names","split","map","name","allPackages","allActivities","possibleActivityNames","oneActivity","currentPkg","join","possibleActivityPatterns","actName","conditionFunc","fullyQualifiedActivity","isActivityFound","some","p","waitForCondition","parseInt","intervalMs","act","waitForNotActivity","uninstallApk","options","info","keepData","forceStop","adbExec","installFromDevicePath","apkPathOnDevice","indexOf","cacheApk","apkPath","appHash","fs","hash","remotePath","path","posix","remoteCachedFiles","errorMarker","lsOutput","_areExtendedLsOptionsSupported","isBoolean","isString","substring","x","filter","Boolean","toHash","parse","catch","timer","timing","Timer","start","size","stat","basename","util","toReadableSizeString","getDuration","asMilliSeconds","toFixed","remoteAppsCache","LRU","max","remoteAppsCacheLimit","difference","keys","forEach","del","set","entriesToCleanup","has","slice","isEmpty","warn","install","appPath","endsWith","APKS_EXTENSION","installApks","cloneDeep","adbExecTimeout","DEFAULT_ADB_EXEC_TIMEOUT","APK_INSTALL_TIMEOUT","timeoutCapName","installArgs","buildInstallArgs","noIncremental","isIncrementalInstallSupported","installOpts","installCmd","performAppInstall","shouldCacheApp","isStreamedInstallSupported","clearCache","cacheApp","cachedAppPath","pmInstallCmdByRemotePath","output","newCachedAppPath","truncatedOutput","substr","isTestPackageOnlyError","msg","err","getApplicationInstallState","apkInfo","getApkInfo","versionCode","pkgVersionCode","versionName","pkgVersionNameStr","getPackageInfo","pkgVersionName","semver","valid","coerce","apkVersionCode","apkVersionNameStr","apkVersionName","satisfies","installOrUpgrade","enforceCurrentBuild","appState","wasUninstalled","uninstallPackage","Object","assign","extractStringsFromApk","language","out","originalAppPath","extractLanguageApk","apkStrings","configMarker","initAapt","formatConfigMarker","binaries","aapt","uniq","os","EOL","parseAaptStrings","stderr","initAapt2","aapt2","parseAapt2Strings","localPath","resolve","mkdirp","writeFile","JSON","stringify","getDeviceLanguage","getDeviceSysLanguage","getDeviceProductLanguage","getDeviceLocale","getDeviceCountry","country","getDeviceSysCountry","getDeviceProductCountry","locale","getDeviceSysLocale","getDeviceProductLocale","setDeviceLocale","validateLocale","split_locale","setDeviceLanguageCountry","ensureCurrentLocale","script","hasLanguage","hasCountry","retryInterval","curLanguage","curCountry","curLocale","localeCode","error","reconnect","ign","restartAdb","toUpperCase","setDeviceSysLocaleViaSettingApp","exists","extractBaseApk","apkReader","ApkReader","open","manifest","readManifest","parseManifest","result","versionNameMatch","versionCodeMatch","pullApk","tmpDir","packageMarker","tmpApp","pull","activateApp","appId","errorAndThrow","activityName","resolveLaunchableActivity","preferCmd"],"sources":["../../../lib/tools/apk-utils.js"],"sourcesContent":["import {\n buildStartCmd, APKS_EXTENSION, buildInstallArgs,\n APK_INSTALL_TIMEOUT, DEFAULT_ADB_EXEC_TIMEOUT,\n parseManifest, parseAaptStrings, parseAapt2Strings, formatConfigMarker,\n escapeShellArg,\n} from '../helpers.js';\nimport { exec } from 'teen_process';\nimport log from '../logger.js';\nimport path from 'path';\nimport _ from 'lodash';\nimport { retryInterval, waitForCondition } from 'asyncbox';\nimport { fs, util, mkdirp, timing } from '@appium/support';\nimport semver from 'semver';\nimport os from 'os';\nimport LRU from 'lru-cache';\nimport ApkReader from 'adbkit-apkreader';\n\nconst apkUtilsMethods = {};\n\napkUtilsMethods.APP_INSTALL_STATE = {\n UNKNOWN: 'unknown',\n NOT_INSTALLED: 'notInstalled',\n NEWER_VERSION_INSTALLED: 'newerVersionInstalled',\n SAME_VERSION_INSTALLED: 'sameVersionInstalled',\n OLDER_VERSION_INSTALLED: 'olderVersionInstalled',\n};\nconst REMOTE_CACHE_ROOT = '/data/local/tmp/appium_cache';\nconst RESOLVER_ACTIVITY_NAME = 'android/com.android.internal.app.ResolverActivity';\n\n\n/**\n * Check whether the particular package is present on the device under test.\n *\n * @param {string} pkg - The name of the package to check.\n * @return {boolean} True if the package is installed.\n * @throws {Error} If there was an error while detecting application state\n */\napkUtilsMethods.isAppInstalled = async function isAppInstalled (pkg) {\n log.debug(`Getting install status for ${pkg}`);\n const installedPattern = new RegExp(`^\\\\s*Package\\\\s+\\\\[${_.escapeRegExp(pkg)}\\\\][^:]+:$`, 'm');\n try {\n const stdout = await this.shell(['dumpsys', 'package', pkg]);\n const isInstalled = installedPattern.test(stdout);\n log.debug(`'${pkg}' is${!isInstalled ? ' not' : ''} installed`);\n return isInstalled;\n } catch (e) {\n throw new Error(`Error finding if '${pkg}' is installed. Original error: ${e.message}`);\n }\n};\n\n/**\n * @typedef {Object} StartUriOptions\n * @property {?boolean} waitForLaunch [true] - if `false` then adb won't wait\n * for the started activity to return the control\n */\n\n/**\n * Start the particular URI on the device under test.\n *\n * @param {string} uri - The name of URI to start.\n * @param {string} pkg - The name of the package to start the URI with.\n * @param {StartUriOptions} opts\n */\napkUtilsMethods.startUri = async function startUri (uri, pkg, opts = {}) {\n const {\n waitForLaunch = true,\n } = opts;\n\n if (!uri || !pkg) {\n throw new Error('URI and package arguments are required');\n }\n\n const args = ['am', 'start'];\n if (waitForLaunch) {\n args.push('-W');\n }\n args.push('-a', 'android.intent.action.VIEW',\n '-d', escapeShellArg(uri),\n pkg);\n\n try {\n const res = await this.shell(args);\n if (res.toLowerCase().includes('unable to resolve intent')) {\n throw new Error(res);\n }\n } catch (e) {\n throw new Error(`Error attempting to start URI. Original error: ${e}`);\n }\n};\n\n/**\n * @typedef {Object} StartAppOptions\n * @property {!string} pkg - The name of the application package\n * @property {?string} activity - The name of the main application activity.\n * This or action is required in order to be able to launch an app.\n * @property {?string} action - The name of the intent action that will launch the required app.\n * This or activity is required in order to be able to launch an app.\n * @property {?boolean} retry [true] - If this property is set to `true`\n * and the activity name does not start with '.' then the method\n * will try to add the missing dot and start the activity once more\n * if the first startup try fails.\n * @property {?boolean} stopApp [true] - Set it to `true` in order to forcefully\n * stop the activity if it is already running.\n * @property {?string} waitPkg - The name of the package to wait to on\n * startup (this only makes sense if this name is different from the one, which is set as `pkg`)\n * @property {?string} waitActivity - The name of the activity to wait to on\n * startup (this only makes sense if this name is different from the one, which is set as `activity`)\n * @property {?number} waitDuration - The number of milliseconds to wait until the\n * `waitActivity` is focused\n * @property {?string|number} user - The number of the user profile to start\n * the given activity with. The default OS user profile (usually zero) is used\n * when this property is unset\n * @property {?boolean} waitForLaunch [true] - if `false` then adb won't wait\n * for the started activity to return the control\n */\n\n/**\n * Start the particular package/activity on the device under test.\n *\n * @param {StartAppOptions} startAppOptions [{}] - Startup options mapping.\n * @return {string} The output of the corresponding adb command.\n * @throws {Error} If there is an error while executing the activity\n */\napkUtilsMethods.startApp = async function startApp (startAppOptions = {}) {\n if (!startAppOptions.pkg || !(startAppOptions.activity || startAppOptions.action)) {\n throw new Error('pkg, and activity or intent action, are required to start an application');\n }\n\n startAppOptions = _.clone(startAppOptions);\n if (startAppOptions.activity) {\n startAppOptions.activity = startAppOptions.activity.replace('$', '\\\\$');\n }\n // initializing defaults\n _.defaults(startAppOptions, {\n waitPkg: startAppOptions.pkg,\n waitForLaunch: true,\n waitActivity: false,\n retry: true,\n stopApp: true\n });\n // preventing null waitpkg\n startAppOptions.waitPkg = startAppOptions.waitPkg || startAppOptions.pkg;\n\n const apiLevel = await this.getApiLevel();\n const cmd = buildStartCmd(startAppOptions, apiLevel);\n const intentName = `${startAppOptions.action}${startAppOptions.optionalIntentArguments ? ' ' + startAppOptions.optionalIntentArguments : ''}`;\n try {\n const shellOpts = {};\n if (_.isInteger(startAppOptions.waitDuration) && startAppOptions.waitDuration >= 0) {\n shellOpts.timeout = startAppOptions.waitDuration;\n }\n const stdout = await this.shell(cmd, shellOpts);\n if (stdout.includes('Error: Activity class') && stdout.includes('does not exist')) {\n if (startAppOptions.retry && !startAppOptions.activity.startsWith('.')) {\n log.debug(`We tried to start an activity that doesn't exist, ` +\n `retrying with '.${startAppOptions.activity}' activity name`);\n startAppOptions.activity = `.${startAppOptions.activity}`;\n startAppOptions.retry = false;\n return await this.startApp(startAppOptions);\n }\n throw new Error(`Activity name '${startAppOptions.activity}' used to start the app doesn't ` +\n `exist or cannot be launched! Make sure it exists and is a launchable activity`);\n } else if (stdout.includes('Error: Intent does not match any activities') || stdout.includes('Error: Activity not started, unable to resolve Intent')) {\n throw new Error(`Activity for intent '${intentName}' used to start the app doesn't ` +\n `exist or cannot be launched! Make sure it exists and is a launchable activity`);\n } else if (stdout.includes('java.lang.SecurityException')) {\n // if the app is disabled on a real device it will throw a security exception\n throw new Error(`The permission to start '${startAppOptions.activity}' activity has been denied.` +\n `Make sure the activity/package names are correct.`);\n }\n if (startAppOptions.waitActivity) {\n await this.waitForActivity(startAppOptions.waitPkg, startAppOptions.waitActivity, startAppOptions.waitDuration);\n }\n return stdout;\n } catch (e) {\n const appDescriptor = startAppOptions.pkg || intentName;\n throw new Error(`Cannot start the '${appDescriptor}' application. ` +\n `Consider checking the driver's troubleshooting documentation. ` +\n `Original error: ${e.message}`);\n }\n};\n\n/**\n * Helper method to call `adb dumpsys window windows/displays`\n */\napkUtilsMethods.dumpWindows = async function dumpWindows () {\n const apiLevel = await this.getApiLevel();\n\n // With version 29, Android changed the dumpsys syntax\n const dumpsysArg = apiLevel >= 29 ? 'displays' : 'windows';\n const cmd = ['dumpsys', 'window', dumpsysArg];\n\n return await this.shell(cmd);\n};\n\n/**\n * @typedef {Object} PackageActivityInfo\n * @property {?string} appPackage - The name of application package,\n * for example 'com.acme.app'.\n * @property {?string} appActivity - The name of main application activity.\n */\n\n/**\n * Get the name of currently focused package and activity.\n *\n * @return {PackageActivityInfo} The mapping, where property names are 'appPackage' and 'appActivity'.\n * @throws {Error} If there is an error while parsing the data.\n */\napkUtilsMethods.getFocusedPackageAndActivity = async function getFocusedPackageAndActivity () {\n log.debug('Getting focused package and activity');\n let stdout;\n try {\n stdout = await this.dumpWindows();\n } catch (e) {\n throw new Error(\n `Could not retrieve the currently focused package and activity. Original error: ${e.message}`\n );\n }\n\n const nullFocusedAppRe = /^\\s*mFocusedApp=null/m;\n // https://regex101.com/r/xZ8vF7/1\n const focusedAppRe = new RegExp(\n '^\\\\s*mFocusedApp.+Record\\\\{.*\\\\s([^\\\\s\\\\/\\\\}]+)\\\\/([^\\\\s\\\\/\\\\}\\\\,]+)\\\\,?(\\\\s[^\\\\s\\\\/\\\\}]+)*\\\\}',\n 'mg'\n );\n const nullCurrentFocusRe = /^\\s*mCurrentFocus=null/m;\n const currentFocusAppRe = new RegExp('^\\\\s*mCurrentFocus.+\\\\{.+\\\\s([^\\\\s\\\\/]+)\\\\/([^\\\\s]+)\\\\b', 'mg');\n\n const focusedAppCandidates = [];\n const currentFocusAppCandidates = [];\n for (const [candidates, pattern] of [\n [focusedAppCandidates, focusedAppRe],\n [currentFocusAppCandidates, currentFocusAppRe]\n ]) {\n let match;\n while ((match = pattern.exec(stdout))) {\n candidates.push({\n appPackage: match[1].trim(),\n appActivity: match[2].trim()\n });\n }\n }\n if (focusedAppCandidates.length > 1 && currentFocusAppCandidates.length > 0) {\n // https://github.com/appium/appium/issues/17106\n return _.intersectionWith(focusedAppCandidates, currentFocusAppCandidates, _.isEqual)[0]\n ?? focusedAppCandidates[0];\n }\n if (focusedAppCandidates.length > 0 || currentFocusAppCandidates.length > 0) {\n return focusedAppCandidates[0] ?? currentFocusAppCandidates[0];\n }\n\n for (const pattern of [nullFocusedAppRe, nullCurrentFocusRe]) {\n if (pattern.exec(stdout)) {\n return {\n appPackage: null,\n appActivity: null\n };\n }\n }\n\n log.debug(stdout);\n throw new Error('Could not retrieve the currently focused package and activity');\n};\n\n/**\n * Wait for the given activity to be focused/non-focused.\n *\n * @param {string} pkg - The name of the package to wait for.\n * @param {string} activity - The name of the activity, belonging to that package,\n * to wait for.\n * @param {boolean} waitForStop - Whether to wait until the activity is focused (true)\n * or is not focused (false).\n * @param {number} waitMs [20000] - Number of milliseconds to wait before timeout occurs.\n * @throws {error} If timeout happens.\n */\napkUtilsMethods.waitForActivityOrNot = async function waitForActivityOrNot (pkg, activity, waitForStop, waitMs = 20000) {\n if (!pkg || !activity) {\n throw new Error('Package and activity required.');\n }\n log.debug(`Waiting up to ${waitMs}ms for activity matching pkg: '${pkg}' and ` +\n `activity: '${activity}' to${waitForStop ? ' not' : ''} be focused`);\n\n const splitNames = (names) => names.split(',').map((name) => name.trim());\n const allPackages = splitNames(pkg);\n const allActivities = splitNames(activity);\n\n const possibleActivityNames = [];\n for (const oneActivity of allActivities) {\n if (oneActivity.startsWith('.')) {\n // add the package name if activity is not full qualified\n for (const currentPkg of allPackages) {\n possibleActivityNames.push(`${currentPkg}${oneActivity}`.replace(/\\.+/g, '.'));\n }\n } else {\n // accept fully qualified activity name.\n possibleActivityNames.push(oneActivity);\n possibleActivityNames.push(`${pkg}.${oneActivity}`);\n }\n }\n log.debug(`Possible activities, to be checked: ${possibleActivityNames.map((name) => `'${name}'`).join(', ')}`);\n\n const possibleActivityPatterns = possibleActivityNames.map(\n (actName) => new RegExp(`^${actName.replace(/\\./g, '\\\\.').replace(/\\*/g, '.*?').replace(/\\$/g, '\\\\$')}$`)\n );\n\n const conditionFunc = async () => {\n let appPackage;\n let appActivity;\n try {\n ({appPackage, appActivity} = await this.getFocusedPackageAndActivity());\n } catch (e) {\n log.debug(e.message);\n return false;\n }\n if (appActivity && appPackage) {\n const fullyQualifiedActivity = appActivity.startsWith('.') ? `${appPackage}${appActivity}` : appActivity;\n log.debug(`Found package: '${appPackage}' and fully qualified activity name : '${fullyQualifiedActivity}'`);\n const isActivityFound = _.includes(allPackages, appPackage)\n && possibleActivityPatterns.some((p) => p.test(fullyQualifiedActivity));\n if ((!waitForStop && isActivityFound) || (waitForStop && !isActivityFound)) {\n return true;\n }\n }\n log.debug('Incorrect package and activity. Retrying.');\n return false;\n };\n\n try {\n await waitForCondition(conditionFunc, {\n waitMs: parseInt(waitMs, 10),\n intervalMs: 500,\n });\n } catch (e) {\n throw new Error(`${possibleActivityNames.map((name) => `'${name}'`).join(' or ')} never ${waitForStop ? 'stopped' : 'started'}. ` +\n `Consider checking the driver's troubleshooting documentation.`);\n }\n};\n\n/**\n * Wait for the given activity to be focused\n *\n * @param {string} pkg - The name of the package to wait for.\n * @param {string} activity - The name of the activity, belonging to that package,\n * to wait for.\n * @param {number} waitMs [20000] - Number of milliseconds to wait before timeout occurs.\n * @throws {error} If timeout happens.\n */\napkUtilsMethods.waitForActivity = async function waitForActivity (pkg, act, waitMs = 20000) {\n await this.waitForActivityOrNot(pkg, act, false, waitMs);\n};\n\n/**\n * Wait for the given activity to be non-focused.\n *\n * @param {string} pkg - The name of the package to wait for.\n * @param {string} activity - The name of the activity, belonging to that package,\n * to wait for.\n * @param {number} waitMs [20000] - Number of milliseconds to wait before timeout occurs.\n * @throws {error} If timeout happens.\n */\napkUtilsMethods.waitForNotActivity = async function waitForNotActivity (pkg, act, waitMs = 20000) {\n await this.waitForActivityOrNot(pkg, act, true, waitMs);\n};\n\n/**\n * @typedef {Object} UninstallOptions\n * @property {number} timeout [adbExecTimeout] - The count of milliseconds to wait until the\n * app is uninstalled.\n * @property {boolean} keepData [false] - Set to true in order to keep the\n * application data and cache folders after uninstall.\n */\n\n/**\n * Uninstall the given package from the device under test.\n *\n * @param {string} pkg - The name of the package to be uninstalled.\n * @param {?UninstallOptions} options - The set of uninstall options.\n * @return {boolean} True if the package was found on the device and\n * successfully uninstalled.\n */\napkUtilsMethods.uninstallApk = async function uninstallApk (pkg, options = {}) {\n log.debug(`Uninstalling ${pkg}`);\n if (!await this.isAppInstalled(pkg)) {\n log.info(`${pkg} was not uninstalled, because it was not present on the device`);\n return false;\n }\n\n const cmd = ['uninstall'];\n if (options.keepData) {\n cmd.push('-k');\n }\n cmd.push(pkg);\n\n let stdout;\n try {\n await this.forceStop(pkg);\n stdout = (await this.adbExec(cmd, {timeout: options.timeout})).trim();\n } catch (e) {\n throw new Error(`Unable to uninstall APK. Original error: ${e.message}`);\n }\n log.debug(`'adb ${cmd.join(' ')}' command output: ${stdout}`);\n if (stdout.includes('Success')) {\n log.info(`${pkg} was successfully uninstalled`);\n return true;\n }\n log.info(`${pkg} was not uninstalled`);\n return false;\n};\n\n/**\n * Install the package after it was pushed to the device under test.\n *\n * @param {string} apkPathOnDevice - The full path to the package on the device file system.\n * @param {object} opts [{}] - Additional exec options. See {@link https://github.com/appium/node-teen_process}\n * for more details on this parameter.\n * @throws {error} If there was a failure during application install.\n */\napkUtilsMethods.installFromDevicePath = async function installFromDevicePath (apkPathOnDevice, opts = {}) {\n let stdout = await this.shell(['pm', 'install', '-r', apkPathOnDevice], opts);\n if (stdout.indexOf('Failure') !== -1) {\n throw new Error(`Remote install failed: ${stdout}`);\n }\n};\n\n/**\n * @typedef {Object} CachingOptions\n * @property {?number} timeout [adbExecTimeout] - The count of milliseconds to wait until the\n * app is uploaded to the remote location.\n */\n\n/**\n * Caches the given APK at a remote location to speed up further APK deployments.\n *\n * @param {string} apkPath - Full path to the apk on the local FS\n * @param {?CachingOptions} options - Caching options\n * @returns {string} - Full path to the cached apk on the remote file system\n * @throws {Error} if there was a failure while caching the app\n */\napkUtilsMethods.cacheApk = async function cacheApk (apkPath, options = {}) {\n const appHash = await fs.hash(apkPath);\n const remotePath = path.posix.join(REMOTE_CACHE_ROOT, `${appHash}.apk`);\n const remoteCachedFiles = [];\n // Get current contents of the remote cache or create it for the first time\n try {\n const errorMarker = '_ERROR_';\n let lsOutput = null;\n if (this._areExtendedLsOptionsSupported === true || !_.isBoolean(this._areExtendedLsOptionsSupported)) {\n lsOutput = await this.shell([`ls -t -1 ${REMOTE_CACHE_ROOT} 2>&1 || echo ${errorMarker}`]);\n }\n if (!_.isString(lsOutput) || (lsOutput.includes(errorMarker) && !lsOutput.includes(REMOTE_CACHE_ROOT))) {\n if (!_.isBoolean(this._areExtendedLsOptionsSupported)) {\n log.debug('The current Android API does not support extended ls options. ' +\n 'Defaulting to no-options call');\n }\n lsOutput = await this.shell([`ls ${REMOTE_CACHE_ROOT} 2>&1 || echo ${errorMarker}`]);\n this._areExtendedLsOptionsSupported = false;\n } else {\n this._areExtendedLsOptionsSupported = true;\n }\n if (lsOutput.includes(errorMarker)) {\n throw new Error(lsOutput.substring(0, lsOutput.indexOf(errorMarker)));\n }\n remoteCachedFiles.push(...(\n lsOutput.split('\\n')\n .map((x) => x.trim())\n .filter(Boolean)\n ));\n } catch (e) {\n log.debug(`Got an error '${e.message.trim()}' while getting the list of files in the cache. ` +\n `Assuming the cache does not exist yet`);\n await this.shell(['mkdir', '-p', REMOTE_CACHE_ROOT]);\n }\n log.debug(`The count of applications in the cache: ${remoteCachedFiles.length}`);\n const toHash = (remotePath) => path.posix.parse(remotePath).name;\n // Push the apk to the remote cache if needed\n if (remoteCachedFiles.some((x) => toHash(x) === appHash)) {\n log.info(`The application at '${apkPath}' is already cached to '${remotePath}'`);\n // Update the application timestamp asynchronously in order to bump its position\n // in the sorted ls output\n // eslint-disable-next-line promise/prefer-await-to-then\n this.shell(['touch', '-am', remotePath]).catch(() => {});\n } else {\n log.info(`Caching the application at '${apkPath}' to '${remotePath}'`);\n const timer = new timing.Timer().start();\n await this.push(apkPath, remotePath, {timeout: options.timeout});\n const {size} = await fs.stat(apkPath);\n log.info(`The upload of '${path.basename(apkPath)}' (${util.toReadableSizeString(size)}) ` +\n `took ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`);\n }\n if (!this.remoteAppsCache) {\n this.remoteAppsCache = new LRU({\n max: this.remoteAppsCacheLimit,\n });\n }\n // Cleanup the invalid entries from the cache\n _.difference([...this.remoteAppsCache.keys()], remoteCachedFiles.map(toHash))\n .forEach((hash) => this.remoteAppsCache.del(hash));\n // Bump the cache record for the recently cached item\n this.remoteAppsCache.set(appHash, remotePath);\n // If the remote cache exceeds this.remoteAppsCacheLimit, remove the least recently used entries\n const entriesToCleanup = remoteCachedFiles\n .map((x) => path.posix.join(REMOTE_CACHE_ROOT, x))\n .filter((x) => !this.remoteAppsCache.has(toHash(x)))\n .slice(this.remoteAppsCacheLimit - [...this.remoteAppsCache.keys()].length);\n if (!_.isEmpty(entriesToCleanup)) {\n try {\n await this.shell(['rm', '-f', ...entriesToCleanup]);\n log.debug(`Deleted ${entriesToCleanup.length} expired application cache entries`);\n } catch (e) {\n log.warn(`Cannot delete ${entriesToCleanup.length} expired application cache entries. ` +\n `Original error: ${e.message}`);\n }\n }\n return remotePath;\n};\n\n/**\n * @typedef {Object} InstallOptions\n * @property {number} timeout [60000] - The count of milliseconds to wait until the\n * app is installed.\n * @property {string} timeoutCapName [androidInstallTimeout] - The timeout option name\n * users can increase the timeout.\n * @property {boolean} allowTestPackages [false] - Set to true in order to allow test\n * packages installation.\n * @property {boolean} useSdcard [false] - Set to true to install the app on sdcard\n * instead of the device memory.\n * @property {boolean} grantPermissions [false] - Set to true in order to grant all the\n * permissions requested in the application's manifest\n * automatically after the installation is completed\n * under Android 6+.\n * @property {boolean} replace [true] - Set it to false if you don't want\n * the application to be upgraded/reinstalled\n * if it is already present on the device.\n * @property {boolean} noIncremental [false] - Forcefully disables incremental installs if set to `true`.\n * Read https://developer.android.com/preview/features#incremental\n * for more details.\n */\n\n/**\n * Install the package from the local file system.\n *\n * @param {string} appPath - The full path to the local package.\n * @param {?InstallOptions} options - The set of installation options.\n * @throws {Error} If an unexpected error happens during install.\n */\napkUtilsMethods.install = async function install (appPath, options = {}) {\n if (appPath.endsWith(APKS_EXTENSION)) {\n return await this.installApks(appPath, options);\n }\n\n options = _.cloneDeep(options);\n _.defaults(options, {\n replace: true,\n timeout: this.adbExecTimeout === DEFAULT_ADB_EXEC_TIMEOUT ? APK_INSTALL_TIMEOUT : this.adbExecTimeout,\n timeoutCapName: 'androidInstallTimeout',\n });\n\n const installArgs = buildInstallArgs(await this.getApiLevel(), options);\n if (options.noIncremental && await this.isIncrementalInstallSupported()) {\n // Adb throws an error if it does not know about an arg,\n // which is the case here for older adb versions.\n installArgs.push('--no-incremental');\n }\n const installOpts = {\n timeout: options.timeout,\n timeoutCapName: options.timeoutCapName,\n };\n const installCmd = [\n 'install',\n ...installArgs,\n appPath,\n ];\n let performAppInstall = async () => await this.adbExec(installCmd, installOpts);\n // this.remoteAppsCacheLimit <= 0 means no caching should be applied\n let shouldCacheApp = this.remoteAppsCacheLimit > 0;\n if (shouldCacheApp) {\n shouldCacheApp = !(await this.isStreamedInstallSupported());\n if (!shouldCacheApp) {\n log.info(`The application at '${appPath}' will not be cached, because the device under test has ` +\n `confirmed the support of streamed installs`);\n }\n }\n if (shouldCacheApp) {\n const clearCache = async () => {\n log.info(`Clearing the cache at '${REMOTE_CACHE_ROOT}'`);\n await this.shell(['rm', '-rf', `${REMOTE_CACHE_ROOT}/*`]);\n };\n const cacheApp = async () => await this.cacheApk(appPath, {\n timeout: options.timeout,\n });\n try {\n const cachedAppPath = await cacheApp();\n performAppInstall = async () => {\n const pmInstallCmdByRemotePath = (remotePath) => [\n 'pm', 'install',\n ...installArgs,\n remotePath,\n ];\n const output = await this.shell(pmInstallCmdByRemotePath(cachedAppPath), installOpts);\n // https://github.com/appium/appium/issues/13970\n if (/\\bINSTALL_FAILED_INSUFFICIENT_STORAGE\\b/.test(output)) {\n log.warn(`There was a failure while installing '${appPath}' ` +\n `because of the insufficient device storage space`);\n await clearCache();\n log.info(`Consider decreasing the maximum amount of cached apps ` +\n `(currently ${this.remoteAppsCacheLimit}) to avoid such issues in the future`);\n const newCachedAppPath = await cacheApp();\n return await this.shell(pmInstallCmdByRemotePath(newCachedAppPath), installOpts);\n }\n return output;\n };\n } catch (e) {\n log.debug(e);\n log.warn(`There was a failure while caching '${appPath}': ${e.message}`);\n log.warn('Falling back to the default installation procedure');\n await clearCache();\n }\n }\n try {\n const timer = new timing.Timer().start();\n const output = await performAppInstall();\n log.info(`The installation of '${path.basename(appPath)}' took ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`);\n const truncatedOutput = (!_.isString(output) || output.length <= 300) ?\n output : `${output.substr(0, 150)}...${output.substr(output.length - 150)}`;\n log.debug(`Install command stdout: ${truncatedOutput}`);\n if (/\\[INSTALL[A-Z_]+FAILED[A-Z_]+\\]/.test(output)) {\n if (this.isTestPackageOnlyError(output)) {\n const msg = `Set 'allowTestPackages' capability to true in order to allow test packages installation.`;\n log.warn(msg);\n throw new Error(`${output}\\n${msg}`);\n }\n throw new Error(output);\n }\n } catch (err) {\n // on some systems this will throw an error if the app already\n // exists\n if (!err.message.includes('INSTALL_FAILED_ALREADY_EXISTS')) {\n throw err;\n }\n log.debug(`Application '${appPath}' already installed. Continuing.`);\n }\n};\n\n/**\n * Retrieves the current installation state of the particular application\n *\n * @param {string} appPath - Full path to the application\n * @param {?string} pkg - Package identifier. If omitted then the script will\n * try to extract it on its own\n * @returns {string}]One of `APP_INSTALL_STATE` constants\n */\napkUtilsMethods.getApplicationInstallState = async function getApplicationInstallState (appPath, pkg = null) {\n let apkInfo = null;\n if (!pkg) {\n apkInfo = await this.getApkInfo(appPath);\n pkg = apkInfo.name;\n }\n if (!pkg) {\n log.warn(`Cannot read the package name of '${appPath}'`);\n return this.APP_INSTALL_STATE.UNKNOWN;\n }\n\n if (!await this.isAppInstalled(pkg)) {\n log.debug(`App '${appPath}' is not installed`);\n return this.APP_INSTALL_STATE.NOT_INSTALLED;\n }\n\n const {versionCode: pkgVersionCode, versionName: pkgVersionNameStr} = await this.getPackageInfo(pkg);\n const pkgVersionName = semver.valid(semver.coerce(pkgVersionNameStr));\n if (!apkInfo) {\n apkInfo = await this.getApkInfo(appPath);\n }\n const {versionCode: apkVersionCode, versionName: apkVersionNameStr} = apkInfo;\n const apkVersionName = semver.valid(semver.coerce(apkVersionNameStr));\n\n if (!_.isInteger(apkVersionCode) || !_.isInteger(pkgVersionCode)) {\n log.warn(`Cannot read version codes of '${appPath}' and/or '${pkg}'`);\n if (!_.isString(apkVersionName) || !_.isString(pkgVersionName)) {\n log.warn(`Cannot read version names of '${appPath}' and/or '${pkg}'`);\n return this.APP_INSTALL_STATE.UNKNOWN;\n }\n }\n if (_.isInteger(apkVersionCode) && _.isInteger(pkgVersionCode)) {\n if (pkgVersionCode > apkVersionCode) {\n log.debug(`The version code of the installed '${pkg}' is greater than the application version code (${pkgVersionCode} > ${apkVersionCode})`);\n return this.APP_INSTALL_STATE.NEWER_VERSION_INSTALLED;\n }\n // Version codes might not be maintained. Check version names.\n if (pkgVersionCode === apkVersionCode) {\n if (_.isString(apkVersionName) && _.isString(pkgVersionName) && semver.satisfies(pkgVersionName, `>=${apkVersionName}`)) {\n log.debug(`The version name of the installed '${pkg}' is greater or equal to the application version name ('${pkgVersionName}' >= '${apkVersionName}')`);\n return semver.satisfies(pkgVersionName, `>${apkVersionName}`)\n ? this.APP_INSTALL_STATE.NEWER_VERSION_INSTALLED\n : this.APP_INSTALL_STATE.SAME_VERSION_INSTALLED;\n }\n if (!_.isString(apkVersionName) || !_.isString(pkgVersionName)) {\n log.debug(`The version name of the installed '${pkg}' is equal to application version name (${pkgVersionCode} === ${apkVersionCode})`);\n return this.APP_INSTALL_STATE.SAME_VERSION_INSTALLED;\n }\n }\n } else if (_.isString(apkVersionName) && _.isString(pkgVersionName) && semver.satisfies(pkgVersionName, `>=${apkVersionName}`)) {\n log.debug(`The version name of the installed '${pkg}' is greater or equal to the application version name ('${pkgVersionName}' >= '${apkVersionName}')`);\n return semver.satisfies(pkgVersionName, `>${apkVersionName}`)\n ? this.APP_INSTALL_STATE.NEWER_VERSION_INSTALLED\n : this.APP_INSTALL_STATE.SAME_VERSION_INSTALLED;\n }\n\n log.debug(`The installed '${pkg}' package is older than '${appPath}' (${pkgVersionCode} < ${apkVersionCode} or '${pkgVersionName}' < '${apkVersionName}')'`);\n return this.APP_INSTALL_STATE.OLDER_VERSION_INSTALLED;\n};\n\n/**\n * @typedef {Object} InstallOrUpgradeOptions\n * @property {number} timeout [60000] - The count of milliseconds to wait until the\n * app is installed.\n * @property {boolean} allowTestPackages [false] - Set to true in order to allow test\n * packages installation.\n * @property {boolean} useSdcard [false] - Set to true to install the app on SDCard\n * instead of the device memory.\n * @property {boolean} grantPermissions [false] - Set to true in order to grant all the\n * permissions requested in the application's manifest\n * automatically after the installation is completed\n * under Android 6+.\n * @property {boolean} enforceCurrentBuild [false] - Set to `true` in order to always prefer\n * the current build over any installed packages having\n * the same identifier\n */\n\n/**\n * @typedef {Object} InstallOrUpgradeResult\n * @property {boolean} wasUninstalled - Equals to `true` if the target app has been uninstalled\n * before being installed\n * @property {APP_INSTALL_STATE} appState - One of `adb.APP_INSTALL_STATE` states, which reflects\n * the state of the application before being installed.\n */\n\n/**\n * Install the package from the local file system or upgrade it if an older\n * version of the same package is already installed.\n *\n * @param {string} appPath - The full path to the local package.\n * @param {?string} pkg - The name of the installed package. The method will\n * perform faster if it is set.\n * @param {?InstallOrUpgradeOptions} options - Set of install options.\n * @throws {Error} If an unexpected error happens during install.\n * @returns {InstallOrUpgradeResult}\n */\napkUtilsMethods.installOrUpgrade = async function installOrUpgrade (appPath, pkg = null, options = {}) {\n if (!pkg) {\n const apkInfo = await this.getApkInfo(appPath);\n pkg = apkInfo.name;\n }\n\n const {\n enforceCurrentBuild,\n } = options;\n const appState = await this.getApplicationInstallState(appPath, pkg);\n let wasUninstalled = false;\n const uninstallPackage = async () => {\n if (!await this.uninstallApk(pkg)) {\n throw new Error(`'${pkg}' package cannot be uninstalled`);\n }\n wasUninstalled = true;\n };\n switch (appState) {\n case this.APP_INSTALL_STATE.NOT_INSTALLED:\n log.debug(`Installing '${appPath}'`);\n await this.install(appPath, Object.assign({}, options, {replace: false}));\n return {\n appState,\n wasUninstalled,\n };\n case this.APP_INSTALL_STATE.NEWER_VERSION_INSTALLED:\n if (enforceCurrentBuild) {\n log.info(`Downgrading '${pkg}' as requested`);\n await uninstallPackage();\n break;\n }\n log.debug(`There is no need to downgrade '${pkg}'`);\n return {\n appState,\n wasUninstalled,\n };\n case this.APP_INSTALL_STATE.SAME_VERSION_INSTALLED:\n if (enforceCurrentBuild) {\n break;\n }\n log.debug(`There is no need to install/upgrade '${appPath}'`);\n return {\n appState,\n wasUninstalled,\n };\n case this.APP_INSTALL_STATE.OLDER_VERSION_INSTALLED:\n log.debug(`Executing upgrade of '${appPath}'`);\n break;\n default:\n log.debug(`The current install state of '${appPath}' is unknown. Installing anyway`);\n break;\n }\n\n try {\n await this.install(appPath, Object.assign({}, options, {replace: true}));\n } catch (err) {\n log.warn(`Cannot install/upgrade '${pkg}' because of '${err.message}'. Trying full reinstall`);\n await uninstallPackage();\n await this.install(appPath, Object.assign({}, options, {replace: false}));\n }\n return {\n appState,\n wasUninstalled,\n };\n};\n\n/**\n * Extract string resources from the given package on local file system.\n *\n * @param {string} appPath - The full path to the .apk(s) package.\n * @param {?string} language - The name of the language to extract the resources for.\n * The default language is used if this equals to `null`/`undefined`\n * @param {string} out - The name of the destination folder on the local file system to\n * store the extracted file to.\n * @return {Object} A mapping object, where properties are: 'apkStrings', containing\n * parsed resource file represented as JSON object, and 'localPath',\n * containing the path to the extracted file on the local file system.\n */\napkUtilsMethods.extractStringsFromApk = async function extractStringsFromApk (appPath, language, out) {\n log.debug(`Extracting strings from for language: ${language || 'default'}`);\n const originalAppPath = appPath;\n if (appPath.endsWith(APKS_EXTENSION)) {\n appPath = await this.extractLanguageApk(appPath, language);\n }\n\n let apkStrings = {};\n let configMarker;\n try {\n await this.initAapt();\n\n configMarker = await formatConfigMarker(async () => {\n const {stdout} = await exec(this.binaries.aapt, [\n 'd', 'configurations', appPath,\n ]);\n return _.uniq(stdout.split(os.EOL));\n }, language, '(default)');\n\n const {stdout} = await exec(this.binaries.aapt, [\n 'd', '--values', 'resources', appPath,\n ]);\n apkStrings = parseAaptStrings(stdout, configMarker);\n } catch (e) {\n log.debug('Cannot extract resources using aapt. Trying aapt2. ' +\n `Original error: ${e.stderr || e.message}`);\n\n await this.initAapt2();\n\n configMarker = await formatConfigMarker(async () => {\n const {stdout} = await exec(this.binaries.aapt2, [\n 'd', 'configurations', appPath,\n ]);\n return _.uniq(stdout.split(os.EOL));\n }, language, '');\n\n try {\n const {stdout} = await exec(this.binaries.aapt2, [\n 'd', 'resources', appPath,\n ]);\n apkStrings = parseAapt2Strings(stdout, configMarker);\n } catch (e) {\n throw new Error(`Cannot extract resources from '${originalAppPath}'. ` +\n `Original error: ${e.message}`);\n }\n }\n\n if (_.isEmpty(apkStrings)) {\n log.warn(`No strings have been found in '${originalAppPath}' resources ` +\n `for '${configMarker || 'default'}' configuration`);\n } else {\n log.info(`Successfully extracted ${_.keys(apkStrings).length} strings from ` +\n `'${originalAppPath}' resources for '${configMarker || 'default'}' configuration`);\n }\n\n const localPath = path.resolve(out, 'strings.json');\n await mkdirp(out);\n await fs.writeFile(localPath, JSON.stringify(apkStrings, null, 2), 'utf-8');\n return {apkStrings, localPath};\n};\n\n/**\n * Get the language name of the device under test.\n *\n * @return {string} The name of device language.\n */\napkUtilsMethods.getDeviceLanguage = async function getDeviceLanguage () {\n let language;\n if (await this.getApiLevel() < 23) {\n language = await this.getDeviceSysLanguage();\n if (!language) {\n language = await this.getDeviceProductLanguage();\n }\n } else {\n language = (await this.getDeviceLocale()).split('-')[0];\n }\n return language;\n};\n\n/**\n * Get the country name of the device under test.\n *\n * @return {string} The name of device country.\n */\napkUtilsMethods.getDeviceCountry = async function getDeviceCountry () {\n // this method is only used in API < 23\n let country = await this.getDeviceSysCountry();\n if (!country) {\n country = await this.getDeviceProductCountry();\n }\n return country;\n};\n\n/**\n * Get the locale name of the device under test.\n *\n * @return {string} The name of device locale.\n */\napkUtilsMethods.getDeviceLocale = async function getDeviceLocale () {\n // this method is only used in API >= 23\n let locale = await this.getDeviceSysLocale();\n if (!locale) {\n locale = await this.getDeviceProductLocale();\n }\n return locale;\n};\n\n/**\n * Set the locale name of the device under test and the format of the locale is en-US, for example.\n * This method call setDeviceLanguageCountry, so, please use setDeviceLanguageCountry as possible.\n *\n * @param {string} locale - Names of the device language and the country connected with `-`. e.g. en-US.\n */\napkUtilsMethods.setDeviceLocale = async function setDeviceLocale (locale) {\n const validateLocale = new RegExp(/[a-zA-Z]+-[a-zA-Z0-9]+/);\n if (!validateLocale.test(locale)) {\n log.warn(`setDeviceLocale requires the following format: en-US or ja-JP`);\n return;\n }\n\n let split_locale = locale.split('-');\n await this.setDeviceLanguageCountry(split_locale[0], split_locale[1]);\n};\n\n/**\n * Make sure current device locale is expected or not.\n *\n * @param {string} language - Language. The language field is case insensitive, but Locale always canonicalizes to lower case.\n * @param {string} country - Country. The language field is case insensitive, but Locale always canonicalizes to lower case.\n * @param {?string} script - Script. The script field is case insensitive but Locale always canonicalizes to title case.\n *\n * @return {boolean} If current locale is language and country as arguments, return true.\n */\napkUtilsMethods.ensureCurrentLocale = async function ensureCurrentLocale (language, country, script = null) {\n const hasLanguage = _.isString(language);\n const hasCountry = _.isString(country);\n\n if (!hasLanguage && !hasCountry) {\n log.warn('ensureCurrentLocale requires language or country');\n return false;\n }\n\n // get lower case versions of the strings\n language = (language || '').toLowerCase();\n country = (country || '').toLowerCase();\n\n const apiLevel = await this.getApiLevel();\n\n return await retryInterval(5, 1000, async () => {\n try {\n if (apiLevel < 23) {\n let curLanguage, curCountry;\n if (hasLanguage) {\n curLanguage = (await this.getDeviceLanguage()).toLowerCase();\n if (!hasCountry && language === curLanguage) {\n return true;\n }\n }\n if (hasCountry) {\n curCountry = (await this.getDeviceCountry()).toLowerCase();\n if (!hasLanguage && country === curCountry) {\n return true;\n }\n }\n if (language === curLanguage && country === curCountry) {\n return true;\n }\n } else {\n const curLocale = (await this.getDeviceLocale()).toLowerCase();\n // zh-hans-cn : zh-cn\n const localeCode = script ? `${language}-${script.toLowerCase()}-${country}` : `${language}-${country}`;\n\n if (localeCode === curLocale) {\n log.debug(`Requested locale is equal to current locale: '${curLocale}'`);\n return true;\n }\n }\n return false;\n } catch (err) {\n // if there has been an error, restart adb and retry\n log.error(`Unable to check device localization: ${err.message}`);\n try {\n await this.reconnect();\n } catch (ign) {\n await this.restartAdb();\n }\n throw err;\n }\n });\n};\n\n/**\n * Set the locale name of the device under test.\n *\n * @param {string} language - Language. The language field is case insensitive, but Locale always canonicalizes to lower case.\n * format: [a-zA-Z]{2,8}. e.g. en, ja : https://developer.android.com/reference/java/util/Locale.html\n * @param {string} country - Country. The country (region) field is case insensitive, but Locale always canonicalizes to upper case.\n * format: [a-zA-Z]{2} | [0-9]{3}. e.g. US, JP : https://developer.android.com/reference/java/util/Locale.html\n * @param {?string} script - Script. The script field is case insensitive but Locale always canonicalizes to title case.\n * format: [a-zA-Z]{4}. e.g. Hans in zh-Hans-CN : https://developer.android.com/reference/java/util/Locale.html\n */\napkUtilsMethods.setDeviceLanguageCountry = async function setDeviceLanguageCountry (language, country, script = null) {\n let hasLanguage = language && _.isString(language);\n let hasCountry = country && _.isString(country);\n if (!hasLanguage || !hasCountry) {\n log.warn(`setDeviceLanguageCountry requires language and country at least`);\n log.warn(`Got language: '${language}' and country: '${country}'`);\n return;\n }\n let apiLevel = await this.getApiLevel();\n\n language = (language || '').toLowerCase();\n country = (country || '').toUpperCase();\n\n if (apiLevel < 23) {\n let curLanguage = (await this.getDeviceLanguage()).toLowerCase();\n let curCountry = (await this.getDeviceCountry()).toUpperCase();\n\n if (language !== curLanguage || country !== curCountry) {\n await this.setDeviceSysLocaleViaSettingApp(language, country);\n }\n } else {\n let curLocale = await this.getDeviceLocale();\n\n // zh-Hans-CN : zh-CN\n const localeCode = script ? `${language}-${script}-${country}` : `${language}-${country}`;\n log.debug(`Current locale: '${curLocale}'; requested locale: '${localeCode}'`);\n if (localeCode.toLowerCase() !== curLocale.toLowerCase()) {\n await this.setDeviceSysLocaleViaSettingApp(language, country, script);\n }\n }\n};\n\n/**\n * @typedef {Object} AppInfo\n * @property {string} name - Package name, for example 'com.acme.app'.\n * @property {number} versionCode - Version code.\n * @property {string} versionName - Version name, for example '1.0'.\n */\n\n/**\n * Get the package info from local apk file.\n *\n * @param {string} appPath - The full path to existing .apk(s) package on the local\n * file system.\n * @return {?AppInfo} The parsed application information.\n */\napkUtilsMethods.getApkInfo = async function getApkInfo (appPath) {\n if (!await fs.exists(appPath)) {\n throw new Error(`The file at path ${appPath} does not exist or is not accessible`);\n }\n\n if (appPath.endsWith(APKS_EXTENSION)) {\n appPath = await this.extractBaseApk(appPath);\n }\n\n try {\n const apkReader = await ApkReader.open(appPath);\n const manifest = await apkReader.readManifest();\n const {pkg, versionName, versionCode} = parseManifest(manifest);\n return {\n name: pkg,\n versionCode,\n versionName,\n };\n } catch (e) {\n log.warn(`Error '${e.message}' while getting badging info`);\n }\n return {};\n};\n\n/**\n * Get the package info from the installed application.\n *\n * @param {string} pkg - The name of the installed package.\n * @return {?AppInfo} The parsed application information.\n */\napkUtilsMethods.getPackageInfo = async function getPackageInfo (pkg) {\n log.debug(`Getting package info for '${pkg}'`);\n let result = {name: pkg};\n try {\n const stdout = await this.shell(['dumpsys', 'package', pkg]);\n const versionNameMatch = new RegExp(/versionName=([\\d+.]+)/).exec(stdout);\n if (versionNameMatch) {\n result.versionName = versionNameMatch[1];\n }\n const versionCodeMatch = new RegExp(/versionCode=(\\d+)/).exec(stdout);\n if (versionCodeMatch) {\n result.versionCode = parseInt(versionCodeMatch[1], 10);\n }\n return result;\n } catch (err) {\n log.warn(`Error '${err.message}' while dumping package info`);\n }\n return result;\n};\n\n/**\n * Fetches base.apk of the given package to the local file system\n *\n * @param {string} pkg The package identifier (must be already installed on the device)\n * @param {string} tmpDir The destination folder path\n * @returns {string} Full path to the downloaded file\n * @throws {Error} If there was an error while fetching the .apk\n */\napkUtilsMethods.pullApk = async function pullApk (pkg, tmpDir) {\n const stdout = _.trim(await this.shell(['pm', 'path', pkg]));\n const packageMarker = 'package:';\n if (!_.startsWith(stdout, packageMarker)) {\n throw new Error(`Cannot pull the .apk package for '${pkg}'. Original error: ${stdout}`);\n }\n\n const remotePath = stdout.replace(packageMarker, '');\n const tmpApp = path.resolve(tmpDir, `${pkg}.apk`);\n await this.pull(remotePath, tmpApp);\n log.debug(`Pulled app for package '${pkg}' to '${tmpApp}'`);\n return tmpApp;\n};\n\n/**\n * Activates the given application or launches it if necessary.\n * The action literally simulates\n * clicking the corresponding application icon on the dashboard.\n *\n * @param {string} appId - Application package identifier\n * @throws {Error} If the app cannot be activated\n */\napkUtilsMethods.activateApp = async function activateApp (appId) {\n log.debug(`Activating '${appId}'`);\n const apiLevel = await this.getApiLevel();\n // Fallback to Monkey in older APIs\n if (apiLevel < 24) {\n // The monkey command could raise an issue as https://stackoverflow.com/questions/44860475/how-to-use-the-monkey-command-with-an-android-system-that-doesnt-have-physical\n // but '--pct-syskeys 0' could cause another background process issue. https://github.com/appium/appium/issues/16941#issuecomment-1129837285\n const cmd = ['monkey',\n '-p', appId,\n '-c', 'android.intent.category.LAUNCHER',\n '1'];\n let output = '';\n try {\n output = await this.shell(cmd);\n log.debug(`Command stdout: ${output}`);\n } catch (e) {\n log.errorAndThrow(`Cannot activate '${appId}'. Original error: ${e.message}`);\n }\n if (output.includes('monkey aborted')) {\n log.errorAndThrow(`Cannot activate '${appId}'. Are you sure it is installed?`);\n }\n return;\n }\n\n let activityName = await this.resolveLaunchableActivity(appId);\n if (activityName === RESOLVER_ACTIVITY_NAME) {\n // https://github.com/appium/appium/issues/17128\n log.debug(\n `The launchable activity name of '${appId}' was resolved to '${activityName}'. ` +\n `Switching the resolver to not use cmd`\n );\n activityName = await this.resolveLaunchableActivity(appId, {preferCmd: false});\n }\n\n const stdout = await this.shell([\n 'am', (apiLevel < 26) ? 'start' : 'start-activity',\n '-a', 'android.intent.action.MAIN',\n '-c', 'android.intent.category.LAUNCHER',\n // FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_RESET_TASK_IF_NEEDED\n // https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_NEW_TASK\n // https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_RESET_TASK_IF_NEEDED\n '-f', '0x10200000',\n '-n', activityName,\n ]);\n log.debug(stdout);\n if (/^error:/mi.test(stdout)) {\n throw new Error(`Cannot activate '${appId}'. Original error: ${stdout}`);\n }\n};\n\nexport { REMOTE_CACHE_ROOT };\nexport default apkUtilsMethods;\n"],"mappings":";;;;;;;;AAAA;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAM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