android: Add field for split tunneling config to data model
authorTobias Brunner <tobias@strongswan.org>
Fri, 24 Jul 2015 09:33:07 +0000 (11:33 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 28 Jul 2015 11:27:33 +0000 (13:27 +0200)
src/frontends/android/src/org/strongswan/android/data/VpnProfile.java
src/frontends/android/src/org/strongswan/android/data/VpnProfileDataSource.java

index 6b83783..5c64ad0 100644 (file)
 
 package org.strongswan.android.data;
 
+
 public class VpnProfile implements Cloneable
 {
+       /* While storing this as EnumSet would be nicer this simplifies storing it in a database */
+       public static final int SPLIT_TUNNELING_BLOCK_IPV4 = 1;
+       public static final int SPLIT_TUNNELING_BLOCK_IPV6 = 2;
+
        private String mName, mGateway, mUsername, mPassword, mCertificate, mUserCertificate;
-       private Integer mMTU, mPort;
+       private Integer mMTU, mPort, mSplitTunneling;
        private VpnType mVpnType;
        private long mId = -1;
 
@@ -124,6 +129,16 @@ public class VpnProfile implements Cloneable
                this.mPort = port;
        }
 
+       public Integer getSplitTunneling()
+       {
+               return mSplitTunneling;
+       }
+
+       public void setSplitTunneling(Integer splitTunneling)
+       {
+               this.mSplitTunneling = splitTunneling;
+       }
+
        @Override
        public String toString()
        {
index b9842a9..45e9b86 100644 (file)
@@ -42,6 +42,7 @@ public class VpnProfileDataSource
        public static final String KEY_USER_CERTIFICATE = "user_certificate";
        public static final String KEY_MTU = "mtu";
        public static final String KEY_PORT = "port";
+       public static final String KEY_SPLIT_TUNNELING = "split_tunneling";
 
        private DatabaseHelper mDbHelper;
        private SQLiteDatabase mDatabase;
@@ -50,7 +51,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 = 6;
+       private static final int DATABASE_VERSION = 7;
 
        public static final String DATABASE_CREATE =
                                                        "CREATE TABLE " + TABLE_VPNPROFILE + " (" +
@@ -63,7 +64,8 @@ public class VpnProfileDataSource
                                                                KEY_CERTIFICATE + " TEXT," +
                                                                KEY_USER_CERTIFICATE + " TEXT," +
                                                                KEY_MTU + " INTEGER," +
-                                                               KEY_PORT + " INTEGER" +
+                                                               KEY_PORT + " INTEGER," +
+                                                               KEY_SPLIT_TUNNELING + " INTEGER" +
                                                        ");";
        private static final String[] ALL_COLUMNS = new String[] {
                                                                KEY_ID,
@@ -76,6 +78,7 @@ public class VpnProfileDataSource
                                                                KEY_USER_CERTIFICATE,
                                                                KEY_MTU,
                                                                KEY_PORT,
+                                                               KEY_SPLIT_TUNNELING,
                                                        };
 
        private static class DatabaseHelper extends SQLiteOpenHelper
@@ -120,6 +123,11 @@ public class VpnProfileDataSource
                                db.execSQL("ALTER TABLE " + TABLE_VPNPROFILE + " ADD " + KEY_PORT +
                                                   " INTEGER;");
                        }
+                       if (oldVersion < 7)
+                       {
+                               db.execSQL("ALTER TABLE " + TABLE_VPNPROFILE + " ADD " + KEY_SPLIT_TUNNELING +
+                                                  " INTEGER;");
+                       }
                }
 
                private void updateColumns(SQLiteDatabase db)
@@ -273,6 +281,7 @@ public class VpnProfileDataSource
                profile.setUserCertificateAlias(cursor.getString(cursor.getColumnIndex(KEY_USER_CERTIFICATE)));
                profile.setMTU(getInt(cursor, cursor.getColumnIndex(KEY_MTU)));
                profile.setPort(getInt(cursor, cursor.getColumnIndex(KEY_PORT)));
+               profile.setSplitTunneling(getInt(cursor, cursor.getColumnIndex(KEY_SPLIT_TUNNELING)));
                return profile;
        }
 
@@ -288,6 +297,7 @@ public class VpnProfileDataSource
                values.put(KEY_USER_CERTIFICATE, profile.getUserCertificateAlias());
                values.put(KEY_MTU, profile.getMTU());
                values.put(KEY_PORT, profile.getPort());
+               values.put(KEY_SPLIT_TUNNELING, profile.getSplitTunneling());
                return values;
        }