Use TLSSocketFactoryCompat for Picasso to enable TLSv1.1/1.2 on <=KitKat devices

This commit is contained in:
evermind 2021-11-06 08:01:28 +01:00
parent d1d97a79f0
commit 5c7afbf4d4
2 changed files with 5 additions and 2 deletions

View file

@ -35,8 +35,9 @@ public final class OkHttpTlsHelper {
* </p>
*
* @param builder The HTTPClient Builder on which TLS is enabled on (will be modified in-place)
* @return the same builder that was supplied. So the method can be chained.
*/
public static void enableModernTLS(final OkHttpClient.Builder builder) {
public static OkHttpClient.Builder enableModernTLS(final OkHttpClient.Builder builder) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
try {
// get the default TrustManager
@ -77,5 +78,7 @@ public final class OkHttpTlsHelper {
}
}
}
return builder;
}
}

View file

@ -40,7 +40,7 @@ public final class PicassoHelper {
public static void init(final Context context) {
picassoCache = new LruCache(10 * 1024 * 1024);
picassoDownloaderClient = new OkHttpClient.Builder()
picassoDownloaderClient = OkHttpTlsHelper.enableModernTLS(new OkHttpClient.Builder())
.cache(new okhttp3.Cache(new File(context.getExternalCacheDir(), "picasso"),
50 * 1024 * 1024))
// this should already be the default timeout in OkHttp3, but just to be sure...