Revoke grants when downloads are deleted.
Jeff Sharkey [Thu, 26 Sep 2013 21:30:47 +0000 (14:30 -0700)]
When deleting downloads, revoke any Uri permission grants, which
removes from getPersistedUriPermissions().

Bug: 10928851
Change-Id: I3e90c4071385832dcb3e0cf9ca3fdccafbe30037

src/com/android/providers/downloads/DownloadProvider.java
src/com/android/providers/downloads/DownloadStorageProvider.java

index 999134f..cb3dc18 100644 (file)
@@ -1162,6 +1162,19 @@ public final class DownloadProvider extends ContentProvider {
             case ALL_DOWNLOADS_ID:
                 SqlSelection selection = getWhereClause(uri, where, whereArgs, match);
                 deleteRequestHeaders(db, selection.getSelection(), selection.getParameters());
+
+                final Cursor cursor = db.query(DB_TABLE, new String[] {
+                        Downloads.Impl._ID }, selection.getSelection(), selection.getParameters(),
+                        null, null, null);
+                try {
+                    while (cursor.moveToNext()) {
+                        final long id = cursor.getLong(0);
+                        DownloadStorageProvider.onDownloadProviderDelete(getContext(), id);
+                    }
+                } finally {
+                    IoUtils.closeQuietly(cursor);
+                }
+
                 count = db.delete(DB_TABLE, selection.getSelection(), selection.getParameters());
                 break;
 
index d982f2a..1b7b691 100644 (file)
@@ -25,6 +25,7 @@ import android.database.Cursor;
 import android.database.MatrixCursor;
 import android.database.MatrixCursor.RowBuilder;
 import android.graphics.Point;
+import android.net.Uri;
 import android.os.Binder;
 import android.os.CancellationSignal;
 import android.os.Environment;
@@ -47,6 +48,7 @@ import java.io.IOException;
  * contents.
  */
 public class DownloadStorageProvider extends DocumentsProvider {
+    private static final String AUTHORITY = Constants.STORAGE_AUTHORITY;
     private static final String DOC_ID_ROOT = Constants.STORAGE_ROOT_ID;
 
     private static final String[] DEFAULT_ROOT_PROJECTION = new String[] {
@@ -82,6 +84,11 @@ public class DownloadStorageProvider extends DocumentsProvider {
         result.setNotificationUri(getContext().getContentResolver(), cursor.getNotificationUri());
     }
 
+    static void onDownloadProviderDelete(Context context, long id) {
+        final Uri uri = DocumentsContract.buildDocumentUri(AUTHORITY, Long.toString(id));
+        context.revokeUriPermission(uri, ~0);
+    }
+
     @Override
     public Cursor queryRoots(String[] projection) throws FileNotFoundException {
         final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));