Skip to content

Commit

Permalink
MtpServer: create new ffs handle if current one fails
Browse files Browse the repository at this point in the history
- fixes MTP not working after USB unplugged and plugged

Change-Id: Iea684107d7de20ff92828543881f6fbec1848b77
  • Loading branch information
nijel8 authored and corsicanu committed May 30, 2022
1 parent e0bbb7f commit 6f4b6ec
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion mtp/ffs/MtpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 6f4b6ec

Please sign in to comment.