android: Add field for MTU to data model
authorTobias Brunner <tobias@strongswan.org>
Mon, 15 Jun 2015 13:36:46 +0000 (15:36 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 28 Jul 2015 11:27:32 +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 8323826..306f18b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Tobias Brunner
+ * Copyright (C) 2012-2015 Tobias Brunner
  * Copyright (C) 2012 Giuliano Grassi
  * Copyright (C) 2012 Ralf Sager
  * Hochschule fuer Technik Rapperswil
@@ -20,6 +20,7 @@ package org.strongswan.android.data;
 public class VpnProfile implements Cloneable
 {
        private String mName, mGateway, mUsername, mPassword, mCertificate, mUserCertificate;
+       private Integer mMTU;
        private VpnType mVpnType;
        private long mId = -1;
 
@@ -103,6 +104,16 @@ public class VpnProfile implements Cloneable
                this.mUserCertificate = alias;
        }
 
+       public Integer getMTU()
+       {
+               return mMTU;
+       }
+
+       public void setMTU(Integer mtu)
+       {
+               this.mMTU = mtu;
+       }
+
        @Override
        public String toString()
        {
index 6fd68d0..e5e5825 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Tobias Brunner
+ * Copyright (C) 2012-2015 Tobias Brunner
  * Copyright (C) 2012 Giuliano Grassi
  * Copyright (C) 2012 Ralf Sager
  * Hochschule fuer Technik Rapperswil
@@ -40,6 +40,7 @@ public class VpnProfileDataSource
        public static final String KEY_PASSWORD = "password";
        public static final String KEY_CERTIFICATE = "certificate";
        public static final String KEY_USER_CERTIFICATE = "user_certificate";
+       public static final String KEY_MTU = "mtu";
 
        private DatabaseHelper mDbHelper;
        private SQLiteDatabase mDatabase;
@@ -48,7 +49,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 = 4;
+       private static final int DATABASE_VERSION = 5;
 
        public static final String DATABASE_CREATE =
                                                        "CREATE TABLE " + TABLE_VPNPROFILE + " (" +
@@ -59,7 +60,8 @@ public class VpnProfileDataSource
                                                                KEY_USERNAME + " TEXT," +
                                                                KEY_PASSWORD + " TEXT," +
                                                                KEY_CERTIFICATE + " TEXT," +
-                                                               KEY_USER_CERTIFICATE + " TEXT" +
+                                                               KEY_USER_CERTIFICATE + " TEXT," +
+                                                               KEY_MTU + " INTEGER" +
                                                        ");";
        private static final String[] ALL_COLUMNS = new String[] {
                                                                KEY_ID,
@@ -70,6 +72,7 @@ public class VpnProfileDataSource
                                                                KEY_PASSWORD,
                                                                KEY_CERTIFICATE,
                                                                KEY_USER_CERTIFICATE,
+                                                               KEY_MTU,
                                                        };
 
        private static class DatabaseHelper extends SQLiteOpenHelper
@@ -104,6 +107,11 @@ public class VpnProfileDataSource
                        {       /* remove NOT NULL constraint from username column */
                                updateColumns(db);
                        }
+                       if (oldVersion < 5)
+                       {
+                               db.execSQL("ALTER TABLE " + TABLE_VPNPROFILE + " ADD " + KEY_MTU +
+                                                  " INTEGER;");
+                       }
                }
 
                private void updateColumns(SQLiteDatabase db)
@@ -255,6 +263,7 @@ public class VpnProfileDataSource
                profile.setPassword(cursor.getString(cursor.getColumnIndex(KEY_PASSWORD)));
                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)));
                return profile;
        }
 
@@ -268,6 +277,12 @@ public class VpnProfileDataSource
                values.put(KEY_PASSWORD, profile.getPassword());
                values.put(KEY_CERTIFICATE, profile.getCertificateAlias());
                values.put(KEY_USER_CERTIFICATE, profile.getUserCertificateAlias());
+               values.put(KEY_MTU, profile.getMTU());
                return values;
        }
+
+       private Integer getInt(Cursor cursor, int columnIndex)
+       {
+               return cursor.isNull(columnIndex) ? null : cursor.getInt(columnIndex);
+       }
 }