Merge pull request #2588 from flutter/revert-2506-device_port_forward
Revert "Add DevicePortForwarder"
This commit is contained in:
commit
c62ce87cf5
@ -51,7 +51,6 @@ class AndroidDevice extends Device {
|
|||||||
bool get isLocalEmulator => false;
|
bool get isLocalEmulator => false;
|
||||||
|
|
||||||
_AdbLogReader _logReader;
|
_AdbLogReader _logReader;
|
||||||
_AndroidDevicePortForwarder _portForwarder;
|
|
||||||
|
|
||||||
List<String> adbCommandForDevice(List<String> args) {
|
List<String> adbCommandForDevice(List<String> args) {
|
||||||
return <String>[androidSdk.adbPath, '-s', id]..addAll(args);
|
return <String>[androidSdk.adbPath, '-s', id]..addAll(args);
|
||||||
@ -170,10 +169,19 @@ class AndroidDevice extends Device {
|
|||||||
Future _forwardObservatoryPort(int port) async {
|
Future _forwardObservatoryPort(int port) async {
|
||||||
bool portWasZero = port == 0;
|
bool portWasZero = port == 0;
|
||||||
|
|
||||||
|
if (port == 0) {
|
||||||
|
// Auto-bind to a port. Set up forwarding for that port. Emit a stdout
|
||||||
|
// message similar to the command-line VM so that tools can parse the output.
|
||||||
|
// "Observatory listening on http://127.0.0.1:52111"
|
||||||
|
port = await findAvailablePort();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Set up port forwarding for observatory.
|
// Set up port forwarding for observatory.
|
||||||
port = await portForwarder.forward(observatoryDefaultPort,
|
runCheckedSync(adbCommandForDevice(<String>[
|
||||||
hostPort: port);
|
'forward', 'tcp:$port', 'tcp:$observatoryDefaultPort'
|
||||||
|
]));
|
||||||
|
|
||||||
if (portWasZero)
|
if (portWasZero)
|
||||||
printStatus('Observatory listening on http://127.0.0.1:$port');
|
printStatus('Observatory listening on http://127.0.0.1:$port');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -284,13 +292,6 @@ class AndroidDevice extends Device {
|
|||||||
return _logReader;
|
return _logReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
DevicePortForwarder get portForwarder {
|
|
||||||
if (_portForwarder == null)
|
|
||||||
_portForwarder = new _AndroidDevicePortForwarder(this);
|
|
||||||
|
|
||||||
return _portForwarder;
|
|
||||||
}
|
|
||||||
|
|
||||||
void startTracing(AndroidApk apk) {
|
void startTracing(AndroidApk apk) {
|
||||||
runCheckedSync(adbCommandForDevice(<String>[
|
runCheckedSync(adbCommandForDevice(<String>[
|
||||||
'shell',
|
'shell',
|
||||||
@ -536,74 +537,3 @@ class _AdbLogReader extends DeviceLogReader {
|
|||||||
return other.device.id == device.id;
|
return other.device.id == device.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _AndroidDevicePortForwarder extends DevicePortForwarder {
|
|
||||||
_AndroidDevicePortForwarder(this.device);
|
|
||||||
|
|
||||||
final AndroidDevice device;
|
|
||||||
|
|
||||||
static int _extractPort(String portString) {
|
|
||||||
return int.parse(portString.trim(), onError: (_) => null);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ForwardedPort> get forwardedPorts {
|
|
||||||
final List<ForwardedPort> ports = <ForwardedPort>[];
|
|
||||||
|
|
||||||
String stdout = runCheckedSync(
|
|
||||||
<String>[
|
|
||||||
androidSdk.adbPath,
|
|
||||||
'forward',
|
|
||||||
'--list'
|
|
||||||
]);
|
|
||||||
|
|
||||||
List<String> lines = LineSplitter.split(stdout).toList();
|
|
||||||
for (String line in lines) {
|
|
||||||
if (line.startsWith(device.id)) {
|
|
||||||
List<String> splitLine = line.split("tcp:");
|
|
||||||
|
|
||||||
// Sanity check splitLine.
|
|
||||||
if (splitLine.length != 3)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Attempt to extract ports.
|
|
||||||
int hostPort = _extractPort(splitLine[1]);
|
|
||||||
int devicePort = _extractPort(splitLine[2]);
|
|
||||||
|
|
||||||
// Failed, skip.
|
|
||||||
if ((hostPort == null) || (devicePort == null))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
ports.add(new ForwardedPort(hostPort, devicePort));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ports;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<int> forward(int devicePort, {int hostPort: null}) async {
|
|
||||||
if ((hostPort == null) || (hostPort == 0)) {
|
|
||||||
// Auto select host port.
|
|
||||||
hostPort = await findAvailablePort();
|
|
||||||
}
|
|
||||||
|
|
||||||
runCheckedSync(
|
|
||||||
<String>[
|
|
||||||
androidSdk.adbPath,
|
|
||||||
'forward',
|
|
||||||
hostPort.toString(),
|
|
||||||
devicePort.toString()
|
|
||||||
]);
|
|
||||||
|
|
||||||
return hostPort;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future unforward(ForwardedPort forwardedPort) async {
|
|
||||||
runCheckedSync(
|
|
||||||
<String>[
|
|
||||||
androidSdk.adbPath,
|
|
||||||
'forward',
|
|
||||||
'--remove',
|
|
||||||
forwardedPort.hostPort.toString()
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -151,9 +151,6 @@ abstract class Device {
|
|||||||
/// Get the log reader for this device.
|
/// Get the log reader for this device.
|
||||||
DeviceLogReader get logReader;
|
DeviceLogReader get logReader;
|
||||||
|
|
||||||
/// Get the port forwarder for this device.
|
|
||||||
DevicePortForwarder get portForwarder;
|
|
||||||
|
|
||||||
/// Clear the device's logs.
|
/// Clear the device's logs.
|
||||||
void clearLogs();
|
void clearLogs();
|
||||||
|
|
||||||
@ -189,30 +186,6 @@ abstract class Device {
|
|||||||
String toString() => '$runtimeType $id';
|
String toString() => '$runtimeType $id';
|
||||||
}
|
}
|
||||||
|
|
||||||
class ForwardedPort {
|
|
||||||
ForwardedPort(this.hostPort, this.devicePort);
|
|
||||||
|
|
||||||
final int hostPort;
|
|
||||||
final int devicePort;
|
|
||||||
|
|
||||||
String toString() => 'ForwardedPort HOST:$hostPort to DEVICE:$devicePort';
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Forward ports from the host machine to the device.
|
|
||||||
abstract class DevicePortForwarder {
|
|
||||||
/// Returns a Future that completes with the current list of forwarded
|
|
||||||
/// ports for this device.
|
|
||||||
List<ForwardedPort> get forwardedPorts;
|
|
||||||
|
|
||||||
/// Forward [hostPort] on the host to [devicePort] on the device.
|
|
||||||
/// If [hostPort] is null, will auto select a host port.
|
|
||||||
/// Returns a Future that completes with the host port.
|
|
||||||
Future<int> forward(int devicePort, {int hostPort: null});
|
|
||||||
|
|
||||||
/// Stops forwarding [forwardedPort].
|
|
||||||
Future unforward(ForwardedPort forwardedPort);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Read the log for a particular device. Subclasses must implement `hashCode`
|
/// Read the log for a particular device. Subclasses must implement `hashCode`
|
||||||
/// and `operator ==` so that log readers that read from the same location can be
|
/// and `operator ==` so that log readers that read from the same location can be
|
||||||
/// de-duped. For example, two Android devices will both try and log using
|
/// de-duped. For example, two Android devices will both try and log using
|
||||||
|
@ -10,7 +10,6 @@ import 'package:path/path.dart' as path;
|
|||||||
|
|
||||||
import '../application_package.dart';
|
import '../application_package.dart';
|
||||||
import '../base/common.dart';
|
import '../base/common.dart';
|
||||||
import '../base/os.dart';
|
|
||||||
import '../base/process.dart';
|
import '../base/process.dart';
|
||||||
import '../build_configuration.dart';
|
import '../build_configuration.dart';
|
||||||
import '../device.dart';
|
import '../device.dart';
|
||||||
@ -66,8 +65,6 @@ class IOSDevice extends Device {
|
|||||||
|
|
||||||
_IOSDeviceLogReader _logReader;
|
_IOSDeviceLogReader _logReader;
|
||||||
|
|
||||||
_IOSDevicePortForwarder _portForwarder;
|
|
||||||
|
|
||||||
bool get isLocalEmulator => false;
|
bool get isLocalEmulator => false;
|
||||||
|
|
||||||
bool get supportsStartPaused => false;
|
bool get supportsStartPaused => false;
|
||||||
@ -233,13 +230,6 @@ class IOSDevice extends Device {
|
|||||||
return _logReader;
|
return _logReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
DevicePortForwarder get portForwarder {
|
|
||||||
if (_portForwarder == null)
|
|
||||||
_portForwarder = new _IOSDevicePortForwarder(this);
|
|
||||||
|
|
||||||
return _portForwarder;
|
|
||||||
}
|
|
||||||
|
|
||||||
void clearLogs() {
|
void clearLogs() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -320,28 +310,3 @@ class _IOSDeviceLogReader extends DeviceLogReader {
|
|||||||
return other.name == name;
|
return other.name == name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _IOSDevicePortForwarder extends DevicePortForwarder {
|
|
||||||
_IOSDevicePortForwarder(this.device);
|
|
||||||
|
|
||||||
final IOSDevice device;
|
|
||||||
|
|
||||||
List<ForwardedPort> get forwardedPorts {
|
|
||||||
final List<ForwardedPort> ports = <ForwardedPort>[];
|
|
||||||
// TODO(chinmaygarde): Implement.
|
|
||||||
return ports;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<int> forward(int devicePort, {int hostPort: null}) async {
|
|
||||||
if ((hostPort == null) || (hostPort == 0)) {
|
|
||||||
// Auto select host port.
|
|
||||||
hostPort = await findAvailablePort();
|
|
||||||
}
|
|
||||||
// TODO(chinmaygarde): Implement.
|
|
||||||
return hostPort;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future unforward(ForwardedPort forwardedPort) async {
|
|
||||||
// TODO(chinmaygarde): Implement.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -321,7 +321,6 @@ class IOSSimulator extends Device {
|
|||||||
bool get isLocalEmulator => true;
|
bool get isLocalEmulator => true;
|
||||||
|
|
||||||
_IOSSimulatorLogReader _logReader;
|
_IOSSimulatorLogReader _logReader;
|
||||||
_IOSSimulatorDevicePortForwarder _portForwarder;
|
|
||||||
|
|
||||||
String get xcrunPath => path.join('/usr', 'bin', 'xcrun');
|
String get xcrunPath => path.join('/usr', 'bin', 'xcrun');
|
||||||
|
|
||||||
@ -545,13 +544,6 @@ class IOSSimulator extends Device {
|
|||||||
return _logReader;
|
return _logReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
DevicePortForwarder get portForwarder {
|
|
||||||
if (_portForwarder == null)
|
|
||||||
_portForwarder = new _IOSSimulatorDevicePortForwarder(this);
|
|
||||||
|
|
||||||
return _portForwarder;
|
|
||||||
}
|
|
||||||
|
|
||||||
void clearLogs() {
|
void clearLogs() {
|
||||||
File logFile = new File(logFilePath);
|
File logFile = new File(logFilePath);
|
||||||
if (logFile.existsSync()) {
|
if (logFile.existsSync()) {
|
||||||
@ -780,28 +772,3 @@ int compareIphoneVersions(String id1, String id2) {
|
|||||||
int q2 = qualifiers.indexOf(m2[2]);
|
int q2 = qualifiers.indexOf(m2[2]);
|
||||||
return q1.compareTo(q2);
|
return q1.compareTo(q2);
|
||||||
}
|
}
|
||||||
|
|
||||||
class _IOSSimulatorDevicePortForwarder extends DevicePortForwarder {
|
|
||||||
_IOSSimulatorDevicePortForwarder(this.device);
|
|
||||||
|
|
||||||
final IOSSimulator device;
|
|
||||||
|
|
||||||
final List<ForwardedPort> _ports = <ForwardedPort>[];
|
|
||||||
|
|
||||||
List<ForwardedPort> get forwardedPorts {
|
|
||||||
return _ports;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<int> forward(int devicePort, {int hostPort: null}) async {
|
|
||||||
if ((hostPort == null) || (hostPort == 0)) {
|
|
||||||
hostPort = devicePort;
|
|
||||||
}
|
|
||||||
assert(devicePort == hostPort);
|
|
||||||
_ports.add(new ForwardedPort(devicePort, hostPort));
|
|
||||||
return hostPort;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future unforward(ForwardedPort forwardedPort) async {
|
|
||||||
_ports.remove(forwardedPort);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user