Todd Volkert 60c5ffc1a9 Switch many Device methods to be async (#9587)
`adb` can sometimes hang, which will in turn hang the Dart isolate if
we're using `Process.runSync()`. This changes many of the `Device` methods
to return `Future<T>` in order to allow them to use the async process
methods. A future change will add timeouts to the associated calls so
that we can properly alert the user to the hung `adb` process.

This is work towards #7102, #9567
2017-04-25 17:23:00 -07:00

45 lines
1.3 KiB
Dart

// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import '../application_package.dart';
import '../base/common.dart';
import '../build_info.dart';
import '../device.dart';
import '../globals.dart';
import '../runner/flutter_command.dart';
class StopCommand extends FlutterCommand {
@override
final String name = 'stop';
@override
final String description = 'Stop your Flutter app on an attached device.';
Device device;
@override
Future<Null> verifyThenRunCommand() async {
commandValidator();
device = await findTargetDevice();
if (device == null)
throwToolExit(null);
return super.verifyThenRunCommand();
}
@override
Future<Null> runCommand() async {
final TargetPlatform targetPlatform = await device.targetPlatform;
final ApplicationPackage app = applicationPackages.getPackageForPlatform(targetPlatform);
if (app == null) {
final String platformName = getNameForTargetPlatform(targetPlatform);
throwToolExit('No Flutter application for $platformName found in the current directory.');
}
printStatus('Stopping apps on ${device.name}.');
if (!await device.stopApp(app))
throwToolExit(null);
}
}