android: Add property for selected apps to VPN profiles
A second property will control if only the selected apps have access to the VPN or if the selected apps are excluded from the VPN, or if the functionality is disabled.
This commit is contained in:
+54
-2
@@ -27,12 +27,32 @@ public class VpnProfile implements Cloneable
|
|||||||
public static final int SPLIT_TUNNELING_BLOCK_IPV6 = 2;
|
public static final int SPLIT_TUNNELING_BLOCK_IPV6 = 2;
|
||||||
|
|
||||||
private String mName, mGateway, mUsername, mPassword, mCertificate, mUserCertificate;
|
private String mName, mGateway, mUsername, mPassword, mCertificate, mUserCertificate;
|
||||||
private String mRemoteId, mLocalId, mExcludedSubnets, mIncludedSubnets;
|
private String mRemoteId, mLocalId, mExcludedSubnets, mIncludedSubnets, mSelectedApps;
|
||||||
private Integer mMTU, mPort, mSplitTunneling;
|
private Integer mMTU, mPort, mSplitTunneling;
|
||||||
|
private SelectedAppsHandling mSelectedAppsHandling = SelectedAppsHandling.SELECTED_APPS_DISABLE;
|
||||||
private VpnType mVpnType;
|
private VpnType mVpnType;
|
||||||
private UUID mUUID;
|
private UUID mUUID;
|
||||||
private long mId = -1;
|
private long mId = -1;
|
||||||
|
|
||||||
|
public enum SelectedAppsHandling
|
||||||
|
{
|
||||||
|
SELECTED_APPS_DISABLE(0),
|
||||||
|
SELECTED_APPS_EXCLUDE(1),
|
||||||
|
SELECTED_APPS_ONLY(2);
|
||||||
|
|
||||||
|
private Integer mValue;
|
||||||
|
|
||||||
|
SelectedAppsHandling(int value)
|
||||||
|
{
|
||||||
|
mValue = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getValue()
|
||||||
|
{
|
||||||
|
return mValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public VpnProfile()
|
public VpnProfile()
|
||||||
{
|
{
|
||||||
this.mUUID = UUID.randomUUID();
|
this.mUUID = UUID.randomUUID();
|
||||||
@@ -182,12 +202,44 @@ public class VpnProfile implements Cloneable
|
|||||||
{
|
{
|
||||||
this.mIncludedSubnets = includedSubnets;
|
this.mIncludedSubnets = includedSubnets;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIncludedSubnets()
|
public String getIncludedSubnets()
|
||||||
{
|
{
|
||||||
return mIncludedSubnets;
|
return mIncludedSubnets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSelectedApps(String selectedApps)
|
||||||
|
{
|
||||||
|
this.mSelectedApps = selectedApps;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSelectedApps()
|
||||||
|
{
|
||||||
|
return mSelectedApps;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectedAppsHandling(SelectedAppsHandling selectedAppsHandling)
|
||||||
|
{
|
||||||
|
this.mSelectedAppsHandling = selectedAppsHandling;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectedAppsHandling(Integer value)
|
||||||
|
{
|
||||||
|
mSelectedAppsHandling = SelectedAppsHandling.SELECTED_APPS_DISABLE;
|
||||||
|
for (SelectedAppsHandling handling : SelectedAppsHandling.values())
|
||||||
|
{
|
||||||
|
if (handling.mValue.equals(value))
|
||||||
|
{
|
||||||
|
mSelectedAppsHandling = handling;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SelectedAppsHandling getSelectedAppsHandling()
|
||||||
|
{
|
||||||
|
return mSelectedAppsHandling;
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getSplitTunneling()
|
public Integer getSplitTunneling()
|
||||||
{
|
{
|
||||||
return mSplitTunneling;
|
return mSplitTunneling;
|
||||||
|
|||||||
+19
-2
@@ -49,6 +49,8 @@ public class VpnProfileDataSource
|
|||||||
public static final String KEY_REMOTE_ID = "remote_id";
|
public static final String KEY_REMOTE_ID = "remote_id";
|
||||||
public static final String KEY_EXCLUDED_SUBNETS = "excluded_subnets";
|
public static final String KEY_EXCLUDED_SUBNETS = "excluded_subnets";
|
||||||
public static final String KEY_INCLUDED_SUBNETS = "included_subnets";
|
public static final String KEY_INCLUDED_SUBNETS = "included_subnets";
|
||||||
|
public static final String KEY_SELECTED_APPS = "selected_apps";
|
||||||
|
public static final String KEY_SELECTED_APPS_LIST = "selected_apps_list";
|
||||||
|
|
||||||
private DatabaseHelper mDbHelper;
|
private DatabaseHelper mDbHelper;
|
||||||
private SQLiteDatabase mDatabase;
|
private SQLiteDatabase mDatabase;
|
||||||
@@ -57,7 +59,7 @@ public class VpnProfileDataSource
|
|||||||
private static final String DATABASE_NAME = "strongswan.db";
|
private static final String DATABASE_NAME = "strongswan.db";
|
||||||
private static final String TABLE_VPNPROFILE = "vpnprofile";
|
private static final String TABLE_VPNPROFILE = "vpnprofile";
|
||||||
|
|
||||||
private static final int DATABASE_VERSION = 11;
|
private static final int DATABASE_VERSION = 12;
|
||||||
|
|
||||||
public static final String DATABASE_CREATE =
|
public static final String DATABASE_CREATE =
|
||||||
"CREATE TABLE " + TABLE_VPNPROFILE + " (" +
|
"CREATE TABLE " + TABLE_VPNPROFILE + " (" +
|
||||||
@@ -76,7 +78,9 @@ public class VpnProfileDataSource
|
|||||||
KEY_LOCAL_ID + " TEXT," +
|
KEY_LOCAL_ID + " TEXT," +
|
||||||
KEY_REMOTE_ID + " TEXT," +
|
KEY_REMOTE_ID + " TEXT," +
|
||||||
KEY_EXCLUDED_SUBNETS + " TEXT," +
|
KEY_EXCLUDED_SUBNETS + " TEXT," +
|
||||||
KEY_INCLUDED_SUBNETS + " TEXT" +
|
KEY_INCLUDED_SUBNETS + " TEXT," +
|
||||||
|
KEY_SELECTED_APPS + " INTEGER," +
|
||||||
|
KEY_SELECTED_APPS_LIST + " TEXT" +
|
||||||
");";
|
");";
|
||||||
private static final String[] ALL_COLUMNS = new String[] {
|
private static final String[] ALL_COLUMNS = new String[] {
|
||||||
KEY_ID,
|
KEY_ID,
|
||||||
@@ -95,6 +99,8 @@ public class VpnProfileDataSource
|
|||||||
KEY_REMOTE_ID,
|
KEY_REMOTE_ID,
|
||||||
KEY_EXCLUDED_SUBNETS,
|
KEY_EXCLUDED_SUBNETS,
|
||||||
KEY_INCLUDED_SUBNETS,
|
KEY_INCLUDED_SUBNETS,
|
||||||
|
KEY_SELECTED_APPS,
|
||||||
|
KEY_SELECTED_APPS_LIST,
|
||||||
};
|
};
|
||||||
|
|
||||||
private static class DatabaseHelper extends SQLiteOpenHelper
|
private static class DatabaseHelper extends SQLiteOpenHelper
|
||||||
@@ -167,6 +173,13 @@ public class VpnProfileDataSource
|
|||||||
db.execSQL("ALTER TABLE " + TABLE_VPNPROFILE + " ADD " + KEY_INCLUDED_SUBNETS +
|
db.execSQL("ALTER TABLE " + TABLE_VPNPROFILE + " ADD " + KEY_INCLUDED_SUBNETS +
|
||||||
" TEXT;");
|
" TEXT;");
|
||||||
}
|
}
|
||||||
|
if (oldVersion < 12)
|
||||||
|
{
|
||||||
|
db.execSQL("ALTER TABLE " + TABLE_VPNPROFILE + " ADD " + KEY_SELECTED_APPS +
|
||||||
|
" INTEGER;");
|
||||||
|
db.execSQL("ALTER TABLE " + TABLE_VPNPROFILE + " ADD " + KEY_SELECTED_APPS_LIST +
|
||||||
|
" TEXT;");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateColumns(SQLiteDatabase db)
|
private void updateColumns(SQLiteDatabase db)
|
||||||
@@ -344,6 +357,8 @@ public class VpnProfileDataSource
|
|||||||
profile.setRemoteId(cursor.getString(cursor.getColumnIndex(KEY_REMOTE_ID)));
|
profile.setRemoteId(cursor.getString(cursor.getColumnIndex(KEY_REMOTE_ID)));
|
||||||
profile.setExcludedSubnets(cursor.getString(cursor.getColumnIndex(KEY_EXCLUDED_SUBNETS)));
|
profile.setExcludedSubnets(cursor.getString(cursor.getColumnIndex(KEY_EXCLUDED_SUBNETS)));
|
||||||
profile.setIncludedSubnets(cursor.getString(cursor.getColumnIndex(KEY_INCLUDED_SUBNETS)));
|
profile.setIncludedSubnets(cursor.getString(cursor.getColumnIndex(KEY_INCLUDED_SUBNETS)));
|
||||||
|
profile.setSelectedAppsHandling(getInt(cursor, cursor.getColumnIndex(KEY_SELECTED_APPS)));
|
||||||
|
profile.setSelectedApps(cursor.getString(cursor.getColumnIndex(KEY_SELECTED_APPS_LIST)));
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -365,6 +380,8 @@ public class VpnProfileDataSource
|
|||||||
values.put(KEY_REMOTE_ID, profile.getRemoteId());
|
values.put(KEY_REMOTE_ID, profile.getRemoteId());
|
||||||
values.put(KEY_EXCLUDED_SUBNETS, profile.getExcludedSubnets());
|
values.put(KEY_EXCLUDED_SUBNETS, profile.getExcludedSubnets());
|
||||||
values.put(KEY_INCLUDED_SUBNETS, profile.getIncludedSubnets());
|
values.put(KEY_INCLUDED_SUBNETS, profile.getIncludedSubnets());
|
||||||
|
values.put(KEY_SELECTED_APPS, profile.getSelectedAppsHandling().getValue());
|
||||||
|
values.put(KEY_SELECTED_APPS_LIST, profile.getSelectedApps());
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user