Move iMobileDevice to globals (#49724)
This commit is contained in:
@@ -14,6 +14,7 @@ import 'base/io.dart';
|
||||
import 'base/logger.dart';
|
||||
import 'base/terminal.dart';
|
||||
import 'cache.dart';
|
||||
import 'ios/mac.dart';
|
||||
import 'macos/xcode.dart';
|
||||
import 'version.dart';
|
||||
|
||||
@@ -44,6 +45,7 @@ Platform get platform => context.get<Platform>() ?? _kLocalPlatform;
|
||||
|
||||
Xcode get xcode => context.get<Xcode>();
|
||||
FlutterVersion get flutterVersion => context.get<FlutterVersion>();
|
||||
IMobileDevice get iMobileDevice => context.get<IMobileDevice>();
|
||||
|
||||
/// Display an error level message to the user. Commands should use this if they
|
||||
/// fail in some way.
|
||||
|
||||
@@ -174,20 +174,20 @@ class IOSDevice extends Device {
|
||||
if (!globals.platform.isMacOS) {
|
||||
throw UnsupportedError('Control of iOS devices or simulators only supported on Mac OS.');
|
||||
}
|
||||
if (!iMobileDevice.isInstalled) {
|
||||
if (!globals.iMobileDevice.isInstalled) {
|
||||
return <IOSDevice>[];
|
||||
}
|
||||
|
||||
final List<IOSDevice> devices = <IOSDevice>[];
|
||||
for (String id in (await iMobileDevice.getAvailableDeviceIDs()).split('\n')) {
|
||||
for (String id in (await globals.iMobileDevice.getAvailableDeviceIDs()).split('\n')) {
|
||||
id = id.trim();
|
||||
if (id.isEmpty) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
final String deviceName = await iMobileDevice.getInfoForDevice(id, 'DeviceName');
|
||||
final String sdkVersion = await iMobileDevice.getInfoForDevice(id, 'ProductVersion');
|
||||
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.
|
||||
@@ -283,7 +283,7 @@ class IOSDevice extends Device {
|
||||
String cpuArchitecture;
|
||||
|
||||
try {
|
||||
cpuArchitecture = await iMobileDevice.getInfoForDevice(id, 'CPUArchitecture');
|
||||
cpuArchitecture = await globals.iMobileDevice.getInfoForDevice(id, 'CPUArchitecture');
|
||||
} on IOSDeviceNotFoundError catch (e) {
|
||||
globals.printError(e.message);
|
||||
return LaunchResult.failed();
|
||||
@@ -460,11 +460,11 @@ class IOSDevice extends Device {
|
||||
void clearLogs() { }
|
||||
|
||||
@override
|
||||
bool get supportsScreenshot => iMobileDevice.isInstalled;
|
||||
bool get supportsScreenshot => globals.iMobileDevice.isInstalled;
|
||||
|
||||
@override
|
||||
Future<void> takeScreenshot(File outputFile) async {
|
||||
await iMobileDevice.takeScreenshot(outputFile);
|
||||
await globals.iMobileDevice.takeScreenshot(outputFile);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -610,7 +610,7 @@ class IOSDeviceLogReader extends DeviceLogReader {
|
||||
if (device.majorSdkVersion >= _minimumUniversalLoggingSdkVersion) {
|
||||
return;
|
||||
}
|
||||
iMobileDevice.startLogger(device.id).then<void>((Process process) {
|
||||
globals.iMobileDevice.startLogger(device.id).then<void>((Process process) {
|
||||
process.stdout.transform<String>(utf8.decoder).transform<String>(const LineSplitter()).listen(_newSyslogLineHandler());
|
||||
process.stderr.transform<String>(utf8.decoder).transform<String>(const LineSplitter()).listen(_newSyslogLineHandler());
|
||||
process.exitCode.whenComplete(() {
|
||||
|
||||
@@ -9,7 +9,6 @@ import 'package:meta/meta.dart';
|
||||
import '../application_package.dart';
|
||||
import '../artifacts.dart';
|
||||
import '../base/common.dart';
|
||||
import '../base/context.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/logger.dart';
|
||||
@@ -26,8 +25,6 @@ import '../reporting/reporting.dart';
|
||||
import 'code_signing.dart';
|
||||
import 'xcodeproj.dart';
|
||||
|
||||
IMobileDevice get iMobileDevice => context.get<IMobileDevice>();
|
||||
|
||||
/// Specialized exception for expected situations where the ideviceinfo
|
||||
/// tool responds with exit code 255 / 'No device found' message
|
||||
class IOSDeviceNotFoundError implements Exception {
|
||||
|
||||
@@ -770,8 +770,8 @@ void main() {
|
||||
});
|
||||
|
||||
testUsingContext('returns no devices if none are attached', () async {
|
||||
when(iMobileDevice.isInstalled).thenReturn(true);
|
||||
when(iMobileDevice.getAvailableDeviceIDs())
|
||||
when(globals.iMobileDevice.isInstalled).thenReturn(true);
|
||||
when(globals.iMobileDevice.getAvailableDeviceIDs())
|
||||
.thenAnswer((Invocation invocation) => Future<String>.value(''));
|
||||
final List<IOSDevice> devices = await IOSDevice.getAttachedDevices();
|
||||
expect(devices, isEmpty);
|
||||
@@ -783,8 +783,8 @@ void main() {
|
||||
final List<Platform> unsupportedPlatforms = <Platform>[linuxPlatform, windowsPlatform];
|
||||
for (final Platform platform in unsupportedPlatforms) {
|
||||
testUsingContext('throws Unsupported Operation exception on ${platform.operatingSystem}', () async {
|
||||
when(iMobileDevice.isInstalled).thenReturn(false);
|
||||
when(iMobileDevice.getAvailableDeviceIDs())
|
||||
when(globals.iMobileDevice.isInstalled).thenReturn(false);
|
||||
when(globals.iMobileDevice.getAvailableDeviceIDs())
|
||||
.thenAnswer((Invocation invocation) => Future<String>.value(''));
|
||||
expect(
|
||||
() async { await IOSDevice.getAttachedDevices(); },
|
||||
@@ -797,19 +797,19 @@ void main() {
|
||||
}
|
||||
|
||||
testUsingContext('returns attached devices', () async {
|
||||
when(iMobileDevice.isInstalled).thenReturn(true);
|
||||
when(iMobileDevice.getAvailableDeviceIDs())
|
||||
when(globals.iMobileDevice.isInstalled).thenReturn(true);
|
||||
when(globals.iMobileDevice.getAvailableDeviceIDs())
|
||||
.thenAnswer((Invocation invocation) => Future<String>.value('''
|
||||
98206e7a4afd4aedaff06e687594e089dede3c44
|
||||
f577a7903cc54959be2e34bc4f7f80b7009efcf4
|
||||
'''));
|
||||
when(iMobileDevice.getInfoForDevice('98206e7a4afd4aedaff06e687594e089dede3c44', 'DeviceName'))
|
||||
when(globals.iMobileDevice.getInfoForDevice('98206e7a4afd4aedaff06e687594e089dede3c44', 'DeviceName'))
|
||||
.thenAnswer((_) => Future<String>.value('La tele me regarde'));
|
||||
when(iMobileDevice.getInfoForDevice('98206e7a4afd4aedaff06e687594e089dede3c44', 'ProductVersion'))
|
||||
when(globals.iMobileDevice.getInfoForDevice('98206e7a4afd4aedaff06e687594e089dede3c44', 'ProductVersion'))
|
||||
.thenAnswer((_) => Future<String>.value('10.3.2'));
|
||||
when(iMobileDevice.getInfoForDevice('f577a7903cc54959be2e34bc4f7f80b7009efcf4', 'DeviceName'))
|
||||
when(globals.iMobileDevice.getInfoForDevice('f577a7903cc54959be2e34bc4f7f80b7009efcf4', 'DeviceName'))
|
||||
.thenAnswer((_) => Future<String>.value('Puits sans fond'));
|
||||
when(iMobileDevice.getInfoForDevice('f577a7903cc54959be2e34bc4f7f80b7009efcf4', 'ProductVersion'))
|
||||
when(globals.iMobileDevice.getInfoForDevice('f577a7903cc54959be2e34bc4f7f80b7009efcf4', 'ProductVersion'))
|
||||
.thenAnswer((_) => Future<String>.value('11.0'));
|
||||
final List<IOSDevice> devices = await IOSDevice.getAttachedDevices();
|
||||
expect(devices, hasLength(2));
|
||||
@@ -823,15 +823,15 @@ f577a7903cc54959be2e34bc4f7f80b7009efcf4
|
||||
});
|
||||
|
||||
testUsingContext('returns attached devices and ignores devices that cannot be found by ideviceinfo', () async {
|
||||
when(iMobileDevice.isInstalled).thenReturn(true);
|
||||
when(iMobileDevice.getAvailableDeviceIDs())
|
||||
when(globals.iMobileDevice.isInstalled).thenReturn(true);
|
||||
when(globals.iMobileDevice.getAvailableDeviceIDs())
|
||||
.thenAnswer((Invocation invocation) => Future<String>.value('''
|
||||
98206e7a4afd4aedaff06e687594e089dede3c44
|
||||
f577a7903cc54959be2e34bc4f7f80b7009efcf4
|
||||
'''));
|
||||
when(iMobileDevice.getInfoForDevice('98206e7a4afd4aedaff06e687594e089dede3c44', 'DeviceName'))
|
||||
when(globals.iMobileDevice.getInfoForDevice('98206e7a4afd4aedaff06e687594e089dede3c44', 'DeviceName'))
|
||||
.thenAnswer((_) => Future<String>.value('La tele me regarde'));
|
||||
when(iMobileDevice.getInfoForDevice('f577a7903cc54959be2e34bc4f7f80b7009efcf4', 'DeviceName'))
|
||||
when(globals.iMobileDevice.getInfoForDevice('f577a7903cc54959be2e34bc4f7f80b7009efcf4', 'DeviceName'))
|
||||
.thenThrow(const IOSDeviceNotFoundError('Device not found'));
|
||||
final List<IOSDevice> devices = await IOSDevice.getAttachedDevices();
|
||||
expect(devices, hasLength(1));
|
||||
|
||||
@@ -60,7 +60,7 @@ void main() {
|
||||
when(mockProcessManager.runSync(
|
||||
<String>[ideviceIdPath, '-h'], environment: anyNamed('environment'),
|
||||
)).thenReturn(ProcessResult(123, 1, '', ''));
|
||||
expect(await iMobileDevice.isWorking, false);
|
||||
expect(await globals.iMobileDevice.isWorking, false);
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Artifacts: () => mockArtifacts,
|
||||
@@ -71,7 +71,7 @@ void main() {
|
||||
<String>[ideviceIdPath, '-l'],
|
||||
environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath},
|
||||
)).thenThrow(ProcessException(ideviceIdPath, <String>['-l']));
|
||||
expect(() async => await iMobileDevice.getAvailableDeviceIDs(), throwsToolExit());
|
||||
expect(() async => await globals.iMobileDevice.getAvailableDeviceIDs(), throwsToolExit());
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Cache: () => mockCache,
|
||||
@@ -83,7 +83,7 @@ void main() {
|
||||
<String>[ideviceIdPath, '-l'],
|
||||
environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath},
|
||||
)).thenAnswer((_) => Future<ProcessResult>.value(ProcessResult(1, 1, '', 'Sad today')));
|
||||
expect(() async => await iMobileDevice.getAvailableDeviceIDs(), throwsToolExit());
|
||||
expect(() async => await globals.iMobileDevice.getAvailableDeviceIDs(), throwsToolExit());
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Cache: () => mockCache,
|
||||
@@ -95,7 +95,7 @@ void main() {
|
||||
<String>[ideviceIdPath, '-l'],
|
||||
environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath},
|
||||
)).thenAnswer((_) => Future<ProcessResult>.value(ProcessResult(1, 0, 'foo', '')));
|
||||
expect(await iMobileDevice.getAvailableDeviceIDs(), 'foo');
|
||||
expect(await globals.iMobileDevice.getAvailableDeviceIDs(), 'foo');
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Cache: () => mockCache,
|
||||
@@ -108,7 +108,7 @@ void main() {
|
||||
<String>[ideviceInfoPath, '-u', 'foo', '-k', 'bar'],
|
||||
environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath},
|
||||
)).thenAnswer((_) => Future<ProcessResult>.value(ProcessResult(1, 255, 'No device found with udid foo, is it plugged in?', '')));
|
||||
expect(() async => await iMobileDevice.getInfoForDevice('foo', 'bar'), throwsA(isA<IOSDeviceNotFoundError>()));
|
||||
expect(() async => await globals.iMobileDevice.getInfoForDevice('foo', 'bar'), throwsA(isA<IOSDeviceNotFoundError>()));
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Cache: () => mockCache,
|
||||
@@ -129,7 +129,7 @@ void main() {
|
||||
);
|
||||
return Future<ProcessResult>.value(result);
|
||||
});
|
||||
expect(() async => await iMobileDevice.getInfoForDevice('foo', 'bar'), throwsA(isA<IOSDeviceNotTrustedError>()));
|
||||
expect(() async => await globals.iMobileDevice.getInfoForDevice('foo', 'bar'), throwsA(isA<IOSDeviceNotTrustedError>()));
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Cache: () => mockCache,
|
||||
@@ -150,7 +150,7 @@ void main() {
|
||||
);
|
||||
return Future<ProcessResult>.value(result);
|
||||
});
|
||||
expect(() async => await iMobileDevice.getInfoForDevice('foo', 'bar'), throwsToolExit());
|
||||
expect(() async => await globals.iMobileDevice.getInfoForDevice('foo', 'bar'), throwsToolExit());
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Cache: () => mockCache,
|
||||
@@ -171,7 +171,7 @@ void main() {
|
||||
);
|
||||
return Future<ProcessResult>.value(result);
|
||||
});
|
||||
expect(() async => await iMobileDevice.getInfoForDevice('foo', 'bar'), throwsA(isA<IOSDeviceNotTrustedError>()));
|
||||
expect(() async => await globals.iMobileDevice.getInfoForDevice('foo', 'bar'), throwsA(isA<IOSDeviceNotTrustedError>()));
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Cache: () => mockCache,
|
||||
@@ -198,7 +198,7 @@ void main() {
|
||||
workingDirectory: null,
|
||||
)).thenAnswer((_) => Future<ProcessResult>.value(ProcessResult(4, 1, '', '')));
|
||||
|
||||
expect(() async => await iMobileDevice.takeScreenshot(mockOutputFile), throwsA(anything));
|
||||
expect(() async => await globals.iMobileDevice.takeScreenshot(mockOutputFile), throwsA(anything));
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Platform: () => osx,
|
||||
@@ -210,7 +210,7 @@ void main() {
|
||||
when(mockProcessManager.run(any, environment: anyNamed('environment'), workingDirectory: null)).thenAnswer(
|
||||
(Invocation invocation) => Future<ProcessResult>.value(ProcessResult(4, 0, '', '')));
|
||||
|
||||
await iMobileDevice.takeScreenshot(mockOutputFile);
|
||||
await globals.iMobileDevice.takeScreenshot(mockOutputFile);
|
||||
verify(mockProcessManager.run(<String>[idevicescreenshotPath, outputPath],
|
||||
environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath},
|
||||
workingDirectory: null,
|
||||
|
||||
Reference in New Issue
Block a user