Skip to content
This repository was archived by the owner on Nov 23, 2022. It is now read-only.

Commit

Permalink
Transfer /dev/mtp_usb fd ownership when instancing MtpDevHandle
Browse files Browse the repository at this point in the history
/dev/mtp_usb was opened before instancing MtpDevHandle, the existing fd
should be passed in otherwise MtpDevHandle::start would be blocked as it
attempted to open the device twice.

Change-Id: I6afc5b6926930dad77aceac2f6a00e1c6759a883
  • Loading branch information
moetayuko committed Mar 28, 2019
1 parent 0ef6492 commit 95244dd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions mtp/ffs/MtpDevHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@

constexpr char mtp_dev_path[] = "/dev/mtp_usb";

MtpDevHandle::MtpDevHandle()
: mFd(-1) {};
MtpDevHandle::MtpDevHandle(int controlFd) {
mFd.reset(controlFd);
}

MtpDevHandle::~MtpDevHandle() {}

Expand Down
2 changes: 1 addition & 1 deletion mtp/ffs/MtpDevHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MtpDevHandle : public IMtpHandle {
android::base::unique_fd mFd;

public:
MtpDevHandle();
MtpDevHandle(int controlFd);
~MtpDevHandle();
int read(void *data, size_t len);
int write(const void *data, size_t len);
Expand Down
2 changes: 1 addition & 1 deletion mtp/ffs/MtpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ MtpServer::MtpServer(IMtpDatabase* database, int controlFd, bool ptp,
mHandle = aio_compat ? new MtpFfsCompatHandle(controlFd) : new MtpFfsHandle(controlFd);
mHandle->writeDescriptors(mPtp);
} else {
mHandle = new MtpDevHandle();
mHandle = new MtpDevHandle(controlFd);
}
}

Expand Down

0 comments on commit 95244dd

Please sign in to comment.