Skip to content

Commit

Permalink
Fix Disconnect/re-connect from notification when both VPN and AppTP a…
Browse files Browse the repository at this point in the history
…re enabled
  • Loading branch information
aitorvs committed Oct 18, 2024
1 parent 1cec8c1 commit 5f36fbf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import android.os.SystemClock
import com.duckduckgo.anvil.annotations.InjectWith
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.di.scopes.ReceiverScope
import com.duckduckgo.mobile.android.app.tracking.AppTrackingProtection
import com.duckduckgo.mobile.android.vpn.Vpn
import com.duckduckgo.mobile.android.vpn.pixels.DeviceShieldPixels
import com.duckduckgo.networkprotection.api.NetworkProtectionState
import dagger.android.AndroidInjection
import java.util.concurrent.TimeUnit
import javax.inject.Inject
Expand All @@ -38,6 +40,10 @@ import logcat.logcat
class VpnActionReceiver : BroadcastReceiver() {
@Inject lateinit var vpn: Vpn

@Inject lateinit var networkProtectionState: NetworkProtectionState

@Inject lateinit var appTrackingProtection: AppTrackingProtection

@Inject lateinit var dispatcherProvider: DispatcherProvider

@Inject lateinit var context: Context
Expand Down Expand Up @@ -65,7 +71,10 @@ class VpnActionReceiver : BroadcastReceiver() {
ACTION_VPN_DISABLE -> {
logcat { "Entire VPN will disabled because the user asked it" }
goAsync(pendingResult) {
// instead of stopping the VPN, we stop the VPN features individually
vpn.stop()
appTrackingProtection.stop()
networkProtectionState.stop()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.squareup.anvil.annotations.ContributesMultibinding
import dagger.SingleInstanceIn
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.runBlocking

Expand Down Expand Up @@ -77,6 +78,7 @@ class AppTPAndNetPEnabledNotificationContentPlugin @Inject constructor(
}

return repository.getVpnTrackers({ dateOfLastHour() })
.filter { isActive() } // make sure we only emit when this plugin is active
.map { trackersBlocked ->
val trackingApps = trackersBlocked.trackingApps()
val location = networkProtectionState.serverLocation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class AppTpEnabledNotificationContentPlugin @Inject constructor(
}

return repository.getVpnTrackers({ dateOfLastHour() })
.filter { isActive() } // make sure we only emit when this plugin is active
.map { trackersBlocked ->
val trackingApps = trackersBlocked.trackingApps()
val isEnabled = appTrackingProtection.isEnabled()
Expand Down

0 comments on commit 5f36fbf

Please sign in to comment.