summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java65
1 files changed, 34 insertions, 31 deletions
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 9eac7187..40bb2eca 100644
--- a/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java
+++ b/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java
@@ -31,6 +31,7 @@ import static se.leap.bitmaskclient.Constants.PROVIDER_EIP_DEFINITION;
import static se.leap.bitmaskclient.Constants.PROVIDER_PRIVATE_KEY;
import static se.leap.bitmaskclient.Constants.PROVIDER_VPN_CERTIFICATE;
import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
+import static se.leap.bitmaskclient.Constants.SU_PERMISSION;
import static se.leap.bitmaskclient.Constants.USE_PLUGGABLE_TRANSPORTS;
import static se.leap.bitmaskclient.Constants.EXCLUDED_APPS;
@@ -214,52 +215,36 @@ public class PreferenceHelper {
apply();
}
+ public static boolean hasSuPermission(Context context) {
+ return getBoolean(context, SU_PERMISSION, false);
+ }
+
+ public static void setSuPermission(Context context, boolean allowed) {
+ putBoolean(context, SU_PERMISSION, allowed);
+ }
+
public static boolean getUsePluggableTransports(Context context) {
- if (context == null) {
- return false;
- }
- SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
- return preferences.getBoolean(USE_PLUGGABLE_TRANSPORTS, false);
+ return getBoolean(context, USE_PLUGGABLE_TRANSPORTS, false);
}
public static void usePluggableTransports(Context context, boolean isEnabled) {
- if (context == null) {
- return;
- }
- SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
- preferences.edit().putBoolean(USE_PLUGGABLE_TRANSPORTS, isEnabled).apply();
+ putBoolean(context, USE_PLUGGABLE_TRANSPORTS, isEnabled);
}
public static void saveBattery(Context context, boolean isEnabled) {
- if (context == null) {
- return;
- }
- SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
- preferences.edit().putBoolean(DEFAULT_SHARED_PREFS_BATTERY_SAVER, isEnabled).apply();
+ putBoolean(context, DEFAULT_SHARED_PREFS_BATTERY_SAVER, isEnabled);
}
public static boolean getSaveBattery(Context context) {
- if (context == null) {
- return false;
- }
- SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
- return preferences.getBoolean(DEFAULT_SHARED_PREFS_BATTERY_SAVER, false);
+ return getBoolean(context, DEFAULT_SHARED_PREFS_BATTERY_SAVER, false);
}
public static void saveShowAlwaysOnDialog(Context context, boolean showAlwaysOnDialog) {
- if (context == null) {
- return;
- }
- SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
- preferences.edit().putBoolean(ALWAYS_ON_SHOW_DIALOG, showAlwaysOnDialog).apply();
+ putBoolean(context, ALWAYS_ON_SHOW_DIALOG, showAlwaysOnDialog);
}
public static boolean getShowAlwaysOnDialog(Context context) {
- if (context == null) {
- return true;
- }
- SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
- return preferences.getBoolean(ALWAYS_ON_SHOW_DIALOG, true);
+ return getBoolean(context, ALWAYS_ON_SHOW_DIALOG, true);
}
public static JSONObject getEipDefinitionFromPreferences(SharedPreferences preferences) {
@@ -296,9 +281,27 @@ public class PreferenceHelper {
return preferences.getString(key, defValue);
}
- public static void putString(Context context, String key, String value){
+ public static void putString(Context context, String key, String value) {
SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
preferences.edit().putString(key, value).apply();
}
+ public static Boolean getBoolean(Context context, String key, Boolean defValue) {
+ if (context == null) {
+ return false;
+ }
+
+ SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
+ return preferences.getBoolean(key, defValue);
+ }
+
+ public static void putBoolean(Context context, String key, Boolean value) {
+ if (context == null) {
+ return;
+ }
+
+ SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
+ preferences.edit().putBoolean(key, value).apply();
+ }
+
}