Skip to content

Commit a8b8bdf

Browse files
committed
Merge branch 'hotfix/5.85.1' into main
2 parents 40c1e8e + 723b137 commit a8b8bdf

File tree

9 files changed

+52037
-45639
lines changed

9 files changed

+52037
-45639
lines changed

app/schemas/com.duckduckgo.app.global.db.AppDatabase/33.json

Lines changed: 866 additions & 0 deletions
Large diffs are not rendered by default.

app/src/androidTest/java/com/duckduckgo/app/global/db/AppDatabaseTest.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ class AppDatabaseTest {
355355
createDatabaseAndMigrate(31, 32, migrationsProvider.MIGRATION_31_TO_32)
356356
}
357357

358+
@Test
359+
fun whenMigratingFromVersion32o33ThenValidationSucceeds() {
360+
createDatabaseAndMigrate(32, 33, migrationsProvider.MIGRATION_32_TO_33)
361+
}
362+
358363
private fun givenUserStageIs(database: SupportSQLiteDatabase, appStage: AppStage) {
359364
database.execSQL("INSERT INTO `userStage` values (1, '${appStage.name}') ")
360365
}

app/src/androidTest/java/com/duckduckgo/app/trackerdetection/TdsTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ class TdsTest {
3838
}
3939

4040
companion object {
41-
private const val DEFAULT_TDS_HASH_VALUE = 2104673228
41+
private const val DEFAULT_TDS_HASH_VALUE = -160289387
4242
}
4343
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2021 DuckDuckGo
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.duckduckgo.app.trackerdetection.api
18+
19+
import okhttp3.Headers
20+
import org.junit.Assert.*
21+
import org.junit.Test
22+
23+
class TrackerDataDownloaderKtTest {
24+
25+
@Test
26+
fun whenExtractETagAndContainsPrefixAndQuotesThenReturnETag() {
27+
val headers = Headers.headersOf("eTag", "W/\"123456789\"")
28+
assertEquals(ETAG, headers.extractETag())
29+
}
30+
31+
@Test
32+
fun whenExtractETagAndContainsQuotesThenReturnETag() {
33+
val headers = Headers.headersOf("eTag", "\"123456789\"")
34+
assertEquals(ETAG, headers.extractETag())
35+
}
36+
37+
@Test
38+
fun whenExtractETagAndDoesNotContainsQuotesAndPrefixThenReturnETag() {
39+
val headers = Headers.headersOf("eTag", "123456789")
40+
assertEquals(ETAG, headers.extractETag())
41+
}
42+
43+
companion object {
44+
const val ETAG = "123456789"
45+
}
46+
}

app/src/main/java/com/duckduckgo/app/global/db/AppDatabase.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import com.duckduckgo.app.usage.search.SearchCountDao
6767
import com.duckduckgo.app.usage.search.SearchCountEntity
6868

