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 }