summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/eip
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2024-01-17 15:16:30 +0100
committercyBerta <cyberta@riseup.net>2024-01-17 15:16:30 +0100
commita7725722c35136c42c9acc242a50588e1fac8bb0 (patch)
treee32004b7f3eba196078537e5e5e74924ec9f08b8 /app/src/main/java/se/leap/bitmaskclient/eip
parent32578d46bea3e54cdd3021b0dd3fac4fb724267a (diff)
replace deprectated Observer and Observables by PropertyChangeListener and PropertyChangeSupport
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/eip')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java10
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java20
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java11
3 files changed, 28 insertions, 13 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
index d8905bca..ed61ca13 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
@@ -67,6 +67,8 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import org.json.JSONException;
import org.json.JSONObject;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.io.Closeable;
import java.lang.ref.WeakReference;
import java.util.Observable;
@@ -97,7 +99,7 @@ import se.leap.bitmaskclient.eip.GatewaysManager.GatewayOptions;
* @author Sean Leonard <meanderingcode@aetherislands.net>
* @author Parménides GV <parmegv@sdf.org>
*/
-public final class EIP extends JobIntentService implements Observer {
+public final class EIP extends JobIntentService implements PropertyChangeListener {
public final static String TAG = EIP.class.getSimpleName(),
@@ -160,9 +162,9 @@ public final class EIP extends JobIntentService implements Observer {
* update eipStatus whenever it changes
*/
@Override
- public void update(Observable observable, Object data) {
- if (observable instanceof EipStatus) {
- eipStatus = (EipStatus) observable;
+ public void propertyChange(PropertyChangeEvent evt) {
+ if (EipStatus.PROPERTY_CHANGE.equals(evt.getPropertyName())) {
+ eipStatus = (EipStatus) evt.getNewValue();
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java
index 8182cab9..c2ba8af3 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java
@@ -20,10 +20,10 @@ import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_NONETWORK;
import android.content.Context;
import android.os.AsyncTask;
-import androidx.annotation.VisibleForTesting;
import android.util.Log;
-import java.util.Observable;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
import de.blinkt.openvpn.core.ConnectionStatus;
import de.blinkt.openvpn.core.LogItem;
@@ -34,7 +34,7 @@ import de.blinkt.openvpn.core.VpnStatus;
* EipStatus changes it's state (EipLevel) when ConnectionStatus gets updated by OpenVpnService or
* by VoidVpnService.
*/
-public class EipStatus extends Observable implements VpnStatus.StateListener {
+public class EipStatus implements VpnStatus.StateListener {
public static String TAG = EipStatus.class.getSimpleName();
private static EipStatus currentStatus;
@@ -60,6 +60,9 @@ public class EipStatus extends Observable implements VpnStatus.StateListener {
private int localizedResId;
private boolean isUpdatingVPNCertificate;
+ private final PropertyChangeSupport propertyChange;
+ public static final String PROPERTY_CHANGE = "EipStatus";
+
public static EipStatus getInstance() {
if (currentStatus == null) {
currentStatus = new EipStatus();
@@ -69,6 +72,7 @@ public class EipStatus extends Observable implements VpnStatus.StateListener {
}
private EipStatus() {
+ propertyChange = new PropertyChangeSupport(this);
}
@Override
@@ -300,8 +304,14 @@ public class EipStatus extends Observable implements VpnStatus.StateListener {
}
public static void refresh() {
- getInstance().setChanged();
- getInstance().notifyObservers();
+ currentStatus.propertyChange.firePropertyChange(PROPERTY_CHANGE, null, currentStatus);
+ }
+
+ public void addObserver(PropertyChangeListener propertyChangeListener) {
+ propertyChange.addPropertyChangeListener(propertyChangeListener);
}
+ public void deleteObserver(PropertyChangeListener propertyChangeListener) {
+ propertyChange.removePropertyChangeListener(propertyChangeListener);
+ }
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
index b32671ae..f08371c6 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
@@ -33,6 +33,8 @@ import android.os.ParcelFileDescriptor;
import android.system.OsConstants;
import android.util.Log;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.util.Observable;
import java.util.Observer;
@@ -43,7 +45,7 @@ import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.base.utils.PreferenceHelper;
-public class VoidVpnService extends VpnService implements Observer, VpnNotificationManager.VpnServiceCallback {
+public class VoidVpnService extends VpnService implements PropertyChangeListener, VpnNotificationManager.VpnServiceCallback {
static final String TAG = VoidVpnService.class.getSimpleName();
private ParcelFileDescriptor fd;
@@ -183,10 +185,11 @@ public class VoidVpnService extends VpnService implements Observer, VpnNotificat
getApplicationContext().startService(startEIP);
}
+
@Override
- public void update(Observable observable, Object arg) {
- if (observable instanceof EipStatus) {
- eipStatus = (EipStatus) observable;
+ public void propertyChange(PropertyChangeEvent evt) {
+ if (EipStatus.PROPERTY_CHANGE.equals(evt.getPropertyName())) {
+ eipStatus = (EipStatus) evt.getNewValue();
}
if (handlerThread.isInterrupted() || !handlerThread.isAlive()) {
return;