Add support for MTP devices on OS X

This commit is contained in:
Kovid Goyal 2014-07-19 09:14:00 +05:30
parent 38a777e2fc
commit 2aed6ba715
3 changed files with 26 additions and 6 deletions

View File

@ -374,9 +374,9 @@ single android device out there, so if your device is not automatically
detected, follow the instructions at :ref:`devsupport` to get your device
supported in |app|.
.. note:: With newer Android devices, the USB connection is only supported on
Windows Vista and newer and Linux. If you are on Windows XP or OS X,
you should use one of the wireless connection methods.
.. note:: With newer Android devices, the USB connection is not supported on
Windows XP. If you are on Windows XP, you should use one of the
wireless connection methods.
Over the air
^^^^^^^^^^^^^^

View File

@ -13,7 +13,7 @@ from collections import namedtuple
from functools import partial
from calibre import prints, as_unicode
from calibre.constants import plugins, islinux
from calibre.constants import plugins, islinux, isosx
from calibre.ptempfile import SpooledTemporaryFile
from calibre.devices.errors import OpenFailed, DeviceError, BlacklistedDevice
from calibre.devices.mtp.base import MTPDeviceBase, synchronous, debug
@ -31,7 +31,7 @@ APPLE = 0x05ac
class MTP_DEVICE(MTPDeviceBase):
# libusb(x) does not work on OS X. So no MTP support for OS X
supported_platforms = ['linux']
supported_platforms = ['linux', 'osx']
def __init__(self, *args, **kwargs):
MTPDeviceBase.__init__(self, *args, **kwargs)
@ -49,6 +49,11 @@ class MTP_DEVICE(MTPDeviceBase):
if islinux:
from calibre.devices.mtp.unix.sysfs import MTPDetect
self._is_device_mtp = MTPDetect()
if isosx and 'osx' in self.supported_platforms:
self.usbobserver, err = plugins['usbobserver']
if err:
raise RuntimeError(err)
self._is_device_mtp = self.osx_is_device_mtp
def is_device_mtp(self, d, debug=None):
''' Returns True iff the _is_device_mtp check returns True and libmtp
@ -58,6 +63,21 @@ class MTP_DEVICE(MTPDeviceBase):
return (self._is_device_mtp(d, debug=debug) and
self.libmtp.is_mtp_device(d.busnum, d.devnum))
def osx_is_device_mtp(self, d, debug=None):
if not d.serial:
ans = False
else:
try:
ans = self.usbobserver.is_mtp_device(d.vendor_id, d.product_id, d.bcd, d.serial)
except Exception:
if debug is not None:
import traceback
traceback.print_stack()
return False
if debug is not None and ans:
debug('Device {0} claims to be an MTP device in the IOKit registry'.format(d))
return bool(ans)
def set_debug_level(self, lvl):
self.libmtp.set_debug_level(lvl)

View File

@ -291,7 +291,7 @@ if islinux:
linux_scanner = LinuxScanner()
libusb_scanner = LibUSBScanner()
if isosx:
if False and isosx:
# Apparently libusb causes mem leaks on some Macs and hangs on others and
# works on a few. OS X users will just have to live without MTP support.
# See https://bugs.launchpad.net/calibre/+bug/1044706