summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/utils
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2018-05-12 12:06:01 +0200
committercyBerta <cyberta@riseup.net>2018-05-12 12:06:01 +0200
commit483d89f3599f06c19141c7817ada43ff2a33c461 (patch)
treec289d1384eb8af8bcb13e2b7f3569f682a68862f /app/src/main/java/se/leap/bitmaskclient/utils
parent93d4870267455b30d10c9ce6be76465e88cc50d1 (diff)
parent4d744883a032e6f1669ac9527797d8d9cad9f5fe (diff)
Merge branch 'cyberta_master' into #8885_testing_ProviderManager
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/utils')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/utils/ConfigHelper.java9
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java22
2 files changed, 31 insertions, 0 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/utils/ConfigHelper.java b/app/src/main/java/se/leap/bitmaskclient/utils/ConfigHelper.java
index bb9fb2d4..5bb637b7 100644
--- a/app/src/main/java/se/leap/bitmaskclient/utils/ConfigHelper.java
+++ b/app/src/main/java/se/leap/bitmaskclient/utils/ConfigHelper.java
@@ -16,6 +16,8 @@
*/
package se.leap.bitmaskclient.utils;
+import android.content.Context;
+import android.os.Looper;
import android.support.annotation.NonNull;
import org.json.JSONException;
@@ -157,5 +159,12 @@ public class ConfigHelper {
return byteArrayToHex(byteArray);
}
+ public static void ensureNotOnMainThread(@NonNull Context context) throws IllegalStateException{
+ Looper looper = Looper.myLooper();
+ if (looper != null && looper == context.getMainLooper()) {
+ throw new IllegalStateException(
+ "calling this from your main thread can lead to deadlock");
+ }
+ }
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java b/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java
index 92f025b2..12015dfb 100644
--- a/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java
+++ b/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java
@@ -2,6 +2,7 @@ package se.leap.bitmaskclient.utils;
import android.content.Context;
import android.content.SharedPreferences;
+import android.os.Looper;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -9,6 +10,12 @@ import android.support.annotation.Nullable;
import org.json.JSONException;
import org.json.JSONObject;
+import java.io.ByteArrayInputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
@@ -217,4 +224,19 @@ public class PreferenceHelper {
SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE);
return preferences.getBoolean(ALWAYS_ON_SHOW_DIALOG, true);
}
+
+ public static JSONObject getEipDefinitionFromPreferences(SharedPreferences preferences) {
+ JSONObject result = new JSONObject();
+ try {
+ String eipDefinitionString = preferences.getString(PROVIDER_EIP_DEFINITION, "");
+ if (!eipDefinitionString.isEmpty()) {
+ result = new JSONObject(eipDefinitionString);
+ }
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return result;
+ }
+
}