summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/DownloadProvider.java
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2016-10-14 23:37:22 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-10-14 23:37:22 +0000
commit9dd6606064f19c050ca6b96c845c4cb9a921813b (patch)
treec19b111aef28a52efc0147ef2bcd56dc423cc4b6 /src/com/android/providers/downloads/DownloadProvider.java
parent34632f0d2a92fd7913dfc9b6a75edb34ce2fd41e (diff)
parentf96f51e8d7386341ca209c795cc6621ab0608d45 (diff)
downloadandroid_packages_providers_DownloadProvider-9dd6606064f19c050ca6b96c845c4cb9a921813b.tar.gz
android_packages_providers_DownloadProvider-9dd6606064f19c050ca6b96c845c4cb9a921813b.tar.bz2
android_packages_providers_DownloadProvider-9dd6606064f19c050ca6b96c845c4cb9a921813b.zip
Only send DOWNLOAD_COMPLETE broadcast once.
am: f96f51e8d7 Change-Id: I3a234d02ebf1a2bbdb52af82530d554417849d68
Diffstat (limited to 'src/com/android/providers/downloads/DownloadProvider.java')
-rw-r--r--src/com/android/providers/downloads/DownloadProvider.java35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java
index b2b2c08d..72975582 100644
--- a/src/com/android/providers/downloads/DownloadProvider.java
+++ b/src/com/android/providers/downloads/DownloadProvider.java
@@ -1077,10 +1077,14 @@ public final class DownloadProvider extends ContentProvider {
Helpers.validateSelection(where, sAppReadableColumnsSet);
- SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+ final Context context = getContext();
+ final ContentResolver resolver = context.getContentResolver();
+
+ final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
int count;
boolean updateSchedule = false;
+ boolean isCompleting = false;
ContentValues filteredValues;
if (Binder.getCallingPid() != Process.myPid()) {
@@ -1121,6 +1125,7 @@ public final class DownloadProvider extends ContentProvider {
if (isRestart || isUserBypassingSizeLimit) {
updateSchedule = true;
}
+ isCompleting = status != null && Downloads.Impl.isStatusCompleted(status);
}
int match = sURIMatcher.match(uri);
@@ -1137,14 +1142,20 @@ public final class DownloadProvider extends ContentProvider {
final SqlSelection selection = getWhereClause(uri, where, whereArgs, match);
count = db.update(DB_TABLE, filteredValues, selection.getSelection(),
selection.getParameters());
- if (updateSchedule) {
+ if (updateSchedule || isCompleting) {
final long token = Binder.clearCallingIdentity();
- try {
- try (Cursor cursor = db.query(DB_TABLE, new String[] { _ID },
- selection.getSelection(), selection.getParameters(),
- null, null, null)) {
- while (cursor.moveToNext()) {
- Helpers.scheduleJob(getContext(), cursor.getInt(0));
+ try (Cursor cursor = db.query(DB_TABLE, null, selection.getSelection(),
+ selection.getParameters(), null, null, null)) {
+ final DownloadInfo.Reader reader = new DownloadInfo.Reader(resolver,
+ cursor);
+ final DownloadInfo info = new DownloadInfo(context);
+ while (cursor.moveToNext()) {
+ reader.updateFromDatabase(info);
+ if (updateSchedule) {
+ Helpers.scheduleJob(context, info);
+ }
+ if (isCompleting) {
+ info.sendIntentIfRequested();
}
}
} finally {
@@ -1257,8 +1268,12 @@ public final class DownloadProvider extends ContentProvider {
}
}
- // Tell requester that download is finished
- info.sendIntentIfRequested();
+ // If the download wasn't completed yet, we're
+ // effectively completing it now, and we need to send
+ // any requested broadcasts
+ if (!Downloads.Impl.isStatusCompleted(info.mStatus)) {
+ info.sendIntentIfRequested();
+ }
}
}