Update DoH implementation
This commit is contained in:
parent
efb1eab327
commit
735b65c50c
@ -128,7 +128,7 @@ object Config : PreferenceModel, DBConfig {
|
|||||||
var themeOrdinal by preference(Key.THEME_ORDINAL, Theme.Piplup.ordinal)
|
var themeOrdinal by preference(Key.THEME_ORDINAL, Theme.Piplup.ordinal)
|
||||||
var suReAuth by preference(Key.SU_REAUTH, false)
|
var suReAuth by preference(Key.SU_REAUTH, false)
|
||||||
var checkUpdate by preference(Key.CHECK_UPDATES, true)
|
var checkUpdate by preference(Key.CHECK_UPDATES, true)
|
||||||
var doh by preference(Key.DOH, defaultLocale.country == "CN")
|
var doh by preference(Key.DOH, false)
|
||||||
var magiskHide by preference(Key.MAGISKHIDE, true)
|
var magiskHide by preference(Key.MAGISKHIDE, true)
|
||||||
var showSystemApp by preference(Key.SHOW_SYSTEM_APP, false)
|
var showSystemApp by preference(Key.SHOW_SYSTEM_APP, false)
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package com.topjohnwu.magisk.di
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import com.squareup.moshi.Moshi
|
import com.squareup.moshi.Moshi
|
||||||
|
import com.topjohnwu.magisk.BuildConfig
|
||||||
import com.topjohnwu.magisk.core.Config
|
import com.topjohnwu.magisk.core.Config
|
||||||
import com.topjohnwu.magisk.core.Const
|
import com.topjohnwu.magisk.core.Const
|
||||||
import com.topjohnwu.magisk.core.Info
|
import com.topjohnwu.magisk.core.Info
|
||||||
@ -20,6 +21,7 @@ import okhttp3.Dns
|
|||||||
import okhttp3.HttpUrl
|
import okhttp3.HttpUrl
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.dnsoverhttps.DnsOverHttps
|
import okhttp3.dnsoverhttps.DnsOverHttps
|
||||||
|
import okhttp3.logging.HttpLoggingInterceptor
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
import retrofit2.converter.moshi.MoshiConverterFactory
|
import retrofit2.converter.moshi.MoshiConverterFactory
|
||||||
@ -39,8 +41,6 @@ val networkingModule = module {
|
|||||||
|
|
||||||
private class DnsResolver(client: OkHttpClient) : Dns {
|
private class DnsResolver(client: OkHttpClient) : Dns {
|
||||||
|
|
||||||
private var dohError = false
|
|
||||||
private val poisonedHosts = listOf("raw.githubusercontent.com")
|
|
||||||
private val doh by lazy {
|
private val doh by lazy {
|
||||||
DnsOverHttps.Builder().client(client)
|
DnsOverHttps.Builder().client(client)
|
||||||
.url(HttpUrl.get("https://cloudflare-dns.com/dns-query"))
|
.url(HttpUrl.get("https://cloudflare-dns.com/dns-query"))
|
||||||
@ -60,16 +60,12 @@ private class DnsResolver(client: OkHttpClient) : Dns {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun lookup(hostname: String): List<InetAddress> {
|
override fun lookup(hostname: String): List<InetAddress> {
|
||||||
return if (!dohError && Config.doh && poisonedHosts.contains(hostname)) {
|
if (Config.doh) {
|
||||||
try {
|
try {
|
||||||
doh.lookup(hostname)
|
return doh.lookup(hostname)
|
||||||
} catch (e: UnknownHostException) {
|
} catch (e: UnknownHostException) {}
|
||||||
dohError = true
|
|
||||||
Dns.SYSTEM.lookup(hostname)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Dns.SYSTEM.lookup(hostname)
|
|
||||||
}
|
}
|
||||||
|
return Dns.SYSTEM.lookup(hostname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,10 +73,11 @@ private class DnsResolver(client: OkHttpClient) : Dns {
|
|||||||
fun createOkHttpClient(context: Context): OkHttpClient {
|
fun createOkHttpClient(context: Context): OkHttpClient {
|
||||||
val builder = OkHttpClient.Builder()
|
val builder = OkHttpClient.Builder()
|
||||||
|
|
||||||
// val httpLoggingInterceptor = HttpLoggingInterceptor().apply {
|
if (BuildConfig.DEBUG) {
|
||||||
// level = HttpLoggingInterceptor.Level.HEADERS
|
builder.addInterceptor(HttpLoggingInterceptor().apply {
|
||||||
// }
|
level = HttpLoggingInterceptor.Level.BASIC
|
||||||
// builder.addInterceptor(httpLoggingInterceptor)
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (!Networking.init(context)) {
|
if (!Networking.init(context)) {
|
||||||
Info.hasGMS = false
|
Info.hasGMS = false
|
||||||
|
Loading…
Reference in New Issue
Block a user