This reverts commit 7750872251.
This commit is contained in:
@@ -15,6 +15,7 @@ import '../base/common.dart' show throwToolExit;
|
||||
import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/logger.dart';
|
||||
import '../base/port_scanner.dart';
|
||||
import '../base/process.dart';
|
||||
import '../base/process_manager.dart';
|
||||
import '../base/utils.dart';
|
||||
@@ -843,7 +844,7 @@ class _AndroidDevicePortForwarder extends DevicePortForwarder {
|
||||
final int devicePort = _extractPort(splitLine[2]);
|
||||
|
||||
// Failed, skip.
|
||||
if (hostPort == null || devicePort == null)
|
||||
if ((hostPort == null) || (devicePort == null))
|
||||
continue;
|
||||
|
||||
ports.add(new ForwardedPort(hostPort, devicePort));
|
||||
@@ -854,30 +855,16 @@ class _AndroidDevicePortForwarder extends DevicePortForwarder {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> forward(int devicePort, {int hostPort}) async {
|
||||
hostPort ??= 0;
|
||||
final RunResult process = await runCheckedAsync(device.adbCommandForDevice(
|
||||
Future<int> forward(int devicePort, { int hostPort }) async {
|
||||
if ((hostPort == null) || (hostPort == 0)) {
|
||||
// Auto select host port.
|
||||
hostPort = await portScanner.findAvailablePort();
|
||||
}
|
||||
|
||||
await runCheckedAsync(device.adbCommandForDevice(
|
||||
<String>['forward', 'tcp:$hostPort', 'tcp:$devicePort']
|
||||
));
|
||||
|
||||
if (process.stderr.isNotEmpty)
|
||||
process.throwException('adb returned error:\n${process.stderr}');
|
||||
|
||||
if (process.exitCode != 0) {
|
||||
if (process.stdout.isNotEmpty)
|
||||
process.throwException('adb returned error:\n${process.stdout}');
|
||||
process.throwException('adb failed without a message');
|
||||
}
|
||||
|
||||
if (hostPort == 0) {
|
||||
if (process.stdout.isEmpty)
|
||||
process.throwException('adb did not report forwarded port');
|
||||
hostPort = int.tryParse(process.stdout) ?? (throw 'adb returned invalid port number:\n${process.stdout}');
|
||||
} else {
|
||||
if (process.stdout.isNotEmpty)
|
||||
process.throwException('adb returned error:\n${process.stdout}');
|
||||
}
|
||||
|
||||
return hostPort;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user