Commit 4c67885b authored by Danny Tuppeny's avatar Danny Tuppeny Committed by Danny Tuppeny

Add support for launching emulators

parent 4d7c3c77
...@@ -9,8 +9,10 @@ import 'package:meta/meta.dart'; ...@@ -9,8 +9,10 @@ import 'package:meta/meta.dart';
import '../android/android_sdk.dart'; import '../android/android_sdk.dart';
import '../android/android_workflow.dart'; import '../android/android_workflow.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/logger.dart';
import '../base/process.dart'; import '../base/process.dart';
import '../emulator.dart'; import '../emulator.dart';
import '../globals.dart';
import 'android_sdk.dart'; import 'android_sdk.dart';
class AndroidEmulators extends EmulatorDiscovery { class AndroidEmulators extends EmulatorDiscovery {
...@@ -39,11 +41,19 @@ class AndroidEmulator extends Emulator { ...@@ -39,11 +41,19 @@ class AndroidEmulator extends Emulator {
@override @override
String get label => _properties['avd.ini.displayname']; String get label => _properties['avd.ini.displayname'];
// @override @override
// Future<bool> launch() async { Future<bool> launch() async {
// // TODO: ... final Status status = logger.startProgress('Launching $id...');
// return null;Í final RunResult launchResult = await runAsync(<String>[getEmulatorPath(), '-avd', id]);
// } status.stop();
if (launchResult.exitCode != 0) {
printError('Error: emulator exited with exit code ${launchResult.exitCode}');
printError('$launchResult');
return false;
}
return true;
}
} }
/// Return the list of available emulator AVDs. /// Return the list of available emulator AVDs.
......
...@@ -12,6 +12,11 @@ import '../globals.dart'; ...@@ -12,6 +12,11 @@ import '../globals.dart';
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
class EmulatorsCommand extends FlutterCommand { class EmulatorsCommand extends FlutterCommand {
EmulatorsCommand() {
argParser.addOption('start',
help: 'The full or partial ID of the emulator to start.');
}
@override @override
final String name = 'emulators'; final String name = 'emulators';
...@@ -20,23 +25,46 @@ class EmulatorsCommand extends FlutterCommand { ...@@ -20,23 +25,46 @@ class EmulatorsCommand extends FlutterCommand {
@override @override
Future<Null> runCommand() async { Future<Null> runCommand() async {
if (!doctor.canListAnything) { if (doctor.workflows.every((Workflow w) => !w.canListEmulators)) {
throwToolExit( throwToolExit(
"Unable to locate emulators; please run 'flutter doctor' for " "Unable to query emulators; please run 'flutter doctor' for "
'information about installing additional components.', 'information about installing additional components.',
exitCode: 1); exitCode: 1);
} }
final List<Emulator> emulators = await emulatorManager.getAllAvailableEmulators().toList(); if (argResults.wasParsed('start')) {
await _startEmulator(argResults['start']);
} else {
await _listEmulators();
}
}
Future<Null> _startEmulator(String id) async {
final List<Emulator> emulators =
await emulatorManager.getEmulatorsById(id).toList();
if (emulators.isEmpty) { if (emulators.isEmpty) {
printStatus( printStatus("No emulator found that matches the ID '$id'.");
'No emulators available.\n\n' } else if (emulators.length > 1) {
// TODO: Change these when we support creation printStatus("More than one emulator matches the ID '$id':\n");
// 'You may need to create images using "flutter emulators --create"\n' Emulator.printEmulators(emulators);
'You may need to create one using Android Studio\n' } else {
'or visit https://flutter.io/setup/ for troubleshooting tips.'); emulators.first.launch();
final List<String> diagnostics = await emulatorManager.getEmulatorDiagnostics(); }
}
Future<Null> _listEmulators() async {
final List<Emulator> emulators =
await emulatorManager.getAllAvailableEmulators().toList();
if (emulators.isEmpty) {
printStatus('No emulators available.\n\n'
// TODO: Change these when we support creation
// 'You may need to create images using "flutter emulators --create"\n'
'You may need to create one using Android Studio\n'
'or visit https://flutter.io/setup/ for troubleshooting tips.');
final List<String> diagnostics =
await emulatorManager.getEmulatorDiagnostics();
if (diagnostics.isNotEmpty) { if (diagnostics.isNotEmpty) {
printStatus(''); printStatus('');
for (String diagnostic in diagnostics) { for (String diagnostic in diagnostics) {
...@@ -44,7 +72,8 @@ class EmulatorsCommand extends FlutterCommand { ...@@ -44,7 +72,8 @@ class EmulatorsCommand extends FlutterCommand {
} }
} }
} else { } else {
printStatus('${emulators.length} available ${pluralize('emulators', emulators.length)}:\n'); printStatus(
'${emulators.length} available ${pluralize('emulators', emulators.length)}:\n');
await Emulator.printEmulators(emulators); await Emulator.printEmulators(emulators);
} }
} }
......
...@@ -135,6 +135,8 @@ abstract class Emulator { ...@@ -135,6 +135,8 @@ abstract class Emulator {
return id == other.id; return id == other.id;
} }
void launch();
@override @override
String toString() => name; String toString() => name;
......
...@@ -61,4 +61,10 @@ class _MockEmulator extends Emulator { ...@@ -61,4 +61,10 @@ class _MockEmulator extends Emulator {
@override @override
final String label; final String label;
@override
void launch() {
throw new UnimplementedError('Not implemented in Mock');
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment