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

idevice_id --list is returning iPhones that are not attached via USB #152

Open
jmoody opened this issue Dec 2, 2014 · 21 comments
Open

idevice_id --list is returning iPhones that are not attached via USB #152

jmoody opened this issue Dec 2, 2014 · 21 comments

Comments

@jmoody
Copy link

jmoody commented Dec 2, 2014

I am not sure if this is expected behavior or not.

I have rspec tests that target physical devices. Part of the test setup is to re-install an .ipa on the (test) target devices.

Prior to Xcode 6, I asked instruments for the list of connected devices.

$ xcrun instruments -s devices

Starting with Xcode 6, iOS 8 devices on the local network appear as available for UIAutomation testing. However, ideviceinstaller cannot install an .ipa over the network.

Until the latest version of libimobiledevice, I have been able to find only those devices that are connected via USB using idevice_id --list.

After updating to 1.1.7, I started seeing devices that are not attached via USB appearing in the output of idevice_id --list.

Configuration

  • MacOS 10.10.1
  • Xcode 6.1.1
  • libimobiledevice toolchain version 1.1.7

The offending device is iOS 8.1.1.

Reproduce

  1. Turn on an iOS 8.1.1 device, but don't connect it via USB.
  2. $ idevice_id --list

Expected

The device UDID to not appear in the list of devices reported by idevice_id --list.

Found

The device UDID appears.

Notes

Occasionally, the iOS 8.1.1 device appears 2x in the output:

$ idevice_id -l
43be < snip > 91124
89b5 < snip > 0ab7b
43be < snip > 91124
@jmoody
Copy link
Author

jmoody commented Dec 8, 2014

It would be helpful if I could get a confirmation of the expected behavior. Is idevice_id --list expected to return devices that are not connected via USB?

@nikias
Copy link
Member

nikias commented Dec 8, 2014

No that behavior is actually not expected. idevice_id --list should give you only those devices that have been made available by usbmuxd. Also a device should never appear more than once. I'm using OSX 10.10.1 aswell and do not see this happening. Is iTunes WiFi Sync enabled on the device(s) ?

@jmoody
Copy link
Author

jmoody commented Dec 8, 2014

@nikias

Is iTunes WiFi Sync enabled on the device(s) ?

No.

Thanks for the reply. I am narrowing down the issues. I got a new USB hub and the problem persists.

I am getting into a bad state whenever I connect or disconnect a device.

Console log is spitting out some com.apple.usbmuxd errors that I am trying to analyze.

@jmoody
Copy link
Author

jmoody commented Dec 9, 2014

I rebuilt from sources. Previously, I was using the homebrew package.

I have 3 devices connected to my machine via USB: iOS 6, iOS 7, and iOS 8.

I rebooted my computer and found this output:

$ idevice_id -l
43 < snip > 24 iOS 7
82 < snip> 0c iOS 6
19 < snip > 0d iOS 8

which is correct; those 3 devices are connected to my machine via USB.

Immediately after, I ran the command again and found:

$ idevice_id -l
44 < snip > db  iOS 8; connected to another machine
6c < snip > e2  iOS 8; connected to another machine
43 < snip > 24 iOS 7
82 < snip> 0c iOS 6
19 < snip > 0d iOS 8

There are actually 4 devices connected to the other machine; 2 appear and 2 do not. One of missing devices is iOS 7 and the other is iOS 8.

If I run the command again, I start seeing duplicate entries of devices:

### Reordered for clarity
$ idevice_id -l
44 < snip > db  iOS 8; connected to another machine
44 < snip > db  iOS 8; connected to another machine
43 < snip > 24 iOS 7
43 < snip > 24 iOS 7
6c < snip > e2  iOS 8; connected to another machine
82 < snip> 0c iOS 6
19 < snip > 0d iOS 8

In the system log, I see messages like this:

com.apple.usbmuxd[55]: _SendAttachNotification Device f0: < snip > :d785._apple-mobdev2._tcp.local. has already appeared on interface 4. Suppressing duplicate attach notification.

for several devices; some attached via USB and some not.

@jmoody
Copy link
Author

jmoody commented Dec 9, 2014

