From 3cd54581c33b20a9bfa55f767b245fc6e56e83ef Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 15 Sep 2015 03:02:05 +0200 Subject: mime: create more general InputDataOperation, which for now and does basic mime parsing --- .../provider/TemporaryStorageProvider.java | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/TemporaryStorageProvider.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/TemporaryStorageProvider.java index 7e9b24989..67f2c36bc 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/TemporaryStorageProvider.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/TemporaryStorageProvider.java @@ -67,8 +67,8 @@ public class TemporaryStorageProvider extends ContentProvider { private static final String COLUMN_NAME = "name"; private static final String COLUMN_TIME = "time"; private static final String COLUMN_TYPE = "mimetype"; - public static final String CONTENT_AUTHORITY = Constants.TEMPSTORAGE_AUTHORITY; - private static final Uri BASE_URI = Uri.parse("content://" + CONTENT_AUTHORITY); + public static final String AUTHORITY = Constants.TEMPSTORAGE_AUTHORITY; + public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY); private static final int DB_VERSION = 3; private static File cacheDir; @@ -77,18 +77,18 @@ public class TemporaryStorageProvider extends ContentProvider { ContentValues contentValues = new ContentValues(); contentValues.put(COLUMN_NAME, targetName); contentValues.put(COLUMN_TYPE, mimeType); - return context.getContentResolver().insert(BASE_URI, contentValues); + return context.getContentResolver().insert(CONTENT_URI, contentValues); } public static Uri createFile(Context context, String targetName) { ContentValues contentValues = new ContentValues(); contentValues.put(COLUMN_NAME, targetName); - return context.getContentResolver().insert(BASE_URI, contentValues); + return context.getContentResolver().insert(CONTENT_URI, contentValues); } public static Uri createFile(Context context) { ContentValues contentValues = new ContentValues(); - return context.getContentResolver().insert(BASE_URI, contentValues); + return context.getContentResolver().insert(CONTENT_URI, contentValues); } public static int setMimeType(Context context, Uri uri, String mimetype) { @@ -98,7 +98,7 @@ public class TemporaryStorageProvider extends ContentProvider { } public static int cleanUp(Context context) { - return context.getContentResolver().delete(BASE_URI, COLUMN_TIME + "< ?", + return context.getContentResolver().delete(CONTENT_URI, COLUMN_TIME + "< ?", new String[]{Long.toString(System.currentTimeMillis() - Constants.TEMPFILE_TTL)}); } @@ -163,12 +163,19 @@ public class TemporaryStorageProvider extends ContentProvider { throw new SecurityException("Listing temporary files is not allowed, only querying single files."); } + Log.d(Constants.TAG, "being asked for file " + uri); + File file; try { file = getFile(uri); + if (file.exists()) { + Log.e(Constants.TAG, "already exists"); + } } catch (FileNotFoundException e) { + Log.e(Constants.TAG, "file not found!"); return null; } + Cursor fileName = db.getReadableDatabase().query(TABLE_FILES, new String[]{COLUMN_NAME}, COLUMN_ID + "=?", new String[]{uri.getLastPathSegment()}, null, null, null); if (fileName != null) { @@ -236,7 +243,7 @@ public class TemporaryStorageProvider extends ContentProvider { Log.e(Constants.TAG, "File creation failed!"); return null; } - return Uri.withAppendedPath(BASE_URI, uuid); + return Uri.withAppendedPath(CONTENT_URI, uuid); } @Override @@ -274,6 +281,7 @@ public class TemporaryStorageProvider extends ContentProvider { @Override public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException { + Log.d(Constants.TAG, "openFile"); return openFileHelper(uri, mode); } -- cgit v1.2.3