appium-adb 14.3.2 → 14.3.3
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.
- package/CHANGELOG.md +6 -0
- package/build/lib/adb.d.ts +9 -9
- package/build/lib/adb.d.ts.map +1 -1
- package/build/lib/adb.js +61 -61
- package/build/lib/adb.js.map +1 -1
- package/build/lib/logcat.d.ts.map +1 -1
- package/build/lib/logcat.js +1 -1
- package/build/lib/logcat.js.map +1 -1
- package/build/lib/tools/apk-utils.d.ts.map +1 -1
- package/build/lib/tools/apk-utils.js +29 -29
- package/build/lib/tools/apk-utils.js.map +1 -1
- package/build/lib/tools/apks-utils.d.ts.map +1 -1
- package/build/lib/tools/apks-utils.js +43 -43
- package/build/lib/tools/apks-utils.js.map +1 -1
- package/build/lib/tools/app-commands.d.ts +11 -11
- package/build/lib/tools/app-commands.d.ts.map +1 -1
- package/build/lib/tools/app-commands.js +0 -2
- package/build/lib/tools/app-commands.js.map +1 -1
- package/build/lib/tools/device-settings.d.ts.map +1 -1
- package/build/lib/tools/device-settings.js +12 -12
- package/build/lib/tools/device-settings.js.map +1 -1
- package/build/lib/tools/emulator-commands.d.ts.map +1 -1
- package/build/lib/tools/emulator-commands.js +42 -42
- package/build/lib/tools/emulator-commands.js.map +1 -1
- package/build/lib/tools/fs-commands.d.ts.map +1 -1
- package/build/lib/tools/fs-commands.js +3 -3
- package/build/lib/tools/fs-commands.js.map +1 -1
- package/build/lib/tools/lockmgmt.d.ts.map +1 -1
- package/build/lib/tools/lockmgmt.js +70 -70
- package/build/lib/tools/lockmgmt.js.map +1 -1
- package/build/lib/tools/system-calls.d.ts +6 -6
- package/build/lib/tools/system-calls.d.ts.map +1 -1
- package/build/lib/tools/system-calls.js +9 -11
- package/build/lib/tools/system-calls.js.map +1 -1
- package/lib/adb.ts +69 -69
- package/lib/logcat.ts +4 -6
- package/lib/tools/apk-utils.ts +37 -37
- package/lib/tools/apks-utils.ts +49 -49
- package/lib/tools/app-commands.ts +12 -16
- package/lib/tools/device-settings.ts +13 -13
- package/lib/tools/emulator-commands.ts +50 -50
- package/lib/tools/fs-commands.ts +4 -4
- package/lib/tools/lockmgmt.ts +82 -82
- package/lib/tools/system-calls.ts +9 -13
- package/package.json +1 -1
package/lib/logcat.ts
CHANGED
|
@@ -36,6 +36,8 @@ export interface LogcatOptions {
|
|
|
36
36
|
maxBufferSize?: number;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
type LogFormat = (typeof SUPPORTED_FORMATS)[number];
|
|
40
|
+
|
|
39
41
|
export class Logcat extends EventEmitter {
|
|
40
42
|
private readonly adb: ADBExecutable;
|
|
41
43
|
private readonly clearLogs: boolean;
|
|
@@ -187,12 +189,6 @@ export class Logcat extends EventEmitter {
|
|
|
187
189
|
}
|
|
188
190
|
}
|
|
189
191
|
|
|
190
|
-
export default Logcat;
|
|
191
|
-
|
|
192
|
-
// Private entities
|
|
193
|
-
|
|
194
|
-
type LogFormat = (typeof SUPPORTED_FORMATS)[number];
|
|
195
|
-
|
|
196
192
|
function requireFormat(format: string): LogFormat {
|
|
197
193
|
if (!SUPPORTED_FORMATS.includes(format as LogFormat)) {
|
|
198
194
|
log.info(`The format value '${format}' is unknown. Supported values are: ${SUPPORTED_FORMATS}`);
|
|
@@ -242,3 +238,5 @@ function formatFilterSpecs(filterSpecs: string | string[]): string[] {
|
|
|
242
238
|
.filter((spec) => spec && _.isString(spec) && !spec.startsWith('-'))
|
|
243
239
|
.map((spec) => (spec.includes(':') ? requireSpec(spec) : spec));
|
|
244
240
|
}
|
|
241
|
+
|
|
242
|
+
export default Logcat;
|
package/lib/tools/apk-utils.ts
CHANGED
|
@@ -583,43 +583,6 @@ export async function getApkInfo(this: ADB, appPath: string): Promise<AppInfo |
|
|
|
583
583
|
|
|
584
584
|
// #region Private functions
|
|
585
585
|
|
|
586
|
-
/**
|
|
587
|
-
* Formats the config marker, which is then passed to parse.. methods
|
|
588
|
-
* to make it compatible with resource formats generated by aapt(2) tool
|
|
589
|
-
*
|
|
590
|
-
* @param configsGetter The function whose result is a list
|
|
591
|
-
* of apk configs
|
|
592
|
-
* @param desiredMarker The desired config marker value
|
|
593
|
-
* @param defaultMarker The default config marker value
|
|
594
|
-
* @returns The formatted config marker
|
|
595
|
-
*/
|
|
596
|
-
async function formatConfigMarker(
|
|
597
|
-
configsGetter: () => Promise<string[]>,
|
|
598
|
-
desiredMarker: string | null,
|
|
599
|
-
defaultMarker: string,
|
|
600
|
-
): Promise<string> {
|
|
601
|
-
let configMarker = desiredMarker || defaultMarker;
|
|
602
|
-
if (configMarker.includes('-') && !configMarker.includes('-r')) {
|
|
603
|
-
configMarker = configMarker.replace('-', '-r');
|
|
604
|
-
}
|
|
605
|
-
const configs = await configsGetter();
|
|
606
|
-
log.debug(`Resource configurations: ${JSON.stringify(configs)}`);
|
|
607
|
-
// Assume the 'en' configuration is the default one
|
|
608
|
-
if (
|
|
609
|
-
configMarker.toLowerCase().startsWith('en') &&
|
|
610
|
-
!configs.some((x) => x.trim() === configMarker)
|
|
611
|
-
) {
|
|
612
|
-
log.debug(
|
|
613
|
-
`Resource configuration name '${configMarker}' is unknown. ` +
|
|
614
|
-
`Replacing it with '${defaultMarker}'`,
|
|
615
|
-
);
|
|
616
|
-
configMarker = defaultMarker;
|
|
617
|
-
} else {
|
|
618
|
-
log.debug(`Selected configuration: '${configMarker}'`);
|
|
619
|
-
}
|
|
620
|
-
return configMarker;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
586
|
/**
|
|
624
587
|
* Parses apk strings from aapt2 tool output
|
|
625
588
|
*
|
|
@@ -812,4 +775,41 @@ export function parseAaptStrings(rawOutput: string, configMarker: string): Strin
|
|
|
812
775
|
return apkStrings;
|
|
813
776
|
}
|
|
814
777
|
|
|
778
|
+
/**
|
|
779
|
+
* Formats the config marker, which is then passed to parse.. methods
|
|
780
|
+
* to make it compatible with resource formats generated by aapt(2) tool
|
|
781
|
+
*
|
|
782
|
+
* @param configsGetter The function whose result is a list
|
|
783
|
+
* of apk configs
|
|
784
|
+
* @param desiredMarker The desired config marker value
|
|
785
|
+
* @param defaultMarker The default config marker value
|
|
786
|
+
* @returns The formatted config marker
|
|
787
|
+
*/
|
|
788
|
+
async function formatConfigMarker(
|
|
789
|
+
configsGetter: () => Promise<string[]>,
|
|
790
|
+
desiredMarker: string | null,
|
|
791
|
+
defaultMarker: string,
|
|
792
|
+
): Promise<string> {
|
|
793
|
+
let configMarker = desiredMarker || defaultMarker;
|
|
794
|
+
if (configMarker.includes('-') && !configMarker.includes('-r')) {
|
|
795
|
+
configMarker = configMarker.replace('-', '-r');
|
|
796
|
+
}
|
|
797
|
+
const configs = await configsGetter();
|
|
798
|
+
log.debug(`Resource configurations: ${JSON.stringify(configs)}`);
|
|
799
|
+
// Assume the 'en' configuration is the default one
|
|
800
|
+
if (
|
|
801
|
+
configMarker.toLowerCase().startsWith('en') &&
|
|
802
|
+
!configs.some((x) => x.trim() === configMarker)
|
|
803
|
+
) {
|
|
804
|
+
log.debug(
|
|
805
|
+
`Resource configuration name '${configMarker}' is unknown. ` +
|
|
806
|
+
`Replacing it with '${defaultMarker}'`,
|
|
807
|
+
);
|
|
808
|
+
configMarker = defaultMarker;
|
|
809
|
+
} else {
|
|
810
|
+
log.debug(`Selected configuration: '${configMarker}'`);
|
|
811
|
+
}
|
|
812
|
+
return configMarker;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
815
|
// #endregion
|
package/lib/tools/apks-utils.ts
CHANGED
|
@@ -39,55 +39,6 @@ process.on('exit', () => {
|
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
/**
|
|
43
|
-
* Extracts the particular apks package into a temporary folder,
|
|
44
|
-
* finds and returns the full path to the file contained in this apk.
|
|
45
|
-
* The resulting temporary path, where the .apks file has been extracted,
|
|
46
|
-
* will be stored into the internal LRU cache for better performance.
|
|
47
|
-
*
|
|
48
|
-
* @param apks - The full path to the .apks file
|
|
49
|
-
* @param dstPath - The relative path to the destination file,
|
|
50
|
-
* which is going to be extracted, where each path component is an array item
|
|
51
|
-
* @returns Full path to the extracted file
|
|
52
|
-
* @throws {Error} If the requested item does not exist in the extracted archive or the provides
|
|
53
|
-
* apks file is not a valid bundle
|
|
54
|
-
*/
|
|
55
|
-
async function extractFromApks(apks: string, dstPath: string | string[]): Promise<string> {
|
|
56
|
-
const normalizedDstPath = _.isArray(dstPath) ? dstPath : [dstPath];
|
|
57
|
-
|
|
58
|
-
return await APKS_CACHE_GUARD.acquire(apks, async () => {
|
|
59
|
-
// It might be that the original file has been replaced,
|
|
60
|
-
// so we need to keep the hash sums instead of the actual file paths
|
|
61
|
-
// as caching keys
|
|
62
|
-
const apksHash = await fs.hash(apks);
|
|
63
|
-
log.debug(`Calculated '${apks}' hash: ${apksHash}`);
|
|
64
|
-
|
|
65
|
-
if (APKS_CACHE.has(apksHash)) {
|
|
66
|
-
const cachedRoot = APKS_CACHE.get(apksHash);
|
|
67
|
-
if (cachedRoot) {
|
|
68
|
-
const resultPath = path.resolve(cachedRoot, ...normalizedDstPath);
|
|
69
|
-
if (await fs.exists(resultPath)) {
|
|
70
|
-
return resultPath;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
APKS_CACHE.delete(apksHash);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const tmpRoot = await tempDir.openDir();
|
|
77
|
-
log.debug(`Unpacking application bundle at '${apks}' to '${tmpRoot}'`);
|
|
78
|
-
await unzipFile(apks, tmpRoot);
|
|
79
|
-
const resultPath = path.resolve(tmpRoot, ...normalizedDstPath);
|
|
80
|
-
if (!(await fs.exists(resultPath))) {
|
|
81
|
-
throw new Error(
|
|
82
|
-
`${normalizedDstPath.join(path.sep)} cannot be found in '${apks}' bundle. ` +
|
|
83
|
-
`Does the archive contain a valid application bundle?`,
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
APKS_CACHE.set(apksHash, tmpRoot);
|
|
87
|
-
return resultPath;
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
42
|
/**
|
|
92
43
|
* Executes bundletool utility with given arguments and returns the actual stdout
|
|
93
44
|
*
|
|
@@ -275,3 +226,52 @@ export async function extractLanguageApk(
|
|
|
275
226
|
export function isTestPackageOnlyError(output: string): boolean {
|
|
276
227
|
return /\[INSTALL_FAILED_TEST_ONLY\]/.test(output);
|
|
277
228
|
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Extracts the particular apks package into a temporary folder,
|
|
232
|
+
* finds and returns the full path to the file contained in this apk.
|
|
233
|
+
* The resulting temporary path, where the .apks file has been extracted,
|
|
234
|
+
* will be stored into the internal LRU cache for better performance.
|
|
235
|
+
*
|
|
236
|
+
* @param apks - The full path to the .apks file
|
|
237
|
+
* @param dstPath - The relative path to the destination file,
|
|
238
|
+
* which is going to be extracted, where each path component is an array item
|
|
239
|
+
* @returns Full path to the extracted file
|
|
240
|
+
* @throws {Error} If the requested item does not exist in the extracted archive or the provides
|
|
241
|
+
* apks file is not a valid bundle
|
|
242
|
+
*/
|
|
243
|
+
async function extractFromApks(apks: string, dstPath: string | string[]): Promise<string> {
|
|
244
|
+
const normalizedDstPath = _.isArray(dstPath) ? dstPath : [dstPath];
|
|
245
|
+
|
|
246
|
+
return await APKS_CACHE_GUARD.acquire(apks, async () => {
|
|
247
|
+
// It might be that the original file has been replaced,
|
|
248
|
+
// so we need to keep the hash sums instead of the actual file paths
|
|
249
|
+
// as caching keys
|
|
250
|
+
const apksHash = await fs.hash(apks);
|
|
251
|
+
log.debug(`Calculated '${apks}' hash: ${apksHash}`);
|
|
252
|
+
|
|
253
|
+
if (APKS_CACHE.has(apksHash)) {
|
|
254
|
+
const cachedRoot = APKS_CACHE.get(apksHash);
|
|
255
|
+
if (cachedRoot) {
|
|
256
|
+
const resultPath = path.resolve(cachedRoot, ...normalizedDstPath);
|
|
257
|
+
if (await fs.exists(resultPath)) {
|
|
258
|
+
return resultPath;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
APKS_CACHE.delete(apksHash);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const tmpRoot = await tempDir.openDir();
|
|
265
|
+
log.debug(`Unpacking application bundle at '${apks}' to '${tmpRoot}'`);
|
|
266
|
+
await unzipFile(apks, tmpRoot);
|
|
267
|
+
const resultPath = path.resolve(tmpRoot, ...normalizedDstPath);
|
|
268
|
+
if (!(await fs.exists(resultPath))) {
|
|
269
|
+
throw new Error(
|
|
270
|
+
`${normalizedDstPath.join(path.sep)} cannot be found in '${apks}' bundle. ` +
|
|
271
|
+
`Does the archive contain a valid application bundle?`,
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
APKS_CACHE.set(apksHash, tmpRoot);
|
|
275
|
+
return resultPath;
|
|
276
|
+
});
|
|
277
|
+
}
|
|
@@ -35,6 +35,18 @@ const LAUNCHER_CATEGORY = 'android.intent.category.LAUNCHER';
|
|
|
35
35
|
|
|
36
36
|
// Public methods
|
|
37
37
|
|
|
38
|
+
export interface StartCmdOptions {
|
|
39
|
+
user?: number | string;
|
|
40
|
+
waitForLaunch?: boolean;
|
|
41
|
+
pkg?: string;
|
|
42
|
+
activity?: string;
|
|
43
|
+
action?: string;
|
|
44
|
+
category?: string;
|
|
45
|
+
stopApp?: boolean;
|
|
46
|
+
flags?: string;
|
|
47
|
+
optionalIntentArguments?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
38
50
|
/**
|
|
39
51
|
* Verify whether the given argument is a
|
|
40
52
|
* valid class name.
|
|
@@ -1159,8 +1171,6 @@ export async function isAppRunning(this: ADB, pkg: string): Promise<boolean> {
|
|
|
1159
1171
|
return !_.isEmpty(await this.listAppProcessIds(pkg));
|
|
1160
1172
|
}
|
|
1161
1173
|
|
|
1162
|
-
// Private methods
|
|
1163
|
-
|
|
1164
1174
|
/**
|
|
1165
1175
|
* Parses optional intent arguments from a string.
|
|
1166
1176
|
*
|
|
@@ -1235,17 +1245,3 @@ function escapeShellArg(arg: string): string {
|
|
|
1235
1245
|
}
|
|
1236
1246
|
return arg.replace(/&/g, '\\&');
|
|
1237
1247
|
}
|
|
1238
|
-
|
|
1239
|
-
// Type definitions
|
|
1240
|
-
|
|
1241
|
-
export interface StartCmdOptions {
|
|
1242
|
-
user?: number | string;
|
|
1243
|
-
waitForLaunch?: boolean;
|
|
1244
|
-
pkg?: string;
|
|
1245
|
-
activity?: string;
|
|
1246
|
-
action?: string;
|
|
1247
|
-
category?: string;
|
|
1248
|
-
stopApp?: boolean;
|
|
1249
|
-
flags?: string;
|
|
1250
|
-
optionalIntentArguments?: string;
|
|
1251
|
-
}
|
|
@@ -288,19 +288,6 @@ export async function toggleGPSLocationProvider(this: ADB, enabled: boolean): Pr
|
|
|
288
288
|
await this.shell(['cmd', 'location', 'set-location-enabled', enabled ? 'true' : 'false']);
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
/**
|
|
292
|
-
* Decorates an exception message with a solution link
|
|
293
|
-
*
|
|
294
|
-
* @param e The error object to be decorated
|
|
295
|
-
* @returns Either the same error or the decorated one
|
|
296
|
-
*/
|
|
297
|
-
function decorateWriteSecureSettingsException(e: Error): Error {
|
|
298
|
-
if (_.includes(e.message, 'requires:android.permission.WRITE_SECURE_SETTINGS')) {
|
|
299
|
-
e.message = `Check https://github.com/appium/appium/issues/13802 for throubleshooting. ${e.message}`;
|
|
300
|
-
}
|
|
301
|
-
return e;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
291
|
/**
|
|
305
292
|
* Set hidden api policy to manage access to non-SDK APIs.
|
|
306
293
|
* https://developer.android.com/preview/restrictions-non-sdk-interfaces
|
|
@@ -715,6 +702,19 @@ export async function getScreenOrientation(this: ADB): Promise<number | null> {
|
|
|
715
702
|
|
|
716
703
|
// #region Private functions
|
|
717
704
|
|
|
705
|
+
/**
|
|
706
|
+
* Decorates an exception message with a solution link
|
|
707
|
+
*
|
|
708
|
+
* @param e The error object to be decorated
|
|
709
|
+
* @returns Either the same error or the decorated one
|
|
710
|
+
*/
|
|
711
|
+
function decorateWriteSecureSettingsException(e: Error): Error {
|
|
712
|
+
if (_.includes(e.message, 'requires:android.permission.WRITE_SECURE_SETTINGS')) {
|
|
713
|
+
e.message = `Check https://github.com/appium/appium/issues/13802 for throubleshooting. ${e.message}`;
|
|
714
|
+
}
|
|
715
|
+
return e;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
718
|
/**
|
|
719
719
|
* Reads SurfaceOrientation in dumpsys output
|
|
720
720
|
*
|
|
@@ -19,56 +19,6 @@ import type {
|
|
|
19
19
|
ExecTelnetOptions,
|
|
20
20
|
} from './types';
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
* Retrieves the list of available Android emulators
|
|
24
|
-
*
|
|
25
|
-
* @returns
|
|
26
|
-
*/
|
|
27
|
-
async function listEmulators(): Promise<EmuInfo[]> {
|
|
28
|
-
let avdsRoot = process.env.ANDROID_AVD_HOME;
|
|
29
|
-
if (await dirExists(avdsRoot ?? '')) {
|
|
30
|
-
return await getAvdConfigPaths(avdsRoot as string);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (avdsRoot) {
|
|
34
|
-
log.warn(
|
|
35
|
-
`The value of the ANDROID_AVD_HOME environment variable '${avdsRoot}' is not an existing directory`,
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const prefsRoot = await getAndroidPrefsRoot();
|
|
40
|
-
if (!prefsRoot) {
|
|
41
|
-
return [];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
avdsRoot = path.resolve(prefsRoot, 'avd');
|
|
45
|
-
if (!(await dirExists(avdsRoot))) {
|
|
46
|
-
log.debug(`Virtual devices config root '${avdsRoot}' is not an existing directory`);
|
|
47
|
-
return [];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return await getAvdConfigPaths(avdsRoot);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Get configuration paths of all virtual devices
|
|
55
|
-
*
|
|
56
|
-
* @param avdsRoot Path to the directory that contains the AVD .ini files
|
|
57
|
-
* @returns
|
|
58
|
-
*/
|
|
59
|
-
async function getAvdConfigPaths(avdsRoot: string): Promise<EmuInfo[]> {
|
|
60
|
-
const configs = await fs.glob('*.ini', {
|
|
61
|
-
cwd: avdsRoot,
|
|
62
|
-
absolute: true,
|
|
63
|
-
});
|
|
64
|
-
return configs
|
|
65
|
-
.map((confPath) => {
|
|
66
|
-
const avdName = path.basename(confPath).split('.').slice(0, -1).join('.');
|
|
67
|
-
return {name: avdName, config: confPath};
|
|
68
|
-
})
|
|
69
|
-
.filter(({name}) => _.trim(name));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
22
|
/**
|
|
73
23
|
* Check the emulator state.
|
|
74
24
|
*
|
|
@@ -480,6 +430,56 @@ export async function sendTelnetCommand(this: ADB, command: string): Promise<str
|
|
|
480
430
|
|
|
481
431
|
// #region Private functions
|
|
482
432
|
|
|
433
|
+
/**
|
|
434
|
+
* Retrieves the list of available Android emulators
|
|
435
|
+
*
|
|
436
|
+
* @returns
|
|
437
|
+
*/
|
|
438
|
+
async function listEmulators(): Promise<EmuInfo[]> {
|
|
439
|
+
let avdsRoot = process.env.ANDROID_AVD_HOME;
|
|
440
|
+
if (await dirExists(avdsRoot ?? '')) {
|
|
441
|
+
return await getAvdConfigPaths(avdsRoot as string);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
if (avdsRoot) {
|
|
445
|
+
log.warn(
|
|
446
|
+
`The value of the ANDROID_AVD_HOME environment variable '${avdsRoot}' is not an existing directory`,
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const prefsRoot = await getAndroidPrefsRoot();
|
|
451
|
+
if (!prefsRoot) {
|
|
452
|
+
return [];
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
avdsRoot = path.resolve(prefsRoot, 'avd');
|
|
456
|
+
if (!(await dirExists(avdsRoot))) {
|
|
457
|
+
log.debug(`Virtual devices config root '${avdsRoot}' is not an existing directory`);
|
|
458
|
+
return [];
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
return await getAvdConfigPaths(avdsRoot);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Get configuration paths of all virtual devices
|
|
466
|
+
*
|
|
467
|
+
* @param avdsRoot Path to the directory that contains the AVD .ini files
|
|
468
|
+
* @returns
|
|
469
|
+
*/
|
|
470
|
+
async function getAvdConfigPaths(avdsRoot: string): Promise<EmuInfo[]> {
|
|
471
|
+
const configs = await fs.glob('*.ini', {
|
|
472
|
+
cwd: avdsRoot,
|
|
473
|
+
absolute: true,
|
|
474
|
+
});
|
|
475
|
+
return configs
|
|
476
|
+
.map((confPath) => {
|
|
477
|
+
const avdName = path.basename(confPath).split('.').slice(0, -1).join('.');
|
|
478
|
+
return {name: avdName, config: confPath};
|
|
479
|
+
})
|
|
480
|
+
.filter(({name}) => _.trim(name));
|
|
481
|
+
}
|
|
482
|
+
|
|
483
483
|
/**
|
|
484
484
|
* Retrieves the full path to the Android preferences root
|
|
485
485
|
*
|
package/lib/tools/fs-commands.ts
CHANGED
|
@@ -3,10 +3,6 @@ import path from 'node:path';
|
|
|
3
3
|
import type {ADB} from '../adb';
|
|
4
4
|
import type {TeenProcessExecOptions} from 'teen_process';
|
|
5
5
|
|
|
6
|
-
function shellEscapeSingleQuotes(str: string): string {
|
|
7
|
-
return str.replace(/'/g, "'\\''");
|
|
8
|
-
}
|
|
9
|
-
|
|
10
6
|
/**
|
|
11
7
|
* Verify whether a remote path exists on the device under test.
|
|
12
8
|
*
|
|
@@ -132,3 +128,7 @@ export async function pull(
|
|
|
132
128
|
export async function mkdir(this: ADB, remotePath: string): Promise<string> {
|
|
133
129
|
return await this.shell([`mkdir -p -- '${shellEscapeSingleQuotes(remotePath)}'`]);
|
|
134
130
|
}
|
|
131
|
+
|
|
132
|
+
function shellEscapeSingleQuotes(str: string): string {
|
|
133
|
+
return str.replace(/'/g, "'\\''");
|
|
134
|
+
}
|
package/lib/tools/lockmgmt.ts
CHANGED
|
@@ -11,51 +11,6 @@ const KEYCODE_POWER = 26;
|
|
|
11
11
|
const KEYCODE_WAKEUP = 224; // works over API Level 20
|
|
12
12
|
const HIDE_KEYBOARD_WAIT_TIME = 100;
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* @param verb
|
|
16
|
-
* @param oldCredential
|
|
17
|
-
* @param args
|
|
18
|
-
*/
|
|
19
|
-
function buildCommand(
|
|
20
|
-
verb: string,
|
|
21
|
-
oldCredential: string | null = null,
|
|
22
|
-
...args: string[]
|
|
23
|
-
): string[] {
|
|
24
|
-
const cmd = ['locksettings', verb];
|
|
25
|
-
if (oldCredential && !_.isEmpty(oldCredential)) {
|
|
26
|
-
cmd.push('--old', oldCredential);
|
|
27
|
-
}
|
|
28
|
-
if (!_.isEmpty(args)) {
|
|
29
|
-
cmd.push(...args);
|
|
30
|
-
}
|
|
31
|
-
return cmd;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Performs swipe up gesture on the screen
|
|
36
|
-
*
|
|
37
|
-
* @param windowDumpsys The output of `adb shell dumpsys window` command
|
|
38
|
-
* @throws {Error} If the display size cannot be retrieved
|
|
39
|
-
*/
|
|
40
|
-
async function swipeUp(this: ADB, windowDumpsys: string): Promise<void> {
|
|
41
|
-
const dimensionsMatch = /init=(\d+)x(\d+)/.exec(windowDumpsys);
|
|
42
|
-
if (!dimensionsMatch) {
|
|
43
|
-
throw new Error('Cannot retrieve the display size');
|
|
44
|
-
}
|
|
45
|
-
const displayWidth = parseInt(dimensionsMatch[1], 10);
|
|
46
|
-
const displayHeight = parseInt(dimensionsMatch[2], 10);
|
|
47
|
-
const x0 = displayWidth / 2;
|
|
48
|
-
const y0 = (displayHeight / 5) * 4;
|
|
49
|
-
const x1 = x0;
|
|
50
|
-
const y1 = displayHeight / 5;
|
|
51
|
-
await this.shell([
|
|
52
|
-
'input',
|
|
53
|
-
'touchscreen',
|
|
54
|
-
'swipe',
|
|
55
|
-
...[x0, y0, x1, y1].map((c) => `${Math.trunc(c)}`),
|
|
56
|
-
]);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
14
|
/**
|
|
60
15
|
* Check whether the device supports lock settings management with `locksettings`
|
|
61
16
|
* command line tool. This tool has been added to Android toolset since API 27 Oreo
|
|
@@ -323,8 +278,90 @@ export async function lock(this: ADB): Promise<void> {
|
|
|
323
278
|
}
|
|
324
279
|
}
|
|
325
280
|
|
|
281
|
+
/**
|
|
282
|
+
* Checks mShowingLockscreen or mDreamingLockscreen in dumpsys output to determine
|
|
283
|
+
* if lock screen is showing
|
|
284
|
+
*
|
|
285
|
+
* A note: `adb shell dumpsys trust` performs better while detecting the locked screen state
|
|
286
|
+
* in comparison to `adb dumpsys window` output parsing.
|
|
287
|
+
* But the trust command does not work for `Swipe` unlock pattern.
|
|
288
|
+
*
|
|
289
|
+
* In some Android devices (Probably around Android 10+), `mShowingLockscreen` and `mDreamingLockscreen`
|
|
290
|
+
* do not work to detect lock status. Instead, keyguard preferences helps to detect the lock condition.
|
|
291
|
+
* Some devices such as Android TV do not have keyguard, so we should keep
|
|
292
|
+
* screen condition as this primary method.
|
|
293
|
+
*
|
|
294
|
+
* @param dumpsys - The output of dumpsys window command.
|
|
295
|
+
* @return True if lock screen is showing.
|
|
296
|
+
*/
|
|
297
|
+
export function isShowingLockscreen(dumpsys: string): boolean {
|
|
298
|
+
return (
|
|
299
|
+
_.some(['mShowingLockscreen=true', 'mDreamingLockscreen=true'], (x) => dumpsys.includes(x)) ||
|
|
300
|
+
// `mIsShowing` and `mInputRestricted` are `true` in lock condition. `false` is unlock condition.
|
|
301
|
+
_.every([/KeyguardStateMonitor[\n\s]+mIsShowing=true/, /\s+mInputRestricted=true/], (x) =>
|
|
302
|
+
x.test(dumpsys),
|
|
303
|
+
)
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Checks screenState has SCREEN_STATE_OFF in dumpsys output to determine
|
|
309
|
+
* possible lock screen.
|
|
310
|
+
*
|
|
311
|
+
* @param dumpsys - The output of dumpsys window command.
|
|
312
|
+
* @return True if lock screen is showing.
|
|
313
|
+
*/
|
|
314
|
+
export function isScreenStateOff(dumpsys: string): boolean {
|
|
315
|
+
return /\s+screenState=SCREEN_STATE_OFF/i.test(dumpsys);
|
|
316
|
+
}
|
|
317
|
+
|
|
326
318
|
// #region Private functions
|
|
327
319
|
|
|
320
|
+
/**
|
|
321
|
+
* @param verb
|
|
322
|
+
* @param oldCredential
|
|
323
|
+
* @param args
|
|
324
|
+
*/
|
|
325
|
+
function buildCommand(
|
|
326
|
+
verb: string,
|
|
327
|
+
oldCredential: string | null = null,
|
|
328
|
+
...args: string[]
|
|
329
|
+
): string[] {
|
|
330
|
+
const cmd = ['locksettings', verb];
|
|
331
|
+
if (oldCredential && !_.isEmpty(oldCredential)) {
|
|
332
|
+
cmd.push('--old', oldCredential);
|
|
333
|
+
}
|
|
334
|
+
if (!_.isEmpty(args)) {
|
|
335
|
+
cmd.push(...args);
|
|
336
|
+
}
|
|
337
|
+
return cmd;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Performs swipe up gesture on the screen
|
|
342
|
+
*
|
|
343
|
+
* @param windowDumpsys The output of `adb shell dumpsys window` command
|
|
344
|
+
* @throws {Error} If the display size cannot be retrieved
|
|
345
|
+
*/
|
|
346
|
+
async function swipeUp(this: ADB, windowDumpsys: string): Promise<void> {
|
|
347
|
+
const dimensionsMatch = /init=(\d+)x(\d+)/.exec(windowDumpsys);
|
|
348
|
+
if (!dimensionsMatch) {
|
|
349
|
+
throw new Error('Cannot retrieve the display size');
|
|
350
|
+
}
|
|
351
|
+
const displayWidth = parseInt(dimensionsMatch[1], 10);
|
|
352
|
+
const displayHeight = parseInt(dimensionsMatch[2], 10);
|
|
353
|
+
const x0 = displayWidth / 2;
|
|
354
|
+
const y0 = (displayHeight / 5) * 4;
|
|
355
|
+
const x1 = x0;
|
|
356
|
+
const y1 = displayHeight / 5;
|
|
357
|
+
await this.shell([
|
|
358
|
+
'input',
|
|
359
|
+
'touchscreen',
|
|
360
|
+
'swipe',
|
|
361
|
+
...[x0, y0, x1, y1].map((c) => `${Math.trunc(c)}`),
|
|
362
|
+
]);
|
|
363
|
+
}
|
|
364
|
+
|
|
328
365
|
/**
|
|
329
366
|
* Checks mScreenOnFully in dumpsys output to determine if screen is showing
|
|
330
367
|
* Default is true.
|
|
@@ -365,41 +402,4 @@ function isInDozingMode(dumpsys: string): boolean {
|
|
|
365
402
|
return /^[\s\w]+wakefulness[^=]*=Dozing$/im.test(dumpsys);
|
|
366
403
|
}
|
|
367
404
|
|
|
368
|
-
/**
|
|
369
|
-
* Checks mShowingLockscreen or mDreamingLockscreen in dumpsys output to determine
|
|
370
|
-
* if lock screen is showing
|
|
371
|
-
*
|
|
372
|
-
* A note: `adb shell dumpsys trust` performs better while detecting the locked screen state
|
|
373
|
-
* in comparison to `adb dumpsys window` output parsing.
|
|
374
|
-
* But the trust command does not work for `Swipe` unlock pattern.
|
|
375
|
-
*
|
|
376
|
-
* In some Android devices (Probably around Android 10+), `mShowingLockscreen` and `mDreamingLockscreen`
|
|
377
|
-
* do not work to detect lock status. Instead, keyguard preferences helps to detect the lock condition.
|
|
378
|
-
* Some devices such as Android TV do not have keyguard, so we should keep
|
|
379
|
-
* screen condition as this primary method.
|
|
380
|
-
*
|
|
381
|
-
* @param dumpsys - The output of dumpsys window command.
|
|
382
|
-
* @return True if lock screen is showing.
|
|
383
|
-
*/
|
|
384
|
-
export function isShowingLockscreen(dumpsys: string): boolean {
|
|
385
|
-
return (
|
|
386
|
-
_.some(['mShowingLockscreen=true', 'mDreamingLockscreen=true'], (x) => dumpsys.includes(x)) ||
|
|
387
|
-
// `mIsShowing` and `mInputRestricted` are `true` in lock condition. `false` is unlock condition.
|
|
388
|
-
_.every([/KeyguardStateMonitor[\n\s]+mIsShowing=true/, /\s+mInputRestricted=true/], (x) =>
|
|
389
|
-
x.test(dumpsys),
|
|
390
|
-
)
|
|
391
|
-
);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
* Checks screenState has SCREEN_STATE_OFF in dumpsys output to determine
|
|
396
|
-
* possible lock screen.
|
|
397
|
-
*
|
|
398
|
-
* @param dumpsys - The output of dumpsys window command.
|
|
399
|
-
* @return True if lock screen is showing.
|
|
400
|
-
*/
|
|
401
|
-
export function isScreenStateOff(dumpsys: string): boolean {
|
|
402
|
-
return /\s+screenState=SCREEN_STATE_OFF/i.test(dumpsys);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
405
|
// #endregion
|
|
@@ -43,7 +43,15 @@ const MIN_DELAY_ADB_API_LEVEL = 28;
|
|
|
43
43
|
const REQUIRED_SERVICES = ['activity', 'package', 'window'] as const;
|
|
44
44
|
const MAX_SHELL_BUFFER_LENGTH = 1000;
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Retrieve full path to the given binary.
|
|
48
|
+
*
|
|
49
|
+
* @param binaryName - The name of the binary
|
|
50
|
+
* @returns The full path to the binary
|
|
51
|
+
*/
|
|
52
|
+
export async function getSdkBinaryPath(this: ADB, binaryName: string): Promise<string> {
|
|
53
|
+
return await this.getBinaryFromSdkRoot(binaryName);
|
|
54
|
+
}
|
|
47
55
|
|
|
48
56
|
/**
|
|
49
57
|
* Retrieve full binary name for the current operating system.
|
|
@@ -93,18 +101,6 @@ async function getOpenSslForOs(): Promise<string> {
|
|
|
93
101
|
}
|
|
94
102
|
}
|
|
95
103
|
|
|
96
|
-
// Public methods
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Retrieve full path to the given binary.
|
|
100
|
-
*
|
|
101
|
-
* @param binaryName - The name of the binary
|
|
102
|
-
* @returns The full path to the binary
|
|
103
|
-
*/
|
|
104
|
-
export async function getSdkBinaryPath(this: ADB, binaryName: string): Promise<string> {
|
|
105
|
-
return await this.getBinaryFromSdkRoot(binaryName);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
104
|
export const getBinaryNameForOS = _.memoize(_getBinaryNameForOS);
|
|
109
105
|
|
|
110
106
|
/**
|