diff options
author | cyBerta <cyberta@riseup.net> | 2018-05-12 12:06:01 +0200 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2018-05-12 12:06:01 +0200 |
commit | 483d89f3599f06c19141c7817ada43ff2a33c461 (patch) | |
tree | c289d1384eb8af8bcb13e2b7f3569f682a68862f /app/src/main/java/se/leap/bitmaskclient/utils | |
parent | 93d4870267455b30d10c9ce6be76465e88cc50d1 (diff) | |
parent | 4d744883a032e6f1669ac9527797d8d9cad9f5fe (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.java | 9 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java | 22 |
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; + } + } |