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 @@ ...@@ -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,39 @@ class FuchsiaRemoteConnection { ...@@ -506,6 +507,39 @@ class FuchsiaRemoteConnection {
_pollDartVms = true; _pollDartVms = true;
} }
/// 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 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 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(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. /// 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 +548,14 @@ class FuchsiaRemoteConnection { ...@@ -514,24 +548,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 List<String> 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 dynamic 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