Switch MtpFfsHandle to aio, add control functions.
MtpFfsHandle now uses kaio to handle usb data.
This achieves better performance without using
the endpoint alloc ioctl.
This also allows ep0 events to be handled without
race conditions. Events will also include control
requests, which will allow both host and device
initiated cancellation.
Bug: 37916658
Bug: 36802721
Test: Transfer various size files, run MtpFfsHandleTest
Test: Cancel transfer on Windows
Test: Allow device to cancel transfer on Windows
Change-Id: Ib3ce996f00782ce7f68f29b2510dbc17f09fdf14
diff --git a/media/mtp/MtpDevHandle.cpp b/media/mtp/MtpDevHandle.cpp
index 9aa0aec..6aa57ac 100644
--- a/media/mtp/MtpDevHandle.cpp
+++ b/media/mtp/MtpDevHandle.cpp
@@ -14,57 +14,37 @@
* limitations under the License.
*/
-#include <utils/Log.h>
-#include <fcntl.h>
-#include <sys/stat.h>
+#include <android-base/logging.h>
#include <cutils/properties.h>
#include <dirent.h>
#include <errno.h>
+#include <fcntl.h>
#include <linux/usb/ch9.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/endian.h>
#include <unistd.h>
-#include <android-base/logging.h>
-#include <android-base/unique_fd.h>
-#include "IMtpHandle.h"
+#include "MtpDevHandle.h"
+
+namespace android {
constexpr char mtp_dev_path[] = "/dev/mtp_usb";
-class MtpDevHandle : public IMtpHandle {
-private:
- android::base::unique_fd mFd;
-
-public:
- MtpDevHandle();
- ~MtpDevHandle();
- int read(void *data, int len);
- int write(const void *data, int len);
-
- int receiveFile(mtp_file_range mfr, bool);
- int sendFile(mtp_file_range mfr);
- int sendEvent(mtp_event me);
-
- int start();
- void close();
-
- int configure(bool ptp);
-};
-
MtpDevHandle::MtpDevHandle()
: mFd(-1) {};
MtpDevHandle::~MtpDevHandle() {}
-int MtpDevHandle::read(void *data, int len) {
+int MtpDevHandle::read(void *data, size_t len) {
return ::read(mFd, data, len);
}
-int MtpDevHandle::write(const void *data, int len) {
+int MtpDevHandle::write(const void *data, size_t len) {
return ::write(mFd, data, len);
}
@@ -81,7 +61,7 @@
}
int MtpDevHandle::start() {
- mFd = android::base::unique_fd(TEMP_FAILURE_RETRY(open(mtp_dev_path, O_RDWR)));
+ mFd.reset(TEMP_FAILURE_RETRY(open(mtp_dev_path, O_RDWR)));
if (mFd == -1) return -1;
return 0;
}
@@ -95,6 +75,4 @@
return 0;
}
-IMtpHandle *get_mtp_handle() {
- return new MtpDevHandle();
-}
+} // namespace android