|
|
@ -6,6 +6,8 @@ import android.content.pm.ApplicationInfo |
|
|
|
import android.os.Build |
|
|
|
import android.os.Build |
|
|
|
import android.text.TextUtils |
|
|
|
import android.text.TextUtils |
|
|
|
import android.util.Log |
|
|
|
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.CronetEngine |
|
|
|
import org.chromium.net.impl.ImplVersion |
|
|
|
import org.chromium.net.impl.ImplVersion |
|
|
|
import splitties.init.appCtx |
|
|
|
import splitties.init.appCtx |
|
|
@ -28,7 +30,8 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { |
|
|
|
private val soFile: File |
|
|
|
private val soFile: File |
|
|
|
private val downloadFile: File |
|
|
|
private val downloadFile: File |
|
|
|
private var cpuAbi: String? = null |
|
|
|
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 |
|
|
|
var download = false |
|
|
|
private var executor: Executor = Executors.newSingleThreadExecutor() |
|
|
|
private var executor: Executor = Executors.newSingleThreadExecutor() |
|
|
|
|
|
|
|
|
|
|
@ -54,7 +57,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun preDownload() { |
|
|
|
fun preDownload() { |
|
|
|
Thread { |
|
|
|
executor.execute { |
|
|
|
md5 = getUrlMd5(md5Url) |
|
|
|
md5 = getUrlMd5(md5Url) |
|
|
|
if (soFile.exists() && md5 == getFileMD5(soFile)) { |
|
|
|
if (soFile.exists() && md5 == getFileMD5(soFile)) { |
|
|
|
Log.e(TAG, "So 库已存在") |
|
|
|
Log.e(TAG, "So 库已存在") |
|
|
@ -62,7 +65,8 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { |
|
|
|
download(soUrl, md5, downloadFile, soFile) |
|
|
|
download(soUrl, md5, downloadFile, soFile) |
|
|
|
} |
|
|
|
} |
|
|
|
Log.e(TAG, soName) |
|
|
|
Log.e(TAG, soName) |
|
|
|
}.start() |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("UnsafeDynamicallyLoadedCode") |
|
|
|
@SuppressLint("UnsafeDynamicallyLoadedCode") |
|
|
@ -136,14 +140,15 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { |
|
|
|
if (TextUtils.isEmpty(cpuAbi)) { |
|
|
|
if (TextUtils.isEmpty(cpuAbi)) { |
|
|
|
cpuAbi = Build.SUPPORTED_ABIS[0] |
|
|
|
cpuAbi = Build.SUPPORTED_ABIS[0] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//貌似只有这个过时了的API能获取当前APP使用的ABI |
|
|
|
|
|
|
|
return cpuAbi |
|
|
|
return cpuAbi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Suppress("SameParameterValue") |
|
|
|
@Suppress("SameParameterValue") |
|
|
|
private fun getUrlMd5(url: String): String? { |
|
|
|
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 |
|
|
|
return md5 |
|
|
|
} |
|
|
|
} |
|
|
|
val inputStream: InputStream |
|
|
|
val inputStream: InputStream |
|
|
@ -158,7 +163,15 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { |
|
|
|
outputStream.write(buffer, 0, read) |
|
|
|
outputStream.write(buffer, 0, read) |
|
|
|
outputStream.flush() |
|
|
|
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) { |
|
|
|
} catch (e: IOException) { |
|
|
|
null |
|
|
|
null |
|
|
|
} |
|
|
|
} |
|
|
|