diff options
author | lado <herrlado@gmail.com> | 2012-01-16 13:14:20 +0100 |
---|---|---|
committer | lado <herrlado@gmail.com> | 2012-01-16 13:14:20 +0100 |
commit | fe98a35ec976b7deead814415afc013ffcaac1f1 (patch) | |
tree | ab1c420f5a8bfaa154fcd18159be60c091d85b1b /vdrmanager/src | |
parent | a6c6c4215082537b3b4ea1d651b45e1bb4cc11c3 (diff) | |
download | vdr-manager-fe98a35ec976b7deead814415afc013ffcaac1f1.tar.gz vdr-manager-fe98a35ec976b7deead814415afc013ffcaac1f1.tar.bz2 |
ORM
Diffstat (limited to 'vdrmanager/src')
-rw-r--r-- | vdrmanager/src/de/bjusystems/vdrmanager/StringUtils.java | 4 | ||||
-rw-r--r-- | vdrmanager/src/de/bjusystems/vdrmanager/app/VdrManagerApp.java | 9 | ||||
-rw-r--r-- | vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java | 1 | ||||
-rw-r--r-- | vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java | 1 | ||||
-rw-r--r-- | vdrmanager/src/de/bjusystems/vdrmanager/data/Vdr.java (renamed from vdrmanager/src/de/bjusystems/vdrmanager/data/VDR.java) | 2 | ||||
-rw-r--r-- | vdrmanager/src/de/bjusystems/vdrmanager/data/db/DataProvider.java | 759 | ||||
-rw-r--r-- | vdrmanager/src/de/bjusystems/vdrmanager/data/db/DbUtils.java | 35 | ||||
-rw-r--r-- | vdrmanager/src/de/bjusystems/vdrmanager/data/db/OrmDatabaseHelper.java | 98 | ||||
-rw-r--r-- | vdrmanager/src/de/bjusystems/vdrmanager/tasks/ChannelsTask.java | 1 | ||||
-rw-r--r-- | vdrmanager/src/de/bjusystems/vdrmanager/utils/crypt/NativeDES.java | 21 | ||||
-rw-r--r-- | vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java | 13 |
11 files changed, 137 insertions, 807 deletions
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/StringUtils.java b/vdrmanager/src/de/bjusystems/vdrmanager/StringUtils.java index 23f1845..18e1d88 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/StringUtils.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/StringUtils.java @@ -1,7 +1,7 @@ package de.bjusystems.vdrmanager; import java.util.ArrayList; -import java.util.List; + public class StringUtils { @@ -38,7 +38,7 @@ public class StringUtils { if (len == 0) { return EMPTY_STRING_ARRAY; } - List list = new ArrayList(); + ArrayList<String> list = new ArrayList<String>(); int sizePlus1 = 1; int i = 0, start = 0; boolean match = false; diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/app/VdrManagerApp.java b/vdrmanager/src/de/bjusystems/vdrmanager/app/VdrManagerApp.java index c89066b..73391d7 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/app/VdrManagerApp.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/app/VdrManagerApp.java @@ -6,13 +6,12 @@ import java.util.Locale; import android.app.Activity; import android.app.Application; -import android.app.LocalActivityManager; import de.bjusystems.vdrmanager.data.Channel; import de.bjusystems.vdrmanager.data.EpgSearchParams; import de.bjusystems.vdrmanager.data.Event; import de.bjusystems.vdrmanager.data.Preferences; import de.bjusystems.vdrmanager.data.Timer; -import de.bjusystems.vdrmanager.data.VDR; +import de.bjusystems.vdrmanager.data.Vdr; public class VdrManagerApp extends Application { @@ -29,13 +28,13 @@ public class VdrManagerApp extends Application { public static final Locale SYSTEM_LOCALE = Locale.getDefault() ; - private VDR currentVDR; + private Vdr currentVDR; - public VDR getCurrentVDR() { + public Vdr getCurrentVDR() { return currentVDR; } - public void setCurrentVDR(VDR currentVDR) { + public void setCurrentVDR(Vdr currentVDR) { this.currentVDR = currentVDR; } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java index 4b7e319..33a248b 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java @@ -5,7 +5,6 @@ import java.util.Locale; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; -import android.text.TextUtils; import de.bjusystems.vdrmanager.R; /** diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java index 0dd375a..2d5eb8d 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java @@ -8,7 +8,6 @@ import java.util.GregorianCalendar; import de.bjusystems.vdrmanager.StringUtils; import de.bjusystems.vdrmanager.app.C; import de.bjusystems.vdrmanager.gui.Utils; -import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient.TimerOperation; /** * Class for timer data diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/VDR.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Vdr.java index 05914c7..51eb82b 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/VDR.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Vdr.java @@ -1,6 +1,6 @@ package de.bjusystems.vdrmanager.data; -public class VDR { +public class Vdr { /** * Use secure channel diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/db/DataProvider.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/db/DataProvider.java deleted file mode 100644 index 95d4fdc..0000000 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/db/DataProvider.java +++ /dev/null @@ -1,759 +0,0 @@ -package de.bjusystems.vdrmanager.data.db; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; - -import android.content.ContentProvider; -import android.content.ContentUris; -import android.content.ContentValues; -import android.content.Context; -import android.content.UriMatcher; -import android.database.Cursor; -import android.database.SQLException; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteOpenHelper; -import android.database.sqlite.SQLiteQueryBuilder; -import android.net.Uri; -import android.text.TextUtils; -import android.util.Log; -import de.bjusystems.vdrmanager.app.VdrManagerApp; - -public class DataProvider extends ContentProvider { - - /** Tag for output. */ - private static final String TAG = "dp"; - - public static final String DATA_ON_SDCARD = "/sdcard/vdrmanager"; - // public static final String INVOICES_DIR = DATA_ON_SDCARD + "/invoices"; - // public static final String EXPORT_DIR = DATA_ON_SDCARD + "/export"; - // public static final String EXPORT_COMPLTED_DIR = EXPORT_DIR + - // "/completed"; - // public static final String EXPORT_CANCELED_DIR = EXPORT_DIR + - // "/canceled"; - - static { - File f = new File(DATA_ON_SDCARD); - if (f.exists()) { - if (f.isDirectory() == false) { - Log.w(TAG, DATA_ON_SDCARD + " exists but is not a directory"); - } - } else { - if (f.mkdirs() == false) { - Log.w(TAG, DATA_ON_SDCARD + " exists but is not a directory"); - } - } - } - - public static boolean checkDataFolderExists() { - File f = new File(DATA_ON_SDCARD); - return f.exists() && f.isDirectory(); - } - - /** Callmeter's package name. */ - public static final String PACKAGE = VdrManagerApp.class.getPackage() - .getName(); - - /** Authority. */ - public static final String AUTHORITY = PACKAGE + "de.bjusystems.vdrmanager.provider"; - - /** Name of the {@link SQLiteDatabase}. */ - private static final String DATABASE_NAME = "vdrmanager.db"; - - /** Version of the {@link SQLiteDatabase}. */ - private static final int DATABASE_VERSION = 1; - - /** Internal id: terms. */ - private static final int REMUX_PARAMS = 1; - - private static final int REMUX_PARAMS_ID = 2; - - private static final int VDR= 3; - - private static final int VDR_ID = 4; - - // /** Internal id: terms. */ - // private static final int TERMS_ID = 2; - // - // /** Internal id: terms. */ - // private static final int SERVICES = 3; - // - // /** Internal id: service id. */ - // private static final int SERVICES_ID = 4; - // - // private static final int PRODUCTS = 5; - // - // private static final int PRODUCTS_ID = 6; - // - // private static final int UOMS_ID = 7; - // - // private static final int UOMS = 8; - // - // private static final int JOBS = 9; - // - // private static final int JOBS_ID = 10; - // - // private static final int PRODUCT_CONFIG = 11; - // - // private static final int PRODUCT_CONFIG_ID = 12; - // - // private static final int PRODUCT_CONFIG_JOB = 13; - // - // private static final int SERVICE_CONFIG = 14; - // - // private static final int SERVICE_CONFIG_ID = 15; - // - // private static final int SERVICE_CONFIG_JOB = 16; - // - // private static final int MILEAGE = 17; - // - // private static final int MILEAGE_ID = 18; - // - // private static final int JOBS_P_S = 19; - - /** {@link UriMatcher}. */ - private static final UriMatcher URI_MATCHER; - - static { - URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH); - URI_MATCHER.addURI(AUTHORITY, "remux_params", REMUX_PARAMS); - URI_MATCHER.addURI(AUTHORITY, "remux_params/#", REMUX_PARAMS_ID); - URI_MATCHER.addURI(AUTHORITY, "vdr", VDR); - URI_MATCHER.addURI(AUTHORITY, "vdr/#", VDR_ID); - } - - /** {@link DatabaseHelper}. */ - private DatabaseHelper mOpenHelper; - - public static final class RemuxParams { - /** Table name. */ - public static final String TABLE = "remux_params"; - /** {@link HashMap} for projection. */ - private static final HashMap<String, String> PROJECTION_MAP; - - /** Index in projection: ID. */ - public static final int INDEX_ID = 0; - /** Index in projection: name of hours group. */ - public static final int INDEX_NAME = 1; - public static final int INDEX_VALUE = 2; - - /** ID. */ - public static final String ID = "_id"; - public static final String PARAM_NAME = "name"; - public static final String PARAM_VALUE = "value"; - - /** Projection used for query. */ - public static final String[] PROJECTION = new String[] {// - ID,// - PARAM_NAME, PARAM_VALUE }; - - /** Content {@link Uri}. */ - public static final Uri CONTENT_URI = Uri.parse("content://" - + AUTHORITY + "/" + TABLE); - /** - * The MIME type of {@link #CONTENT_URI} providing a list. - */ - public static final String CONTENT_TYPE = // . - "vnd.android.cursor.dir/vnd.vdramager.remux_params"; - - /** - * The MIME type of a {@link #CONTENT_URI} single entry. - */ - public static final String CONTENT_ITEM_TYPE = // . - "vnd.android.cursor.item/vnd.vdramager.jobs"; - - static { - PROJECTION_MAP = new HashMap<String, String>(); - for (String s : PROJECTION) { - PROJECTION_MAP.put(s, s); - } - } - - /** - * Get Name for id. - * - * @param cr - * {@link ContentResolver} - * @param id - * id - * @return name - */ - // public static String getName(final ContentResolver cr, final long id) - // { - // final Cursor cursor = cr.query( - // ContentUris.withAppendedId(CONTENT_URI, id), - // new String[] { NAME }, null, null, null); - // String ret = null; - // if (cursor != null && cursor.moveToFirst()) { - // ret = cursor.getString(0); - // } - // if (cursor != null && !cursor.isClosed()) { - // cursor.close(); - // } - // return ret; - // } - - /** - * Create table in {@link SQLiteDatabase}. - * - * @param db - * {@link SQLiteDatabase} - */ - public static void onCreate(final SQLiteDatabase db) { - Log.i(TAG, "create table: " + TABLE); - db.execSQL("DROP TABLE IF EXISTS " + TABLE); - db.execSQL("CREATE TABLE " + TABLE + " (" // . - + ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " // . - + PARAM_NAME + " TEXT, "// - + PARAM_VALUE + ");");// - } - - /** - * Upgrade table. - * - * @param db - * {@link SQLiteDatabase} - * @param oldVersion - * old version - * @param newVersion - * new version - */ - public static void onUpgrade(final SQLiteDatabase db, - final int oldVersion, final int newVersion) { - Log.w(TAG, "Upgrading table: " + TABLE); - // if(newVersion == 2){ - // final ContentValues[] values = backup(db, TABLE, PROJECTION, - // null); - // onCreate(db); - // reload(db, TABLE, values); - // } else if (newVersion >) - // db.execSQL("DROP INDEX IF EXISTS jobs.canceled_index"); - // db.execSQL("CREATE INDEX canceled_index ON jobs(canceled)"); - // db.execSQL("ALTER TABLE JOBS ADD " + EVENT_ID2 + " LONG"); - } - - /** Default constructor. */ - private RemuxParams() { - } - } - - - public static final class Vdr { - /** Table name. */ - public static final String TABLE = "vdr"; - /** {@link HashMap} for projection. */ - private static final HashMap<String, String> PROJECTION_MAP; - - /** Index in projection: ID. */ - public static final int INDEX_ID = 0; - /** Index in projection: name of hours group. */ - public static final int INDEX_NAME = 1; - public static final int INDEX_HOST = 2; - public static final int INDEX_PORT = 3; - public static final int INDEX_SECURE = 4; - public static final int INDEX_FILTER_CHANNELS = 5; - public static final int INDEX_CHANNEL_FILTER = 6; - public static final int INDEX_ENABLE_WAKEUP = 7; - public static final int INDEX_WAKEUP_METHOD = 8; - public static final int INDEX_WAKEUP_URL = 9; - public static final int INDEX_WAKEUP_USER = 10; - public static final int INDEX_WAKEUP_PASSWORD = 11; - public static final int INDEX_VDR_MAC = 12; - public static final int INDEX_ENABLE_ALIVE_CHECK = 13; - public static final int INDEX_ALIVE_CHECK_INTERVAL = 14; - public static final int INDEX_TIMER_PRE_MARGIN = 15; - public static final int INDEX_TIMER_POST_MARGIN = 15; - public static final int INDEX_TIMER_DEFAULT_PRIORITY = 16; - public static final int INDEX_TIMER_DEFAULT_LIFETIME = 17; - public static final int INDEX_STREAM_PORT = 18; - public static final int INDEX_STREAM_USERNAME = 19; - public static final int INDEX_STREAM_PASSWORD = 20; - public static final int INDEX_STREAMFORMAT = 21; - public static final int INDEX_WOL_CUSTOM_BROADCAST = 22; - public static final int INDEX_ENABLE_REMUX = 23; - public static final int INDEX_REMUX_PARAMETER = 24; - - - - /** ID. */ - public static final String ID = "_id"; - public static final String HOST = "host"; - public static final String PORT= "port"; - public static final String SECURE = "secure"; - /* - public static final String = ""; - public static final String = ""; - public static final String = ""; - public static final String = ""; - public static final String = ""; - public static final String = ""; - public static final String = ""; - public static final String = ""; - public static final String = ""; - - public static final String = ""; - public static final String = ""; - */ - - - /** Projection used for query. */ - public static final String[] PROJECTION = new String[] {// - ID,// - HOST, PORT, SECURE }; - - /** Content {@link Uri}. */ - public static final Uri CONTENT_URI = Uri.parse("content://" - + AUTHORITY + "/" + TABLE); - /** - * The MIME type of {@link #CONTENT_URI} providing a list. - */ - public static final String CONTENT_TYPE = // . - "vnd.android.cursor.dir/vnd.vdramager.remux_params"; - - /** - * The MIME type of a {@link #CONTENT_URI} single entry. - */ - public static final String CONTENT_ITEM_TYPE = // . - "vnd.android.cursor.item/vnd.vdramager.jobs"; - - static { - PROJECTION_MAP = new HashMap<String, String>(); - for (String s : PROJECTION) { - PROJECTION_MAP.put(s, s); - } - } - - /** - * Get Name for id. - * - * @param cr - * {@link ContentResolver} - * @param id - * id - * @return name - */ - // public static String getName(final ContentResolver cr, final long id) - // { - // final Cursor cursor = cr.query( - // ContentUris.withAppendedId(CONTENT_URI, id), - // new String[] { NAME }, null, null, null); - // String ret = null; - // if (cursor != null && cursor.moveToFirst()) { - // ret = cursor.getString(0); - // } - // if (cursor != null && !cursor.isClosed()) { - // cursor.close(); - // } - // return ret; - // } - - /** - * Create table in {@link SQLiteDatabase}. - * - * @param db - * {@link SQLiteDatabase} - */ - public static void onCreate(final SQLiteDatabase db) { - Log.i(TAG, "create table: " + TABLE); - db.execSQL("DROP TABLE IF EXISTS " + TABLE); - db.execSQL("CREATE TABLE " + TABLE + " (" // . - + ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " // . - + HOST + " TEXT, "// - + PORT + " INTEGER, " - + SECURE +" INTEGER" + - " " + - " " + - - - - - ");");// - } - - /** - * Upgrade table. - * - * @param db - * {@link SQLiteDatabase} - * @param oldVersion - * old version - * @param newVersion - * new version - */ - public static void onUpgrade(final SQLiteDatabase db, - final int oldVersion, final int newVersion) { - Log.w(TAG, "Upgrading table: " + TABLE); - // if(newVersion == 2){ - // final ContentValues[] values = backup(db, TABLE, PROJECTION, - // null); - // onCreate(db); - // reload(db, TABLE, values); - // } else if (newVersion >) - // db.execSQL("DROP INDEX IF EXISTS jobs.canceled_index"); - // db.execSQL("CREATE INDEX canceled_index ON jobs(canceled)"); - // db.execSQL("ALTER TABLE JOBS ADD " + EVENT_ID2 + " LONG"); - } - - /** Default constructor. */ - private Vdr() { - } - } - - - - /** - * Try to backup fields from table. - * - * @param db - * {@link SQLiteDatabase} - * @param table - * table - * @param cols - * columns - * @param strip - * column to forget on backup, eg. _id - * @return array of rows - */ - private static ContentValues[] backup(final SQLiteDatabase db, - final String table, final String[] cols, final String strip) { - ArrayList<ContentValues> ret = new ArrayList<ContentValues>(); - String[] proj = cols; - if (strip != null) { - proj = new String[cols.length - 1]; - int i = 0; - for (String c : cols) { - if (strip.equals(c)) { - continue; - } - proj[i] = c; - ++i; - } - } - final int l = proj.length; - Cursor cursor = null; - try { - cursor = db.query(table, proj, null, null, null, null, null); - } catch (SQLException e) { - if (l == 1) { - return null; - } - final String err = e.getMessage(); - if (!err.startsWith("no such column:")) { - return null; - } - final String str = err.split(":", 3)[1].trim(); - return backup(db, table, proj, str); - } - if (cursor != null && cursor.moveToFirst()) { - do { - final ContentValues cv = new ContentValues(); - for (int i = 0; i < l; i++) { - final String s = cursor.getString(i); - if (s != null) { - cv.put(proj[i], s); - } - } - ret.add(cv); - } while (cursor.moveToNext()); - } - if (cursor != null && !cursor.isClosed()) { - cursor.close(); - } - return ret.toArray(new ContentValues[0]); - } - - /** - * Reload backup into table. - * - * @param db - * {@link SQLiteDatabase} - * @param table - * table - * @param values - * {@link ContentValues}[] backed up with backup() - */ - private static void reload(final SQLiteDatabase db, final String table, - final ContentValues[] values) { - if (values == null || values.length == 0) { - return; - } - Log.d(TAG, "reload(db, " + table + ", cv[" + values.length + "])"); - for (ContentValues cv : values) { - db.insert(table, null, cv); - } - return; - } - - @Override - public Cursor query(Uri uri, String[] projection, String selection, - String[] selectionArgs, String sortOrder) { - final SQLiteDatabase db = this.mOpenHelper.getReadableDatabase(); - SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); - final int uid = URI_MATCHER.match(uri); - String groupBy = null; - switch (uid) { - case REMUX_PARAMS_ID: - qb.appendWhere(RemuxParams.ID + "=" + ContentUris.parseId(uri)); - qb.setTables(RemuxParams.TABLE); - qb.setProjectionMap(RemuxParams.PROJECTION_MAP); - break; - case REMUX_PARAMS: - sortOrder = RemuxParams.PARAM_NAME; - qb.setTables(RemuxParams.TABLE); - qb.setProjectionMap(RemuxParams.PROJECTION_MAP); - break; - - default: - throw new IllegalArgumentException("Unknown Uri " + uri); - } - // If no sort order is specified use the default - String orderBy; - if (TextUtils.isEmpty(sortOrder)) { - orderBy = null; - } else { - orderBy = sortOrder; - } - - // Run the query - final Cursor c = qb.query(db, projection, selection, selectionArgs, - groupBy, null, orderBy); - - // Tell the cursor what uri to watch, so it knows when its source data - // changes - c.setNotificationUri(this.getContext().getContentResolver(), uri); - return c; - } - - @Override - public String getType(Uri uri) { - switch (URI_MATCHER.match(uri)) { - case REMUX_PARAMS: - return RemuxParams.CONTENT_TYPE; - case REMUX_PARAMS_ID: - return RemuxParams.CONTENT_ITEM_TYPE; - } - throw new IllegalArgumentException("Unknown URI: " + uri); - } - - @Override - public Uri insert(Uri uri, ContentValues values) { - final SQLiteDatabase db = this.mOpenHelper.getWritableDatabase(); - long ret = -1; - switch (URI_MATCHER.match(uri)) { - case REMUX_PARAMS: - ret = db.insert(RemuxParams.TABLE, null, values); - break; - default: - throw new IllegalArgumentException("Unknown Uri " + uri); - } - if (ret < 0) { - return null; - } else { - this.getContext().getContentResolver().notifyChange(uri, null); - return ContentUris.withAppendedId(uri, ret); - } - } - - @Override - public int delete(Uri uri, String selection, String[] selectionArgs) { - final SQLiteDatabase db = this.mOpenHelper.getWritableDatabase(); - int ret = 0; - long id; - Cursor c; - String w; - switch (URI_MATCHER.match(uri)) { - case REMUX_PARAMS: - ret = db.delete(RemuxParams.TABLE, selection, selectionArgs); - break; - case REMUX_PARAMS_ID: - ret = db.delete(RemuxParams.TABLE, DbUtils.sqlAnd(RemuxParams.ID - + "=" + ContentUris.parseId(uri), selection), selectionArgs); - break; - default: - throw new IllegalArgumentException("Unknown Uri " + uri); - - } - if (ret > 0) { - this.getContext().getContentResolver().notifyChange(uri, null); - } - return ret; - } - - @Override - public int update(Uri uri, ContentValues values, String selection, - String[] selectionArgs) { - final SQLiteDatabase db = this.mOpenHelper.getWritableDatabase(); - long i; - int ret = 0; - switch (URI_MATCHER.match(uri)) { - case REMUX_PARAMS: - ret = db.update(RemuxParams.TABLE, values, selection, selectionArgs); - break; - case REMUX_PARAMS_ID: - ret = db.update(RemuxParams.TABLE, values, - DbUtils.sqlAnd( - RemuxParams.ID + "=" + ContentUris.parseId(uri), - selection), selectionArgs); - break; - default: - throw new IllegalArgumentException("Unknown Uri " + uri); - } - if (ret > 0) { - this.getContext().getContentResolver().notifyChange(uri, null); - } - return ret; - } - - /** - * This class helps open, create, and upgrade the database file. - */ - private static class DatabaseHelper extends SQLiteOpenHelper { - /** - * {@inheritDoc} - */ - @Override - public synchronized SQLiteDatabase getReadableDatabase() { - Log.d(TAG, "get readble db"); - SQLiteDatabase ret; - try { - ret = super.getReadableDatabase(); - } catch (IllegalStateException e) { - Log.e(TAG, "could not open databse, try again", e); - ret = super.getReadableDatabase(); - } - if (!ret.isOpen()) { // a restore closes the db. retry. - Log.w(TAG, "got closed database, try again"); - ret = super.getReadableDatabase(); - } - return ret; - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized SQLiteDatabase getWritableDatabase() { - Log.d(TAG, "get writable db"); - SQLiteDatabase ret; - try { - ret = super.getWritableDatabase(); - } catch (IllegalStateException e) { - Log.e(TAG, "could not open databse, try again", e); - ret = super.getWritableDatabase(); - } - if (!ret.isOpen()) { // a restore closes the db. retry. - Log.w(TAG, "got closed database, try again"); - ret = super.getWritableDatabase(); - } - return ret; - } - - /** {@link Context} . */ - private final Context ctx; - - /** - * Default Constructor. - * - * @param context - * {@link Context} - */ - DatabaseHelper(final Context context) { - super(context, DATABASE_NAME, null, DATABASE_VERSION); - this.ctx = context; - } - - /** - * {@inheritDoc} - */ - @Override - public void onCreate(final SQLiteDatabase db) { - Log.i(TAG, "create database"); - // if (doRestore(db)) { - // return; // skip create - // } - // Logs.onCreate(db); - // WebSMS.onCreate(db); - // SipCall.onCreate(db); - // Plans.onCreate(db); - // Rules.onCreate(db); - // Numbers.onCreate(db); - // NumbersGroup.onCreate(db); - // Hours.onCreate(db); - // HoursGroup.onCreate(db); - RemuxParams.onCreate(db); - - // import default - // BufferedReader reader = new BufferedReader(new InputStreamReader( - // this.ctx.getResources() - // .openRawResource(R.raw.default_setup))); - // final ArrayList<String> sb = new ArrayList<String>(); - // try { - // String line = reader.readLine(); - // while (line != null) { - // sb.add(line); - // line = reader.readLine(); - // } - // } catch (IOException e) { - // Log.e(TAG, "error reading raw data", e); - // } - // importData(db, sb.toArray(new String[] {})); - } - - /** - * {@inheritDoc} - */ - @Override - public void onUpgrade(final SQLiteDatabase db, final int oldVersion, - final int newVersion) { - Log.w(TAG, "Upgrading database from version " + oldVersion + " to " - + newVersion + ", which will destroy all old data"); - // ProductConfig.onUpgrade(db, oldVersion, newVersion); - // ServiceConfig.onUpgrade(db, oldVersion, newVersion); - // ConfiguredProduct.o - // Products.onUpgrade(db, oldVersion, newVersion); - // Jobs.onUpgrade(db, oldVersion, newVersion); - // Logs.onUpgrade(db, oldVersion, newVersion); - // WebSMS.onUpgrade(db, oldVersion, newVersion); - // SipCall.onUpgrade(db, oldVersion, newVersion); - // Plans.onUpgrade(db, oldVersion, newVersion); - // Rules.onUpgrade(db, oldVersion, newVersion); - // Numbers.onUpgrade(db, oldVersion, newVersion); - // NumbersGroup.onUpgrade(db, oldVersion, newVersion); - // Hours.onUpgrade(db, oldVersion, newVersion); - // HoursGroup.onUpgrade(db, oldVersion, newVersion); - // unmatch(db); - } - } - - // private static void unmatch(final SQLiteDatabase db) { - // Log.d(TAG, "unmatch()"); - // if (db.isReadOnly()) { - // Log.e(TAG, "Database is readonly, cann not unmatch on upgrade!"); - // return; - // } - // ContentValues cv = new ContentValues(); - // cv.put(DataProvider.Logs.PLAN_ID, DataProvider.NO_ID); - // cv.put(DataProvider.Logs.RULE_ID, DataProvider.NO_ID); - // db.update(DataProvider.Logs.TABLE, cv, null, null); - // cv.clear(); - // cv.put(DataProvider.Plans.NEXT_ALERT, 0); - // db.update(DataProvider.Plans.TABLE, cv, null, null); - // } - /** - * {@inheritDoc} - */ - @Override - public boolean onCreate() { - this.mOpenHelper = new DatabaseHelper(this.getContext()) { - public void onOpen(SQLiteDatabase db) { - super.onOpen(db); - if (!db.isReadOnly()) { - // Enable foreign key constraints - db.execSQL("PRAGMA foreign_keys=ON;"); - } - }; - - }; - return true; - } -} diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/db/DbUtils.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/db/DbUtils.java deleted file mode 100644 index ff3f3db..0000000 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/db/DbUtils.java +++ /dev/null @@ -1,35 +0,0 @@ -package de.bjusystems.vdrmanager.data.db; - -/** - * @author flx - */ -public class DbUtils { - - /** - * Default Constructor. - */ - private DbUtils() { - - } - - /** - * SQL AND for where clause. - * - * @param arg0 - * arg0 - * @param arg1 - * arg1 - * @return ( arg0 ) AND ( arg1 ) - */ - public static String sqlAnd(final String arg0, final String arg1) { - if (arg0 != null && arg1 != null) { - return "( " + arg0 + " ) AND ( " + arg1 + " )"; - } else if (arg0 != null) { - return arg0; - } else if (arg1 != null) { - return arg1; - } else { - return null; - } - } -} diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/db/OrmDatabaseHelper.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/db/OrmDatabaseHelper.java new file mode 100644 index 0000000..348260c --- /dev/null +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/db/OrmDatabaseHelper.java @@ -0,0 +1,98 @@ +package de.bjusystems.vdrmanager.data.db; + +import java.sql.SQLException; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.util.Log; + +import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper; +import com.j256.ormlite.dao.RuntimeExceptionDao; +import com.j256.ormlite.support.ConnectionSource; +import com.j256.ormlite.table.TableUtils; + +import de.bjusystems.vdrmanager.data.Vdr; + +/** + * Database helper class used to manage the creation and upgrading of your database. This class also usually provides + * the DAOs used by the other classes. + */ +public class OrmDatabaseHelper extends OrmLiteSqliteOpenHelper { + + // name of the database file for your application -- change to something appropriate for your app + private static final String DATABASE_NAME = "vdrmanager.db"; + // any time you make changes to your database objects, you may have to increase the database version + private static final int DATABASE_VERSION = 1; + + + private RuntimeExceptionDao<Vdr, Integer> vdrDAO = null; + + + public OrmDatabaseHelper(Context context) { + super(context, DATABASE_NAME, null, DATABASE_VERSION); + } + + /** + * This is called when the database is first created. Usually you should call createTable statements here to create + * the tables that will store your data. + */ + @Override + public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) { + try { + Log.i(OrmDatabaseHelper.class.getName(), "onCreate"); + TableUtils.createTable(connectionSource, Vdr.class); + } catch (SQLException e) { + Log.e(OrmDatabaseHelper.class.getName(), "Can't create database", e); + throw new RuntimeException(e); + } + +// // here we try inserting data in the on-create as a test +// RuntimeExceptionDao<Note, Integer> dao = getSimpleDataDao(); +// long millis = System.currentTimeMillis(); +// // create some entries in the onCreate +// Note simple = new Note(); +// dao.create(simple); +// simple = new SimpleData(millis + 1); +// dao.create(simple); +// Log.i(DatabaseHelper.class.getName(), "created new entries in onCreate: " + millis); + } + + /** + * This is called when your application is upgraded and it has a higher version number. This allows you to adjust + * the various data to match the new version number. + */ + @Override + public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) { + try { + Log.i(OrmDatabaseHelper.class.getName(), "onUpgrade"); + TableUtils.dropTable(connectionSource, Vdr.class, true); + // after we drop the old databases, we create the new ones + onCreate(db, connectionSource); + } catch (SQLException e) { + Log.e(OrmDatabaseHelper.class.getName(), "Can't drop databases", e); + throw new RuntimeException(e); + } + } + + + + /** + * Returns the Database Access Object (DAO) for our Label class. It will create it or just give the cached + * value. + */ + public RuntimeExceptionDao<Vdr, Integer> getVDRDAO() { + if (vdrDAO == null) { + vdrDAO = getRuntimeExceptionDao(Vdr.class); + } + return vdrDAO; + } + + /** + * Close the database connections and clear any cached DAOs. + */ + @Override + public void close() { + super.close(); + vdrDAO = null; + } +}
\ No newline at end of file diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ChannelsTask.java b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ChannelsTask.java index f4a3358..bd4a679 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ChannelsTask.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ChannelsTask.java @@ -1,7 +1,6 @@ package de.bjusystems.vdrmanager.tasks; import android.app.Activity; -import de.bjusystems.vdrmanager.R; import de.bjusystems.vdrmanager.data.Channel; import de.bjusystems.vdrmanager.utils.svdrp.ChannelClient; diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/crypt/NativeDES.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/crypt/NativeDES.java new file mode 100644 index 0000000..114f540 --- /dev/null +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/crypt/NativeDES.java @@ -0,0 +1,21 @@ +package de.bjusystems.vdrmanager.utils.crypt; + +public class NativeDES { + static { + System.loadLibrary("native_des"); + } + /** + * @param str + * @param key + * @return + */ + public native String encrypt( String str, String key); + + + /** + * @param str + * @param key + * @return + */ + public native String decrypt(String str, String key); +} diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java index 7423a26..aa45fb7 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java @@ -17,6 +17,7 @@ import java.util.zip.InflaterInputStream; import android.util.Log; import de.bjusystems.vdrmanager.app.C; import de.bjusystems.vdrmanager.data.Preferences; +import de.bjusystems.vdrmanager.utils.crypt.NativeDES; /** * Class for SVDRP communication @@ -50,6 +51,8 @@ public abstract class SvdrpClient<Result> { // } private Timer watchDog = new Timer(); + + private NativeDES crypt = new NativeDES(); public boolean isConnected() { if (socket == null) { @@ -241,8 +244,11 @@ public abstract class SvdrpClient<Result> { */ protected void writeLine(final String line) throws IOException { - final String command = line + "\r\n"; - final byte[] bytes = command.getBytes(); + String command = line + "\r\n"; + if(Preferences.get().isSSL()){ + command = crypt.encrypt(command, Preferences.get().getPassword()); + } + final byte[] bytes = command.getBytes("utf-8"); outputStream.write(bytes); outputStream.flush(); } @@ -289,6 +295,9 @@ public abstract class SvdrpClient<Result> { Log.w(TAG, usex); line = lineBytes.toString(); } + if(Preferences.get().isSSL()){ + line = crypt.decrypt(line, Preferences.get().getPassword()); + } return line; } |