diff options
author | cyBerta <cyberta@riseup.net> | 2019-12-30 17:16:14 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2019-12-30 17:16:14 +0100 |
commit | 988bd203ee14a589eef58a4aa6bd51a5b005d072 (patch) | |
tree | 374ca8b476c5275ebe7d93d25a575fa8a29e12ba /app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java | |
parent | 22eb43939a8bcae2ed7f89d37abf023fc33c485f (diff) |
reduce su calls, add logging, save if su exists and was allowed to preferences
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.java | 29 |
1 files changed, 28 insertions, 1 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..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(); + } + } |