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

Commit 2c377d34 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Merge cherrypicks of ['googleplex-android-review.googlesource.com/24303963',...

Merge cherrypicks of ['googleplex-android-review.googlesource.com/24303963', 'googleplex-android-review.googlesource.com/24303958', 'googleplex-android-review.googlesource.com/24433390'] into udc-release.

Change-Id: I1337e2d012c6f1c06d5fdc79bc67b44143e11ef3
parents 402dbe88 844ca64c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -105,6 +105,7 @@ ARTPWriter::ARTPWriter(int fd)

    mRTCPAddr = mRTPAddr;
    mRTCPAddr.sin_port = htons(ntohs(mRTPAddr.sin_port) | 1);
    mVPSBuf = NULL;
    mSPSBuf = NULL;
    mPPSBuf = NULL;

+14 −0
Original line number Diff line number Diff line
@@ -297,6 +297,10 @@ int MtpFfsHandle::start(bool ptp) {
}

void MtpFfsHandle::close() {
    auto timeout = std::chrono::seconds(2);
    std::unique_lock lk(m);
    cv.wait_for(lk, timeout ,[this]{return child_threads==0;});

    io_destroy(mCtx);
    closeEndpoints();
    closeConfig();
@@ -669,6 +673,11 @@ int MtpFfsHandle::sendEvent(mtp_event me) {
    char *temp = new char[me.length];
    memcpy(temp, me.data, me.length);
    me.data = temp;

    std::unique_lock lk(m);
    child_threads++;
    lk.unlock();

    std::thread t([this, me]() { return this->doSendEvent(me); });
    t.detach();
    return 0;
@@ -680,6 +689,11 @@ void MtpFfsHandle::doSendEvent(mtp_event me) {
    if (static_cast<unsigned>(ret) != length)
        PLOG(ERROR) << "Mtp error sending event thread!";
    delete[] reinterpret_cast<char*>(me.data);

    std::unique_lock lk(m);
    child_threads--;
    lk.unlock();
    cv.notify_one();
}

} // namespace android
+4 −0
Original line number Diff line number Diff line
@@ -60,6 +60,10 @@ protected:
    bool mCanceled;
    bool mBatchCancel;

    std::mutex m;
    std::condition_variable cv;
    std::atomic<int> child_threads{0};

    android::base::unique_fd mControl;
    // "in" from the host's perspective => sink for mtp server
    android::base::unique_fd mBulkIn;
+31 −9
Original line number Diff line number Diff line
@@ -92,25 +92,47 @@ void MtpPacket::copyFrom(const MtpPacket& src) {
}

uint16_t MtpPacket::getUInt16(int offset) const {
    if ((unsigned long)(offset+2) <= mBufferSize) {
        return ((uint16_t)mBuffer[offset + 1] << 8) | (uint16_t)mBuffer[offset];
    }
    else {
        ALOGE("offset for buffer read is greater than buffer size!");
        abort();
    }
}

uint32_t MtpPacket::getUInt32(int offset) const {
    if ((unsigned long)(offset+4) <= mBufferSize) {
        return ((uint32_t)mBuffer[offset + 3] << 24) | ((uint32_t)mBuffer[offset + 2] << 16) |
               ((uint32_t)mBuffer[offset + 1] << 8)  | (uint32_t)mBuffer[offset];
    }
    else {
        ALOGE("offset for buffer read is greater than buffer size!");
        abort();
    }
}

void MtpPacket::putUInt16(int offset, uint16_t value) {
    if ((unsigned long)(offset+2) <= mBufferSize) {
        mBuffer[offset++] = (uint8_t)(value & 0xFF);
        mBuffer[offset++] = (uint8_t)((value >> 8) & 0xFF);
    }
    else {
        ALOGE("offset for buffer write is greater than buffer size!");
    }
}

void MtpPacket::putUInt32(int offset, uint32_t value) {
    if ((unsigned long)(offset+4) <= mBufferSize) {
        mBuffer[offset++] = (uint8_t)(value & 0xFF);
        mBuffer[offset++] = (uint8_t)((value >> 8) & 0xFF);
        mBuffer[offset++] = (uint8_t)((value >> 16) & 0xFF);
        mBuffer[offset++] = (uint8_t)((value >> 24) & 0xFF);
    }
    else {
        ALOGE("offset for buffer write is greater than buffer size!");
    }
}

uint16_t MtpPacket::getContainerCode() const {
    return getUInt16(MTP_CONTAINER_CODE_OFFSET);