Loading mtp/twrpMtp.cpp +16 −1 Original line number Diff line number Diff line Loading @@ -82,7 +82,7 @@ int twrpMtp::start(void) { return 0; } pthread_t twrpMtp::runserver(void) { pthread_t twrpMtp::threadserver(void) { pthread_t thread; ThreadPtr mtpptr = &twrpMtp::start; PThreadPtr p = *(PThreadPtr*)&mtpptr; Loading @@ -90,6 +90,21 @@ pthread_t twrpMtp::runserver(void) { return thread; } pid_t twrpMtp::forkserver(void) { pid_t pid; if ((pid = fork()) == -1) { MTPE("MTP fork failed.\n"); return 0; } if (pid == 0) { // Child process start(); } else { return pid; } return 0; } void twrpMtp::addStorage(std::string display, std::string path, int mtpid) { s = new storage; s->display = display; Loading mtp/twrpMtp.hpp +2 −1 Original line number Diff line number Diff line Loading @@ -34,7 +34,8 @@ class twrpMtp { public: twrpMtp(int debug_enabled /* = 0 */); pthread_t runserver(void); pthread_t threadserver(void); pid_t forkserver(void); void addStorage(std::string display, std::string path, int mtpid); private: int start(void); Loading partitionmanager.cpp +12 −7 Original line number Diff line number Diff line Loading @@ -2153,7 +2153,7 @@ TWPartition *TWPartitionManager::Get_Default_Storage_Partition() bool TWPartitionManager::Enable_MTP(void) { #ifdef TW_HAS_MTP if (mtpthread) { if (mtppid) { LOGERR("MTP already enabled\n"); return true; } Loading Loading @@ -2183,9 +2183,14 @@ bool TWPartitionManager::Enable_MTP(void) { } } if (count) { mtpthread = mtp->runserver(); mtppid = mtp->forkserver(); if (mtppid) { DataManager::SetValue("tw_mtp_enabled", 1); return true; } else { LOGERR("Failed to enable MTP\n"); return false; } } LOGERR("No valid storage partitions found for MTP.\n"); #else Loading @@ -2206,9 +2211,9 @@ bool TWPartitionManager::Disable_MTP(void) { string productstr = product; TWFunc::write_file("/sys/class/android_usb/android0/idVendor", vendorstr); TWFunc::write_file("/sys/class/android_usb/android0/idProduct", productstr); if (mtpthread) { pthread_kill(mtpthread, 0); mtpthread = NULL; if (mtppid) { kill(mtppid, SIGTERM); mtppid = 0; } property_set("sys.usb.config", "adb"); DataManager::SetValue("tw_mtp_enabled", 0); Loading partitions.hpp +1 −1 Original line number Diff line number Diff line Loading @@ -239,7 +239,7 @@ private: TWPartition* Find_Next_Storage(string Path, string Exclude); int Open_Lun_File(string Partition_Path, string Lun_File); int mtpid; pthread_t mtpthread; pid_t mtppid; bool mtp_was_enabled; private: Loading Loading
mtp/twrpMtp.cpp +16 −1 Original line number Diff line number Diff line Loading @@ -82,7 +82,7 @@ int twrpMtp::start(void) { return 0; } pthread_t twrpMtp::runserver(void) { pthread_t twrpMtp::threadserver(void) { pthread_t thread; ThreadPtr mtpptr = &twrpMtp::start; PThreadPtr p = *(PThreadPtr*)&mtpptr; Loading @@ -90,6 +90,21 @@ pthread_t twrpMtp::runserver(void) { return thread; } pid_t twrpMtp::forkserver(void) { pid_t pid; if ((pid = fork()) == -1) { MTPE("MTP fork failed.\n"); return 0; } if (pid == 0) { // Child process start(); } else { return pid; } return 0; } void twrpMtp::addStorage(std::string display, std::string path, int mtpid) { s = new storage; s->display = display; Loading
mtp/twrpMtp.hpp +2 −1 Original line number Diff line number Diff line Loading @@ -34,7 +34,8 @@ class twrpMtp { public: twrpMtp(int debug_enabled /* = 0 */); pthread_t runserver(void); pthread_t threadserver(void); pid_t forkserver(void); void addStorage(std::string display, std::string path, int mtpid); private: int start(void); Loading
partitionmanager.cpp +12 −7 Original line number Diff line number Diff line Loading @@ -2153,7 +2153,7 @@ TWPartition *TWPartitionManager::Get_Default_Storage_Partition() bool TWPartitionManager::Enable_MTP(void) { #ifdef TW_HAS_MTP if (mtpthread) { if (mtppid) { LOGERR("MTP already enabled\n"); return true; } Loading Loading @@ -2183,9 +2183,14 @@ bool TWPartitionManager::Enable_MTP(void) { } } if (count) { mtpthread = mtp->runserver(); mtppid = mtp->forkserver(); if (mtppid) { DataManager::SetValue("tw_mtp_enabled", 1); return true; } else { LOGERR("Failed to enable MTP\n"); return false; } } LOGERR("No valid storage partitions found for MTP.\n"); #else Loading @@ -2206,9 +2211,9 @@ bool TWPartitionManager::Disable_MTP(void) { string productstr = product; TWFunc::write_file("/sys/class/android_usb/android0/idVendor", vendorstr); TWFunc::write_file("/sys/class/android_usb/android0/idProduct", productstr); if (mtpthread) { pthread_kill(mtpthread, 0); mtpthread = NULL; if (mtppid) { kill(mtppid, SIGTERM); mtppid = 0; } property_set("sys.usb.config", "adb"); DataManager::SetValue("tw_mtp_enabled", 0); Loading
partitions.hpp +1 −1 Original line number Diff line number Diff line Loading @@ -239,7 +239,7 @@ private: TWPartition* Find_Next_Storage(string Path, string Exclude); int Open_Lun_File(string Partition_Path, string Lun_File); int mtpid; pthread_t mtpthread; pid_t mtppid; bool mtp_was_enabled; private: Loading