From fb2b4209cf2693f15b5a5a07ecae802d83a0b8f6 Mon Sep 17 00:00:00 2001 From: akwizgran Date: Wed, 10 Feb 2021 11:46:41 +0000 Subject: [PATCH] Use IMPORTANCE_LOW for ongoing notification, don't show a badge. --- .../org/briarproject/briar/android/BriarService.java | 11 +++++++++-- .../briar/api/android/AndroidNotificationManager.java | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/briar-android/src/main/java/org/briarproject/briar/android/BriarService.java b/briar-android/src/main/java/org/briarproject/briar/android/BriarService.java index a4f4d0b0e..6bfbb2663 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/BriarService.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/BriarService.java @@ -37,7 +37,7 @@ import javax.inject.Inject; import androidx.core.app.NotificationCompat; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; -import static android.app.NotificationManager.IMPORTANCE_NONE; +import static android.app.NotificationManager.IMPORTANCE_LOW; import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; import static android.content.Intent.ACTION_SHUTDOWN; import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK; @@ -56,6 +56,7 @@ import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY; import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_CHANNEL_ID; import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_NOTIFICATION_ID; import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_CHANNEL_ID; +import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_CHANNEL_OLD_ID; import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_NOTIFICATION_ID; import static org.briarproject.briar.api.android.LockManager.ACTION_LOCK; @@ -120,11 +121,17 @@ public class BriarService extends Service { if (SDK_INT >= 26) { NotificationManager nm = (NotificationManager) requireNonNull(getSystemService(NOTIFICATION_SERVICE)); + // Delete the old notification channel, which had + // IMPORTANCE_NONE and showed a badge + nm.deleteNotificationChannel(ONGOING_CHANNEL_OLD_ID); + // Use IMPORTANCE_LOW so the system doesn't show its own + // notification on API 26-27 NotificationChannel ongoingChannel = new NotificationChannel( ONGOING_CHANNEL_ID, getString(R.string.ongoing_notification_title), - IMPORTANCE_NONE); + IMPORTANCE_LOW); ongoingChannel.setLockscreenVisibility(VISIBILITY_SECRET); + ongoingChannel.setShowBadge(false); nm.createNotificationChannel(ongoingChannel); NotificationChannel failureChannel = new NotificationChannel( FAILURE_CHANNEL_ID, diff --git a/briar-android/src/main/java/org/briarproject/briar/api/android/AndroidNotificationManager.java b/briar-android/src/main/java/org/briarproject/briar/api/android/AndroidNotificationManager.java index 9e69808d5..6a3a5cbb2 100644 --- a/briar-android/src/main/java/org/briarproject/briar/api/android/AndroidNotificationManager.java +++ b/briar-android/src/main/java/org/briarproject/briar/api/android/AndroidNotificationManager.java @@ -39,7 +39,8 @@ public interface AndroidNotificationManager { String BLOG_CHANNEL_ID = "blogs"; // Channels are sorted by channel ID in the Settings app, so use IDs // that will sort below the main channels such as contacts - String ONGOING_CHANNEL_ID = "zForegroundService"; + String ONGOING_CHANNEL_OLD_ID = "zForegroundService"; + String ONGOING_CHANNEL_ID = "zForegroundService2"; String FAILURE_CHANNEL_ID = "zStartupFailure"; String REMINDER_CHANNEL_ID = "zSignInReminder";