UNPKG

appium-adb

Version:

Android Debug Bridge interface

398 lines 19.3 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ADB = exports.DEFAULT_OPTS = exports.DEFAULT_ADB_PORT = void 0; const lodash_1 = __importDefault(require("lodash")); const node_os_1 = __importDefault(require("node:os")); const helpers_1 = require("./helpers"); const logger_1 = require("./logger"); const generalCommands = __importStar(require("./tools/general-commands")); const manifestCommands = __importStar(require("./tools/android-manifest")); const systemCommands = __importStar(require("./tools/system-calls")); const signingCommands = __importStar(require("./tools/apk-signing")); const apkUtilCommands = __importStar(require("./tools/apk-utils")); const apksUtilCommands = __importStar(require("./tools/apks-utils")); const aabUtilCommands = __importStar(require("./tools/aab-utils")); const emuCommands = __importStar(require("./tools/emulator-commands")); const emuConstants = __importStar(require("./tools/emu-constants")); const lockManagementCommands = __importStar(require("./tools/lockmgmt")); const keyboardCommands = __importStar(require("./tools/keyboard-commands")); const deviceSettingsCommands = __importStar(require("./tools/device-settings")); const fsCommands = __importStar(require("./tools/fs-commands")); const appCommands = __importStar(require("./tools/app-commands")); const networkCommands = __importStar(require("./tools/network-commands")); const logcatCommands = __importStar(require("./tools/logcat-commands")); const processCommands = __importStar(require("./tools/process-commands")); exports.DEFAULT_ADB_PORT = 5037; exports.DEFAULT_OPTS = { sdkRoot: (0, helpers_1.getSdkRootFromEnv)(), executable: { path: 'adb', defaultArgs: [] }, tmpDir: node_os_1.default.tmpdir(), binaries: {}, adbPort: exports.DEFAULT_ADB_PORT, adbExecTimeout: helpers_1.DEFAULT_ADB_EXEC_TIMEOUT, remoteAppsCacheLimit: 10, allowOfflineDevices: false, allowDelayAdb: true, listenAllNetwork: false, }; class ADB { adbHost; adbPort; _apiLevel; _logcatStartupParams; _doesPsSupportAOption; _isPgrepAvailable; _canPgrepUseFullCmdLineSearch; _isPidofAvailable; _memoizedFeatures; _areExtendedLsOptionsSupported; remoteAppsCache; _isLockManagementSupported; sdkRoot; udid; useKeystore; keystorePath; keystorePassword; keyAlias; keyPassword; executable; tmpDir; curDeviceId; emulatorPort; logcat; binaries; suppressKillServer; adbExecTimeout; remoteAppsCacheLimit; buildToolsVersion; allowOfflineDevices; allowDelayAdb; remoteAdbHost; remoteAdbPort; clearDeviceLogsOnStart; listenAllNetwork; constructor(opts = {}) { const options = lodash_1.default.defaultsDeep(opts, lodash_1.default.cloneDeep(exports.DEFAULT_OPTS)); lodash_1.default.defaultsDeep(this, options); // The above defaultsDeep call guarantees the 'executable' field to be always assigned this.executable = options.executable; // do not add -a option twice if the defualtArgs already had it. if (options.listenAllNetwork && !this.executable.defaultArgs.includes('-a')) { this.executable.defaultArgs.push('-a'); } else if (this.executable.defaultArgs.includes('-a')) { this.listenAllNetwork = true; } if (options.remoteAdbHost) { this.executable.defaultArgs.push('-H', options.remoteAdbHost); this.adbHost = options.remoteAdbHost; } // TODO figure out why we have this option as it does not appear to be // used anywhere. Probably deprecate in favor of simple opts.adbPort if (options.remoteAdbPort) { this.adbPort = options.remoteAdbPort; } this.executable.defaultArgs.push('-P', String(this.adbPort)); if (options.udid) { this.setDeviceId(options.udid); } } /** * Create a new instance of `ADB` that inherits configuration from this `ADB` instance. * This avoids the need to call `ADB.createADB()` multiple times. * @param opts - Additional options mapping to pass to the `ADB` constructor. * @returns The resulting class instance. */ clone(opts = {}) { const originalOptions = lodash_1.default.cloneDeep(lodash_1.default.pick(this, Object.keys(exports.DEFAULT_OPTS))); const cloneOptions = lodash_1.default.defaultsDeep(opts, originalOptions); // Reset default arguments created in the constructor. // Without this code, -H and -P can be injected into defaultArgs multiple times. const defaultArgs = cloneOptions.executable.defaultArgs; if (cloneOptions.remoteAdbHost && defaultArgs.includes('-H')) { defaultArgs.splice(defaultArgs.indexOf('-H'), 2); } if (defaultArgs.includes('-P')) { defaultArgs.splice(defaultArgs.indexOf('-P'), 2); } return new ADB(cloneOptions); } static async createADB(opts = {}) { const adb = new ADB(opts); adb.sdkRoot = await (0, helpers_1.requireSdkRoot)(adb.sdkRoot); await adb.getAdbWithCorrectAdbPath(); if (!opts?.suppressKillServer) { try { await adb.adbExec(['start-server']); } catch (e) { const err = e; logger_1.log.warn(err.stderr || err.message); } } return adb; } getAdbWithCorrectAdbPath = generalCommands.getAdbWithCorrectAdbPath; initAapt = generalCommands.initAapt; initAapt2 = generalCommands.initAapt2; initZipAlign = generalCommands.initZipAlign; initBundletool = generalCommands.initBundletool; getApiLevel = generalCommands.getApiLevel; isDeviceConnected = generalCommands.isDeviceConnected; clearTextField = generalCommands.clearTextField; back = generalCommands.back; goToHome = generalCommands.goToHome; getAdbPath = generalCommands.getAdbPath; restart = generalCommands.restart; bugreport = generalCommands.bugreport; screenrecord = generalCommands.screenrecord; listFeatures = generalCommands.listFeatures; isStreamedInstallSupported = generalCommands.isStreamedInstallSupported; isIncrementalInstallSupported = generalCommands.isIncrementalInstallSupported; takeScreenshot = generalCommands.takeScreenshot; startLogcat = logcatCommands.startLogcat; stopLogcat = logcatCommands.stopLogcat; getLogcatLogs = logcatCommands.getLogcatLogs; setLogcatListener = logcatCommands.setLogcatListener; removeLogcatListener = logcatCommands.removeLogcatListener; getForwardList = networkCommands.getForwardList; forwardPort = networkCommands.forwardPort; listPorts = networkCommands.listPorts; ping = networkCommands.ping; forwardAbstractPort = networkCommands.forwardAbstractPort; removePortReverse = networkCommands.removePortReverse; reversePort = networkCommands.reversePort; getReverseList = networkCommands.getReverseList; removePortForward = networkCommands.removePortForward; executeApksigner = signingCommands.executeApksigner; signWithDefaultCert = signingCommands.signWithDefaultCert; signWithCustomCert = signingCommands.signWithCustomCert; sign = signingCommands.sign; zipAlignApk = signingCommands.zipAlignApk; checkApkCert = signingCommands.checkApkCert; getKeystoreHash = signingCommands.getKeystoreHash; grantAllPermissions = appCommands.grantAllPermissions; grantPermissions = appCommands.grantPermissions; grantPermission = appCommands.grantPermission; revokePermission = appCommands.revokePermission; getGrantedPermissions = appCommands.getGrantedPermissions; getDeniedPermissions = appCommands.getDeniedPermissions; getReqPermissions = appCommands.getReqPermissions; stopAndClear = appCommands.stopAndClear; isValidClass = appCommands.isValidClass; resolveLaunchableActivity = appCommands.resolveLaunchableActivity; forceStop = appCommands.forceStop; killPackage = appCommands.killPackage; clear = appCommands.clear; APP_INSTALL_STATE = appCommands.APP_INSTALL_STATE; isAppInstalled = appCommands.isAppInstalled; listInstalledPackages = appCommands.listInstalledPackages; startUri = appCommands.startUri; startApp = appCommands.startApp; dumpWindows = appCommands.dumpWindows; getFocusedPackageAndActivity = appCommands.getFocusedPackageAndActivity; waitForActivityOrNot = appCommands.waitForActivityOrNot; waitForActivity = appCommands.waitForActivity; waitForNotActivity = appCommands.waitForNotActivity; getPackageInfo = appCommands.getPackageInfo; pullApk = appCommands.pullApk; activateApp = appCommands.activateApp; listAppProcessIds = appCommands.listAppProcessIds; isAppRunning = appCommands.isAppRunning; broadcast = appCommands.broadcast; listProcessStatus = processCommands.listProcessStatus; getProcessNameById = processCommands.getProcessNameById; getProcessIdsByName = processCommands.getProcessIdsByName; killProcessesByName = processCommands.killProcessesByName; killProcessByPID = processCommands.killProcessByPID; processExists = processCommands.processExists; uninstallApk = apkUtilCommands.uninstallApk; installFromDevicePath = apkUtilCommands.installFromDevicePath; cacheApk = apkUtilCommands.cacheApk; install = apkUtilCommands.install; installOrUpgrade = apkUtilCommands.installOrUpgrade; extractStringsFromApk = apkUtilCommands.extractStringsFromApk; getApkInfo = apkUtilCommands.getApkInfo; getApplicationInstallState = apkUtilCommands.getApplicationInstallState; hideKeyboard = keyboardCommands.hideKeyboard; isSoftKeyboardPresent = keyboardCommands.isSoftKeyboardPresent; keyevent = keyboardCommands.keyevent; availableIMEs = keyboardCommands.availableIMEs; enabledIMEs = keyboardCommands.enabledIMEs; enableIME = keyboardCommands.enableIME; disableIME = keyboardCommands.disableIME; setIME = keyboardCommands.setIME; defaultIME = keyboardCommands.defaultIME; inputText = keyboardCommands.inputText; runInImeContext = keyboardCommands.runInImeContext; lock = lockManagementCommands.lock; isLockManagementSupported = lockManagementCommands.isLockManagementSupported; verifyLockCredential = lockManagementCommands.verifyLockCredential; clearLockCredential = lockManagementCommands.clearLockCredential; isLockEnabled = lockManagementCommands.isLockEnabled; setLockCredential = lockManagementCommands.setLockCredential; isScreenLocked = lockManagementCommands.isScreenLocked; dismissKeyguard = lockManagementCommands.dismissKeyguard; cycleWakeUp = lockManagementCommands.cycleWakeUp; getSdkBinaryPath = systemCommands.getSdkBinaryPath; getBinaryNameForOS = systemCommands.getBinaryNameForOS; getBinaryFromSdkRoot = systemCommands.getBinaryFromSdkRoot; getBinaryFromPath = systemCommands.getBinaryFromPath; getConnectedDevices = systemCommands.getConnectedDevices; getDevicesWithRetry = systemCommands.getDevicesWithRetry; reconnect = systemCommands.reconnect; restartAdb = systemCommands.restartAdb; killServer = systemCommands.killServer; resetTelnetAuthToken = systemCommands.resetTelnetAuthToken; adbExecEmu = systemCommands.adbExecEmu; EXEC_OUTPUT_FORMAT = systemCommands.EXEC_OUTPUT_FORMAT; adbExec = systemCommands.adbExec; shell = systemCommands.shell; shellChunks = systemCommands.shellChunks; createSubProcess = systemCommands.createSubProcess; getAdbServerPort = systemCommands.getAdbServerPort; getEmulatorPort = systemCommands.getEmulatorPort; getPortFromEmulatorString = systemCommands.getPortFromEmulatorString; getConnectedEmulators = systemCommands.getConnectedEmulators; setEmulatorPort = systemCommands.setEmulatorPort; setDeviceId = systemCommands.setDeviceId; setDevice = systemCommands.setDevice; getRunningAVD = systemCommands.getRunningAVD; getRunningAVDWithRetry = systemCommands.getRunningAVDWithRetry; killAllEmulators = systemCommands.killAllEmulators; killEmulator = systemCommands.killEmulator; launchAVD = systemCommands.launchAVD; getVersion = systemCommands.getVersion; waitForEmulatorReady = systemCommands.waitForEmulatorReady; waitForDevice = systemCommands.waitForDevice; reboot = systemCommands.reboot; changeUserPrivileges = systemCommands.changeUserPrivileges; root = systemCommands.root; unroot = systemCommands.unroot; isRoot = systemCommands.isRoot; installMitmCertificate = systemCommands.installMitmCertificate; isMitmCertificateInstalled = systemCommands.isMitmCertificateInstalled; execBundletool = apksUtilCommands.execBundletool; getDeviceSpec = apksUtilCommands.getDeviceSpec; installMultipleApks = apksUtilCommands.installMultipleApks; installApks = apksUtilCommands.installApks; extractBaseApk = apksUtilCommands.extractBaseApk; extractLanguageApk = apksUtilCommands.extractLanguageApk; isTestPackageOnlyError = apksUtilCommands.isTestPackageOnlyError; packageAndLaunchActivityFromManifest = manifestCommands.packageAndLaunchActivityFromManifest; targetSdkVersionFromManifest = manifestCommands.targetSdkVersionFromManifest; targetSdkVersionUsingPKG = manifestCommands.targetSdkVersionUsingPKG; compileManifest = manifestCommands.compileManifest; insertManifest = manifestCommands.insertManifest; hasInternetPermissionFromManifest = manifestCommands.hasInternetPermissionFromManifest; extractUniversalApk = aabUtilCommands.extractUniversalApk; isEmulatorConnected = emuCommands.isEmulatorConnected; verifyEmulatorConnected = emuCommands.verifyEmulatorConnected; fingerprint = emuCommands.fingerprint; rotate = emuCommands.rotate; powerAC = emuCommands.powerAC; sensorSet = emuCommands.sensorSet; powerCapacity = emuCommands.powerCapacity; powerOFF = emuCommands.powerOFF; sendSMS = emuCommands.sendSMS; gsmCall = emuCommands.gsmCall; gsmSignal = emuCommands.gsmSignal; gsmVoice = emuCommands.gsmVoice; networkSpeed = emuCommands.networkSpeed; sendTelnetCommand = emuCommands.sendTelnetCommand; execEmuConsoleCommand = emuCommands.execEmuConsoleCommand; getEmuVersionInfo = emuCommands.getEmuVersionInfo; getEmuImageProperties = emuCommands.getEmuImageProperties; checkAvdExist = emuCommands.checkAvdExist; POWER_AC_STATES = emuConstants.POWER_AC_STATES; GSM_CALL_ACTIONS = emuConstants.GSM_CALL_ACTIONS; GSM_VOICE_STATES = emuConstants.GSM_VOICE_STATES; GSM_SIGNAL_STRENGTHS = emuConstants.GSM_SIGNAL_STRENGTHS; NETWORK_SPEED = emuConstants.NETWORK_SPEED; SENSORS = emuConstants.SENSORS; fileExists = fsCommands.fileExists; ls = fsCommands.ls; fileSize = fsCommands.fileSize; rimraf = fsCommands.rimraf; push = fsCommands.push; pull = fsCommands.pull; mkdir = fsCommands.mkdir; getDeviceProperty = deviceSettingsCommands.getDeviceProperty; setDeviceProperty = deviceSettingsCommands.setDeviceProperty; getDeviceSysLanguage = deviceSettingsCommands.getDeviceSysLanguage; getDeviceSysCountry = deviceSettingsCommands.getDeviceSysCountry; getDeviceSysLocale = deviceSettingsCommands.getDeviceSysLocale; getDeviceProductLanguage = deviceSettingsCommands.getDeviceProductLanguage; getDeviceProductCountry = deviceSettingsCommands.getDeviceProductCountry; getDeviceProductLocale = deviceSettingsCommands.getDeviceProductLocale; getModel = deviceSettingsCommands.getModel; getManufacturer = deviceSettingsCommands.getManufacturer; getScreenSize = deviceSettingsCommands.getScreenSize; getScreenDensity = deviceSettingsCommands.getScreenDensity; setHttpProxy = deviceSettingsCommands.setHttpProxy; deleteHttpProxy = deviceSettingsCommands.deleteHttpProxy; setSetting = deviceSettingsCommands.setSetting; getSetting = deviceSettingsCommands.getSetting; getTimeZone = deviceSettingsCommands.getTimeZone; getPlatformVersion = deviceSettingsCommands.getPlatformVersion; getLocationProviders = deviceSettingsCommands.getLocationProviders; toggleGPSLocationProvider = deviceSettingsCommands.toggleGPSLocationProvider; setHiddenApiPolicy = deviceSettingsCommands.setHiddenApiPolicy; setDefaultHiddenApiPolicy = deviceSettingsCommands.setDefaultHiddenApiPolicy; getDeviceLanguage = deviceSettingsCommands.getDeviceLanguage; getDeviceCountry = deviceSettingsCommands.getDeviceCountry; getDeviceLocale = deviceSettingsCommands.getDeviceLocale; ensureCurrentLocale = deviceSettingsCommands.ensureCurrentLocale; setWifiState = deviceSettingsCommands.setWifiState; setDataState = deviceSettingsCommands.setDataState; getDeviceIdleWhitelist = deviceSettingsCommands.getDeviceIdleWhitelist; addToDeviceIdleWhitelist = deviceSettingsCommands.addToDeviceIdleWhitelist; isAirplaneModeOn = deviceSettingsCommands.isAirplaneModeOn; setAirplaneMode = deviceSettingsCommands.setAirplaneMode; setBluetoothOn = deviceSettingsCommands.setBluetoothOn; setNfcOn = deviceSettingsCommands.setNfcOn; broadcastAirplaneMode = deviceSettingsCommands.broadcastAirplaneMode; isWifiOn = deviceSettingsCommands.isWifiOn; isDataOn = deviceSettingsCommands.isDataOn; isAnimationOn = deviceSettingsCommands.isAnimationOn; setAnimationScale = deviceSettingsCommands.setAnimationScale; getScreenOrientation = deviceSettingsCommands.getScreenOrientation; } exports.ADB = ADB; //# sourceMappingURL=adb.js.map