diff options
author | Tobias Brunner <tobias@strongswan.org> | 2017-06-26 11:35:46 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2017-07-03 10:27:53 +0200 |
commit | 43b33f075a67970436d382631fea992421542249 (patch) | |
tree | f958be406afb96021f32c84d09feb894e2fe69f1 | |
parent | 05c5e894a9d0539bf8ce328b1f163fd27288a8ef (diff) | |
download | strongswan-43b33f075a67970436d382631fea992421542249.tar.bz2 strongswan-43b33f075a67970436d382631fea992421542249.tar.xz |
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.
2 files changed, 73 insertions, 4 deletions
diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/data/VpnProfile.java b/src/frontends/android/app/src/main/java/org/strongswan/android/data/VpnProfile.java index 69ec893fe..92e590634 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/data/VpnProfile.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/data/VpnProfile.java @@ -27,12 +27,32 @@ public class VpnProfile implements Cloneable public static final int SPLIT_TUNNELING_BLOCK_IPV6 = 2; 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 SelectedAppsHandling mSelectedAppsHandling = SelectedAppsHandling.SELECTED_APPS_DISABLE; private VpnType mVpnType; private UUID mUUID; 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() { this.mUUID = UUID.randomUUID(); @@ -182,12 +202,44 @@ public class VpnProfile implements Cloneable { this.mIncludedSubnets = includedSubnets; } - public String getIncludedSubnets() { 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() { return mSplitTunneling; diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/data/VpnProfileDataSource.java b/src/frontends/android/app/src/main/java/org/strongswan/android/data/VpnProfileDataSource.java index 4defe1a83..380dbda39 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/data/VpnProfileDataSource.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/data/VpnProfileDataSource.java @@ -49,6 +49,8 @@ public class VpnProfileDataSource public static final String KEY_REMOTE_ID = "remote_id"; public static final String KEY_EXCLUDED_SUBNETS = "excluded_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 SQLiteDatabase mDatabase; @@ -57,7 +59,7 @@ public class VpnProfileDataSource private static final String DATABASE_NAME = "strongswan.db"; 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 = "CREATE TABLE " + TABLE_VPNPROFILE + " (" + @@ -76,7 +78,9 @@ public class VpnProfileDataSource KEY_LOCAL_ID + " TEXT," + KEY_REMOTE_ID + " 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[] { KEY_ID, @@ -95,6 +99,8 @@ public class VpnProfileDataSource KEY_REMOTE_ID, KEY_EXCLUDED_SUBNETS, KEY_INCLUDED_SUBNETS, + KEY_SELECTED_APPS, + KEY_SELECTED_APPS_LIST, }; private static class DatabaseHelper extends SQLiteOpenHelper @@ -167,6 +173,13 @@ public class VpnProfileDataSource db.execSQL("ALTER TABLE " + TABLE_VPNPROFILE + " ADD " + KEY_INCLUDED_SUBNETS + " 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) @@ -344,6 +357,8 @@ public class VpnProfileDataSource profile.setRemoteId(cursor.getString(cursor.getColumnIndex(KEY_REMOTE_ID))); profile.setExcludedSubnets(cursor.getString(cursor.getColumnIndex(KEY_EXCLUDED_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; } @@ -365,6 +380,8 @@ public class VpnProfileDataSource values.put(KEY_REMOTE_ID, profile.getRemoteId()); values.put(KEY_EXCLUDED_SUBNETS, profile.getExcludedSubnets()); 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; } |