Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create the transient channel used for upload notification when notifications are disabled #20168

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
132 changes: 77 additions & 55 deletions WordPress/src/main/java/org/wordpress/android/AppInitializer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down Expand Up @@ -980,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 {
Expand Down
Loading