fixx ssl handshake exception

This commit is contained in:
2025-08-29 21:29:25 +02:00
parent 94d9d179c1
commit fde4dc10df
3 changed files with 89 additions and 13 deletions

View File

@@ -5,10 +5,19 @@ import com.onesignal.OneSignal;
import com.squareup.picasso.OkHttp3Downloader;
import com.squareup.picasso.Picasso;
import java.security.SecureRandom;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import ch.pizzalemon.android.api.ApiConstants;
import ch.pizzalemon.android.api.SSLTrustManager;
import io.github.inflationx.calligraphy3.CalligraphyConfig;
import io.github.inflationx.calligraphy3.CalligraphyInterceptor;
import io.github.inflationx.viewpump.ViewPump;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
/**
* Created by cimenmus on 11/09/2017.
@@ -35,20 +44,25 @@ public class App extends MultiDexApplication {
}
private void initPicasso(){
// DISK CACHE
// Disk cache of 2% storage space up to 50MB but no less than 5MB
// 48 megabyte
//Picasso picasso = new Picasso.Builder(this).downloader(new OkHttp3Downloader(getCacheDir(), 48 * 1024 * 1024)).build();
Picasso picasso = new Picasso.Builder(this).downloader(new OkHttp3Downloader(getCacheDir())).build();
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.cache(new Cache(getCacheDir(), 48 * 1024 * 1024))
.connectTimeout(ApiConstants.API_CONNECT_TIMEOUT, java.util.concurrent.TimeUnit.SECONDS)
.readTimeout(ApiConstants.API_READ_TIMEOUT, java.util.concurrent.TimeUnit.SECONDS)
.retryOnConnectionFailure(true)
.addInterceptor(logging);
addSSLTrustToOkHttp(builder);
OkHttpClient okHttpClient = builder.build();
OkHttp3Downloader okHttp3Downloader = new OkHttp3Downloader(okHttpClient);
Picasso picasso = new Picasso.Builder(this)
.downloader(okHttp3Downloader)
.build();
Picasso.setSingletonInstance(picasso);
/*
// MEMORY CACHE
//default cache size is %15 of available memory
// LRU memory cache of 15% the available application RAM
//LruCache() takes byte parameter. Here is 4 megabyte
Picasso.Builder picassoBuilder = new Picasso.Builder(this).memoryCache(new LruCache(8 * 1024 * 1024));
Picasso.setSingletonInstance(picassoBuilder.build());
*/
}
private void initOneSignal(){
@@ -56,4 +70,17 @@ public class App extends MultiDexApplication {
OneSignal.setAppId(ApiConstants.ONESIGNAL_APP_ID);
OneSignal.unsubscribeWhenNotificationsAreDisabled(true);
}
private void addSSLTrustToOkHttp(OkHttpClient.Builder okHttpClientBuilder) {
try {
TrustManager[] trustAllCerts = new TrustManager[]{new SSLTrustManager()};
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new SecureRandom());
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
okHttpClientBuilder.sslSocketFactory(sslContext.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
}
}
}