Unverified Commit a0665aba authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Reland Replace ideviceinfo and idevice_id with xcdevice (#50252)

parent fbb3d281
......@@ -166,6 +166,11 @@ Future<T> runInContext<T>(
fileSystem: globals.fs,
xcodeProjectInterpreter: xcodeProjectInterpreter,
),
XCDevice: () => XCDevice(
processManager: globals.processManager,
logger: globals.logger,
xcode: globals.xcode,
),
XcodeProjectInterpreter: () => XcodeProjectInterpreter(
logger: globals.logger,
processManager: globals.processManager,
......
......@@ -57,6 +57,8 @@ Xcode get xcode => context.get<Xcode>();
FlutterVersion get flutterVersion => context.get<FlutterVersion>();
IMobileDevice get iMobileDevice => context.get<IMobileDevice>();
XCDevice get xcdevice => context.get<XCDevice>();
/// Display an error level message to the user. Commands should use this if they
/// fail in some way.
///
......
......@@ -5,6 +5,7 @@
import 'dart:async';
import 'package:meta/meta.dart';
import 'package:platform/platform.dart';
import '../application_package.dart';
import '../artifacts.dart';
......@@ -18,6 +19,7 @@ import '../build_info.dart';
import '../convert.dart';
import '../device.dart';
import '../globals.dart' as globals;
import '../macos/xcode.dart';
import '../mdns_discovery.dart';
import '../project.dart';
import '../protocol_discovery.dart';
......@@ -111,11 +113,18 @@ class IOSDevices extends PollingDeviceDiscovery {
bool get canListAnything => iosWorkflow.canListDevices;
@override
Future<List<Device>> pollingGetDevices() => IOSDevice.getAttachedDevices();
Future<List<Device>> pollingGetDevices() => IOSDevice.getAttachedDevices(globals.platform, globals.xcdevice);
@override
Future<List<String>> getDiagnostics() => IOSDevice.getDiagnostics(globals.platform, globals.xcdevice);
}
class IOSDevice extends Device {
IOSDevice(String id, { this.name, String sdkVersion })
IOSDevice(String id, {
@required this.name,
@required this.cpuArchitecture,
@required String sdkVersion,
})
: _sdkVersion = sdkVersion,
super(
id,
......@@ -157,6 +166,8 @@ class IOSDevice extends Device {
@override
final String name;
final DarwinArch cpuArchitecture;
Map<IOSApp, DeviceLogReader> _logReaders;
DevicePortForwarder _portForwarder;
......@@ -170,34 +181,20 @@ class IOSDevice extends Device {
@override
bool get supportsStartPaused => false;
static Future<List<IOSDevice>> getAttachedDevices() async {
if (!globals.platform.isMacOS) {
throw UnsupportedError('Control of iOS devices or simulators only supported on Mac OS.');
}
if (!globals.iMobileDevice.isInstalled) {
return <IOSDevice>[];
static Future<List<IOSDevice>> getAttachedDevices(Platform platform, XCDevice xcdevice) async {
if (!platform.isMacOS) {
throw UnsupportedError('Control of iOS devices or simulators only supported on macOS.');
}
final List<IOSDevice> devices = <IOSDevice>[];
for (String id in (await globals.iMobileDevice.getAvailableDeviceIDs()).split('\n')) {
id = id.trim();
if (id.isEmpty) {
continue;
}
return await xcdevice.getAvailableTetheredIOSDevices();
}
try {
final String deviceName = await globals.iMobileDevice.getInfoForDevice(id, 'DeviceName');
final String sdkVersion = await globals.iMobileDevice.getInfoForDevice(id, 'ProductVersion');
devices.add(IOSDevice(id, name: deviceName, sdkVersion: sdkVersion));
} on IOSDeviceNotFoundError catch (error) {
// Unable to find device with given udid. Possibly a network device.
globals.printTrace('Error getting attached iOS device: $error');
} on IOSDeviceNotTrustedError catch (error) {
globals.printTrace('Error getting attached iOS device information: $error');
UsageEvent('device', 'ios-trust-failure').send();
}
static Future<List<String>> getDiagnostics(Platform platform, XCDevice xcdevice) async {
if (!platform.isMacOS) {
return const <String>['Control of iOS devices or simulators only supported on macOS.'];
}
return devices;
return await xcdevice.getDiagnostics();
}
@override
......@@ -280,24 +277,13 @@ class IOSDevice extends Device {
// TODO(chinmaygarde): Use mainPath, route.
globals.printTrace('Building ${package.name} for $id');
String cpuArchitecture;
try {
cpuArchitecture = await globals.iMobileDevice.getInfoForDevice(id, 'CPUArchitecture');
} on IOSDeviceNotFoundError catch (e) {
globals.printError(e.message);
return LaunchResult.failed();
}
final DarwinArch iosArch = getIOSArchForName(cpuArchitecture);
// Step 1: Build the precompiled/DBC application if necessary.
final XcodeBuildResult buildResult = await buildXcodeProject(
app: package as BuildableIOSApp,
buildInfo: debuggingOptions.buildInfo,
targetOverride: mainPath,
buildForDevice: true,
activeArch: iosArch,
activeArch: cpuArchitecture,
);
if (!buildResult.success) {
globals.printError('Could not build the precompiled application for the device.');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment