foregroundPackage method

Future<String?> foregroundPackage(
  1. String serial
)

Whether deviceId is still booted / connected — the cheap check behind deviceGone, so a closed simulator is named instead of guessed at. The package in front on Android device serial (e.g. the launcher), or null when adb cannot tell.

Implementation

Future<String?> foregroundPackage(String serial) async {
  try {
    final res = await runBounded(adbPath, ['-s', serial, 'shell', 'dumpsys', 'activity', 'activities'],
        timeout: const Duration(seconds: 3), phase: 'adb dumpsys activity');
    final m = RegExp(r'topResumedActivity=ActivityRecord\{\S+ \S+ ([\w.]+)/').firstMatch(res.stdout as String);
    return m?.group(1);
  } on Object {
    return null;
  }
}