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

Commit b01a5efe authored by Mike Lockwood's avatar Mike Lockwood Committed by Android (Google) Code Review
Browse files

Merge changes Ic0e611f5,Ic06d754e

* changes:
  MTP: Remove retry loop from MTP server code
  MTP: Compatibility fixes for transferring strings
parents 4fbcdbbb 2b2bff5d
Loading
Loading
Loading
Loading
+17 −38
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ private:
    MtpDatabase*    mDatabase;
    MtpServer*      mServer;
    String8         mStoragePath;
    bool            mDone;
    jobject         mJavaServer;

public:
@@ -63,18 +62,16 @@ public:
        : mDatabase(database),
            mServer(NULL),
            mStoragePath(storagePath),
            mDone(false),
            mJavaServer(javaServer)
    {
    }

    virtual bool threadLoop() {
        while (1) {
        int fd = open("/dev/mtp_usb", O_RDWR);
        printf("open returned %d\n", fd);
        if (fd < 0) {
            LOGE("could not open MTP driver\n");
                break;
            return false;
        }

        sMutex.lock();
@@ -89,15 +86,7 @@ public:
        sMutex.lock();
        delete mServer;
        mServer = NULL;
            if (mDone)
                goto done;
            sMutex.unlock();
            // wait a bit before retrying
            sleep(1);
        }

        sMutex.lock();
done:
        JNIEnv* env = AndroidRuntime::getJNIEnv();
        env->SetIntField(mJavaServer, field_context, 0);
        env->DeleteGlobalRef(mJavaServer);
@@ -107,11 +96,6 @@ done:
        return false;
    }

    void setDone() {
        LOGD("setDone");
        mDone = true; 
    }

    void sendObjectAdded(MtpObjectHandle handle) {
        sMutex.lock();
        if (mServer)
@@ -171,11 +155,6 @@ android_media_MtpServer_stop(JNIEnv *env, jobject thiz)
{
#ifdef HAVE_ANDROID_OS
    LOGD("stop\n");
    sMutex.lock();
    MtpThread *thread = (MtpThread *)env->GetIntField(thiz, field_context);
    if (thread)
        thread->setDone();
    sMutex.unlock();
#endif
}

+4 −1
Original line number Diff line number Diff line
@@ -325,9 +325,12 @@ void MtpDataPacket::putString(const uint16_t* string) {
        else
            break;
    }
    putUInt8(count);
    putUInt8(count > 0 ? count + 1 : 0);
    for (int i = 0; i < count; i++)
        putUInt16(string[i]);
    // only terminate with zero if string is not empty
    if (count > 0)
        putUInt16(0);
}

#ifdef MTP_DEVICE 
+1 −1
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ public:
    void                putString(const MtpStringBuffer& string);
    void                putString(const char* string);
    void                putString(const uint16_t* string);
    inline void         putEmptyString() { putUInt16(0); }
    inline void         putEmptyString() { putUInt8(0); }
    inline void         putEmptyArray() { putUInt32(0); }


+4 −1
Original line number Diff line number Diff line
@@ -112,7 +112,7 @@ void MtpStringBuffer::readFromPacket(MtpDataPacket* packet) {
void MtpStringBuffer::writeToPacket(MtpDataPacket* packet) const {
    int count = mCharCount;
    const uint8_t* src = mBuffer;
    packet->putUInt8(count);
    packet->putUInt8(count > 0 ? count + 1 : 0);

    // expand utf8 to 16 bit chars
    for (int i = 0; i < count; i++) {
@@ -133,6 +133,9 @@ void MtpStringBuffer::writeToPacket(MtpDataPacket* packet) const {
        }
        packet->putUInt16(ch);
    }
    // only terminate with zero if string is not empty
    if (count > 0)
        packet->putUInt16(0);
}

}  // namespace android