I restarted and was able to interact with a problem device for about 15 minutes and then it stopped responding to ideviceinstaller. I unplugged it and ran idevice_id -l and found:

$ idevice_id --list
44 < snip > db iOS 7 device; not connected by USB

Host Machine Logs

com.apple.usbmuxd[55]: HandleUSBMuxDictionary client 0x1003228f0-libusbmuxd/org.libimobiledevice.usbmuxd using library usbmuxd built for freedom, running usbmuxd-344.3
com.apple.usbmuxd[55]: HandleUSBMuxDictionary client 0x100509c10-libusbmuxd/org.libimobiledevice.usbmuxd using library usbmuxd built for freedom, running usbmuxd-344.3
com.apple.usbmuxd[55]: HandleUSBMuxDictionary client 0x10063b490-libusbmuxd/org.libimobiledevice.usbmuxd using library usbmuxd built for freedom, running usbmuxd-344.3
com.apple.usbmuxd[55]: HandleUSBMuxDictionary client 0x100325690-libusbmuxd/org.libimobiledevice.usbmuxd using library usbmuxd built for freedom, running usbmuxd-344.3
com.apple.usbmuxd[55]: HandleUSBMuxDictionary client 0x10063b490-libusbmuxd/org.libimobiledevice.usbmuxd using library usbmuxd built for freedom, running usbmuxd-344.3
com.apple.usbmuxd[55]: HandleUSBMuxDictionary client 0x100523be0-libusbmuxd/org.libimobiledevice.usbmuxd using library usbmuxd built for freedom, running usbmuxd-344.3
com.apple.usbmuxd[55]: HandleUSBMuxDictionary client 0x10052a5b0-libusbmuxd/org.libimobiledevice.usbmuxd using library usbmuxd built for freedom, running usbmuxd-344.3
com.apple.usbmuxd[55]: HandleUSBMuxDictionary client 0x100411bc0-libusbmuxd/org.libimobiledevice.usbmuxd using library usbmuxd built for freedom, running usbmuxd-344.3
com.apple.usbmuxd[55]: HandleUSBMuxDictionary client 0x10063b490-libusbmuxd/org.libimobiledevice.usbmuxd using library usbmuxd built for freedom, running usbmuxd-344.3
com.apple.usbmuxd[55]: SCEDeviceSocketCallback 0x100509c10-libusbmuxd/org.libimobiledevice.usbmuxd remote peer closed connection for sce 0x100509c10.

Device Logs

