pull/2718/head
kunfei 2 years ago
parent e2e923aec1
commit 1a9a5770fe
  1. 2
      app/build.gradle
  2. 2
      app/src/app/java/io/legado/app/lib/cronet/AbsCallBack.kt
  3. 2
      app/src/app/java/io/legado/app/lib/cronet/BodyUploadProvider.kt
  4. 7
      app/src/app/java/io/legado/app/lib/cronet/CronetCoroutineInterceptor.kt
  5. 2
      app/src/app/java/io/legado/app/lib/cronet/CronetHelper.kt
  6. 6
      app/src/app/java/io/legado/app/lib/cronet/CronetInterceptor.kt
  7. 11
      app/src/app/java/io/legado/app/lib/cronet/CronetLoader.kt
  8. 2
      app/src/app/java/io/legado/app/lib/cronet/NewCallBack.kt
  9. 2
      app/src/app/java/io/legado/app/lib/cronet/OldCallback.kt
  10. 4
      app/src/main/java/io/legado/app/App.kt
  11. 11
      app/src/main/java/io/legado/app/help/http/HttpHelper.kt
  12. 22
      app/src/main/java/io/legado/app/help/http/cronet/Cronet.kt
  13. 9
      app/src/main/java/io/legado/app/help/http/cronet/CronetLoaderInterface.kt

