Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Block notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
mtwalli committed Feb 20, 2023
1 parent b39e815 commit 30f91d6
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
Expand Up @@ -8,6 +8,7 @@ import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import dagger.Reusable
import de.rki.coronawarnapp.R
import de.rki.coronawarnapp.eol.AppEol
import de.rki.coronawarnapp.ui.main.MainActivity
import de.rki.coronawarnapp.util.BuildVersionWrap
import de.rki.coronawarnapp.util.di.AppContext
Expand All @@ -27,6 +28,7 @@ class DigitalCovidCertificateNotifications @Inject constructor(
@AppContext private val context: Context,
private val navDeepLinkBuilderFactory: NavDeepLinkBuilderFactory,
private val notificationManagerCompat: NotificationManagerCompat,
private val appEol: AppEol,
) {

private val channelId = "${context.packageName}.notification.digitalCovidCertificateChannelId"
Expand Down Expand Up @@ -80,6 +82,11 @@ class DigitalCovidCertificateNotifications @Inject constructor(
setupChannel()
}
Timber.i("Showing notification for ID=$notificationId: %s", notification)

if (appEol.eolBlocking) {
Timber.d("EOL -> skip")
return
}
notificationManagerCompat.notify(notificationId, notification)
}
}
Expand Up @@ -14,7 +14,9 @@ import de.rki.coronawarnapp.util.flow.shareLatest
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.runBlocking
import timber.log.Timber
import java.time.ZoneId
import java.time.ZonedDateTime
Expand Down Expand Up @@ -62,6 +64,8 @@ class AppEol @Inject constructor(
}
.shareLatest(scope = appScope)

val eolBlocking get() = runBlocking { isEol.first() }

companion object {
private val TAG = tag<AppEol>()
}
Expand Down
Expand Up @@ -19,6 +19,7 @@ import dagger.Reusable
import de.rki.coronawarnapp.R
import de.rki.coronawarnapp.coronatest.type.BaseCoronaTest
import de.rki.coronawarnapp.coronatest.type.TestIdentifier
import de.rki.coronawarnapp.eol.AppEol
import de.rki.coronawarnapp.notification.NotificationConstants.NOTIFICATION_ID
import de.rki.coronawarnapp.notification.NotificationConstants.POSITIVE_LEGACY_RESULT_NOTIFICATION_ID
import de.rki.coronawarnapp.notification.NotificationConstants.POSITIVE_RESULT_NOTIFICATION_TEST_ID
Expand All @@ -39,7 +40,8 @@ import javax.inject.Inject
@Reusable
class GeneralNotifications @Inject constructor(
@AppContext private val context: Context,
private val notificationManagerCompat: NotificationManagerCompat
private val notificationManagerCompat: NotificationManagerCompat,
private val appEol: AppEol,
) {

private var isNotificationChannelSetup = false
Expand Down Expand Up @@ -159,6 +161,11 @@ class GeneralNotifications @Inject constructor(
setupNotificationChannel()
}
Timber.tag(TAG).i("Showing notification for ID=$notificationId: %s", notification)

if (appEol.eolBlocking) {
Timber.d("EOL -> skip")
return
}
notificationManagerCompat.notify(notificationId, notification)
}

Expand Down
Expand Up @@ -8,6 +8,7 @@ import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import dagger.Reusable
import de.rki.coronawarnapp.R
import de.rki.coronawarnapp.eol.AppEol
import de.rki.coronawarnapp.ui.main.MainActivity
import de.rki.coronawarnapp.util.BuildVersionWrap
import de.rki.coronawarnapp.util.di.AppContext
Expand All @@ -27,6 +28,7 @@ class PresenceTracingNotifications @Inject constructor(
@AppContext private val context: Context,
private val notificationManagerCompat: NotificationManagerCompat,
private val navDeepLinkBuilderFactory: NavDeepLinkBuilderFactory,
private val appEol: AppEol,
) {

private val channelId = "${context.packageName}.notification.presenceTracingChannelId"
Expand Down Expand Up @@ -80,6 +82,11 @@ class PresenceTracingNotifications @Inject constructor(
setupChannel()
}
Timber.i("Showing notification for ID=$notificationId: %s", notification)

if (appEol.eolBlocking) {
Timber.d("EOl -> skip")
return
}
notificationManagerCompat.notify(notificationId, notification)
}
}
Expand Up @@ -317,7 +317,7 @@ class MainActivity : AppCompatActivity(), HasAndroidInjector {
Timber.i("Uri:$uriString")
viewModel.onNavigationUri(uriString)
}

private fun showEnergyOptimizedEnabledForBackground() = displayDialog {
title(R.string.onboarding_energy_optimized_dialog_headline)
message(R.string.onboarding_energy_optimized_dialog_body)
Expand Down
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationManagerCompat
import de.rki.coronawarnapp.covidcertificate.common.notification.DigitalCovidCertificateNotifications
import de.rki.coronawarnapp.eol.AppEol
import de.rki.coronawarnapp.util.BuildVersionWrap
import de.rki.coronawarnapp.util.notifications.NavDeepLinkBuilderFactory
import io.kotest.matchers.shouldBe
Expand All @@ -25,6 +26,7 @@ class DigitalCovidCertificateNotificationsTest : BaseTest() {
@MockK lateinit var context: Context
@MockK lateinit var notificationManager: NotificationManagerCompat
@MockK lateinit var deepLinkBuilderFactory: NavDeepLinkBuilderFactory
@MockK lateinit var appEol: AppEol

private val channelSlot = slot<NotificationChannelCompat>()

Expand All @@ -44,12 +46,14 @@ class DigitalCovidCertificateNotificationsTest : BaseTest() {
every { createNotificationChannel(capture(channelSlot)) } just Runs
every { notify(any(), any()) } just Runs
}
every { appEol.eolBlocking } returns false
}

fun createInstance() = DigitalCovidCertificateNotifications(
context = context,
notificationManagerCompat = notificationManager,
navDeepLinkBuilderFactory = deepLinkBuilderFactory
navDeepLinkBuilderFactory = deepLinkBuilderFactory,
appEol = appEol,
)

@Test
Expand Down

0 comments on commit 30f91d6

Please sign in to comment.