summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2015-10-14 17:14:51 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-10-14 17:14:51 +0000
commitb176072652b18f5d169845ef453b968e78a54a57 (patch)
tree519e166352e8c6fdf56dbf3ebb20815e21e8c0c5
parentde84b09c2c70e5565b31d1cb814cf7225b916e59 (diff)
parent9f3eacce1250e96e7a7becb59e06bd49958e2e9e (diff)
downloadandroid_packages_providers_MediaProvider-b176072652b18f5d169845ef453b968e78a54a57.tar.gz
android_packages_providers_MediaProvider-b176072652b18f5d169845ef453b968e78a54a57.tar.bz2
android_packages_providers_MediaProvider-b176072652b18f5d169845ef453b968e78a54a57.zip
am 9f3eacce: am 2e1abd83: Allow deletion of media through SAF.
* commit '9f3eacce1250e96e7a7becb59e06bd49958e2e9e': Allow deletion of media through SAF.
-rw-r--r--src/com/android/providers/media/MediaDocumentsProvider.java52
1 files changed, 35 insertions, 17 deletions
diff --git a/src/com/android/providers/media/MediaDocumentsProvider.java b/src/com/android/providers/media/MediaDocumentsProvider.java
index 751ccd30..d099a415 100644
--- a/src/com/android/providers/media/MediaDocumentsProvider.java
+++ b/src/com/android/providers/media/MediaDocumentsProvider.java
@@ -187,6 +187,35 @@ public class MediaDocumentsProvider extends DocumentsProvider {
return projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION;
}
+ private Uri getUriForDocumentId(String docId) {
+ final Ident ident = getIdentForDocId(docId);
+ if (TYPE_IMAGE.equals(ident.type) && ident.id != -1) {
+ return ContentUris.withAppendedId(
+ Images.Media.EXTERNAL_CONTENT_URI, ident.id);
+ } else if (TYPE_VIDEO.equals(ident.type) && ident.id != -1) {
+ return ContentUris.withAppendedId(
+ Video.Media.EXTERNAL_CONTENT_URI, ident.id);
+ } else if (TYPE_AUDIO.equals(ident.type) && ident.id != -1) {
+ return ContentUris.withAppendedId(
+ Audio.Media.EXTERNAL_CONTENT_URI, ident.id);
+ } else {
+ throw new UnsupportedOperationException("Unsupported document " + docId);
+ }
+ }
+
+ @Override
+ public void deleteDocument(String docId) throws FileNotFoundException {
+ final Uri target = getUriForDocumentId(docId);
+
+ // Delegate to real provider
+ final long token = Binder.clearCallingIdentity();
+ try {
+ getContext().getContentResolver().delete(target, null, null);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
@@ -415,26 +444,12 @@ public class MediaDocumentsProvider extends DocumentsProvider {
@Override
public ParcelFileDescriptor openDocument(String docId, String mode, CancellationSignal signal)
throws FileNotFoundException {
- final Ident ident = getIdentForDocId(docId);
+ final Uri target = getUriForDocumentId(docId);
if (!"r".equals(mode)) {
throw new IllegalArgumentException("Media is read-only");
}
- final Uri target;
- if (TYPE_IMAGE.equals(ident.type) && ident.id != -1) {
- target = ContentUris.withAppendedId(
- Images.Media.EXTERNAL_CONTENT_URI, ident.id);
- } else if (TYPE_VIDEO.equals(ident.type) && ident.id != -1) {
- target = ContentUris.withAppendedId(
- Video.Media.EXTERNAL_CONTENT_URI, ident.id);
- } else if (TYPE_AUDIO.equals(ident.type) && ident.id != -1) {
- target = ContentUris.withAppendedId(
- Audio.Media.EXTERNAL_CONTENT_URI, ident.id);
- } else {
- throw new UnsupportedOperationException("Unsupported document " + docId);
- }
-
// Delegate to real provider
final long token = Binder.clearCallingIdentity();
try {
@@ -609,7 +624,8 @@ public class MediaDocumentsProvider extends DocumentsProvider {
row.add(Document.COLUMN_MIME_TYPE, cursor.getString(ImageQuery.MIME_TYPE));
row.add(Document.COLUMN_LAST_MODIFIED,
cursor.getLong(ImageQuery.DATE_MODIFIED) * DateUtils.SECOND_IN_MILLIS);
- row.add(Document.COLUMN_FLAGS, Document.FLAG_SUPPORTS_THUMBNAIL);
+ row.add(Document.COLUMN_FLAGS,
+ Document.FLAG_SUPPORTS_THUMBNAIL | Document.FLAG_SUPPORTS_DELETE);
}
private interface VideosBucketQuery {
@@ -667,7 +683,8 @@ public class MediaDocumentsProvider extends DocumentsProvider {
row.add(Document.COLUMN_MIME_TYPE, cursor.getString(VideoQuery.MIME_TYPE));
row.add(Document.COLUMN_LAST_MODIFIED,
cursor.getLong(VideoQuery.DATE_MODIFIED) * DateUtils.SECOND_IN_MILLIS);
- row.add(Document.COLUMN_FLAGS, Document.FLAG_SUPPORTS_THUMBNAIL);
+ row.add(Document.COLUMN_FLAGS,
+ Document.FLAG_SUPPORTS_THUMBNAIL | Document.FLAG_SUPPORTS_DELETE);
}
private interface ArtistQuery {
@@ -736,6 +753,7 @@ public class MediaDocumentsProvider extends DocumentsProvider {
row.add(Document.COLUMN_MIME_TYPE, cursor.getString(SongQuery.MIME_TYPE));
row.add(Document.COLUMN_LAST_MODIFIED,
cursor.getLong(SongQuery.DATE_MODIFIED) * DateUtils.SECOND_IN_MILLIS);
+ row.add(Document.COLUMN_FLAGS, Document.FLAG_SUPPORTS_DELETE);
}
private interface ImagesBucketThumbnailQuery {