@ -200,7 +200,7 @@ dependencies {
//
implementation('com.squareup.okhttp3:okhttp:4.10.0')
implementation(fileTree(dir: 'cronetlib', include: ['*.jar', '*.aar']))
appImplementation(fileTree(dir: 'cronetlib', include: ['*.jar', '*.aar']))
//Glide
def glideVersion = "4.14.2"

@ -1,4 +1,4 @@
package io.legado.app.help.http.cronet
package io.legado.app.lib.cronet
import io.legado.app.help.http.okHttpClient
import io.legado.app.utils.DebugLog

@ -1,4 +1,4 @@
package io.legado.app.help.http.cronet
package io.legado.app.lib.cronet
import okhttp3.RequestBody
import okio.Buffer

@ -1,5 +1,6 @@
package io.legado.app.help.http.cronet
package io.legado.app.lib.cronet
import io.legado.app.help.http.cookieJar
import io.legado.app.utils.printOnDebug
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.suspendCancellableCoroutine
@ -12,8 +13,8 @@ import java.io.IOException
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
class CronetCoroutineInterceptor(private val cookieJar: CookieJar = CookieJar.NO_COOKIES) :
Interceptor {
@Suppress("unused")
class CronetCoroutineInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
if (chain.call().isCanceled()) {
throw IOException("Canceled")

@ -1,4 +1,4 @@
package io.legado.app.help.http.cronet
package io.legado.app.lib.cronet
import io.legado.app.constant.AppLog
import io.legado.app.help.config.AppConfig

@ -1,13 +1,15 @@
package io.legado.app.help.http.cronet
package io.legado.app.lib.cronet
import android.os.Build
import io.legado.app.help.http.cookieJar
import io.legado.app.utils.printOnDebug
import okhttp3.*
import okhttp3.internal.http.receiveHeaders
import java.io.IOException
class CronetInterceptor(private val cookieJar: CookieJar = CookieJar.NO_COOKIES) : Interceptor {
@Suppress("unused")
class CronetInterceptor : Interceptor {
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
if (chain.call().isCanceled()) {

@ -1,4 +1,4 @@
package io.legado.app.help.http.cronet
package io.legado.app.lib.cronet
import android.annotation.SuppressLint
import android.content.Context
@ -8,6 +8,7 @@ import android.text.TextUtils
import io.legado.app.BuildConfig
import io.legado.app.help.config.AppConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.http.cronet.CronetLoaderInterface
import io.legado.app.utils.DebugLog
import io.legado.app.utils.printOnDebug
@ -23,7 +24,7 @@ import java.security.MessageDigest
import java.util.*
object CronetLoader : CronetEngine.Builder.LibraryLoader() {
object CronetLoader : CronetEngine.Builder.LibraryLoader(), CronetLoaderInterface {
//https://storage.googleapis.com/chromium-cronet/android/92.0.4515.159/Release/cronet/libs/arm64-v8a/libcronet.92.0.4515.159.so
private const val soVersion = BuildConfig.Cronet_Version
@ -55,7 +56,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() {
/**
* 判断Cronet是否安装完成
*/
fun install(): Boolean {
override fun install(): Boolean {
synchronized(this) {
if (cacheInstall) {
return true
@ -77,7 +78,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() {
/**
* 预加载Cronet
*/
fun preDownload() {
override fun preDownload() {
if (AppConfig.isGooglePlay) {
return
}
@ -288,7 +289,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() {
cacheInstall = false
val parentFile = downloadTempFile.parentFile
@Suppress("SameParameterValue")
deleteHistoryFile(parentFile!!, null)
(deleteHistoryFile(parentFile!!, null))
}
// executor.execute {
//

@ -1,4 +1,4 @@
package io.legado.app.help.http.cronet
package io.legado.app.lib.cronet
import android.os.Build

@ -1,4 +1,4 @@
package io.legado.app.help.http.cronet
package io.legado.app.lib.cronet
import android.os.ConditionVariable
import okhttp3.Call

@ -24,7 +24,7 @@ import io.legado.app.help.book.BookHelp
import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.ThemeConfig.applyDayNight
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.http.cronet.CronetLoader
import io.legado.app.help.http.cronet.Cronet
import io.legado.app.model.BookCover
import io.legado.app.utils.defaultSharedPreferences
import io.legado.app.utils.getPrefBoolean
@ -42,7 +42,7 @@ class App : MultiDexApplication() {
oldConfig = Configuration(resources.configuration)
CrashHandler(this)
//预下载Cronet so
CronetLoader.preDownload()
Cronet.preDownload()
createNotificationChannels()
applyDayNight(this)
LiveEventBus.config()

@ -3,8 +3,7 @@ package io.legado.app.help.http
import io.legado.app.constant.AppConst
import io.legado.app.help.CacheManager
import io.legado.app.help.config.AppConfig
import io.legado.app.help.http.cronet.CronetInterceptor
import io.legado.app.help.http.cronet.CronetLoader
import io.legado.app.help.http.cronet.Cronet
import io.legado.app.utils.NetworkUtils
import okhttp3.*
import java.net.InetSocketAddress
@ -70,8 +69,12 @@ val okHttpClient: OkHttpClient by lazy {
builder.addHeader("Cache-Control", "no-cache")
chain.proceed(builder.build())
})
if (!AppConfig.isGooglePlay && AppConfig.isCronet && CronetLoader.install()) {
builder.addInterceptor(CronetInterceptor(cookieJar = cookieJar))
if (!AppConfig.isGooglePlay && AppConfig.isCronet) {
if (Cronet.loader?.install() == true) {
Cronet.interceptor?.let {
builder.addInterceptor(it)
}
}
}
builder.build()
}

@ -0,0 +1,22 @@
package io.legado.app.help.http.cronet
import okhttp3.Interceptor
object Cronet {
val loader: CronetLoaderInterface? by lazy {
val cl = Class.forName("io.legado.app.lib.cronet.CronetLoader")
?.kotlin?.objectInstance
cl as? CronetLoaderInterface
}
fun preDownload() {
loader?.preDownload()
}
val interceptor: Interceptor? by lazy {
val cl = Class.forName("io.legado.app.lib.cronet.CronetInterceptor")?.newInstance()
cl as? Interceptor
}
}

@ -0,0 +1,9 @@
package io.legado.app.help.http.cronet
interface CronetLoaderInterface {
fun install(): Boolean
fun preDownload()
}
Loading…
Cancel
Save