diff options
author | cyBerta <cyberta@riseup.net> | 2021-11-21 19:37:58 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2021-11-21 19:39:52 +0100 |
commit | b7817e7d65e390f6e3291e856b3a69333f8f3758 (patch) | |
tree | 29fa234a818b4a2b0f8b9cdb39de929943e31389 /app/src/main | |
parent | a6cd31ae8624f830454adc627ac3a6be323a5333 (diff) |
make PreferenceHelper null safe
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java index 93284968..40b7fc05 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java @@ -2,6 +2,7 @@ package se.leap.bitmaskclient.base.utils; import android.content.Context; import android.content.SharedPreferences; + import androidx.annotation.NonNull; import androidx.annotation.WorkerThread; @@ -34,8 +35,8 @@ import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_VPN_CERTIFICA import static se.leap.bitmaskclient.base.models.Constants.RESTART_ON_UPDATE; import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; import static se.leap.bitmaskclient.base.models.Constants.SHOW_EXPERIMENTAL; -import static se.leap.bitmaskclient.base.models.Constants.USE_IPv6_FIREWALL; import static se.leap.bitmaskclient.base.models.Constants.USE_BRIDGES; +import static se.leap.bitmaskclient.base.models.Constants.USE_IPv6_FIREWALL; import static se.leap.bitmaskclient.base.models.Constants.USE_TOR; /** @@ -265,27 +266,42 @@ public class PreferenceHelper { } public static long getLong(Context context, String key, long defValue) { + if (context == null) { + return defValue; + } SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); return preferences.getLong(key, defValue); } public static void putLong(Context context, String key, long value) { + if (context == null) { + return; + } SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); preferences.edit().putLong(key, value).apply(); } public static String getString(Context context, String key, String defValue) { + if (context == null) { + return defValue; + } SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); return preferences.getString(key, defValue); } @WorkerThread public static void putStringSync(Context context, String key, String value) { + if (context == null) { + return; + } SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); preferences.edit().putString(key, value).commit(); } public static void putString(Context context, String key, String value) { + if (context == null) { + return; + } SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); preferences.edit().putString(key, value).apply(); } |