summaryrefslogtreecommitdiffstats
path: root/mtp
diff options
context:
space:
mode:
authorEthan Yonker <dees_troy@teamw.in>2015-01-30 17:08:48 +0100
committerDees Troy <dees_troy@teamw.in>2015-02-02 15:45:51 +0100
commit1b03920ca7d576c8400dd006ac1bbdecc1664231 (patch)
treef00558bafaa42a3bcd212ac1ac98b4b4c51f600b /mtp
parentgui: simplify code in GUIKeyboard (diff)
downloadandroid_bootable_recovery-1b03920ca7d576c8400dd006ac1bbdecc1664231.tar
android_bootable_recovery-1b03920ca7d576c8400dd006ac1bbdecc1664231.tar.gz
android_bootable_recovery-1b03920ca7d576c8400dd006ac1bbdecc1664231.tar.bz2
android_bootable_recovery-1b03920ca7d576c8400dd006ac1bbdecc1664231.tar.lz
android_bootable_recovery-1b03920ca7d576c8400dd006ac1bbdecc1664231.tar.xz
android_bootable_recovery-1b03920ca7d576c8400dd006ac1bbdecc1664231.tar.zst
android_bootable_recovery-1b03920ca7d576c8400dd006ac1bbdecc1664231.zip
Diffstat (limited to 'mtp')
-rwxr-xr-xmtp/MtpServer.cpp14
-rwxr-xr-xmtp/MtpServer.h4
-rwxr-xr-xmtp/mtp_MtpServer.cpp56
-rwxr-xr-xmtp/mtp_MtpServer.hpp2
4 files changed, 34 insertions, 42 deletions
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;
}
diff --git a/mtp/MtpServer.h b/mtp/MtpServer.h
index 61f5ccfac..944331134 100755
--- a/mtp/MtpServer.h
+++ b/mtp/MtpServer.h
@@ -92,7 +92,7 @@ private:
android::Vector<ObjectEdit*> mObjectEditList;
public:
- MtpServer(int fd, MtpDatabase* database, bool ptp,
+ MtpServer(MtpDatabase* database, bool ptp,
int fileGroup, int filePerm, int directoryPerm);
virtual ~MtpServer();
@@ -102,7 +102,7 @@ public:
void addStorage(MtpStorage* storage);
void removeStorage(MtpStorage* storage);
- void run();
+ void run(int fd);
void sendObjectAdded(MtpObjectHandle handle);
void sendObjectRemoved(MtpObjectHandle handle);
diff --git a/mtp/mtp_MtpServer.cpp b/mtp/mtp_MtpServer.cpp
index b53d07a8f..8d6038c77 100755
--- a/mtp/mtp_MtpServer.cpp
+++ b/mtp/mtp_MtpServer.cpp
@@ -37,23 +37,6 @@
void twmtp_MtpServer::start()
{
- if (setup() == 0) {
- add_storage();
- MTPD("Starting add / remove mtppipe monitor thread\n");
- pthread_t thread;
- ThreadPtr mtpptr = &twmtp_MtpServer::mtppipe_thread;
- PThreadPtr p = *(PThreadPtr*)&mtpptr;
- pthread_create(&thread, NULL, p, this);
- server->run();
- }
-}
-
-void twmtp_MtpServer::set_storages(storages* mtpstorages) {
- stores = mtpstorages;
-}
-
-int twmtp_MtpServer::setup()
-{
usePtp = false;
MyMtpDatabase* mtpdb = new MyMtpDatabase();
/* Sleep for a bit before we open the MTP USB device because some
@@ -64,27 +47,36 @@ int twmtp_MtpServer::setup()
#ifdef USB_MTP_DEVICE
#define STRINGIFY(x) #x
#define EXPAND(x) STRINGIFY(x)
+ const char* mtp_device = EXPAND(USB_MTP_DEVICE);
MTPI("Using '%s' for MTP device.\n", EXPAND(USB_MTP_DEVICE));
- int fd = open(EXPAND(USB_MTP_DEVICE), O_RDWR);
#else
- int fd = open("/dev/mtp_usb", O_RDWR);
+ const char* mtp_device = "/dev/mtp_usb";
#endif
- if (fd >= 0) {
- MTPD("fd: %d\n", fd);
- server = new MtpServer(fd, mtpdb, usePtp, 0, 0664, 0775);
- refserver = server;
- MTPI("created new mtpserver object\n");
- } else {
+ int fd = open(mtp_device, O_RDWR);
+ if (fd < 0) {
MTPE("could not open MTP driver, errno: %d\n", errno);
- return -1;
+ return;
+ }
+ MTPD("fd: %d\n", fd);
+ server = new MtpServer(mtpdb, usePtp, 0, 0664, 0775);
+ refserver = server;
+ MTPI("created new mtpserver object\n");
+ add_storage();
+ MTPD("Starting add / remove mtppipe monitor thread\n");
+ pthread_t thread;
+ ThreadPtr mtpptr = &twmtp_MtpServer::mtppipe_thread;
+ PThreadPtr p = *(PThreadPtr*)&mtpptr;
+ pthread_create(&thread, NULL, p, this);
+ // This loop restarts the MTP process if the device is unplugged and replugged in
+ while (true) {
+ server->run(fd);
+ fd = open(mtp_device, O_RDWR);
+ usleep(800000);
}
- return 0;
}
-void twmtp_MtpServer::run()
-{
- MTPD("running in twmtp\n");
- server->run();
+void twmtp_MtpServer::set_storages(storages* mtpstorages) {
+ stores = mtpstorages;
}
void twmtp_MtpServer::cleanup()
@@ -126,7 +118,7 @@ void twmtp_MtpServer::add_storage()
android::Mutex sMutex;
android::Mutex::Autolock autoLock(sMutex);
- MTPI("adding internal storage\n");
+ MTPD("twmtp_MtpServer::add_storage count of storage devices: %i\n", stores->size());
for (unsigned int i = 0; i < stores->size(); ++i) {
std::string pathStr = stores->at(i)->mount;
diff --git a/mtp/mtp_MtpServer.hpp b/mtp/mtp_MtpServer.hpp
index 622ed6d6f..99f63d510 100755
--- a/mtp/mtp_MtpServer.hpp
+++ b/mtp/mtp_MtpServer.hpp
@@ -44,8 +44,6 @@ typedef std::vector<storage*> storages;
class twmtp_MtpServer {
public:
void start();
- int setup();
- void run();
void cleanup();
void send_object_added(int handle);
void send_object_removed(int handle);