Skip to content

Commit

Permalink
Replace toggles db with shared preferences (#1496)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosholgado authored Oct 14, 2021
1 parent a60fb74 commit 42bfff3
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package com.duckduckgo.feature.toggles.api
interface FeatureToggle {
/**
* This method takes a [featureName] and optionally a default value.
* @return `true` if the feature is enabled, `false` is is not and `null` if the feature does not exist.
* @return `true` if the feature is enabled, `false` if is not and `null` if the feature does not exist.
*/
fun isFeatureEnabled(featureName: FeatureName, defaultValue: Boolean = true): Boolean?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ import com.duckduckgo.privacy.config.impl.network.JSONObjectAdapter
import com.duckduckgo.privacy.config.impl.network.PrivacyConfigService
import com.duckduckgo.privacy.config.impl.plugins.PrivacyFeaturePlugin
import com.duckduckgo.privacy.config.impl.plugins.PrivacyFeaturePluginPoint
import com.duckduckgo.privacy.config.store.ALL_MIGRATIONS
import com.duckduckgo.privacy.config.store.PrivacyConfigDatabase
import com.duckduckgo.privacy.config.store.PrivacyConfigRepository
import com.duckduckgo.privacy.config.store.PrivacyFeatureTogglesDataStore
import com.duckduckgo.privacy.config.store.PrivacyFeatureTogglesRepository
import com.duckduckgo.privacy.config.store.PrivacyFeatureTogglesSharedPreferences
import com.duckduckgo.privacy.config.store.RealPrivacyConfigRepository
import com.duckduckgo.privacy.config.store.RealPrivacyFeatureTogglesRepository
import com.duckduckgo.privacy.config.store.features.contentblocking.ContentBlockingRepository
Expand Down Expand Up @@ -99,6 +102,7 @@ class DatabaseModule {
return Room.databaseBuilder(context, PrivacyConfigDatabase::class.java, "privacy_config.db")
.enableMultiInstanceInvalidation()
.fallbackToDestructiveMigration()
.addMigrations(*ALL_MIGRATIONS)
.build()
}

Expand Down Expand Up @@ -126,6 +130,12 @@ class DatabaseModule {
return GpcSharedPreferences(context)
}

@Singleton
@Provides
fun providePrivacyFeatureTogglesDataStore(context: Context): PrivacyFeatureTogglesDataStore {
return PrivacyFeatureTogglesSharedPreferences(context)
}

@Singleton
@Provides
fun provideGpcRepository(gpcDataStore: GpcDataStore, database: PrivacyConfigDatabase, @AppCoroutineScope coroutineScope: CoroutineScope, dispatcherProvider: DispatcherProvider): GpcRepository {
Expand All @@ -146,7 +156,7 @@ class DatabaseModule {

@Singleton
@Provides
fun providePrivacyFeatureTogglesRepository(database: PrivacyConfigDatabase): PrivacyFeatureTogglesRepository {
return RealPrivacyFeatureTogglesRepository(database)
fun providePrivacyFeatureTogglesRepository(privacyFeatureTogglesDataStore: PrivacyFeatureTogglesDataStore): PrivacyFeatureTogglesRepository {
return RealPrivacyFeatureTogglesRepository(privacyFeatureTogglesDataStore)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,23 @@

package com.duckduckgo.privacy.config.impl.plugins

import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.di.scopes.AppObjectGraph
import com.duckduckgo.feature.toggles.api.FeatureTogglesPlugin
import com.duckduckgo.feature.toggles.api.FeatureName
import com.duckduckgo.privacy.config.api.PrivacyFeatureName
import com.duckduckgo.privacy.config.store.PrivacyFeatureToggles
import com.duckduckgo.privacy.config.store.PrivacyFeatureTogglesRepository
import com.squareup.anvil.annotations.ContributesMultibinding
import kotlinx.coroutines.runBlocking
import javax.inject.Inject

@ContributesMultibinding(AppObjectGraph::class)
class PrivacyFeatureTogglesPlugin @Inject constructor(private val privacyFeatureTogglesRepository: PrivacyFeatureTogglesRepository, private val dispatcherProvider: DispatcherProvider) :
class PrivacyFeatureTogglesPlugin @Inject constructor(private val privacyFeatureTogglesRepository: PrivacyFeatureTogglesRepository) :
FeatureTogglesPlugin {

override fun isEnabled(featureName: FeatureName, defaultValue: Boolean): Boolean? {
return runBlocking(dispatcherProvider.io()) {
if (featureName is PrivacyFeatureName) {
val privacyFeature: PrivacyFeatureToggles? = privacyFeatureTogglesRepository.get(featureName.value)
privacyFeature?.let {
return@runBlocking privacyFeature.enabled
}
return@runBlocking defaultValue
}
return@runBlocking null
return if (featureName is PrivacyFeatureName) {
privacyFeatureTogglesRepository.get(featureName.value, defaultValue)
} else {
null
}
}

}
189 changes: 60 additions & 129 deletions privacy-config/privacy-config-impl/src/main/res/raw/privacy_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,57 @@
"contentBlocking": {
"state": "enabled",
"exceptions": [
{
"domain": "pnc.com",
"reason": "Login issues"
},
{
"domain": "www.corsair.com",
"reason": "Missing content"
},
{
"domain": "www.eurogamer.net",
"reason": "Hard adwall"
},
{
"domain": "53.com",
"reason": "Broken sign in"
},
{
"domain": "www.costco.com",
"reason": "Broken sign in"
},
{
"domain": "www.livenewsnow.com",
"reason": "Adblocker wall"
},
{
"domain": "rp5.ru",
"reason": "Adblocker wall"
},
{
"domain": "easyjet.com",
"reason": "Broken site content"
},
{
"domain": "id.me",
"reason": "Broken logins"
},
{
"domain": "stubhub.com",
"reason": "Missing site content"
},
{
"domain": "riteaid.com",
"reason": "Missing site content"
},
{
"domain": "zoosk.com",
"reason": "Mobile site banner breakage"
},
{
"domain": "pch.com",
"reason": "Broken site reports"
}
]
},
Expand All @@ -27,16 +71,7 @@
},
"trackingCookies3p": {
"state": "enabled",
"exceptions": [
{
"domain": "hangouts.google.com",
"reason": "site breakage"
},
{
"domain": "docs.google.com",
"reason": "site breakage"
}
],
"exceptions": [],
"settings": {
"excludedCookieDomains": [
{
Expand Down Expand Up @@ -138,6 +173,10 @@
{
"domain": "docs.google.com",
"reason": "site breakage"
},
{
"domain": "btsport-utils-prod.akamaized.net",
"reason": "broken videos"
}
]
}
Expand All @@ -160,127 +199,21 @@
"state": "enabled",
"exceptions": [
{
"domain": "www.delta.com",
"reason": "site breakage"
},
{
"domain": "www.johnlewis.com",
"reason": "site breakage"
},
{
"domain": "warzone.com",
"reason": "site breakage"
},
{
"domain": "skribbl.io",
"reason": "site breakage"
},
{
"domain": "kroger.com",
"reason": "site breakage"
},
{
"domain": "bakersplus.com",
"reason": "site breakage"
},
{
"domain": "citymarket.com",
"reason": "site breakage"
},
{
"domain": "dillons.com",
"reason": "site breakage"
},
{
"domain": "food4less.com",
"reason": "site breakage"
},
{
"domain": "foodsco.net",
"reason": "site breakage"
},
{
"domain": "fredmeyer.com",
"reason": "site breakage"
},
{
"domain": "frysfood.com",
"reason": "site breakage"
},
{
"domain": "gerbes.com",
"reason": "site breakage"
},
{
"domain": "jaycfoods.com",
"reason": "site breakage"
},
{
"domain": "kingsoopers.com",
"reason": "site breakage"
},
{
"domain": "marianos.com",
"reason": "site breakage"
},
{
"domain": "metromarket.net",
"reason": "site breakage"
},
{
"domain": "pay-less.com",
"reason": "site breakage"
},
{
"domain": "picknsave.com",
"reason": "site breakage"
},
{
"domain": "qfc.com",
"reason": "site breakage"
},
{
"domain": "ralphs.com",
"reason": "site breakage"
},
{
"domain": "smithsfoodanddrug.com",
"reason": "site breakage"
},
{
"domain": "pnc.com",
"reason": "site breakage"
},
{
"domain": "www.coolmathgames.com",
"reason": "site breakage"
},
{
"domain": "textfree.us",
"reason": "site breakage"
},
{
"domain": "www.academy.com",
"reason": "site breakage"
},
{
"domain": "edd.ca.gov",
"reason": "login issues"
},
{
"domain": "chase.com",
"reason": "Login"
"domain": "usaa.com",
"reason": "Broken login"
}
]
},
"fingerprintingAudio": {
"state": "disabled",
"exceptions": [
{
"domain": "youtube.com"
"domain": "youtube.com",
"reason": "site breakage"
},
{
"domain": "meet.google.com"
"domain": "meet.google.com",
"reason": "site breakage"
}
]
},
Expand All @@ -304,10 +237,12 @@
"state": "enabled",
"exceptions": [
{
"domain": "play.geforcenow.com"
"domain": "play.geforcenow.com",
"reason": "site breakage"
},
{
"domain": "stadia.google.com"
"domain": "stadia.google.com",
"reason": "site breakage"
}
]
},
Expand Down Expand Up @@ -369,7 +304,7 @@
]
}
},
"version": 1628840233002,
"version": 1634121326614,
"unprotectedTemporary": [
{
"domain": "inlandbank.com",
Expand Down Expand Up @@ -427,10 +362,6 @@
"domain": "tiaa.org",
"reason": "site breakage"
},
{
"domain": "53.com",
"reason": "site breakage"
},
{
"domain": "fidelity.com",
"reason": "site breakage"
Expand Down
Loading

0 comments on commit 42bfff3

Please sign in to comment.