让安装了GMS的低版本Android在okhttp模式时支持TLSv1.3

pull/2449/head
ag2s20150909 2 years ago
parent c40d59d71d
commit 0f68aff302
  1. 28
      app/src/main/java/io/legado/app/App.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/manage/ComposeView.kt

@ -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 = {

Loading…
Cancel
Save