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
This commit is contained in:
Ethan Yonker
2015-01-30 10:08:48 -06:00
committed by Dees Troy
parent 1a7ba9751f
commit 1b03920ca7
6 changed files with 61 additions and 66 deletions
+8 -6
View File
@@ -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;
}