DoH Google + More updates to cloudflare / useragent from upstream

Co-Authored-By: arkon <4098258+arkon@users.noreply.github.com>
This commit is contained in:
Jays2Kings 2021-04-14 20:14:59 -04:00
parent 331d2fcd9e
commit 72f297f457
12 changed files with 110 additions and 42 deletions

View File

@ -130,9 +130,9 @@ dependencies {
implementation("com.github.tfcporciuncula:flow-preferences:1.3.4")
// Network client
implementation("com.squareup.okhttp3:okhttp:${Versions.OKHTTP}")
implementation("com.squareup.okhttp3:logging-interceptor:${Versions.OKHTTP}")
implementation("com.squareup.okhttp3:okhttp-dnsoverhttps:${Versions.OKHTTP}")
implementation("com.squareup.okhttp3:okhttp:${Versions.okhttp}")
implementation("com.squareup.okhttp3:logging-interceptor:${Versions.okhttp}")
implementation("com.squareup.okhttp3:okhttp-dnsoverhttps:${Versions.okhttp}")
implementation("com.squareup.okio:okio:2.10.0")
// Chucker

View File

@ -1,13 +1,17 @@
package eu.kanade.tachiyomi
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.data.backup.BackupCreatorJob
import eu.kanade.tachiyomi.data.download.DownloadProvider
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
import eu.kanade.tachiyomi.data.preference.PreferenceKeys
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.data.updater.UpdaterJob
import eu.kanade.tachiyomi.extension.ExtensionUpdateJob
import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE
import eu.kanade.tachiyomi.ui.library.LibraryPresenter
import eu.kanade.tachiyomi.util.system.toast
import uy.kohesive.injekt.Injekt
@ -96,6 +100,17 @@ object Migrations {
context.toast(R.string.myanimelist_relogin)
}
}
if (oldVersion < 71) {
// Migrate DNS over HTTPS setting
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
val wasDohEnabled = prefs.getBoolean("enable_doh", false)
if (wasDohEnabled) {
prefs.edit {
putInt(PreferenceKeys.dohProvider, PREF_DOH_CLOUDFLARE)
remove("enable_doh")
}
}
}
return true
}
return false

View File

