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.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()
}

@ -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))

@ -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()

@ -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)) {

Loading…
Cancel
Save