MediaStore should reflect state on disk.
It's an index of data scanned from disk, and it's been misleading to let people mutate that data directly in MediaStore, since those edits aren't durable in any way. We never updated the metadata in the underlying files, so any changes would be lost when moving between devices. This change moves to always re-scan files after they've been edited, to ensure we pick up metadata changes. It also ignores direct edit attempts from apps. Bug: 120711487 Test: atest android.media.cts.MediaScannerTest Test: atest cts/tests/tests/provider/src/android/provider/cts/MediaStore* Change-Id: I4cc3ae24d6c6b5f01fe4bb47610ccf162c81ce83
This commit is contained in:
@@ -1338,7 +1338,7 @@ public final class MediaStore {
|
||||
public static final String insertImage(ContentResolver cr, Bitmap source,
|
||||
String title, String description) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(Images.Media.TITLE, title);
|
||||
values.put(Images.Media.DISPLAY_NAME, title);
|
||||
values.put(Images.Media.DESCRIPTION, description);
|
||||
values.put(Images.Media.MIME_TYPE, "image/jpeg");
|
||||
|
||||
|
||||
@@ -902,6 +902,7 @@ public class MediaScanner implements AutoCloseable {
|
||||
map.put(MediaStore.MediaColumns.SIZE, mFileSize);
|
||||
map.put(MediaStore.MediaColumns.MIME_TYPE, mMimeType);
|
||||
map.put(MediaStore.MediaColumns.IS_DRM, mIsDrm);
|
||||
map.putNull(MediaStore.MediaColumns.HASH);
|
||||
|
||||
String resolution = null;
|
||||
if (mWidth > 0 && mHeight > 0) {
|
||||
@@ -934,7 +935,7 @@ public class MediaScanner implements AutoCloseable {
|
||||
}
|
||||
} else if (MediaFile.isImageMimeType(mMimeType)) {
|
||||
// FIXME - add DESCRIPTION
|
||||
} else if (mScanSuccess && MediaFile.isAudioMimeType(mMimeType)) {
|
||||
} else if (MediaFile.isAudioMimeType(mMimeType)) {
|
||||
map.put(Audio.Media.ARTIST, (mArtist != null && mArtist.length() > 0) ?
|
||||
mArtist : MediaStore.UNKNOWN_STRING);
|
||||
map.put(Audio.Media.ALBUM_ARTIST, (mAlbumArtist != null &&
|
||||
@@ -950,10 +951,6 @@ public class MediaScanner implements AutoCloseable {
|
||||
map.put(Audio.Media.DURATION, mDuration);
|
||||
map.put(Audio.Media.COMPILATION, mCompilation);
|
||||
}
|
||||
if (!mScanSuccess) {
|
||||
// force mediaprovider to not determine the media type from the mime type
|
||||
map.put(Files.FileColumns.MEDIA_TYPE, 0);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
@@ -1056,7 +1053,7 @@ public class MediaScanner implements AutoCloseable {
|
||||
Uri tableUri = mFilesUri;
|
||||
int mediaType = FileColumns.MEDIA_TYPE_NONE;
|
||||
MediaInserter inserter = mMediaInserter;
|
||||
if (mScanSuccess && !mNoMedia) {
|
||||
if (!mNoMedia) {
|
||||
if (MediaFile.isVideoMimeType(mMimeType)) {
|
||||
tableUri = mVideoUri;
|
||||
mediaType = FileColumns.MEDIA_TYPE_VIDEO;
|
||||
@@ -1131,7 +1128,7 @@ public class MediaScanner implements AutoCloseable {
|
||||
// with squashed lower case paths
|
||||
values.remove(MediaStore.MediaColumns.DATA);
|
||||
|
||||
if (mScanSuccess && !mNoMedia) {
|
||||
if (!mNoMedia) {
|
||||
// Changing media type must be done as separate update
|
||||
if (mediaType != entry.mMediaType) {
|
||||
final ContentValues mediaTypeValues = new ContentValues();
|
||||
|
||||
Reference in New Issue
Block a user