1
1
import _ from 'lodash' ;
2
2
import os from 'node:os' ;
3
- import methods , { getAndroidBinaryPath } from './tools' ;
4
- import { DEFAULT_ADB_EXEC_TIMEOUT , requireSdkRoot , getSdkRootFromEnv } from './helpers' ;
3
+ import {
4
+ DEFAULT_ADB_EXEC_TIMEOUT ,
5
+ requireSdkRoot ,
6
+ getSdkRootFromEnv
7
+ } from './helpers' ;
5
8
import log from './logger' ;
6
9
import type { ADBOptions , ADBExecutable } from './options' ;
7
- import type { LogcatOpts } from './logcat' ;
10
+ import type { LogcatOpts , Logcat } from './logcat' ;
8
11
import type { LRUCache } from 'lru-cache' ;
9
12
import type { ExecError } from 'teen_process' ;
13
+ import type { StringRecord } from '@appium/types' ;
10
14
11
- const DEFAULT_ADB_PORT = 5037 ;
15
+ import * as generalMethods from './tools/adb-commands' ;
16
+ import * as manifestMethods from './tools/android-manifest' ;
17
+ import * as systemCallMethods from './tools/system-calls' ;
18
+ import * as apkSigningMethods from './tools/apk-signing' ;
19
+ import * as apkUtilsMethods from './tools/apk-utils' ;
20
+ import * as apksUtilsMethods from './tools/apks-utils' ;
21
+ import * as aabUtilsMethods from './tools/aab-utils' ;
22
+ import * as emuMethods from './tools/adb-emu-commands' ;
23
+ import * as lockManagementCommands from './tools/lockmgmt' ;
24
+ import * as keyboardCommands from './tools/keyboard-commands' ;
25
+
26
+
27
+ export const DEFAULT_ADB_PORT = 5037 ;
12
28
export const DEFAULT_OPTS = {
13
29
sdkRoot : getSdkRootFromEnv ( ) ,
14
30
executable : { path : 'adb' , defaultArgs : [ ] } ,
@@ -21,7 +37,7 @@ export const DEFAULT_OPTS = {
21
37
allowDelayAdb : true ,
22
38
} as const ;
23
39
24
- export class ADB {
40
+ export class ADB implements ADBOptions {
25
41
adbHost ?: string ;
26
42
adbPort ?: number ;
27
43
_apiLevel : number | undefined ;
@@ -35,7 +51,30 @@ export class ADB {
35
51
remoteAppsCache : LRUCache < string , string > | undefined ;
36
52
_isLockManagementSupported : boolean | undefined ;
37
53
54
+ sdkRoot ?: string ;
55
+ udid ?: string ;
56
+ appDeviceReadyTimeout ?: number ;
57
+ useKeystore ?: boolean ;
58
+ keystorePath ?: string ;
59
+ keystorePassword ?: string ;
60
+ keyAlias ?: string ;
61
+ keyPassword ?: string ;
38
62
executable : ADBExecutable ;
63
+ tmpDir ?: string ;
64
+ curDeviceId ?: string ;
65
+ emulatorPort ?: number ;
66
+ logcat ?: Logcat ;
67
+ binaries ?: StringRecord ;
68
+ suppressKillServer ?: boolean ;
69
+ adbExecTimeout ?: number ;
70
+ remoteAppsCacheLimit ?: number ;
71
+ buildToolsVersion ?: string ;
72
+ allowOfflineDevices ?: boolean ;
73
+ allowDelayAdb ?: boolean ;
74
+ remoteAdbHost ?: string ;
75
+ remoteAdbPort ?: number ;
76
+ clearDeviceLogsOnStart ?: boolean ;
77
+
39
78
constructor ( opts : ADBOptions = ( { } as ADBOptions ) ) {
40
79
const options : ADBOptions = _ . defaultsDeep ( opts , _ . cloneDeep ( DEFAULT_OPTS ) ) ;
41
80
_ . defaultsDeep ( this , options ) ;
@@ -95,9 +134,238 @@ export class ADB {
95
134
}
96
135
return adb ;
97
136
}
98
- }
99
137
100
- // add all the methods to the ADB prototype
101
- Object . assign ( ADB . prototype , methods ) ;
138
+ // TODO: Group methods from general to corresponding modules
139
+ shellChunks = generalMethods . shellChunks ;
140
+ getAdbWithCorrectAdbPath = generalMethods . getAdbWithCorrectAdbPath ;
141
+ initAapt = generalMethods . initAapt ;
142
+ initAapt2 = generalMethods . initAapt2 ;
143
+ initZipAlign = generalMethods . initZipAlign ;
144
+ initBundletool = generalMethods . initBundletool ;
145
+ getApiLevel = generalMethods . getApiLevel ;
146
+ getPlatformVersion = generalMethods . getPlatformVersion ;
147
+ isDeviceConnected = generalMethods . isDeviceConnected ;
148
+ mkdir = generalMethods . mkdir ;
149
+ isValidClass = generalMethods . isValidClass ;
150
+ resolveLaunchableActivity = generalMethods . resolveLaunchableActivity ;
151
+ forceStop = generalMethods . forceStop ;
152
+ killPackage = generalMethods . killPackage ;
153
+ clear = generalMethods . clear ;
154
+ grantAllPermissions = generalMethods . grantAllPermissions ;
155
+ grantPermissions = generalMethods . grantPermissions ;
156
+ grantPermission = generalMethods . grantPermission ;
157
+ revokePermission = generalMethods . revokePermission ;
158
+ getGrantedPermissions = generalMethods . getGrantedPermissions ;
159
+ getDeniedPermissions = generalMethods . getDeniedPermissions ;
160
+ getReqPermissions = generalMethods . getReqPermissions ;
161
+ getLocationProviders = generalMethods . getLocationProviders ;
162
+ toggleGPSLocationProvider = generalMethods . toggleGPSLocationProvider ;
163
+ setHiddenApiPolicy = generalMethods . setHiddenApiPolicy ;
164
+ setDefaultHiddenApiPolicy = generalMethods . setDefaultHiddenApiPolicy ;
165
+ stopAndClear = generalMethods . stopAndClear ;
166
+ availableIMEs = generalMethods . availableIMEs ;
167
+ enabledIMEs = generalMethods . enabledIMEs ;
168
+ enableIME = generalMethods . enableIME ;
169
+ disableIME = generalMethods . disableIME ;
170
+ setIME = generalMethods . setIME ;
171
+ defaultIME = generalMethods . defaultIME ;
172
+ keyevent = generalMethods . keyevent ;
173
+ inputText = generalMethods . inputText ;
174
+ clearTextField = generalMethods . clearTextField ;
175
+ lock = generalMethods . lock ;
176
+ back = generalMethods . back ;
177
+ goToHome = generalMethods . goToHome ;
178
+ getAdbPath = generalMethods . getAdbPath ;
179
+ getScreenOrientation = generalMethods . getScreenOrientation ;
180
+ sendTelnetCommand = generalMethods . sendTelnetCommand ;
181
+ isAirplaneModeOn = generalMethods . isAirplaneModeOn ;
182
+ setAirplaneMode = generalMethods . setAirplaneMode ;
183
+ setBluetoothOn = generalMethods . setBluetoothOn ;
184
+ setNfcOn = generalMethods . setNfcOn ;
185
+ broadcastAirplaneMode = generalMethods . broadcastAirplaneMode ;
186
+ isWifiOn = generalMethods . isWifiOn ;
187
+ isDataOn = generalMethods . isDataOn ;
188
+ isAnimationOn = generalMethods . isAnimationOn ;
189
+ setAnimationScale = generalMethods . setAnimationScale ;
190
+ rimraf = generalMethods . rimraf ;
191
+ push = generalMethods . push ;
192
+ pull = generalMethods . pull ;
193
+ processExists = generalMethods . processExists ;
194
+ getForwardList = generalMethods . getForwardList ;
195
+ forwardPort = generalMethods . forwardPort ;
196
+ removePortForward = generalMethods . removePortForward ;
197
+ getReverseList = generalMethods . getReverseList ;
198
+ reversePort = generalMethods . reversePort ;
199
+ removePortReverse = generalMethods . removePortReverse ;
200
+ forwardAbstractPort = generalMethods . forwardAbstractPort ;
201
+ ping = generalMethods . ping ;
202
+ restart = generalMethods . restart ;
203
+ startLogcat = generalMethods . startLogcat ;
204
+ stopLogcat = generalMethods . stopLogcat ;
205
+ getLogcatLogs = generalMethods . getLogcatLogs ;
206
+ setLogcatListener = generalMethods . setLogcatListener ;
207
+ removeLogcatListener = generalMethods . removeLogcatListener ;
208
+ listProcessStatus = generalMethods . listProcessStatus ;
209
+ getNameByPid = generalMethods . getNameByPid ;
210
+ getPIDsByName = generalMethods . getPIDsByName ;
211
+ killProcessesByName = generalMethods . killProcessesByName ;
212
+ killProcessByPID = generalMethods . killProcessByPID ;
213
+ broadcastProcessEnd = generalMethods . broadcastProcessEnd ;
214
+ broadcast = generalMethods . broadcast ;
215
+ getDeviceProperty = generalMethods . getDeviceProperty ;
216
+ setDeviceProperty = generalMethods . setDeviceProperty ;
217
+ getDeviceSysLanguage = generalMethods . getDeviceSysLanguage ;
218
+ getDeviceSysCountry = generalMethods . getDeviceSysCountry ;
219
+ getDeviceSysLocale = generalMethods . getDeviceSysLocale ;
220
+ getDeviceProductLanguage = generalMethods . getDeviceProductLanguage ;
221
+ getDeviceProductCountry = generalMethods . getDeviceProductCountry ;
222
+ getDeviceProductLocale = generalMethods . getDeviceProductLocale ;
223
+ getModel = generalMethods . getModel ;
224
+ getManufacturer = generalMethods . getManufacturer ;
225
+ getScreenSize = generalMethods . getScreenSize ;
226
+ getScreenDensity = generalMethods . getScreenDensity ;
227
+ setHttpProxy = generalMethods . setHttpProxy ;
228
+ deleteHttpProxy = generalMethods . deleteHttpProxy ;
229
+ setSetting = generalMethods . setSetting ;
230
+ getSetting = generalMethods . getSetting ;
231
+ bugreport = generalMethods . bugreport ;
232
+ screenrecord = generalMethods . screenrecord ;
233
+ runInImeContext = generalMethods . runInImeContext ;
234
+ getTimeZone = generalMethods . getTimeZone ;
235
+ listFeatures = generalMethods . listFeatures ;
236
+ isStreamedInstallSupported = generalMethods . isStreamedInstallSupported ;
237
+ isIncrementalInstallSupported = generalMethods . isIncrementalInstallSupported ;
238
+ getDeviceIdleWhitelist = generalMethods . getDeviceIdleWhitelist ;
239
+ addToDeviceIdleWhitelist = generalMethods . addToDeviceIdleWhitelist ;
240
+ takeScreenshot = generalMethods . takeScreenshot ;
241
+ setWifiState = generalMethods . setWifiState ;
242
+ setDataState = generalMethods . setDataState ;
243
+ listPorts = generalMethods . listPorts ;
244
+
245
+ executeApksigner = apkSigningMethods . executeApksigner ;
246
+ signWithDefaultCert = apkSigningMethods . signWithDefaultCert ;
247
+ signWithCustomCert = apkSigningMethods . signWithCustomCert ;
248
+ sign = apkSigningMethods . sign ;
249
+ zipAlignApk = apkSigningMethods . zipAlignApk ;
250
+ checkApkCert = apkSigningMethods . checkApkCert ;
251
+ getKeystoreHash = apkSigningMethods . getKeystoreHash ;
252
+
253
+ APP_INSTALL_STATE = apkUtilsMethods . APP_INSTALL_STATE ;
254
+ isAppInstalled = apkUtilsMethods . isAppInstalled ;
255
+ startUri = apkUtilsMethods . startUri ;
256
+ startApp = apkUtilsMethods . startApp ;
257
+ dumpWindows = apkUtilsMethods . dumpWindows ;
258
+ getFocusedPackageAndActivity = apkUtilsMethods . getFocusedPackageAndActivity ;
259
+ waitForActivityOrNot = apkUtilsMethods . waitForActivityOrNot ;
260
+ waitForActivity = apkUtilsMethods . waitForActivity ;
261
+ waitForNotActivity = apkUtilsMethods . waitForNotActivity ;
262
+ uninstallApk = apkUtilsMethods . uninstallApk ;
263
+ installFromDevicePath = apkUtilsMethods . installFromDevicePath ;
264
+ cacheApk = apkUtilsMethods . cacheApk ;
265
+ install = apkUtilsMethods . install ;
266
+ getApplicationInstallState = apkUtilsMethods . getApplicationInstallState ;
267
+ installOrUpgrade = apkUtilsMethods . installOrUpgrade ;
268
+ extractStringsFromApk = apkUtilsMethods . extractStringsFromApk ;
269
+ getDeviceLanguage = apkUtilsMethods . getDeviceLanguage ;
270
+ getDeviceCountry = apkUtilsMethods . getDeviceCountry ;
271
+ getDeviceLocale = apkUtilsMethods . getDeviceLocale ;
272
+ ensureCurrentLocale = apkUtilsMethods . ensureCurrentLocale ;
273
+ getApkInfo = apkUtilsMethods . getApkInfo ;
274
+ getPackageInfo = apkUtilsMethods . getPackageInfo ;
275
+ pullApk = apkUtilsMethods . pullApk ;
276
+ activateApp = apkUtilsMethods . activateApp ;
277
+
278
+ hideKeyboard = keyboardCommands . hideKeyboard ;
279
+ isSoftKeyboardPresent = keyboardCommands . isSoftKeyboardPresent ;
102
280
103
- export { DEFAULT_ADB_PORT , getAndroidBinaryPath , getSdkRootFromEnv } ;
281
+ isLockManagementSupported = lockManagementCommands . isLockManagementSupported ;
282
+ verifyLockCredential = lockManagementCommands . verifyLockCredential ;
283
+ clearLockCredential = lockManagementCommands . clearLockCredential ;
284
+ isLockEnabled = lockManagementCommands . isLockEnabled ;
285
+ setLockCredential = lockManagementCommands . setLockCredential ;
286
+ isScreenLocked = lockManagementCommands . isScreenLocked ;
287
+ dismissKeyguard = lockManagementCommands . dismissKeyguard ;
288
+ cycleWakeUp = lockManagementCommands . cycleWakeUp ;
289
+
290
+ getSdkBinaryPath = systemCallMethods . getSdkBinaryPath ;
291
+ getBinaryNameForOS = systemCallMethods . getBinaryNameForOS ;
292
+ getBinaryFromSdkRoot = systemCallMethods . getBinaryFromSdkRoot ;
293
+ getBinaryFromPath = systemCallMethods . getBinaryFromPath ;
294
+ getConnectedDevices = systemCallMethods . getConnectedDevices ;
295
+ getDevicesWithRetry = systemCallMethods . getDevicesWithRetry ;
296
+ reconnect = systemCallMethods . reconnect ;
297
+ restartAdb = systemCallMethods . restartAdb ;
298
+ killServer = systemCallMethods . killServer ;
299
+ resetTelnetAuthToken = systemCallMethods . resetTelnetAuthToken ;
300
+ adbExecEmu = systemCallMethods . adbExecEmu ;
301
+ EXEC_OUTPUT_FORMAT = systemCallMethods . EXEC_OUTPUT_FORMAT ;
302
+ adbExec = systemCallMethods . adbExec ;
303
+ shell = systemCallMethods . shell ;
304
+ createSubProcess = systemCallMethods . createSubProcess ;
305
+ getAdbServerPort = systemCallMethods . getAdbServerPort ;
306
+ getEmulatorPort = systemCallMethods . getEmulatorPort ;
307
+ getPortFromEmulatorString = systemCallMethods . getPortFromEmulatorString ;
308
+ getConnectedEmulators = systemCallMethods . getConnectedEmulators ;
309
+ setEmulatorPort = systemCallMethods . setEmulatorPort ;
310
+ setDeviceId = systemCallMethods . setDeviceId ;
311
+ setDevice = systemCallMethods . setDevice ;
312
+ getRunningAVD = systemCallMethods . getRunningAVD ;
313
+ getRunningAVDWithRetry = systemCallMethods . getRunningAVDWithRetry ;
314
+ killAllEmulators = systemCallMethods . killAllEmulators ;
315
+ killEmulator = systemCallMethods . killEmulator ;
316
+ launchAVD = systemCallMethods . launchAVD ;
317
+ getVersion = systemCallMethods . getVersion ;
318
+ waitForEmulatorReady = systemCallMethods . waitForEmulatorReady ;
319
+ waitForDevice = systemCallMethods . waitForDevice ;
320
+ reboot = systemCallMethods . reboot ;
321
+ changeUserPrivileges = systemCallMethods . changeUserPrivileges ;
322
+ root = systemCallMethods . root ;
323
+ unroot = systemCallMethods . unroot ;
324
+ isRoot = systemCallMethods . isRoot ;
325
+ fileExists = systemCallMethods . fileExists ;
326
+ ls = systemCallMethods . ls ;
327
+ fileSize = systemCallMethods . fileSize ;
328
+ installMitmCertificate = systemCallMethods . installMitmCertificate ;
329
+ isMitmCertificateInstalled = systemCallMethods . isMitmCertificateInstalled ;
330
+
331
+ execBundletool = apksUtilsMethods . execBundletool ;
332
+ getDeviceSpec = apksUtilsMethods . getDeviceSpec ;
333
+ installMultipleApks = apksUtilsMethods . installMultipleApks ;
334
+ installApks = apksUtilsMethods . installApks ;
335
+ extractBaseApk = apksUtilsMethods . extractBaseApk ;
336
+ extractLanguageApk = apksUtilsMethods . extractLanguageApk ;
337
+ isTestPackageOnlyError = apksUtilsMethods . isTestPackageOnlyError ;
338
+
339
+ packageAndLaunchActivityFromManifest = manifestMethods . packageAndLaunchActivityFromManifest ;
340
+ targetSdkVersionFromManifest = manifestMethods . targetSdkVersionFromManifest ;
341
+ targetSdkVersionUsingPKG = manifestMethods . targetSdkVersionUsingPKG ;
342
+ compileManifest = manifestMethods . compileManifest ;
343
+ insertManifest = manifestMethods . insertManifest ;
344
+ hasInternetPermissionFromManifest = manifestMethods . hasInternetPermissionFromManifest ;
345
+
346
+ extractUniversalApk = aabUtilsMethods . extractUniversalApk ;
347
+
348
+ isEmulatorConnected = emuMethods . isEmulatorConnected ;
349
+ verifyEmulatorConnected = emuMethods . verifyEmulatorConnected ;
350
+ fingerprint = emuMethods . fingerprint ;
351
+ rotate = emuMethods . rotate ;
352
+ powerAC = emuMethods . powerAC ;
353
+ sensorSet = emuMethods . sensorSet ;
354
+ powerCapacity = emuMethods . powerCapacity ;
355
+ powerOFF = emuMethods . powerOFF ;
356
+ sendSMS = emuMethods . sendSMS ;
357
+ gsmCall = emuMethods . gsmCall ;
358
+ gsmSignal = emuMethods . gsmSignal ;
359
+ gsmVoice = emuMethods . gsmVoice ;
360
+ networkSpeed = emuMethods . networkSpeed ;
361
+ execEmuConsoleCommand = emuMethods . execEmuConsoleCommand ;
362
+ getEmuVersionInfo = emuMethods . getEmuVersionInfo ;
363
+ getEmuImageProperties = emuMethods . getEmuImageProperties ;
364
+ checkAvdExist = emuMethods . checkAvdExist ;
365
+ POWER_AC_STATES = emuMethods . POWER_AC_STATES ;
366
+ GSM_CALL_ACTIONS = emuMethods . GSM_CALL_ACTIONS ;
367
+ GSM_VOICE_STATES = emuMethods . GSM_VOICE_STATES ;
368
+ GSM_SIGNAL_STRENGTHS = emuMethods . GSM_SIGNAL_STRENGTHS ;
369
+ NETWORK_SPEED = emuMethods . NETWORK_SPEED ;
370
+ SENSORS = emuMethods . SENSORS ;
371
+ }
0 commit comments