@ -191,7 +191,7 @@ object PreferenceKeys {
const val createLegacyBackup = "create_legacy_backup"
const val enableDoh = "enable_doh"
const val dohProvider = "doh_provider"
const val showNsfwSource = "show_nsfw_source"
const val showNsfwExtension = "show_nsfw_extension"

View File

@ -366,5 +366,5 @@ class PreferencesHelper(val context: Context) {
fun labelNsfwExtension() = prefs.getBoolean(Keys.labelNsfwExtension, true)
fun createLegacyBackup() = flowPrefs.getBoolean(Keys.createLegacyBackup, true)
fun enableDoh() = prefs.getBoolean(Keys.enableDoh, false)
fun dohProvider() = prefs.getInt(Keys.dohProvider, -1)
}

View File

@ -12,9 +12,7 @@ class AndroidCookieJar : CookieJar {
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
val urlString = url.toString()
for (cookie in cookies) {
manager.setCookie(urlString, cookie.toString())
}
cookies.forEach { manager.setCookie(urlString, it.toString()) }
}
override fun loadForRequest(url: HttpUrl): List<Cookie> {

View File

@ -0,0 +1,40 @@
package eu.kanade.tachiyomi.network
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import okhttp3.dnsoverhttps.DnsOverHttps
import java.net.InetAddress
/**
* Based on https://github.com/square/okhttp/blob/ef5d0c83f7bbd3a0c0534e7ca23cbc4ee7550f3b/okhttp-dnsoverhttps/src/test/java/okhttp3/dnsoverhttps/DohProviders.java
*/
const val PREF_DOH_CLOUDFLARE = 1
const val PREF_DOH_GOOGLE = 2
fun OkHttpClient.Builder.dohCloudflare() = dns(
DnsOverHttps.Builder().client(build())
.url("https://cloudflare-dns.com/dns-query".toHttpUrl())
.bootstrapDnsHosts(
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()
)
fun OkHttpClient.Builder.dohGoogle() = dns(
DnsOverHttps.Builder().client(build())
.url("https://dns.google/dns-query".toHttpUrl())
.bootstrapDnsHosts(
InetAddress.getByName("8.8.4.4"),
InetAddress.getByName("8.8.8.8")
)
.build()
)

View File

@ -34,7 +34,7 @@ abstract class HttpSource : CatalogueSource {
// * Preferences that a source may need.
// */
// val preferences: SharedPreferences by lazy {
// Injekt.get<Application>().getSharedPreferences("source_$id", Context.MODE_PRIVATE)
// Injekt.get<Application>().getSharedPreferences(source.getPreferenceKey(), Context.MODE_PRIVATE)
// }
/**

View File

@ -34,10 +34,10 @@ class ChapterLoader(
return Observable.just(chapter)
.doOnNext { chapter.state = ReaderChapter.State.Loading }
.observeOn(Schedulers.io())
.flatMap {
.flatMap { readerChapter ->
Timber.d("Loading pages for ${chapter.chapter.name}")
val loader = getPageLoader(it)
val loader = getPageLoader(readerChapter)
chapter.pageLoader = loader
loader.getPages().take(1).doOnNext { pages ->
@ -47,7 +47,7 @@ class ChapterLoader(
.observeOn(AndroidSchedulers.mainThread())
.doOnNext { pages ->
if (pages.isEmpty()) {
throw Exception("Page list is empty")
throw Exception(downloadManager.context.getString(R.string.no_pages_found))
}
chapter.state = ReaderChapter.State.Loaded(pages)

View File

@ -106,7 +106,8 @@ class HttpPageLoader(
.getPageListFromCache(chapter.chapter)
.onErrorResumeNext { source.fetchPageList(chapter.chapter) }
.map { pages ->
pages.mapIndexed { index, page -> // Don't trust sources and use our own indexing
pages.mapIndexed { index, page ->
// Don't trust sources and use our own indexing
ReaderPage(index, page.url, page.imageUrl)
}
}
@ -231,13 +232,15 @@ class HttpPageLoader(
private fun HttpSource.getCachedImage(page: ReaderPage): Observable<ReaderPage> {
val imageUrl = page.imageUrl ?: return Observable.just(page)
return Observable.just(page).flatMap {
return Observable.just(page)
.flatMap {
if (!chapterCache.isImageInCache(imageUrl)) {
cacheImage(page)
} else {
Observable.just(page)
}
}.doOnNext {
}
.doOnNext {
val readerTheme = preferences.readerTheme().get()
if (readerTheme >= 2) {
val stream = chapterCache.getImageFile(imageUrl).inputStream()
@ -252,7 +255,9 @@ class HttpPageLoader(
}
page.stream = { chapterCache.getImageFile(imageUrl).inputStream() }
page.status = Page.READY
}.doOnError { page.status = Page.ERROR }.onErrorReturn { page }
}
.doOnError { page.status = Page.ERROR }
.onErrorReturn { page }
}
/**

View File

@ -23,6 +23,8 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateService
import eu.kanade.tachiyomi.data.library.LibraryUpdateService.Target
import eu.kanade.tachiyomi.data.preference.PreferenceKeys
import eu.kanade.tachiyomi.network.NetworkHelper
import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE
import eu.kanade.tachiyomi.network.PREF_DOH_GOOGLE
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.util.CrashLogUtil
@ -164,12 +166,17 @@ class SettingsAdvancedController : SettingsController() {
}
}
switchPreference {
key = "enable_doh"
key = PreferenceKeys.enableDoh
titleRes = R.string.dns_over_https
summaryRes = R.string.requires_app_restart
defaultValue = false
intListPreference(activity) {
key = PreferenceKeys.dohProvider
titleRes = R.string.doh
entriesRes = arrayOf(R.string.disabled, R.string.cloudflare, R.string.google)
entryValues = listOf(-1, PREF_DOH_CLOUDFLARE, PREF_DOH_GOOGLE)
defaultValue = -1
onChange {
activity?.toast(R.string.requires_app_restart)
true
}
}
}

View File

@ -51,6 +51,7 @@
<string name="chapters_removed">Chapters removed.</string>
<string name="chapter_not_found">Chapter not found</string>
<string name="no_chapters_error">No chapters found</string>
<string name="no_pages_found">No pages found</string>
<plurals name="remove_n_chapters">
<item quantity="one">Remove %1$d downloaded chapter?</item>
<item quantity="other">Remove %1$d downloaded chapters?</item>
@ -630,7 +631,10 @@
<string name="saves_error_logs">Saves error logs to a file for sharing with the developers</string>
<string name="crash_log_saved">Crash logs saved</string>
<string name="network">Network</string>
<string name="dns_over_https">DNS over HTTPS (Cloudflare)</string>
<string name="doh">DNS over HTTPS</string>
<string name="disabled">Disabled</string>
<string name="cloudflare" translatable="false">Cloudflare</string>
<string name="google" translatable="false">Google</string>
<string name="requires_app_restart">Requires app restart to take effect</string>
<string name="used_">Used: %1$s</string>
<plurals name="cache_cleared">

View File

@ -6,7 +6,6 @@ object Versions {
const val FASTADAPTER = "5.0.0"
const val HYPERION = "0.9.27"
const val NUCLEUS = "3.0.0"
const val OKHTTP = "4.8.1"
const val OSS_LICENSE = "17.0.0"
const val RETROFIT = "2.7.2"
const val KOTLINSERIALIZATION = "1.0.1"
@ -65,7 +64,7 @@ object Versions {
const val moshi = "1.9.3"
const val nucleus = "3.0.0"
const val numberSlidingPicker = "1.0.3"
const val okhttp = "4.8.1"
const val okhttp = "5.0.0-alpha.2"
const val okio = "2.6.0"
const val photoView = "2.3.0"
const val reactiveNetwork = "0.13.0"