diff options
author | steckbrief <steckbrief@chefmail.de> | 2016-10-20 19:45:26 +0200 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2016-10-20 19:45:26 +0200 |
commit | 59e861ee6904296cbe8dd43c4a29513c2e928981 (patch) | |
tree | a3bf768814ece1c377caefca35bc535c758a47c5 /src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java | |
parent | 2860088f0ea1cd5753756861c71cc7c118094f32 (diff) | |
parent | 9ec29bb1dcf664fea606105b7e700641a4b44ae4 (diff) |
Merge remote-tracking branch 'remotes/origin/trz/rename' into trz/rebase
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java b/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java index 4b11bb4a..fb1e9392 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java +++ b/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java @@ -3,15 +3,25 @@ package de.thedevstack.conversationsplus; import android.app.Application; import android.content.Context; import android.content.pm.PackageManager; +import android.os.PowerManager; import android.preference.PreferenceManager; import java.io.File; +import java.security.SecureRandom; +import de.duenndns.ssl.MemorizingTrustManager; +import de.thedevstack.conversationsplus.http.HttpClient; import de.thedevstack.conversationsplus.utils.ImageUtil; +import de.thedevstack.conversationsplus.services.filetransfer.FileTransferManager; +import de.thedevstack.conversationsplus.services.filetransfer.http.upload.HttpUploadFileTransferService; +import de.thedevstack.conversationsplus.services.filetransfer.jingle.JingleFileTransferService; import eu.siacs.conversations.R; +import eu.siacs.conversations.http.HttpConnectionManager; +import eu.siacs.conversations.utils.PRNGFixes; import eu.siacs.conversations.persistance.FileBackend; import eu.siacs.conversations.utils.SerialSingleThreadExecutor; +import okhttp3.OkHttpClient; /** * This class is used to provide static access to the applicationcontext. @@ -25,6 +35,9 @@ public class ConversationsPlusApplication extends Application { private final SerialSingleThreadExecutor mFileAddingExecutor = new SerialSingleThreadExecutor(); private final SerialSingleThreadExecutor mDatabaseExecutor = new SerialSingleThreadExecutor(); + private MemorizingTrustManager memorizingTrustManager; + private SecureRandom secureRandom; + /** * Initializes the application and saves its instance. */ @@ -32,8 +45,21 @@ public class ConversationsPlusApplication extends Application { super.onCreate(); ConversationsPlusApplication.instance = this; ConversationsPlusPreferences.init(PreferenceManager.getDefaultSharedPreferences(getAppContext())); + this.initializeSecurity(); ImageUtil.initBitmapCache(); FileBackend.init(); + FileTransferManager.init(new HttpUploadFileTransferService(), new JingleFileTransferService()); + HttpConnectionManager.init(); + HttpClient.init(); + } + + /** + * Initializes security features. + */ + private void initializeSecurity() { + PRNGFixes.apply(); + this.secureRandom = new SecureRandom(); + ConversationsPlusApplication.updateMemorizingTrustmanager(); } /** @@ -102,4 +128,36 @@ public class ConversationsPlusApplication extends Application { public static String getNameAndVersion() { return getName() + " " + getVersion(); } + + public static PowerManager.WakeLock createPartialWakeLock(String name) { + PowerManager powerManager = (PowerManager) getAppContext().getSystemService(Context.POWER_SERVICE); + return powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, name); + } + + public static MemorizingTrustManager getMemorizingTrustManager() { + return getInstance().memorizingTrustManager; + } + + public void setMemorizingTrustManager(MemorizingTrustManager trustManager) { + this.memorizingTrustManager = trustManager; + } + + public static void updateMemorizingTrustmanager() { + final MemorizingTrustManager tm; + if (ConversationsPlusPreferences.dontTrustSystemCAs()) { + tm = new MemorizingTrustManager(getAppContext(), null); + } else { + tm = new MemorizingTrustManager(getAppContext()); + } + getInstance().setMemorizingTrustManager(tm); + } + + private static void initHttpClient() { + OkHttpClient client = new OkHttpClient.Builder() + .build(); + } + + public static SecureRandom getSecureRandom() { + return getInstance().secureRandom; + } } |