From 83ec9746a994e9523d2987d1007067b1a42d751d Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 25 Aug 2021 20:43:28 +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/build.gradle | 2 +- app/src/main/java/io/legado/app/App.kt | 2 +- .../app/help/http/cronet/CronetHelper.kt | 26 +++++++++++-------- .../app/help/http/cronet/CronetLoader.kt | 5 ++++ 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1d1b83bb5..58a908646 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -182,7 +182,7 @@ dependencies { //网络 implementation('com.squareup.okhttp3:okhttp:4.9.1') - appImplementation(fileTree(dir: 'cronetlib', include: ['*.jar', '*.aar'])) + implementation(fileTree(dir: 'cronetlib', include: ['*.jar', '*.aar'])) googleImplementation 'com.google.android.gms:play-services-cronet:17.0.0' //Glide diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 24bfe161d..fbeca1521 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -23,7 +23,7 @@ class App : MultiDexApplication() { override fun onCreate() { super.onCreate() CrashHandler(this) - if (AppConfig.isCronet) { + if (AppConfig.isCronet && !AppConfig.isGooglePlay) { //预下载Cronet so CronetLoader.preDownload() } 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 4d01657d4..ca5abca0d 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 @@ -1,6 +1,7 @@ package io.legado.app.help.http.cronet import android.util.Log +import io.legado.app.help.AppConfig import okhttp3.Headers import okhttp3.MediaType import okhttp3.Request @@ -19,18 +20,21 @@ val executor: Executor by lazy { Executors.newCachedThreadPool() } val cronetEngine: ExperimentalCronetEngine by lazy { CronetLoader.preDownload() - val builder = ExperimentalCronetEngine.Builder(appCtx) - .setLibraryLoader(CronetLoader)//设置自定义so库加载 - .setStoragePath(appCtx.externalCacheDir?.absolutePath)//设置缓存路径 - .enableHttpCache(HTTP_CACHE_DISK, (1024 * 1024 * 50))//设置缓存模式 - .enableQuic(true)//设置支持http/3 - .enableHttp2(true) //设置支持http/2 - .enablePublicKeyPinningBypassForLocalTrustAnchors(true) - //.enableNetworkQualityEstimator(true) + val builder = ExperimentalCronetEngine.Builder(appCtx).apply { + if (!AppConfig.isGooglePlay) { + setLibraryLoader(CronetLoader)//设置自定义so库加载 + } + setStoragePath(appCtx.externalCacheDir?.absolutePath)//设置缓存路径 + enableHttpCache(HTTP_CACHE_DISK, (1024 * 1024 * 50))//设置缓存模式 + enableQuic(true)//设置支持http/3 + enableHttp2(true) //设置支持http/2 + enablePublicKeyPinningBypassForLocalTrustAnchors(true) + //enableNetworkQualityEstimator(true) - //Brotli压缩 - builder.enableBrotli(true) - //builder.setExperimentalOptions("{\"quic_version\": \"h3-29\"}") + //Brotli压缩 + enableBrotli(true) + //setExperimentalOptions("{\"quic_version\": \"h3-29\"}") + } val engine = builder.build() Log.d("Cronet", "Cronet Version:" + engine.versionString) //这会导致Jsoup的网络请求出现问题,暂时不接管系统URL 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 544c0fb28..0625a2311 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 @@ -6,6 +6,7 @@ import android.content.pm.ApplicationInfo import android.os.Build import android.text.TextUtils import android.util.Log +import io.legado.app.help.AppConfig import io.legado.app.help.coroutine.Coroutine import io.legado.app.utils.getPrefString import io.legado.app.utils.putPrefString @@ -50,10 +51,14 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { } fun install(): Boolean { + if (AppConfig.isGooglePlay) { + return true + } return soFile.exists() } fun preDownload() { + if (AppConfig.isGooglePlay) return Coroutine.async { md5 = getUrlMd5(md5Url) if (soFile.exists() && md5 == getFileMD5(soFile)) {