summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2016-11-19 18:16:01 +0100
committerArne Schwabe <arne@rfc2549.org>2016-11-19 18:16:01 +0100
commit5e50072b9a95aad7623d8317473c295446901fb7 (patch)
treef065a80ff975fb3bede520404b843e08e90b5c8f /main
parent34f9c3afec04f8d36a11e37346549e613e1b4bb8 (diff)
Always use the most current version of a profile
Diffstat (limited to 'main')
-rw-r--r--main/src/main/aidl/de/blinkt/openvpn/core/IServiceStatus.aidl4
-rw-r--r--main/src/main/java/de/blinkt/openvpn/VpnProfile.java5
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java4
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVPNStatusService.java6
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java28
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/StatusListener.java5
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java9
7 files changed, 51 insertions, 10 deletions
diff --git a/main/src/main/aidl/de/blinkt/openvpn/core/IServiceStatus.aidl b/main/src/main/aidl/de/blinkt/openvpn/core/IServiceStatus.aidl
index 0772dcb9..b73284bb 100644
--- a/main/src/main/aidl/de/blinkt/openvpn/core/IServiceStatus.aidl
+++ b/main/src/main/aidl/de/blinkt/openvpn/core/IServiceStatus.aidl
@@ -16,4 +16,8 @@ interface IServiceStatus {
*/
void unregisterStatusCallback(in IStatusCallbacks cb);
+ /**
+ *
+ */
+ String getLastConnectedVPN();
}
diff --git a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
index c39603b2..5b9445be 100644
--- a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
+++ b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
@@ -164,11 +164,14 @@ public class VpnProfile implements Serializable, Cloneable {
public boolean mPushPeerInfo = false;
public static final boolean mIsOpenVPN22 = false;
+ public int mVersion=0;
+
/* Options no longer used in new profiles */
public String mServerName = "openvpn.blinkt.de";
public String mServerPort = "1194";
public boolean mUseUdp = true;
+
public VpnProfile(String name) {
mUuid = UUID.randomUUID();
mName = name;
@@ -672,7 +675,7 @@ public class VpnProfile implements Serializable, Cloneable {
Intent intent = new Intent(context, OpenVPNService.class);
intent.putExtra(prefix + ".profileUUID", mUuid.toString());
-
+ intent.putExtra(prefix + ".profileVersion", mVersion);
return intent;
}
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 86a4043a..4e8deac0 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
@@ -399,7 +399,9 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
if (intent != null && intent.hasExtra(getPackageName() + ".profileUUID")) {
String profileUUID = intent.getStringExtra(getPackageName() + ".profileUUID");
- mProfile = ProfileManager.get(this, profileUUID);
+ int profileVersion = intent.getIntExtra(getPackageName() + ".profileVersion", 0);
+ // Try for 10s to get current version of the profile
+ mProfile = ProfileManager.get(this, profileUUID, profileVersion, 100);
} else {
/* The intent is null when we are set as always-on or the service has been restarted. */
mProfile = ProfileManager.getLastConnectedProfile(this);
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNStatusService.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNStatusService.java
index 4b32d9fa..24ae7704 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNStatusService.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNStatusService.java
@@ -61,13 +61,17 @@ public class OpenVPNStatusService extends Service implements VpnStatus.LogListen
@Override
public void registerStatusCallback(IStatusCallbacks cb) throws RemoteException {
mCallbacks.register(cb);
-
}
@Override
public void unregisterStatusCallback(IStatusCallbacks cb) throws RemoteException {
mCallbacks.unregister(cb);
}
+
+ @Override
+ public String getLastConnectedVPN() throws RemoteException {
+ return VpnStatus.getLastConnectedVPNProfile();
+ }
};
@Override
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 2856a069..15ff7651 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java
@@ -129,13 +129,13 @@ public class ProfileManager {
ProfileManager.tmpprofile = tmp;
}
- public static boolean isTempProfile()
- {
+ public static boolean isTempProfile() {
return mLastConnectedVpn == tmpprofile;
}
public void saveProfile(Context context, VpnProfile profile) {
+ profile.mVersion += 1;
ObjectOutputStream vpnfile;
try {
vpnfile = new ObjectOutputStream(context.openFileOutput((profile.getUUID().toString() + ".vp"), Activity.MODE_PRIVATE));
@@ -188,8 +188,30 @@ public class ProfileManager {
}
public static VpnProfile get(Context context, String profileUUID) {
+ return get(context, profileUUID, 0, 10);
+ }
+
+ public static VpnProfile get(Context context, String profileUUID, int version, int tries) {
checkInstance(context);
- return get(profileUUID);
+ VpnProfile profile = get(profileUUID);
+ int tried = 0;
+ while ((profile == null || profile.mVersion < version) && (tried++ < tries)) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException ignored) {
+ }
+ instance.loadVPNList(context);
+ profile = get(profileUUID);
+ int ver = profile == null ? -1 : profile.mVersion;
+ }
+
+ if (tried != 0)
+
+ {
+ int ver = profile == null ? -1 : profile.mVersion;
+ VpnStatus.logError(String.format("Used x %d tries to get current version (%d/%d) of the profile", tried, ver, version));
+ }
+ return profile;
}
public static VpnProfile getLastConnectedVpn() {
diff --git a/main/src/main/java/de/blinkt/openvpn/core/StatusListener.java b/main/src/main/java/de/blinkt/openvpn/core/StatusListener.java
index d6660147..8df1dfed 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/StatusListener.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/StatusListener.java
@@ -27,9 +27,12 @@ public class StatusListener {
IServiceStatus serviceStatus = IServiceStatus.Stub.asInterface(service);
try {
/* Check if this a local service ... */
- if (service.queryLocalInterface("de.blinkt.openvpn.core.IServiceStatus") == null)
+ if (service.queryLocalInterface("de.blinkt.openvpn.core.IServiceStatus") == null) {
+ VpnStatus.setConnectedVPNProfile(serviceStatus.getLastConnectedVPN());
serviceStatus.registerStatusCallback(mCallback);
+ }
+
} catch (RemoteException e) {
e.printStackTrace();
}
diff --git a/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java b/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java
index db0d10bd..84cb4719 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java
@@ -158,14 +158,17 @@ public class VpnStatus {
public static LogLevel getEnumByValue(int value) {
switch (value) {
- case 1:
- return INFO;
case 2:
+ return INFO;
+ case -2:
return ERROR;
- case 3:
+ case 1:
return WARNING;
+ case 3:
+ return VERBOSE;
case 4:
return DEBUG;
+
default:
return null;
}