master
kunfei 2 years ago
parent ea571837c0
commit 7e2281fee5
  1. 3
      app/src/app/java/io/legado/app/lib/cronet/CronetCoroutineInterceptor.kt
  2. 3
      app/src/app/java/io/legado/app/lib/cronet/CronetInterceptor.kt
  3. 4
      app/src/app/java/io/legado/app/lib/cronet/CronetLoader.kt
  4. 2
      app/src/main/java/io/legado/app/App.kt
  5. 35
      app/src/main/java/io/legado/app/help/http/Cronet.kt
  6. 1
      app/src/main/java/io/legado/app/help/http/HttpHelper.kt
  7. 25
      app/src/main/java/io/legado/app/help/http/cronet/Cronet.kt
  8. 9
      app/src/main/java/io/legado/app/help/http/cronet/CronetLoaderInterface.kt

@ -1,7 +1,6 @@
package io.legado.app.lib.cronet package io.legado.app.lib.cronet
import androidx.annotation.Keep import androidx.annotation.Keep
import io.legado.app.help.http.cookieJar
import io.legado.app.utils.printOnDebug import io.legado.app.utils.printOnDebug
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.suspendCancellableCoroutine
@ -16,7 +15,7 @@ import kotlin.coroutines.resumeWithException
@Keep @Keep
@Suppress("unused") @Suppress("unused")
class CronetCoroutineInterceptor : Interceptor { class CronetCoroutineInterceptor(private val cookieJar: CookieJar) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response { override fun intercept(chain: Interceptor.Chain): Response {
if (chain.call().isCanceled()) { if (chain.call().isCanceled()) {

@ -2,7 +2,6 @@ package io.legado.app.lib.cronet
import android.os.Build import android.os.Build
import androidx.annotation.Keep import androidx.annotation.Keep
import io.legado.app.help.http.cookieJar
import io.legado.app.utils.printOnDebug import io.legado.app.utils.printOnDebug
import okhttp3.* import okhttp3.*
import okhttp3.internal.http.receiveHeaders import okhttp3.internal.http.receiveHeaders
@ -10,7 +9,7 @@ import java.io.IOException
@Keep @Keep
@Suppress("unused") @Suppress("unused")
class CronetInterceptor : 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 {

@ -9,7 +9,7 @@ import androidx.annotation.Keep
import io.legado.app.BuildConfig import io.legado.app.BuildConfig
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.http.cronet.CronetLoaderInterface import io.legado.app.help.http.Cronet
import io.legado.app.utils.DebugLog import io.legado.app.utils.DebugLog
import io.legado.app.utils.printOnDebug import io.legado.app.utils.printOnDebug
@ -25,7 +25,7 @@ import java.security.MessageDigest
import java.util.* import java.util.*
@Keep @Keep
object CronetLoader : CronetEngine.Builder.LibraryLoader(), CronetLoaderInterface { object CronetLoader : CronetEngine.Builder.LibraryLoader(), Cronet.LoaderInterface {
//https://storage.googleapis.com/chromium-cronet/android/92.0.4515.159/Release/cronet/libs/arm64-v8a/libcronet.92.0.4515.159.so //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 private const val soVersion = BuildConfig.Cronet_Version

@ -24,7 +24,7 @@ import io.legado.app.help.book.BookHelp
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.ThemeConfig.applyDayNight import io.legado.app.help.config.ThemeConfig.applyDayNight
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.http.cronet.Cronet import io.legado.app.help.http.Cronet
import io.legado.app.model.BookCover import io.legado.app.model.BookCover
import io.legado.app.utils.defaultSharedPreferences import io.legado.app.utils.defaultSharedPreferences
import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefBoolean

@ -0,0 +1,35 @@
package io.legado.app.help.http
import okhttp3.CookieJar
import okhttp3.Interceptor
object Cronet {
val loader: LoaderInterface? by lazy {
kotlin.runCatching {
Class.forName("io.legado.app.lib.cronet.CronetLoader")
.kotlin.objectInstance as LoaderInterface
}.getOrNull()
}
fun preDownload() {
loader?.preDownload()
}
val interceptor: Interceptor? by lazy {
kotlin.runCatching {
val iClass = Class.forName("io.legado.app.lib.cronet.CronetInterceptor")
iClass.getDeclaredConstructor(CookieJar::class.java)
.newInstance(cookieJar) as Interceptor
}.getOrNull()
}
interface LoaderInterface {
fun install(): Boolean
fun preDownload()
}
}

@ -3,7 +3,6 @@ package io.legado.app.help.http
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.help.CacheManager import io.legado.app.help.CacheManager
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.help.http.cronet.Cronet
import io.legado.app.utils.NetworkUtils import io.legado.app.utils.NetworkUtils
import okhttp3.* import okhttp3.*
import java.net.InetSocketAddress import java.net.InetSocketAddress

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

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