MCPcopy Create free account
hub / github.com/callstack/agent-device / resolveAndroidApp

Function resolveAndroidApp

src/platforms/android/app-lifecycle.ts:63–104  ·  view source on GitHub ↗
(
  device: DeviceInfo,
  app: string,
)

Source from the content-addressed store, hash-verified

61}
62
63export async function resolveAndroidApp(
64 device: DeviceInfo,
65 app: string,
66): Promise<AndroidAppResolution> {
67 const trimmed = app.trim();
68 if (classifyAndroidAppTarget(trimmed) === 'package') return { type: 'package', value: trimmed };
69
70 const alias = ALIASES[trimmed.toLowerCase()];
71 if (alias) return alias;
72
73 const cacheScope = androidAppResolutionScope(device);
74 const cached = androidAppResolutionCache.get(cacheScope, trimmed);
75 if (cached) return cached;
76
77 const result = await runAndroidAdb(device, ['shell', 'pm', 'list', 'packages']);
78 const packages = result.stdout
79 .split('\n')
80 .map((line: string) => line.replace('package:', '').trim())
81 .filter(Boolean);
82
83 const matches = packages.filter((pkg: string) =>
84 pkg.toLowerCase().includes(trimmed.toLowerCase()),
85 );
86 const match = matches[0];
87 if (match !== undefined && matches.length === 1) {
88 return androidAppResolutionCache.set(cacheScope, trimmed, {
89 type: 'package',
90 value: match,
91 });
92 }
93
94 if (matches.length > 1) {
95 throw new AppError('INVALID_ARGS', `Multiple packages matched "${app}"`, {
96 matches,
97 hint: ANDROID_AMBIGUOUS_APP_HINT,
98 });
99 }
100
101 throw new AppError('APP_NOT_INSTALLED', `No package found matching "${app}"`, {
102 hint: ANDROID_APPS_DISCOVERY_HINT,
103 });
104}
105
106export async function listAndroidApps(
107 device: DeviceInfo,

Callers 7

setAndroidSettingFunction · 0.90
index.test.tsFile · 0.90
openAndroidAppFunction · 0.85
closeAndroidAppFunction · 0.85
uninstallAndroidAppFunction · 0.85

Calls 5

classifyAndroidAppTargetFunction · 0.90
runAndroidAdbFunction · 0.90
getMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…