Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6d154c4f authored by Ethan Yonker's avatar Ethan Yonker
Browse files

Allow toggle of MTP debug

Via command line in TWRP:
twrp set tw_mtp_debug 1

This will enable debugging for MTP. You will need to disable and
re-enable MTP in order to see the debug logging.

Change-Id: Ia7bb0c584e10a4322b65ecf80a67ed7ee836b38e
parent 20fd25c2
Loading
Loading
Loading
Loading
+14 −9
Original line number Diff line number Diff line
@@ -21,11 +21,11 @@
#include <stdio.h>

#define MTP_DEBUG_BUFFER_SIZE 2048
//#define MTP_DEBUG 1
static int debug_enabled = 0;

extern "C" void mtpdebug(const char *fmt, ...)
{
#ifdef MTP_DEBUG
	if (debug_enabled) {
		char buf[MTP_DEBUG_BUFFER_SIZE];		// We're going to limit a single request to 512 bytes

		va_list ap;
@@ -34,7 +34,7 @@ extern "C" void mtpdebug(const char *fmt, ...)
		va_end(ap);

		fputs(buf, stdout);
#endif
	}
}

struct CodeEntry {
@@ -417,3 +417,8 @@ const char* MtpDebug::getDevicePropCodeName(MtpPropertyCode code) {
		return "NONE";
	return getCodeName(code, sDevicePropCodes);
}

void MtpDebug::enableDebug(void) {
	debug_enabled = 1;
	MTPD("MTP debug logging enabled\n");
}
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ public:
	static const char* getFormatCodeName(MtpObjectFormat code);
	static const char* getObjectPropCodeName(MtpPropertyCode code);
	static const char* getDevicePropCodeName(MtpPropertyCode code);
	static void enableDebug();
};


+3 −1
Original line number Diff line number Diff line
@@ -68,7 +68,9 @@ int main(int argc, char* argv[]) {
}
#endif //def TWRPMTP

twrpMtp::twrpMtp() {
twrpMtp::twrpMtp(int debug_enabled = 0) {
	if (debug_enabled)
		MtpDebug::enableDebug();
	mtpstorages = new storages;
}

+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@

class twrpMtp {
	public:
		twrpMtp();
		twrpMtp(int debug_enabled /* = 0 */);
		pthread_t runserver(void);
		void addStorage(std::string display, std::string path, int mtpid);
	private:
+4 −1
Original line number Diff line number Diff line
@@ -2171,7 +2171,10 @@ bool TWPartitionManager::Enable_MTP(void) {
	TWFunc::write_file("/sys/class/android_usb/android0/idProduct", productstr);
	property_set("sys.usb.config", "mtp,adb");
	std::vector<TWPartition*>::iterator iter;
	twrpMtp *mtp = new twrpMtp();
	/* To enable MTP debug, use the twrp command line feature to
	 * twrp set tw_mtp_debug 1
	 */
	twrpMtp *mtp = new twrpMtp(DataManager::GetIntValue("tw_mtp_debug"));
	for (iter = Partitions.begin(); iter != Partitions.end(); iter++) {
		if ((*iter)->Is_Storage && (*iter)->Is_Present && (*iter)->Mount(false)) {
			printf("twrp mtpid: %d\n", (*iter)->mtpid);