1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:process/process.dart';
6
7import '../base/io.dart';
8import '../base/logger.dart';
9import '../base/process.dart';
10
11/// Wraps iproxy command line tool port forwarding.
12///
13/// See https://github.com/libimobiledevice/libusbmuxd.
14class IProxy {
15 IProxy({
16 required String iproxyPath,
17 required Logger logger,
18 required ProcessManager processManager,
19 required MapEntry<String, String> dyLdLibEntry,
20 }) : _dyLdLibEntry = dyLdLibEntry,
21 _processUtils = ProcessUtils(processManager: processManager, logger: logger),
22 _logger = logger,
23 _iproxyPath = iproxyPath;
24
25 /// Create a [IProxy] for testing.
26 ///
27 /// This specifies the path to iproxy as 'iproxy` and the dyLdLibEntry as
28 /// 'DYLD_LIBRARY_PATH: /path/to/libs'.
29 factory IProxy.test({required Logger logger, required ProcessManager processManager}) {
30 return IProxy(
31 iproxyPath: 'iproxy',
32 logger: logger,
33 processManager: processManager,
34 dyLdLibEntry: const MapEntry<String, String>('DYLD_LIBRARY_PATH', '/path/to/libs'),
35 );
36 }
37
38 final String _iproxyPath;
39 final ProcessUtils _processUtils;
40 final Logger _logger;
41 final MapEntry<String, String> _dyLdLibEntry;
42
43 Future<Process> forward(int devicePort, int hostPort, String deviceId) {
44 // Usage: iproxy LOCAL_PORT:DEVICE_PORT --udid UDID
45 return _processUtils.start(<String>[
46 _iproxyPath,
47 '$hostPort:$devicePort',
48 '--udid',
49 deviceId,
50 if (_logger.isVerbose) '--debug',
51 ], environment: Map<String, String>.fromEntries(<MapEntry<String, String>>[_dyLdLibEntry]));
52 }
53}
54