From be2eaa55bb3dca3422da25fe907b50a4ad70df17 Mon Sep 17 00:00:00 2001 From: Vasu Nori Date: Thu, 14 Oct 2010 22:57:46 -0700 Subject: bug:3099994 NPE in DownloadManager when deleting non-media file DownloadService always scans files and assumes MediaProvider returns a valid Uri. But MediaProvider returns null for return param 'uri' if the file is not audio/video/image etc media type file (for example, pdf) Change-Id: If32bd1895b00b5406973a5e240ad3558d46f9f4a --- src/com/android/providers/downloads/Helpers.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/com/android/providers/downloads/Helpers.java') diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java index cbcae5f4..855cba28 100644 --- a/src/com/android/providers/downloads/Helpers.java +++ b/src/com/android/providers/downloads/Helpers.java @@ -16,6 +16,7 @@ package com.android.providers.downloads; +import android.content.ContentResolver; import android.content.ContentUris; import android.content.Context; import android.content.Intent; @@ -799,4 +800,19 @@ public class Helpers { (c >= '0' && c <= '9'); } } + + /** + * Delete the given file from device + * and delete its row from the downloads database. + */ + /* package */ static void deleteFile(ContentResolver resolver, long id, String path, String mimeType) { + try { + File file = new File(path); + file.delete(); + } catch (Exception e) { + Log.w(Constants.TAG, "file: '" + path + "' couldn't be deleted", e); + } + resolver.delete(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, Downloads.Impl._ID + " = ? ", + new String[]{String.valueOf(id)}); + } } -- cgit v1.2.3