summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/DownloadInfo.java
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 /src/com/android/providers/downloads/DownloadInfo.java
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 'src/com/android/providers/downloads/DownloadInfo.java')
-rw-r--r--src/com/android/providers/downloads/DownloadInfo.java8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/com/android/providers/downloads/DownloadInfo.java b/src/com/android/providers/downloads/DownloadInfo.java
index 3327e80b..36816b59 100644
--- a/src/com/android/providers/downloads/DownloadInfo.java
+++ b/src/com/android/providers/downloads/DownloadInfo.java
@@ -29,6 +29,7 @@ import android.net.ConnectivityManager;
import android.net.Uri;
import android.provider.Downloads;
import android.provider.Downloads.Impl;
+import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
@@ -84,6 +85,9 @@ public class DownloadInfo {
info.mCurrentBytes = getLong(Downloads.Impl.COLUMN_CURRENT_BYTES);
info.mETag = getString(info.mETag, Constants.ETAG);
info.mMediaScanned = getInt(Constants.MEDIA_SCANNED) == 1;
+ info.mDeleted = getInt(Downloads.Impl.COLUMN_DELETED) == 1;
+ info.mMediaProviderUri = getString(info.mMediaProviderUri,
+ Downloads.Impl.COLUMN_MEDIAPROVIDER_URI);
info.mIsPublicApi = getInt(Downloads.Impl.COLUMN_IS_PUBLIC_API) != 0;
info.mAllowedNetworkTypes = getInt(Downloads.Impl.COLUMN_ALLOWED_NETWORK_TYPES);
info.mAllowRoaming = getInt(Downloads.Impl.COLUMN_ALLOW_ROAMING) != 0;
@@ -231,6 +235,8 @@ public class DownloadInfo {
public long mCurrentBytes;
public String mETag;
public boolean mMediaScanned;
+ public boolean mDeleted;
+ public String mMediaProviderUri;
public boolean mIsPublicApi;
public int mAllowedNetworkTypes;
public boolean mAllowRoaming;
@@ -511,6 +517,8 @@ public class DownloadInfo {
Log.v(Constants.TAG, "CURRENT : " + mCurrentBytes);
Log.v(Constants.TAG, "ETAG : " + mETag);
Log.v(Constants.TAG, "SCANNED : " + mMediaScanned);
+ Log.v(Constants.TAG, "DELETED : " + mDeleted);
+ Log.v(Constants.TAG, "MEDIAPROVIDER_URI : " + mMediaProviderUri);
}
/**