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

Commit 94ef0eab authored by Jerry Zhang's avatar Jerry Zhang
Browse files

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
(cherry picked from commit d80492b8)
parent b5c1bcb9
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -719,9 +719,22 @@ int MtpFfsHandle::sendFile(mtp_file_range mfr) {
}

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
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ private:
    bool initFunctionfs();
    void closeConfig();
    void closeEndpoints();
    void doSendEvent(mtp_event me);

    bool mPtp;