6969
@Database(
70-
exportSchema = true, version = 32,
70+
exportSchema = true, version = 33,
7171
entities = [
7272
TdsTracker::class,
7373
TdsEntity::class,
@@ -405,6 +405,15 @@ class MigrationsProvider(
405405
}
406406
}
407407

408+
val MIGRATION_32_TO_33: Migration = object : Migration(32, 33) {
409+
override fun migrate(database: SupportSQLiteDatabase) {
410+
database.execSQL("DELETE FROM tds_domain_entity")
411+
database.execSQL("DELETE FROM tds_entity")
412+
database.execSQL("DELETE FROM tds_tracker")
413+
database.execSQL("DELETE FROM tdsMetadata")
414+
}
415+
}
416+
408417
val BOOKMARKS_DB_ON_CREATE = object : RoomDatabase.Callback() {
409418
override fun onCreate(database: SupportSQLiteDatabase) {
410419
MIGRATION_29_TO_30.migrate(database)
@@ -449,7 +458,8 @@ class MigrationsProvider(
449458
MIGRATION_28_TO_29,
450459
MIGRATION_29_TO_30,
451460
MIGRATION_30_TO_31,
452-
MIGRATION_31_TO_32
461+
MIGRATION_31_TO_32,
462+
MIGRATION_32_TO_33
453463
)
454464

455465
@Deprecated(

app/src/main/java/com/duckduckgo/app/trackerdetection/TrackerDataLoader.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,6 @@ class TrackerDataLoader @Inject constructor(
8686
}
8787

8888
companion object {
89-
const val DEFAULT_ETAG = "5c5dda7f1873f3183b141c0739a187ca"
89+
const val DEFAULT_ETAG = "961c7d692c985496126cad2d64231243"
9090
}
9191
}

app/src/main/java/com/duckduckgo/app/trackerdetection/api/TrackerDataDownloader.kt

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ import com.duckduckgo.app.global.filterBlankItems
2222
import com.duckduckgo.app.global.store.BinaryDataStore
2323
import com.duckduckgo.app.trackerdetection.Client.ClientName.*
2424
import com.duckduckgo.app.trackerdetection.TrackerDataLoader
25-
import com.duckduckgo.app.trackerdetection.db.TdsTrackerDao
25+
import com.duckduckgo.app.trackerdetection.db.TdsMetadataDao
2626
import com.duckduckgo.app.trackerdetection.db.TemporaryTrackingWhitelistDao
2727
import com.duckduckgo.app.trackerdetection.model.TemporaryTrackingWhitelistedDomain
2828
import io.reactivex.Completable
29+
import okhttp3.Headers
2930
import timber.log.Timber
3031
import java.io.IOException
3132
import javax.inject.Inject
@@ -34,9 +35,9 @@ class TrackerDataDownloader @Inject constructor(
3435
private val trackerListService: TrackerListService,
3536
private val binaryDataStore: BinaryDataStore,
3637
private val trackerDataLoader: TrackerDataLoader,
37-
private val tdsTrackerDao: TdsTrackerDao,
3838
private val temporaryTrackingWhitelistDao: TemporaryTrackingWhitelistDao,
39-
private val appDatabase: AppDatabase
39+
private val appDatabase: AppDatabase,
40+
private val metadataDao: TdsMetadataDao
4041
) {
4142

4243
fun downloadTds(): Completable {
@@ -51,17 +52,16 @@ class TrackerDataDownloader @Inject constructor(
5152
if (!response.isSuccessful) {
5253
throw IOException("Status: ${response.code()} - ${response.errorBody()?.string()}")
5354
}
54-
if (response.isCached && tdsTrackerDao.count() != 0) {
55-
Timber.d("Tds data already cached and stored")
56-
return@fromAction
57-
}
5855

59-
Timber.d("Updating tds data from server")
6056
val body = response.body()!!
61-
val eTag = response.headers()["eTag"]?.removeSurrounding("W/\"", "\"").orEmpty() // removes weak eTag validator
62-
appDatabase.runInTransaction {
63-
trackerDataLoader.persistTds(eTag, body)
64-
trackerDataLoader.loadTrackers()
57+
val eTag = response.headers().extractETag()
58+
val oldEtag = metadataDao.eTag()
59+
if (eTag != oldEtag) {
60+
Timber.d("Updating tds data from server")
61+
appDatabase.runInTransaction {
62+
trackerDataLoader.persistTds(eTag, body)
63+
trackerDataLoader.loadTrackers()
64+
}
6565
}
6666
}
6767
}
@@ -107,3 +107,7 @@ class TrackerDataDownloader @Inject constructor(
107107
}
108108
}
109109
}
110+
111+
fun Headers.extractETag(): String {
112+
return this["eTag"]?.removePrefix("W/")?.removeSurrounding("\"", "\"").orEmpty() // removes weak eTag validator
113+
}

0 commit comments

Comments
 (0)