lockdownd[53] <Notice>: 00295000 -[watchedServiceInfo logService:]: first service <watchedServiceInfo: 0x14609290> [client=ideviceinstaller (DF < snip > 04 fe80::c < snip > 9:37066)] [fd=12] [pid=101 (notification_proxy fd=6)] [hb=47708631116]
lockdownd[53] <Notice>: 00295000 -[watchedServiceInfo logService:]: Watching <watchedServiceInfo: 0x14609290> [client=ideviceinstaller (DF < snip > 04 fe80::c < snip > 9:37066)] [fd=12] [pid=101 (notification_proxy fd=6)] [hb=47708631116]
lockdownd[53] <Notice>: 01a57000 -[hostWatcher runWatcher]: starting loop for <hostWatcher: 0x145198d0> [DF < snip > 04 fe80::c <snip > 9:31434] [fd=17]
wifid[15] <Notice>: WiFi:[439779048.885338]: External power source removed
lockdownd[53] <Notice>: 3aee018c _bump_connection_count: connectionCount now 13 usbHostConnected false pairableHostConnected false unpairedPtpAllowed false
lockdownd[53] <Notice>: 3aee018c _bump_connection_count: connectionCount now 14 usbHostConnected false pairableHostConnected false unpairedPtpAllowed false
ptpd[135] <Notice>: PTP interface has been deactivated.
kernel[0] <Debug>: AppleD2018PMUPowerSource: AppleUSBCableDetect 0
kernel[0] <Debug>: AppleD2018PMUPowerSource: AppleUSBCableType Detached
kernel[0] <Debug>: virtual IOReturn AppleUSBDeviceMux::message(UInt32, IOService *, void *) - kMessageInterfaceWasDeActivated
kernel[0] <Debug>: AppleUSBDeviceMux::reportStats: USB mux statistics: 
kernel[0] <Debug>: USB mux: 6512 reads / 0 errors, 10377 writes / 0 errors
kernel[0] <Debug>: USB mux: 0 short packets, 0 dups
lockdownd[53] <Notice>: 00201000 -[watchedServiceInfo logService:]: Freeing heartbeat <watchedServiceInfo: 0x14609290> [client=ideviceinstaller (DF < snip > 04 fe80::c < snip > 9:37066)] [fd=12] [pid=101 (notification_proxy fd=6)] [hb=47708631116]
lockdownd[53] <Notice>: 00201000 -[watchedServiceInfo logService:]: last service <watchedServiceInfo: 0x14609290> [client=ideviceinstaller (DF < snip > 04 fe80::c < snip > 9:37066)] [fd=12] [pid=101 (notification_proxy fd=6)] [hb=47708631116]
lockdownd[53] <Notice>: 01a57000 -[hostWatcher runWatcher]: ended loop for <hostWatcher: 0x145198d0> [DF < snip > 04 fe80::c <snip > 9:31434] [fd=17]
lockdownd[53] <Notice>: 00201000 -[watchedServiceInfo logService:]: dealloc <watchedServiceInfo: 0x14609290> [client=ideviceinstaller (DF < snip > 04 fe80::c < snip > 9:37066)] [fd=12] [pid=101 (notification_proxy fd=6)] [hb=47708631116]
lockdownd[53] <Notice>: 00295000 -[watchedServiceInfo logService:]: first service <watchedServiceInfo: 0x1451b9c0> [client=ideviceinstaller (DF < snip > 04 fe80::c < snip > 9:38858)] [fd=12] [pid=101 (notification_proxy fd=5)] [hb=48298510881]
lockdownd[53] <Notice>: 00295000 -[watchedServiceInfo logService:]: Watching <watchedServiceInfo: 0x1451b9c0> [client=ideviceinstaller (DF < snip > 04 fe80::c < snip > 9:38858)] [fd=12] [pid=101 (notification_proxy fd=5)] [hb=48298510881]
lockdownd[53] <Notice>: 01a57000 -[hostWatcher runWatcher]: starting loop for <hostWatcher: 0x145198d0> [DF < snip > 04 fe80::c <snip > 9:31434] [fd=17]
lockdownd[53] <Notice>: 00201000 _select_socket: receive secure message timeout!

Are those logs helpful? Is it strange that ideviceinstaller is trying to connect when device is unplugged? The ideviceinstaller process did not abort; it just hangs.

I plugged the device in again and found:

$ idevice_id --list
44 < snip > db
44 < snip > db

Then I powered down the device and found:

$ idevice_id --list
44 < snip > db

### Log
com.apple.usbmuxd[55]: HandleUSBMuxDictionary client 0x100509c10-libusbmuxd/org.libimobiledevice.usbmuxd using library usbmuxd built for freedom, running usbmuxd-344.3

@aburgh
Copy link
Contributor

aburgh commented Dec 9, 2014

Contrary to Nikias's experience, I do see wireless devices listed by idevice_id, and if the device is also plugged into USB it will be listed twice. I have seen this with Mavericks and Yosemite (and probably Mountain Lion, but I don't specifically recall), with devices running iOS 6, 7, and 8. The devices come and go and I have not tried to find a pattern, other than to note that disabling WiFi on the device will definitely eliminate the duplicate device.

I have contemplated exposing the connection type via idevice_t, or at least allowing a connection request to request USB-only, since the WiFi connection is considerably slower and less stable than the USB connection.

@FunkyM
Copy link
Member

FunkyM commented Dec 9, 2014

These are indeed Wifi attached devices. The functionality behind it is "iTunes Wifi Sync".
We'll add some code to skip these on iteration but it requires to implement a few internal usbmux commands. So confirming this bug.

@jmoody
Copy link
Author

jmoody commented Dec 9, 2014

The functionality behind it is "iTunes Wifi Sync".

Will this occur if Wifi Sync is not enabled for the device? I have all the syncing disabled for these devices.

