summaryrefslogtreecommitdiff
path: root/app/src/main/java/de
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2023-08-02 22:45:26 +0200
committercyBerta <cyberta@riseup.net>2023-08-02 22:45:26 +0200
commit64449816223cb9abb6e75310c03dcc9353a42ee4 (patch)
tree66cb86d382cc67267441a10320f7e13cd125e66b /app/src/main/java/de
parent1ac4ec903f0d10b65810b720f76f08df969c3bec (diff)
use single instance of shared prefernces across the app, this reduces the laggyness of the UI noticably
Diffstat (limited to 'app/src/main/java/de')
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java15
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java4
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/VpnStatus.java11
3 files changed, 11 insertions, 19 deletions
diff --git a/app/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java b/app/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java
index 219c1394..c3083a1f 100644
--- a/app/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java
+++ b/app/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java
@@ -5,6 +5,8 @@
package de.blinkt.openvpn.core;
+import static de.blinkt.openvpn.core.OpenVPNManagement.pauseReason;
+
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -14,19 +16,14 @@ import android.net.NetworkInfo;
import android.net.NetworkInfo.State;
import android.os.Handler;
import android.os.Looper;
-import android.preference.PreferenceManager;
-import se.leap.bitmaskclient.R;
+import java.util.LinkedList;
+
import de.blinkt.openvpn.core.VpnStatus.ByteCountListener;
+import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.base.utils.PreferenceHelper;
import se.leap.bitmaskclient.tethering.TetheringObservable;
-import java.util.LinkedList;
-import java.util.Objects;
-import java.util.StringTokenizer;
-
-import static de.blinkt.openvpn.core.OpenVPNManagement.pauseReason;
-
public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountListener, OpenVPNManagement.PausedStateCallback {
private final Handler mDisconnectHandler;
private int lastNetwork = -1;
@@ -143,7 +140,7 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL
if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
networkStateChange(context);
} else if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
- boolean screenOffPause = PreferenceHelper.getSaveBattery(context);
+ boolean screenOffPause = PreferenceHelper.getSaveBattery();
boolean isTethering = TetheringObservable.getInstance().getTetheringState().isVpnTetheringRunning();
if (screenOffPause && !isTethering) {
if (VpnStatus.getLastConnectedVpnProfile() != null && !VpnStatus.getLastConnectedVpnProfile().mPersistTun)
diff --git a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
index 6adffda1..575f1f59 100644
--- a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
+++ b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
@@ -335,7 +335,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
Log.d(TAG, "Starting VPN due to isAlwaysOn system settings or app crash.");
startWithForegroundNotification();
- mProfile = VpnStatus.getLastConnectedVpnProfile(this);
+ mProfile = VpnStatus.getLastConnectedVpnProfile();
VpnStatus.logInfo(R.string.service_restarted);
if (mProfile != null) {
@@ -357,7 +357,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
/* start the OpenVPN process itself in a background thread */
new Thread(this::startOpenVPN).start();
- VpnStatus.setLastConnectedVpnProfile(getApplicationContext(), mProfile);
+ VpnStatus.setLastConnectedVpnProfile(mProfile);
return START_STICKY;
}
diff --git a/app/src/main/java/de/blinkt/openvpn/core/VpnStatus.java b/app/src/main/java/de/blinkt/openvpn/core/VpnStatus.java
index 8115548f..ecc03a19 100644
--- a/app/src/main/java/de/blinkt/openvpn/core/VpnStatus.java
+++ b/app/src/main/java/de/blinkt/openvpn/core/VpnStatus.java
@@ -153,19 +153,14 @@ public class VpnStatus {
}
public static VpnProfile getLastConnectedVpnProfile() {
- return lastConnectedProfile;
+ return lastConnectedProfile != null ? lastConnectedProfile : PreferenceHelper.getLastConnectedVpnProfile();
}
- public static VpnProfile getLastConnectedVpnProfile(Context context) {
- return PreferenceHelper.getLastConnectedVpnProfile(context);
- }
-
-
/**
* Sets the profile that is connected (to connect if the service restarts)
*/
- public static void setLastConnectedVpnProfile(Context context, VpnProfile connectedProfile) {
- PreferenceHelper.setLastUsedVpnProfile(context, connectedProfile);
+ public static void setLastConnectedVpnProfile(VpnProfile connectedProfile) {
+ PreferenceHelper.setLastUsedVpnProfile(connectedProfile);
lastConnectedProfile = connectedProfile;
setConnectedVPNProfile(lastConnectedProfile.getUUIDString());
}