UNPKG

appium-adb

Version:

Android Debug Bridge interface

352 lines 20 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")); 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, }; class ADB { constructor(opts = {}) { this.getAdbWithCorrectAdbPath = generalCommands.getAdbWithCorrectAdbPath; this.initAapt = generalCommands.initAapt; this.initAapt2 = generalCommands.initAapt2; this.initZipAlign = generalCommands.initZipAlign; this.initBundletool = generalCommands.initBundletool; this.getApiLevel = generalCommands.getApiLevel; this.isDeviceConnected = generalCommands.isDeviceConnected; this.clearTextField = generalCommands.clearTextField; this.back = generalCommands.back; this.goToHome = generalCommands.goToHome; this.getAdbPath = generalCommands.getAdbPath; this.restart = generalCommands.restart; this.bugreport = generalCommands.bugreport; this.screenrecord = generalCommands.screenrecord; this.listFeatures = generalCommands.listFeatures; this.isStreamedInstallSupported = generalCommands.isStreamedInstallSupported; this.isIncrementalInstallSupported = generalCommands.isIncrementalInstallSupported; this.takeScreenshot = generalCommands.takeScreenshot; this.startLogcat = logcatCommands.startLogcat; this.stopLogcat = logcatCommands.stopLogcat; this.getLogcatLogs = logcatCommands.getLogcatLogs; this.setLogcatListener = logcatCommands.setLogcatListener; this.removeLogcatListener = logcatCommands.removeLogcatListener; this.getForwardList = networkCommands.getForwardList; this.forwardPort = networkCommands.forwardPort; this.listPorts = networkCommands.listPorts; this.ping = networkCommands.ping; this.forwardAbstractPort = networkCommands.forwardAbstractPort; this.removePortReverse = networkCommands.removePortReverse; this.reversePort = networkCommands.reversePort; this.getReverseList = networkCommands.getReverseList; this.removePortForward = networkCommands.removePortForward; this.executeApksigner = signingCommands.executeApksigner; this.signWithDefaultCert = signingCommands.signWithDefaultCert; this.signWithCustomCert = signingCommands.signWithCustomCert; this.sign = signingCommands.sign; this.zipAlignApk = signingCommands.zipAlignApk; this.checkApkCert = signingCommands.checkApkCert; this.getKeystoreHash = signingCommands.getKeystoreHash; this.grantAllPermissions = appCommands.grantAllPermissions; this.grantPermissions = appCommands.grantPermissions; this.grantPermission = appCommands.grantPermission; this.revokePermission = appCommands.revokePermission; this.getGrantedPermissions = appCommands.getGrantedPermissions; this.getDeniedPermissions = appCommands.getDeniedPermissions; this.getReqPermissions = appCommands.getReqPermissions; this.stopAndClear = appCommands.stopAndClear; this.isValidClass = appCommands.isValidClass; this.resolveLaunchableActivity = appCommands.resolveLaunchableActivity; this.forceStop = appCommands.forceStop; this.killPackage = appCommands.killPackage; this.clear = appCommands.clear; this.listProcessStatus = appCommands.listProcessStatus; this.getNameByPid = appCommands.getNameByPid; this.getPIDsByName = appCommands.getPIDsByName; this.killProcessesByName = appCommands.killProcessesByName; this.killProcessByPID = appCommands.killProcessByPID; this.broadcastProcessEnd = appCommands.broadcastProcessEnd; this.broadcast = appCommands.broadcast; this.processExists = appCommands.processExists; this.APP_INSTALL_STATE = appCommands.APP_INSTALL_STATE; this.isAppInstalled = appCommands.isAppInstalled; this.startUri = appCommands.startUri; this.startApp = appCommands.startApp; this.dumpWindows = appCommands.dumpWindows; this.getFocusedPackageAndActivity = appCommands.getFocusedPackageAndActivity; this.waitForActivityOrNot = appCommands.waitForActivityOrNot; this.waitForActivity = appCommands.waitForActivity; this.waitForNotActivity = appCommands.waitForNotActivity; this.getPackageInfo = appCommands.getPackageInfo; this.pullApk = appCommands.pullApk; this.activateApp = appCommands.activateApp; this.uninstallApk = apkUtilCommands.uninstallApk; this.installFromDevicePath = apkUtilCommands.installFromDevicePath; this.cacheApk = apkUtilCommands.cacheApk; this.install = apkUtilCommands.install; this.installOrUpgrade = apkUtilCommands.installOrUpgrade; this.extractStringsFromApk = apkUtilCommands.extractStringsFromApk; this.getApkInfo = apkUtilCommands.getApkInfo; this.getApplicationInstallState = apkUtilCommands.getApplicationInstallState; this.hideKeyboard = keyboardCommands.hideKeyboard; this.isSoftKeyboardPresent = keyboardCommands.isSoftKeyboardPresent; this.keyevent = keyboardCommands.keyevent; this.availableIMEs = keyboardCommands.availableIMEs; this.enabledIMEs = keyboardCommands.enabledIMEs; this.enableIME = keyboardCommands.enableIME; this.disableIME = keyboardCommands.disableIME; this.setIME = keyboardCommands.setIME; this.defaultIME = keyboardCommands.defaultIME; this.inputText = keyboardCommands.inputText; this.runInImeContext = keyboardCommands.runInImeContext; this.lock = lockManagementCommands.lock; this.isLockManagementSupported = lockManagementCommands.isLockManagementSupported; this.verifyLockCredential = lockManagementCommands.verifyLockCredential; this.clearLockCredential = lockManagementCommands.clearLockCredential; this.isLockEnabled = lockManagementCommands.isLockEnabled; this.setLockCredential = lockManagementCommands.setLockCredential; this.isScreenLocked = lockManagementCommands.isScreenLocked; this.dismissKeyguard = lockManagementCommands.dismissKeyguard; this.cycleWakeUp = lockManagementCommands.cycleWakeUp; this.getSdkBinaryPath = systemCommands.getSdkBinaryPath; this.getBinaryNameForOS = systemCommands.getBinaryNameForOS; this.getBinaryFromSdkRoot = systemCommands.getBinaryFromSdkRoot; this.getBinaryFromPath = systemCommands.getBinaryFromPath; this.getConnectedDevices = systemCommands.getConnectedDevices; this.getDevicesWithRetry = systemCommands.getDevicesWithRetry; this.reconnect = systemCommands.reconnect; this.restartAdb = systemCommands.restartAdb; this.killServer = systemCommands.killServer; this.resetTelnetAuthToken = systemCommands.resetTelnetAuthToken; this.adbExecEmu = systemCommands.adbExecEmu; this.EXEC_OUTPUT_FORMAT = systemCommands.EXEC_OUTPUT_FORMAT; this.adbExec = systemCommands.adbExec; this.shell = systemCommands.shell; this.shellChunks = systemCommands.shellChunks; this.createSubProcess = systemCommands.createSubProcess; this.getAdbServerPort = systemCommands.getAdbServerPort; this.getEmulatorPort = systemCommands.getEmulatorPort; this.getPortFromEmulatorString = systemCommands.getPortFromEmulatorString; this.getConnectedEmulators = systemCommands.getConnectedEmulators; this.setEmulatorPort = systemCommands.setEmulatorPort; this.setDeviceId = systemCommands.setDeviceId; this.setDevice = systemCommands.setDevice; this.getRunningAVD = systemCommands.getRunningAVD; this.getRunningAVDWithRetry = systemCommands.getRunningAVDWithRetry; this.killAllEmulators = systemCommands.killAllEmulators; this.killEmulator = systemCommands.killEmulator; this.launchAVD = systemCommands.launchAVD; this.getVersion = systemCommands.getVersion; this.waitForEmulatorReady = systemCommands.waitForEmulatorReady; this.waitForDevice = systemCommands.waitForDevice; this.reboot = systemCommands.reboot; this.changeUserPrivileges = systemCommands.changeUserPrivileges; this.root = systemCommands.root; this.unroot = systemCommands.unroot; this.isRoot = systemCommands.isRoot; this.installMitmCertificate = systemCommands.installMitmCertificate; this.isMitmCertificateInstalled = systemCommands.isMitmCertificateInstalled; this.execBundletool = apksUtilCommands.execBundletool; this.getDeviceSpec = apksUtilCommands.getDeviceSpec; this.installMultipleApks = apksUtilCommands.installMultipleApks; this.installApks = apksUtilCommands.installApks; this.extractBaseApk = apksUtilCommands.extractBaseApk; this.extractLanguageApk = apksUtilCommands.extractLanguageApk; this.isTestPackageOnlyError = apksUtilCommands.isTestPackageOnlyError; this.packageAndLaunchActivityFromManifest = manifestCommands.packageAndLaunchActivityFromManifest; this.targetSdkVersionFromManifest = manifestCommands.targetSdkVersionFromManifest; this.targetSdkVersionUsingPKG = manifestCommands.targetSdkVersionUsingPKG; this.compileManifest = manifestCommands.compileManifest; this.insertManifest = manifestCommands.insertManifest; this.hasInternetPermissionFromManifest = manifestCommands.hasInternetPermissionFromManifest; this.extractUniversalApk = aabUtilCommands.extractUniversalApk; this.isEmulatorConnected = emuCommands.isEmulatorConnected; this.verifyEmulatorConnected = emuCommands.verifyEmulatorConnected; this.fingerprint = emuCommands.fingerprint; this.rotate = emuCommands.rotate; this.powerAC = emuCommands.powerAC; this.sensorSet = emuCommands.sensorSet; this.powerCapacity = emuCommands.powerCapacity; this.powerOFF = emuCommands.powerOFF; this.sendSMS = emuCommands.sendSMS; this.gsmCall = emuCommands.gsmCall; this.gsmSignal = emuCommands.gsmSignal; this.gsmVoice = emuCommands.gsmVoice; this.networkSpeed = emuCommands.networkSpeed; this.sendTelnetCommand = emuCommands.sendTelnetCommand; this.execEmuConsoleCommand = emuCommands.execEmuConsoleCommand; this.getEmuVersionInfo = emuCommands.getEmuVersionInfo; this.getEmuImageProperties = emuCommands.getEmuImageProperties; this.checkAvdExist = emuCommands.checkAvdExist; this.POWER_AC_STATES = emuConstants.POWER_AC_STATES; this.GSM_CALL_ACTIONS = emuConstants.GSM_CALL_ACTIONS; this.GSM_VOICE_STATES = emuConstants.GSM_VOICE_STATES; this.GSM_SIGNAL_STRENGTHS = emuConstants.GSM_SIGNAL_STRENGTHS; this.NETWORK_SPEED = emuConstants.NETWORK_SPEED; this.SENSORS = emuConstants.SENSORS; this.fileExists = fsCommands.fileExists; this.ls = fsCommands.ls; this.fileSize = fsCommands.fileSize; this.rimraf = fsCommands.rimraf; this.push = fsCommands.push; this.pull = fsCommands.pull; this.mkdir = fsCommands.mkdir; this.getDeviceProperty = deviceSettingsCommands.getDeviceProperty; this.setDeviceProperty = deviceSettingsCommands.setDeviceProperty; this.getDeviceSysLanguage = deviceSettingsCommands.getDeviceSysLanguage; this.getDeviceSysCountry = deviceSettingsCommands.getDeviceSysCountry; this.getDeviceSysLocale = deviceSettingsCommands.getDeviceSysLocale; this.getDeviceProductLanguage = deviceSettingsCommands.getDeviceProductLanguage; this.getDeviceProductCountry = deviceSettingsCommands.getDeviceProductCountry; this.getDeviceProductLocale = deviceSettingsCommands.getDeviceProductLocale; this.getModel = deviceSettingsCommands.getModel; this.getManufacturer = deviceSettingsCommands.getManufacturer; this.getScreenSize = deviceSettingsCommands.getScreenSize; this.getScreenDensity = deviceSettingsCommands.getScreenDensity; this.setHttpProxy = deviceSettingsCommands.setHttpProxy; this.deleteHttpProxy = deviceSettingsCommands.deleteHttpProxy; this.setSetting = deviceSettingsCommands.setSetting; this.getSetting = deviceSettingsCommands.getSetting; this.getTimeZone = deviceSettingsCommands.getTimeZone; this.getPlatformVersion = deviceSettingsCommands.getPlatformVersion; this.getLocationProviders = deviceSettingsCommands.getLocationProviders; this.toggleGPSLocationProvider = deviceSettingsCommands.toggleGPSLocationProvider; this.setHiddenApiPolicy = deviceSettingsCommands.setHiddenApiPolicy; this.setDefaultHiddenApiPolicy = deviceSettingsCommands.setDefaultHiddenApiPolicy; this.getDeviceLanguage = deviceSettingsCommands.getDeviceLanguage; this.getDeviceCountry = deviceSettingsCommands.getDeviceCountry; this.getDeviceLocale = deviceSettingsCommands.getDeviceLocale; this.ensureCurrentLocale = deviceSettingsCommands.ensureCurrentLocale; this.setWifiState = deviceSettingsCommands.setWifiState; this.setDataState = deviceSettingsCommands.setDataState; this.getDeviceIdleWhitelist = deviceSettingsCommands.getDeviceIdleWhitelist; this.addToDeviceIdleWhitelist = deviceSettingsCommands.addToDeviceIdleWhitelist; this.isAirplaneModeOn = deviceSettingsCommands.isAirplaneModeOn; this.setAirplaneMode = deviceSettingsCommands.setAirplaneMode; this.setBluetoothOn = deviceSettingsCommands.setBluetoothOn; this.setNfcOn = deviceSettingsCommands.setNfcOn; this.broadcastAirplaneMode = deviceSettingsCommands.broadcastAirplaneMode; this.isWifiOn = deviceSettingsCommands.isWifiOn; this.isDataOn = deviceSettingsCommands.isDataOn; this.isAnimationOn = deviceSettingsCommands.isAnimationOn; this.setAnimationScale = deviceSettingsCommands.setAnimationScale; this.getScreenOrientation = deviceSettingsCommands.getScreenOrientation; 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; 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; } } exports.ADB = ADB; //# sourceMappingURL=adb.js.map