@FunkyM
Copy link
Member

FunkyM commented Dec 9, 2014

Pretty likely as far as I remember. This is because the device discovery doesn't really need Wifi Sync enabled. As long as you did setup Wifi sync before, they might be listed. Try to disable your Wifi and see if the devices still show up. ;)

@FunkyM
Copy link
Member

FunkyM commented Dec 9, 2014

Probably related to libimobiledevice/libusbmuxd#22.

@jmoody
Copy link
Author

jmoody commented Jan 28, 2015

Try to disable your Wifi and see if the devices still show up. ;)

The device appears only once after turning off the WiFi.

This is causing problems with ideviceinstaller. If the device is list 2x, ideviceinstaller cannot install.

@jmoody
Copy link
Author

jmoody commented Jan 28, 2015

Try to disable your Wifi and see if the devices still show up. ;)

The device appears only once after turning off the WiFi.

Spoke too soon. The device appears even if it is not connected via WiFi

@FunkyM
Copy link
Member

FunkyM commented Jan 28, 2015

WiFi communication is unstable and Apple's usbmuxd might have cached an older WiFi connected device to overcome connection drops. This is probably the reason why you still see some devices despite turning off WiFi.

As you can imagine, it doesn't make sense that your device would still be working when neither attached by USB or WiFi.

Anyways, this is an unhandled feature to be fixed in libusbmuxd which needs to learn to skip devices with the "Network" connection type property.

Thus confirming this is a duplicate of libimobiledevice/libusbmuxd#22 (see related ticket for a temporary workaround, too).

We'll probably fix it properly soon in libusbmuxd without implementing WiFi support yet.

@FunkyM FunkyM added this to the 1.4.0 Release milestone Jan 28, 2015
@cbowns
Copy link

cbowns commented Aug 26, 2015

I personally love libimobiledevice's ability to connect to devices wirelessly: I use it to debug device sleep/wake cycles, and to monitor a device's behaviour when not attached to power.

@letsautom8
Copy link

not all wants connection through usb. maybe a filter parameter would be a better solution?

@chachi
Copy link

chachi commented Dec 1, 2016

Has there been any progress on this front? It can make CI jobs unreliable if other devices connect and disconnect wirelessly and automatically.

@dnsBlah
Copy link

dnsBlah commented Oct 10, 2017

Please make a argument to allow/disallow to view wireless devices

@felyppers
Copy link

Hey guys, I had this same issue this week and solved by disabling the wifi service in the MAC.

In your MAC, use the command below to list your network services
networksetup -listallnetworkservices

Write down the service name similar to iPhone USB and run:
networksetup -setnetworkserviceenabled SERVICE_NAME off

After that, restart your mobile and it should work, but I agree that should be a flag to ignore Wi-Fi connections, similar to "ios-deploy --no-wifi" flag.

@harlentan
Copy link

Hey guys, I had this same issue this week and solved by disabling the wifi service in the MAC.

In your MAC, use the command below to list your network services
networksetup -listallnetworkservices

Write down the service name similar to iPhone USB and run:
networksetup -setnetworkserviceenabled SERVICE_NAME off

After that, restart your mobile and it should work, but I agree that should be a flag to ignore Wi-Fi connections, similar to "ios-deploy --no-wifi" flag.

I can also see duplicate device udid with idevice_id by following your steps.

  1. Disable the iTunes wifi sync
  2. Disable the iTunes auto sync
  3. Disable wifi of my Mac
  4. restart the iPhone and Mac.

After all of that, But failed. I can still see duplicate device udid with idevice_id

@rikan
Copy link

rikan commented Aug 20, 2019

Hi guys, I have the same issue. I found that if the mac and iphone were in the same AP(access point) network, the issue happened. So I connected iphone to the another AP, the issue was solved. Hope it is helpful.

@rbucker
Copy link

rbucker commented Sep 26, 2019

In my case my iPhone was connect via USB and WiFi. When I disabled the Wifi and waited a few minutes the second entry was removed. The thing is.... what does it mean to have 2 and does that effect anything downstream? Would be nice if someone in the triage team would make a decision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests