From a57109beba4d3ce38055f59da915dfd64dc8f0f6 Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Thu, 29 Oct 2015 13:56:34 -0700 Subject: [PATCH] Wait for sky server to start before starting device Instead of just waiting for the sky server process to start before we start the activity on the device, this causes us to wait for the sky server to actually start listening on its port Fixes #141 --- packages/flutter_tools/lib/src/device.dart | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index bb5ea053476..830f37bc190 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart @@ -5,6 +5,7 @@ library sky_tools.device; import 'dart:async'; +import 'dart:convert'; import 'dart:io'; import 'dart:math'; @@ -512,6 +513,9 @@ class AndroidDevice extends Device { static const String className = 'AndroidDevice'; static final String defaultDeviceID = 'default_android_device'; + static const String _kFlutterServerStartMessage = 'Serving'; + static const Duration _kFlutterServerTimeout = const Duration(seconds: 3); + String productID; String modelID; String deviceCodeName; @@ -773,8 +777,14 @@ class AndroidDevice extends Device { [adbPath, 'forward', observatoryPortString, observatoryPortString]); // Actually start the server. - await Process.start(sdkBinaryName('pub'), ['run', 'sky_tools:sky_server', _serverPort], - workingDirectory: serverRoot, mode: ProcessStartMode.DETACHED); + Process server = await Process.start( + sdkBinaryName('pub'), ['run', 'sky_tools:sky_server', _serverPort], + workingDirectory: serverRoot, + mode: ProcessStartMode.DETACHED_WITH_STDIO + ); + await server.stdout.transform(UTF8.decoder) + .firstWhere((String value) => value.startsWith(_kFlutterServerStartMessage)) + .timeout(_kFlutterServerTimeout); // Set up reverse port-forwarding so that the Android app can reach the // server running on localhost.