Detect USB/network interface from iOS devices (#58257)
This commit is contained in:
@@ -58,7 +58,7 @@ class IOSDevices extends PollingDeviceDiscovery {
|
||||
);
|
||||
}
|
||||
|
||||
return await _xcdevice.getAvailableTetheredIOSDevices(timeout: timeout);
|
||||
return await _xcdevice.getAvailableIOSDevices(timeout: timeout);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -73,11 +73,18 @@ class IOSDevices extends PollingDeviceDiscovery {
|
||||
}
|
||||
}
|
||||
|
||||
enum IOSDeviceInterface {
|
||||
none,
|
||||
usb,
|
||||
network,
|
||||
}
|
||||
|
||||
class IOSDevice extends Device {
|
||||
IOSDevice(String id, {
|
||||
@required FileSystem fileSystem,
|
||||
@required this.name,
|
||||
@required this.cpuArchitecture,
|
||||
@required this.interfaceType,
|
||||
@required String sdkVersion,
|
||||
@required Platform platform,
|
||||
@required Artifacts artifacts,
|
||||
@@ -123,16 +130,21 @@ class IOSDevice extends Device {
|
||||
}
|
||||
|
||||
@override
|
||||
bool get supportsHotReload => true;
|
||||
bool get supportsHotReload => interfaceType == IOSDeviceInterface.usb;
|
||||
|
||||
@override
|
||||
bool get supportsHotRestart => true;
|
||||
bool get supportsHotRestart => interfaceType == IOSDeviceInterface.usb;
|
||||
|
||||
@override
|
||||
bool get supportsFlutterExit => interfaceType == IOSDeviceInterface.usb;
|
||||
|
||||
@override
|
||||
final String name;
|
||||
|
||||
final DarwinArch cpuArchitecture;
|
||||
|
||||
final IOSDeviceInterface interfaceType;
|
||||
|
||||
Map<IOSApp, DeviceLogReader> _logReaders;
|
||||
|
||||
DevicePortForwarder _portForwarder;
|
||||
@@ -178,6 +190,7 @@ class IOSDevice extends Device {
|
||||
deviceId: id,
|
||||
bundlePath: bundle.path,
|
||||
launchArguments: <String>[],
|
||||
interfaceType: interfaceType,
|
||||
);
|
||||
} on ProcessException catch (e) {
|
||||
_logger.printError(e.message);
|
||||
@@ -319,6 +332,7 @@ class IOSDevice extends Device {
|
||||
deviceId: id,
|
||||
bundlePath: bundle.path,
|
||||
launchArguments: launchArguments,
|
||||
interfaceType: interfaceType,
|
||||
);
|
||||
if (installationResult != 0) {
|
||||
_logger.printError('Could not run ${bundle.path} on $id.');
|
||||
@@ -410,7 +424,7 @@ class IOSDevice extends Device {
|
||||
void clearLogs() { }
|
||||
|
||||
@override
|
||||
bool get supportsScreenshot => _iMobileDevice.isInstalled;
|
||||
bool get supportsScreenshot => _iMobileDevice.isInstalled && interfaceType == IOSDeviceInterface.usb;
|
||||
|
||||
@override
|
||||
Future<void> takeScreenshot(File outputFile) async {
|
||||
|
||||
@@ -14,6 +14,7 @@ import '../base/process.dart';
|
||||
import '../build_info.dart';
|
||||
import '../cache.dart';
|
||||
import 'code_signing.dart';
|
||||
import 'devices.dart';
|
||||
|
||||
// Error message patterns from ios-deploy output
|
||||
const String noProvisioningProfileErrorOne = 'Error 0xe8008015';
|
||||
@@ -84,6 +85,7 @@ class IOSDeploy {
|
||||
@required String deviceId,
|
||||
@required String bundlePath,
|
||||
@required List<String>launchArguments,
|
||||
@required IOSDeviceInterface interfaceType,
|
||||
}) async {
|
||||
final List<String> launchCommand = <String>[
|
||||
_binaryPath,
|
||||
@@ -91,7 +93,8 @@ class IOSDeploy {
|
||||
deviceId,
|
||||
'--bundle',
|
||||
bundlePath,
|
||||
'--no-wifi',
|
||||
if (interfaceType != IOSDeviceInterface.network)
|
||||
'--no-wifi',
|
||||
if (launchArguments.isNotEmpty) ...<String>[
|
||||
'--args',
|
||||
launchArguments.join(' '),
|
||||
@@ -113,6 +116,7 @@ class IOSDeploy {
|
||||
@required String deviceId,
|
||||
@required String bundlePath,
|
||||
@required List<String> launchArguments,
|
||||
@required IOSDeviceInterface interfaceType,
|
||||
}) async {
|
||||
final List<String> launchCommand = <String>[
|
||||
_binaryPath,
|
||||
@@ -120,7 +124,8 @@ class IOSDeploy {
|
||||
deviceId,
|
||||
'--bundle',
|
||||
bundlePath,
|
||||
'--no-wifi',
|
||||
if (interfaceType != IOSDeviceInterface.network)
|
||||
'--no-wifi',
|
||||
'--justlaunch',
|
||||
if (launchArguments.isNotEmpty) ...<String>[
|
||||
'--args',
|
||||
|
||||
@@ -290,7 +290,7 @@ class XCDevice {
|
||||
List<dynamic> _cachedListResults;
|
||||
|
||||
/// [timeout] defaults to 2 seconds.
|
||||
Future<List<IOSDevice>> getAvailableTetheredIOSDevices({ Duration timeout }) async {
|
||||
Future<List<IOSDevice>> getAvailableIOSDevices({ Duration timeout }) async {
|
||||
final List<dynamic> allAvailableDevices = await _getAllDevices(timeout: timeout ?? const Duration(seconds: 2));
|
||||
|
||||
if (allAvailableDevices == null) {
|
||||
@@ -364,8 +364,11 @@ class XCDevice {
|
||||
}
|
||||
}
|
||||
|
||||
final IOSDeviceInterface interface = _interfaceType(deviceProperties);
|
||||
|
||||
// Only support USB devices, skip "network" interface (Xcode > Window > Devices and Simulators > Connect via network).
|
||||
if (!_isUSBTethered(deviceProperties)) {
|
||||
// TODO(jmagman): Remove this check once wirelessly detected devices can be observed and attached, https://github.com/flutter/flutter/issues/15072.
|
||||
if (interface != IOSDeviceInterface.usb) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -373,6 +376,7 @@ class XCDevice {
|
||||
device['identifier'] as String,
|
||||
name: device['name'] as String,
|
||||
cpuArchitecture: _cpuArchitecture(deviceProperties),
|
||||
interfaceType: interface,
|
||||
sdkVersion: _sdkVersion(deviceProperties),
|
||||
artifacts: globals.artifacts,
|
||||
fileSystem: globals.fs,
|
||||
@@ -409,10 +413,18 @@ class XCDevice {
|
||||
return null;
|
||||
}
|
||||
|
||||
static bool _isUSBTethered(Map<String, dynamic> deviceProperties) {
|
||||
// Interface can be "usb", "network", or not present for simulators.
|
||||
return deviceProperties.containsKey('interface') &&
|
||||
(deviceProperties['interface'] as String).toLowerCase() == 'usb';
|
||||
static IOSDeviceInterface _interfaceType(Map<String, dynamic> deviceProperties) {
|
||||
// Interface can be "usb", "network", or "none" for simulators
|
||||
// and unknown future interfaces.
|
||||
if (deviceProperties.containsKey('interface')) {
|
||||
if ((deviceProperties['interface'] as String).toLowerCase() == 'network') {
|
||||
return IOSDeviceInterface.network;
|
||||
} else {
|
||||
return IOSDeviceInterface.usb;
|
||||
}
|
||||
}
|
||||
|
||||
return IOSDeviceInterface.none;
|
||||
}
|
||||
|
||||
static String _sdkVersion(Map<String, dynamic> deviceProperties) {
|
||||
|
||||
Reference in New Issue
Block a user