Skip to content

Conversation

@cbracken
Copy link
Member

Extract out IMobileDevice class, move class to idevice_id, ideviceinfo
(and eventually other libimobiledevice tools such as iproxy) behind this
interface.

Add tests for the case where libimobiledevice is not installed, the case
where it returns no devices, and the case where it returns device IDs.

Extract out IMobileDevice class, move class to idevice_id, ideviceinfo
(and eventually other libimobiledevice tools such as iproxy) behind this
interface.

Add tests for the case where libimobiledevice is not installed, the case
where it returns no devices, and the case where it returns device IDs.
@cbracken cbracken requested a review from tvolkert June 16, 2017 01:03
@cbracken
Copy link
Member Author

Prefactoring for #10602, #10633


IOSWorkflow get iosWorkflow => context.putIfAbsent(IOSWorkflow, () => new IOSWorkflow());

IMobileDevice get iMobileDevice => IMobileDevice.instance;
Copy link
Member Author

@cbracken cbracken Jun 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could move this to mac.dart and kill the instance getter there. If we do that, probably worth doing the same for the Xcode.instance getter. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


// If a device is attached, verify that we can get its name.
final ProcessResult result = (await runAsync(<String>['idevice_id', '-l'])).processResult;
if (result.exitCode == 0 && result.stdout.isNotEmpty && !await exitsHappyAsync(<String>['idevicename']))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, this logic seems wrong... if idevice_id -l exits non-zero, we say isWorking==true??

In any case, with the logic as it is, how abut the following phrasing?

    return result.exitCode != 0
        || result.stdout.isEmpty
        || await exitsHappyAsync(<String>['idevicename']);

Copy link
Member Author

@cbracken cbracken Jun 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The breakage this is detecting happens when idevice_id returns 0, but idevicename returns non-zero.

Specifically we're looking for the case where:

  1. There are devices attached: idevice_id returns 0 when devices are attached, non-zero otherwise.
  2. We fail to get the name of the attached device(s): idevicename returns non-zero in this case.

This typically happens when an older version of libimobiledevice is installed that can't handle the iOS version on the device. (Unfortunately libimobiledevice tools don't include a --version flag or we'd just do that)

The reason for the current phrasing was an effort to make the above condition slightly more direct, but if that's not the case, I can definitely demorgan's it the other way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same logic, but broke it up a bit and added comments.

}

List<String> getAttachedDeviceIDs() {
return runSync(<String>['idevice_id', '-l']).trim().split('\n').where((String line) => line.isNotEmpty).toList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newlines for cascade?

    return runSync(<String>['idevice_id', '-l'])
        .trim()
        .split('\n')
        .where((String line) => line.isNotEmpty)
        .toList();

return true;
}

List<String> getAttachedDeviceIDs() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How tough is it to change this to Stream<String> and use runAsync()? We've had bugs in this code where sync process invocations hang flutter tools indefinitely (if the child process doesn't exit), whereas in async, we can time them out.

Copy link
Member Author

@cbracken cbracken Jun 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Painful -- it cascades down to a whole bunch of API changes to shared iOS and Android interfaces :( I think it's worth doing, but I'd rather avoid doing it as part of this change.

}

static String _getDeviceInfo(String deviceID, String infoKey) {
final String informerPath = _checkForCommand('ideviceinfo');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed - informerPath exists as an instance getter (and is the same value).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better, after killing off _getDeviceInfo, informerPath isn't needed either.

}
}

static String _getDeviceInfo(String deviceID, String infoKey) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this can be removed in favor of IMobileDevice.getInfoForDevice()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@cbracken cbracken merged commit d6ec71d into flutter:master Jun 16, 2017
@cbracken cbracken deleted the list-devices-test branch June 16, 2017 02:03
gspencergoog pushed a commit to gspencergoog/flutter that referenced this pull request Jul 1, 2017
Extract out IMobileDevice class, move class to idevice_id, ideviceinfo
(and eventually other libimobiledevice tools such as iproxy) behind this
interface.

Add tests for the case where libimobiledevice is not installed, the case
where it returns no devices, and the case where it returns device IDs.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants