macOS Preview appears to hold MTP devices open indefinitely

I am developing a USB MTP device for use with macOS.

When the device is connected while Preview is running, I observe the host send OpenSession, then GetDeviceInfo, and then no further MTP commands. I do not see a later CloseSession.

Problem is that once this happens, exclusive access to the USB interface is retained, so another application cannot connect to the device. From the device side, there is no obvious way to recover except forcing a USB disconnect/reset or shutting down the USB interface.

My questions are:

  • Is this expected behavior for Preview, or for a Preview-related macOS helper?
  • Is it expected on macOS that a client may open an MTP session and then leave it idle without sending CloseSession?

I am mainly trying to understand whether this is expected macOS behavior, or whether this should be considered a bug.

When the device is connected while Preview is running, I observe the host send OpenSession, then GetDeviceInfo, and then no further MTP commands. I do not see a later CloseSession.

I don't know enough about your accessory to be certain about exactly what's going on, but I think what's actually happening here is that Preview is indirectly causing the session to open through its interactions with ImageCaptureCore. However, that also means that Preview doesn't really own/control the device itself; the major role of the ImageCapture framework is to allow multiple apps to interact with the same accessory.

The problem is that once this happens, exclusive access to the USB interface is retained, so another application cannot connect to the device.

What API are you actually trying to use here?

From the device side, there is no obvious way to recover except forcing a USB disconnect/reset or shutting down the USB interface.

Well... yes. There's no way for your accessory to know about the state of the connecting system, so this isn't an issue your hardware should try and address.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

hi kevin
we use libmtp->libusb->IOKit to access our devices.

it looks like the short term solution would be to ask ImageCapture framework to release the device so we can access it. i'll try that first.

long term it would be nice to go through ImageCapture framework if that is possible with all the operations we need to perform:

  • List directory
  • Download file
  • Read partial content
  • Upload file
  • Create folder
  • Delete file/folder
  • Rename file/folder
  • Move object
  • Copy object
  • Get battery level
  • Get disk space
  • Get device version
  • Get/set datetime

we perform full backup & restore of the device file tree including setting correct file time stamps and it looks like ImageCapture framework might not do all that.
i need to read up and do some testing.

macOS Preview appears to hold MTP devices open indefinitely
 
 
Q