Bug 1476966 Constant notification ringing when downloading a file r?
Created specific notification channel dedicated to download progress notifications.
MozReview-Commit-ID: 88vsQiI2L2
***
--- a/mobile/android/base/java/org/mozilla/gecko/notifications/NotificationClient.java
+++ b/mobile/android/base/java/org/mozilla/gecko/notifications/NotificationClient.java
@@ -229,21 +229,21 @@ public final class NotificationClient im
return;
}
final Notification.Builder notificationBuilder = new Notification.Builder(mContext)
.setContentText(alertText)
.setSmallIcon(notification.icon)
.setWhen(notification.when)
.setContentIntent(notification.contentIntent)
+ .setOnlyAlertOnce(true)
.setProgress((int) progressMax, (int) progress, false);
if (!AppConstants.Versions.preO) {
- notificationBuilder.setChannelId(NotificationHelper.getInstance(mContext)
- .getNotificationChannel(NotificationHelper.Channel.DEFAULT).getId());
+ notificationBuilder.setChannelId(notification.getChannelId());
}
notification = notificationBuilder.build();
add(name, notification);
}
/* package */ synchronized Notification onNotificationClose(final String name) {
mNotificationManager.cancel(name, 0);
--- a/mobile/android/base/java/org/mozilla/gecko/notifications/NotificationHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/notifications/NotificationHelper.java
@@ -21,16 +21,17 @@ import android.os.StrictMode;
import android.support.v4.app.NotificationCompat;
import android.support.v4.util.SimpleArrayMap;
import android.util.Log;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoActivityMonitor;
import org.mozilla.gecko.GeckoAppShell;
+import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.R;
import org.mozilla.gecko.mozglue.SafeIntent;
import org.mozilla.gecko.util.BitmapUtils;
import org.mozilla.gecko.util.BundleEventListener;
import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.GeckoBundle;
import org.mozilla.gecko.util.ThreadUtils;
@@ -87,25 +88,32 @@ public final class NotificationHelper im
public enum Channel {
/**
* Default notification channel.
*/
DEFAULT,
/**
* Mozilla Location Services notification channel.
*/
- MLS
+ MLS,
+ /**
+ * Mozilla Location Services notification channel.
+ */
+ DOWNLOAD
}
private final Map<Channel, String> mDefinedNotificationChannels = new HashMap<Channel, String>() {{
final String DEFAULT_CHANNEL_TAG = "default-notification-channel";
put(Channel.DEFAULT, DEFAULT_CHANNEL_TAG);
final String MLS_CHANNEL_TAG = "mls-notification-channel";
put(Channel.MLS, MLS_CHANNEL_TAG);
+
+ final String DOWNLOAD_NOTIFICATION_TAG = "download-notification-channel";
+ put(Channel.DOWNLOAD, DOWNLOAD_NOTIFICATION_TAG);
}};
// Holds a list of notifications that should be cleared if the Fennec Activity is shut down.
// Will not include ongoing or persistent notifications that are tied to Gecko's lifecycle.
private SimpleArrayMap<String, GeckoBundle> mClearableNotifications;
private boolean mInitialized;
private static NotificationHelper sInstance;
@@ -157,16 +165,22 @@ public final class NotificationHelper im
if (channel == null) {
switch (definedChannel) {
case MLS: {
channel = new NotificationChannel(mDefinedNotificationChannels.get(definedChannel),
mContext.getString(R.string.mls_notification_channel), NotificationManager.IMPORTANCE_LOW);
}
break;
+ case DOWNLOAD: {
+ channel = new NotificationChannel(mDefinedNotificationChannels.get(definedChannel),
+ mContext.getString(R.string.download_notification_channel), NotificationManager.IMPORTANCE_LOW);
+ }
+ break;
+
case DEFAULT:
default: {
channel = new NotificationChannel(mDefinedNotificationChannels.get(definedChannel),
mContext.getString(R.string.default_notification_channel), NotificationManager.IMPORTANCE_HIGH);
}
break;
}
@@ -314,20 +328,16 @@ public final class NotificationHelper im
final Uri imageUri = Uri.parse(message.getString(SMALLICON_ATTR, ""));
builder.setSmallIcon(BitmapUtils.getResource(mContext, imageUri));
final int[] light = message.getIntArray(LIGHT_ATTR);
if (light != null && light.length == 3) {
builder.setLights(light[0], light[1], light[2]);
}
- if (!AppConstants.Versions.preO) {
- builder.setChannelId(getNotificationChannel(Channel.DEFAULT).getId());
- }
-
final boolean ongoing = message.getBoolean(ONGOING_ATTR);
builder.setOngoing(ongoing);
if (message.containsKey(WHEN_ATTR)) {
final long when = (long) message.getDouble(WHEN_ATTR);
builder.setWhen(when);
}
@@ -337,16 +347,25 @@ public final class NotificationHelper im
}
if (message.containsKey(LARGE_ICON_ATTR)) {
final Bitmap b = BitmapUtils.getBitmapFromDataURI(
message.getString(LARGE_ICON_ATTR, ""));
builder.setLargeIcon(b);
}
+ if (!AppConstants.Versions.preO) {
+ if (message.getString(HANDLER_ATTR).equals("downloads")) {
+ builder.setChannelId(getNotificationChannel(Channel.DOWNLOAD).getId());
+ builder.setOnlyAlertOnce(true);
+ } else {
+ builder.setChannelId(getNotificationChannel(Channel.DEFAULT).getId());
+ }
+ }
+
if (message.containsKey(PROGRESS_VALUE_ATTR) &&
message.containsKey(PROGRESS_MAX_ATTR) &&
message.containsKey(PROGRESS_INDETERMINATE_ATTR)) {
final int progress = message.getInt(PROGRESS_VALUE_ATTR);
final int progressMax = message.getInt(PROGRESS_MAX_ATTR);
final boolean progressIndeterminate = message.getBoolean(PROGRESS_INDETERMINATE_ATTR);
builder.setProgress(progressMax, progress, progressIndeterminate);
}
--- a/mobile/android/base/locales/en-US/android_strings.dtd
+++ b/mobile/android/base/locales/en-US/android_strings.dtd
@@ -891,9 +891,10 @@ See also https://bug1409261.bmoattachmen
Picture-in-picture mini window -->
<!ENTITY pip_play_button_title "Play">
<!ENTITY pip_play_button_description "Resume playing">
<!ENTITY pip_pause_button_title "Pause">
<!ENTITY pip_pause_button_description "Pause playing">
<!-- Notification channels names -->
<!ENTITY default_notification_channel "&brandShortName;">
-<!ENTITY mls_notification_channel "&vendorShortName; Location Service">
\ No newline at end of file
+<!ENTITY mls_notification_channel "&vendorShortName; Location Service">
+<!ENTITY download_notification_channel "Downloads">
\ No newline at end of file
--- a/mobile/android/base/strings.xml.in
+++ b/mobile/android/base/strings.xml.in
@@ -645,9 +645,10 @@
<string name="pip_play_button_title">&pip_play_button_title;</string>
<string name="pip_play_button_description">&pip_play_button_description;</string>
<string name="pip_pause_button_title">&pip_pause_button_title;</string>
<string name="pip_pause_button_description">&pip_pause_button_description;</string>
<string name="default_notification_channel">&default_notification_channel;</string>
<string name="mls_notification_channel">&mls_notification_channel;</string>
+ <string name="download_notification_channel">&download_notification_channel;</string>
</resources>