[fenix] Bug 1810114 - Part 2: Move marketingNotificationAllowed metric to FenixApplication

pull/600/head
rahulsainani 1 year ago committed by mergify[bot]
parent 2c8869f666
commit 115422015e

@ -61,6 +61,7 @@ import mozilla.components.support.webextensions.WebExtensionSupport
import org.mozilla.fenix.GleanMetrics.Addons
import org.mozilla.fenix.GleanMetrics.AndroidAutofill
import org.mozilla.fenix.GleanMetrics.CustomizeHome
import org.mozilla.fenix.GleanMetrics.Events.marketingNotificationAllowed
import org.mozilla.fenix.GleanMetrics.GleanBuildInfo
import org.mozilla.fenix.GleanMetrics.Metrics
import org.mozilla.fenix.GleanMetrics.PerfStartup
@ -73,13 +74,16 @@ import org.mozilla.fenix.components.appstate.AppAction
import org.mozilla.fenix.components.metrics.MetricServiceType
import org.mozilla.fenix.components.metrics.MozillaProductDetector
import org.mozilla.fenix.components.toolbar.ToolbarPosition
import org.mozilla.fenix.ext.areNotificationsEnabledSafe
import org.mozilla.fenix.ext.containsQueryParameters
import org.mozilla.fenix.ext.getCustomGleanServerUrlIfAvailable
import org.mozilla.fenix.ext.isCustomEngine
import org.mozilla.fenix.ext.isKnownSearchDomain
import org.mozilla.fenix.ext.isNotificationChannelEnabled
import org.mozilla.fenix.ext.setCustomEndpointIfAvailable
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.nimbus.FxNimbus
import org.mozilla.fenix.onboarding.MARKETING_CHANNEL_ID
import org.mozilla.fenix.perf.MarkersActivityLifecycleCallbacks
import org.mozilla.fenix.perf.ProfilerMarkerFactProcessor
import org.mozilla.fenix.perf.StartupTimeline
@ -723,14 +727,11 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
defaultWallpaper.set(isDefaultTheCurrentWallpaper)
@Suppress("TooGenericExceptionCaught")
try {
notificationsAllowed.set(
NotificationManagerCompat.from(applicationContext).areNotificationsEnabled(),
)
} catch (e: Exception) {
Logger.warn("Failed to check if notifications are enabled", e)
}
val notificationManagerCompat = NotificationManagerCompat.from(applicationContext)
notificationsAllowed.set(notificationManagerCompat.areNotificationsEnabledSafe())
marketingNotificationAllowed.set(
notificationManagerCompat.isNotificationChannelEnabled(MARKETING_CHANNEL_ID),
)
}
with(AndroidAutofill) {

@ -8,14 +8,11 @@ import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import androidx.core.app.NotificationManagerCompat
import org.mozilla.fenix.GleanMetrics.Events.marketingNotificationAllowed
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.areNotificationsEnabledSafe
// Channel ID was not updated when it was renamed to marketing. Thus, we'll have to continue
// to use this ID as the marketing channel ID
private const val MARKETING_CHANNEL_ID = "org.mozilla.fenix.default.browser.channel"
const val MARKETING_CHANNEL_ID = "org.mozilla.fenix.default.browser.channel"
// For notification that uses the marketing notification channel, IDs should be unique.
const val DEFAULT_BROWSER_NOTIFICATION_ID = 1
@ -27,7 +24,6 @@ const val RE_ENGAGEMENT_NOTIFICATION_ID = 2
* Returns the channel id to be used for notifications.
*/
fun ensureMarketingChannelExists(context: Context): String {
var channelEnabled = true
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val notificationManager: NotificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
@ -44,13 +40,7 @@ fun ensureMarketingChannelExists(context: Context): String {
notificationManager.createNotificationChannel(channel)
}
channelEnabled = channel.importance != NotificationManager.IMPORTANCE_NONE
}
val notificationsEnabled = NotificationManagerCompat.from(context).areNotificationsEnabledSafe()
marketingNotificationAllowed.set(notificationsEnabled && channelEnabled)
return MARKETING_CHANNEL_ID
}

Loading…
Cancel
Save