boot method

Future<String> boot(
  1. String avd, {
  2. String? webcam,
  3. void onProgress(
    1. int elapsedSec,
    2. String phase
    )?,
  4. Duration timeout = const Duration(minutes: 5),
  5. Duration progressEvery = const Duration(seconds: 15),
  6. Duration offlineLimit = const Duration(seconds: 60),
  7. List<String>? notes,
})

Boots avd detached from glint on a free console port, with gRPC asked for (the emulator does not always start it alone), and waits until Android has booted; returns its serial. A webcam id becomes its front camera; one Mac camera cannot back both, so the back keeps the AVD's own. When adb shows the emulator offline for offlineLimit, glint stops it (it started it) and boots once more with -no-snapshot-load, recording that in notes.

Implementation

Future<String> boot(
  String avd, {
  String? webcam,
  void Function(int elapsedSec, String phase)? onProgress,
  Duration timeout = const Duration(minutes: 5),
  Duration progressEvery = const Duration(seconds: 15),
  Duration offlineLimit = const Duration(seconds: 60),
  List<String>? notes,
}) async {
  final exe = emulatorPath;
  if (exe == null) {
    throw AvdBootError('found no Android emulator binary',
        detail: 'looked next to adb and under ANDROID_HOME, ANDROID_SDK_ROOT and the default SDK folder');
  }
  final clock = Stopwatch()..start();
  final first = await _start(exe, avd, webcam: webcam);
  try {
    return await _awaitBoot(first, clock, timeout, progressEvery, offlineLimit, onProgress);
  } on _StuckOffline catch (stuck) {
    onProgress?.call(clock.elapsed.inSeconds,
        'adb kept ${first.serial} offline for ${stuck.offlineSec}s, restarting $avd with a cold boot');
    await _stop(first);
    final second = await _start(exe, avd, webcam: webcam, coldBoot: true);
    try {
      final serial = await _awaitBoot(second, clock, timeout, progressEvery, offlineLimit, onProgress);
      notes?.add('${first.serial} came up with adb offline from its saved snapshot, so glint restarted $avd with a '
          'cold boot (-no-snapshot-load); it now runs as $serial');
      return serial;
    } on _StuckOffline catch (again) {
      throw await _offlineError(avd, second.serial, again.offlineSec, offlineLimit,
          coldBooted: true, log: second.log, adbPath: adbPath);
    }
  }
}