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

This commit is contained in:
ag2s20150909
2022-10-17 17:52:34 +08:00
parent c40d59d71d
commit 0f68aff302
2 changed files with 29 additions and 1 deletions

View File

@@ -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
*/

View File

@@ -26,7 +26,7 @@ fun BatchChangeSourceDialog(
cancel.invoke()
state.value = false
}, content = {
Text(text = "取消")
Text(text = appCtx.getString(R.string.cancel))
})
},
title = {