@@ -18,6 +18,7 @@ package com.duckduckgo.app.browser.remotemessage
1818
1919import android.content.Context
2020import android.content.Intent
21+ import android.os.SystemClock
2122import androidx.lifecycle.LifecycleOwner
2223import com.duckduckgo.app.cta.db.DismissedCtaDao
2324import com.duckduckgo.app.cta.model.CtaId
@@ -80,25 +81,46 @@ class RemoteMessageModalSurfaceEvaluatorImpl @Inject constructor(
8081 return @withContext
8182 }
8283
83- // TODO ANA: This is now called all the time. Update!
84+ if (! hasMetBackgroundTimeThreshold()) {
85+ return @withContext
86+ }
87+
8488 val message = remoteMessagingRepository.message() ? : return @withContext
89+
8590 if (message.surfaces.contains(Surface .MODAL )) {
8691 val intent = globalActivityStarter.startIntent(
8792 applicationContext,
8893 ModalSurfaceActivityFromMessageId (message.id, message.content.messageType),
8994 ) ? : return @withContext
9095
91- intent.flags = Intent .FLAG_ACTIVITY_NEW_TASK or Intent .FLAG_ACTIVITY_SINGLE_TOP
92- applicationContext.startActivity(intent)
96+ withContext(dispatchers.main()) {
97+ intent.flags = Intent .FLAG_ACTIVITY_NEW_TASK or Intent .FLAG_ACTIVITY_SINGLE_TOP
98+ applicationContext.startActivity(intent)
99+ }
93100 }
94101 }
95102 }
96103
104+ private fun hasMetBackgroundTimeThreshold (): Boolean {
105+ if (! settingsDataStore.hasBackgroundTimestampRecorded()) {
106+ return false
107+ }
108+
109+ val backgroundTimestamp = settingsDataStore.appBackgroundedTimestamp
110+ // Using elapsed real time as this is how it's saved in the data store.
111+ val currentTimestamp = SystemClock .elapsedRealtime()
112+ return (currentTimestamp - backgroundTimestamp) >= BACKGROUND_THRESHOLD_MILLIS
113+ }
114+
97115 private fun isHomeOnboardingComplete (): Boolean {
98116 val noBrowserCtaExperiment = extendedOnboardingFeatureToggles.noBrowserCtas().isEnabled()
99117 return dismissedCtaDao.exists(CtaId .DAX_END ) ||
100118 noBrowserCtaExperiment ||
101119 settingsDataStore.hideTips ||
102120 dismissedCtaDao.exists(CtaId .ADD_WIDGET )
103121 }
122+
123+ companion object {
124+ private const val BACKGROUND_THRESHOLD_MILLIS = 4 * 60 * 60 * 1000L // 4 hours
125+ }
104126}
0 commit comments