Skip to content

Commit

Permalink
Merge branch 'hotfix/5.171.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
malmstein committed Sep 19, 2023
2 parents 51448ed + 3015685 commit 921de94
Show file tree
Hide file tree
Showing 143 changed files with 388 additions and 703 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class RealAppTrackingProtection @Inject constructor(
}

override fun restart() {
coroutineScope.launch(dispatcherProvider.io()) {
coroutineScope.launch {
vpnFeaturesRegistry.refreshFeature(AppTpVpnFeature.APPTP_VPN)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

@SuppressLint("NoLifecycleObserver") // we don't observe app lifecycle
@ContributesViewModel(ActivityScope::class)
Expand All @@ -63,7 +62,7 @@ class ManageAppsProtectionViewModel @Inject constructor(
private val defaultTimeWindow = TimeWindow(5, DAYS)

private fun MutableStateFlow<Long>.refresh() {
viewModelScope.launch(dispatcherProvider.io()) {
viewModelScope.launch {
emit(System.currentTimeMillis())
}
}
Expand All @@ -87,8 +86,8 @@ class ManageAppsProtectionViewModel @Inject constructor(
.launchIn(viewModelScope)
}

internal suspend fun getProtectedApps(): Flow<ViewState> = withContext(dispatcherProvider.io()) {
return@withContext excludedApps.getAppsAndProtectionInfo()
internal suspend fun getProtectedApps(): Flow<ViewState> {
return excludedApps.getAppsAndProtectionInfo()
.combine(filterState.asStateFlow()) { list, filter ->
val protectedApps = list.filter { !it.isExcluded }.map { AppInfoType(it) }
val unprotectedApps = list.filter { it.isExcluded }.map { AppInfoType(it) }
Expand Down Expand Up @@ -125,8 +124,8 @@ class ManageAppsProtectionViewModel @Inject constructor(
}
}

internal suspend fun getRecentApps() = withContext(dispatcherProvider.io()) {
return@withContext appTrackersRepository.getMostRecentVpnTrackers { defaultTimeWindow.asString() }.map { aggregateDataPerApp(it) }
internal suspend fun getRecentApps() =
appTrackersRepository.getMostRecentVpnTrackers { defaultTimeWindow.asString() }.map { aggregateDataPerApp(it) }
.combine(excludedApps.getAppsAndProtectionInfo()) { recentAppsBlocked, protectedApps ->
recentAppsBlocked.map {
protectedApps.firstOrNull { protectedApp -> protectedApp.packageName == it.packageId }
Expand All @@ -137,7 +136,6 @@ class ManageAppsProtectionViewModel @Inject constructor(
}.map { ViewState(it) }
.onStart { pixel.didShowExclusionListActivity() }
.flowOn(dispatcherProvider.io())
}

private suspend fun aggregateDataPerApp(
trackerData: List<VpnTrackerWithEntity>,
Expand Down Expand Up @@ -165,7 +163,7 @@ class ManageAppsProtectionViewModel @Inject constructor(
report: Boolean,
) {
pixel.didDisableAppProtectionFromApps()
viewModelScope.launch(dispatcherProvider.io()) {
viewModelScope.launch {
excludedApps.manuallyExcludeApp(packageName)
pixel.didSubmitManuallyDisableAppProtectionDialog()
if (report) {
Expand All @@ -184,14 +182,14 @@ class ManageAppsProtectionViewModel @Inject constructor(
packageName: String,
) {
pixel.didEnableAppProtectionFromApps()
viewModelScope.launch(dispatcherProvider.io()) {
viewModelScope.launch {
excludedApps.manuallyEnabledApp(packageName)
}
}

fun restoreProtectedApps() {
pixel.restoreDefaultProtectionList()
viewModelScope.launch(dispatcherProvider.io()) {
viewModelScope.launch {
excludedApps.restoreDefaultProtectedList()
// as product wanted to restart VPN as soon as we restored protections, we need to refresh the snapshot here
refreshSnapshot.refresh()
Expand All @@ -215,7 +213,7 @@ class ManageAppsProtectionViewModel @Inject constructor(
fun canRestoreDefaults() = currentManualProtections.isNotEmpty()

fun applyAppsFilter(value: AppsFilter) {
viewModelScope.launch(dispatcherProvider.io()) {
viewModelScope.launch {
filterState.emit(value)
}
}
Expand All @@ -229,7 +227,7 @@ class ManageAppsProtectionViewModel @Inject constructor(
}

private fun onLeavingScreen() {
viewModelScope.launch(dispatcherProvider.io()) {
viewModelScope.launch {
if (userMadeChanges()) {
command.send(Command.RestartVpn)
}
Expand All @@ -241,7 +239,7 @@ class ManageAppsProtectionViewModel @Inject constructor(
position: Int,
enabled: Boolean,
) {
viewModelScope.launch(dispatcherProvider.io()) {
viewModelScope.launch {
if (enabled) {
checkForAppProtectionEnabled(excludedAppInfo, position)
} else {
Expand Down Expand Up @@ -271,7 +269,7 @@ class ManageAppsProtectionViewModel @Inject constructor(

fun launchFeedback() {
pixel.launchAppTPFeedback()
viewModelScope.launch(dispatcherProvider.io()) {
viewModelScope.launch {
command.send(
Command.LaunchFeedback(
ReportBreakageScreen.ListOfInstalledApps("apptp", breakageCategories),
Expand All @@ -282,7 +280,7 @@ class ManageAppsProtectionViewModel @Inject constructor(

fun launchManageAppsProtection() {
pixel.didOpenExclusionListActivityFromManageAppsProtectionScreen()
viewModelScope.launch(dispatcherProvider.io()) {
viewModelScope.launch {
command.send(Command.LaunchAllAppsProtection)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,26 @@ package com.duckduckgo.mobile.android.vpn.breakage
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.duckduckgo.anvil.annotations.ContributesViewModel
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.di.scopes.ActivityScope
import com.duckduckgo.mobile.android.vpn.apps.TrackingProtectionAppsRepository
import javax.inject.Inject
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

@ContributesViewModel(ActivityScope::class)
class ReportBreakageAppListViewModel @Inject constructor(
private val trackingProtectionAppsRepository: TrackingProtectionAppsRepository,
private val dispatcherProvider: DispatcherProvider,
) : ViewModel() {

private val selectedAppFlow = MutableStateFlow<InstalledApp?>(null)

private val command = Channel<ReportBreakageAppListView.Command>(1, BufferOverflow.DROP_OLDEST)
internal fun commands(): Flow<ReportBreakageAppListView.Command> = command.receiveAsFlow()

internal suspend fun getInstalledApps(): Flow<ReportBreakageAppListView.State> = withContext(dispatcherProvider.io()) {
return@withContext trackingProtectionAppsRepository.getAppsAndProtectionInfo()
internal suspend fun getInstalledApps(): Flow<ReportBreakageAppListView.State> {
return trackingProtectionAppsRepository.getAppsAndProtectionInfo()
.combine(selectedAppFlow.asStateFlow()) { apps, selectedApp ->
val installedApps = apps.map { InstalledApp(it.packageName, it.name) }
selectedApp?.let { appSelected ->
Expand All @@ -52,19 +49,19 @@ class ReportBreakageAppListViewModel @Inject constructor(
}

internal fun onAppSelected(app: InstalledApp) {
viewModelScope.launch(dispatcherProvider.io()) {
viewModelScope.launch {
selectedAppFlow.emit(app.copy(isSelected = true))
}
}

internal fun onSubmitBreakage() {
viewModelScope.launch(dispatcherProvider.io()) {
viewModelScope.launch {
selectedAppFlow.value?.let { command.send(ReportBreakageAppListView.Command.LaunchBreakageForm(it)) }
}
}

internal fun onBreakageSubmitted(issueReport: IssueReport) {
viewModelScope.launch(dispatcherProvider.io()) {
viewModelScope.launch {
selectedAppFlow.value?.let {
command.send(ReportBreakageAppListView.Command.SendBreakageInfo(issueReport.copy(appPackageId = it.packageName)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AppTpFeatureConfigImpl @Inject constructor(
@AppCoroutineScope private val coroutineScope: CoroutineScope,
private val appBuildConfig: AppBuildConfig,
vpnRemoteConfigDatabase: VpnRemoteConfigDatabase,
private val dispatcherProvider: DispatcherProvider,
dispatcherProvider: DispatcherProvider,
) : AppTpFeatureConfig, AppTpFeatureConfig.Editor {

private val togglesDao = vpnRemoteConfigDatabase.vpnConfigTogglesDao()
Expand Down Expand Up @@ -76,7 +76,7 @@ class AppTpFeatureConfigImpl @Inject constructor(
}

private fun persistToggle(toggle: VpnConfigToggle) {
coroutineScope.launch(dispatcherProvider.io()) {
coroutineScope.launch {
// Remote configs will not override any value that has isManualOverride = true
// But this is only for INTERNAL builds, because we have internal settings
// In any other build that is not internal isManualOverride is always false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.duckduckgo.mobile.android.vpn.feature.settings

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
import com.duckduckgo.mobile.android.vpn.VpnFeaturesRegistry
Expand All @@ -43,7 +42,6 @@ class ExceptionListsSettingPlugin @Inject constructor(
private val vpnDatabase: VpnDatabase,
@AppCoroutineScope private val appCoroutineScope: CoroutineScope,
private val vpnFeaturesRegistry: VpnFeaturesRegistry,
private val dispatcherProvider: DispatcherProvider,
) : AppTpSettingPlugin {
private val jsonAdapter = Moshi.Builder().build().adapter(JsonConfigModel::class.java)

Expand All @@ -69,7 +67,7 @@ class ExceptionListsSettingPlugin @Inject constructor(
)

// Restart VPN now that the lists were updated
appCoroutineScope.launch(dispatcherProvider.io()) {
appCoroutineScope.launch {
vpnFeaturesRegistry.refreshFeature(AppTpVpnFeature.APPTP_VPN)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.duckduckgo.mobile.android.vpn.health

import android.content.Context
import android.os.PowerManager
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.app.global.extensions.isAirplaneModeOn
import com.duckduckgo.app.global.plugins.PluginPoint
import com.duckduckgo.app.utils.ConflatedJob
Expand Down Expand Up @@ -52,13 +51,12 @@ class NetworkConnectivityHealthHandler @Inject constructor(
private val pixel: DeviceShieldPixels,
private val trackerBlockingVpnService: Provider<TrackerBlockingVpnService>,
private val vpnConnectivityLossListenerPluginPoint: PluginPoint<VpnConnectivityLossListenerPlugin>,
private val dispatcherProvider: DispatcherProvider,
) : VpnServiceCallbacks {
private val powerManager = context.applicationContext.getSystemService(Context.POWER_SERVICE) as PowerManager
private val job = ConflatedJob()

override fun onVpnStarted(coroutineScope: CoroutineScope) {
job += coroutineScope.launch(dispatcherProvider.io()) {
job += coroutineScope.launch {
while (isActive) {
delay(15_000)
if (powerManager.isInteractive && !context.isAirplaneModeOn() && !hasVpnConnectivity()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class VpnServiceHeartbeat @Inject constructor(

override fun onVpnStarted(coroutineScope: CoroutineScope) {
logcat { "onVpnStarted called" }
job += coroutineScope.launch(dispatcherProvider.io()) {
job += coroutineScope.launch {
while (true) {
storeHeartbeat(VpnServiceHeartbeatMonitor.DATA_HEART_BEAT_TYPE_ALIVE)
delay(TimeUnit.MINUTES.toMillis(HEART_BEAT_PERIOD_MINUTES))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class DeviceShieldTileService : TileService() {

private fun pollDeviceShieldState() {
deviceShieldStatePollingJob +=
serviceScope.launch(dispatcherProvider.io()) {
serviceScope.launch {
while (isActive) {
val tile = qsTile
tile?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.appbuildconfig.api.AppBuildConfig
import com.duckduckgo.appbuildconfig.api.isInternalBuild
import com.duckduckgo.di.scopes.VpnScope
Expand All @@ -42,11 +41,10 @@ class RestartReceiver @Inject constructor(
@AppCoroutineScope private val coroutineScope: CoroutineScope,
private val context: Context,
private val appBuildConfig: AppBuildConfig,
private val dispatcherProvider: DispatcherProvider,
) : BroadcastReceiver(), VpnServiceCallbacks {
override fun onReceive(context: Context, intent: Intent) {
if (intent.getStringExtra("action")?.lowercase() == "restart") {
coroutineScope.launch(dispatcherProvider.io()) {
coroutineScope.launch {
TrackerBlockingVpnService.restartVpnService(context)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class AppTPReminderNotificationScheduler @Inject constructor(
private var isAppTPEnabled: AtomicReference<Boolean> = AtomicReference(false)

override fun onVpnStarted(coroutineScope: CoroutineScope) {
coroutineScope.launch(dispatchers.io()) {
coroutineScope.launch {
isAppTPEnabled.set(appTrackingProtection.isEnabled())
if (isAppTPEnabled.get()) {
// These are all relevant for when AppTP has been enabled.
Expand All @@ -77,7 +77,7 @@ class AppTPReminderNotificationScheduler @Inject constructor(
coroutineScope: CoroutineScope,
vpnStopReason: VpnStopReason,
) {
coroutineScope.launch(dispatchers.io()) {
coroutineScope.launch {
when (vpnStopReason) {
VpnStopReason.RESTART -> {} // no-op
VpnStopReason.SELF_STOP -> onVPNManuallyStopped()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class DeviceShieldNotificationScheduler(

private fun scheduleDailyNotification() {
val vpnNotificationsDao = vpnDatabase.vpnNotificationsDao()
coroutineScope.launch(dispatchers.io()) {
coroutineScope.launch {
val exists = withContext(dispatchers.io()) {
vpnNotificationsDao.exists(VPN_DAILY_NOTIFICATION_ID)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class VpnOnboardingViewModel @Inject constructor(
}

private fun sendCommand(newCommand: Command) {
viewModelScope.launch(dispatcherProvider.io()) {
viewModelScope.launch {
command.send(newCommand)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ class AppTPCompanyDetailsAdapter : RecyclerView.Adapter<AppTPCompanyDetailsAdapt

items.clear().also { items.addAll(newData) }

withContext(Dispatchers.Main) {
diffResult.dispatchUpdatesTo(this@AppTPCompanyDetailsAdapter)
}
diffResult.dispatchUpdatesTo(this@AppTPCompanyDetailsAdapter)
}

private class DiffCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import androidx.lifecycle.lifecycleScope
import com.bumptech.glide.Glide
import com.duckduckgo.anvil.annotations.InjectWith
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.app.global.DuckDuckGoActivity
import com.duckduckgo.app.global.extensions.safeGetApplicationIcon
import com.duckduckgo.browser.api.ui.WebViewActivityWithParams
Expand Down Expand Up @@ -92,9 +91,6 @@ class AppTPCompanyTrackersActivity : DuckDuckGoActivity() {
@AppTpBreakageCategories
lateinit var breakageCategories: List<AppBreakageCategory>

@Inject
lateinit var dispatcherProvider: DispatcherProvider

private val binding: ActivityApptpCompanyTrackersActivityBinding by viewBinding()
private val viewModel: AppTPCompanyTrackersViewModel by bindViewModel()

Expand Down Expand Up @@ -168,7 +164,7 @@ class AppTPCompanyTrackersActivity : DuckDuckGoActivity() {
override fun onStart() {
super.onStart()

lifecycleScope.launch(dispatcherProvider.io()) {
lifecycleScope.launch {
viewModel.loadData(
getDate(),
getPackage(),
Expand All @@ -185,7 +181,7 @@ class AppTPCompanyTrackersActivity : DuckDuckGoActivity() {
)
binding.includeToolbar.appTrackedAgo.text = viewState.lastTrackerBlockedAgo

lifecycleScope.launch(dispatcherProvider.io()) {
lifecycleScope.launch {
itemsAdapter.updateData(viewState.trackingCompanies)
}

Expand Down Expand Up @@ -229,7 +225,7 @@ class AppTPCompanyTrackersActivity : DuckDuckGoActivity() {

private fun restartVpn() {
// we use the app coroutine scope to ensure this call outlives the Activity
appCoroutineScope.launch(dispatcherProvider.io()) {
appCoroutineScope.launch {
vpnFeaturesRegistry.refreshFeature(AppTpVpnFeature.APPTP_VPN)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class AppTPCompanyTrackersViewModel @Inject constructor(
statsRepository
.getTrackersForAppFromDate(date, packageName)
.map { aggregateDataPerApp(it, packageName) }
.flowOn(dispatchers.default())
.collectLatest { state ->
viewStateFlow.emit(state)
}
Expand Down Expand Up @@ -149,7 +150,7 @@ class AppTPCompanyTrackersViewModel @Inject constructor(
checked: Boolean,
packageName: String,
) {
viewModelScope.launch(dispatchers.io()) {
viewModelScope.launch {
withContext(dispatchers.io()) {
if (checked) {
deviceShieldPixels.didEnableAppProtectionFromDetail()
Expand Down
Loading

0 comments on commit 921de94

Please sign in to comment.