diff options
author | Vasu Nori <vnori@google.com> | 2010-10-26 16:37:08 -0700 |
---|---|---|
committer | Vasu Nori <vnori@google.com> | 2010-10-26 23:49:28 -0700 |
commit | fdbeea8d2eb7566bbd556d42960995cfc695c983 (patch) | |
tree | 977f23c3c8adb6d47a0e6cacd85858b8a883bf52 /src/com | |
parent | 399fad44a108741b40de57a0d504b87cbc618b01 (diff) | |
download | android_packages_providers_DownloadProvider-fdbeea8d2eb7566bbd556d42960995cfc695c983.tar.gz android_packages_providers_DownloadProvider-fdbeea8d2eb7566bbd556d42960995cfc695c983.tar.bz2 android_packages_providers_DownloadProvider-fdbeea8d2eb7566bbd556d42960995cfc695c983.zip |
reduce number of times mediascanner is invoked by downloadservice
this is one of the 2 bugs mentioned in bug:3129943
sometimes MediaProvider returns null for returned param Uri.
in such cases, mark the file as 'scanned' in the downloads db
so that it is NOT scanned again later by DownlaodService.
depends on Change-Id: I92514e1a11f5119229c0c7292e410e352a9dbcdd
Change-Id: Ie9d839581f656c929a77bd5f244ad6b2fb1585e6
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/providers/downloads/DownloadService.java | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/com/android/providers/downloads/DownloadService.java b/src/com/android/providers/downloads/DownloadService.java index 2596fae3..d5dff564 100644 --- a/src/com/android/providers/downloads/DownloadService.java +++ b/src/com/android/providers/downloads/DownloadService.java @@ -367,7 +367,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 { @@ -584,21 +584,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 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); } } |