phoneAppPids function
The pids of bundleId's main process on the phone udid (extensions excluded); empty when it is not running.
Implementation
Future<List<int>> phoneAppPids(String udid, String bundleId) async {
final apps = await _devicectl(['device', 'info', 'apps', '--device', udid, '--bundle-id', bundleId]);
final url = ((apps?['apps'] as List?)?.cast<Map>().firstOrNull)?['url'] as String?;
if (url == null) return const [];
final bundlePath = Uri.parse(url).path;
final procs = await _devicectl(['device', 'info', 'processes', '--device', udid]);
return [
for (final p in (procs?['runningProcesses'] as List? ?? const []).cast<Map>())
if (Uri.tryParse('${p['executable']}')?.path case final exe?
when exe.startsWith(bundlePath) && !exe.substring(bundlePath.length).contains('/'))
(p['processIdentifier'] as num).toInt(),
];
}