aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2016-05-29 20:33:36 +0200
committersteckbrief <steckbrief@chefmail.de>2016-05-29 20:33:36 +0200
commitb1ab7347b92329512bebe57f6624cae33c27036f (patch)
tree9234c39535e6320d0ca217b9e28e3dfcd0eb56ea /src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java
parentd3a2fe5796e18493a8ff641308d2c6d21bfd06a4 (diff)
FileTransfer reworked (first steps - functionality as is), HttpUpload
separated, some bugfixes - HttpUpload moved into own package - FileTransfer managed by a central manager class, several FileTransferService implementation can be used - Security initializations moved to ConversationsPlusApplication - Access to PowerManager moved to ConversationsPlusApplication - Removed unused code fragments - Access to HttpConnectionManager is now static
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;
+ }
}