Unverified Commit 1725a26e 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. (#114834)

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