summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/providers/downloads/DownloadNotifier.java23
-rw-r--r--src/com/android/providers/downloads/DownloadService.java2
-rw-r--r--tests/src/com/android/providers/downloads/StorageTest.java2
3 files changed, 21 insertions, 6 deletions
diff --git a/src/com/android/providers/downloads/DownloadNotifier.java b/src/com/android/providers/downloads/DownloadNotifier.java
index 2ff8b634..5f961eb2 100644
--- a/src/com/android/providers/downloads/DownloadNotifier.java
+++ b/src/com/android/providers/downloads/DownloadNotifier.java
@@ -33,11 +33,14 @@ import android.content.res.Resources;
import android.net.Uri;
import android.os.SystemClock;
import android.provider.Downloads;
+import android.service.notification.StatusBarNotification;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.Log;
import android.util.LongSparseLongArray;
+import com.android.internal.util.ArrayUtils;
+
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
@@ -92,8 +95,16 @@ public class DownloadNotifier {
Context.NOTIFICATION_SERVICE);
}
- public void cancelAll() {
- mNotifManager.cancelAll();
+ public void init() {
+ synchronized (mActiveNotifs) {
+ mActiveNotifs.clear();
+ final StatusBarNotification[] notifs = mNotifManager.getActiveNotifications();
+ if (!ArrayUtils.isEmpty(notifs)) {
+ for (StatusBarNotification notif : notifs) {
+ mActiveNotifs.put(notif.getTag(), notif.getPostTime());
+ }
+ }
+ }
}
/**
@@ -127,7 +138,6 @@ public class DownloadNotifier {
for (DownloadInfo info : cluster) {
wasDeleted = wasDeleted && info.mDeleted;
}
-
return wasDeleted;
}
@@ -144,12 +154,15 @@ public class DownloadNotifier {
}
// Build notification for each cluster
- for (String tag : clustered.keySet()) {
+ Iterator<String> it = clustered.keySet().iterator();
+ while (it.hasNext()) {
+ final String tag = it.next();
final int type = getNotificationTagType(tag);
final Collection<DownloadInfo> cluster = clustered.get(tag);
// If each of the downloads was canceled, don't show notification for the cluster
if (isClusterDeleted(cluster)) {
+ it.remove();
continue;
}
@@ -325,7 +338,7 @@ public class DownloadNotifier {
}
// Remove stale tags that weren't renewed
- final Iterator<String> it = mActiveNotifs.keySet().iterator();
+ it = mActiveNotifs.keySet().iterator();
while (it.hasNext()) {
final String tag = it.next();
if (!clustered.containsKey(tag)) {
diff --git a/src/com/android/providers/downloads/DownloadService.java b/src/com/android/providers/downloads/DownloadService.java
index 7845ce0e..7d4392e8 100644
--- a/src/com/android/providers/downloads/DownloadService.java
+++ b/src/com/android/providers/downloads/DownloadService.java
@@ -211,7 +211,7 @@ public class DownloadService extends Service {
mScanner = new DownloadScanner(this);
mNotifier = new DownloadNotifier(this);
- mNotifier.cancelAll();
+ mNotifier.init();
mObserver = new DownloadManagerContentObserver();
getContentResolver().registerContentObserver(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI,
diff --git a/tests/src/com/android/providers/downloads/StorageTest.java b/tests/src/com/android/providers/downloads/StorageTest.java
index 8ba3cbce..95bd3676 100644
--- a/tests/src/com/android/providers/downloads/StorageTest.java
+++ b/tests/src/com/android/providers/downloads/StorageTest.java
@@ -32,6 +32,7 @@ import android.system.ErrnoException;
import android.system.Os;
import android.system.StructStatVfs;
import android.test.MoreAsserts;
+import android.test.suitebuilder.annotation.MediumTest;
import android.util.Log;
import com.android.providers.downloads.StorageUtils.ObserverLatch;
@@ -47,6 +48,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
+@MediumTest
public class StorageTest extends AbstractPublicApiTest {
private static final String TAG = "StorageTest";