Skip to content

Commit

Permalink
Merge branch 'release/5.212.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
aitorvs committed Aug 15, 2024
2 parents 02ca56c + 93904a2 commit b1eec70
Show file tree
Hide file tree
Showing 190 changed files with 6,666 additions and 981 deletions.
3 changes: 2 additions & 1 deletion ad-click/ad-click-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ plugins {
id 'com.android.library'
id 'kotlin-android'
id 'com.squareup.anvil'
id 'com.google.devtools.ksp' version "$ksp_version"
}

apply from: "$rootProject.projectDir/gradle/android-library.gradle"
Expand All @@ -43,7 +44,6 @@ dependencies {
implementation project(path: ':privacy-config-api')
implementation project(path: ':feature-toggles-api')
implementation project(path: ':app-build-config-api')
implementation project(path: ':ad-click-store')

implementation AndroidX.core.ktx

Expand All @@ -65,6 +65,7 @@ dependencies {
implementation AndroidX.room.runtime
implementation AndroidX.room.rxJava2
implementation AndroidX.room.ktx
ksp AndroidX.room.compiler
testImplementation AndroidX.room.testing

// Dagger
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
package com.duckduckgo.adclick.impl

import android.net.Uri
import com.duckduckgo.adclick.api.AdClickFeatureName
import com.duckduckgo.adclick.store.AdClickAttributionLinkFormatEntity
import com.duckduckgo.adclick.store.AdClickAttributionRepository
import com.duckduckgo.adclick.impl.remoteconfig.AdClickAttributionFeature
import com.duckduckgo.adclick.impl.remoteconfig.AdClickAttributionRepository
import com.duckduckgo.adclick.impl.store.AdClickAttributionLinkFormatEntity
import com.duckduckgo.app.browser.UriString
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.feature.toggles.api.FeatureToggle
import com.squareup.anvil.annotations.ContributesBinding
import java.util.concurrent.TimeUnit
import javax.inject.Inject
Expand All @@ -40,11 +39,11 @@ interface AdClickAttribution {
@ContributesBinding(AppScope::class)
class RealAdClickAttribution @Inject constructor(
private val adClickAttributionRepository: AdClickAttributionRepository,
private val featureToggle: FeatureToggle,
private val adClickAttributionFeature: AdClickAttributionFeature,
) : AdClickAttribution {

override fun isAllowed(url: String): Boolean {
if (!featureToggle.isFeatureEnabled(AdClickFeatureName.AdClickAttributionFeatureName.value, true)) {
if (!adClickAttributionFeature.self().isEnabled()) {
return false
}
if (!isHeuristicDetectionEnabled() && !isDomainDetectionEnabled()) {
Expand All @@ -56,7 +55,7 @@ class RealAdClickAttribution @Inject constructor(
override fun isAdClick(url: String): Pair<Boolean, String?> {
val noMatch = Pair(false, null)

if (!featureToggle.isFeatureEnabled(AdClickFeatureName.AdClickAttributionFeatureName.value, true)) {
if (!adClickAttributionFeature.self().isEnabled()) {
return noMatch
}
if (!isHeuristicDetectionEnabled() && !isDomainDetectionEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ package com.duckduckgo.adclick.impl.di

import android.content.Context
import androidx.room.Room
import com.duckduckgo.adclick.store.AdClickAttributionRepository
import com.duckduckgo.adclick.store.AdClickDatabase
import com.duckduckgo.adclick.store.AdClickDatabase.Companion.ALL_MIGRATIONS
import com.duckduckgo.adclick.store.AdClickFeatureToggleRepository
import com.duckduckgo.adclick.store.RealAdClickAttributionRepository
import com.duckduckgo.adclick.impl.remoteconfig.AdClickAttributionRepository
import com.duckduckgo.adclick.impl.remoteconfig.RealAdClickAttributionRepository
import com.duckduckgo.adclick.impl.store.AdClickDatabase
import com.duckduckgo.adclick.impl.store.AdClickDatabase.Companion.ALL_MIGRATIONS
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.di.IsMainProcess
import com.duckduckgo.common.utils.DispatcherProvider
Expand Down Expand Up @@ -56,10 +55,4 @@ class AdClickModule {
): AdClickAttributionRepository {
return RealAdClickAttributionRepository(database, appCoroutineScope, dispatcherProvider, isMainProcess)
}

@SingleInstanceIn(AppScope::class)
@Provides
fun provideAdClickFeatureToggleRepository(context: Context): AdClickFeatureToggleRepository {
return AdClickFeatureToggleRepository.create(context)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2024 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.adclick.impl.remoteconfig

import com.duckduckgo.anvil.annotations.ContributesRemoteFeature
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.feature.toggles.api.Toggle

@ContributesRemoteFeature(
scope = AppScope::class,
featureName = "adClickAttribution",
settingsStore = AdClickAttributionFeatureSettingsStore::class,
)
/**
* This is the class that represents the adClickAttribution feature flags.
*/
interface AdClickAttributionFeature {
/**
* @return `true` when the remote config has the global "adClickAttribution" feature flag enabled
* If the remote feature is not present defaults to `false`
*/
@Toggle.DefaultValue(false)
fun self(): Toggle
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 DuckDuckGo
* Copyright (c) 2024 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,32 +14,35 @@
* limitations under the License.
*/

package com.duckduckgo.adclick.impl
package com.duckduckgo.adclick.impl.remoteconfig

import com.duckduckgo.feature.toggles.api.FeatureExceptions.FeatureException
import com.squareup.moshi.Json

data class AdClickAttributionFeature(
val state: String,
val minSupportedVersion: Int?,
val settings: AdClickAttributionSettings,
val exceptions: List<FeatureException>,
)

data class AdClickAttributionSettings(
data class AdClickAttributionFeatureModel(
@field:Json(name = "linkFormats")
val linkFormats: List<AdClickAttributionLinkFormat>,
@field:Json(name = "allowlist")
val allowlist: List<AdClickAttributionAllowlist>,
@field:Json(name = "navigationExpiration")
val navigationExpiration: Long,
@field:Json(name = "totalExpiration")
val totalExpiration: Long,
@field:Json(name = "heuristicDetection")
val heuristicDetection: String?,
@field:Json(name = "domainDetection")
val domainDetection: String?,
)

data class AdClickAttributionLinkFormat(
@field:Json(name = "url")
val url: String,
@field:Json(name = "adDomainParameterName")
val adDomainParameterName: String?,
)

data class AdClickAttributionAllowlist(
@field:Json(name = "blocklistEntry")
val blocklistEntry: String?,
@field:Json(name = "host")
val host: String?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2024 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.adclick.impl.remoteconfig

import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.feature.toggles.api.FeatureSettings
import com.duckduckgo.feature.toggles.api.RemoteFeatureStoreNamed
import com.squareup.anvil.annotations.ContributesBinding
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import javax.inject.Inject

@ContributesBinding(AppScope::class)
@RemoteFeatureStoreNamed(AdClickAttributionFeature::class)
class AdClickAttributionFeatureSettingsStore @Inject constructor(
private val adClickAttributionRepository: AdClickAttributionRepository,
) : FeatureSettings.Store {

private val jsonAdapter by lazy { buildJsonAdapter() }

override fun store(jsonString: String) {
jsonAdapter.fromJson(jsonString)?.let {
adClickAttributionRepository.updateAll(
it.linkFormats,
it.allowlist,
it.navigationExpiration,
it.totalExpiration,
it.heuristicDetection,
it.domainDetection,
)
}
}

private fun buildJsonAdapter(): JsonAdapter<AdClickAttributionFeatureModel> {
val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
return moshi.adapter(AdClickAttributionFeatureModel::class.java)
}
}
Loading

0 comments on commit b1eec70

Please sign in to comment.