Commit 83e6ee36 authored by John McCutchan's avatar John McCutchan

Sniff service protocol port from device

parent 882f849c
...@@ -17,6 +17,7 @@ import '../build_configuration.dart'; ...@@ -17,6 +17,7 @@ import '../build_configuration.dart';
import '../device.dart'; import '../device.dart';
import '../flx.dart' as flx; import '../flx.dart' as flx;
import '../globals.dart'; import '../globals.dart';
import '../service_protocol.dart';
import '../toolchain.dart'; import '../toolchain.dart';
import 'adb.dart'; import 'adb.dart';
import 'android.dart'; import 'android.dart';
...@@ -185,12 +186,12 @@ class AndroidDevice extends Device { ...@@ -185,12 +186,12 @@ class AndroidDevice extends Device {
return true; return true;
} }
Future<Null> _forwardObservatoryPort(int port) async { Future<Null> _forwardObservatoryPort(int devicePort, int port) async {
bool portWasZero = port == 0; bool portWasZero = (port == null) || (port == 0);
try { try {
// Set up port forwarding for observatory. // Set up port forwarding for observatory.
port = await portForwarder.forward(observatoryDefaultPort, port = await portForwarder.forward(devicePort,
hostPort: port); hostPort: port);
if (portWasZero) if (portWasZero)
printStatus('Observatory listening on http://127.0.0.1:$port'); printStatus('Observatory listening on http://127.0.0.1:$port');
...@@ -214,13 +215,18 @@ class AndroidDevice extends Device { ...@@ -214,13 +215,18 @@ class AndroidDevice extends Device {
return false; return false;
} }
await _forwardObservatoryPort(debugPort);
if (clearLogs) if (clearLogs)
this.clearLogs(); this.clearLogs();
runCheckedSync(adbCommandForDevice(<String>['push', bundlePath, _deviceBundlePath])); runCheckedSync(adbCommandForDevice(<String>['push', bundlePath, _deviceBundlePath]));
ServiceProtocolDiscovery serviceProtocolDiscovery =
new ServiceProtocolDiscovery(logReader);
// We take this future here but do not wait for completion until *after*
// we start the bundle.
Future<int> serviceProtocolPort = serviceProtocolDiscovery.nextPort();
List<String> cmd = adbCommandForDevice(<String>[ List<String> cmd = adbCommandForDevice(<String>[
'shell', 'am', 'start', 'shell', 'am', 'start',
'-a', 'android.intent.action.RUN', '-a', 'android.intent.action.RUN',
...@@ -243,6 +249,13 @@ class AndroidDevice extends Device { ...@@ -243,6 +249,13 @@ class AndroidDevice extends Device {
printError(result.trim()); printError(result.trim());
return false; return false;
} }
// Wait for the service protocol port here. This will complete once
// the device has printed "Observatory is listening on..."
int devicePort = await serviceProtocolPort;
printTrace('service protocol port = $devicePort');
await _forwardObservatoryPort(devicePort, debugPort);
return true; return true;
} }
......
...@@ -199,7 +199,6 @@ class IOSDevice extends Device { ...@@ -199,7 +199,6 @@ class IOSDevice extends Device {
return false; return false;
} }
printTrace('Installation successful.');
return true; return true;
} }
......
...@@ -16,6 +16,7 @@ import '../build_configuration.dart'; ...@@ -16,6 +16,7 @@ import '../build_configuration.dart';
import '../device.dart'; import '../device.dart';
import '../flx.dart' as flx; import '../flx.dart' as flx;
import '../globals.dart'; import '../globals.dart';
import '../service_protocol.dart';
import '../toolchain.dart'; import '../toolchain.dart';
import 'mac.dart'; import 'mac.dart';
...@@ -462,6 +463,13 @@ class IOSSimulator extends Device { ...@@ -462,6 +463,13 @@ class IOSSimulator extends Device {
if (!(await _setupUpdatedApplicationBundle(app, toolchain))) if (!(await _setupUpdatedApplicationBundle(app, toolchain)))
return false; return false;
ServiceProtocolDiscovery serviceProtocolDiscovery =
new ServiceProtocolDiscovery(logReader);
// We take this future here but do not wait for completion until *after*
// we start the application.
Future<int> serviceProtocolPort = serviceProtocolDiscovery.nextPort();
// Prepare launch arguments. // Prepare launch arguments.
List<String> args = <String>[ List<String> args = <String>[
"--flx=${path.absolute(path.join('build', 'app.flx'))}", "--flx=${path.absolute(path.join('build', 'app.flx'))}",
...@@ -486,7 +494,12 @@ class IOSSimulator extends Device { ...@@ -486,7 +494,12 @@ class IOSSimulator extends Device {
return false; return false;
} }
// Wait for the service protocol port here. This will complete once
// the device has printed "Observatory is listening on..."
int devicePort = await serviceProtocolPort;
printTrace('service protocol port = $devicePort');
printTrace('Successfully started ${app.name} on $id.'); printTrace('Successfully started ${app.name} on $id.');
printStatus('Observatory listening on http://127.0.0.1:$devicePort');
return true; return true;
} }
......
...@@ -29,7 +29,7 @@ class ServiceProtocolDiscovery { ...@@ -29,7 +29,7 @@ class ServiceProtocolDiscovery {
void _onLine(String line) { void _onLine(String line) {
int portNumber = 0; int portNumber = 0;
if (line.startsWith('Observatory listening on http://')) { if (line.contains('Observatory listening on http://')) {
try { try {
RegExp portExp = new RegExp(r"\d+.\d+.\d+.\d+:(\d+)"); RegExp portExp = new RegExp(r"\d+.\d+.\d+.\d+:(\d+)");
String port = portExp.firstMatch(line).group(1); String port = portExp.firstMatch(line).group(1);
......
...@@ -40,6 +40,11 @@ void main() { ...@@ -40,6 +40,11 @@ void main() {
const Duration(milliseconds: 100), onTimeout: () => 77); const Duration(milliseconds: 100), onTimeout: () => 77);
// Expect the timeout port. // Expect the timeout port.
expect(port, 77); expect(port, 77);
// Get next port future.
nextPort = discoverer.nextPort();
logReader.addLine(
'I/flutter : Observatory listening on http://127.0.0.1:52584');
expect(await nextPort, 52584);
}); });
}); });
} }
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