diff options
author | Vasu Nori <vnori@google.com> | 2010-10-27 14:55:07 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-10-27 14:55:07 -0700 |
commit | fdb8fb155914bba44351b41911c54d34d8cdfaae (patch) | |
tree | c640083ca7b8cc3ac389cdca0792bb43b32f7064 /src | |
parent | ff1e6cd67948876caf14da45bd6e493297b6b4a7 (diff) | |
parent | fdbeea8d2eb7566bbd556d42960995cfc695c983 (diff) | |
download | android_packages_providers_DownloadProvider-fdb8fb155914bba44351b41911c54d34d8cdfaae.tar.gz android_packages_providers_DownloadProvider-fdb8fb155914bba44351b41911c54d34d8cdfaae.tar.bz2 android_packages_providers_DownloadProvider-fdb8fb155914bba44351b41911c54d34d8cdfaae.zip |
Merge "reduce number of times mediascanner is invoked by downloadservice"
Diffstat (limited to 'src')
-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); } } |