diff options
Diffstat (limited to 'main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java')
-rw-r--r-- | main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java b/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java index 02b54add..175ecb70 100644 --- a/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java +++ b/main/src/main/java/de/blinkt/openvpn/api/AppRestrictions.java @@ -10,9 +10,12 @@ import android.content.*; import android.os.Build; import android.os.Bundle; import android.os.Parcelable; +import android.text.TextUtils; + import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.core.ConfigParser; import de.blinkt.openvpn.core.Connection; +import de.blinkt.openvpn.core.Preferences; import de.blinkt.openvpn.core.ProfileManager; import de.blinkt.openvpn.core.VpnStatus; @@ -99,6 +102,9 @@ public class AppRestrictions { Set<String> provisionedUuids = new HashSet<>(); + String defaultprofile = restrictions.getString("defaultprofile", null); + boolean defaultprofileProvisioned = false; + ProfileManager pm = ProfileManager.getInstance(c); for (Parcelable profile : profileList) { if (!(profile instanceof Bundle)) { @@ -116,6 +122,9 @@ public class AppRestrictions { continue; } + if (uuid.equals(defaultprofile)) + defaultprofileProvisioned = true; + String ovpnHash = hashConfig(ovpn); provisionedUuids.add(uuid.toLowerCase(Locale.ENGLISH)); @@ -135,36 +144,51 @@ public class AppRestrictions { Vector<VpnProfile> profilesToRemove = new Vector<>(); // get List of all managed profiles - for (VpnProfile vp: pm.getProfiles()) - { + for (VpnProfile vp : pm.getProfiles()) { if (PROFILE_CREATOR.equals(vp.mProfileCreator)) { if (!provisionedUuids.contains(vp.getUUIDString())) profilesToRemove.add(vp); } } - for (VpnProfile vp: profilesToRemove) { + for (VpnProfile vp : profilesToRemove) { VpnStatus.logInfo("Remove with uuid: %s and name: %s since it is no longer in the list of managed profiles"); pm.removeProfile(c, vp); } + if (!TextUtils.isEmpty(defaultprofile)) { + if (!defaultprofileProvisioned) { + VpnStatus.logError("App restrictions: Setting a default profile UUID without providing a profile with that UUID"); + } else { + SharedPreferences prefs = Preferences.getDefaultSharedPreferences(c); + String uuid = prefs.getString("alwaysOnVpn", null); + if (!defaultprofile.equals(uuid)) + { + SharedPreferences.Editor editor = prefs.edit(); + editor.putString("alwaysOnVpn", defaultprofile); + editor.apply(); + } + } + } } private String prepare(String config) { String newLine = System.getProperty("line.separator"); - if (!config.contains(newLine)&& !config.contains(" ")) { + if (!config.contains(newLine) && !config.contains(" ")) { try { byte[] decoded = android.util.Base64.decode(config.getBytes(), android.util.Base64.DEFAULT); - config = new String(decoded); - return config; - } catch(IllegalArgumentException e) { - + config = new String(decoded); + return config; + } catch (IllegalArgumentException e) { + } } return config; - }; - + } + + ; + private void addProfile(Context c, String config, String uuid, String name, VpnProfile vpnProfile) { - config = prepare(config); + config = prepare(config); ConfigParser cp = new ConfigParser(); try { cp.parseConfig(new StringReader(config)); @@ -204,8 +228,7 @@ public class AppRestrictions { applyRestrictions(c); } - public void pauseCheckRestrictions(Context c) - { + public void pauseCheckRestrictions(Context c) { removeChangesListener(c); } } |