Switch the way we retrieve the vm_service_port from /hub to iquery, on device. (#114834)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:process/process.dart';
|
||||
@@ -506,6 +507,39 @@ class FuchsiaRemoteConnection {
|
||||
_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.
|
||||
///
|
||||
/// The method attempts to get service ports through an SSH connection. Upon
|
||||
@@ -514,24 +548,14 @@ class FuchsiaRemoteConnection {
|
||||
/// 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');
|
||||
final List<int> ports = <int>[];
|
||||
for (final String path in portPaths) {
|
||||
if (path == '') {
|
||||
continue;
|
||||
}
|
||||
final List<String> lsOutput =
|
||||
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);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user