MtpServer: create new ffs handle if current one fails

- fixes MTP not working after USB unplugged and plugged

Change-Id: Iea684107d7de20ff92828543881f6fbec1848b77
This commit is contained in:
nijel8
2022-01-14 11:59:21 -05:00
committed by bigbiff
parent fbf1fdd07f
commit bb7f0ba2a7
+10 -1
View File
@@ -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;
}