mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
让安装了GMS的低版本Android在okhttp模式时支持TLSv1.3
This commit is contained in:
@@ -49,6 +49,7 @@ class App : MultiDexApplication() {
|
||||
registerActivityLifecycleCallbacks(LifecycleHelp)
|
||||
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(AppConfig)
|
||||
Coroutine.async {
|
||||
installGmsTlsProvider(this@App)
|
||||
//初始化封面
|
||||
BookCover.toString()
|
||||
//清除过期数据
|
||||
@@ -84,6 +85,33 @@ class App : MultiDexApplication() {
|
||||
oldConfig = Configuration(newConfig)
|
||||
}
|
||||
|
||||
/**
|
||||
* 尝试在安装了GMS的设备上(GMS或者MicroG)使用GMS内置的Conscrypt
|
||||
* 作为首选JCE提供程序,而使Okhttp在低版本Android上
|
||||
* 能够启用TLSv1.3
|
||||
* https://f-droid.org/zh_Hans/2020/05/29/android-updates-and-tls-connections.html
|
||||
* https://developer.android.google.cn/reference/javax/net/ssl/SSLSocket
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
private suspend fun installGmsTlsProvider(context: Context): Boolean {
|
||||
return 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
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建通知ID
|
||||
*/
|
||||
|
||||
@@ -26,7 +26,7 @@ fun BatchChangeSourceDialog(
|
||||
cancel.invoke()
|
||||
state.value = false
|
||||
}, content = {
|
||||
Text(text = "取消")
|
||||
Text(text = appCtx.getString(R.string.cancel))
|
||||
})
|
||||
},
|
||||
title = {
|
||||
|
||||
Reference in New Issue
Block a user