Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd88ebbe authored by Guillaume Jacquart's avatar Guillaume Jacquart
Browse files

Merge branch '3720-srv_notification_shows_on_reboot' into 'main'

fix:3720:service notification re-show on reboot.

See merge request !30
parents 3e9351d9 21ab5a47
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -257,8 +257,8 @@ class SubscriberService : Service() {
                it.setShowBadge(false) // Don't show long-press badge
                it
            }
            notificationManager.createNotificationChannel(channel)
            NotificationChannelHider(this, GlobalScope).hideChannel(NOTIFICATION_CHANNEL_ID)

            NotificationChannelHider(this, GlobalScope).createAndHideChannel(channel)
            return notificationManager
        }
        return null
+11 −4
Original line number Diff line number Diff line
@@ -36,7 +36,17 @@ class NotificationChannelHider(
        private const val UPDATE_CHANNEL_DELAY = 30000L
    }

    fun hideChannel(channelId: String) {
    private val notificationManager: NotificationManager by lazy {
        context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
    }

    fun createAndHideChannel(notificationsChannel: NotificationChannel) {
        // Set blockable before create the channel, otherwise it will re-show on each create call.
        NotificationChannelHiddenMethods.setBlockable(notificationsChannel, true)

        notificationManager.createNotificationChannel(notificationsChannel)

        val channelId = notificationsChannel.id
        // Hide works if updating importance is called after the notification is
        // used as the ForegroundService notification. This may take a few seconds sometimes, so
        // we wait a few seconds.
@@ -47,9 +57,6 @@ class NotificationChannelHider(
    }

    private fun setImportanceToNone(channelId: String) {
        val notificationManager: NotificationManager by lazy {
            context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        }
        val notificationsChannel: NotificationChannel = notificationManager.getNotificationChannel(channelId)
        NotificationChannelHiddenMethods.setBlockable(notificationsChannel, true)
        notificationsChannel.importance = NotificationManager.IMPORTANCE_NONE