am 2bc6971d: Merge changes I7df1ff78,Ibc2e8adf into honeycomb

* commit '2bc6971dd82d37273b0baafeeebf3ba90d15837f':
  MediaScanner: Make sure name field is set for file based playlists
  MTP: Fix problem with MTP starting up on the first try.
This commit is contained in:
Mike Lockwood
2011-01-18 20:31:45 -08:00
committed by Android Git Automerger
2 changed files with 37 additions and 14 deletions

View File

@@ -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
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

View File

@@ -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);
sMutex.unlock();
LOGD("MtpThread mServer->run");
mServer->run();
while (!mDone) {
sMutex.unlock();
LOGD("MtpThread mServer->run");
mServer->run();
sleep(1);
sMutex.lock();
}
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
}
@@ -212,7 +228,7 @@ android_mtp_MtpServer_set_ptp_mode(JNIEnv *env, jobject thiz, jboolean usePtp)
MtpThread *thread = (MtpThread *)env->GetIntField(thiz, field_context);
if (thread)
thread->setPtpMode(usePtp);
#endif
#endif
}
// ----------------------------------------------------------------------------