Unverified Commit b187bc47 authored by Naud Ghebre's avatar Naud Ghebre Committed by GitHub

Switch the way we retrieve the vm_service_port from /hub to iquery, on device. (#114637)

* [fuchsia_remote_debug_protocol] Switch the way we retrieve the vm_service_port from /hub to iquery, on device.

* [fuchsia_remote_debug_protocol] Switch the way we retrieve the vm_service_port from /hub to iquery, on device.
parent 6ea01e6a
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:process/process.dart'; import 'package:process/process.dart';
...@@ -506,6 +507,28 @@ class FuchsiaRemoteConnection { ...@@ -506,6 +507,28 @@ class FuchsiaRemoteConnection {
_pollDartVms = true; _pollDartVms = true;
} }
/// Helper for getDeviceServicePorts() to extract the vm_service_port from
/// json response.
List<int> getVmServicePortFromInspectSnapshot(List<dynamic> inspectSnapshot) {
final ports = <int>[];
for (final item in inspectSnapshot) {
if (item['payload'] == null || !(item as Map).containsKey('payload')) continue;
final payload = item['payload'];
if (payload['root'] == null || !(payload as Map).containsKey('root')) continue;
final root = payload['root'];
if (root['vm_service_port'] == null ||
!(root as Map).containsKey('vm_service_port')) continue;
final int? port = int.tryParse(root['vm_service_port']);
if (port != null) {
ports.add(port);
}
}
return ports;
}
/// Gets the open Dart VM service ports on a remote Fuchsia device. /// Gets the open Dart VM service ports on a remote Fuchsia device.
/// ///
/// The method attempts to get service ports through an SSH connection. Upon /// The method attempts to get service ports through an SSH connection. Upon
...@@ -514,24 +537,14 @@ class FuchsiaRemoteConnection { ...@@ -514,24 +537,14 @@ class FuchsiaRemoteConnection {
/// found. An exception is thrown in the event of an actual error when /// found. An exception is thrown in the event of an actual error when
/// attempting to acquire the ports. /// attempting to acquire the ports.
Future<List<int>> getDeviceServicePorts() async { Future<List<int>> getDeviceServicePorts() async {
final List<String> portPaths = await _sshCommandRunner final inspectResult = await _sshCommandRunner
.run('/bin/find /hub -name vmservice-port'); .run('iquery --format json show \'**:root:vm_service_port\'');
final List<int> ports = <int>[]; final inspectOutputJson = jsonDecode(inspectResult.join('\n'));
for (final String path in portPaths) { final List<int> ports =
if (path == '') { getVmServicePortFromInspectSnapshot(inspectOutputJson);
continue;
} if (ports.length > 1) {
final List<String> lsOutput = throw StateError('More than one Flutter observatory port found');
await _sshCommandRunner.run('/bin/ls $path');
for (final String line in lsOutput) {
if (line == '') {
continue;
}
final int? port = int.tryParse(line);
if (port != null) {
ports.add(port);
}
}
} }
return ports; return ports;
} }
......
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