From 0f68aff302d8ca3b6d2ca03e4604e35048653a4a Mon Sep 17 00:00:00 2001 From: ag2s20150909 Date: Mon, 17 Oct 2022 17:52:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A9=E5=AE=89=E8=A3=85=E4=BA=86GMS?= =?UTF-8?q?=E7=9A=84=E4=BD=8E=E7=89=88=E6=9C=ACAndroid=E5=9C=A8okhttp?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E6=97=B6=E6=94=AF=E6=8C=81TLSv1.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/App.kt | 28 +++++++++++++++++++ .../legado/app/ui/book/manage/ComposeView.kt | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 0ffea5a41..eedbf56b8 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.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 */ diff --git a/app/src/main/java/io/legado/app/ui/book/manage/ComposeView.kt b/app/src/main/java/io/legado/app/ui/book/manage/ComposeView.kt index ffa57baa2..c3a813de4 100644 --- a/app/src/main/java/io/legado/app/ui/book/manage/ComposeView.kt +++ b/app/src/main/java/io/legado/app/ui/book/manage/ComposeView.kt @@ -26,7 +26,7 @@ fun BatchChangeSourceDialog( cancel.invoke() state.value = false }, content = { - Text(text = "取消") + Text(text = appCtx.getString(R.string.cancel)) }) }, title = {