From 7e2281fee5cdbd63e1aa79ddefc230c698346cb8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 27 Jan 2023 22:42:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/cronet/CronetCoroutineInterceptor.kt | 3 +- .../app/lib/cronet/CronetInterceptor.kt | 3 +- .../io/legado/app/lib/cronet/CronetLoader.kt | 4 +-- app/src/main/java/io/legado/app/App.kt | 2 +- .../java/io/legado/app/help/http/Cronet.kt | 35 +++++++++++++++++++ .../io/legado/app/help/http/HttpHelper.kt | 1 - .../io/legado/app/help/http/cronet/Cronet.kt | 25 ------------- .../help/http/cronet/CronetLoaderInterface.kt | 9 ----- 8 files changed, 40 insertions(+), 42 deletions(-) create mode 100644 app/src/main/java/io/legado/app/help/http/Cronet.kt delete mode 100644 app/src/main/java/io/legado/app/help/http/cronet/Cronet.kt delete mode 100644 app/src/main/java/io/legado/app/help/http/cronet/CronetLoaderInterface.kt diff --git a/app/src/app/java/io/legado/app/lib/cronet/CronetCoroutineInterceptor.kt b/app/src/app/java/io/legado/app/lib/cronet/CronetCoroutineInterceptor.kt index fb3d357f4..87fe65ea7 100644 --- a/app/src/app/java/io/legado/app/lib/cronet/CronetCoroutineInterceptor.kt +++ b/app/src/app/java/io/legado/app/lib/cronet/CronetCoroutineInterceptor.kt @@ -1,7 +1,6 @@ package io.legado.app.lib.cronet import androidx.annotation.Keep -import io.legado.app.help.http.cookieJar import io.legado.app.utils.printOnDebug import kotlinx.coroutines.runBlocking import kotlinx.coroutines.suspendCancellableCoroutine @@ -16,7 +15,7 @@ import kotlin.coroutines.resumeWithException @Keep @Suppress("unused") -class CronetCoroutineInterceptor : Interceptor { +class CronetCoroutineInterceptor(private val cookieJar: CookieJar) : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { if (chain.call().isCanceled()) { diff --git a/app/src/app/java/io/legado/app/lib/cronet/CronetInterceptor.kt b/app/src/app/java/io/legado/app/lib/cronet/CronetInterceptor.kt index b045c1632..f076fef80 100644 --- a/app/src/app/java/io/legado/app/lib/cronet/CronetInterceptor.kt +++ b/app/src/app/java/io/legado/app/lib/cronet/CronetInterceptor.kt @@ -2,7 +2,6 @@ package io.legado.app.lib.cronet import android.os.Build import androidx.annotation.Keep -import io.legado.app.help.http.cookieJar import io.legado.app.utils.printOnDebug import okhttp3.* import okhttp3.internal.http.receiveHeaders @@ -10,7 +9,7 @@ import java.io.IOException @Keep @Suppress("unused") -class CronetInterceptor : Interceptor { +class CronetInterceptor(private val cookieJar: CookieJar) : Interceptor { @Throws(IOException::class) override fun intercept(chain: Interceptor.Chain): Response { diff --git a/app/src/app/java/io/legado/app/lib/cronet/CronetLoader.kt b/app/src/app/java/io/legado/app/lib/cronet/CronetLoader.kt index ffb78d326..b2121f35d 100644 --- a/app/src/app/java/io/legado/app/lib/cronet/CronetLoader.kt +++ b/app/src/app/java/io/legado/app/lib/cronet/CronetLoader.kt @@ -9,7 +9,7 @@ import androidx.annotation.Keep import io.legado.app.BuildConfig import io.legado.app.constant.AppConst import io.legado.app.help.coroutine.Coroutine -import io.legado.app.help.http.cronet.CronetLoaderInterface +import io.legado.app.help.http.Cronet import io.legado.app.utils.DebugLog import io.legado.app.utils.printOnDebug @@ -25,7 +25,7 @@ import java.security.MessageDigest import java.util.* @Keep -object CronetLoader : CronetEngine.Builder.LibraryLoader(), CronetLoaderInterface { +object CronetLoader : CronetEngine.Builder.LibraryLoader(), Cronet.LoaderInterface { //https://storage.googleapis.com/chromium-cronet/android/92.0.4515.159/Release/cronet/libs/arm64-v8a/libcronet.92.0.4515.159.so private const val soVersion = BuildConfig.Cronet_Version diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 8c82a99e3..b63beb82c 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -24,7 +24,7 @@ import io.legado.app.help.book.BookHelp import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ThemeConfig.applyDayNight import io.legado.app.help.coroutine.Coroutine -import io.legado.app.help.http.cronet.Cronet +import io.legado.app.help.http.Cronet import io.legado.app.model.BookCover import io.legado.app.utils.defaultSharedPreferences import io.legado.app.utils.getPrefBoolean diff --git a/app/src/main/java/io/legado/app/help/http/Cronet.kt b/app/src/main/java/io/legado/app/help/http/Cronet.kt new file mode 100644 index 000000000..4881589cd --- /dev/null +++ b/app/src/main/java/io/legado/app/help/http/Cronet.kt @@ -0,0 +1,35 @@ +package io.legado.app.help.http + +import okhttp3.CookieJar +import okhttp3.Interceptor + +object Cronet { + + val loader: LoaderInterface? by lazy { + kotlin.runCatching { + Class.forName("io.legado.app.lib.cronet.CronetLoader") + .kotlin.objectInstance as LoaderInterface + }.getOrNull() + } + + fun preDownload() { + loader?.preDownload() + } + + val interceptor: Interceptor? by lazy { + kotlin.runCatching { + val iClass = Class.forName("io.legado.app.lib.cronet.CronetInterceptor") + iClass.getDeclaredConstructor(CookieJar::class.java) + .newInstance(cookieJar) as Interceptor + }.getOrNull() + } + + interface LoaderInterface { + + fun install(): Boolean + + fun preDownload() + + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt index 145ab9657..b7fc67ed2 100644 --- a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt +++ b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt @@ -3,7 +3,6 @@ package io.legado.app.help.http import io.legado.app.constant.AppConst import io.legado.app.help.CacheManager import io.legado.app.help.config.AppConfig -import io.legado.app.help.http.cronet.Cronet import io.legado.app.utils.NetworkUtils import okhttp3.* import java.net.InetSocketAddress diff --git a/app/src/main/java/io/legado/app/help/http/cronet/Cronet.kt b/app/src/main/java/io/legado/app/help/http/cronet/Cronet.kt deleted file mode 100644 index 094e6c464..000000000 --- a/app/src/main/java/io/legado/app/help/http/cronet/Cronet.kt +++ /dev/null @@ -1,25 +0,0 @@ -package io.legado.app.help.http.cronet - -import okhttp3.Interceptor - -object Cronet { - - val loader: CronetLoaderInterface? by lazy { - kotlin.runCatching { - Class.forName("io.legado.app.lib.cronet.CronetLoader") - .kotlin.objectInstance as CronetLoaderInterface - }.getOrNull() - } - - fun preDownload() { - loader?.preDownload() - } - - val interceptor: Interceptor? by lazy { - kotlin.runCatching { - Class.forName("io.legado.app.lib.cronet.CronetInterceptor") - .newInstance() as Interceptor - }.getOrNull() - } - -} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/http/cronet/CronetLoaderInterface.kt b/app/src/main/java/io/legado/app/help/http/cronet/CronetLoaderInterface.kt deleted file mode 100644 index 2b4c35ba1..000000000 --- a/app/src/main/java/io/legado/app/help/http/cronet/CronetLoaderInterface.kt +++ /dev/null @@ -1,9 +0,0 @@ -package io.legado.app.help.http.cronet - -interface CronetLoaderInterface { - - fun install(): Boolean - - fun preDownload() - -} \ No newline at end of file