Loading media/mtp/f_mtp.h +7 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,11 @@ #ifndef __LINUX_USB_F_MTP_H #define __LINUX_USB_F_MTP_H /* Constants for MTP_SET_INTERFACE_MODE */ #define MTP_INTERFACE_MODE_MTP 0 #define MTP_INTERFACE_MODE_PTP 1 struct mtp_file_range { /* path for file to transfer */ const char *path; Loading @@ -35,5 +40,7 @@ struct mtp_file_range { * The file is created if it does not exist. */ #define MTP_RECEIVE_FILE _IOW('M', 1, struct mtp_file_range) /* Sets the driver mode to either MTP or PTP */ #define MTP_SET_INTERFACE_MODE _IOW('M', 2, int) #endif /* __LINUX_USB_F_MTP_H */ media/mtp/mtptest.cpp +22 −4 Original line number Diff line number Diff line Loading @@ -21,9 +21,11 @@ #include <stdlib.h> #include <sys/types.h> #include <fcntl.h> #include <sys/ioctl.h> #include "MtpServer.h" #include "MtpStorage.h" #include "f_mtp.h" using namespace android; Loading @@ -40,10 +42,13 @@ static void enable_usb_function(const char* name, bool enable) { close(fd); } int main() { // first disable UMS and enable MTP USB functions enable_usb_function("usb_mass_storage", false); enable_usb_function("mtp", true); int main(int argc, char* argv[]) { bool usePTP = false; for (int i = 1; i < argc; i++) { if (!strcmp(argv[i], "-p")) usePTP = true; } int fd = open("/dev/mtp_usb", O_RDWR); printf("open returned %d\n", fd); Loading @@ -52,6 +57,19 @@ int main() { return -1; } if (usePTP) { // set driver mode to PTP int ret = ioctl(fd, MTP_SET_INTERFACE_MODE, MTP_INTERFACE_MODE_PTP); if (ret) { fprintf(stderr, "MTP_SET_INTERFACE_MODE failed\n"); return -1; } } // disable UMS and enable MTP USB functions enable_usb_function("usb_mass_storage", false); enable_usb_function("mtp", true); MtpServer server(fd, "/data/data/mtp/mtp.db"); server.addStorage("/sdcard"); server.scanStorage(); Loading Loading
media/mtp/f_mtp.h +7 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,11 @@ #ifndef __LINUX_USB_F_MTP_H #define __LINUX_USB_F_MTP_H /* Constants for MTP_SET_INTERFACE_MODE */ #define MTP_INTERFACE_MODE_MTP 0 #define MTP_INTERFACE_MODE_PTP 1 struct mtp_file_range { /* path for file to transfer */ const char *path; Loading @@ -35,5 +40,7 @@ struct mtp_file_range { * The file is created if it does not exist. */ #define MTP_RECEIVE_FILE _IOW('M', 1, struct mtp_file_range) /* Sets the driver mode to either MTP or PTP */ #define MTP_SET_INTERFACE_MODE _IOW('M', 2, int) #endif /* __LINUX_USB_F_MTP_H */
media/mtp/mtptest.cpp +22 −4 Original line number Diff line number Diff line Loading @@ -21,9 +21,11 @@ #include <stdlib.h> #include <sys/types.h> #include <fcntl.h> #include <sys/ioctl.h> #include "MtpServer.h" #include "MtpStorage.h" #include "f_mtp.h" using namespace android; Loading @@ -40,10 +42,13 @@ static void enable_usb_function(const char* name, bool enable) { close(fd); } int main() { // first disable UMS and enable MTP USB functions enable_usb_function("usb_mass_storage", false); enable_usb_function("mtp", true); int main(int argc, char* argv[]) { bool usePTP = false; for (int i = 1; i < argc; i++) { if (!strcmp(argv[i], "-p")) usePTP = true; } int fd = open("/dev/mtp_usb", O_RDWR); printf("open returned %d\n", fd); Loading @@ -52,6 +57,19 @@ int main() { return -1; } if (usePTP) { // set driver mode to PTP int ret = ioctl(fd, MTP_SET_INTERFACE_MODE, MTP_INTERFACE_MODE_PTP); if (ret) { fprintf(stderr, "MTP_SET_INTERFACE_MODE failed\n"); return -1; } } // disable UMS and enable MTP USB functions enable_usb_function("usb_mass_storage", false); enable_usb_function("mtp", true); MtpServer server(fd, "/data/data/mtp/mtp.db"); server.addStorage("/sdcard"); server.scanStorage(); Loading