pull/1391/head
gedoor 3 years ago
parent 91c790976e
commit d47c12f55a
  1. 9
      app/src/main/java/io/legado/app/help/http/HttpHelper.kt
  2. 7
      app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt
  3. 1
      app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt
  4. 4
      app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt

@ -7,6 +7,7 @@ import okhttp3.ConnectionSpec
import okhttp3.Credentials import okhttp3.Credentials
import okhttp3.Interceptor import okhttp3.Interceptor
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import timber.log.Timber
import java.net.InetSocketAddress import java.net.InetSocketAddress
import java.net.Proxy import java.net.Proxy
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
@ -44,8 +45,12 @@ val okHttpClient: OkHttpClient by lazy {
chain.proceed(request) chain.proceed(request)
}) })
if (AppConfig.isCronet && CronetLoader.install()) { if (AppConfig.isCronet && CronetLoader.install()) {
//提供CookieJar 用于同步Cookie try {
builder.addInterceptor(CronetInterceptor(null)) //提供CookieJar 用于同步Cookie
builder.addInterceptor(CronetInterceptor(null))
} catch (e: Exception) {
Timber.e(e, "初始化Cronet失败")
}
} }
builder.build() builder.build()
} }

@ -35,12 +35,7 @@ val cronetEngine: ExperimentalCronetEngine by lazy {
enablePublicKeyPinningBypassForLocalTrustAnchors(true) enablePublicKeyPinningBypassForLocalTrustAnchors(true)
enableBrotli(true)//Brotli压缩 enableBrotli(true)//Brotli压缩
} }
val engine = try { val engine = builder.build()
builder.build()
} catch (e: Exception) {
builder.setLibraryLoader(CronetLoader)//设置自定义so库加载
builder.build()
}
Timber.d("Cronet Version:" + engine.versionString) Timber.d("Cronet Version:" + engine.versionString)
//这会导致Jsoup的网络请求出现问题,暂时不接管系统URL //这会导致Jsoup的网络请求出现问题,暂时不接管系统URL
//URL.setURLStreamHandlerFactory(CronetURLStreamHandlerFactory(engine)) //URL.setURLStreamHandlerFactory(CronetURLStreamHandlerFactory(engine))

@ -5,6 +5,7 @@ import okhttp3.*
import java.io.IOException import java.io.IOException
class CronetInterceptor(private val cookieJar: CookieJar?) : Interceptor { class CronetInterceptor(private val cookieJar: CookieJar?) : Interceptor {
@Throws(IOException::class) @Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response { override fun intercept(chain: Interceptor.Chain): Response {
val original: Request = chain.request() val original: Request = chain.request()

@ -77,6 +77,10 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() {
* 预加载Cronet * 预加载Cronet
*/ */
fun preDownload() { fun preDownload() {
if (AppConfig.isGooglePlay) {
CronetProviderInstaller.installProvider(appCtx)
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