summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVasu Nori <vnori@google.com>2011-01-16 13:20:18 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2011-01-16 13:20:18 -0800
commita13a82c1be907673623268ccce15e9552877fec1 (patch)
tree2d2f38773ce20c676d67738a26fa47dfcf3801b6
parent5e69e69e20a0e0dfcf1ea81c8ab06901f3507ba4 (diff)
parentdbc5c7118e00932182b0f5dfef44d388a174d4d5 (diff)
downloadandroid_packages_providers_DownloadProvider-a13a82c1be907673623268ccce15e9552877fec1.tar.gz
android_packages_providers_DownloadProvider-a13a82c1be907673623268ccce15e9552877fec1.tar.bz2
android_packages_providers_DownloadProvider-a13a82c1be907673623268ccce15e9552877fec1.zip
am dbc5c711: Merge "(GB/GBMR) (do not merge) delete file from disk when deleting from db" into gingerbread
* commit 'dbc5c7118e00932182b0f5dfef44d388a174d4d5': (GB/GBMR) (do not merge) delete file from disk when deleting from db
-rw-r--r--src/com/android/providers/downloads/DownloadService.java34
-rw-r--r--ui/src/com/android/providers/downloads/ui/DownloadList.java9
2 files changed, 27 insertions, 16 deletions
diff --git a/src/com/android/providers/downloads/DownloadService.java b/src/com/android/providers/downloads/DownloadService.java
index 169ef970..95d07d6f 100644
--- a/src/com/android/providers/downloads/DownloadService.java
+++ b/src/com/android/providers/downloads/DownloadService.java
@@ -363,7 +363,7 @@ public class DownloadService extends Service {
if (info.shouldScanFile()) {
// initiate rescan of the file to - which will populate
// mediaProviderUri column in this row
- if (!scanFile(info, true, false)) {
+ if (!scanFile(info, false, true)) {
throw new IllegalStateException("scanFile failed!");
}
} else {
@@ -377,9 +377,9 @@ public class DownloadService extends Service {
// in DownProvider database (the order of deletion is important).
getContentResolver().delete(Uri.parse(info.mMediaProviderUri), null,
null);
- getContentResolver().delete(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI,
- Downloads.Impl._ID + " = ? ",
- new String[]{String.valueOf(info.mId)});
+ // the following deletes the file and then deletes it from downloads db
+ Helpers.deleteFile(getContentResolver(), info.mId, info.mFileName,
+ info.mMimeType);
}
}
}
@@ -580,21 +580,23 @@ public class DownloadService extends Service {
mMediaScannerService.requestScanFile(info.mFileName, info.mMimeType,
new IMediaScannerListener.Stub() {
public void scanCompleted(String path, Uri uri) {
- if (uri != null && updateDatabase) {
- // file is scanned and mediaprovider returned uri. store it in downloads
- // table (i.e., update this downloaded file's row)
+ if (updateDatabase) {
+ // Mark this as 'scanned' in the database
+ // so that it is NOT subject to re-scanning by MediaScanner
+ // next time this database row is encountered
ContentValues values = new ContentValues();
values.put(Constants.MEDIA_SCANNED, 1);
- values.put(Downloads.Impl.COLUMN_MEDIAPROVIDER_URI,
- uri.toString());
+ if (uri != null) {
+ values.put(Downloads.Impl.COLUMN_MEDIAPROVIDER_URI,
+ uri.toString());
+ }
getContentResolver().update(key, values, null, null);
- } else if (uri == null && deleteFile) {
- // callback returned NO uri..that means this file doesn't
- // exist in MediaProvider. but it still needs to be deleted
- // TODO don't scan files that are not scannable by MediaScanner.
- // create a public method in MediaFile.java to return false
- // if the given file's mimetype is not any of the types
- // the mediaprovider is interested in.
+ } else if (deleteFile) {
+ if (uri != null) {
+ // use the Uri returned to delete it from the MediaProvider
+ getContentResolver().delete(uri, null, null);
+ }
+ // delete the file and delete its row from the downloads db
Helpers.deleteFile(resolver, id, path, mimeType);
}
}
diff --git a/ui/src/com/android/providers/downloads/ui/DownloadList.java b/ui/src/com/android/providers/downloads/ui/DownloadList.java
index 0ab3f936..dfd5ffc9 100644
--- a/ui/src/com/android/providers/downloads/ui/DownloadList.java
+++ b/ui/src/com/android/providers/downloads/ui/DownloadList.java
@@ -52,6 +52,7 @@ 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;
@@ -592,6 +593,14 @@ public class DownloadList extends Activity
return;
} else {
getContentResolver().delete(Uri.parse(mediaProviderUri), null, null);
+ // sometimes mediaprovider doesn't delete file from sdcard after deleting it
+ // from its db. delete it now
+ try {
+ File file = new File(path);
+ file.delete();
+ } catch (Exception e) {
+ Log.w(LOG_TAG, "file: '" + path + "' couldn't be deleted", e);
+ }
}
}
}