From 1b03920ca7d576c8400dd006ac1bbdecc1664231 Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Fri, 30 Jan 2015 10:08:48 -0600 Subject: MTP: make MTP work even if unplugged and replugged Set up a loop to keep trying to open / read the MTP device so that MTP will work even if the device is unplugged during boot or unplugged and replugged in. Change-Id: I0d3a3b7c91ce84a8cbed16caa4b15efee35b3641 --- mtp/MtpServer.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'mtp/MtpServer.cpp') diff --git a/mtp/MtpServer.cpp b/mtp/MtpServer.cpp index 2c6d37648..9cd67324f 100755 --- a/mtp/MtpServer.cpp +++ b/mtp/MtpServer.cpp @@ -96,10 +96,9 @@ static const MtpEventCode kSupportedEventCodes[] = { MTP_EVENT_OBJECT_PROP_CHANGED, }; -MtpServer::MtpServer(int fd, MtpDatabase* database, bool ptp, +MtpServer::MtpServer(MtpDatabase* database, bool ptp, int fileGroup, int filePerm, int directoryPerm) - : mFD(fd), - mDatabase(database), + : mDatabase(database), mPtp(ptp), mFileGroup(fileGroup), mFilePermission(filePerm), @@ -110,6 +109,7 @@ MtpServer::MtpServer(int fd, MtpDatabase* database, bool ptp, mSendObjectFormat(0), mSendObjectFileSize(0) { + mFD = -1; } MtpServer::~MtpServer() { @@ -183,9 +183,11 @@ bool MtpServer::hasStorage(MtpStorageID id) { return (getStorage(id) != NULL); } -void MtpServer::run() { - int fd = mFD; +void MtpServer::run(int fd) { + if (fd < 0) + return; + mFD = fd; MTPI("MtpServer::run fd: %d\n", fd); while (1) { @@ -275,7 +277,7 @@ void MtpServer::run() { mObjectEditList.clear(); if (mSessionOpen) - mDatabase->sessionEnded(); + mDatabase->sessionEnded(); // This doesn't actually do anything but was carry over from AOSP close(fd); mFD = -1; } -- cgit v1.2.3