From 988bd203ee14a589eef58a4aa6bd51a5b005d072 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Mon, 30 Dec 2019 17:16:14 +0100 Subject: reduce su calls, add logging, save if su exists and was allowed to preferences --- .../leap/bitmaskclient/utils/PreferenceHelper.java | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java') 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..bf97b5c5 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,6 +215,14 @@ 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; @@ -296,9 +305,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(); + } + } -- cgit v1.2.3