Commit 8f78f15d authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Show a selection of default host sources in f-droid builds

parent e10f2428
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="hide_adblocking_servers">false</bool>
<bool name="add_default_hostsources">true</bool>
</resources>
\ No newline at end of file
......@@ -355,9 +355,27 @@ class DnsRuleActivity : BaseActivity() {
dnsRule = rule
text.text = rule.host
}
override fun destroy() {}
}
companion object {
val defaultHostSources:List<HostSource> by lazy {
mutableListOf(
HostSource("Energized Basic", "https://raw.githubusercontent.com/EnergizedProtection/block/master/basic/formats/domains.txt"),
HostSource("Energized Blu", "https://raw.githubusercontent.com/EnergizedProtection/block/master/blu/formats/domains.txt"),
HostSource("Energized Spark", "https://raw.githubusercontent.com/EnergizedProtection/block/master/spark/formats/domains.txt"),
HostSource("Energized Porn", "https://raw.githubusercontent.com/EnergizedProtection/block/master/porn/formats/domains.txt"),
HostSource("Energized Ultimate", "https://raw.githubusercontent.com/EnergizedProtection/block/master/ultimate/formats/domains.txt"),
HostSource("AdAway", "https://adaway.org/hosts.txt"),
HostSource("StevenBlack unified", "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"),
HostSource("CoinBlockerList", "https://zerodot1.gitlab.io/CoinBlockerLists/hosts"),
HostSource("Malewaredomainlist.com", "http://www.malwaredomainlist.com/hostslist/hosts.txt"),
HostSource("PiHoleBlocklist Android tracking", "https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/android-tracking.txt"),
HostSource("Quidsup NoTrack Tracker Blocklist", "https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-blocklist.txt"),
HostSource("someonewhocares.org", "https://someonewhocares.org/hosts/zero/hosts")
).apply {
forEach { it.enabled = false }
}
}
}
}
\ No newline at end of file
......@@ -16,6 +16,7 @@ import com.frostnerd.navigationdraweractivity.items.createMenu
import com.frostnerd.navigationdraweractivity.items.singleInstanceFragment
import com.frostnerd.preferenceskt.typedpreferences.TypedPreferences
import com.frostnerd.smokescreen.*
import com.frostnerd.smokescreen.database.getDatabase
import com.frostnerd.smokescreen.dialog.ChangelogDialog
import com.frostnerd.smokescreen.dialog.CrashReportingEnableDialog
import com.frostnerd.smokescreen.dialog.NewServerDialog
......@@ -108,6 +109,10 @@ class MainActivity : NavigationDrawerActivity() {
dialog.dismiss()
}, null)
}
if(resources.getBoolean(R.bool.add_default_hostsources) && !getPreferences().hostSourcesPopulated) {
getDatabase().hostSourceRepository().insertAllAsync(DnsRuleActivity.defaultHostSources)
getPreferences().hostSourcesPopulated = true
}
}
override fun createDrawerItems(): MutableList<DrawerItem> {
......
......@@ -57,7 +57,7 @@ interface DnsRuleDao {
@Query("SELECT COUNT(*) FROM DnsRule WHERE importedFrom IS NULL")
fun getUserCount():Long
@Query("SELECT CASE WHEN :type=28 THEN IFNULL(ipv6Target, target) ELSE target END FROM DnsRule WHERE host=:host AND (type = :type OR type=255) AND (importedFrom is NULL OR (SELECT enabled FROM HostSource h WHERE h.id=importedFrom) = 1) AND (importedFrom IS NOT NULL OR :useUserRules=1) LIMIT 1")
@Query("SELECT CASE WHEN :type=28 THEN IFNULL(ipv6Target, target) ELSE target END FROM DnsRule WHERE host=:host AND (type = :type OR type=255) AND (importedFrom is NULL OR IFNULL((SELECT enabled FROM HostSource h WHERE h.id=importedFrom),0) = 1) AND (importedFrom IS NOT NULL OR :useUserRules=1) LIMIT 1")
fun findRuleTarget(host: String, type: Record.TYPE, useUserRules:Boolean): String?
@Query("DELETE FROM DnsRule WHERE importedFrom=:sourceId")
......
......@@ -28,6 +28,9 @@ interface HostSourceDao {
@Insert
fun insert(hostSource: HostSource)
@Insert
fun insertAll(hostSources: Collection<HostSource>)
@Update
fun update(hostSource: HostSource)
......
......@@ -24,4 +24,10 @@ class HostSourceRepository(val hostSourceDao: HostSourceDao) {
hostSourceDao.delete(hostSource)
}
}
fun insertAllAsync(sources:Collection<HostSource>, coroutineScope: CoroutineScope = GlobalScope) {
coroutineScope.launch {
hostSourceDao.insertAll(sources)
}
}
}
\ No newline at end of file
......@@ -241,6 +241,7 @@ class AppSettingsSharedPreferences(context: Context) : AppSettings, SimpleTypedP
var customHostsEnabled:Boolean by booleanPref("custom_hosts", true)
var dnsRulesEnabled:Boolean by booleanPref("dns_rules_enabled", false)
var hostSourcesPopulated:Boolean by booleanPref("dns_rules_sources_populated", false)
}
fun AppSettings.Companion.fromSharedPreferences(context: Context): AppSettingsSharedPreferences {
......
......@@ -2,6 +2,7 @@
<resources>
<bool name="keep_service_alive">true</bool>
<bool name="hide_adblocking_servers">true</bool>
<bool name="add_default_hostsources">false</bool>
<string-array name="interface_address_prefixes">
<item>192.168.0/24</item>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment