Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fixup API usage to make ios-deploy work also with wifi connections #385

Merged
merged 4 commits into from
Jul 17, 2019

Conversation

Ukalnins
Copy link

This quite a large change, comes dowm to few changes.

  • Added ServiceConnRef and AFCConnectionRef typedefs to better separate when what is used.
  • Fixed some API usege to use functions that work on both WIFI and USB. This was done in start_remote_debug_server and start_house_arrest_service.
  • Removed some incorrect assert usage, that would break if someone compiled it for release.

@Ukalnins
Copy link
Author

Should probably fix #370 and #340 and #320 .

@reidhoch
Copy link

reidhoch commented Jun 7, 2019

Any chance of seeing this merged soon?

@gabebear
Copy link

This also fixes problems I'm having with launching the debugServer on iOS13 (not over Wifi)

@Ukalnins
Copy link
Author

This also fixes problems I'm having with launching the debugServer on iOS13 (not over Wifi)

Nice to hear. Have not gotten around on testing anything on ios 13 yet.

Sadly it seems that noone is actually looking at this.

@mattmilan-dev
Copy link

As a general usage note should anyone wish to use this particular change before it is pulled in, you can do so by running:
npm uninstall ios-deploy (use the -g if it's globally installed) then:
npm install --save https://github.com/Ukalnins/ios-deploy/tarball/my_master (using -g if you want it globally).

@shazron
Copy link

shazron commented Jul 1, 2019

The WiFi detect feature doesn't seem to work on the corporate network, will have to try at home.

Tasks:

  • Code review
  • Test WiFi detect feature (iOS 12 device)
  • Test WiFi detect feature (iOS 13 beta device)
  • Test deploy app feature works via USB (iOS 12 device)
  • Test deploy app feature works via USB (iOS 13 beta device)
  • Test deploy app feature works via WiFi (iOS 12 device)
  • Test deploy app feature works via WiFi (iOS 13 beta device)

@shazron
Copy link

shazron commented Jul 1, 2019

When I do this, it detects fine (USB):

$ build/Release/ios-deploy --detect
[....] Waiting up to 5 seconds for iOS device to be connected
[....] Found XXXXXX-XXXXXXXXXX (N841AP, iPhone XR, iphoneos, arm64e) a.k.a. 'Shazron’s iPhone XR' connected through USB.

But when I try to deploy an app, it gets stuck:

$ build/Release/ios-deploy -d -b ~/Desktop/HelloCordova.app
[....] Waiting for iOS device to be connected

It is fine if I set a timeout value:

$ build/Release/ios-deploy -d -b ~/Desktop/HelloCordova.app -t 1
[....] Waiting up to 1 seconds for iOS device to be connected
[....] Using XXXXXX-XXXXXXXXXX (N841AP, iPhone XR, iphoneos, arm64e) a.k.a. 'Shazron’s iPhone XR'.
------ Install phase ------
[  0%] Found XXXXXX-XXXXXXXXXX (N841AP, iPhone XR, iphoneos, arm64e) a.k.a. 'Shazron’s iPhone XR' connected through USB, beginning install
# deleted log here

@shazron
Copy link

shazron commented Jul 1, 2019

Did some tests with ios-deploy -d -b path/to/your.app:

  • Works with released version 1.9.4
  • works with master at 0c20374

So based on this evidence, I think it's clear this PR has introduced a bug that needs to be resolved before it can be merged.

@shazron
Copy link

shazron commented Jul 1, 2019

If you omit the -d flag, the code in this PR works.

With versions 1.9.4 and master, omitting the -d flag, or including it, both work -- we need to maintain backwards compatibility, if not we will have to bump a major version for this breakage.

@@ -1726,7 +1698,7 @@ void handle_device(AMDeviceRef device) {
void device_callback(struct am_device_notification_callback_info *info, void *arg) {
switch (info->msg) {
case ADNCI_MSG_CONNECTED:
if(device_id != NULL || !debug || AMDeviceGetInterfaceType(info->dev) != 2) {
if(device_id != NULL || !debug || detect_only) {
Copy link

Choose a reason for hiding this comment

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

This line causes the breakage, if you revert the change it works as before (backwards compatible)

Copy link

@shazron shazron Jul 1, 2019

Choose a reason for hiding this comment

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

If this is reverted of course it will be problematic since WiFi devices won't be detected (the 2 is for WiFi devices). So this if statement needs to be reworked

Copy link

Choose a reason for hiding this comment

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

Found the original PR that added that added that code block which explains the logic: #48

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I misunderstood the if statement. It was crafted to detect wifi devices only if we don't have debug set or device_id is specified.

When you specify the timeout, the best_device_match is used after the timeout and that is why it works.

As the AMDeviceGetInterfaceType(info->dev) != 2 was always true for USB devices, I think we can just remove the if and also the best_device_match handling. It seems that old behaviour was to use USB device and fall back to Wifi if no USB device was found. (Even if no-wifi is specified).

I propose rewriting the device_callback to:

void device_callback(struct am_device_notification_callback_info *info, void *arg) {
    switch (info->msg) {
        case ADNCI_MSG_CONNECTED:
            if (no_wifi && AMDeviceGetInterfaceType(info->dev) == 2)
            {
                NSLogVerbose(@"Skipping wifi device (type: %d)", AMDeviceGetInterfaceType(info->dev));
            }
            else
            {
                NSLogVerbose(@"Handling device type: %d", AMDeviceGetInterfaceType(info->dev));
                handle_device(info->dev);
            }
        default:
            break;
    }
}

Copy link
Author

Choose a reason for hiding this comment

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

I think that the logic is not needed anymore as we use the device over wifi now as needed. It would be nice to favor USB over Wifi, but I'm not sure that we can implement that without having some delay to collect devices and then choose the best.

Copy link
Author

Choose a reason for hiding this comment

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

I may be misunderstanding, but it seems that in your variant the if(_timeout ..) part would cause the last device detected to be chosen and only after the timeout has expired. As now we dont have special handling for Wifi Here, I think that the best_device_match does not have any usable logic left in it currently, but the timeout part breaks actual timeout usage.

Also, why we dont wanto deploy over wifi if debug is present? It's my understanding that this PR fixes the reasoning why it was there.

Copy link

Choose a reason for hiding this comment

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

Regarding the no debug over wifi, I was relying on the information in PR #48, I don't have experience with wifi deploys. My guess is it was put there because we can't link lldb over wifi -- if we can, then we can remove the restriction.

The if(_timeout...) code was to preserve the existing logic with the timeout and how that works (save the last detected device, for use when the timeout expires, so it can handle it). Ok, I also now see a memory leak there in the CFRetain if more than 1 device is connected before the timeout... (should release the previous if it is set)

Personally I would love to refactor this, but I am settling for "not breaking existing functionality" for now.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, running and debugging over wifi now works.

I think you are misunderstanding the old functionallity. The AMDeviceGetInterfaceType(info->dev) != 2 is always true for USB devices, so best_device_match is set only if we are trying to debug with only Wifi device present. (it will search for USB devices, if finds none - falls back to wifi after timeout).

Now, as the wifi debugging works, we dont need to fallback, we can just use the first device we get.

Atleast for the Iphone I have, the USB connection is always detected first, which would be preferrable, but this may not be the case always. For cases when you want to force the USB connection, one can still use the --no-wifi flag.

Copy link

Choose a reason for hiding this comment

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

Alright. Can you make the changes needed as you proposed and I'll retest.

Copy link
Author

Choose a reason for hiding this comment

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

Hi, pushed the changes.

Uldis Kalniņš added 2 commits July 4, 2019 11:49
As previous commit fixes debugging over wifi, it is unnecessery to
only fallback to wifi if no valid usb devices are found.
@shazron shazron added this to the 1.10.0 milestone Jul 17, 2019
@shazron shazron merged commit 20265e8 into ios-control:master Jul 17, 2019
@shazron
Copy link

shazron commented Jul 17, 2019

I am going to leave the testing via pre-release versions I will release via npm, and fix bugs as reports come in. I will update this thread.

@shazron shazron changed the title Fixup API usage to make ios-deploy work also with wifi connections feat: fixup API usage to make ios-deploy work also with wifi connections Jul 18, 2019
@shazron
Copy link

shazron commented Jul 19, 2019

Beta release, please test. Instructions: https://github.com/ios-control/ios-deploy/releases/tag/1.10.0-beta.1

geekonion pushed a commit to geekonion/ios-deploy that referenced this pull request Jun 29, 2023
…os-control#385)

* Fixup API usage to make ios-deploy work also with wifi connections

* remove best match logic
As previous commit fixes debugging over wifi, it is unnecessary to
only fallback to wifi if no valid usb devices are found.

* remove the unnecessary !found_device
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants