android: Add field for MTU to data model
[strongswan.git] / src / frontends / android / src / org / strongswan / android / data / VpnProfileDataSource.java
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);
+       }
 }