MtpServer: create new ffs handle if current one fails
- fixes MTP not working after USB unplugged and plugged
Change-Id: Iea684107d7de20ff92828543881f6fbec1848b77
diff --git a/mtp/ffs/MtpServer.cpp b/mtp/ffs/MtpServer.cpp
index fa67024..454da25 100755
--- a/mtp/ffs/MtpServer.cpp
+++ b/mtp/ffs/MtpServer.cpp
@@ -164,8 +164,17 @@
void MtpServer::run() {
if (mHandle->start(mPtp)) {
- MTPE("Failed to start usb driver!");
+ MTPE("Failed to start usb driver!\n");
mHandle->close();
+ int controlFd = open(FFS_MTP_EP0, O_RDWR);
+ bool ffs_ok = access(FFS_MTP_EP0, W_OK) == 0;
+ if (ffs_ok) {
+ bool aio_compat = android::base::GetBoolProperty("sys.usb.ffs.aio_compat", false);
+ mHandle = aio_compat ? new MtpFfsCompatHandle(controlFd) : new MtpFfsHandle(controlFd);
+ mHandle->writeDescriptors(mPtp);
+ } else {
+ mHandle = new MtpDevHandle(controlFd);
+ }
return;
}