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

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

Merge changes I7df1ff78,Ibc2e8adf into honeycomb

* changes:
  MediaScanner: Make sure name field is set for file based playlists
  MTP: Fix problem with MTP starting up on the first try.
parents 3cd030a4 242d0cdc
Loading
Loading
Loading
Loading
+16 −9
Original line number Diff line number Diff line
@@ -1462,22 +1462,29 @@ public class MediaScanner
        if (lastSlash < 0) throw new IllegalArgumentException("bad path " + path);
        Uri uri, membersUri;
        long rowId = entry.mRowId;
        if (rowId == 0) {
            // Create a new playlist

        // make sure we have a name
        String name = values.getAsString(MediaStore.Audio.Playlists.NAME);
        if (name == null) {
            name = values.getAsString(MediaStore.MediaColumns.TITLE);
            if (name == null) {
                // extract name from file name
                int lastDot = path.lastIndexOf('.');
            String name = (lastDot < 0 ? path.substring(lastSlash + 1) : path.substring(lastSlash + 1, lastDot));
                name = (lastDot < 0 ? path.substring(lastSlash + 1)
                        : path.substring(lastSlash + 1, lastDot));
            }
        }

        values.put(MediaStore.Audio.Playlists.NAME, name);
            values.put(MediaStore.Audio.Playlists.DATA, path);
        values.put(MediaStore.Audio.Playlists.DATE_MODIFIED, entry.mLastModified);

        if (rowId == 0) {
            values.put(MediaStore.Audio.Playlists.DATA, path);
            uri = mMediaProvider.insert(mPlaylistsUri, values);
            rowId = ContentUris.parseId(uri);
            membersUri = Uri.withAppendedPath(uri, Playlists.Members.CONTENT_DIRECTORY);
        } else {
            uri = ContentUris.withAppendedId(mPlaylistsUri, rowId);

            // update lastModified value of existing playlist
            values.put(MediaStore.Audio.Playlists.DATE_MODIFIED, entry.mLastModified);
            mMediaProvider.update(uri, values, null, null);

            // delete members of existing playlist
+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
}