Skip to content

Commit

Permalink
Fix FDroid build (#4949)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/488551667048375/1208148719076009/f

### Description

### Steps to test this PR

- [x] Fresh install (internal or play flavor)
- [x] Navigate to duckduckgo.com/pro
- [x] Check onboarding in-context dialog is not shown
- [x] Perform a search
- [x] check SERP in-context dialog is shown

### No UI changes
  • Loading branch information
lmac012 authored Aug 29, 2024
1 parent 84a3585 commit 74b939d
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ class BrowserTabViewModelTest {
dispatchers = coroutineRule.testDispatcherProvider,
duckDuckGoUrlDetector = DuckDuckGoUrlDetectorImpl(),
extendedOnboardingFeatureToggles = mockExtendedOnboardingFeatureToggles,
subscriptions = mock(),
)

val siteFactory = SiteFactoryImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import com.duckduckgo.app.widget.ui.WidgetCapabilities
import com.duckduckgo.common.test.CoroutineTestRule
import com.duckduckgo.common.test.InstantSchedulersRule
import com.duckduckgo.feature.toggles.api.Toggle
import com.duckduckgo.subscriptions.api.Subscriptions
import java.util.concurrent.TimeUnit
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.drop
Expand Down Expand Up @@ -112,6 +113,9 @@ class CtaViewModelTest {
@Mock
private lateinit var mockExtendedOnboardingFeatureToggles: ExtendedOnboardingFeatureToggles

@Mock
private lateinit var mockSubscriptions: Subscriptions

private val requiredDaxOnboardingCtas: List<CtaId> = listOf(
CtaId.DAX_INTRO,
CtaId.DAX_DIALOG_SERP,
Expand Down Expand Up @@ -153,6 +157,7 @@ class CtaViewModelTest {
dispatchers = coroutineRule.testDispatcherProvider,
duckDuckGoUrlDetector = DuckDuckGoUrlDetectorImpl(),
extendedOnboardingFeatureToggles = mockExtendedOnboardingFeatureToggles,
subscriptions = mockSubscriptions,
)
}

Expand Down Expand Up @@ -715,6 +720,7 @@ class CtaViewModelTest {
@Test
fun givenPrivacyProSiteWhenRefreshCtaWhileBrowsingThenReturnNull() = runTest {
val privacyProUrl = "https://duckduckgo.com/pro"
whenever(mockSubscriptions.isPrivacyProUrl(privacyProUrl)).thenReturn(true)
givenDaxOnboardingActive()
val site = site(url = privacyProUrl)

Expand Down
13 changes: 3 additions & 10 deletions app/src/main/java/com/duckduckgo/app/cta/ui/CtaViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.duckduckgo.app.cta.ui

import androidx.annotation.VisibleForTesting
import androidx.annotation.WorkerThread
import androidx.core.net.toUri
import com.duckduckgo.app.browser.DuckDuckGoUrlDetector
import com.duckduckgo.app.cta.db.DismissedCtaDao
import com.duckduckgo.app.cta.model.CtaId
Expand All @@ -37,10 +36,8 @@ import com.duckduckgo.app.statistics.pixels.Pixel
import com.duckduckgo.app.tabs.model.TabRepository
import com.duckduckgo.app.widget.ui.WidgetCapabilities
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.common.utils.extensions.toTldPlusOne
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.PRIVACY_PRO_ETLD
import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.PRIVACY_PRO_PATH
import com.duckduckgo.subscriptions.api.Subscriptions
import dagger.SingleInstanceIn
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
Expand All @@ -64,6 +61,7 @@ class CtaViewModel @Inject constructor(
private val dispatchers: DispatcherProvider,
private val duckDuckGoUrlDetector: DuckDuckGoUrlDetector,
private val extendedOnboardingFeatureToggles: ExtendedOnboardingFeatureToggles,
private val subscriptions: Subscriptions,
) {
@ExperimentalCoroutinesApi
@VisibleForTesting
Expand Down Expand Up @@ -291,12 +289,7 @@ class CtaViewModel @Inject constructor(
}

private fun isSiteNotAllowedForOnboarding(url: String?): Boolean {
val uri = url?.toUri() ?: return true
val eTld = uri.host?.toTldPlusOne() ?: return false
val size = uri.pathSegments.size
val path = uri.pathSegments.firstOrNull()
val isPrivacyProSite = eTld == PRIVACY_PRO_ETLD && size == 1 && path == PRIVACY_PRO_PATH
return isPrivacyProSite
return url == null || subscriptions.isPrivacyProUrl(url)
}

private fun daxDialogIntroShown(): Boolean = dismissedCtaDao.exists(CtaId.DAX_INTRO)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class OnboardingDaxDialogTests {
dismissedCtaDao,
userAllowListRepository,
settingsDataStore, onboardingStore, userStageStore, tabRepository, dispatchers, duckDuckGoUrlDetector, extendedOnboardingFeatureToggles,
subscriptions = mock(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ interface Subscriptions {
* Launches Privacy Pro with Settings as the parent activity
*/
fun launchPrivacyPro(context: Context, uri: Uri?)

/**
* @return `true` if the given URL leads to the Privacy Pro page, or `false` otherwise
*/
fun isPrivacyProUrl(url: String): Boolean
}

enum class Product(val value: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ class SubscriptionsDummy @Inject constructor() : Subscriptions {
) {
// no-op
}

override fun isPrivacyProUrl(url: String): Boolean = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,22 @@ class RealSubscriptions @Inject constructor(
}

override fun shouldLaunchPrivacyProForUrl(url: String): Boolean {
val uri = url.toUri()
val eTld = uri.host?.toTldPlusOne() ?: return false
val size = uri.pathSegments.size
val path = uri.pathSegments.firstOrNull()
return if (eTld == PRIVACY_PRO_ETLD && size == 1 && path == PRIVACY_PRO_PATH) {
return if (isPrivacyProUrl(url)) {
runBlocking {
isEligible()
}
} else {
false
}
}

override fun isPrivacyProUrl(url: String): Boolean {
val uri = url.toUri()
val eTld = uri.host?.toTldPlusOne() ?: return false
val size = uri.pathSegments.size
val path = uri.pathSegments.firstOrNull()
return eTld == PRIVACY_PRO_ETLD && size == 1 && path == PRIVACY_PRO_PATH
}
}

@ContributesRemoteFeature(
Expand Down

0 comments on commit 74b939d

Please sign in to comment.