From c0018a4981e318359a3741b3d1e8fd04b975353e Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Tue, 6 Mar 2018 18:31:10 +0100 Subject: 8876 - refactor EIP to service --- .../java/se/leap/bitmaskclient/ConfigHelper.java | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java b/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java index aaff9ebc..03f8a881 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java @@ -21,19 +21,16 @@ import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.util.Log; import org.json.JSONException; import org.json.JSONObject; import org.spongycastle.util.encoders.Base64; -import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.math.BigInteger; import java.net.MalformedURLException; import java.net.URL; @@ -51,13 +48,10 @@ import java.security.interfaces.RSAPrivateKey; import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Set; -import static android.R.attr.name; import static se.leap.bitmaskclient.Constants.ALWAYS_ON_SHOW_DIALOG; import static se.leap.bitmaskclient.Constants.DEFAULT_SHARED_PREFS_BATTERY_SAVER; import static se.leap.bitmaskclient.Constants.PREFERENCES_APP_VERSION; @@ -442,4 +436,19 @@ public class ConfigHelper { 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; + } + } -- cgit v1.2.3 From 203043429b2c9c2f60dbf5a66177c0b80830d5eb Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 8 Mar 2018 01:42:01 +0100 Subject: #8876 introduce blocking OpenvpnServiceConnection for EIP and cancel connections more rigid --- app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java b/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java index 03f8a881..bfc77261 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java @@ -18,6 +18,7 @@ package se.leap.bitmaskclient; 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; @@ -451,4 +452,11 @@ public class ConfigHelper { return result; } + 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"); + } + } } -- cgit v1.2.3