Add advanced option for DNS over HTTPS via Cloudflare (closes #3377)

(cherry picked from commit 3645d19135683cf8d076f560619c1b47c7b21d00)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt
This commit is contained in:
arkon 2020-06-23 22:42:53 -04:00 committed by Jobobby04
parent fe9ccd473d
commit 3e9e42271e
6 changed files with 62 additions and 15 deletions

View File

@ -187,6 +187,7 @@ dependencies {
final okhttp_version = '4.7.2' final okhttp_version = '4.7.2'
implementation "com.squareup.okhttp3:okhttp:$okhttp_version" implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_version" implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_version"
implementation "com.squareup.okhttp3:okhttp-dnsoverhttps:$okhttp_version"
implementation 'com.squareup.okio:okio:2.6.0' implementation 'com.squareup.okio:okio:2.6.0'
// TLS 1.3 support for Android < 10 // TLS 1.3 support for Android < 10

View File

@ -161,6 +161,8 @@ object PreferenceKeys {
const val searchPinnedSourcesOnly = "search_pinned_sources_only" const val searchPinnedSourcesOnly = "search_pinned_sources_only"
const val enableDoh = "enable_doh"
fun trackUsername(syncId: Int) = "pref_mangasync_username_$syncId" fun trackUsername(syncId: Int) = "pref_mangasync_username_$syncId"
fun trackPassword(syncId: Int) = "pref_mangasync_password_$syncId" fun trackPassword(syncId: Int) = "pref_mangasync_password_$syncId"

View File

@ -240,6 +240,8 @@ class PreferencesHelper(val context: Context) {
fun trustedSignatures() = flowPrefs.getStringSet("trusted_signatures", emptySet()) fun trustedSignatures() = flowPrefs.getStringSet("trusted_signatures", emptySet())
fun enableDoh() = prefs.getBoolean(Keys.enableDoh, false)
// --> AZ J2K CHERRYPICKING // --> AZ J2K CHERRYPICKING
fun defaultMangaOrder() = flowPrefs.getString("default_manga_order", "") fun defaultMangaOrder() = flowPrefs.getString("default_manga_order", "")

View File

@ -2,14 +2,21 @@ package eu.kanade.tachiyomi.network
import android.content.Context import android.content.Context
import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import java.io.File import java.io.File
import java.net.InetAddress
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import okhttp3.Cache import okhttp3.Cache
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.dnsoverhttps.DnsOverHttps
import okhttp3.logging.HttpLoggingInterceptor import okhttp3.logging.HttpLoggingInterceptor
import uy.kohesive.injekt.injectLazy
/* SY --> */ open /* SY <-- */ class NetworkHelper(context: Context) { /* SY --> */ open /* SY <-- */ class NetworkHelper(context: Context) {
private val preferences: PreferencesHelper by injectLazy()
private val cacheDir = File(context.cacheDir, "network_cache") private val cacheDir = File(context.cacheDir, "network_cache")
private val cacheSize = 5L * 1024 * 1024 // 5 MiB private val cacheSize = 5L * 1024 * 1024 // 5 MiB
@ -30,6 +37,27 @@ import okhttp3.logging.HttpLoggingInterceptor
builder.addInterceptor(httpLoggingInterceptor) builder.addInterceptor(httpLoggingInterceptor)
} }
if (preferences.enableDoh()) {
builder.dns(
DnsOverHttps.Builder().client(builder.build())
.url("https://cloudflare-dns.com/dns-query".toHttpUrl())
.bootstrapDnsHosts(
listOf(
InetAddress.getByName("162.159.36.1"),
InetAddress.getByName("162.159.46.1"),
InetAddress.getByName("1.1.1.1"),
InetAddress.getByName("1.0.0.1"),
InetAddress.getByName("162.159.132.53"),
InetAddress.getByName("2606:4700:4700::1111"),
InetAddress.getByName("2606:4700:4700::1001"),
InetAddress.getByName("2606:4700:4700::0064"),
InetAddress.getByName("2606:4700:4700::6400")
)
)
.build()
)
}
builder.build() builder.build()
} }

View File

@ -18,7 +18,7 @@ import eu.kanade.tachiyomi.data.cache.ChapterCache
import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.data.library.LibraryUpdateService
import eu.kanade.tachiyomi.data.library.LibraryUpdateService.Target import eu.kanade.tachiyomi.data.library.LibraryUpdateService.Target
import eu.kanade.tachiyomi.data.preference.PreferenceKeys import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.NetworkHelper
import eu.kanade.tachiyomi.source.SourceManager.Companion.DELEGATED_SOURCES import eu.kanade.tachiyomi.source.SourceManager.Companion.DELEGATED_SOURCES
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
@ -97,14 +97,6 @@ class SettingsAdvancedController : SettingsController() {
onClick { clearChapterCache() } onClick { clearChapterCache() }
} }
preference {
titleRes = R.string.pref_clear_cookies
onClick {
network.cookieManager.removeAll()
activity?.toast(R.string.cookies_cleared)
}
}
preference { preference {
titleRes = R.string.pref_clear_database titleRes = R.string.pref_clear_database
summaryRes = R.string.pref_clear_database_summary summaryRes = R.string.pref_clear_database_summary
@ -117,6 +109,25 @@ class SettingsAdvancedController : SettingsController() {
} }
} }
preferenceCategory {
titleRes = R.string.label_data
preference {
titleRes = R.string.pref_clear_cookies
onClick {
network.cookieManager.removeAll()
activity?.toast(R.string.cookies_cleared)
}
}
switchPreference {
key = Keys.enableDoh
titleRes = R.string.pref_dns_over_https
summaryRes = R.string.pref_dns_over_https_summary
defaultValue = false
}
}
preferenceCategory { preferenceCategory {
titleRes = R.string.label_library titleRes = R.string.label_library
@ -141,7 +152,7 @@ class SettingsAdvancedController : SettingsController() {
switchPreference { switchPreference {
title = "Enable integrated hentai features" title = "Enable integrated hentai features"
summary = "This is a experimental feature that will disable all hentai features if toggled off" summary = "This is a experimental feature that will disable all hentai features if toggled off"
key = PreferenceKeys.eh_is_hentai_enabled key = Keys.eh_is_hentai_enabled
defaultValue = true defaultValue = true
onChange { onChange {
@ -202,13 +213,13 @@ class SettingsAdvancedController : SettingsController() {
switchPreference { switchPreference {
title = "Enable delegated sources" title = "Enable delegated sources"
key = PreferenceKeys.eh_delegateSources key = Keys.eh_delegateSources
defaultValue = true defaultValue = true
summary = "Apply ${context.getString(R.string.app_name)} enhancements to the following sources if they are installed: ${DELEGATED_SOURCES.values.map { it.sourceName }.distinct().joinToString()}" summary = "Apply ${context.getString(R.string.app_name)} enhancements to the following sources if they are installed: ${DELEGATED_SOURCES.values.map { it.sourceName }.distinct().joinToString()}"
} }
intListPreference { intListPreference {
key = PreferenceKeys.eh_logLevel key = Keys.eh_logLevel
title = "Log level" title = "Log level"
entries = EHLogLevel.values().map { entries = EHLogLevel.values().map {
@ -222,7 +233,7 @@ class SettingsAdvancedController : SettingsController() {
switchPreference { switchPreference {
title = "Enable source blacklist" title = "Enable source blacklist"
key = PreferenceKeys.eh_enableSourceBlacklist key = Keys.eh_enableSourceBlacklist
defaultValue = true defaultValue = true
summary = "Hide extensions/sources that are incompatible with ${context.getString(R.string.app_name)}. Force-restart app after changing." summary = "Hide extensions/sources that are incompatible with ${context.getString(R.string.app_name)}. Force-restart app after changing."
} }

View File

@ -359,13 +359,16 @@
<string name="restoring_backup_canceled">Canceled restore</string> <string name="restoring_backup_canceled">Canceled restore</string>
<!-- Advanced section --> <!-- Advanced section -->
<string name="label_network">Network</string>
<string name="pref_clear_cookies">Clear cookies</string>
<string name="pref_dns_over_https" translatable="false">DNS over HTTPS (Cloudflare)</string>
<string name="pref_dns_over_https_summary">Requires app restart to take effect</string>
<string name="cookies_cleared">Cookies cleared</string>
<string name="label_data">Data</string> <string name="label_data">Data</string>
<string name="pref_clear_chapter_cache">Clear chapter cache</string> <string name="pref_clear_chapter_cache">Clear chapter cache</string>
<string name="used_cache">Used: %1$s</string> <string name="used_cache">Used: %1$s</string>
<string name="cache_deleted">Cache cleared. %1$d files have been deleted</string> <string name="cache_deleted">Cache cleared. %1$d files have been deleted</string>
<string name="cache_delete_error">An error occurred while clearing cache</string> <string name="cache_delete_error">An error occurred while clearing cache</string>
<string name="pref_clear_cookies">Clear cookies</string>
<string name="cookies_cleared">Cookies cleared</string>
<string name="choices_reset">Dialog choices reset</string> <string name="choices_reset">Dialog choices reset</string>
<string name="pref_clear_database">Clear database</string> <string name="pref_clear_database">Clear database</string>
<string name="pref_clear_database_summary">Delete history for manga that are not saved in your library</string> <string name="pref_clear_database_summary">Delete history for manga that are not saved in your library</string>