Skip to content

Commit 928a82c

Browse files
authored
Create module for malicious sites protection (#5317)
Task/Issue URL: https://app.asana.com/0/0/1207943168535186/f ### Description ### Steps to test this PR _Feature 1_ - [ ] - [ ] ### UI changes | Before | After | | ------ | ----- | !(Upload before screenshot)|(Upload after screenshot)|
1 parent c9b3f86 commit 928a82c

File tree

9 files changed

+243
-0
lines changed

9 files changed

+243
-0
lines changed

app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ fladle {
215215
}
216216

217217
dependencies {
218+
implementation project(":malicious-site-protection-impl")
219+
implementation project(":malicious-site-protection-api")
218220
implementation project(":custom-tabs-impl")
219221
implementation project(":custom-tabs-api")
220222
implementation project(":duckplayer-impl")

malicious-site-protection/malicious-site-protection-api/.gitignore

Whitespace-only changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
plugins {
18+
id 'com.android.library'
19+
id 'kotlin-android'
20+
}
21+
22+
apply from: "$rootProject.projectDir/gradle/android-library.gradle"
23+
24+
android {
25+
namespace 'com.duckduckgo.malicioussiteprotection.api'
26+
}
27+
28+
dependencies {
29+
implementation Kotlin.stdlib.jdk7
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2024 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.malicioussiteprotection.api
18+
19+
interface MaliciousSiteProtection
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
plugins {
18+
id 'com.android.library'
19+
id 'kotlin-android'
20+
id 'com.squareup.anvil'
21+
id 'com.google.devtools.ksp'
22+
}
23+
24+
apply from: "$rootProject.projectDir/gradle/android-library.gradle"
25+
26+
dependencies {
27+
implementation project(":malicious-site-protection-api")
28+
29+
anvil project(path: ':anvil-compiler')
30+
implementation project(path: ':anvil-annotations')
31+
implementation project(path: ':di')
32+
ksp AndroidX.room.compiler
33+
34+
implementation KotlinX.coroutines.android
35+
implementation AndroidX.core.ktx
36+
implementation Google.dagger
37+
38+
implementation project(path: ':common-utils')
39+
40+
implementation "com.squareup.logcat:logcat:_"
41+
implementation JakeWharton.timber
42+
43+
implementation Google.android.material
44+
45+
testImplementation Testing.junit4
46+
testImplementation "org.mockito.kotlin:mockito-kotlin:_"
47+
testImplementation project(path: ':common-test')
48+
testImplementation CashApp.turbine
49+
testImplementation Testing.robolectric
50+
testImplementation(KotlinX.coroutines.test) {
51+
// https://github.com/Kotlin/kotlinx.coroutines/issues/2023
52+
// conflicts with mockito due to direct inclusion of byte buddy
53+
exclude group: "org.jetbrains.kotlinx", module: "kotlinx-coroutines-debug"
54+
}
55+
56+
coreLibraryDesugaring Android.tools.desugarJdkLibs
57+
}
58+
59+
android {
60+
namespace "com.duckduckgo.malicioussiteprotection.impl"
61+
anvil {
62+
generateDaggerFactories = true // default is false
63+
}
64+
lint {
65+
baseline file("lint-baseline.xml")
66+
}
67+
testOptions {
68+
unitTests {
69+
includeAndroidResources = true
70+
}
71+
}
72+
compileOptions {
73+
coreLibraryDesugaringEnabled = true
74+
}
75+
}
76+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<issues format="6" by="lint 8.5.1" type="baseline" client="gradle" dependencies="false" name="AGP (8.5.1)" variant="all" version="8.5.1">
3+
4+
</issues>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2024 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.malicioussiteprotection.impl
18+
19+
import com.duckduckgo.anvil.annotations.ContributesRemoteFeature
20+
import com.duckduckgo.di.scopes.AppScope
21+
import com.duckduckgo.feature.toggles.api.Toggle
22+
23+
@ContributesRemoteFeature(
24+
scope = AppScope::class,
25+
featureName = "maliciousSiteProtection",
26+
)
27+
/**
28+
* This is the class that represents the maliciousSiteProtection feature flags
29+
*/
30+
interface MaliciousSiteProtectionFeature {
31+
/**
32+
* @return `true` when the remote config has the global "maliciousSiteProtection" feature flag enabled
33+
* If the remote feature is not present defaults to `false`
34+
*/
35+
@Toggle.InternalAlwaysEnabled
36+
@Toggle.DefaultValue(false)
37+
fun self(): Toggle
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2024 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.malicioussiteprotection.impl
18+
19+
import com.duckduckgo.app.di.AppCoroutineScope
20+
import com.duckduckgo.app.di.IsMainProcess
21+
import com.duckduckgo.common.utils.DispatcherProvider
22+
import com.duckduckgo.di.scopes.AppScope
23+
import com.duckduckgo.malicioussiteprotection.api.MaliciousSiteProtection
24+
import com.duckduckgo.privacy.config.api.PrivacyConfigCallbackPlugin
25+
import com.squareup.anvil.annotations.ContributesBinding
26+
import javax.inject.Inject
27+
import kotlinx.coroutines.CoroutineScope
28+
import kotlinx.coroutines.launch
29+
import org.json.JSONObject
30+
31+
@ContributesBinding(AppScope::class, MaliciousSiteProtection::class)
32+
@ContributesBinding(AppScope::class, PrivacyConfigCallbackPlugin::class)
33+
class RealMaliciousSiteProtection @Inject constructor(
34+
private val dispatchers: DispatcherProvider,
35+
private val maliciousSiteProtectionFeature: MaliciousSiteProtectionFeature,
36+
@IsMainProcess private val isMainProcess: Boolean,
37+
@AppCoroutineScope private val appCoroutineScope: CoroutineScope,
38+
) : MaliciousSiteProtection, PrivacyConfigCallbackPlugin {
39+
40+
private var isFeatureEnabled = false
41+
private var hashPrefixUpdateFrequency = 20L
42+
private var filterSetUpdateFrequency = 720L
43+
44+
init {
45+
if (isMainProcess) {
46+
loadToMemory()
47+
}
48+
}
49+
50+
override fun onPrivacyConfigDownloaded() {
51+
loadToMemory()
52+
}
53+
54+
private fun loadToMemory() {
55+
appCoroutineScope.launch(dispatchers.io()) {
56+
isFeatureEnabled = maliciousSiteProtectionFeature.self().isEnabled()
57+
maliciousSiteProtectionFeature.self().getSettings()?.let {
58+
JSONObject(it).let { settings ->
59+
hashPrefixUpdateFrequency = settings.getLong("hashPrefixUpdateFrequency")
60+
filterSetUpdateFrequency = settings.getLong("filterSetUpdateFrequency")
61+
}
62+
}
63+
}
64+
}
65+
}

malicious-site-protection/readme.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Feature Name
2+
3+
In-browser feature to detect phishing and malware sites.
4+
5+
## Who can help you better understand this feature?
6+
- ❓ Cris Barreiro
7+
8+
## More information
9+
- [Asana: feature documentation](https://app.asana.com/0/1208717418466383/1199621914667995/f)

0 commit comments

Comments
 (0)