Merge pull request #1751 from runnerway/decrypt-filename

Fix wrong behavior of third-party apps while opening files after decryption
This commit is contained in:
Dominik Schürmann
2016-03-05 15:06:43 +01:00
2 changed files with 14 additions and 4 deletions

View File

@@ -119,8 +119,9 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
// inform the storage provider about the mime type for this uri // inform the storage provider about the mime type for this uri
if (decryptResult.getDecryptionMetadata() != null) { if (decryptResult.getDecryptionMetadata() != null) {
TemporaryFileProvider.setMimeType(mContext, currentInputUri, OpenPgpMetadata meta = decryptResult.getDecryptionMetadata();
decryptResult.getDecryptionMetadata().getMimeType()); TemporaryFileProvider.setName(mContext, currentInputUri, meta.getFilename());
TemporaryFileProvider.setMimeType(mContext, currentInputUri, meta.getMimeType());
} }
} else { } else {

View File

@@ -99,6 +99,12 @@ public class TemporaryFileProvider extends ContentProvider {
return context.getContentResolver().insert(CONTENT_URI, contentValues); return context.getContentResolver().insert(CONTENT_URI, contentValues);
} }
public static int setName(Context context, Uri uri, String name) {
ContentValues values = new ContentValues();
values.put(TemporaryFileColumns.COLUMN_NAME, name);
return context.getContentResolver().update(uri, values, null, null);
}
public static int setMimeType(Context context, Uri uri, String mimetype) { public static int setMimeType(Context context, Uri uri, String mimetype) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(TemporaryFileColumns.COLUMN_TYPE, mimetype); values.put(TemporaryFileColumns.COLUMN_TYPE, mimetype);
@@ -283,8 +289,11 @@ public class TemporaryFileProvider extends ContentProvider {
@Override @Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
if (values.size() != 1 || !values.containsKey(TemporaryFileColumns.COLUMN_TYPE)) { if (values.size() != 1) {
throw new UnsupportedOperationException("Update supported only for type field!"); throw new UnsupportedOperationException("Update supported only for one field at a time!");
}
if (!values.containsKey(TemporaryFileColumns.COLUMN_NAME) && !values.containsKey(TemporaryFileColumns.COLUMN_TYPE)) {
throw new UnsupportedOperationException("Update supported only for name and type field!");
} }
if (selection != null || selectionArgs != null) { if (selection != null || selectionArgs != null) {
throw new UnsupportedOperationException("Update supported only for plain uri!"); throw new UnsupportedOperationException("Update supported only for plain uri!");