android: Add convenience methods to get/set selected apps to/from a sorted set
This commit is contained in:
@@ -18,6 +18,11 @@
|
||||
package org.strongswan.android.data;
|
||||
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
|
||||
public class VpnProfile implements Cloneable
|
||||
@@ -202,6 +207,7 @@ public class VpnProfile implements Cloneable
|
||||
{
|
||||
this.mIncludedSubnets = includedSubnets;
|
||||
}
|
||||
|
||||
public String getIncludedSubnets()
|
||||
{
|
||||
return mIncludedSubnets;
|
||||
@@ -212,11 +218,26 @@ public class VpnProfile implements Cloneable
|
||||
this.mSelectedApps = selectedApps;
|
||||
}
|
||||
|
||||
public void setSelectedApps(SortedSet<String> selectedApps)
|
||||
{
|
||||
this.mSelectedApps = selectedApps.size() > 0 ? TextUtils.join(" ", selectedApps) : null;
|
||||
}
|
||||
|
||||
public String getSelectedApps()
|
||||
{
|
||||
return mSelectedApps;
|
||||
}
|
||||
|
||||
public SortedSet<String> getSelectedAppsSet()
|
||||
{
|
||||
TreeSet<String> set = new TreeSet<>();
|
||||
if (!TextUtils.isEmpty(mSelectedApps))
|
||||
{
|
||||
set.addAll(Arrays.asList(mSelectedApps.split("\\s+")));
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
public void setSelectedAppsHandling(SelectedAppsHandling selectedAppsHandling)
|
||||
{
|
||||
this.mSelectedAppsHandling = selectedAppsHandling;
|
||||
|
||||
+4
-4
@@ -64,6 +64,7 @@ import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.SortedSet;
|
||||
|
||||
public class CharonVpnService extends VpnService implements Runnable, VpnStateService.VpnStateListener
|
||||
{
|
||||
@@ -811,7 +812,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
|
||||
private final IPRangeSet mExcludedSubnets;
|
||||
private final int mSplitTunneling;
|
||||
private final SelectedAppsHandling mAppHandling;
|
||||
private final String[] mSelectedApps;
|
||||
private final SortedSet<String> mSelectedApps;
|
||||
private int mMtu;
|
||||
private boolean mIPv4Seen, mIPv6Seen;
|
||||
|
||||
@@ -833,8 +834,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
|
||||
Integer splitTunneling = profile.getSplitTunneling();
|
||||
mSplitTunneling = splitTunneling != null ? splitTunneling : 0;
|
||||
mAppHandling = profile.getSelectedAppsHandling();
|
||||
String selectedApps = profile.getSelectedApps();
|
||||
mSelectedApps = selectedApps != null ? selectedApps.split("\\s+") : null;
|
||||
mSelectedApps = profile.getSelectedAppsSet();
|
||||
}
|
||||
|
||||
public void addAddress(String address, int prefixLength)
|
||||
@@ -961,7 +961,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
|
||||
builder.addRoute("::", 0);
|
||||
}
|
||||
/* apply selected applications */
|
||||
if (mSelectedApps != null && mSelectedApps.length > 0)
|
||||
if (mSelectedApps.size() > 0)
|
||||
{
|
||||
switch (mAppHandling)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user