Skip to content

Commit

Permalink
Fix AppCoroutineScope scoping (#3499)
Browse files Browse the repository at this point in the history
  • Loading branch information
aitorvs authored Sep 11, 2023
1 parent 0f29dae commit ec0fd09
Show file tree
Hide file tree
Showing 22 changed files with 44 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.duckduckgo.app.anr

import com.duckduckgo.anrs.api.CrashLogger
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.app.statistics.pixels.Pixel
import com.duckduckgo.di.scopes.AppScope
Expand All @@ -39,7 +40,7 @@ class GlobalUncaughtExceptionHandler @Inject constructor(
@InternalApi private val originalHandler: Thread.UncaughtExceptionHandler,
private val crashLogger: CrashLogger,
private val dispatcherProvider: DispatcherProvider,
private val appCoroutineScope: CoroutineScope,
@AppCoroutineScope private val appCoroutineScope: CoroutineScope,
) : Thread.UncaughtExceptionHandler {

override fun uncaughtException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.duckduckgo.mobile.android.app.tracking

import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.mobile.android.vpn.AppTpVpnFeature
Expand All @@ -33,7 +34,7 @@ import kotlinx.coroutines.withContext
class RealAppTrackingProtection @Inject constructor(
private val vpnStore: VpnStore,
private val vpnFeaturesRegistry: VpnFeaturesRegistry,
private val coroutineScope: CoroutineScope,
@AppCoroutineScope private val coroutineScope: CoroutineScope,
private val dispatcherProvider: DispatcherProvider,
) : AppTrackingProtection {
override suspend fun isOnboarded(): Boolean = withContext(dispatcherProvider.io()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import android.content.Intent
import android.content.IntentFilter
import androidx.core.app.NotificationManagerCompat
import androidx.lifecycle.LifecycleOwner
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.app.lifecycle.MainProcessLifecycleObserver
import com.duckduckgo.appbuildconfig.api.AppBuildConfig
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.mobile.android.vpn.ui.notification.*
import com.duckduckgo.vpn.di.VpnCoroutineScope
import com.squareup.anvil.annotations.ContributesMultibinding
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -72,7 +72,7 @@ class DeviceShieldNotificationsDebugReceiverRegister @Inject constructor(
private val weeklyNotificationPressedHandler: WeeklyNotificationPressedHandler,
private val dailyNotificationPressedHandler: DailyNotificationPressedHandler,
private val deviceShieldAlertNotificationBuilder: DeviceShieldAlertNotificationBuilder,
@VpnCoroutineScope private val vpnCoroutineScope: CoroutineScope,
@AppCoroutineScope private val coroutineScope: CoroutineScope,
private val dispatchers: DispatcherProvider,
) : MainProcessLifecycleObserver {

Expand All @@ -88,7 +88,7 @@ class DeviceShieldNotificationsDebugReceiverRegister @Inject constructor(
val weekly = kotlin.runCatching { intent.getStringExtra("weekly")?.toInt() }.getOrNull()
val daily = kotlin.runCatching { intent.getStringExtra("daily")?.toInt() }.getOrNull()

vpnCoroutineScope.launch(dispatchers.io()) {
coroutineScope.launch(dispatchers.io()) {
val notification = if (weekly != null) {
logcat { "Debug - Sending weekly notification $weekly" }
weeklyNotificationPressedHandler.notificationVariant = weekly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.duckduckgo.mobile.android.vpn.pixels

import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.app.statistics.api.RefreshRetentionAtbPlugin
import com.duckduckgo.di.scopes.AppScope
Expand All @@ -30,7 +31,7 @@ import kotlinx.coroutines.launch
class DeviceShieldRetentionPixelSender @Inject constructor(
private val deviceShieldPixels: DeviceShieldPixels,
private val vpnFeaturesRegistry: VpnFeaturesRegistry,
private val coroutineScope: CoroutineScope,
@AppCoroutineScope private val coroutineScope: CoroutineScope,
private val dispatcherProvider: DispatcherProvider,
) : RefreshRetentionAtbPlugin {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.core.app.NotificationManagerCompat
import androidx.lifecycle.LifecycleOwner
import androidx.work.*
import com.duckduckgo.anvil.annotations.ContributesWorker
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.app.lifecycle.MainProcessLifecycleObserver
import com.duckduckgo.di.scopes.AppScope
Expand All @@ -30,7 +31,6 @@ import com.duckduckgo.mobile.android.vpn.pixels.DeviceShieldPixels
import com.duckduckgo.mobile.android.vpn.stats.AppTrackerBlockingStatsRepository
import com.duckduckgo.mobile.android.vpn.store.VpnDatabase
import com.duckduckgo.mobile.android.vpn.ui.notification.DeviceShieldNotificationScheduler.Companion
import com.duckduckgo.vpn.di.VpnCoroutineScope
import com.squareup.anvil.annotations.ContributesTo
import dagger.Module
import dagger.Provides
Expand All @@ -46,7 +46,7 @@ object DeviceShieldNotificationSchedulerModule {
@Provides
@IntoSet
fun provideDeviceShieldNotificationScheduler(
@VpnCoroutineScope coroutineScope: CoroutineScope,
@AppCoroutineScope coroutineScope: CoroutineScope,
workManager: WorkManager,
vpnDatabase: VpnDatabase,
dispatchers: DispatcherProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.duckduckgo.anvil.annotations.ContributesViewModel
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.di.scopes.ActivityScope
import com.duckduckgo.mobile.android.vpn.R
Expand All @@ -45,7 +46,7 @@ class VpnOnboardingViewModel @Inject constructor(
private val vpnDetector: ExternalVpnDetector,
private val vpnStateMonitor: VpnStateMonitor,
private val appTPOnboardingAnimationHelper: AppTPOnboardingResourceHelper,
private val appCoroutineScope: CoroutineScope,
@AppCoroutineScope private val appCoroutineScope: CoroutineScope,
private val dispatcherProvider: DispatcherProvider,
) : ViewModel() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.duckduckgo.app.brokensite.api

import android.net.Uri
import com.duckduckgo.app.brokensite.model.BrokenSite
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.app.global.absoluteString
import com.duckduckgo.app.pixels.AppPixelName
Expand Down Expand Up @@ -49,7 +50,7 @@ class BrokenSiteSubmitter @Inject constructor(
private val gpc: Gpc,
private val featureToggle: FeatureToggle,
private val pixel: Pixel,
private val appCoroutineScope: CoroutineScope,
@AppCoroutineScope private val appCoroutineScope: CoroutineScope,
private val appBuildConfig: AppBuildConfig,
private val dispatcherProvider: DispatcherProvider,
private val privacyConfig: PrivacyConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.duckduckgo.app.browser.logindetection.WebNavigationEvent
import com.duckduckgo.app.browser.model.BasicAuthenticationRequest
import com.duckduckgo.app.browser.navigation.safeCopyBackForwardList
import com.duckduckgo.app.browser.print.PrintInjector
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.app.statistics.pixels.Pixel
import com.duckduckgo.autoconsent.api.Autoconsent
Expand All @@ -63,7 +64,7 @@ class BrowserWebViewClient @Inject constructor(
private val loginDetector: DOMLoginDetector,
private val dosDetector: DosDetector,
private val thirdPartyCookieManager: ThirdPartyCookieManager,
private val appCoroutineScope: CoroutineScope,
@AppCoroutineScope private val appCoroutineScope: CoroutineScope,
private val dispatcherProvider: DispatcherProvider,
private val browserAutofillConfigurator: BrowserAutofill.Configurator,
private val accessibilityManager: AccessibilityManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.duckduckgo.anvil.annotations.InjectWith
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.pixels.AppPixelName
import com.duckduckgo.app.statistics.pixels.Pixel
import com.duckduckgo.di.scopes.ReceiverScope
Expand All @@ -40,6 +41,7 @@ class SharePromoLinkRMFBroadCastReceiver : BroadcastReceiver() {
lateinit var remoteMessagingRepository: RemoteMessagingRepository

@Inject
@AppCoroutineScope
lateinit var coroutineScope: CoroutineScope

override fun onReceive(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.duckduckgo.app.email

import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.email.api.EmailService
import com.duckduckgo.app.email.db.EmailDataStore
import com.duckduckgo.app.global.DispatcherProvider
Expand Down Expand Up @@ -46,7 +47,7 @@ class AppEmailManager @Inject constructor(
private val emailService: EmailService,
private val emailDataStore: EmailDataStore,
private val dispatcherProvider: DispatcherProvider,
private val appCoroutineScope: CoroutineScope,
@AppCoroutineScope private val appCoroutineScope: CoroutineScope,
private val pixel: Pixel,
) : EmailManager, BrowserFeatureStateReporterPlugin {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.app.PendingIntent
import android.content.Context
import android.os.Bundle
import com.duckduckgo.app.browser.R
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.app.notification.NotificationRegistrar
import com.duckduckgo.app.notification.TaskStackBuilderFactory
Expand Down Expand Up @@ -86,7 +87,7 @@ class ClearDataNotificationPlugin @Inject constructor(
private val schedulableNotification: ClearDataNotification,
private val taskStackBuilderFactory: TaskStackBuilderFactory,
private val pixel: Pixel,
private val coroutineScope: CoroutineScope,
@AppCoroutineScope private val coroutineScope: CoroutineScope,
private val dispatcherProvider: DispatcherProvider,
) : SchedulableNotificationPlugin {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.content.Context
import android.os.Bundle
import com.duckduckgo.app.browser.R
import com.duckduckgo.app.browser.defaultbrowsing.DefaultBrowserDetector
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.app.notification.NotificationRegistrar
import com.duckduckgo.app.notification.TaskStackBuilderFactory
Expand Down Expand Up @@ -91,7 +92,7 @@ class DefaultNotificationPlugin @Inject constructor(
private val schedulableNotification: DefaultBrowserNotification,
private val taskStackBuilderFactory: TaskStackBuilderFactory,
private val pixel: Pixel,
private val coroutineScope: CoroutineScope,
@AppCoroutineScope private val coroutineScope: CoroutineScope,
private val dispatcherProvider: DispatcherProvider,
) : SchedulableNotificationPlugin {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.content.Context
import android.os.Bundle
import com.duckduckgo.app.browser.BrowserActivity
import com.duckduckgo.app.browser.R
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.app.notification.NotificationRegistrar
import com.duckduckgo.app.notification.TaskStackBuilderFactory
Expand Down Expand Up @@ -97,7 +98,7 @@ class PrivacyProtectionNotificationPlugin @Inject constructor(
private val schedulableNotification: PrivacyProtectionNotification,
private val taskStackBuilderFactory: TaskStackBuilderFactory,
private val pixel: Pixel,
private val coroutineScope: CoroutineScope,
@AppCoroutineScope private val coroutineScope: CoroutineScope,
private val dispatcherProvider: DispatcherProvider,
) : SchedulableNotificationPlugin {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.duckduckgo.app.privacy.db

import android.net.Uri
import androidx.core.net.toUri
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.app.global.domain
import com.duckduckgo.di.scopes.AppScope
Expand All @@ -33,7 +34,7 @@ import kotlinx.coroutines.launch
@SingleInstanceIn(AppScope::class)
class RealUserAllowListRepository @Inject constructor(
private val userAllowListDao: UserAllowListDao,
coroutineScope: CoroutineScope,
@AppCoroutineScope coroutineScope: CoroutineScope,
dispatcherProvider: DispatcherProvider,
) : UserAllowListRepository {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.app.PendingIntent
import android.content.Context
import android.os.Bundle
import com.duckduckgo.app.browser.R
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.app.notification.NotificationRegistrar
import com.duckduckgo.app.notification.TaskStackBuilderFactory
Expand Down Expand Up @@ -82,7 +83,7 @@ class AvailableSurveyNotificationPlugin @Inject constructor(
private val schedulableNotification: SurveyAvailableNotification,
private val taskStackBuilderFactory: TaskStackBuilderFactory,
private val pixel: Pixel,
private val coroutineScope: CoroutineScope,
@AppCoroutineScope private val coroutineScope: CoroutineScope,
private val dispatcherProvider: DispatcherProvider,
private val surveyRepository: SurveyRepository,
) : SchedulableNotificationPlugin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.content.ComponentName
import android.content.Context
import androidx.lifecycle.LifecycleOwner
import com.duckduckgo.app.browser.R
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.lifecycle.MainProcessLifecycleObserver
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.savedsites.api.SavedSitesRepository
Expand All @@ -34,7 +35,7 @@ import kotlinx.coroutines.launch
class FavoritesObserver @Inject constructor(
context: Context,
private val savedSitesRepository: SavedSitesRepository,
private val appCoroutineScope: CoroutineScope,
@AppCoroutineScope private val appCoroutineScope: CoroutineScope,
) : MainProcessLifecycleObserver {

private val instance = AppWidgetManager.getInstance(context)
Expand Down
6 changes: 3 additions & 3 deletions di/src/main/java/com/duckduckgo/app/di/AppCoroutineScope.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package com.duckduckgo.app.di

import javax.inject.Scope
import javax.inject.Qualifier

/** Identifies a coroutine scope type that is scope to the app lifecycle */
@Scope
@Qualifier
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
@Retention(AnnotationRetention.BINARY)
annotation class AppCoroutineScope
27 changes: 0 additions & 27 deletions di/src/main/java/com/duckduckgo/vpn/di/VpnCoroutineScope.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.duckduckgo.networkprotection.impl.state

import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.mobile.android.vpn.VpnFeaturesRegistry
Expand All @@ -41,7 +42,7 @@ import kotlinx.coroutines.withContext
@ContributesBinding(AppScope::class)
class NetworkProtectionStateImpl @Inject constructor(
private val vpnFeaturesRegistry: VpnFeaturesRegistry,
private val coroutineScope: CoroutineScope,
@AppCoroutineScope private val coroutineScope: CoroutineScope,
private val cohortStore: NetpCohortStore,
private val dispatcherProvider: DispatcherProvider,
private val networkProtectionRepository: NetworkProtectionRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.app.PendingIntent
import android.content.Context
import android.os.Bundle
import androidx.core.app.NotificationManagerCompat
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.notification.NotificationSender
import com.duckduckgo.app.notification.TaskStackBuilderFactory
import com.duckduckgo.app.notification.model.Channel
Expand All @@ -46,7 +47,7 @@ open class NetPWaitlistCodeNotification @Inject constructor(
private val context: Context,
private val netPWaitlistManager: NetPWaitlistManager,
private val notificationSender: Provider<NotificationSender>,
private val coroutineScope: CoroutineScope,
@AppCoroutineScope private val coroutineScope: CoroutineScope,
private val networkProtectionState: NetworkProtectionState,
private val notificationManager: NotificationManagerCompat,
) : SchedulableNotification {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.duckduckgo.networkprotection.impl.waitlist

import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.appbuildconfig.api.AppBuildConfig
import com.duckduckgo.appbuildconfig.api.isInternalBuild
import com.duckduckgo.di.scopes.AppScope
Expand Down Expand Up @@ -105,7 +106,7 @@ class NetPRemoteFeatureWrapper @Inject constructor(
private val netPRemoteFeature: NetPRemoteFeature,
private val netPFeatureRemover: NetPFeatureRemover,
private val appBuildConfig: AppBuildConfig,
private val coroutineScope: CoroutineScope,
@AppCoroutineScope private val coroutineScope: CoroutineScope,
) {
/**
* @return `true` if the waitlist beta is active. This is different that having waitlist enabled and they are
Expand Down
Loading

0 comments on commit ec0fd09

Please sign in to comment.