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.
diff --git a/media/java/android/media/MediaScanner.java b/media/java/android/media/MediaScanner.java
index 10c9a9a..33c6385 100644
--- a/media/java/android/media/MediaScanner.java
+++ b/media/java/android/media/MediaScanner.java
@@ -1462,22 +1462,29 @@
if (lastSlash < 0) throw new IllegalArgumentException("bad path " + path);
Uri uri, membersUri;
long rowId = entry.mRowId;
- if (rowId == 0) {
- // Create a new playlist
- int lastDot = path.lastIndexOf('.');
- String name = (lastDot < 0 ? path.substring(lastSlash + 1) : path.substring(lastSlash + 1, lastDot));
- values.put(MediaStore.Audio.Playlists.NAME, name);
+ // 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('.');
+ name = (lastDot < 0 ? path.substring(lastSlash + 1)
+ : path.substring(lastSlash + 1, lastDot));
+ }
+ }
+
+ values.put(MediaStore.Audio.Playlists.NAME, name);
+ values.put(MediaStore.Audio.Playlists.DATE_MODIFIED, entry.mLastModified);
+
+ if (rowId == 0) {
values.put(MediaStore.Audio.Playlists.DATA, path);
- values.put(MediaStore.Audio.Playlists.DATE_MODIFIED, entry.mLastModified);
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
diff --git a/media/jni/android_mtp_MtpServer.cpp b/media/jni/android_mtp_MtpServer.cpp
index 241f18a..4693ec5c 100644
--- a/media/jni/android_mtp_MtpServer.cpp
+++ b/media/jni/android_mtp_MtpServer.cpp
@@ -62,6 +62,7 @@
String8 mStoragePath;
uint64_t mReserveSpace;
jobject mJavaServer;
+ bool mDone;
int mFd;
public:
@@ -72,6 +73,7 @@
mStoragePath(storagePath),
mReserveSpace(reserveSpace),
mJavaServer(javaServer),
+ mDone(false),
mFd(-1)
{
}
@@ -104,12 +106,17 @@
mServer = new MtpServer(mFd, mDatabase, AID_MEDIA_RW, 0664, 0775);
mServer->addStorage(mStoragePath, mReserveSpace);
- sMutex.unlock();
- LOGD("MtpThread mServer->run");
- mServer->run();
+ while (!mDone) {
+ sMutex.unlock();
- sMutex.lock();
+ LOGD("MtpThread mServer->run");
+ mServer->run();
+ sleep(1);
+
+ sMutex.lock();
+ }
+
close(mFd);
mFd = -1;
delete mServer;
@@ -124,6 +131,12 @@
return false;
}
+ void stop() {
+ sMutex.lock();
+ mDone = true;
+ sMutex.unlock();
+ }
+
void sendObjectAdded(MtpObjectHandle handle) {
sMutex.lock();
if (mServer)
@@ -181,6 +194,9 @@
{
#ifdef HAVE_ANDROID_OS
LOGD("stop\n");
+ MtpThread *thread = (MtpThread *)env->GetIntField(thiz, field_context);
+ if (thread)
+ thread->stop();
#endif
}
@@ -212,7 +228,7 @@
MtpThread *thread = (MtpThread *)env->GetIntField(thiz, field_context);
if (thread)
thread->setPtpMode(usePtp);
- #endif
+#endif
}
// ----------------------------------------------------------------------------