Ian Hickson | 449f4a6 | 2019-11-27 15:04:02 -0800 | [diff] [blame] | 1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
Ian Fischer | 81746e9 | 2015-09-11 12:20:20 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ian Fischer | 8cac55a | 2015-09-25 16:29:47 -0700 | [diff] [blame] | 5 | import 'dart:async'; |
Devon Carew | 4daee0c | 2016-03-14 09:41:00 -0700 | [diff] [blame] | 6 | import 'dart:math' as math; |
Ian Fischer | b72d67a | 2015-09-15 16:17:47 -0700 | [diff] [blame] | 7 | |
Jonah Williams | 5c52498 | 2019-06-18 15:23:14 -0700 | [diff] [blame] | 8 | import 'package:meta/meta.dart'; |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 9 | import 'package:process/process.dart'; |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 10 | import 'package:vm_service/vm_service.dart' as vm_service; |
Jonah Williams | 5c52498 | 2019-06-18 15:23:14 -0700 | [diff] [blame] | 11 | |
Jonah Williams | 46f0a5f | 2020-03-17 17:58:39 -0700 | [diff] [blame] | 12 | import 'android/android_device_discovery.dart'; |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 13 | import 'android/android_sdk.dart'; |
Jonah Williams | 46f0a5f | 2020-03-17 17:58:39 -0700 | [diff] [blame] | 14 | import 'android/android_workflow.dart'; |
Ian Fischer | 0cc758d | 2015-09-18 17:11:30 -0700 | [diff] [blame] | 15 | import 'application_package.dart'; |
Zachary Anderson | 61236c8 | 2019-05-06 09:26:58 -0700 | [diff] [blame] | 16 | import 'artifacts.dart'; |
includecmath | 6d46ff7 | 2020-09-03 08:30:04 +0800 | [diff] [blame] | 17 | import 'base/common.dart'; |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 18 | import 'base/config.dart'; |
John McCutchan | 0b737ac | 2016-11-29 07:54:20 -0800 | [diff] [blame] | 19 | import 'base/context.dart'; |
Ben Konyi | 3a5a3ea | 2020-07-29 10:05:40 -0700 | [diff] [blame] | 20 | import 'base/dds.dart'; |
Todd Volkert | 8bb2703 | 2017-01-06 16:51:44 -0800 | [diff] [blame] | 21 | import 'base/file_system.dart'; |
Christopher Fujino | ed482c3 | 2019-10-09 16:30:27 -0700 | [diff] [blame] | 22 | import 'base/io.dart'; |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 23 | import 'base/logger.dart'; |
Jonah Williams | ddb8177 | 2020-10-02 21:52:53 -0700 | [diff] [blame] | 24 | import 'base/os.dart'; |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 25 | import 'base/platform.dart'; |
Jonah Williams | 30c0fc1 | 2020-10-08 12:28:58 -0700 | [diff] [blame] | 26 | import 'base/terminal.dart'; |
| 27 | import 'base/user_messages.dart' hide userMessages; |
Devon Carew | 067715e | 2016-05-10 13:47:00 -0700 | [diff] [blame] | 28 | import 'base/utils.dart'; |
Jason Simmons | a590ee2 | 2016-05-12 12:22:15 -0700 | [diff] [blame] | 29 | import 'build_info.dart'; |
Jonah Williams | ddab09f | 2020-10-08 13:40:19 -0700 | [diff] [blame] | 30 | import 'devfs.dart'; |
Jonah Williams | 42ae15f | 2020-02-28 10:27:27 -0800 | [diff] [blame] | 31 | import 'features.dart'; |
Jonah Williams | b7c9c96 | 2018-10-22 16:48:17 -0700 | [diff] [blame] | 32 | import 'fuchsia/fuchsia_device.dart'; |
Jonah Williams | 0ecc7a4 | 2020-05-05 13:40:38 -0700 | [diff] [blame] | 33 | import 'fuchsia/fuchsia_sdk.dart'; |
| 34 | import 'fuchsia/fuchsia_workflow.dart'; |
Jonah Williams | 30c0fc1 | 2020-10-08 12:28:58 -0700 | [diff] [blame] | 35 | import 'globals.dart' as globals show logger; |
Devon Carew | 67046f9 | 2016-02-20 22:00:11 -0800 | [diff] [blame] | 36 | import 'ios/devices.dart'; |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 37 | import 'ios/ios_workflow.dart'; |
Devon Carew | 67046f9 | 2016-02-20 22:00:11 -0800 | [diff] [blame] | 38 | import 'ios/simulators.dart'; |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 39 | import 'linux/linux_device.dart'; |
| 40 | import 'macos/macos_device.dart'; |
Jonah Williams | 9f04086 | 2020-07-22 18:23:20 -0700 | [diff] [blame] | 41 | import 'macos/macos_workflow.dart'; |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 42 | import 'macos/xcode.dart'; |
Jonah Williams | 6b19184 | 2019-04-25 12:25:12 -0700 | [diff] [blame] | 43 | import 'project.dart'; |
Konstantin Scheglov | 38970f5 | 2018-04-10 09:37:16 -0700 | [diff] [blame] | 44 | import 'tester/flutter_tester.dart'; |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 45 | import 'version.dart'; |
Jonah Williams | 6f5f037 | 2019-02-26 16:58:24 -0800 | [diff] [blame] | 46 | import 'web/web_device.dart'; |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 47 | import 'windows/windows_device.dart'; |
Jonah Williams | ddb8177 | 2020-10-02 21:52:53 -0700 | [diff] [blame] | 48 | import 'windows/windows_workflow.dart'; |
Ian Fischer | b72d67a | 2015-09-15 16:17:47 -0700 | [diff] [blame] | 49 | |
Jonah Williams | 0acd3e6 | 2019-04-25 15:51:08 -0700 | [diff] [blame] | 50 | DeviceManager get deviceManager => context.get<DeviceManager>(); |
John McCutchan | 0b737ac | 2016-11-29 07:54:20 -0800 | [diff] [blame] | 51 | |
Jonah Williams | 5c52498 | 2019-06-18 15:23:14 -0700 | [diff] [blame] | 52 | /// A description of the kind of workflow the device supports. |
| 53 | class Category { |
| 54 | const Category._(this.value); |
| 55 | |
| 56 | static const Category web = Category._('web'); |
| 57 | static const Category desktop = Category._('desktop'); |
| 58 | static const Category mobile = Category._('mobile'); |
| 59 | |
| 60 | final String value; |
| 61 | |
| 62 | @override |
| 63 | String toString() => value; |
| 64 | } |
| 65 | |
| 66 | /// The platform sub-folder that a device type supports. |
| 67 | class PlatformType { |
| 68 | const PlatformType._(this.value); |
| 69 | |
| 70 | static const PlatformType web = PlatformType._('web'); |
| 71 | static const PlatformType android = PlatformType._('android'); |
| 72 | static const PlatformType ios = PlatformType._('ios'); |
| 73 | static const PlatformType linux = PlatformType._('linux'); |
| 74 | static const PlatformType macos = PlatformType._('macos'); |
| 75 | static const PlatformType windows = PlatformType._('windows'); |
| 76 | static const PlatformType fuchsia = PlatformType._('fuchsia'); |
| 77 | |
| 78 | final String value; |
| 79 | |
| 80 | @override |
| 81 | String toString() => value; |
| 82 | } |
| 83 | |
Jonah Williams | 08576cb | 2020-10-12 09:31:02 -0700 | [diff] [blame] | 84 | /// A discovery mechanism for flutter-supported development devices. |
Jonah Williams | 741608a | 2020-07-08 18:07:27 -0700 | [diff] [blame] | 85 | abstract class DeviceManager { |
Jonah Williams | 30c0fc1 | 2020-10-08 12:28:58 -0700 | [diff] [blame] | 86 | DeviceManager({ |
| 87 | @required Logger logger, |
| 88 | @required Terminal terminal, |
| 89 | @required UserMessages userMessages, |
| 90 | }) : _logger = logger, |
| 91 | _terminal = terminal, |
| 92 | _userMessages = userMessages; |
| 93 | |
| 94 | final Logger _logger; |
| 95 | final Terminal _terminal; |
| 96 | final UserMessages _userMessages; |
Jonah Williams | 8e2ea26 | 2019-01-31 18:42:30 -0800 | [diff] [blame] | 97 | |
Devon Carew | 2dbceaf | 2016-02-06 19:19:50 -0800 | [diff] [blame] | 98 | /// Constructing DeviceManagers is cheap; they only do expensive work if some |
Adam Barth | b1b6271 | 2016-05-24 17:53:04 -0700 | [diff] [blame] | 99 | /// of their methods are called. |
Jonah Williams | 741608a | 2020-07-08 18:07:27 -0700 | [diff] [blame] | 100 | List<DeviceDiscovery> get deviceDiscoverers; |
Jonah Williams | 6f5f037 | 2019-02-26 16:58:24 -0800 | [diff] [blame] | 101 | |
Zachary Anderson | 0770c3c | 2017-04-26 21:49:38 -0700 | [diff] [blame] | 102 | String _specifiedDeviceId; |
Devon Carew | 2dbceaf | 2016-02-06 19:19:50 -0800 | [diff] [blame] | 103 | |
Zachary Anderson | 0770c3c | 2017-04-26 21:49:38 -0700 | [diff] [blame] | 104 | /// A user-specified device ID. |
| 105 | String get specifiedDeviceId { |
Zachary Anderson | e2340c6 | 2019-09-13 14:51:35 -0700 | [diff] [blame] | 106 | if (_specifiedDeviceId == null || _specifiedDeviceId == 'all') { |
Zachary Anderson | 0770c3c | 2017-04-26 21:49:38 -0700 | [diff] [blame] | 107 | return null; |
Zachary Anderson | e2340c6 | 2019-09-13 14:51:35 -0700 | [diff] [blame] | 108 | } |
Zachary Anderson | 0770c3c | 2017-04-26 21:49:38 -0700 | [diff] [blame] | 109 | return _specifiedDeviceId; |
| 110 | } |
| 111 | |
| 112 | set specifiedDeviceId(String id) { |
| 113 | _specifiedDeviceId = id; |
| 114 | } |
| 115 | |
| 116 | /// True when the user has specified a single specific device. |
Devon Carew | 2dbceaf | 2016-02-06 19:19:50 -0800 | [diff] [blame] | 117 | bool get hasSpecifiedDeviceId => specifiedDeviceId != null; |
Devon Carew | 7ac4e62 | 2016-01-27 14:03:41 -0800 | [diff] [blame] | 118 | |
Zachary Anderson | 0770c3c | 2017-04-26 21:49:38 -0700 | [diff] [blame] | 119 | /// True when the user has specified all devices by setting |
| 120 | /// specifiedDeviceId = 'all'. |
| 121 | bool get hasSpecifiedAllDevices => _specifiedDeviceId == 'all'; |
| 122 | |
Jenn Magder | 85b54d4 | 2020-02-19 17:40:24 -0800 | [diff] [blame] | 123 | Future<List<Device>> getDevicesById(String deviceId) async { |
Jenn Magder | f9499f4 | 2020-07-24 16:15:44 -0700 | [diff] [blame] | 124 | final String lowerDeviceId = deviceId.toLowerCase(); |
Todd Volkert | 60c5ffc | 2017-04-25 17:23:00 -0700 | [diff] [blame] | 125 | bool exactlyMatchesDeviceId(Device device) => |
Jenn Magder | f9499f4 | 2020-07-24 16:15:44 -0700 | [diff] [blame] | 126 | device.id.toLowerCase() == lowerDeviceId || |
| 127 | device.name.toLowerCase() == lowerDeviceId; |
Todd Volkert | 60c5ffc | 2017-04-25 17:23:00 -0700 | [diff] [blame] | 128 | bool startsWithDeviceId(Device device) => |
Jenn Magder | f9499f4 | 2020-07-24 16:15:44 -0700 | [diff] [blame] | 129 | device.id.toLowerCase().startsWith(lowerDeviceId) || |
| 130 | device.name.toLowerCase().startsWith(lowerDeviceId); |
Devon Carew | 5ad6a57 | 2016-03-11 08:49:55 -0800 | [diff] [blame] | 131 | |
Jenn Magder | f9499f4 | 2020-07-24 16:15:44 -0700 | [diff] [blame] | 132 | // Some discoverers have hard-coded device IDs and return quickly, and others |
| 133 | // shell out to other processes and can take longer. |
| 134 | // Process discoverers as they can return results, so if an exact match is |
| 135 | // found quickly, we don't wait for all the discoverers to complete. |
| 136 | final List<Device> prefixMatches = <Device>[]; |
| 137 | final Completer<Device> exactMatchCompleter = Completer<Device>(); |
| 138 | final List<Future<List<Device>>> futureDevices = <Future<List<Device>>>[ |
| 139 | for (final DeviceDiscovery discoverer in _platformDiscoverers) |
| 140 | discoverer |
| 141 | .devices |
| 142 | .then((List<Device> devices) { |
| 143 | for (final Device device in devices) { |
| 144 | if (exactlyMatchesDeviceId(device)) { |
| 145 | exactMatchCompleter.complete(device); |
| 146 | return null; |
| 147 | } |
| 148 | if (startsWithDeviceId(device)) { |
| 149 | prefixMatches.add(device); |
| 150 | } |
| 151 | } |
| 152 | return null; |
| 153 | }, onError: (dynamic error, StackTrace stackTrace) { |
| 154 | // Return matches from other discoverers even if one fails. |
Jonah Williams | 30c0fc1 | 2020-10-08 12:28:58 -0700 | [diff] [blame] | 155 | _logger.printTrace('Ignored error discovering $deviceId: $error'); |
Jenn Magder | f9499f4 | 2020-07-24 16:15:44 -0700 | [diff] [blame] | 156 | }) |
| 157 | ]; |
| 158 | |
| 159 | // Wait for an exact match, or for all discoverers to return results. |
| 160 | await Future.any<dynamic>(<Future<dynamic>>[ |
| 161 | exactMatchCompleter.future, |
| 162 | Future.wait<List<Device>>(futureDevices), |
| 163 | ]); |
| 164 | |
| 165 | if (exactMatchCompleter.isCompleted) { |
| 166 | return <Device>[await exactMatchCompleter.future]; |
Todd Volkert | 60c5ffc | 2017-04-25 17:23:00 -0700 | [diff] [blame] | 167 | } |
Jenn Magder | f9499f4 | 2020-07-24 16:15:44 -0700 | [diff] [blame] | 168 | return prefixMatches; |
Devon Carew | 78e0588 | 2016-02-01 10:36:09 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Jenn Magder | 2f216ce | 2020-03-16 14:15:00 -0700 | [diff] [blame] | 171 | /// Returns the list of connected devices, filtered by any user-specified device id. |
Jenn Magder | 85b54d4 | 2020-02-19 17:40:24 -0800 | [diff] [blame] | 172 | Future<List<Device>> getDevices() { |
Todd Volkert | 60c5ffc | 2017-04-25 17:23:00 -0700 | [diff] [blame] | 173 | return hasSpecifiedDeviceId |
| 174 | ? getDevicesById(specifiedDeviceId) |
| 175 | : getAllConnectedDevices(); |
Devon Carew | 2dbceaf | 2016-02-06 19:19:50 -0800 | [diff] [blame] | 176 | } |
| 177 | |
Chris Bracken | 1d9f009 | 2017-06-19 13:14:57 -0700 | [diff] [blame] | 178 | Iterable<DeviceDiscovery> get _platformDiscoverers { |
Jonah Williams | 8e2ea26 | 2019-01-31 18:42:30 -0800 | [diff] [blame] | 179 | return deviceDiscoverers.where((DeviceDiscovery discoverer) => discoverer.supportsPlatform); |
Chris Bracken | 1d9f009 | 2017-06-19 13:14:57 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Jenn Magder | 2f216ce | 2020-03-16 14:15:00 -0700 | [diff] [blame] | 182 | /// Returns the list of all connected devices. |
Jenn Magder | 85b54d4 | 2020-02-19 17:40:24 -0800 | [diff] [blame] | 183 | Future<List<Device>> getAllConnectedDevices() async { |
| 184 | final List<List<Device>> devices = await Future.wait<List<Device>>(<Future<List<Device>>>[ |
| 185 | for (final DeviceDiscovery discoverer in _platformDiscoverers) |
| 186 | discoverer.devices, |
| 187 | ]); |
| 188 | |
| 189 | return devices.expand<Device>((List<Device> deviceList) => deviceList).toList(); |
Devon Carew | 7ac4e62 | 2016-01-27 14:03:41 -0800 | [diff] [blame] | 190 | } |
Devon Carew | 0350c9e | 2017-12-07 09:32:23 -0800 | [diff] [blame] | 191 | |
Jenn Magder | 2f216ce | 2020-03-16 14:15:00 -0700 | [diff] [blame] | 192 | /// Returns the list of all connected devices. Discards existing cache of devices. |
| 193 | Future<List<Device>> refreshAllConnectedDevices({ Duration timeout }) async { |
| 194 | final List<List<Device>> devices = await Future.wait<List<Device>>(<Future<List<Device>>>[ |
| 195 | for (final DeviceDiscovery discoverer in _platformDiscoverers) |
| 196 | discoverer.discoverDevices(timeout: timeout), |
| 197 | ]); |
| 198 | |
| 199 | return devices.expand<Device>((List<Device> deviceList) => deviceList).toList(); |
| 200 | } |
| 201 | |
Devon Carew | 0350c9e | 2017-12-07 09:32:23 -0800 | [diff] [blame] | 202 | /// Whether we're capable of listing any devices given the current environment configuration. |
| 203 | bool get canListAnything { |
| 204 | return _platformDiscoverers.any((DeviceDiscovery discoverer) => discoverer.canListAnything); |
| 205 | } |
| 206 | |
| 207 | /// Get diagnostics about issues with any connected devices. |
| 208 | Future<List<String>> getDeviceDiagnostics() async { |
Alexandre Ardhuin | 758009b | 2019-07-02 21:11:56 +0200 | [diff] [blame] | 209 | return <String>[ |
Alexandre Ardhuin | 4f9b6cf | 2020-01-07 16:32:04 +0100 | [diff] [blame] | 210 | for (final DeviceDiscovery discoverer in _platformDiscoverers) |
Alexandre Ardhuin | 758009b | 2019-07-02 21:11:56 +0200 | [diff] [blame] | 211 | ...await discoverer.getDiagnostics(), |
| 212 | ]; |
Devon Carew | 0350c9e | 2017-12-07 09:32:23 -0800 | [diff] [blame] | 213 | } |
Lau Ching Jun | c8cefce | 2019-06-26 10:09:14 -0700 | [diff] [blame] | 214 | |
| 215 | /// Find and return a list of devices based on the current project and environment. |
| 216 | /// |
Greg Spencer | a60bf8e | 2019-11-22 08:43:55 -0800 | [diff] [blame] | 217 | /// Returns a list of devices specified by the user. |
Jonah Williams | 1e26c41 | 2019-07-08 15:58:38 -0700 | [diff] [blame] | 218 | /// |
| 219 | /// * If the user specified '-d all', then return all connected devices which |
| 220 | /// support the current project, except for fuchsia and web. |
| 221 | /// |
| 222 | /// * If the user specified a device id, then do nothing as the list is already |
| 223 | /// filtered by [getDevices]. |
| 224 | /// |
| 225 | /// * If the user did not specify a device id and there is more than one |
| 226 | /// device connected, then filter out unsupported devices and prioritize |
| 227 | /// ephemeral devices. |
Jonah Williams | 1bea512 | 2020-10-02 21:12:50 -0700 | [diff] [blame] | 228 | /// |
| 229 | /// * If [flutterProject] is null, then assume the project supports all |
| 230 | /// device types. |
Jenn Magder | 6175183 | 2020-09-02 15:38:52 -0700 | [diff] [blame] | 231 | Future<List<Device>> findTargetDevices(FlutterProject flutterProject, { Duration timeout }) async { |
| 232 | if (timeout != null) { |
| 233 | // Reset the cache with the specified timeout. |
| 234 | await refreshAllConnectedDevices(timeout: timeout); |
| 235 | } |
| 236 | |
Jenn Magder | 85b54d4 | 2020-02-19 17:40:24 -0800 | [diff] [blame] | 237 | List<Device> devices = await getDevices(); |
Lau Ching Jun | c8cefce | 2019-06-26 10:09:14 -0700 | [diff] [blame] | 238 | |
Jonah Williams | 1e26c41 | 2019-07-08 15:58:38 -0700 | [diff] [blame] | 239 | // Always remove web and fuchsia devices from `--all`. This setting |
| 240 | // currently requires devices to share a frontend_server and resident |
Jonah Williams | 08576cb | 2020-10-12 09:31:02 -0700 | [diff] [blame] | 241 | // runner instance. Both web and fuchsia require differently configured |
Jonah Williams | 1e26c41 | 2019-07-08 15:58:38 -0700 | [diff] [blame] | 242 | // compilers, and web requires an entirely different resident runner. |
| 243 | if (hasSpecifiedAllDevices) { |
| 244 | devices = <Device>[ |
Alexandre Ardhuin | 4f9b6cf | 2020-01-07 16:32:04 +0100 | [diff] [blame] | 245 | for (final Device device in devices) |
Zachary Anderson | 0dfabb2 | 2019-10-28 09:38:08 -0700 | [diff] [blame] | 246 | if (await device.targetPlatform != TargetPlatform.fuchsia_arm64 && |
| 247 | await device.targetPlatform != TargetPlatform.fuchsia_x64 && |
Jonah Williams | 1e26c41 | 2019-07-08 15:58:38 -0700 | [diff] [blame] | 248 | await device.targetPlatform != TargetPlatform.web_javascript) |
Alexandre Ardhuin | f0553ba | 2019-09-30 18:48:23 +0200 | [diff] [blame] | 249 | device, |
Jonah Williams | 1e26c41 | 2019-07-08 15:58:38 -0700 | [diff] [blame] | 250 | ]; |
| 251 | } |
Lau Ching Jun | c8cefce | 2019-06-26 10:09:14 -0700 | [diff] [blame] | 252 | |
Jonah Williams | 1e26c41 | 2019-07-08 15:58:38 -0700 | [diff] [blame] | 253 | // If there is no specified device, the remove all devices which are not |
| 254 | // supported by the current application. For example, if there was no |
| 255 | // 'android' folder then don't attempt to launch with an Android device. |
| 256 | if (devices.length > 1 && !hasSpecifiedDeviceId) { |
| 257 | devices = <Device>[ |
Alexandre Ardhuin | 4f9b6cf | 2020-01-07 16:32:04 +0100 | [diff] [blame] | 258 | for (final Device device in devices) |
Jonah Williams | b257c33 | 2019-07-15 16:10:39 -0700 | [diff] [blame] | 259 | if (isDeviceSupportedForProject(device, flutterProject)) |
Alexandre Ardhuin | f0553ba | 2019-09-30 18:48:23 +0200 | [diff] [blame] | 260 | device, |
Jonah Williams | 1e26c41 | 2019-07-08 15:58:38 -0700 | [diff] [blame] | 261 | ]; |
Jonah Williams | b2a4ebe | 2019-08-29 21:39:38 -0700 | [diff] [blame] | 262 | } else if (devices.length == 1 && |
| 263 | !hasSpecifiedDeviceId && |
| 264 | !isDeviceSupportedForProject(devices.single, flutterProject)) { |
| 265 | // If there is only a single device but it is not supported, then return |
| 266 | // early. |
| 267 | return <Device>[]; |
Jonah Williams | 1e26c41 | 2019-07-08 15:58:38 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | // If there are still multiple devices and the user did not specify to run |
| 271 | // all, then attempt to prioritize ephemeral devices. For example, if the |
Natan Portilho | f567a0c | 2020-07-08 13:41:02 -0300 | [diff] [blame] | 272 | // user only typed 'flutter run' and both an Android device and desktop |
Jonah Williams | 08576cb | 2020-10-12 09:31:02 -0700 | [diff] [blame] | 273 | // device are available, choose the Android device. |
Jonah Williams | 1e26c41 | 2019-07-08 15:58:38 -0700 | [diff] [blame] | 274 | if (devices.length > 1 && !hasSpecifiedAllDevices) { |
Lau Ching Jun | c8cefce | 2019-06-26 10:09:14 -0700 | [diff] [blame] | 275 | // Note: ephemeral is nullable for device types where this is not well |
| 276 | // defined. |
| 277 | if (devices.any((Device device) => device.ephemeral == true)) { |
Natan Portilho | f567a0c | 2020-07-08 13:41:02 -0300 | [diff] [blame] | 278 | // if there is only one ephemeral device, get it |
| 279 | final List<Device> ephemeralDevices = devices |
Lau Ching Jun | c8cefce | 2019-06-26 10:09:14 -0700 | [diff] [blame] | 280 | .where((Device device) => device.ephemeral == true) |
| 281 | .toList(); |
Natan Portilho | f567a0c | 2020-07-08 13:41:02 -0300 | [diff] [blame] | 282 | |
| 283 | if (ephemeralDevices.length == 1){ |
| 284 | devices = ephemeralDevices; |
| 285 | } |
| 286 | } |
| 287 | // If it was not able to prioritize a device. For example, if the user |
| 288 | // has two active Android devices running, then we request the user to |
| 289 | // choose one. If the user has two nonEphemeral devices running, we also |
| 290 | // request input to choose one. |
Jonah Williams | 30c0fc1 | 2020-10-08 12:28:58 -0700 | [diff] [blame] | 291 | if (devices.length > 1 && _terminal.stdinHasTerminal) { |
| 292 | _logger.printStatus(_userMessages.flutterMultipleDevicesFound); |
| 293 | await Device.printDevices(devices, _logger); |
Natan Portilho | f567a0c | 2020-07-08 13:41:02 -0300 | [diff] [blame] | 294 | final Device chosenDevice = await _chooseOneOfAvailableDevices(devices); |
Jonah Williams | 30c0fc1 | 2020-10-08 12:28:58 -0700 | [diff] [blame] | 295 | specifiedDeviceId = chosenDevice.id; |
Natan Portilho | f567a0c | 2020-07-08 13:41:02 -0300 | [diff] [blame] | 296 | devices = <Device>[chosenDevice]; |
Lau Ching Jun | c8cefce | 2019-06-26 10:09:14 -0700 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | return devices; |
| 300 | } |
| 301 | |
Natan Portilho | f567a0c | 2020-07-08 13:41:02 -0300 | [diff] [blame] | 302 | Future<Device> _chooseOneOfAvailableDevices(List<Device> devices) async { |
| 303 | _displayDeviceOptions(devices); |
| 304 | final String userInput = await _readUserInput(devices.length); |
includecmath | 6d46ff7 | 2020-09-03 08:30:04 +0800 | [diff] [blame] | 305 | if (userInput.toLowerCase() == 'q') { |
| 306 | throwToolExit(''); |
| 307 | } |
J-P Nurmi | 612ef20 | 2020-12-21 18:29:05 +0100 | [diff] [blame] | 308 | return devices[int.parse(userInput) - 1]; |
Natan Portilho | f567a0c | 2020-07-08 13:41:02 -0300 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | void _displayDeviceOptions(List<Device> devices) { |
J-P Nurmi | 612ef20 | 2020-12-21 18:29:05 +0100 | [diff] [blame] | 312 | int count = 1; |
Natan Portilho | f567a0c | 2020-07-08 13:41:02 -0300 | [diff] [blame] | 313 | for (final Device device in devices) { |
Jonah Williams | 30c0fc1 | 2020-10-08 12:28:58 -0700 | [diff] [blame] | 314 | _logger.printStatus(_userMessages.flutterChooseDevice(count, device.name, device.id)); |
Natan Portilho | f567a0c | 2020-07-08 13:41:02 -0300 | [diff] [blame] | 315 | count++; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | Future<String> _readUserInput(int deviceCount) async { |
Jonah Williams | 30c0fc1 | 2020-10-08 12:28:58 -0700 | [diff] [blame] | 320 | _terminal.usesTerminalUi = true; |
| 321 | final String result = await _terminal.promptForCharInput( |
J-P Nurmi | 612ef20 | 2020-12-21 18:29:05 +0100 | [diff] [blame] | 322 | <String>[ for (int i = 0; i < deviceCount; i++) '${i + 1}', 'q', 'Q'], |
Jonah Williams | 30c0fc1 | 2020-10-08 12:28:58 -0700 | [diff] [blame] | 323 | displayAcceptedCharacters: false, |
| 324 | logger: _logger, |
| 325 | prompt: _userMessages.flutterChooseOne, |
| 326 | ); |
Natan Portilho | f567a0c | 2020-07-08 13:41:02 -0300 | [diff] [blame] | 327 | return result; |
| 328 | } |
| 329 | |
Lau Ching Jun | c8cefce | 2019-06-26 10:09:14 -0700 | [diff] [blame] | 330 | /// Returns whether the device is supported for the project. |
Jonah Williams | b257c33 | 2019-07-15 16:10:39 -0700 | [diff] [blame] | 331 | /// |
Jonah Williams | 1bea512 | 2020-10-02 21:12:50 -0700 | [diff] [blame] | 332 | /// This exists to allow the check to be overridden for google3 clients. If |
| 333 | /// [flutterProject] is null then return true. |
Lau Ching Jun | c8cefce | 2019-06-26 10:09:14 -0700 | [diff] [blame] | 334 | bool isDeviceSupportedForProject(Device device, FlutterProject flutterProject) { |
Jonah Williams | 1bea512 | 2020-10-02 21:12:50 -0700 | [diff] [blame] | 335 | if (flutterProject == null) { |
| 336 | return true; |
| 337 | } |
Lau Ching Jun | c8cefce | 2019-06-26 10:09:14 -0700 | [diff] [blame] | 338 | return device.isSupportedForProject(flutterProject); |
| 339 | } |
Devon Carew | 7ac4e62 | 2016-01-27 14:03:41 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Jonah Williams | 741608a | 2020-07-08 18:07:27 -0700 | [diff] [blame] | 342 | class FlutterDeviceManager extends DeviceManager { |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 343 | FlutterDeviceManager({ |
| 344 | @required Logger logger, |
| 345 | @required Platform platform, |
| 346 | @required ProcessManager processManager, |
| 347 | @required FileSystem fileSystem, |
| 348 | @required AndroidSdk androidSdk, |
| 349 | @required FeatureFlags featureFlags, |
| 350 | @required IOSSimulatorUtils iosSimulatorUtils, |
| 351 | @required XCDevice xcDevice, |
| 352 | @required AndroidWorkflow androidWorkflow, |
| 353 | @required IOSWorkflow iosWorkflow, |
| 354 | @required FuchsiaWorkflow fuchsiaWorkflow, |
| 355 | @required FlutterVersion flutterVersion, |
| 356 | @required Config config, |
| 357 | @required Artifacts artifacts, |
Jonah Williams | 9f04086 | 2020-07-22 18:23:20 -0700 | [diff] [blame] | 358 | @required MacOSWorkflow macOSWorkflow, |
Jonah Williams | 6180a4c | 2020-10-05 15:47:57 -0700 | [diff] [blame] | 359 | @required UserMessages userMessages, |
Jonah Williams | ddb8177 | 2020-10-02 21:52:53 -0700 | [diff] [blame] | 360 | @required OperatingSystemUtils operatingSystemUtils, |
| 361 | @required WindowsWorkflow windowsWorkflow, |
Jonah Williams | 30c0fc1 | 2020-10-08 12:28:58 -0700 | [diff] [blame] | 362 | @required Terminal terminal, |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 363 | }) : deviceDiscoverers = <DeviceDiscovery>[ |
Jonah Williams | 741608a | 2020-07-08 18:07:27 -0700 | [diff] [blame] | 364 | AndroidDevices( |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 365 | logger: logger, |
| 366 | androidSdk: androidSdk, |
Jonah Williams | 741608a | 2020-07-08 18:07:27 -0700 | [diff] [blame] | 367 | androidWorkflow: androidWorkflow, |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 368 | processManager: processManager, |
Jonah Williams | 6180a4c | 2020-10-05 15:47:57 -0700 | [diff] [blame] | 369 | fileSystem: fileSystem, |
| 370 | platform: platform, |
| 371 | userMessages: userMessages, |
Jonah Williams | 741608a | 2020-07-08 18:07:27 -0700 | [diff] [blame] | 372 | ), |
| 373 | IOSDevices( |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 374 | platform: platform, |
| 375 | xcdevice: xcDevice, |
| 376 | iosWorkflow: iosWorkflow, |
| 377 | logger: logger, |
Jonah Williams | 741608a | 2020-07-08 18:07:27 -0700 | [diff] [blame] | 378 | ), |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 379 | IOSSimulators( |
| 380 | iosSimulatorUtils: iosSimulatorUtils, |
| 381 | ), |
Jonah Williams | 741608a | 2020-07-08 18:07:27 -0700 | [diff] [blame] | 382 | FuchsiaDevices( |
| 383 | fuchsiaSdk: fuchsiaSdk, |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 384 | logger: logger, |
Jonah Williams | 741608a | 2020-07-08 18:07:27 -0700 | [diff] [blame] | 385 | fuchsiaWorkflow: fuchsiaWorkflow, |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 386 | platform: platform, |
Jonah Williams | 741608a | 2020-07-08 18:07:27 -0700 | [diff] [blame] | 387 | ), |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 388 | FlutterTesterDevices( |
| 389 | fileSystem: fileSystem, |
| 390 | flutterVersion: flutterVersion, |
| 391 | processManager: processManager, |
| 392 | config: config, |
| 393 | logger: logger, |
| 394 | artifacts: artifacts, |
| 395 | ), |
Jonah Williams | 9f04086 | 2020-07-22 18:23:20 -0700 | [diff] [blame] | 396 | MacOSDevices( |
| 397 | processManager: processManager, |
| 398 | macOSWorkflow: macOSWorkflow, |
| 399 | logger: logger, |
| 400 | platform: platform, |
Jonah Williams | 943b41b | 2020-09-22 16:57:04 -0700 | [diff] [blame] | 401 | fileSystem: fileSystem, |
Jonah Williams | ddb8177 | 2020-10-02 21:52:53 -0700 | [diff] [blame] | 402 | operatingSystemUtils: operatingSystemUtils, |
Jonah Williams | 9f04086 | 2020-07-22 18:23:20 -0700 | [diff] [blame] | 403 | ), |
Jonah Williams | 741608a | 2020-07-08 18:07:27 -0700 | [diff] [blame] | 404 | LinuxDevices( |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 405 | platform: platform, |
Jonah Williams | 741608a | 2020-07-08 18:07:27 -0700 | [diff] [blame] | 406 | featureFlags: featureFlags, |
Jonah Williams | 9f04086 | 2020-07-22 18:23:20 -0700 | [diff] [blame] | 407 | processManager: processManager, |
| 408 | logger: logger, |
Jonah Williams | 943b41b | 2020-09-22 16:57:04 -0700 | [diff] [blame] | 409 | fileSystem: fileSystem, |
Jonah Williams | ddb8177 | 2020-10-02 21:52:53 -0700 | [diff] [blame] | 410 | operatingSystemUtils: operatingSystemUtils, |
Jonah Williams | 741608a | 2020-07-08 18:07:27 -0700 | [diff] [blame] | 411 | ), |
Jonah Williams | ddb8177 | 2020-10-02 21:52:53 -0700 | [diff] [blame] | 412 | WindowsDevices( |
| 413 | processManager: processManager, |
| 414 | operatingSystemUtils: operatingSystemUtils, |
| 415 | logger: logger, |
| 416 | fileSystem: fileSystem, |
| 417 | windowsWorkflow: windowsWorkflow, |
| 418 | ), |
Jonah Williams | 741608a | 2020-07-08 18:07:27 -0700 | [diff] [blame] | 419 | WebDevices( |
| 420 | featureFlags: featureFlags, |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 421 | fileSystem: fileSystem, |
| 422 | platform: platform, |
| 423 | processManager: processManager, |
| 424 | logger: logger, |
Jonah Williams | 741608a | 2020-07-08 18:07:27 -0700 | [diff] [blame] | 425 | ), |
Jonah Williams | 30c0fc1 | 2020-10-08 12:28:58 -0700 | [diff] [blame] | 426 | ], super( |
| 427 | logger: logger, |
| 428 | terminal: terminal, |
| 429 | userMessages: userMessages, |
| 430 | ); |
Jonah Williams | 1c1ef13 | 2020-07-10 11:52:09 -0700 | [diff] [blame] | 431 | |
| 432 | @override |
| 433 | final List<DeviceDiscovery> deviceDiscoverers; |
Jonah Williams | 741608a | 2020-07-08 18:07:27 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Devon Carew | 7ac4e62 | 2016-01-27 14:03:41 -0800 | [diff] [blame] | 436 | /// An abstract class to discover and enumerate a specific type of devices. |
| 437 | abstract class DeviceDiscovery { |
| 438 | bool get supportsPlatform; |
Todd Volkert | 6a4b08b | 2017-05-03 16:12:08 -0700 | [diff] [blame] | 439 | |
| 440 | /// Whether this device discovery is capable of listing any devices given the |
| 441 | /// current environment configuration. |
| 442 | bool get canListAnything; |
| 443 | |
Jenn Magder | 2f216ce | 2020-03-16 14:15:00 -0700 | [diff] [blame] | 444 | /// Return all connected devices, cached on subsequent calls. |
Chris Bracken | 1d9f009 | 2017-06-19 13:14:57 -0700 | [diff] [blame] | 445 | Future<List<Device>> get devices; |
Devon Carew | 0350c9e | 2017-12-07 09:32:23 -0800 | [diff] [blame] | 446 | |
Jenn Magder | 2f216ce | 2020-03-16 14:15:00 -0700 | [diff] [blame] | 447 | /// Return all connected devices. Discards existing cache of devices. |
| 448 | Future<List<Device>> discoverDevices({ Duration timeout }); |
| 449 | |
Devon Carew | 0350c9e | 2017-12-07 09:32:23 -0800 | [diff] [blame] | 450 | /// Gets a list of diagnostic messages pertaining to issues with any connected |
| 451 | /// devices (will be an empty list if there are no issues). |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 452 | Future<List<String>> getDiagnostics() => Future<List<String>>.value(<String>[]); |
Devon Carew | 7ac4e62 | 2016-01-27 14:03:41 -0800 | [diff] [blame] | 453 | } |
| 454 | |
Devon Carew | 67046f9 | 2016-02-20 22:00:11 -0800 | [diff] [blame] | 455 | /// A [DeviceDiscovery] implementation that uses polling to discover device adds |
| 456 | /// and removals. |
| 457 | abstract class PollingDeviceDiscovery extends DeviceDiscovery { |
| 458 | PollingDeviceDiscovery(this.name); |
| 459 | |
Alexandre Ardhuin | eda03e2 | 2018-08-02 12:02:32 +0200 | [diff] [blame] | 460 | static const Duration _pollingInterval = Duration(seconds: 4); |
| 461 | static const Duration _pollingTimeout = Duration(seconds: 30); |
Devon Carew | 67046f9 | 2016-02-20 22:00:11 -0800 | [diff] [blame] | 462 | |
| 463 | final String name; |
Jenn Magder | f4d26a3 | 2020-06-01 12:33:01 -0700 | [diff] [blame] | 464 | |
| 465 | @protected |
| 466 | @visibleForTesting |
| 467 | ItemListNotifier<Device> deviceNotifier; |
| 468 | |
Jonah Williams | 19e551c | 2019-10-28 19:35:43 -0700 | [diff] [blame] | 469 | Timer _timer; |
Devon Carew | 67046f9 | 2016-02-20 22:00:11 -0800 | [diff] [blame] | 470 | |
Jenn Magder | 2f216ce | 2020-03-16 14:15:00 -0700 | [diff] [blame] | 471 | Future<List<Device>> pollingGetDevices({ Duration timeout }); |
Devon Carew | 67046f9 | 2016-02-20 22:00:11 -0800 | [diff] [blame] | 472 | |
Jonah Williams | 1bea512 | 2020-10-02 21:12:50 -0700 | [diff] [blame] | 473 | void startPolling() { |
Jonah Williams | 19e551c | 2019-10-28 19:35:43 -0700 | [diff] [blame] | 474 | if (_timer == null) { |
Jenn Magder | f4d26a3 | 2020-06-01 12:33:01 -0700 | [diff] [blame] | 475 | deviceNotifier ??= ItemListNotifier<Device>(); |
Jenn Magder | bd43008 | 2020-05-14 11:00:51 -0700 | [diff] [blame] | 476 | // Make initial population the default, fast polling timeout. |
| 477 | _timer = _initTimer(null); |
Devon Carew | 67046f9 | 2016-02-20 22:00:11 -0800 | [diff] [blame] | 478 | } |
| 479 | } |
| 480 | |
Jenn Magder | bd43008 | 2020-05-14 11:00:51 -0700 | [diff] [blame] | 481 | Timer _initTimer(Duration pollingTimeout) { |
Jonah Williams | 19e551c | 2019-10-28 19:35:43 -0700 | [diff] [blame] | 482 | return Timer(_pollingInterval, () async { |
| 483 | try { |
Jenn Magder | bd43008 | 2020-05-14 11:00:51 -0700 | [diff] [blame] | 484 | final List<Device> devices = await pollingGetDevices(timeout: pollingTimeout); |
Jenn Magder | f4d26a3 | 2020-06-01 12:33:01 -0700 | [diff] [blame] | 485 | deviceNotifier.updateWithNewList(devices); |
Jonah Williams | 19e551c | 2019-10-28 19:35:43 -0700 | [diff] [blame] | 486 | } on TimeoutException { |
Jonah Williams | 30c0fc1 | 2020-10-08 12:28:58 -0700 | [diff] [blame] | 487 | // Do nothing on a timeout. |
Jonah Williams | 19e551c | 2019-10-28 19:35:43 -0700 | [diff] [blame] | 488 | } |
Jenn Magder | bd43008 | 2020-05-14 11:00:51 -0700 | [diff] [blame] | 489 | // Subsequent timeouts after initial population should wait longer. |
| 490 | _timer = _initTimer(_pollingTimeout); |
Jonah Williams | 19e551c | 2019-10-28 19:35:43 -0700 | [diff] [blame] | 491 | }); |
| 492 | } |
| 493 | |
Jonah Williams | 1bea512 | 2020-10-02 21:12:50 -0700 | [diff] [blame] | 494 | void stopPolling() { |
Jonah Williams | 19e551c | 2019-10-28 19:35:43 -0700 | [diff] [blame] | 495 | _timer?.cancel(); |
| 496 | _timer = null; |
Devon Carew | 67046f9 | 2016-02-20 22:00:11 -0800 | [diff] [blame] | 497 | } |
| 498 | |
Hixie | 797e27e | 2016-03-14 13:31:43 -0700 | [diff] [blame] | 499 | @override |
Jonah Williams | 1bea512 | 2020-10-02 21:12:50 -0700 | [diff] [blame] | 500 | Future<List<Device>> get devices { |
Jenn Magder | 2f216ce | 2020-03-16 14:15:00 -0700 | [diff] [blame] | 501 | return _populateDevices(); |
| 502 | } |
| 503 | |
| 504 | @override |
Jonah Williams | 1bea512 | 2020-10-02 21:12:50 -0700 | [diff] [blame] | 505 | Future<List<Device>> discoverDevices({ Duration timeout }) { |
Jenn Magder | f4d26a3 | 2020-06-01 12:33:01 -0700 | [diff] [blame] | 506 | deviceNotifier = null; |
Jenn Magder | 2f216ce | 2020-03-16 14:15:00 -0700 | [diff] [blame] | 507 | return _populateDevices(timeout: timeout); |
| 508 | } |
| 509 | |
| 510 | Future<List<Device>> _populateDevices({ Duration timeout }) async { |
Jenn Magder | f4d26a3 | 2020-06-01 12:33:01 -0700 | [diff] [blame] | 511 | deviceNotifier ??= ItemListNotifier<Device>.from(await pollingGetDevices(timeout: timeout)); |
| 512 | return deviceNotifier.items; |
Devon Carew | 67046f9 | 2016-02-20 22:00:11 -0800 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | Stream<Device> get onAdded { |
Jenn Magder | f4d26a3 | 2020-06-01 12:33:01 -0700 | [diff] [blame] | 516 | deviceNotifier ??= ItemListNotifier<Device>(); |
| 517 | return deviceNotifier.onAdded; |
Devon Carew | 67046f9 | 2016-02-20 22:00:11 -0800 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | Stream<Device> get onRemoved { |
Jenn Magder | f4d26a3 | 2020-06-01 12:33:01 -0700 | [diff] [blame] | 521 | deviceNotifier ??= ItemListNotifier<Device>(); |
| 522 | return deviceNotifier.onRemoved; |
Devon Carew | 67046f9 | 2016-02-20 22:00:11 -0800 | [diff] [blame] | 523 | } |
| 524 | |
Jonah Williams | 1bea512 | 2020-10-02 21:12:50 -0700 | [diff] [blame] | 525 | void dispose() => stopPolling(); |
Devon Carew | 67046f9 | 2016-02-20 22:00:11 -0800 | [diff] [blame] | 526 | |
Hixie | 797e27e | 2016-03-14 13:31:43 -0700 | [diff] [blame] | 527 | @override |
Devon Carew | 67046f9 | 2016-02-20 22:00:11 -0800 | [diff] [blame] | 528 | String toString() => '$name device discovery'; |
| 529 | } |
| 530 | |
Jonah Williams | 4f88ed1 | 2020-06-08 11:20:15 -0700 | [diff] [blame] | 531 | /// A device is a physical hardware that can run a flutter application. |
| 532 | /// |
| 533 | /// This may correspond to a connected iOS or Android device, or represent |
| 534 | /// the host operating system in the case of Flutter Desktop. |
Adam Barth | bdd2066 | 2015-10-11 19:42:50 -0700 | [diff] [blame] | 535 | abstract class Device { |
Jonah Williams | 4f88ed1 | 2020-06-08 11:20:15 -0700 | [diff] [blame] | 536 | Device(this.id, { |
| 537 | @required this.category, |
| 538 | @required this.platformType, |
| 539 | @required this.ephemeral, |
| 540 | }); |
Devon Carew | 9e6d45c | 2016-02-05 20:44:32 -0800 | [diff] [blame] | 541 | |
Ian Fischer | 81746e9 | 2015-09-11 12:20:20 -0700 | [diff] [blame] | 542 | final String id; |
Ian Fischer | 81746e9 | 2015-09-11 12:20:20 -0700 | [diff] [blame] | 543 | |
Jonah Williams | 5c52498 | 2019-06-18 15:23:14 -0700 | [diff] [blame] | 544 | /// The [Category] for this device type. |
| 545 | final Category category; |
| 546 | |
| 547 | /// The [PlatformType] for this device. |
| 548 | final PlatformType platformType; |
| 549 | |
| 550 | /// Whether this is an ephemeral device. |
| 551 | final bool ephemeral; |
| 552 | |
Devon Carew | 8bb8e1d | 2016-01-19 15:14:05 -0800 | [diff] [blame] | 553 | String get name; |
| 554 | |
Devon Carew | 4ed7945 | 2016-02-11 09:38:19 -0800 | [diff] [blame] | 555 | bool get supportsStartPaused => true; |
| 556 | |
Yegor Jbanov | 677e63b | 2016-02-25 15:58:09 -0800 | [diff] [blame] | 557 | /// Whether it is an emulated device running on localhost. |
Jonah Williams | 4f88ed1 | 2020-06-08 11:20:15 -0700 | [diff] [blame] | 558 | /// |
| 559 | /// This may return `true` for certain physical Android devices, and is |
| 560 | /// generally only a best effort guess. |
Todd Volkert | 60c5ffc | 2017-04-25 17:23:00 -0700 | [diff] [blame] | 561 | Future<bool> get isLocalEmulator; |
Yegor Jbanov | 677e63b | 2016-02-25 15:58:09 -0800 | [diff] [blame] | 562 | |
Danny Tuppeny | f3be1d9 | 2019-06-26 16:39:23 +0100 | [diff] [blame] | 563 | /// The unique identifier for the emulator that corresponds to this device, or |
| 564 | /// null if it is not an emulator. |
| 565 | /// |
| 566 | /// The ID returned matches that in the output of `flutter emulators`. Fetching |
| 567 | /// this name may require connecting to the device and if an error occurs null |
| 568 | /// will be returned. |
| 569 | Future<String> get emulatorId; |
| 570 | |
Jonah Williams | 4f88ed1 | 2020-06-08 11:20:15 -0700 | [diff] [blame] | 571 | /// Whether this device can run the provided [buildMode]. |
| 572 | /// |
| 573 | /// For example, some emulator architectures cannot run profile or |
| 574 | /// release builds. |
| 575 | FutureOr<bool> supportsRuntimeMode(BuildMode buildMode) => true; |
| 576 | |
Jonah Williams | afabdfe | 2018-03-08 10:41:29 -0800 | [diff] [blame] | 577 | /// Whether the device is a simulator on a platform which supports hardware rendering. |
Jonah Williams | 4f88ed1 | 2020-06-08 11:20:15 -0700 | [diff] [blame] | 578 | // This is soft-deprecated since the logic is not correct expect for iOS simulators. |
Jonah Williams | afabdfe | 2018-03-08 10:41:29 -0800 | [diff] [blame] | 579 | Future<bool> get supportsHardwareRendering async { |
Jonah Williams | 4f88ed1 | 2020-06-08 11:20:15 -0700 | [diff] [blame] | 580 | return true; |
Jonah Williams | afabdfe | 2018-03-08 10:41:29 -0800 | [diff] [blame] | 581 | } |
| 582 | |
Jonah Williams | 6b19184 | 2019-04-25 12:25:12 -0700 | [diff] [blame] | 583 | /// Whether the device is supported for the current project directory. |
| 584 | bool isSupportedForProject(FlutterProject flutterProject); |
| 585 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 586 | /// Check if a version of the given app is already installed. |
| 587 | /// |
| 588 | /// Specify [userIdentifier] to check if installed for a particular user (Android only). |
| 589 | Future<bool> isAppInstalled( |
| 590 | covariant ApplicationPackage app, { |
| 591 | String userIdentifier, |
| 592 | }); |
Todd Volkert | 51d4ab3 | 2016-05-27 11:05:10 -0700 | [diff] [blame] | 593 | |
Jakob Andersen | a745fd5 | 2017-02-22 14:35:49 +0100 | [diff] [blame] | 594 | /// Check if the latest build of the [app] is already installed. |
Alexandre Ardhuin | adc7351 | 2019-11-19 07:57:42 +0100 | [diff] [blame] | 595 | Future<bool> isLatestBuildInstalled(covariant ApplicationPackage app); |
Jakob Andersen | a745fd5 | 2017-02-22 14:35:49 +0100 | [diff] [blame] | 596 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 597 | /// Install an app package on the current device. |
| 598 | /// |
| 599 | /// Specify [userIdentifier] to install for a particular user (Android only). |
| 600 | Future<bool> installApp( |
| 601 | covariant ApplicationPackage app, { |
| 602 | String userIdentifier, |
| 603 | }); |
Ian Fischer | 81746e9 | 2015-09-11 12:20:20 -0700 | [diff] [blame] | 604 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 605 | /// Uninstall an app package from the current device. |
| 606 | /// |
| 607 | /// Specify [userIdentifier] to uninstall for a particular user, |
| 608 | /// defaults to all users (Android only). |
| 609 | Future<bool> uninstallApp( |
| 610 | covariant ApplicationPackage app, { |
| 611 | String userIdentifier, |
| 612 | }); |
Todd Volkert | 51d4ab3 | 2016-05-27 11:05:10 -0700 | [diff] [blame] | 613 | |
Nolan Scobie | 43c1b34 | 2020-08-06 19:18:52 -0400 | [diff] [blame] | 614 | /// Check if the device is supported by Flutter. |
Chinmay Garde | d797995 | 2016-02-19 14:16:02 -0800 | [diff] [blame] | 615 | bool isSupported(); |
| 616 | |
Jenn Magder | cdacae8 | 2020-12-16 11:52:59 -0800 | [diff] [blame] | 617 | // String meant to be displayed to the user indicating if the device is |
| 618 | // supported by Flutter, and, if not, why. |
| 619 | String supportMessage() => isSupported() ? 'Supported' : 'Unsupported'; |
| 620 | |
Todd Volkert | 60c5ffc | 2017-04-25 17:23:00 -0700 | [diff] [blame] | 621 | /// The device's platform. |
| 622 | Future<TargetPlatform> get targetPlatform; |
Adam Barth | bdd2066 | 2015-10-11 19:42:50 -0700 | [diff] [blame] | 623 | |
Jenn Magder | de5bf09 | 2020-10-30 13:48:04 -0700 | [diff] [blame] | 624 | /// Platform name for display only. |
| 625 | Future<String> get targetPlatformDisplayName async => |
| 626 | getNameForTargetPlatform(await targetPlatform); |
| 627 | |
Todd Volkert | 60c5ffc | 2017-04-25 17:23:00 -0700 | [diff] [blame] | 628 | Future<String> get sdkNameAndVersion; |
Dan Rubel | 0b49d81 | 2016-10-27 09:07:21 +0100 | [diff] [blame] | 629 | |
Jonah Williams | ddab09f | 2020-10-08 13:40:19 -0700 | [diff] [blame] | 630 | /// Create a platform-specific [DevFSWriter] for the given [app], or |
| 631 | /// null if the device does not support them. |
| 632 | /// |
Jonah Williams | 08576cb | 2020-10-12 09:31:02 -0700 | [diff] [blame] | 633 | /// For example, the desktop device classes can use a writer which |
Jonah Williams | ddab09f | 2020-10-08 13:40:19 -0700 | [diff] [blame] | 634 | /// copies the files across the local file system. |
| 635 | DevFSWriter createDevFSWriter( |
| 636 | covariant ApplicationPackage app, |
| 637 | String userIdentifier, |
| 638 | ) { |
| 639 | return null; |
| 640 | } |
| 641 | |
Todd Volkert | 9cb914d | 2016-11-16 17:19:00 -0800 | [diff] [blame] | 642 | /// Get a log reader for this device. |
xster | 1376746 | 2020-03-25 16:45:49 -0700 | [diff] [blame] | 643 | /// |
| 644 | /// If `app` is specified, this will return a log reader specific to that |
Todd Volkert | 9cb914d | 2016-11-16 17:19:00 -0800 | [diff] [blame] | 645 | /// application. Otherwise, a global log reader will be returned. |
xster | 1376746 | 2020-03-25 16:45:49 -0700 | [diff] [blame] | 646 | /// |
| 647 | /// If `includePastLogs` is true and the device type supports it, the log |
| 648 | /// reader will also include log messages from before the invocation time. |
| 649 | /// Defaults to false. |
| 650 | FutureOr<DeviceLogReader> getLogReader({ |
| 651 | covariant ApplicationPackage app, |
| 652 | bool includePastLogs = false, |
| 653 | }); |
John McCutchan | 8803cec | 2016-03-07 13:52:27 -0800 | [diff] [blame] | 654 | |
John McCutchan | 5e140b7 | 2016-03-10 15:48:37 -0800 | [diff] [blame] | 655 | /// Get the port forwarder for this device. |
| 656 | DevicePortForwarder get portForwarder; |
| 657 | |
Ben Konyi | 3a5a3ea | 2020-07-29 10:05:40 -0700 | [diff] [blame] | 658 | /// Get the DDS instance for this device. |
| 659 | DartDevelopmentService get dds => _dds ??= DartDevelopmentService( |
| 660 | logger: globals.logger, |
| 661 | ); |
| 662 | DartDevelopmentService _dds; |
| 663 | |
John McCutchan | 8803cec | 2016-03-07 13:52:27 -0800 | [diff] [blame] | 664 | /// Clear the device's logs. |
| 665 | void clearLogs(); |
Adam Barth | bdd2066 | 2015-10-11 19:42:50 -0700 | [diff] [blame] | 666 | |
Zachary Anderson | 61236c8 | 2019-05-06 09:26:58 -0700 | [diff] [blame] | 667 | /// Optional device-specific artifact overrides. |
| 668 | OverrideArtifacts get artifactOverrides => null; |
| 669 | |
Devon Carew | 5bce2fb | 2016-01-21 11:56:14 -0800 | [diff] [blame] | 670 | /// Start an app package on the current device. |
| 671 | /// |
| 672 | /// [platformArgs] allows callers to pass platform-specific arguments to the |
Chinmay Garde | 66fee3a | 2016-05-23 12:58:42 -0700 | [diff] [blame] | 673 | /// start call. The build mode is not used by all platforms. |
Devon Carew | b0dca79 | 2016-04-27 14:43:42 -0700 | [diff] [blame] | 674 | Future<LaunchResult> startApp( |
Alexandre Ardhuin | adc7351 | 2019-11-19 07:57:42 +0100 | [diff] [blame] | 675 | covariant ApplicationPackage package, { |
Devon Carew | 5bce2fb | 2016-01-21 11:56:14 -0800 | [diff] [blame] | 676 | String mainPath, |
| 677 | String route, |
Devon Carew | b0dca79 | 2016-04-27 14:43:42 -0700 | [diff] [blame] | 678 | DebuggingOptions debuggingOptions, |
John McCutchan | ca8070f | 2016-09-28 08:46:16 -0700 | [diff] [blame] | 679 | Map<String, dynamic> platformArgs, |
Alexandre Ardhuin | 09276be | 2018-06-05 08:50:40 +0200 | [diff] [blame] | 680 | bool prebuiltApplication = false, |
Alexandre Ardhuin | 09276be | 2018-06-05 08:50:40 +0200 | [diff] [blame] | 681 | bool ipv6 = false, |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 682 | String userIdentifier, |
Devon Carew | 5bce2fb | 2016-01-21 11:56:14 -0800 | [diff] [blame] | 683 | }); |
Ian Fischer | 844678d | 2015-10-07 15:13:24 -0700 | [diff] [blame] | 684 | |
Jonah Williams | c11633e | 2018-11-09 10:33:22 -0800 | [diff] [blame] | 685 | /// Whether this device implements support for hot reload. |
| 686 | bool get supportsHotReload => true; |
| 687 | |
| 688 | /// Whether this device implements support for hot restart. |
| 689 | bool get supportsHotRestart => true; |
Devon Carew | ec75177 | 2016-05-26 15:26:14 -0700 | [diff] [blame] | 690 | |
Jonah Williams | 891036c | 2019-01-07 21:58:15 -0800 | [diff] [blame] | 691 | /// Whether flutter applications running on this device can be terminated |
Jonah Williams | 08576cb | 2020-10-12 09:31:02 -0700 | [diff] [blame] | 692 | /// from the VM Service. |
Zachary Anderson | 5555725 | 2019-06-06 11:16:19 -0700 | [diff] [blame] | 693 | bool get supportsFlutterExit => true; |
Jonah Williams | 891036c | 2019-01-07 21:58:15 -0800 | [diff] [blame] | 694 | |
| 695 | /// Whether the device supports taking screenshots of a running flutter |
| 696 | /// application. |
| 697 | bool get supportsScreenshot => false; |
| 698 | |
Jonah Williams | bda9d90 | 2019-12-10 10:26:14 -0800 | [diff] [blame] | 699 | /// Whether the device supports the '--fast-start' development mode. |
| 700 | bool get supportsFastStart => false; |
| 701 | |
Devon Carew | 5bce2fb | 2016-01-21 11:56:14 -0800 | [diff] [blame] | 702 | /// Stop an app package on the current device. |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 703 | /// |
| 704 | /// Specify [userIdentifier] to stop app installed to a profile (Android only). |
| 705 | Future<bool> stopApp( |
| 706 | covariant ApplicationPackage app, { |
| 707 | String userIdentifier, |
| 708 | }); |
Devon Carew | e36b07f | 2015-11-25 12:47:25 -0800 | [diff] [blame] | 709 | |
Jonah Williams | 831163f | 2019-11-26 14:49:56 -0800 | [diff] [blame] | 710 | /// Query the current application memory usage.. |
| 711 | /// |
| 712 | /// If the device does not support this callback, an empty map |
| 713 | /// is returned. |
| 714 | Future<MemoryInfo> queryMemoryInfo() { |
| 715 | return Future<MemoryInfo>.value(const MemoryInfo.empty()); |
| 716 | } |
| 717 | |
Alexandre Ardhuin | 2d3ff10 | 2018-10-05 07:54:56 +0200 | [diff] [blame] | 718 | Future<void> takeScreenshot(File outputFile) => Future<void>.error('unimplemented'); |
Devon Carew | 15b9e1d | 2016-03-25 16:04:22 -0700 | [diff] [blame] | 719 | |
Alexandre Ardhuin | f5a9902 | 2020-04-06 22:36:01 +0200 | [diff] [blame] | 720 | @nonVirtual |
Hixie | 797e27e | 2016-03-14 13:31:43 -0700 | [diff] [blame] | 721 | @override |
Alexandre Ardhuin | f5a9902 | 2020-04-06 22:36:01 +0200 | [diff] [blame] | 722 | // ignore: avoid_equals_and_hash_code_on_mutable_classes |
Devon Carew | 67046f9 | 2016-02-20 22:00:11 -0800 | [diff] [blame] | 723 | int get hashCode => id.hashCode; |
| 724 | |
Alexandre Ardhuin | f5a9902 | 2020-04-06 22:36:01 +0200 | [diff] [blame] | 725 | @nonVirtual |
Hixie | 797e27e | 2016-03-14 13:31:43 -0700 | [diff] [blame] | 726 | @override |
Alexandre Ardhuin | f5a9902 | 2020-04-06 22:36:01 +0200 | [diff] [blame] | 727 | // ignore: avoid_equals_and_hash_code_on_mutable_classes |
Alexandre Ardhuin | 82262d8 | 2020-01-09 17:23:02 +0100 | [diff] [blame] | 728 | bool operator ==(Object other) { |
Zachary Anderson | e2340c6 | 2019-09-13 14:51:35 -0700 | [diff] [blame] | 729 | if (identical(this, other)) { |
Devon Carew | 67046f9 | 2016-02-20 22:00:11 -0800 | [diff] [blame] | 730 | return true; |
Zachary Anderson | e2340c6 | 2019-09-13 14:51:35 -0700 | [diff] [blame] | 731 | } |
Alexandre Ardhuin | 82262d8 | 2020-01-09 17:23:02 +0100 | [diff] [blame] | 732 | return other is Device |
| 733 | && other.id == id; |
Devon Carew | 67046f9 | 2016-02-20 22:00:11 -0800 | [diff] [blame] | 734 | } |
| 735 | |
Hixie | 797e27e | 2016-03-14 13:31:43 -0700 | [diff] [blame] | 736 | @override |
Devon Carew | 5ad6a57 | 2016-03-11 08:49:55 -0800 | [diff] [blame] | 737 | String toString() => name; |
Devon Carew | 4daee0c | 2016-03-14 09:41:00 -0700 | [diff] [blame] | 738 | |
Todd Volkert | 60c5ffc | 2017-04-25 17:23:00 -0700 | [diff] [blame] | 739 | static Stream<String> descriptions(List<Device> devices) async* { |
Zachary Anderson | e2340c6 | 2019-09-13 14:51:35 -0700 | [diff] [blame] | 740 | if (devices.isEmpty) { |
Todd Volkert | 60c5ffc | 2017-04-25 17:23:00 -0700 | [diff] [blame] | 741 | return; |
Zachary Anderson | e2340c6 | 2019-09-13 14:51:35 -0700 | [diff] [blame] | 742 | } |
Devon Carew | 4daee0c | 2016-03-14 09:41:00 -0700 | [diff] [blame] | 743 | |
Dan Rubel | 0b49d81 | 2016-10-27 09:07:21 +0100 | [diff] [blame] | 744 | // Extract device information |
Chris Bracken | 7a09316 | 2017-03-03 17:50:46 -0800 | [diff] [blame] | 745 | final List<List<String>> table = <List<String>>[]; |
Alexandre Ardhuin | 4f9b6cf | 2020-01-07 16:32:04 +0100 | [diff] [blame] | 746 | for (final Device device in devices) { |
Devon Carew | 4daee0c | 2016-03-14 09:41:00 -0700 | [diff] [blame] | 747 | String supportIndicator = device.isSupported() ? '' : ' (unsupported)'; |
Todd Volkert | 60c5ffc | 2017-04-25 17:23:00 -0700 | [diff] [blame] | 748 | final TargetPlatform targetPlatform = await device.targetPlatform; |
| 749 | if (await device.isLocalEmulator) { |
| 750 | final String type = targetPlatform == TargetPlatform.ios ? 'simulator' : 'emulator'; |
Devon Carew | b00e6cd | 2016-10-04 20:29:10 -0700 | [diff] [blame] | 751 | supportIndicator += ' ($type)'; |
| 752 | } |
Dan Rubel | 0b49d81 | 2016-10-27 09:07:21 +0100 | [diff] [blame] | 753 | table.add(<String>[ |
James D. Lin | cf8fbc3 | 2020-06-30 11:28:02 -0700 | [diff] [blame] | 754 | '${device.name} (${device.category})', |
Dan Rubel | 0b49d81 | 2016-10-27 09:07:21 +0100 | [diff] [blame] | 755 | device.id, |
Jenn Magder | de5bf09 | 2020-10-30 13:48:04 -0700 | [diff] [blame] | 756 | await device.targetPlatformDisplayName, |
Todd Volkert | 60c5ffc | 2017-04-25 17:23:00 -0700 | [diff] [blame] | 757 | '${await device.sdkNameAndVersion}$supportIndicator', |
Dan Rubel | 0b49d81 | 2016-10-27 09:07:21 +0100 | [diff] [blame] | 758 | ]); |
| 759 | } |
| 760 | |
| 761 | // Calculate column widths |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 762 | final List<int> indices = List<int>.generate(table[0].length - 1, (int i) => i); |
Alexandre Ardhuin | f62afdc | 2018-10-01 21:29:08 +0200 | [diff] [blame] | 763 | List<int> widths = indices.map<int>((int i) => 0).toList(); |
Alexandre Ardhuin | 4f9b6cf | 2020-01-07 16:32:04 +0100 | [diff] [blame] | 764 | for (final List<String> row in table) { |
Alexandre Ardhuin | f62afdc | 2018-10-01 21:29:08 +0200 | [diff] [blame] | 765 | widths = indices.map<int>((int i) => math.max(widths[i], row[i].length)).toList(); |
Dan Rubel | 0b49d81 | 2016-10-27 09:07:21 +0100 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | // Join columns into lines of text |
Alexandre Ardhuin | 4f9b6cf | 2020-01-07 16:32:04 +0100 | [diff] [blame] | 769 | for (final List<String> row in table) { |
Alexandre Ardhuin | f62afdc | 2018-10-01 21:29:08 +0200 | [diff] [blame] | 770 | yield indices.map<String>((int i) => row[i].padRight(widths[i])).join(' • ') + ' • ${row.last}'; |
Todd Volkert | 60c5ffc | 2017-04-25 17:23:00 -0700 | [diff] [blame] | 771 | } |
Dan Rubel | 023b7de | 2016-09-01 17:55:16 -0400 | [diff] [blame] | 772 | } |
| 773 | |
Jonah Williams | 30c0fc1 | 2020-10-08 12:28:58 -0700 | [diff] [blame] | 774 | static Future<void> printDevices(List<Device> devices, Logger logger) async { |
| 775 | await descriptions(devices).forEach(logger.printStatus); |
Devon Carew | 4daee0c | 2016-03-14 09:41:00 -0700 | [diff] [blame] | 776 | } |
Christopher Fujino | ed482c3 | 2019-10-09 16:30:27 -0700 | [diff] [blame] | 777 | |
JustWe | 6c8d7b0 | 2020-06-04 07:14:38 +0800 | [diff] [blame] | 778 | static List<String> devicesPlatformTypes(List<Device> devices) { |
| 779 | return devices |
| 780 | .map( |
| 781 | (Device d) => d.platformType.toString(), |
| 782 | ).toSet().toList()..sort(); |
| 783 | } |
| 784 | |
Kirill Pertsev | d680639 | 2020-04-09 09:14:16 -0700 | [diff] [blame] | 785 | /// Convert the Device object to a JSON representation suitable for serialization. |
| 786 | Future<Map<String, Object>> toJson() async { |
| 787 | final bool isLocalEmu = await isLocalEmulator; |
| 788 | return <String, Object>{ |
| 789 | 'name': name, |
| 790 | 'id': id, |
| 791 | 'isSupported': isSupported(), |
| 792 | 'targetPlatform': getNameForTargetPlatform(await targetPlatform), |
| 793 | 'emulator': isLocalEmu, |
| 794 | 'sdk': await sdkNameAndVersion, |
| 795 | 'capabilities': <String, Object>{ |
| 796 | 'hotReload': supportsHotReload, |
| 797 | 'hotRestart': supportsHotRestart, |
| 798 | 'screenshot': supportsScreenshot, |
| 799 | 'fastStart': supportsFastStart, |
| 800 | 'flutterExit': supportsFlutterExit, |
| 801 | 'hardwareRendering': isLocalEmu && await supportsHardwareRendering, |
| 802 | 'startPaused': supportsStartPaused, |
| 803 | } |
| 804 | }; |
| 805 | } |
| 806 | |
Nolan Scobie | 43c1b34 | 2020-08-06 19:18:52 -0400 | [diff] [blame] | 807 | /// Clean up resources allocated by device. |
Christopher Fujino | ed482c3 | 2019-10-09 16:30:27 -0700 | [diff] [blame] | 808 | /// |
| 809 | /// For example log readers or port forwarders. |
Zachary Anderson | 99684ce | 2019-12-05 08:48:00 -0800 | [diff] [blame] | 810 | Future<void> dispose(); |
Ian Fischer | 81746e9 | 2015-09-11 12:20:20 -0700 | [diff] [blame] | 811 | } |
| 812 | |
Jonah Williams | 831163f | 2019-11-26 14:49:56 -0800 | [diff] [blame] | 813 | /// Information about an application's memory usage. |
| 814 | abstract class MemoryInfo { |
| 815 | /// Const constructor to allow subclasses to be const. |
| 816 | const MemoryInfo(); |
| 817 | |
| 818 | /// Create a [MemoryInfo] object with no information. |
| 819 | const factory MemoryInfo.empty() = _NoMemoryInfo; |
| 820 | |
| 821 | /// Convert the object to a JSON representation suitable for serialization. |
| 822 | Map<String, Object> toJson(); |
| 823 | } |
| 824 | |
| 825 | class _NoMemoryInfo implements MemoryInfo { |
| 826 | const _NoMemoryInfo(); |
| 827 | |
| 828 | @override |
| 829 | Map<String, Object> toJson() => <String, Object>{}; |
| 830 | } |
| 831 | |
Devon Carew | b0dca79 | 2016-04-27 14:43:42 -0700 | [diff] [blame] | 832 | class DebuggingOptions { |
Alexandre Ardhuin | bfa1d25 | 2019-03-23 00:02:21 +0100 | [diff] [blame] | 833 | DebuggingOptions.enabled( |
| 834 | this.buildInfo, { |
Alexandre Ardhuin | 09276be | 2018-06-05 08:50:40 +0200 | [diff] [blame] | 835 | this.startPaused = false, |
Ben Konyi | 3764cb8 | 2019-04-18 21:01:50 -0700 | [diff] [blame] | 836 | this.disableServiceAuthCodes = false, |
Ben Konyi | 3a5a3ea | 2020-07-29 10:05:40 -0700 | [diff] [blame] | 837 | this.disableDds = false, |
George Wright | 2b51278 | 2020-11-06 15:34:02 -0800 | [diff] [blame] | 838 | this.dartEntrypointArgs = const <String>[], |
Ben Konyi | e59d9a8 | 2019-06-11 11:37:47 -0700 | [diff] [blame] | 839 | this.dartFlags = '', |
Alexandre Ardhuin | 09276be | 2018-06-05 08:50:40 +0200 | [diff] [blame] | 840 | this.enableSoftwareRendering = false, |
| 841 | this.skiaDeterministicRendering = false, |
| 842 | this.traceSkia = false, |
Michael Goderbauer | e48b7e9 | 2020-06-19 13:43:02 -0700 | [diff] [blame] | 843 | this.traceAllowlist, |
Chinmay Garde | e38efc8 | 2019-01-28 19:55:01 -0800 | [diff] [blame] | 844 | this.traceSystrace = false, |
Gityuan | b8dd6bd | 2020-02-07 04:33:01 +0800 | [diff] [blame] | 845 | this.endlessTraceBuffer = false, |
liyuqian | be5c83b | 2019-03-15 12:37:53 -0700 | [diff] [blame] | 846 | this.dumpSkpOnShaderCompilation = false, |
liyuqian | 31cb448 | 2019-10-15 14:28:55 -0700 | [diff] [blame] | 847 | this.cacheSkSL = false, |
Yuqian Li | 22bf19c | 2020-07-29 12:24:39 -0700 | [diff] [blame] | 848 | this.purgePersistentCache = false, |
Alexandre Ardhuin | 09276be | 2018-06-05 08:50:40 +0200 | [diff] [blame] | 849 | this.useTestFonts = false, |
Jonah Williams | 25820ab | 2019-03-13 22:42:12 -0700 | [diff] [blame] | 850 | this.verboseSystemLogs = false, |
Jonah Williams | e3cb2c3 | 2019-11-13 16:02:46 -0800 | [diff] [blame] | 851 | this.hostVmServicePort, |
Jenn Magder | f8b1de3 | 2020-10-07 08:52:05 -0700 | [diff] [blame] | 852 | this.disablePortPublication = false, |
Jonah Williams | e3cb2c3 | 2019-11-13 16:02:46 -0800 | [diff] [blame] | 853 | this.deviceVmServicePort, |
Ben Konyi | a17b330 | 2020-09-16 16:27:42 -0700 | [diff] [blame] | 854 | this.ddsPort, |
Jonah Williams | 925a52f | 2019-09-12 08:58:49 -0700 | [diff] [blame] | 855 | this.hostname, |
| 856 | this.port, |
Danny Tuppeny | 4944622 | 2019-12-12 18:43:58 +0000 | [diff] [blame] | 857 | this.webEnableExposeUrl, |
Danny Tuppeny | 589b14d | 2020-04-08 17:02:03 +0100 | [diff] [blame] | 858 | this.webUseSseForDebugProxy = true, |
Danny Tuppeny | f8135ad | 2020-07-13 21:31:04 +0100 | [diff] [blame] | 859 | this.webUseSseForDebugBackend = true, |
Yegor | b340469 | 2020-02-13 18:34:08 -0800 | [diff] [blame] | 860 | this.webRunHeadless = false, |
| 861 | this.webBrowserDebugPort, |
Anna Gringauze | bc1c1b2 | 2020-04-17 10:42:02 -0700 | [diff] [blame] | 862 | this.webEnableExpressionEvaluation = false, |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 863 | this.vmserviceOutFile, |
Jonah Williams | bda9d90 | 2019-12-10 10:26:14 -0800 | [diff] [blame] | 864 | this.fastStart = false, |
Jonah Williams | c86d090 | 2020-08-11 11:36:03 -0700 | [diff] [blame] | 865 | this.nullAssertions = false, |
Jonah Williams | 9e5c877 | 2020-12-03 08:59:31 -0800 | [diff] [blame] | 866 | this.nativeNullAssertions = false, |
Devon Carew | b0dca79 | 2016-04-27 14:43:42 -0700 | [diff] [blame] | 867 | }) : debuggingEnabled = true; |
| 868 | |
Danny Tuppeny | 4944622 | 2019-12-12 18:43:58 +0000 | [diff] [blame] | 869 | DebuggingOptions.disabled(this.buildInfo, { |
George Wright | 2b51278 | 2020-11-06 15:34:02 -0800 | [diff] [blame] | 870 | this.dartEntrypointArgs = const <String>[], |
Danny Tuppeny | 4944622 | 2019-12-12 18:43:58 +0000 | [diff] [blame] | 871 | this.port, |
| 872 | this.hostname, |
| 873 | this.webEnableExposeUrl, |
Danny Tuppeny | 589b14d | 2020-04-08 17:02:03 +0100 | [diff] [blame] | 874 | this.webUseSseForDebugProxy = true, |
Danny Tuppeny | f8135ad | 2020-07-13 21:31:04 +0100 | [diff] [blame] | 875 | this.webUseSseForDebugBackend = true, |
Yegor | b340469 | 2020-02-13 18:34:08 -0800 | [diff] [blame] | 876 | this.webRunHeadless = false, |
| 877 | this.webBrowserDebugPort, |
Danny Tuppeny | 4944622 | 2019-12-12 18:43:58 +0000 | [diff] [blame] | 878 | this.cacheSkSL = false, |
Michael Goderbauer | e48b7e9 | 2020-06-19 13:43:02 -0700 | [diff] [blame] | 879 | this.traceAllowlist, |
Danny Tuppeny | 4944622 | 2019-12-12 18:43:58 +0000 | [diff] [blame] | 880 | }) : debuggingEnabled = false, |
Alexandre Ardhuin | ef276ff | 2019-01-29 21:47:16 +0100 | [diff] [blame] | 881 | useTestFonts = false, |
| 882 | startPaused = false, |
Ben Konyi | e59d9a8 | 2019-06-11 11:37:47 -0700 | [diff] [blame] | 883 | dartFlags = '', |
Ben Konyi | 3764cb8 | 2019-04-18 21:01:50 -0700 | [diff] [blame] | 884 | disableServiceAuthCodes = false, |
Ben Konyi | 3a5a3ea | 2020-07-29 10:05:40 -0700 | [diff] [blame] | 885 | disableDds = false, |
Alexandre Ardhuin | ef276ff | 2019-01-29 21:47:16 +0100 | [diff] [blame] | 886 | enableSoftwareRendering = false, |
| 887 | skiaDeterministicRendering = false, |
| 888 | traceSkia = false, |
| 889 | traceSystrace = false, |
Gityuan | b8dd6bd | 2020-02-07 04:33:01 +0800 | [diff] [blame] | 890 | endlessTraceBuffer = false, |
liyuqian | be5c83b | 2019-03-15 12:37:53 -0700 | [diff] [blame] | 891 | dumpSkpOnShaderCompilation = false, |
Yuqian Li | 22bf19c | 2020-07-29 12:24:39 -0700 | [diff] [blame] | 892 | purgePersistentCache = false, |
Jonah Williams | 25820ab | 2019-03-13 22:42:12 -0700 | [diff] [blame] | 893 | verboseSystemLogs = false, |
Jonah Williams | e3cb2c3 | 2019-11-13 16:02:46 -0800 | [diff] [blame] | 894 | hostVmServicePort = null, |
Jenn Magder | f8b1de3 | 2020-10-07 08:52:05 -0700 | [diff] [blame] | 895 | disablePortPublication = false, |
Jonah Williams | e3cb2c3 | 2019-11-13 16:02:46 -0800 | [diff] [blame] | 896 | deviceVmServicePort = null, |
Ben Konyi | a17b330 | 2020-09-16 16:27:42 -0700 | [diff] [blame] | 897 | ddsPort = null, |
Jonah Williams | bda9d90 | 2019-12-10 10:26:14 -0800 | [diff] [blame] | 898 | vmserviceOutFile = null, |
Anna Gringauze | bc1c1b2 | 2020-04-17 10:42:02 -0700 | [diff] [blame] | 899 | fastStart = false, |
Jonah Williams | c86d090 | 2020-08-11 11:36:03 -0700 | [diff] [blame] | 900 | webEnableExpressionEvaluation = false, |
Jonah Williams | 9e5c877 | 2020-12-03 08:59:31 -0800 | [diff] [blame] | 901 | nullAssertions = false, |
| 902 | nativeNullAssertions = false; |
Devon Carew | b0dca79 | 2016-04-27 14:43:42 -0700 | [diff] [blame] | 903 | |
| 904 | final bool debuggingEnabled; |
| 905 | |
Mikkel Nygaard Ravn | 9496e6d | 2017-08-23 10:55:35 +0200 | [diff] [blame] | 906 | final BuildInfo buildInfo; |
Devon Carew | b0dca79 | 2016-04-27 14:43:42 -0700 | [diff] [blame] | 907 | final bool startPaused; |
Ben Konyi | e59d9a8 | 2019-06-11 11:37:47 -0700 | [diff] [blame] | 908 | final String dartFlags; |
George Wright | 2b51278 | 2020-11-06 15:34:02 -0800 | [diff] [blame] | 909 | final List<String> dartEntrypointArgs; |
Ben Konyi | 3764cb8 | 2019-04-18 21:01:50 -0700 | [diff] [blame] | 910 | final bool disableServiceAuthCodes; |
Ben Konyi | 3a5a3ea | 2020-07-29 10:05:40 -0700 | [diff] [blame] | 911 | final bool disableDds; |
Gary Qian | a367dcb | 2017-06-02 09:44:36 -0700 | [diff] [blame] | 912 | final bool enableSoftwareRendering; |
Todd Volkert | 21c514f | 2018-02-20 23:22:58 -0800 | [diff] [blame] | 913 | final bool skiaDeterministicRendering; |
Carlo Bernaschina | ba36008 | 2017-09-13 12:59:05 -0700 | [diff] [blame] | 914 | final bool traceSkia; |
Michael Goderbauer | e48b7e9 | 2020-06-19 13:43:02 -0700 | [diff] [blame] | 915 | final String traceAllowlist; |
Chinmay Garde | e38efc8 | 2019-01-28 19:55:01 -0800 | [diff] [blame] | 916 | final bool traceSystrace; |
Gityuan | b8dd6bd | 2020-02-07 04:33:01 +0800 | [diff] [blame] | 917 | final bool endlessTraceBuffer; |
liyuqian | be5c83b | 2019-03-15 12:37:53 -0700 | [diff] [blame] | 918 | final bool dumpSkpOnShaderCompilation; |
liyuqian | 31cb448 | 2019-10-15 14:28:55 -0700 | [diff] [blame] | 919 | final bool cacheSkSL; |
Yuqian Li | 22bf19c | 2020-07-29 12:24:39 -0700 | [diff] [blame] | 920 | final bool purgePersistentCache; |
Ian Hickson | 2a54524 | 2017-04-12 13:33:02 -0700 | [diff] [blame] | 921 | final bool useTestFonts; |
Jonah Williams | 25820ab | 2019-03-13 22:42:12 -0700 | [diff] [blame] | 922 | final bool verboseSystemLogs; |
Jonah Williams | e3cb2c3 | 2019-11-13 16:02:46 -0800 | [diff] [blame] | 923 | final int hostVmServicePort; |
| 924 | final int deviceVmServicePort; |
Jenn Magder | f8b1de3 | 2020-10-07 08:52:05 -0700 | [diff] [blame] | 925 | final bool disablePortPublication; |
Ben Konyi | a17b330 | 2020-09-16 16:27:42 -0700 | [diff] [blame] | 926 | final int ddsPort; |
Jonah Williams | 925a52f | 2019-09-12 08:58:49 -0700 | [diff] [blame] | 927 | final String port; |
| 928 | final String hostname; |
Danny Tuppeny | 4944622 | 2019-12-12 18:43:58 +0000 | [diff] [blame] | 929 | final bool webEnableExposeUrl; |
Danny Tuppeny | 589b14d | 2020-04-08 17:02:03 +0100 | [diff] [blame] | 930 | final bool webUseSseForDebugProxy; |
Danny Tuppeny | f8135ad | 2020-07-13 21:31:04 +0100 | [diff] [blame] | 931 | final bool webUseSseForDebugBackend; |
Yegor | b340469 | 2020-02-13 18:34:08 -0800 | [diff] [blame] | 932 | |
| 933 | /// Whether to run the browser in headless mode. |
| 934 | /// |
| 935 | /// Some CI environments do not provide a display and fail to launch the |
| 936 | /// browser with full graphics stack. Some browsers provide a special |
| 937 | /// "headless" mode that runs the browser with no graphics. |
| 938 | final bool webRunHeadless; |
| 939 | |
| 940 | /// The port the browser should use for its debugging protocol. |
| 941 | final int webBrowserDebugPort; |
| 942 | |
Nolan Scobie | 43c1b34 | 2020-08-06 19:18:52 -0400 | [diff] [blame] | 943 | /// Enable expression evaluation for web target. |
Anna Gringauze | bc1c1b2 | 2020-04-17 10:42:02 -0700 | [diff] [blame] | 944 | final bool webEnableExpressionEvaluation; |
| 945 | |
Jonah Williams | 08576cb | 2020-10-12 09:31:02 -0700 | [diff] [blame] | 946 | /// A file where the VM Service URL should be written after the application is started. |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 947 | final String vmserviceOutFile; |
Jonah Williams | bda9d90 | 2019-12-10 10:26:14 -0800 | [diff] [blame] | 948 | final bool fastStart; |
Devon Carew | b0dca79 | 2016-04-27 14:43:42 -0700 | [diff] [blame] | 949 | |
Jonah Williams | c86d090 | 2020-08-11 11:36:03 -0700 | [diff] [blame] | 950 | final bool nullAssertions; |
| 951 | |
Jonah Williams | 9e5c877 | 2020-12-03 08:59:31 -0800 | [diff] [blame] | 952 | /// Additional null runtime checks inserted for web applications. |
| 953 | /// |
| 954 | /// See also: |
| 955 | /// * https://github.com/dart-lang/sdk/blob/master/sdk/lib/html/doc/NATIVE_NULL_ASSERTIONS.md |
| 956 | final bool nativeNullAssertions; |
| 957 | |
Jonah Williams | e3cb2c3 | 2019-11-13 16:02:46 -0800 | [diff] [blame] | 958 | bool get hasObservatoryPort => hostVmServicePort != null; |
Devon Carew | b0dca79 | 2016-04-27 14:43:42 -0700 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | class LaunchResult { |
Jason Simmons | 1affb42 | 2017-10-30 15:53:04 -0700 | [diff] [blame] | 962 | LaunchResult.succeeded({ this.observatoryUri }) : started = true; |
Alexandre Ardhuin | ef276ff | 2019-01-29 21:47:16 +0100 | [diff] [blame] | 963 | LaunchResult.failed() |
| 964 | : started = false, |
| 965 | observatoryUri = null; |
Devon Carew | b0dca79 | 2016-04-27 14:43:42 -0700 | [diff] [blame] | 966 | |
Dan Rubel | a9584e1 | 2016-11-30 20:29:04 -0500 | [diff] [blame] | 967 | bool get hasObservatory => observatoryUri != null; |
Devon Carew | b0dca79 | 2016-04-27 14:43:42 -0700 | [diff] [blame] | 968 | |
| 969 | final bool started; |
Dan Rubel | a9584e1 | 2016-11-30 20:29:04 -0500 | [diff] [blame] | 970 | final Uri observatoryUri; |
Devon Carew | b0dca79 | 2016-04-27 14:43:42 -0700 | [diff] [blame] | 971 | |
| 972 | @override |
| 973 | String toString() { |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 974 | final StringBuffer buf = StringBuffer('started=$started'); |
Zachary Anderson | e2340c6 | 2019-09-13 14:51:35 -0700 | [diff] [blame] | 975 | if (observatoryUri != null) { |
Dan Rubel | a9584e1 | 2016-11-30 20:29:04 -0500 | [diff] [blame] | 976 | buf.write(', observatory=$observatoryUri'); |
Zachary Anderson | e2340c6 | 2019-09-13 14:51:35 -0700 | [diff] [blame] | 977 | } |
Devon Carew | b0dca79 | 2016-04-27 14:43:42 -0700 | [diff] [blame] | 978 | return buf.toString(); |
| 979 | } |
| 980 | } |
| 981 | |
John McCutchan | 5e140b7 | 2016-03-10 15:48:37 -0800 | [diff] [blame] | 982 | class ForwardedPort { |
Chinmay Garde | 9782d97 | 2016-06-14 11:47:51 -0700 | [diff] [blame] | 983 | ForwardedPort(this.hostPort, this.devicePort) : context = null; |
| 984 | ForwardedPort.withContext(this.hostPort, this.devicePort, this.context); |
John McCutchan | 5e140b7 | 2016-03-10 15:48:37 -0800 | [diff] [blame] | 985 | |
| 986 | final int hostPort; |
| 987 | final int devicePort; |
Alexandre Ardhuin | adc7351 | 2019-11-19 07:57:42 +0100 | [diff] [blame] | 988 | final Process context; |
John McCutchan | 5e140b7 | 2016-03-10 15:48:37 -0800 | [diff] [blame] | 989 | |
Hixie | 797e27e | 2016-03-14 13:31:43 -0700 | [diff] [blame] | 990 | @override |
John McCutchan | 5e140b7 | 2016-03-10 15:48:37 -0800 | [diff] [blame] | 991 | String toString() => 'ForwardedPort HOST:$hostPort to DEVICE:$devicePort'; |
Christopher Fujino | ed482c3 | 2019-10-09 16:30:27 -0700 | [diff] [blame] | 992 | |
| 993 | /// Kill subprocess (if present) used in forwarding. |
| 994 | void dispose() { |
Alexandre Ardhuin | adc7351 | 2019-11-19 07:57:42 +0100 | [diff] [blame] | 995 | if (context != null) { |
| 996 | context.kill(); |
Christopher Fujino | ed482c3 | 2019-10-09 16:30:27 -0700 | [diff] [blame] | 997 | } |
| 998 | } |
John McCutchan | 5e140b7 | 2016-03-10 15:48:37 -0800 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | /// Forward ports from the host machine to the device. |
| 1002 | abstract class DevicePortForwarder { |
| 1003 | /// Returns a Future that completes with the current list of forwarded |
| 1004 | /// ports for this device. |
| 1005 | List<ForwardedPort> get forwardedPorts; |
| 1006 | |
| 1007 | /// Forward [hostPort] on the host to [devicePort] on the device. |
Ian Hickson | 35ad2a7 | 2018-06-27 16:44:28 -0700 | [diff] [blame] | 1008 | /// If [hostPort] is null or zero, will auto select a host port. |
John McCutchan | 5e140b7 | 2016-03-10 15:48:37 -0800 | [diff] [blame] | 1009 | /// Returns a Future that completes with the host port. |
Alexandre Ardhuin | 5169ab5 | 2019-02-21 09:27:07 +0100 | [diff] [blame] | 1010 | Future<int> forward(int devicePort, { int hostPort }); |
John McCutchan | 5e140b7 | 2016-03-10 15:48:37 -0800 | [diff] [blame] | 1011 | |
| 1012 | /// Stops forwarding [forwardedPort]. |
Alexandre Ardhuin | 2d3ff10 | 2018-10-05 07:54:56 +0200 | [diff] [blame] | 1013 | Future<void> unforward(ForwardedPort forwardedPort); |
Christopher Fujino | ed482c3 | 2019-10-09 16:30:27 -0700 | [diff] [blame] | 1014 | |
Nolan Scobie | 43c1b34 | 2020-08-06 19:18:52 -0400 | [diff] [blame] | 1015 | /// Cleanup allocated resources, like [forwardedPorts]. |
Zachary Anderson | 99684ce | 2019-12-05 08:48:00 -0800 | [diff] [blame] | 1016 | Future<void> dispose(); |
John McCutchan | 5e140b7 | 2016-03-10 15:48:37 -0800 | [diff] [blame] | 1017 | } |
| 1018 | |
Devon Carew | b0dca79 | 2016-04-27 14:43:42 -0700 | [diff] [blame] | 1019 | /// Read the log for a particular device. |
Devon Carew | 78e0588 | 2016-02-01 10:36:09 -0800 | [diff] [blame] | 1020 | abstract class DeviceLogReader { |
| 1021 | String get name; |
| 1022 | |
Devon Carew | b0dca79 | 2016-04-27 14:43:42 -0700 | [diff] [blame] | 1023 | /// A broadcast stream where each element in the string is a line of log output. |
| 1024 | Stream<String> get logLines; |
Devon Carew | 78e0588 | 2016-02-01 10:36:09 -0800 | [diff] [blame] | 1025 | |
Jenn Magder | 2e7d913 | 2019-11-01 14:37:17 -0700 | [diff] [blame] | 1026 | /// Some logs can be obtained from a VM service stream. |
| 1027 | /// Set this after the VM services are connected. |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 1028 | vm_service.VmService connectedVMService; |
Jenn Magder | 2e7d913 | 2019-11-01 14:37:17 -0700 | [diff] [blame] | 1029 | |
Hixie | 797e27e | 2016-03-14 13:31:43 -0700 | [diff] [blame] | 1030 | @override |
Devon Carew | 78e0588 | 2016-02-01 10:36:09 -0800 | [diff] [blame] | 1031 | String toString() => name; |
Jason Simmons | 67b3871 | 2017-04-07 13:41:29 -0700 | [diff] [blame] | 1032 | |
Greg Spencer | 0259be9 | 2017-11-17 10:05:21 -0800 | [diff] [blame] | 1033 | /// Process ID of the app on the device. |
Jason Simmons | 67b3871 | 2017-04-07 13:41:29 -0700 | [diff] [blame] | 1034 | int appPid; |
Christopher Fujino | ed482c3 | 2019-10-09 16:30:27 -0700 | [diff] [blame] | 1035 | |
| 1036 | // Clean up resources allocated by log reader e.g. subprocesses |
Zachary Anderson | 99684ce | 2019-12-05 08:48:00 -0800 | [diff] [blame] | 1037 | void dispose(); |
Devon Carew | 78e0588 | 2016-02-01 10:36:09 -0800 | [diff] [blame] | 1038 | } |
Jason Simmons | 00c7734 | 2016-06-02 14:00:27 -0700 | [diff] [blame] | 1039 | |
| 1040 | /// Describes an app running on the device. |
| 1041 | class DiscoveredApp { |
Jason Simmons | 1affb42 | 2017-10-30 15:53:04 -0700 | [diff] [blame] | 1042 | DiscoveredApp(this.id, this.observatoryPort); |
Jason Simmons | 00c7734 | 2016-06-02 14:00:27 -0700 | [diff] [blame] | 1043 | final String id; |
| 1044 | final int observatoryPort; |
| 1045 | } |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 1046 | |
| 1047 | // An empty device log reader |
| 1048 | class NoOpDeviceLogReader implements DeviceLogReader { |
| 1049 | NoOpDeviceLogReader(this.name); |
| 1050 | |
| 1051 | @override |
| 1052 | final String name; |
| 1053 | |
| 1054 | @override |
| 1055 | int appPid; |
| 1056 | |
| 1057 | @override |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 1058 | vm_service.VmService connectedVMService; |
Jenn Magder | 2e7d913 | 2019-11-01 14:37:17 -0700 | [diff] [blame] | 1059 | |
| 1060 | @override |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 1061 | Stream<String> get logLines => const Stream<String>.empty(); |
Christopher Fujino | ed482c3 | 2019-10-09 16:30:27 -0700 | [diff] [blame] | 1062 | |
| 1063 | @override |
| 1064 | void dispose() { } |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 1065 | } |
| 1066 | |
Jonah Williams | 08576cb | 2020-10-12 09:31:02 -0700 | [diff] [blame] | 1067 | // A port forwarder which does not support forwarding ports. |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 1068 | class NoOpDevicePortForwarder implements DevicePortForwarder { |
| 1069 | const NoOpDevicePortForwarder(); |
| 1070 | |
| 1071 | @override |
Alexandre Ardhuin | 5169ab5 | 2019-02-21 09:27:07 +0100 | [diff] [blame] | 1072 | Future<int> forward(int devicePort, { int hostPort }) async => devicePort; |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 1073 | |
| 1074 | @override |
| 1075 | List<ForwardedPort> get forwardedPorts => <ForwardedPort>[]; |
| 1076 | |
| 1077 | @override |
Alexandre Ardhuin | a0d1f93 | 2019-03-09 09:03:11 +0100 | [diff] [blame] | 1078 | Future<void> unforward(ForwardedPort forwardedPort) async { } |
Christopher Fujino | ed482c3 | 2019-10-09 16:30:27 -0700 | [diff] [blame] | 1079 | |
| 1080 | @override |
| 1081 | Future<void> dispose() async { } |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 1082 | } |
Jonah Williams | c86d090 | 2020-08-11 11:36:03 -0700 | [diff] [blame] | 1083 | |
| 1084 | /// Append --null_assertions to any existing Dart VM flags if |
| 1085 | /// [debuggingOptions.nullAssertions] is true. |
| 1086 | String computeDartVmFlags(DebuggingOptions debuggingOptions) { |
| 1087 | return <String>[ |
| 1088 | if (debuggingOptions.dartFlags?.isNotEmpty ?? false) |
| 1089 | debuggingOptions.dartFlags, |
| 1090 | if (debuggingOptions.nullAssertions) |
| 1091 | '--null_assertions', |
| 1092 | ].join(','); |
| 1093 | } |