Commit 31a0c2fb authored by Sebastian Kaspari's avatar Sebastian Kaspari
Browse files

Closes #3780: Re-create media channel with lower importance.

parent 5b348f86
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@ import mozilla.components.feature.media.R
import mozilla.components.feature.media.service.MediaService
import mozilla.components.feature.media.state.MediaState

private const val NOTIFICATION_CHANNEL_ID = "Media"

/**
 * Helper to display a notification for web content playing media.
 */
@@ -27,20 +25,23 @@ internal class MediaNotification(
    /**
     * Creates a new [Notification] for the given [state].
     */
    @Suppress("LongMethod")
    fun create(state: MediaState, mediaSession: MediaSessionCompat): Notification {
        MediaNotificationChannel.ensureChannelExists(context)
        val channel = MediaNotificationChannel.ensureChannelExists(context)

        val intent = context.packageManager.getLaunchIntentForPackage(context.packageName)
        val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0)

        val data = state.toNotificationData(context)

        val builder = NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
        val builder = NotificationCompat.Builder(context, channel)
            .setSmallIcon(data.icon)
            .setContentTitle(data.title)
            .setContentText(data.description)
            .setLargeIcon(data.largeIcon)
            .addAction(data.action)
            .setPriority(NotificationCompat.PRIORITY_LOW)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setStyle(androidx.media.app.NotificationCompat.MediaStyle()
                .setMediaSession(mediaSession.sessionToken)
                .setShowActionsInCompactView(0))
+9 −2
Original line number Diff line number Diff line
@@ -8,9 +8,11 @@ import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import androidx.core.app.NotificationCompat
import mozilla.components.feature.media.R

private const val NOTIFICATION_CHANNEL_ID = "Media"
private const val NOTIFICATION_CHANNEL_ID = "mozac.feature.media.generic"
private const val LEGACY_NOTIFICATION_CHANNEL_ID = "Media"

internal object MediaNotificationChannel {
    /**
@@ -27,10 +29,15 @@ internal object MediaNotificationChannel {
            val channel = NotificationChannel(
                NOTIFICATION_CHANNEL_ID,
                context.getString(R.string.mozac_feature_media_notification_channel),
                NotificationManager.IMPORTANCE_DEFAULT
                NotificationManager.IMPORTANCE_LOW
            )
            channel.setShowBadge(false)
            channel.lockscreenVisibility = NotificationCompat.VISIBILITY_PUBLIC

            notificationManager.createNotificationChannel(channel)

            // We can't just change a channel. So we had to re-create the channel with a new name.
            notificationManager.deleteNotificationChannel(LEGACY_NOTIFICATION_CHANNEL_ID)
        }

        return NOTIFICATION_CHANNEL_ID