This commit is contained in:
kunfei
2022-10-17 21:02:11 +08:00
parent a72e94522a
commit ff75c024a9
+23 -15
View File
@@ -28,6 +28,10 @@ import io.legado.app.help.http.cronet.CronetLoader
import io.legado.app.model.BookCover import io.legado.app.model.BookCover
import io.legado.app.utils.defaultSharedPreferences import io.legado.app.utils.defaultSharedPreferences
import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefBoolean
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import splitties.systemservices.notificationManager import splitties.systemservices.notificationManager
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@@ -49,7 +53,7 @@ class App : MultiDexApplication() {
registerActivityLifecycleCallbacks(LifecycleHelp) registerActivityLifecycleCallbacks(LifecycleHelp)
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(AppConfig) defaultSharedPreferences.registerOnSharedPreferenceChangeListener(AppConfig)
Coroutine.async { Coroutine.async {
installGmsTlsProvider(this@App) installGmsTlsProviderAsync(this@App).start()
//初始化封面 //初始化封面
BookCover.toString() BookCover.toString()
//清除过期数据 //清除过期数据
@@ -95,20 +99,24 @@ class App : MultiDexApplication() {
* @param context * @param context
* @return * @return
*/ */
private suspend fun installGmsTlsProvider(context: Context): Boolean { private suspend fun installGmsTlsProviderAsync(context: Context): Deferred<Boolean> {
return try { return coroutineScope {
val gms = context.createPackageContext( async(IO) {
"com.google.android.gms", try {
CONTEXT_INCLUDE_CODE or CONTEXT_IGNORE_SECURITY val gms = context.createPackageContext(
) "com.google.android.gms",
gms.classLoader CONTEXT_INCLUDE_CODE or CONTEXT_IGNORE_SECURITY
.loadClass("com.google.android.gms.common.security.ProviderInstallerImpl") )
.getMethod("insertProvider", Context::class.java) gms.classLoader
.invoke(null, gms) .loadClass("com.google.android.gms.common.security.ProviderInstallerImpl")
true .getMethod("insertProvider", Context::class.java)
} catch (e: java.lang.Exception) { .invoke(null, gms)
e.printStackTrace() true
false } catch (e: java.lang.Exception) {
e.printStackTrace()
false
}
}
} }
} }