From d47c12f55a401b634862ba212e4b9e3aafa52ddc Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 20 Oct 2021 08:07:07 +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 --- app/src/main/java/io/legado/app/help/http/HttpHelper.kt | 9 +++++++-- .../java/io/legado/app/help/http/cronet/CronetHelper.kt | 7 +------ .../io/legado/app/help/http/cronet/CronetInterceptor.kt | 1 + .../java/io/legado/app/help/http/cronet/CronetLoader.kt | 4 ++++ 4 files changed, 13 insertions(+), 8 deletions(-) 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 533d62a6a..3f82ff822 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 @@ -7,6 +7,7 @@ import okhttp3.ConnectionSpec import okhttp3.Credentials import okhttp3.Interceptor import okhttp3.OkHttpClient +import timber.log.Timber import java.net.InetSocketAddress import java.net.Proxy import java.util.concurrent.ConcurrentHashMap @@ -44,8 +45,12 @@ val okHttpClient: OkHttpClient by lazy { chain.proceed(request) }) if (AppConfig.isCronet && CronetLoader.install()) { - //提供CookieJar 用于同步Cookie - builder.addInterceptor(CronetInterceptor(null)) + try { + //提供CookieJar 用于同步Cookie + builder.addInterceptor(CronetInterceptor(null)) + } catch (e: Exception) { + Timber.e(e, "初始化Cronet失败") + } } builder.build() } diff --git a/app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt b/app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt index e13dbe228..cb376740e 100644 --- a/app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt +++ b/app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt @@ -35,12 +35,7 @@ val cronetEngine: ExperimentalCronetEngine by lazy { enablePublicKeyPinningBypassForLocalTrustAnchors(true) enableBrotli(true)//Brotli压缩 } - val engine = try { - builder.build() - } catch (e: Exception) { - builder.setLibraryLoader(CronetLoader)//设置自定义so库加载 - builder.build() - } + val engine = builder.build() Timber.d("Cronet Version:" + engine.versionString) //这会导致Jsoup的网络请求出现问题,暂时不接管系统URL //URL.setURLStreamHandlerFactory(CronetURLStreamHandlerFactory(engine)) diff --git a/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt b/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt index ae9f85fe4..de578c755 100644 --- a/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt +++ b/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt @@ -5,6 +5,7 @@ import okhttp3.* import java.io.IOException class CronetInterceptor(private val cookieJar: CookieJar?) : Interceptor { + @Throws(IOException::class) override fun intercept(chain: Interceptor.Chain): Response { val original: Request = chain.request() diff --git a/app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt b/app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt index 0f045b1d6..20900f456 100644 --- a/app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt +++ b/app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt @@ -77,6 +77,10 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { * 预加载Cronet */ fun preDownload() { + if (AppConfig.isGooglePlay) { + CronetProviderInstaller.installProvider(appCtx) + return + } Coroutine.async { //md5 = getUrlMd5(md5Url) if (soFile.exists() && md5 == getFileMD5(soFile)) {