From f4cc12a0b2f9cf66af356ce6093e447dc827a21d Mon Sep 17 00:00:00 2001 From: ag2s20150909 Date: Fri, 30 Jul 2021 19:51:36 +0800 Subject: [PATCH] =?UTF-8?q?Cronet:=E4=BF=AE=E5=A4=8D=E5=9C=A8=E6=96=AD?= =?UTF-8?q?=E7=BD=91=E6=9D=A1=E4=BB=B6=E4=B8=8B=E4=BC=9A=E5=9B=A0=E4=B8=BA?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=B8=8D=E5=88=B0md5,=E5=AF=BC=E8=87=B4md5?= =?UTF-8?q?=E4=B8=8D=E5=8C=B9=E9=85=8D=E8=80=8C=E5=88=A0=E9=99=A4=E5=B7=B2?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E7=9A=84so?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/help/http/cronet/CronetLoader.kt | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt b/app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt index 1f505d99f..9f16e8233 100644 --- a/app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt +++ b/app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt @@ -6,6 +6,8 @@ import android.content.pm.ApplicationInfo import android.os.Build import android.text.TextUtils import android.util.Log +import io.legado.app.utils.getPrefString +import io.legado.app.utils.putPrefString import org.chromium.net.CronetEngine import org.chromium.net.impl.ImplVersion import splitties.init.appCtx @@ -28,7 +30,8 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { private val soFile: File private val downloadFile: File private var cpuAbi: String? = null - private var md5: String? = null + private var md5: String? = appCtx.getPrefString("soMd5") + private val version: String? = appCtx.getPrefString("soVersion", ImplVersion.getCronetVersion()) var download = false private var executor: Executor = Executors.newSingleThreadExecutor() @@ -54,7 +57,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { } fun preDownload() { - Thread { + executor.execute { md5 = getUrlMd5(md5Url) if (soFile.exists() && md5 == getFileMD5(soFile)) { Log.e(TAG, "So 库已存在") @@ -62,7 +65,8 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { download(soUrl, md5, downloadFile, soFile) } Log.e(TAG, soName) - }.start() + + } } @SuppressLint("UnsafeDynamicallyLoadedCode") @@ -136,14 +140,15 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { if (TextUtils.isEmpty(cpuAbi)) { cpuAbi = Build.SUPPORTED_ABIS[0] } - - //貌似只有这个过时了的API能获取当前APP使用的ABI return cpuAbi } @Suppress("SameParameterValue") private fun getUrlMd5(url: String): String? { - if (md5 != null && md5!!.length == 32) { + //这样在下载成功后,遇到无网条件下,只要版本未发生变化也能获取md5 + if (md5 != null && md5!!.length == 32&& version==ImplVersion.getCronetVersion()) { + appCtx.putPrefString("soMd5",md5) + appCtx.putPrefString("soVersion",ImplVersion.getCronetVersion()) return md5 } val inputStream: InputStream @@ -158,7 +163,15 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { outputStream.write(buffer, 0, read) outputStream.flush() } - outputStream.toString() + val tmd5=outputStream.toString() + //成功获取到md5后保存md5和版本 + if(tmd5.length==32){ + appCtx.putPrefString("soMd5",tmd5) + appCtx.putPrefString("soVersion",ImplVersion.getCronetVersion()) + } + + return tmd5 + } catch (e: IOException) { null }