From 735b65c50cf7deedd4db8fa136ed81214076d11d Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 11 Oct 2020 15:19:19 -0700 Subject: [PATCH] Update DoH implementation --- .../java/com/topjohnwu/magisk/core/Config.kt | 2 +- .../topjohnwu/magisk/di/NetworkingModule.kt | 25 ++++++++----------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Config.kt b/app/src/main/java/com/topjohnwu/magisk/core/Config.kt index e3bd21b43..f51165531 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Config.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Config.kt @@ -128,7 +128,7 @@ object Config : PreferenceModel, DBConfig { var themeOrdinal by preference(Key.THEME_ORDINAL, Theme.Piplup.ordinal) var suReAuth by preference(Key.SU_REAUTH, false) 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 showSystemApp by preference(Key.SHOW_SYSTEM_APP, false) diff --git a/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt index b3711dc8c..cd78ec27c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt @@ -3,6 +3,7 @@ package com.topjohnwu.magisk.di import android.content.Context import android.os.Build import com.squareup.moshi.Moshi +import com.topjohnwu.magisk.BuildConfig import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.Info @@ -20,6 +21,7 @@ import okhttp3.Dns import okhttp3.HttpUrl import okhttp3.OkHttpClient import okhttp3.dnsoverhttps.DnsOverHttps +import okhttp3.logging.HttpLoggingInterceptor import org.koin.dsl.module import retrofit2.Retrofit import retrofit2.converter.moshi.MoshiConverterFactory @@ -39,8 +41,6 @@ val networkingModule = module { private class DnsResolver(client: OkHttpClient) : Dns { - private var dohError = false - private val poisonedHosts = listOf("raw.githubusercontent.com") private val doh by lazy { DnsOverHttps.Builder().client(client) .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 { - return if (!dohError && Config.doh && poisonedHosts.contains(hostname)) { + if (Config.doh) { try { - doh.lookup(hostname) - } catch (e: UnknownHostException) { - dohError = true - Dns.SYSTEM.lookup(hostname) - } - } else { - Dns.SYSTEM.lookup(hostname) + return doh.lookup(hostname) + } catch (e: UnknownHostException) {} } + return Dns.SYSTEM.lookup(hostname) } } @@ -77,10 +73,11 @@ private class DnsResolver(client: OkHttpClient) : Dns { fun createOkHttpClient(context: Context): OkHttpClient { val builder = OkHttpClient.Builder() -// val httpLoggingInterceptor = HttpLoggingInterceptor().apply { -// level = HttpLoggingInterceptor.Level.HEADERS -// } -// builder.addInterceptor(httpLoggingInterceptor) + if (BuildConfig.DEBUG) { + builder.addInterceptor(HttpLoggingInterceptor().apply { + level = HttpLoggingInterceptor.Level.BASIC + }) + } if (!Networking.init(context)) { Info.hasGMS = false