diff options
author | Arne Schwabe <arne@rfc2549.org> | 2017-01-08 16:55:19 +0100 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2017-01-08 16:55:31 +0100 |
commit | db3fa686e93cfd2dd1d25a3afb9f9cbb10e9536a (patch) | |
tree | 962506b647f9a683ad7508a48e5d12e4b32aee79 /main/src | |
parent | 6717094a10174223d716d0c296ad9e3f4413c173 (diff) |
Use multi process on sharedpreferences until I have time for a proper fix
Diffstat (limited to 'main/src')
9 files changed, 61 insertions, 25 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java b/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java index 7545869f..ad5171e8 100644 --- a/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java +++ b/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java @@ -37,6 +37,7 @@ import de.blinkt.openvpn.core.ConnectionStatus; import de.blinkt.openvpn.core.IServiceStatus; import de.blinkt.openvpn.core.OpenVPNStatusService; import de.blinkt.openvpn.core.PasswordCache; +import de.blinkt.openvpn.core.Preferences; import de.blinkt.openvpn.core.ProfileManager; import de.blinkt.openvpn.core.VPNLaunchHelper; import de.blinkt.openvpn.core.VpnStatus; @@ -128,7 +129,7 @@ public class LaunchVPN extends Activity { if (Intent.ACTION_MAIN.equals(action)) { // Check if we need to clear the log - if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(CLEARLOG, true)) + if (Preferences.getDefaultSharedPreferences(this).getBoolean(CLEARLOG, true)) VpnStatus.clearLog(); // we got called to be the starting point, most likely a shortcut @@ -233,7 +234,7 @@ public class LaunchVPN extends Activity { ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT); askForPW(needpw); } else { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + SharedPreferences prefs = Preferences.getDefaultSharedPreferences(this); boolean showLogWindow = prefs.getBoolean("showlogwindow", true); if (!mhideLog && showLogWindow) @@ -305,7 +306,7 @@ public class LaunchVPN extends Activity { Intent intent = VpnService.prepare(this); // Check if we want to fix /dev/tun - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + SharedPreferences prefs = Preferences.getDefaultSharedPreferences(this); boolean usecm9fix = prefs.getBoolean("useCM9Fix", false); boolean loadTunModule = prefs.getBoolean("loadTunModule", false); diff --git a/main/src/main/java/de/blinkt/openvpn/OnBootReceiver.java b/main/src/main/java/de/blinkt/openvpn/OnBootReceiver.java index 4f9d6f91..89b5e8d2 100644 --- a/main/src/main/java/de/blinkt/openvpn/OnBootReceiver.java +++ b/main/src/main/java/de/blinkt/openvpn/OnBootReceiver.java @@ -9,8 +9,8 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.preference.PreferenceManager; +import de.blinkt.openvpn.core.Preferences; import de.blinkt.openvpn.core.ProfileManager; @@ -21,7 +21,7 @@ public class OnBootReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + SharedPreferences prefs = Preferences.getDefaultSharedPreferences(context); boolean useStartOnBoot = prefs.getBoolean("restartvpnonboot", false); if (!useStartOnBoot) diff --git a/main/src/main/java/de/blinkt/openvpn/api/ExternalAppDatabase.java b/main/src/main/java/de/blinkt/openvpn/api/ExternalAppDatabase.java index 2f62026b..f569abf2 100644 --- a/main/src/main/java/de/blinkt/openvpn/api/ExternalAppDatabase.java +++ b/main/src/main/java/de/blinkt/openvpn/api/ExternalAppDatabase.java @@ -5,13 +5,14 @@ package de.blinkt.openvpn.api; -import java.util.HashSet; -import java.util.Set; - import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; -import android.preference.PreferenceManager; + +import java.util.HashSet; +import java.util.Set; + +import de.blinkt.openvpn.core.Preferences; public class ExternalAppDatabase { @@ -31,7 +32,7 @@ public class ExternalAppDatabase { } public Set<String> getExtAppList() { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); + SharedPreferences prefs = Preferences.getDefaultSharedPreferences(mContext); return prefs.getStringSet(PREFERENCES_KEY, new HashSet<String>()); } @@ -43,7 +44,7 @@ public class ExternalAppDatabase { } private void saveExtAppList( Set<String> allowedapps) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); + SharedPreferences prefs = Preferences.getDefaultSharedPreferences(mContext); Editor prefedit = prefs.edit(); prefedit.putStringSet(PREFERENCES_KEY, allowedapps); prefedit.apply(); diff --git a/main/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java b/main/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java index ccd5f7ff..f36840f5 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java +++ b/main/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java @@ -135,7 +135,7 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL @Override
public void onReceive(Context context, Intent intent) {
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ SharedPreferences prefs = Preferences.getDefaultSharedPreferences(context); if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
@@ -181,7 +181,7 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL public void networkStateChange(Context context) {
NetworkInfo networkInfo = getCurrentNetworkInfo(context);
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ SharedPreferences prefs = Preferences.getDefaultSharedPreferences(context); boolean sendusr1 = prefs.getBoolean("netchangereconnect", true);
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java index 5866cd00..f5778d1a 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java +++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java @@ -496,7 +496,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac mStarting = false; // Start a new session by creating a new thread. - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + SharedPreferences prefs = Preferences.getDefaultSharedPreferences(this); mOvpn3 = prefs.getBoolean("ovpn3", false); if (!"ovpn3".equals(BuildConfig.FLAVOR)) diff --git a/main/src/main/java/de/blinkt/openvpn/core/Preferences.java b/main/src/main/java/de/blinkt/openvpn/core/Preferences.java new file mode 100644 index 00000000..16da955f --- /dev/null +++ b/main/src/main/java/de/blinkt/openvpn/core/Preferences.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012-2016 Arne Schwabe + * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt + */ + +package de.blinkt.openvpn.core; + +import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; + +import de.blinkt.openvpn.LaunchVPN; + +/** + * Created by arne on 08.01.17. + */ + +// Until I find a good solution + +public class Preferences { + + static SharedPreferences getSharedPreferencesMulti(String name, Context c) { + return c.getSharedPreferences(name, Context.MODE_MULTI_PROCESS | Context.MODE_PRIVATE); + + } + + + public static SharedPreferences getDefaultSharedPreferences(Context c) { + return c.getSharedPreferences(c.getPackageName() + "_preferences", Context.MODE_MULTI_PROCESS | Context.MODE_PRIVATE); + + } + + +} diff --git a/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java b/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java index bce5e288..f6643fbc 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java +++ b/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java @@ -9,8 +9,6 @@ import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; -import android.content.pm.ShortcutManager; -import android.preference.PreferenceManager; import java.io.IOException; import java.io.ObjectInputStream; @@ -60,7 +58,7 @@ public class ProfileManager { } public static void setConntectedVpnProfileDisconnected(Context c) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c); + SharedPreferences prefs = Preferences.getDefaultSharedPreferences(c); Editor prefsedit = prefs.edit(); prefsedit.putString(LAST_CONNECTED_PROFILE, null); prefsedit.apply(); @@ -71,7 +69,7 @@ public class ProfileManager { * Sets the profile that is connected (to connect if the service restarts) */ public static void setConnectedVpnProfile(Context c, VpnProfile connectedProfile) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c); + SharedPreferences prefs = Preferences.getDefaultSharedPreferences(c); Editor prefsedit = prefs.edit(); prefsedit.putString(LAST_CONNECTED_PROFILE, connectedProfile.getUUIDString()); @@ -84,7 +82,7 @@ public class ProfileManager { * Returns the profile that was last connected (to connect if the service restarts) */ public static VpnProfile getLastConnectedProfile(Context c) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c); + SharedPreferences prefs = Preferences.getDefaultSharedPreferences(c); String lastConnectedProfile = prefs.getString(LAST_CONNECTED_PROFILE, null); if (lastConnectedProfile != null) @@ -108,7 +106,7 @@ public class ProfileManager { } public void saveProfileList(Context context) { - SharedPreferences sharedprefs = context.getSharedPreferences(PREFS_NAME, Activity.MODE_PRIVATE); + SharedPreferences sharedprefs = Preferences.getSharedPreferencesMulti(PREFS_NAME, context); Editor editor = sharedprefs.edit(); editor.putStringSet("vpnlist", profiles.keySet()); @@ -158,7 +156,7 @@ public class ProfileManager { private void loadVPNList(Context context) { profiles = new HashMap<>(); - SharedPreferences listpref = context.getSharedPreferences(PREFS_NAME, Activity.MODE_PRIVATE); + SharedPreferences listpref = Preferences.getSharedPreferencesMulti(PREFS_NAME, context); Set<String> vlist = listpref.getStringSet("vpnlist", null); if (vlist == null) { vlist = new HashSet<>(); @@ -226,7 +224,7 @@ public class ProfileManager { public static VpnProfile getAlwaysOnVPN(Context context) { checkInstance(context); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + SharedPreferences prefs = Preferences.getDefaultSharedPreferences(context); String uuid = prefs.getString("alwaysOnVpn", null); return get(uuid); diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java b/main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java index 549e0a58..7962aac5 100644 --- a/main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java +++ b/main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java @@ -60,6 +60,7 @@ import de.blinkt.openvpn.activities.VPNPreferences; import de.blinkt.openvpn.core.ConnectionStatus; import de.blinkt.openvpn.core.OpenVPNManagement; import de.blinkt.openvpn.core.OpenVPNService; +import de.blinkt.openvpn.core.Preferences; import de.blinkt.openvpn.core.ProfileManager; import de.blinkt.openvpn.core.VpnStatus; import de.blinkt.openvpn.core.LogItem; @@ -603,7 +604,7 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. mClearLogCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().putBoolean(LaunchVPN.CLEARLOG, isChecked).apply(); + Preferences.getDefaultSharedPreferences(getActivity()).edit().putBoolean(LaunchVPN.CLEARLOG, isChecked).apply(); } }); diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java b/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java index 054279fa..c88ef2f8 100644 --- a/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java +++ b/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java @@ -51,6 +51,7 @@ import de.blinkt.openvpn.activities.DisconnectVPN; import de.blinkt.openvpn.activities.FileSelect; import de.blinkt.openvpn.activities.VPNPreferences; import de.blinkt.openvpn.core.ConnectionStatus; +import de.blinkt.openvpn.core.Preferences; import de.blinkt.openvpn.core.ProfileManager; import de.blinkt.openvpn.core.VpnStatus; @@ -377,7 +378,7 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn } private void populateVpnList() { - boolean sortByLRU = PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean(PREF_SORT_BY_LRU, false); + boolean sortByLRU = Preferences.getDefaultSharedPreferences(getActivity()).getBoolean(PREF_SORT_BY_LRU, false); Collection<VpnProfile> allvpn = getPM().getProfiles(); TreeSet<VpnProfile> sortedset; if (sortByLRU) @@ -433,7 +434,7 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn } private boolean changeSorting() { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); + SharedPreferences prefs = Preferences.getDefaultSharedPreferences(getActivity()); boolean oldValue = prefs.getBoolean(PREF_SORT_BY_LRU, false); SharedPreferences.Editor prefsedit = prefs.edit(); if (oldValue) { |