android: Add property for selected apps to VPN profiles
authorTobias Brunner <tobias@strongswan.org>
Mon, 26 Jun 2017 09:35:46 +0000 (11:35 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 3 Jul 2017 08:27:53 +0000 (10:27 +0200)
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.

src/frontends/android/app/src/main/java/org/strongswan/android/data/VpnProfile.java
src/frontends/android/app/src/main/java/org/strongswan/android/data/VpnProfileDataSource.java

index 69ec893..92e5906 100644 (file)
@@ -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;
index 4defe1a..380dbda 100644 (file)
@@ -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;
        }