android: Add field for server port to data model
authorTobias Brunner <tobias@strongswan.org>
Tue, 16 Jun 2015 14:39:08 +0000 (16:39 +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 306f18b..6b83783 100644 (file)
@@ -20,7 +20,7 @@ package org.strongswan.android.data;
 public class VpnProfile implements Cloneable
 {
        private String mName, mGateway, mUsername, mPassword, mCertificate, mUserCertificate;
-       private Integer mMTU;
+       private Integer mMTU, mPort;
        private VpnType mVpnType;
        private long mId = -1;
 
@@ -114,6 +114,16 @@ public class VpnProfile implements Cloneable
                this.mMTU = mtu;
        }
 
+       public Integer getPort()
+       {
+               return mPort;
+       }
+
+       public void setPort(Integer port)
+       {
+               this.mPort = port;
+       }
+
        @Override
        public String toString()
        {
index e5e5825..b9842a9 100644 (file)
@@ -41,6 +41,7 @@ public class VpnProfileDataSource
        public static final String KEY_CERTIFICATE = "certificate";
        public static final String KEY_USER_CERTIFICATE = "user_certificate";
        public static final String KEY_MTU = "mtu";
+       public static final String KEY_PORT = "port";
 
        private DatabaseHelper mDbHelper;
        private SQLiteDatabase mDatabase;
@@ -49,7 +50,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 = 5;
+       private static final int DATABASE_VERSION = 6;
 
        public static final String DATABASE_CREATE =
                                                        "CREATE TABLE " + TABLE_VPNPROFILE + " (" +
@@ -61,7 +62,8 @@ public class VpnProfileDataSource
                                                                KEY_PASSWORD + " TEXT," +
                                                                KEY_CERTIFICATE + " TEXT," +
                                                                KEY_USER_CERTIFICATE + " TEXT," +
-                                                               KEY_MTU + " INTEGER" +
+                                                               KEY_MTU + " INTEGER," +
+                                                               KEY_PORT + " INTEGER" +
                                                        ");";
        private static final String[] ALL_COLUMNS = new String[] {
                                                                KEY_ID,
@@ -73,6 +75,7 @@ public class VpnProfileDataSource
                                                                KEY_CERTIFICATE,
                                                                KEY_USER_CERTIFICATE,
                                                                KEY_MTU,
+                                                               KEY_PORT,
                                                        };
 
        private static class DatabaseHelper extends SQLiteOpenHelper
@@ -112,6 +115,11 @@ public class VpnProfileDataSource
                                db.execSQL("ALTER TABLE " + TABLE_VPNPROFILE + " ADD " + KEY_MTU +
                                                   " INTEGER;");
                        }
+                       if (oldVersion < 6)
+                       {
+                               db.execSQL("ALTER TABLE " + TABLE_VPNPROFILE + " ADD " + KEY_PORT +
+                                                  " INTEGER;");
+                       }
                }
 
                private void updateColumns(SQLiteDatabase db)
@@ -264,6 +272,7 @@ public class VpnProfileDataSource
                profile.setCertificateAlias(cursor.getString(cursor.getColumnIndex(KEY_CERTIFICATE)));
                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)));
                return profile;
        }
 
@@ -278,6 +287,7 @@ public class VpnProfileDataSource
                values.put(KEY_CERTIFICATE, profile.getCertificateAlias());
                values.put(KEY_USER_CERTIFICATE, profile.getUserCertificateAlias());
                values.put(KEY_MTU, profile.getMTU());
+               values.put(KEY_PORT, profile.getPort());
                return values;
        }