From 830ecde32fbaba5db0a0e5c0b5d3422aa45d5c29 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 17 Oct 2022 23:03:08 +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 --- app/src/main/java/io/legado/app/App.kt | 38 +++++++++++--------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index a9f1f0d22..c47bba828 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -28,10 +28,9 @@ import io.legado.app.help.http.cronet.CronetLoader import io.legado.app.model.BookCover import io.legado.app.utils.defaultSharedPreferences import io.legado.app.utils.getPrefBoolean -import kotlinx.coroutines.Deferred -import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.async -import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.delay +import splitties.init.appCtx import splitties.systemservices.notificationManager import java.util.concurrent.TimeUnit @@ -53,7 +52,7 @@ class App : MultiDexApplication() { registerActivityLifecycleCallbacks(LifecycleHelp) defaultSharedPreferences.registerOnSharedPreferenceChangeListener(AppConfig) Coroutine.async { - installGmsTlsProviderAsync(this@App).start() + async { installGmsTlsProvider(appCtx) }.start() //初始化封面 BookCover.toString() //清除过期数据 @@ -99,24 +98,19 @@ class App : MultiDexApplication() { * @param context * @return */ - private suspend fun installGmsTlsProviderAsync(context: Context): Deferred { - return coroutineScope { - async(IO) { - try { - val gms = context.createPackageContext( - "com.google.android.gms", - CONTEXT_INCLUDE_CODE or CONTEXT_IGNORE_SECURITY - ) - gms.classLoader - .loadClass("com.google.android.gms.common.security.ProviderInstallerImpl") - .getMethod("insertProvider", Context::class.java) - .invoke(null, gms) - true - } catch (e: java.lang.Exception) { - e.printStackTrace() - false - } - } + private suspend fun installGmsTlsProvider(context: Context) { + try { + val gms = context.createPackageContext( + "com.google.android.gms", + CONTEXT_INCLUDE_CODE or CONTEXT_IGNORE_SECURITY + ) + gms.classLoader + .loadClass("com.google.android.gms.common.security.ProviderInstallerImpl") + .getMethod("insertProvider", Context::class.java) + .invoke(null, gms) + delay(1000) + } catch (e: java.lang.Exception) { + e.printStackTrace() } }