Lazily init Conscrypt

This commit is contained in:
xynngh 2020-07-03 20:24:19 +04:00
parent 110402b9fe
commit f4caa0ef89
4 changed files with 37 additions and 8 deletions

View File

@ -39,7 +39,7 @@ dependencies {
implementation 'org.conscrypt:conscrypt-android:2.4.0'
//noinspection GradleDependency: 3.12.* is the latest version compatible with Android <5
implementation 'com.squareup.okhttp3:okhttp:3.12.12'
implementation 'com.gitlab.xynngh:LibPhoneNumberInfo:6292917c02'
implementation 'com.gitlab.xynngh:LibPhoneNumberInfo:fd60ad9583'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'

View File

@ -5,11 +5,8 @@ import android.app.Application;
import android.content.Context;
import android.os.Build;
import org.conscrypt.Conscrypt;
import org.greenrobot.eventbus.EventBus;
import java.security.Security;
import dummydomain.yetanothercallblocker.data.Config;
public class App extends Application {
@ -33,8 +30,6 @@ public class App extends Application {
instance = this;
Security.insertProviderAt(Conscrypt.newProvider(), 1);
new DeviceProtectedStorageMigrator().migrate(this);
settings = new Settings(getDeviceProtectedStorageContext());

View File

@ -15,8 +15,12 @@ import dummydomain.yetanothercallblocker.sia.model.database.AbstractDatabase;
import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabase;
import dummydomain.yetanothercallblocker.sia.model.database.DbManager;
import dummydomain.yetanothercallblocker.sia.model.database.FeaturedDatabase;
import dummydomain.yetanothercallblocker.sia.network.DbDownloader;
import dummydomain.yetanothercallblocker.sia.network.OkHttpClientFactory;
import dummydomain.yetanothercallblocker.sia.network.WebService;
import dummydomain.yetanothercallblocker.sia.utils.Utils;
import dummydomain.yetanothercallblocker.utils.DeferredInit;
import okhttp3.OkHttpClient;
import static dummydomain.yetanothercallblocker.data.SiaConstants.SIA_PATH_PREFIX;
import static dummydomain.yetanothercallblocker.data.SiaConstants.SIA_PROPERTIES;
@ -86,13 +90,19 @@ public class Config {
Settings siaSettings
= new SettingsImpl(new AndroidProperties(context, SIA_PROPERTIES));
OkHttpClientFactory okHttpClientFactory = () -> {
DeferredInit.initNetwork();
return new OkHttpClient();
};
WSParameterProvider wsParameterProvider = new WSParameterProvider();
wsParameterProvider.setSettings(settings);
WebService webService = new WebService(wsParameterProvider);
WebService webService = new WebService(wsParameterProvider, okHttpClientFactory);
DatabaseSingleton.setWebService(webService);
DatabaseSingleton.setDbManager(new DbManager(storage, SIA_PATH_PREFIX));
DatabaseSingleton.setDbManager(new DbManager(storage, SIA_PATH_PREFIX,
new DbDownloader(okHttpClientFactory)));
CommunityDatabase communityDatabase = new CommunityDatabase(
storage, AbstractDatabase.Source.ANY, SIA_PATH_PREFIX,

View File

@ -0,0 +1,24 @@
package dummydomain.yetanothercallblocker.utils;
import org.conscrypt.Conscrypt;
import java.security.Security;
public class DeferredInit {
private static boolean networkInitialized;
private static final Object NETWORK_INIT_LOCK = new Object();
public static void initNetwork() {
if (networkInitialized) return;
synchronized (NETWORK_INIT_LOCK) {
if (networkInitialized) return;
Security.insertProviderAt(Conscrypt.newProvider(), 1);
networkInitialized = true;
}
}
}