aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2016-08-22 08:55:37 +0200
committersteckbrief <steckbrief@chefmail.de>2016-08-22 08:55:37 +0200
commit77d0c1110a8ae7a980f1c4420d719af803990da8 (patch)
tree20d3ce434f3c6d740141727d4c143ea5f027a646 /src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java
parent97100834a5bcb08f2fdf2eb6c580d3ceeb8b6b2f (diff)
parentf45ad10b1baaf09fd4a40d6b63d1cd093623eedc (diff)
Merge remote-tracking branch 'remotes/origin/filetransfer'
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java b/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java
index a9f0c6ad..26854205 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java
@@ -3,12 +3,20 @@ 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.HttpConnectionManager;
import de.thedevstack.conversationsplus.persistance.FileBackend;
+import de.thedevstack.conversationsplus.services.filetransfer.FileTransferManager;
+import de.thedevstack.conversationsplus.services.filetransfer.httpupload.HttpUploadFileTransferService;
+import de.thedevstack.conversationsplus.services.filetransfer.jingle.JingleFileTransferService;
import de.thedevstack.conversationsplus.utils.ImageUtil;
+import de.thedevstack.conversationsplus.utils.PRNGFixes;
import de.thedevstack.conversationsplus.utils.SerialSingleThreadExecutor;
/**
@@ -23,6 +31,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.
*/
@@ -30,8 +41,20 @@ 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();
+ }
+
+ /**
+ * Initializes security features.
+ */
+ private void initializeSecurity() {
+ PRNGFixes.apply();
+ this.secureRandom = new SecureRandom();
+ ConversationsPlusApplication.updateMemorizingTrustmanager();
}
/**
@@ -100,4 +123,31 @@ 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);
+ }
+
+ public static SecureRandom getSecureRandom() {
+ return getInstance().secureRandom;
+ }
}