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.
This commit is contained in:
committed by
Android (Google) Code Review
commit
2bc6971dd8
@@ -1462,22 +1462,29 @@ public class MediaScanner
|
|||||||
if (lastSlash < 0) throw new IllegalArgumentException("bad path " + path);
|
if (lastSlash < 0) throw new IllegalArgumentException("bad path " + path);
|
||||||
Uri uri, membersUri;
|
Uri uri, membersUri;
|
||||||
long rowId = entry.mRowId;
|
long rowId = entry.mRowId;
|
||||||
if (rowId == 0) {
|
|
||||||
// Create a new playlist
|
|
||||||
|
|
||||||
int lastDot = path.lastIndexOf('.');
|
// make sure we have a name
|
||||||
String name = (lastDot < 0 ? path.substring(lastSlash + 1) : path.substring(lastSlash + 1, lastDot));
|
String name = values.getAsString(MediaStore.Audio.Playlists.NAME);
|
||||||
values.put(MediaStore.Audio.Playlists.NAME, 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.DATA, path);
|
||||||
values.put(MediaStore.Audio.Playlists.DATE_MODIFIED, entry.mLastModified);
|
|
||||||
uri = mMediaProvider.insert(mPlaylistsUri, values);
|
uri = mMediaProvider.insert(mPlaylistsUri, values);
|
||||||
rowId = ContentUris.parseId(uri);
|
rowId = ContentUris.parseId(uri);
|
||||||
membersUri = Uri.withAppendedPath(uri, Playlists.Members.CONTENT_DIRECTORY);
|
membersUri = Uri.withAppendedPath(uri, Playlists.Members.CONTENT_DIRECTORY);
|
||||||
} else {
|
} else {
|
||||||
uri = ContentUris.withAppendedId(mPlaylistsUri, rowId);
|
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);
|
mMediaProvider.update(uri, values, null, null);
|
||||||
|
|
||||||
// delete members of existing playlist
|
// delete members of existing playlist
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ private:
|
|||||||
String8 mStoragePath;
|
String8 mStoragePath;
|
||||||
uint64_t mReserveSpace;
|
uint64_t mReserveSpace;
|
||||||
jobject mJavaServer;
|
jobject mJavaServer;
|
||||||
|
bool mDone;
|
||||||
int mFd;
|
int mFd;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -72,6 +73,7 @@ public:
|
|||||||
mStoragePath(storagePath),
|
mStoragePath(storagePath),
|
||||||
mReserveSpace(reserveSpace),
|
mReserveSpace(reserveSpace),
|
||||||
mJavaServer(javaServer),
|
mJavaServer(javaServer),
|
||||||
|
mDone(false),
|
||||||
mFd(-1)
|
mFd(-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -104,12 +106,17 @@ public:
|
|||||||
|
|
||||||
mServer = new MtpServer(mFd, mDatabase, AID_MEDIA_RW, 0664, 0775);
|
mServer = new MtpServer(mFd, mDatabase, AID_MEDIA_RW, 0664, 0775);
|
||||||
mServer->addStorage(mStoragePath, mReserveSpace);
|
mServer->addStorage(mStoragePath, mReserveSpace);
|
||||||
sMutex.unlock();
|
|
||||||
|
|
||||||
LOGD("MtpThread mServer->run");
|
while (!mDone) {
|
||||||
mServer->run();
|
sMutex.unlock();
|
||||||
|
|
||||||
|
LOGD("MtpThread mServer->run");
|
||||||
|
mServer->run();
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
sMutex.lock();
|
||||||
|
}
|
||||||
|
|
||||||
sMutex.lock();
|
|
||||||
close(mFd);
|
close(mFd);
|
||||||
mFd = -1;
|
mFd = -1;
|
||||||
delete mServer;
|
delete mServer;
|
||||||
@@ -124,6 +131,12 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void stop() {
|
||||||
|
sMutex.lock();
|
||||||
|
mDone = true;
|
||||||
|
sMutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
void sendObjectAdded(MtpObjectHandle handle) {
|
void sendObjectAdded(MtpObjectHandle handle) {
|
||||||
sMutex.lock();
|
sMutex.lock();
|
||||||
if (mServer)
|
if (mServer)
|
||||||
@@ -181,6 +194,9 @@ android_mtp_MtpServer_stop(JNIEnv *env, jobject thiz)
|
|||||||
{
|
{
|
||||||
#ifdef HAVE_ANDROID_OS
|
#ifdef HAVE_ANDROID_OS
|
||||||
LOGD("stop\n");
|
LOGD("stop\n");
|
||||||
|
MtpThread *thread = (MtpThread *)env->GetIntField(thiz, field_context);
|
||||||
|
if (thread)
|
||||||
|
thread->stop();
|
||||||
#endif
|
#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);
|
MtpThread *thread = (MtpThread *)env->GetIntField(thiz, field_context);
|
||||||
if (thread)
|
if (thread)
|
||||||
thread->setPtpMode(usePtp);
|
thread->setPtpMode(usePtp);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user