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

Commit a1c91804 authored by Mike Lockwood's avatar Mike Lockwood
Browse files

MTP: Fix problem with MTP starting up on the first try.



BUG: 3361230

Change-Id: Ibc2e8adf24a14ea18385b306e786a77983ff8f5b
Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent 5f31aa30
Loading
Loading
Loading
Loading
+21 −5
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ private:
    String8         mStoragePath;
    uint64_t        mReserveSpace;
    jobject         mJavaServer;
    bool            mDone;
    int             mFd;

public:
@@ -72,6 +73,7 @@ public:
            mStoragePath(storagePath),
            mReserveSpace(reserveSpace),
            mJavaServer(javaServer),
            mDone(false),
            mFd(-1)
    {
    }
@@ -104,12 +106,17 @@ public:

        mServer = new MtpServer(mFd, mDatabase, AID_MEDIA_RW, 0664, 0775);
        mServer->addStorage(mStoragePath, mReserveSpace);

        while (!mDone) {
            sMutex.unlock();

            LOGD("MtpThread mServer->run");
            mServer->run();
            sleep(1);

            sMutex.lock();
        }

        close(mFd);
        mFd = -1;
        delete mServer;
@@ -124,6 +131,12 @@ public:
        return false;
    }

    void stop() {
        sMutex.lock();
        mDone = true;
        sMutex.unlock();
    }

    void sendObjectAdded(MtpObjectHandle handle) {
        sMutex.lock();
        if (mServer)
@@ -181,6 +194,9 @@ android_mtp_MtpServer_stop(JNIEnv *env, jobject thiz)
{
#ifdef HAVE_ANDROID_OS
    LOGD("stop\n");
    MtpThread *thread = (MtpThread *)env->GetIntField(thiz, field_context);
    if (thread)
        thread->stop();
#endif
}