Skip to content

Commit 9792f52

Browse files
committed
docs(android): document package listing helpers
1 parent b2ad407 commit 9792f52

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

lib/common/mobile/android/android-application-manager.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export class AndroidApplicationManager extends ApplicationManagerBase {
4242
super($logger, $hooksService, $deviceLogProvider);
4343
}
4444

45+
/**
46+
* Lists the identifiers of all packages installed on the device.
47+
* Falls back to listing packages per user when the plain listing yields
48+
* nothing, which happens on devices where shell cannot access every user.
49+
* @returns {Promise<string[]>} Unique package identifiers across all users.
50+
*/
4551
public async getInstalledApplications(): Promise<string[]> {
4652
if (!this.listPackagesPerUser) {
4753
const packages = this.parsePackageList(
@@ -74,6 +80,11 @@ export class AndroidApplicationManager extends ApplicationManagerBase {
7480
return _.uniq(packages);
7581
}
7682

83+
/**
84+
* Extracts package identifiers from `pm list packages` output.
85+
* @param {string} output Raw shell output, one `package:<id>` line per package.
86+
* @returns {string[]} The package identifiers, in output order.
87+
*/
7788
private parsePackageList(output: string): string[] {
7889
const regex = /package:(.+)/;
7990
return (output || "")
@@ -85,6 +96,10 @@ export class AndroidApplicationManager extends ApplicationManagerBase {
8596
.filter((parsedPackage: string) => parsedPackage !== null);
8697
}
8798

99+
/**
100+
* Lists the ids of all Android users on the device via `pm list users`.
101+
* @returns {Promise<string[]>} User ids as printed by the device, e.g. ["0", "150"].
102+
*/
88103
private async getUserIds(): Promise<string[]> {
89104
const output: string =
90105
(await this.adb.executeShellCommand(["pm", "list", "users"])) || "";

lib/common/test/unit-tests/android-application-manager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,11 @@ describe("android-application-manager", () => {
383383
"\tUserInfo{150:Secure Folder:1030} running",
384384
].join(EOL);
385385

386+
/**
387+
* Replaces the adb shell stub with one that records every command and
388+
* answers from the given map, keyed by the space-joined command arguments.
389+
* @param {Record<string, string>} outputs Shell output per command; unknown commands return "".
390+
*/
386391
function stubShellOutputs(outputs: Record<string, string>) {
387392
shellCalls = [];
388393
androidDebugBridge.executeShellCommand = async (args: string[]) => {

0 commit comments

Comments
 (0)