From ad1657465778c05cef7a7ba9d25f97943cf68144 Mon Sep 17 00:00:00 2001 From: Markus Doits Date: Fri, 4 Nov 2011 21:22:49 +0100 Subject: Allow to pass large blobs and a new content provider to simplify this Since AIDL is not for passing large data, a blob can be passed to APG by a Uri. This Uri is opened as a file by APG and read/written to. Note the file is overwritten by APG, so make sure it is a copy if you want to keep the original. With the ApgServiceBlobProvider, Apg has an own ContentProvider that can be used like mentioned above. For now the data is stored in the dir where APG stores other files and NOT DELETED after en/decryption. This is tbd. It can only be accessed by an application with the permission "org.thialfihar.android.apg.permission.STORE_BLOBS". ApgCon has been updated accordingly and can handle blobs with `setBlob` and `getBlobResult`. That is a really easy way to en/decrypt large data. Note that encrypting by blob should only be used for large files (1MB+). On all other cases, the data should be passed as as String through the AIDl-Interface, so no temporary file must be created. See ApgCon for a complete example of how to connect to the AIDL and use it. Or use it in your own project! --- .../apg/provider/ApgServiceBlobDatabase.java | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/org/thialfihar/android/apg/provider/ApgServiceBlobDatabase.java (limited to 'src/org/thialfihar/android/apg/provider/ApgServiceBlobDatabase.java') diff --git a/src/org/thialfihar/android/apg/provider/ApgServiceBlobDatabase.java b/src/org/thialfihar/android/apg/provider/ApgServiceBlobDatabase.java new file mode 100644 index 000000000..9a891ddfa --- /dev/null +++ b/src/org/thialfihar/android/apg/provider/ApgServiceBlobDatabase.java @@ -0,0 +1,54 @@ +package org.thialfihar.android.apg.provider; + +import org.thialfihar.android.apg.ApgService; + +import android.content.ContentUris; +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.net.Uri; +import android.util.Log; + +public class ApgServiceBlobDatabase extends SQLiteOpenHelper { + + private static final String TAG = "ApgServiceBlobDatabase"; + + private static final int VERSION = 1; + private static final String NAME = "apg_service_blob_data"; + private static final String TABLE = "data"; + + public ApgServiceBlobDatabase(Context context) { + super(context, NAME, null, VERSION); + if(ApgService.LOCAL_LOGD) Log.d(TAG, "constructor called"); + } + + @Override + public void onCreate(SQLiteDatabase db) { + if(ApgService.LOCAL_LOGD) Log.d(TAG, "onCreate() called"); + db.execSQL("create table " + TABLE + " ( _id integer primary key autoincrement," + + "key text not null)"); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + if(ApgService.LOCAL_LOGD) Log.d(TAG, "onUpgrade() called"); + // no upgrade necessary yet + } + + public Uri insert(ContentValues vals) { + if(ApgService.LOCAL_LOGD) Log.d(TAG, "insert() called"); + SQLiteDatabase db = this.getWritableDatabase(); + long newId = db.insert(TABLE, null, vals); + return ContentUris.withAppendedId(ApgServiceBlobProvider.CONTENT_URI, newId); + } + + public Cursor query(String id, String key) { + if(ApgService.LOCAL_LOGD) Log.d(TAG, "query() called"); + SQLiteDatabase db = this.getReadableDatabase(); + return db.query(TABLE, new String[] {"_id"}, + "_id = ? and key = ?", new String[] {id, key}, + null, null, null); + } +} -- cgit v1.2.3