From 414ddf809666941a0ad68b415bd83f523b4cfb5d Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Fri, 9 Feb 2024 15:22:21 +0200 Subject: [PATCH 1/3] Allow defining which notification channels to create on app initialisation --- .../org/wordpress/android/AppInitializer.kt | 119 ++++++++++-------- 1 file changed, 66 insertions(+), 53 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/AppInitializer.kt b/WordPress/src/main/java/org/wordpress/android/AppInitializer.kt index cd4fba1f5bd5..8d7a32fcd36b 100644 --- a/WordPress/src/main/java/org/wordpress/android/AppInitializer.kt +++ b/WordPress/src/main/java/org/wordpress/android/AppInitializer.kt @@ -464,65 +464,78 @@ class AppInitializer @Inject constructor( credentialsClient.connect() } - private fun createNotificationChannelsOnSdk26() { + private fun createNotificationChannelsOnSdk26( + normal: Boolean = true, + important: Boolean = true, + reminder: Boolean = true, + transient: Boolean = true, + weeklyRoundup: Boolean = true + ) { // create Notification channels introduced in Android Oreo if (Build.VERSION.SDK_INT >= VERSION_CODES.O) { - // Create the NORMAL channel (used for likes, comments, replies, etc.) - val normalChannel = NotificationChannel( - application.getString(R.string.notification_channel_normal_id), - application.getString(R.string.notification_channel_general_title), - NotificationManager.IMPORTANCE_DEFAULT - ) - // Register the channel with the system; you can't change the importance - // or other notification behaviors after this val notificationManager = application.getSystemService( Context.NOTIFICATION_SERVICE ) as NotificationManager - notificationManager.createNotificationChannel(normalChannel) + if (normal) { + // Create the NORMAL channel (used for likes, comments, replies, etc.) + val normalChannel = NotificationChannel( + application.getString(R.string.notification_channel_normal_id), + application.getString(R.string.notification_channel_general_title), + NotificationManager.IMPORTANCE_DEFAULT + ) + // Register the channel with the system; you can't change the importance + // or other notification behaviors after this - // Create the IMPORTANT channel (used for 2fa auth, for example) - val importantChannel = NotificationChannel( - application.getString(R.string.notification_channel_important_id), - application.getString(R.string.notification_channel_important_title), - NotificationManager.IMPORTANCE_HIGH - ) - // Register the channel with the system; you can't change the importance - // or other notification behaviors after this - notificationManager.createNotificationChannel(importantChannel) - - // Create the REMINDER channel (used for various reminders, like Quick Start, etc.) - val reminderChannel = NotificationChannel( - application.getString(R.string.notification_channel_reminder_id), - application.getString(R.string.notification_channel_reminder_title), - NotificationManager.IMPORTANCE_LOW - ) - // Register the channel with the system; you can't change the importance - // or other notification behaviors after this - notificationManager.createNotificationChannel(reminderChannel) - - // Create the TRANSIENT channel (used for short-lived notifications such as processing a Like/Approve, - // or media upload) - val transientChannel = NotificationChannel( - application.getString(R.string.notification_channel_transient_id), - application.getString(R.string.notification_channel_transient_title), - NotificationManager.IMPORTANCE_DEFAULT - ) - transientChannel.setSound(null, null) - transientChannel.enableVibration(false) - transientChannel.enableLights(false) - // Register the channel with the system; you can't change the importance - // or other notification behaviors after this - notificationManager.createNotificationChannel(transientChannel) - - // Create the WEEKLY ROUNDUP channel (used for weekly roundup notification containing weekly stats) - val weeklyRoundupChannel = NotificationChannel( - application.getString(R.string.notification_channel_weekly_roundup_id), - application.getString(R.string.notification_channel_weekly_roundup_title), - NotificationManager.IMPORTANCE_LOW - ) - // Register the channel with the system; you can't change the importance or other notification behaviors - // after this - notificationManager.createNotificationChannel(weeklyRoundupChannel) + notificationManager.createNotificationChannel(normalChannel) + } + if (important) { + // Create the IMPORTANT channel (used for 2fa auth, for example) + val importantChannel = NotificationChannel( + application.getString(R.string.notification_channel_important_id), + application.getString(R.string.notification_channel_important_title), + NotificationManager.IMPORTANCE_HIGH + ) + // Register the channel with the system; you can't change the importance + // or other notification behaviors after this + notificationManager.createNotificationChannel(importantChannel) + } + if (reminder) { + // Create the REMINDER channel (used for various reminders, like Quick Start, etc.) + val reminderChannel = NotificationChannel( + application.getString(R.string.notification_channel_reminder_id), + application.getString(R.string.notification_channel_reminder_title), + NotificationManager.IMPORTANCE_LOW + ) + // Register the channel with the system; you can't change the importance + // or other notification behaviors after this + notificationManager.createNotificationChannel(reminderChannel) + } + if (transient) { + // Create the TRANSIENT channel (used for short-lived notifications such as processing a Like/Approve, + // or media upload) + val transientChannel = NotificationChannel( + application.getString(R.string.notification_channel_transient_id), + application.getString(R.string.notification_channel_transient_title), + NotificationManager.IMPORTANCE_DEFAULT + ) + transientChannel.setSound(null, null) + transientChannel.enableVibration(false) + transientChannel.enableLights(false) + // Register the channel with the system; you can't change the importance + // or other notification behaviors after this + notificationManager.createNotificationChannel(transientChannel) + } + if (weeklyRoundup) { + // Create the WEEKLY ROUNDUP channel (used for weekly roundup notification containing weekly stats) + val weeklyRoundupChannel = NotificationChannel( + application.getString(R.string.notification_channel_weekly_roundup_id), + application.getString(R.string.notification_channel_weekly_roundup_title), + NotificationManager.IMPORTANCE_LOW + ) + // Register the channel with the system; you can't change the importance or other notification behaviors + // after this + notificationManager.createNotificationChannel(weeklyRoundupChannel) + } } } From 80790f9feb025335c97108b99fcd6c7772280c78 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Fri, 9 Feb 2024 15:23:17 +0200 Subject: [PATCH 2/3] Only create the transient channel when notifications are disabled to prevent upload notification crash --- .../java/org/wordpress/android/AppInitializer.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/AppInitializer.kt b/WordPress/src/main/java/org/wordpress/android/AppInitializer.kt index 8d7a32fcd36b..02eb23ed98bc 100644 --- a/WordPress/src/main/java/org/wordpress/android/AppInitializer.kt +++ b/WordPress/src/main/java/org/wordpress/android/AppInitializer.kt @@ -993,10 +993,19 @@ class AppInitializer @Inject constructor( } private fun updateNotificationSettings() { - if(!jetpackFeatureRemovalPhaseHelper.shouldShowNotifications()) + if (!jetpackFeatureRemovalPhaseHelper.shouldShowNotifications()) { NotificationsUtils.cancelAllNotifications(application) - else + // Only create the transient notification channel to handle upload notifications + createNotificationChannelsOnSdk26( + normal = false, + important = false, + reminder = false, + transient = true, + weeklyRoundup = false, + ) + } else { createNotificationChannelsOnSdk26() + } } companion object { From 07d89b5ca50cc4c311a02582312a3952f9bb5945 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Fri, 9 Feb 2024 16:01:10 +0200 Subject: [PATCH 3/3] Adds release note --- RELEASE-NOTES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index ba0924f0ba7a..43636fbd07d7 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -11,6 +11,7 @@ * [**] Prevent images from temporarily disappearing when uploading media [https://github.com/WordPress/gutenberg/pull/57869] * [***] [Jetpack-only] Reader: introduced new UI/UX for content navigation and filtering [https://github.com/wordpress-mobile/WordPress-Android/pull/19978] * [**] Prevents crashes when the webview state is too big [https://github.com/wordpress-mobile/WordPress-Android/pull/20139] +* [*] [WordPress-only] Prevents a crash occurring when uploading videos under certain conditions [https://github.com/wordpress-mobile/WordPress-Android/pull/20168] 24.1 -----