( device: DeviceInfo, app: string, )
| 61 | } |
| 62 | |
| 63 | export 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 | |
| 106 | export async function listAndroidApps( |
| 107 | device: DeviceInfo, |
no test coverage detected
searching dependent graphs…