From 08fa91badf0b34323c535dde6f8113e16ae94e21 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Wed, 30 Mar 2016 20:31:05 -0600 Subject: Avoid flashing download notifications. When service starts, use new API to read the current set of notification tags from the system instead of clearing and starting from scratch. Bug: 27634130 Change-Id: I049fe5e445a62a52042d7638c2cb50417977435f --- src/com/android/providers/downloads/DownloadNotifier.java | 15 +++++++++++++-- src/com/android/providers/downloads/DownloadService.java | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'src/com/android/providers/downloads') diff --git a/src/com/android/providers/downloads/DownloadNotifier.java b/src/com/android/providers/downloads/DownloadNotifier.java index 2ff8b634..a03f012c 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()); + } + } + } } /** 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, -- cgit v1.2.3