mtp: Send events async.
AFT will not read the events endpoint at all
causing every sendEvent() to block. Since
event ordering doesn't really matter, send
events in their own detached thread instead.
Bug: 36802721
Test: Connect AFT, create a folder from device, check not frozen
Change-Id: I4b8aee93c19fa9c73e6b2f34d9794a491b2433e1
diff --git a/media/mtp/MtpFfsHandle.cpp b/media/mtp/MtpFfsHandle.cpp
index c50af2f..23fd7ab 100644
--- a/media/mtp/MtpFfsHandle.cpp
+++ b/media/mtp/MtpFfsHandle.cpp
@@ -719,9 +719,22 @@
}
int MtpFfsHandle::sendEvent(mtp_event me) {
+ // Mimic the behavior of f_mtp by sending the event async.
+ // Events aren't critical to the connection, so we don't need to check the return value.
+ char *temp = new char[me.length];
+ memcpy(temp, me.data, me.length);
+ me.data = temp;
+ std::thread t([&me](MtpFfsHandle *h) { return h->doSendEvent(me); }, this);
+ t.detach();
+ return 0;
+}
+
+void MtpFfsHandle::doSendEvent(mtp_event me) {
unsigned length = me.length;
- int ret = writeHandle(mIntr, me.data, length);
- return static_cast<unsigned>(ret) == length ? 0 : -1;
+ int ret = ::write(mIntr, me.data, length);
+ delete[] reinterpret_cast<char*>(me.data);
+ if (static_cast<unsigned>(ret) != length)
+ PLOG(ERROR) << "Mtp error sending event thread!";
}
} // namespace android