From 32335c9ee1a85e73a1c4ea09ed362c3806dda306 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 19 Oct 2021 14:31:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/help/http/cronet/CronetHelper.kt | 15 ++++++++------- .../main/java/io/legado/app/model/BookCover.kt | 10 ++++++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt b/app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt index 2886b8db1..a8ab18c5c 100644 --- a/app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt +++ b/app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt @@ -1,6 +1,5 @@ package io.legado.app.help.http.cronet -import android.util.Log import com.google.android.gms.net.CronetProviderInstaller import io.legado.app.help.AppConfig import okhttp3.Headers @@ -12,6 +11,7 @@ import org.chromium.net.ExperimentalCronetEngine import org.chromium.net.UploadDataProviders import org.chromium.net.UrlRequest import splitties.init.appCtx +import timber.log.Timber import java.util.concurrent.ExecutorService import java.util.concurrent.Executors @@ -24,8 +24,6 @@ val cronetEngine: ExperimentalCronetEngine by lazy { } else { CronetLoader.preDownload() } - - val builder = ExperimentalCronetEngine.Builder(appCtx).apply { if (!AppConfig.isGooglePlay && CronetLoader.install()) { setLibraryLoader(CronetLoader)//设置自定义so库加载 @@ -35,12 +33,15 @@ val cronetEngine: ExperimentalCronetEngine by lazy { enableQuic(true)//设置支持http/3 enableHttp2(true) //设置支持http/2 enablePublicKeyPinningBypassForLocalTrustAnchors(true) - enableBrotli(true)//Brotli压缩 - } - val engine = builder.build() - Log.d("Cronet", "Cronet Version:" + engine.versionString) + val engine = try { + builder.build() + } catch (e: Exception) { + CronetLoader.preDownload() + builder.build() + } + Timber.d("Cronet Version:" + engine.versionString) //这会导致Jsoup的网络请求出现问题,暂时不接管系统URL //URL.setURLStreamHandlerFactory(CronetURLStreamHandlerFactory(engine)) return@lazy engine diff --git a/app/src/main/java/io/legado/app/model/BookCover.kt b/app/src/main/java/io/legado/app/model/BookCover.kt index a196cc60c..8948cb504 100644 --- a/app/src/main/java/io/legado/app/model/BookCover.kt +++ b/app/src/main/java/io/legado/app/model/BookCover.kt @@ -42,8 +42,14 @@ object BookCover { } val key = if (isNightTheme) PreferKey.defaultCoverDark else PreferKey.defaultCover val path = appCtx.getPrefString(key) - defaultDrawable = Drawable.createFromPath(path) - ?: appCtx.resources.getDrawable(R.drawable.image_cover_default, null) + defaultDrawable = try { + Drawable.createFromPath(path) + ?: appCtx.resources.getDrawable(R.drawable.image_cover_default, null) + } catch (e: OutOfMemoryError) { + appCtx.resources.getDrawable(R.drawable.image_cover_default, null) + } catch (e: Exception) { + appCtx.resources.getDrawable(R.drawable.image_cover_default, null) + } } fun getBlurDefaultCover(context: Context): RequestBuilder {