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
diff --git a/mtp/MtpServer.cpp b/mtp/MtpServer.cpp
index 2c6d376..9cd6732 100755
--- a/mtp/MtpServer.cpp
+++ b/mtp/MtpServer.cpp
@@ -96,10 +96,9 @@
 	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 @@
 		mSendObjectFormat(0),
 		mSendObjectFileSize(0)
 {
+	mFD = -1;
 }
 
 MtpServer::~MtpServer() {
@@ -183,9 +183,11 @@
 	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 @@
 	mObjectEditList.clear();
 
 	if (mSessionOpen)
-		mDatabase->sessionEnded();
+		mDatabase->sessionEnded(); // This doesn't actually do anything but was carry over from AOSP
 	close(fd);
 	mFD = -1;
 }