summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2022-07-22 16:45:37 +0200
committerArne Schwabe <arne@rfc2549.org>2022-07-22 16:45:37 +0200
commitdf2a66a4a1dd54d76a65ed516bc55ea3f521329d (patch)
tree5a16b4cf6aaca54c011e20a7fde881dfdaa8966b /main
parent552264611d9ca218a905e3e461df27e3d0f860cd (diff)
Refresh VPN list on resume() of VPN list fragment (closes #1508)
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java99
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java1
2 files changed, 63 insertions, 37 deletions
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 06822817..1185a697 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/ProfileManager.java
@@ -241,6 +241,29 @@ public class ProfileManager {
profiles.put(profile.getUUID().toString(), profile);
}
+ /**
+ * Checks if a profile has been added deleted since last loading and will update its
+ * profiles
+ * @param context
+ */
+ public void refreshVPNList(Context context)
+ {
+ SharedPreferences listpref = Preferences.getSharedPreferencesMulti(PREFS_NAME, context);
+ Set<String> vlist = listpref.getStringSet("vpnlist", null);
+ if (vlist == null)
+ return;
+
+ for (String vpnentry : vlist) {
+ if (!profiles.containsKey(vpnentry))
+ loadVpnEntry(context, vpnentry);
+ }
+ for (String profileuuid:profiles.keySet())
+ {
+ if (!vlist.contains(profileuuid))
+ profiles.remove(profileuuid);
+ }
+ }
+
private void loadVPNList(Context context) {
profiles = new HashMap<>();
SharedPreferences listpref = Preferences.getSharedPreferencesMulti(PREFS_NAME, context);
@@ -252,44 +275,46 @@ public class ProfileManager {
vlist.add(TEMPORARY_PROFILE_FILENAME);
for (String vpnentry : vlist) {
- ObjectInputStream vpnfile = null;
- try {
- FileInputStream vpInput;
- File encryptedPath = context.getFileStreamPath(vpnentry + ".cp");
- File encryptedPathOld = context.getFileStreamPath(vpnentry + ".cpold");
-
- if (encryptedPath.exists()) {
- vpInput = ProfileEncryption.getEncryptedVpInput(context, encryptedPath);
- } else if (encryptedPathOld.exists()) {
- vpInput = ProfileEncryption.getEncryptedVpInput(context, encryptedPathOld);
- } else {
- vpInput = context.openFileInput(vpnentry + ".vp");
- }
- vpnfile = new ObjectInputStream(vpInput);
- VpnProfile vp = ((VpnProfile) vpnfile.readObject());
-
- // Sanity check
- if (vp == null || vp.mName == null || vp.getUUID() == null)
- continue;
-
- vp.upgradeProfile();
- if (vpnentry.equals(TEMPORARY_PROFILE_FILENAME)) {
- tmpprofile = vp;
- } else {
- profiles.put(vp.getUUID().toString(), vp);
- }
-
+ loadVpnEntry(context, vpnentry);
+ }
+ }
- } catch (IOException | ClassNotFoundException | GeneralSecurityException e) {
- if (!vpnentry.equals(TEMPORARY_PROFILE_FILENAME))
- VpnStatus.logException("Loading VPN List", e);
- } finally {
- if (vpnfile != null) {
- try {
- vpnfile.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ private void loadVpnEntry(Context context, String vpnentry) {
+ ObjectInputStream vpnfile = null;
+ try {
+ FileInputStream vpInput;
+ File encryptedPath = context.getFileStreamPath(vpnentry + ".cp");
+ File encryptedPathOld = context.getFileStreamPath(vpnentry + ".cpold");
+
+ if (encryptedPath.exists()) {
+ vpInput = ProfileEncryption.getEncryptedVpInput(context, encryptedPath);
+ } else if (encryptedPathOld.exists()) {
+ vpInput = ProfileEncryption.getEncryptedVpInput(context, encryptedPathOld);
+ } else {
+ vpInput = context.openFileInput(vpnentry + ".vp");
+ }
+ vpnfile = new ObjectInputStream(vpInput);
+ VpnProfile vp = ((VpnProfile) vpnfile.readObject());
+
+ // Sanity check
+ if (vp == null || vp.mName == null || vp.getUUID() == null)
+ return;
+
+ vp.upgradeProfile();
+ if (vpnentry.equals(TEMPORARY_PROFILE_FILENAME)) {
+ tmpprofile = vp;
+ } else {
+ profiles.put(vp.getUUID().toString(), vp);
+ }
+ } catch (IOException | ClassNotFoundException | GeneralSecurityException e) {
+ if (!vpnentry.equals(TEMPORARY_PROFILE_FILENAME))
+ VpnStatus.logException("Loading VPN List", e);
+ } finally {
+ if (vpnfile != null) {
+ try {
+ vpnfile.close();
+ } catch (IOException e) {
+ e.printStackTrace();
}
}
}
diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java b/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java
index cf48cc48..c7ee5df1 100644
--- a/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java
+++ b/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java
@@ -292,6 +292,7 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn
private void populateVpnList() {
boolean sortByLRU = Preferences.getDefaultSharedPreferences(requireActivity()).getBoolean(PREF_SORT_BY_LRU, false);
+ getPM().refreshVPNList(requireContext());
Collection<VpnProfile> allvpn = getPM().getProfiles();
TreeSet<VpnProfile> sortedset;
if (sortByLRU)