From bb7f0ba2a7d478858788a6331b921181d504569d Mon Sep 17 00:00:00 2001 From: nijel8 Date: Fri, 14 Jan 2022 11:59:21 -0500 Subject: [PATCH] MtpServer: create new ffs handle if current one fails - fixes MTP not working after USB unplugged and plugged Change-Id: Iea684107d7de20ff92828543881f6fbec1848b77 --- mtp/ffs/MtpServer.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mtp/ffs/MtpServer.cpp b/mtp/ffs/MtpServer.cpp index fa670243..454da251 100755 --- a/mtp/ffs/MtpServer.cpp +++ b/mtp/ffs/MtpServer.cpp @@ -164,8 +164,17 @@ bool MtpServer::hasStorage(MtpStorageID id) { 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; }