execute method

Future<ProcessResult> execute(
  1. List<String> arguments, {
  2. bool runInShell = true,
  3. bool checkIfRunning = true,
  4. Duration? timeout,
  5. bool debug = false,
})

Implementation

Future<io.ProcessResult> execute(
  List<String> arguments, {
  bool runInShell = true,
  bool checkIfRunning = true,
  Duration? timeout,
  bool debug = false,
}) async {
  final time = DateTime.now();

  if (debug) {
    final timeString = '${time.hour}:${time.minute}:${time.second}.${time.millisecond}';
    debugPrint('[$timeString] Executing $_adbPath ${arguments.join(' ')}');
  }

  await init();
  final process = io.Process.run(_adbPath!, arguments, runInShell: runInShell);
  final result;

  if (timeout != null) {
    result = await process.timeout(timeout);
  } else {
    result = await process;
  }

  if (debug) {
    final t2 = DateTime.now();
    final elapsed = t2.difference(time).inMilliseconds;
    final timeString = '${t2.hour}:${t2.minute}:${t2.second}.${t2.millisecond}';
    debugPrint('[$timeString] exitCode: ${result.exitCode}, elapsed: $elapsed ms');
  }

  if (checkIfRunning && result.exitCode != 0) {
    if (result.stderr.toString().contains(AdbDaemonNotRunningException.trigger)) {
      throw AdbDaemonNotRunningException(message: result.stderr.toString());
    }

    throw Exception(result.stderr);
  }
  return result;
}