Add -p option to mtptest program to run in PTP mode instead of MTP

Change-Id: Idbd1437756daab8d6141db49b07d4eb0814c9e7e
Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/media/mtp/mtptest.cpp b/media/mtp/mtptest.cpp
index 89aa622..0d9d45a 100644
--- a/media/mtp/mtptest.cpp
+++ b/media/mtp/mtptest.cpp
@@ -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;
 
@@ -40,10 +42,13 @@
     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);
@@ -52,6 +57,19 @@
         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();