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

Commit 0475d911 authored by Jerry Zhang's avatar Jerry Zhang
Browse files

Add timeout to lock in MtpServer configure

In situations where MtpServer is in a bad state, this will prevent
the configure call from blocking indefinitely, which will prevent
a few visible problems and allow the state to recover on the next
config change.

Bug: 34873000
Test: Connect to AA test sled
Change-Id: I5daf9cfcec69c967bde6bf3f6fd90e1c434e18bb
parent 58a220fe
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -490,7 +490,11 @@ int MtpFfsHandle::start() {

int MtpFfsHandle::configure(bool usePtp) {
    // Wait till previous server invocation has closed
    std::lock_guard<std::mutex> lk(mLock);
    if (!mLock.try_lock_for(std::chrono::milliseconds(1000))) {
        LOG(ERROR) << "MtpServer was unable to get configure lock";
        return -1;
    }
    int ret = 0;

    // If ptp is changed, the configuration must be rewritten
    if (mPtp != usePtp) {
@@ -500,10 +504,10 @@ int MtpFfsHandle::configure(bool usePtp) {
    mPtp = usePtp;

    if (!initFunctionfs()) {
        return -1;
        ret = -1;
    }

    return 0;
    mLock.unlock();
    return ret;
}

void MtpFfsHandle::close() {
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ private:

    bool mPtp;

    std::mutex mLock;
    std::timed_mutex mLock;

    android::base::unique_fd mControl;
    // "in" from the host's perspective => sink for mtp server