Loading media/mtp/IMtpHandle.h +1 −2 Original line number Diff line number Diff line Loading @@ -32,8 +32,7 @@ public: virtual int sendEvent(mtp_event me) = 0; // Return 0 if operation is successful, or -1 else virtual int start() = 0; virtual int configure(bool ptp) = 0; virtual int start(bool ptp) = 0; virtual void close() = 0; Loading media/mtp/MtpDescriptors.cpp +23 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,9 @@ * limitations under the License. */ #include <android-base/logging.h> #include <sys/types.h> #include "MtpDescriptors.h" namespace android { Loading Loading @@ -257,4 +260,24 @@ const struct desc_v1 ptp_desc_v1 = { .hs_descs = ptp_hs_descriptors, }; bool writeDescriptors(int fd, bool ptp) { ssize_t ret = TEMP_FAILURE_RETRY(write(fd, &(ptp ? ptp_desc_v2 : mtp_desc_v2), sizeof(desc_v2))); if (ret < 0) { PLOG(ERROR) << fd << "Switching to V1 descriptor format"; ret = TEMP_FAILURE_RETRY(write(fd, &(ptp ? ptp_desc_v1 : mtp_desc_v1), sizeof(desc_v1))); if (ret < 0) { PLOG(ERROR) << fd << "Writing descriptors failed"; return false; } } ret = TEMP_FAILURE_RETRY(write(fd, &mtp_strings, sizeof(mtp_strings))); if (ret < 0) { PLOG(ERROR) << fd << "Writing strings failed"; return false; } return true; } }; // namespace android media/mtp/MtpDescriptors.h +12 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,16 @@ namespace android { constexpr char FFS_MTP_EP0[] = "/dev/usb-ffs/mtp/ep0"; constexpr char FFS_MTP_EP_IN[] = "/dev/usb-ffs/mtp/ep1"; constexpr char FFS_MTP_EP_OUT[] = "/dev/usb-ffs/mtp/ep2"; constexpr char FFS_MTP_EP_INTR[] = "/dev/usb-ffs/mtp/ep3"; constexpr char FFS_PTP_EP0[] = "/dev/usb-ffs/ptp/ep0"; constexpr char FFS_PTP_EP_IN[] = "/dev/usb-ffs/ptp/ep1"; constexpr char FFS_PTP_EP_OUT[] = "/dev/usb-ffs/ptp/ep2"; constexpr char FFS_PTP_EP_INTR[] = "/dev/usb-ffs/ptp/ep3"; constexpr int MAX_PACKET_SIZE_FS = 64; constexpr int MAX_PACKET_SIZE_HS = 512; constexpr int MAX_PACKET_SIZE_SS = 1024; Loading Loading @@ -91,6 +101,8 @@ extern const struct desc_v1 mtp_desc_v1; extern const struct desc_v1 ptp_desc_v1; extern const struct functionfs_strings mtp_strings; bool writeDescriptors(int fd, bool ptp); }; // namespace android #endif // MTP_DESCRIPTORS_H media/mtp/MtpDevHandle.cpp +1 −6 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ int MtpDevHandle::sendEvent(mtp_event me) { return ioctl(mFd, MTP_SEND_EVENT, reinterpret_cast<unsigned long>(&me)); } int MtpDevHandle::start() { int MtpDevHandle::start(bool /* ptp */) { mFd.reset(TEMP_FAILURE_RETRY(open(mtp_dev_path, O_RDWR))); if (mFd == -1) return -1; return 0; Loading @@ -70,9 +70,4 @@ void MtpDevHandle::close() { mFd.reset(); } int MtpDevHandle::configure(bool) { // Nothing to do, driver can configure itself return 0; } } // namespace android media/mtp/MtpDevHandle.h +1 −3 Original line number Diff line number Diff line Loading @@ -36,10 +36,8 @@ public: int sendFile(mtp_file_range mfr); int sendEvent(mtp_event me); int start(); int start(bool ptp); void close(); int configure(bool ptp); }; } // namespace android Loading Loading
media/mtp/IMtpHandle.h +1 −2 Original line number Diff line number Diff line Loading @@ -32,8 +32,7 @@ public: virtual int sendEvent(mtp_event me) = 0; // Return 0 if operation is successful, or -1 else virtual int start() = 0; virtual int configure(bool ptp) = 0; virtual int start(bool ptp) = 0; virtual void close() = 0; Loading
media/mtp/MtpDescriptors.cpp +23 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,9 @@ * limitations under the License. */ #include <android-base/logging.h> #include <sys/types.h> #include "MtpDescriptors.h" namespace android { Loading Loading @@ -257,4 +260,24 @@ const struct desc_v1 ptp_desc_v1 = { .hs_descs = ptp_hs_descriptors, }; bool writeDescriptors(int fd, bool ptp) { ssize_t ret = TEMP_FAILURE_RETRY(write(fd, &(ptp ? ptp_desc_v2 : mtp_desc_v2), sizeof(desc_v2))); if (ret < 0) { PLOG(ERROR) << fd << "Switching to V1 descriptor format"; ret = TEMP_FAILURE_RETRY(write(fd, &(ptp ? ptp_desc_v1 : mtp_desc_v1), sizeof(desc_v1))); if (ret < 0) { PLOG(ERROR) << fd << "Writing descriptors failed"; return false; } } ret = TEMP_FAILURE_RETRY(write(fd, &mtp_strings, sizeof(mtp_strings))); if (ret < 0) { PLOG(ERROR) << fd << "Writing strings failed"; return false; } return true; } }; // namespace android
media/mtp/MtpDescriptors.h +12 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,16 @@ namespace android { constexpr char FFS_MTP_EP0[] = "/dev/usb-ffs/mtp/ep0"; constexpr char FFS_MTP_EP_IN[] = "/dev/usb-ffs/mtp/ep1"; constexpr char FFS_MTP_EP_OUT[] = "/dev/usb-ffs/mtp/ep2"; constexpr char FFS_MTP_EP_INTR[] = "/dev/usb-ffs/mtp/ep3"; constexpr char FFS_PTP_EP0[] = "/dev/usb-ffs/ptp/ep0"; constexpr char FFS_PTP_EP_IN[] = "/dev/usb-ffs/ptp/ep1"; constexpr char FFS_PTP_EP_OUT[] = "/dev/usb-ffs/ptp/ep2"; constexpr char FFS_PTP_EP_INTR[] = "/dev/usb-ffs/ptp/ep3"; constexpr int MAX_PACKET_SIZE_FS = 64; constexpr int MAX_PACKET_SIZE_HS = 512; constexpr int MAX_PACKET_SIZE_SS = 1024; Loading Loading @@ -91,6 +101,8 @@ extern const struct desc_v1 mtp_desc_v1; extern const struct desc_v1 ptp_desc_v1; extern const struct functionfs_strings mtp_strings; bool writeDescriptors(int fd, bool ptp); }; // namespace android #endif // MTP_DESCRIPTORS_H
media/mtp/MtpDevHandle.cpp +1 −6 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ int MtpDevHandle::sendEvent(mtp_event me) { return ioctl(mFd, MTP_SEND_EVENT, reinterpret_cast<unsigned long>(&me)); } int MtpDevHandle::start() { int MtpDevHandle::start(bool /* ptp */) { mFd.reset(TEMP_FAILURE_RETRY(open(mtp_dev_path, O_RDWR))); if (mFd == -1) return -1; return 0; Loading @@ -70,9 +70,4 @@ void MtpDevHandle::close() { mFd.reset(); } int MtpDevHandle::configure(bool) { // Nothing to do, driver can configure itself return 0; } } // namespace android
media/mtp/MtpDevHandle.h +1 −3 Original line number Diff line number Diff line Loading @@ -36,10 +36,8 @@ public: int sendFile(mtp_file_range mfr); int sendEvent(mtp_event me); int start(); int start(bool ptp); void close(); int configure(bool ptp); }; } // namespace android Loading