summaryrefslogtreecommitdiffstats
path: root/ui/src/com/android/providers
diff options
context:
space:
mode:
authorVasu Nori <vnori@google.com>2010-10-12 23:27:49 -0700
committerVasu Nori <vnori@google.com>2010-10-13 16:23:03 -0700
commite00c31208405bd2e4c88e069df7a2b15237f70bf (patch)
treeb5e8c3da030e821681e36660360ad5cf34c0d9b7 /ui/src/com/android/providers
parentcd990514feb2b17848809d9262e0d73a828b2142 (diff)
downloadandroid_packages_providers_DownloadProvider-e00c31208405bd2e4c88e069df7a2b15237f70bf.tar.gz
android_packages_providers_DownloadProvider-e00c31208405bd2e4c88e069df7a2b15237f70bf.tar.bz2
android_packages_providers_DownloadProvider-e00c31208405bd2e4c88e069df7a2b15237f70bf.zip
bug:3069735 in Download UI app, handle deletes correctly
gingerbread. High-level details 1. When a file is downloaded by DownloadManager, metadata about the file is stored in 2 databases: DownloadProvider and MediaProvider. 2. So, when it is to be deleted, its metadata needs to be cleaned up from both the databases. 3. But the 2 databases use differnt content-uri's as "primary keys" and DownloadProvider loses the "primary-key" of the row in MediaProvider database. 4. Easiest thing would have been to have DownloadProvider give filepath to MediaProvider and let MediaProvider linearly scan its database to locate the row and delete it. 5. The other - faster but more coding for now - option is to have DownloadProvider store the "primary-key" of the MediaProvider's row. implemented in this CL. Low-level details 1. add 2 new columns to downloads table in downloads.db: mediaprovider_uri = downloaded file's content_uri in mediaprovider db this column is null for downloads that finished before this column is added to the database. deleted = flag is set to true if a file is to be deleted 2. download UI app shows only those files whose 'deleted' flag is not set. 3. when the user deletes downloads from download UI app, 3.1. if mediaprovider_uri is NOT null, then the row is deleted from downloads table AND from the mediaprovider database. 3.2 if mediaprovider_uri is NULL, then its row in downloads database is marked 'tp be deleted' by setting 'deleted' column to '1'. 4. When DownloadService (in DownloadProvider) processes all rows from downloads table, if it sees any rows wth 'deleted' = 1, then it uses MediaScanner Service to re-scan the file, get the mediaprovider_uri from MediaProvider and update the row in downloads table with this mediaprovider_uri value and then delete the row by doing the following 1. delete it from MediaProvider database using mediaprovider_uri 2. delete it from DownloadProvider database Problem with this solution: There is a small window where it is deleted by the user on the Download app (and the row disappears from the display) but it is still present in Gallery app. Thats due to the following asynchronous operations 1. DownladService which processes rows-to-be-deleted is not always up 2. DownloadService uses asynchronous call to have the file re-scanned by MediaScanner to get mediaprovider_uri Change-Id: Ib90eb9e647f543312c865d3bbf9a06fb867a648b
Diffstat (limited to 'ui/src/com/android/providers')
-rw-r--r--ui/src/com/android/providers/downloads/ui/DownloadList.java37
1 files changed, 18 insertions, 19 deletions
diff --git a/ui/src/com/android/providers/downloads/ui/DownloadList.java b/ui/src/com/android/providers/downloads/ui/DownloadList.java
index f1cb91fe..33f821f6 100644
--- a/ui/src/com/android/providers/downloads/ui/DownloadList.java
+++ b/ui/src/com/android/providers/downloads/ui/DownloadList.java
@@ -33,6 +33,7 @@ import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.Downloads;
+import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
@@ -51,7 +52,6 @@ import android.widget.Toast;
import com.android.providers.downloads.ui.DownloadItem.DownloadSelectListener;
-import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashSet;
@@ -86,6 +86,7 @@ public class DownloadList extends Activity
private int mLocalUriColumnId;
private int mMediaTypeColumnId;
private int mReasonColumndId;
+ private int mMediaProviderUriId;
private boolean mIsSortedBySize = false;
private Set<Long> mSelectedIds = new HashSet<Long>();
@@ -148,6 +149,9 @@ public class DownloadList extends Activity
mDateSortedCursor.getColumnIndexOrThrow(DownloadManager.COLUMN_MEDIA_TYPE);
mReasonColumndId =
mDateSortedCursor.getColumnIndexOrThrow(DownloadManager.COLUMN_REASON);
+ mMediaProviderUriId =
+ mDateSortedCursor.getColumnIndexOrThrow(
+ DownloadManager.COLUMN_MEDIAPROVIDER_URI);
mDateSortedAdapter = new DateSortedDownloadAdapter(this, mDateSortedCursor, this);
mDateOrderedListView.setAdapter(mDateSortedAdapter);
@@ -588,30 +592,25 @@ public class DownloadList extends Activity
if (isComplete && localUri != null) {
String path = Uri.parse(localUri).getPath();
if (path.startsWith(Environment.getExternalStorageDirectory().getPath())) {
- String mediaType = mDateSortedCursor.getString(mMediaTypeColumnId);
- deleteDownloadedFile(path, mediaType);
+ String mediaProviderUri = mDateSortedCursor.getString(mMediaProviderUriId);
+ if (TextUtils.isEmpty(mediaProviderUri)) {
+ // downloads database doesn't have the mediaprovider_uri. It means
+ // this download occurred before mediaprovider_uri column existed
+ // in downloads table. Since MediaProvider needs the mediaprovider_uri to
+ // delete this download, just set the 'deleted' flag to 1 on this row
+ // in the database. DownloadService, upon seeing this flag set to 1, will
+ // re-scan the file and get the MediaProviderUri and then delete the file
+ mDownloadManager.markRowDeleted(downloadId);
+ return;
+ } else {
+ getContentResolver().delete(Uri.parse(mediaProviderUri), null, null);
+ }
}
}
}
mDownloadManager.remove(downloadId);
}
- /**
- * Delete the file at the given path. Try sending an intent to delete it, but if that goes
- * unhandled, delete it ourselves.
- * @param path path to the file to delete
- */
- private void deleteDownloadedFile(String path, String mediaType) {
- Intent intent = new Intent(Intent.ACTION_DELETE);
- File file = new File(path);
- intent.setDataAndType(Uri.fromFile(file), mediaType);
- try {
- startActivity(intent);
- } catch (ActivityNotFoundException exc) {
- file.delete();
- }
- }
-
@Override
public boolean isDownloadSelected(long id) {
return mSelectedIds.contains(id);