pull/1273/head
gedoor 3 years ago
parent 0bd978d6b7
commit 83ec9746a9
  1. 2
      app/build.gradle
  2. 2
      app/src/main/java/io/legado/app/App.kt
  3. 24
      app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt
  4. 5
      app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt

@ -182,7 +182,7 @@ dependencies {
// //
implementation('com.squareup.okhttp3:okhttp:4.9.1') 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' googleImplementation 'com.google.android.gms:play-services-cronet:17.0.0'
//Glide //Glide

@ -23,7 +23,7 @@ class App : MultiDexApplication() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
CrashHandler(this) CrashHandler(this)
if (AppConfig.isCronet) { if (AppConfig.isCronet && !AppConfig.isGooglePlay) {
//预下载Cronet so //预下载Cronet so
CronetLoader.preDownload() CronetLoader.preDownload()
} }

@ -1,6 +1,7 @@
package io.legado.app.help.http.cronet package io.legado.app.help.http.cronet
import android.util.Log import android.util.Log
import io.legado.app.help.AppConfig
import okhttp3.Headers import okhttp3.Headers
import okhttp3.MediaType import okhttp3.MediaType
import okhttp3.Request import okhttp3.Request
@ -19,18 +20,21 @@ val executor: Executor by lazy { Executors.newCachedThreadPool() }
val cronetEngine: ExperimentalCronetEngine by lazy { val cronetEngine: ExperimentalCronetEngine by lazy {
CronetLoader.preDownload() CronetLoader.preDownload()
val builder = ExperimentalCronetEngine.Builder(appCtx) val builder = ExperimentalCronetEngine.Builder(appCtx).apply {
.setLibraryLoader(CronetLoader)//设置自定义so库加载 if (!AppConfig.isGooglePlay) {
.setStoragePath(appCtx.externalCacheDir?.absolutePath)//设置缓存路径 setLibraryLoader(CronetLoader)//设置自定义so库加载
.enableHttpCache(HTTP_CACHE_DISK, (1024 * 1024 * 50))//设置缓存模式 }
.enableQuic(true)//设置支持http/3 setStoragePath(appCtx.externalCacheDir?.absolutePath)//设置缓存路径
.enableHttp2(true) //设置支持http/2 enableHttpCache(HTTP_CACHE_DISK, (1024 * 1024 * 50))//设置缓存模式
.enablePublicKeyPinningBypassForLocalTrustAnchors(true) enableQuic(true)//设置支持http/3
//.enableNetworkQualityEstimator(true) enableHttp2(true) //设置支持http/2
enablePublicKeyPinningBypassForLocalTrustAnchors(true)
//enableNetworkQualityEstimator(true)
//Brotli压缩 //Brotli压缩
builder.enableBrotli(true) enableBrotli(true)
//builder.setExperimentalOptions("{\"quic_version\": \"h3-29\"}") //setExperimentalOptions("{\"quic_version\": \"h3-29\"}")
}
val engine = builder.build() val engine = builder.build()
Log.d("Cronet", "Cronet Version:" + engine.versionString) Log.d("Cronet", "Cronet Version:" + engine.versionString)
//这会导致Jsoup的网络请求出现问题,暂时不接管系统URL //这会导致Jsoup的网络请求出现问题,暂时不接管系统URL

@ -6,6 +6,7 @@ import android.content.pm.ApplicationInfo
import android.os.Build import android.os.Build
import android.text.TextUtils import android.text.TextUtils
import android.util.Log import android.util.Log
import io.legado.app.help.AppConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
import io.legado.app.utils.putPrefString import io.legado.app.utils.putPrefString
@ -50,10 +51,14 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() {
} }
fun install(): Boolean { fun install(): Boolean {
if (AppConfig.isGooglePlay) {
return true
}
return soFile.exists() return soFile.exists()
} }
fun preDownload() { fun preDownload() {
if (AppConfig.isGooglePlay) return
Coroutine.async { Coroutine.async {
md5 = getUrlMd5(md5Url) md5 = getUrlMd5(md5Url)
if (soFile.exists() && md5 == getFileMD5(soFile)) { if (soFile.exists() && md5 == getFileMD5(soFile)) {

Loading…
Cancel
Save