Rename TemporaryStorageProvider to TemporaryFileProvider, use interface for db contract

This commit is contained in:
Dominik Schürmann
2015-10-15 19:37:08 +02:00
parent c0cd872954
commit 7384fa7f2b
14 changed files with 71 additions and 63 deletions

View File

@@ -32,7 +32,7 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider;
import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.ui.util.Notify.Style;
import static android.support.test.InstrumentationRegistry.getInstrumentation; import static android.support.test.InstrumentationRegistry.getInstrumentation;
@@ -133,7 +133,7 @@ public class SymmetricTextOperationTests {
hasExtra(equalTo(Intent.EXTRA_INTENT), allOf( hasExtra(equalTo(Intent.EXTRA_INTENT), allOf(
hasAction(Intent.ACTION_VIEW), hasAction(Intent.ACTION_VIEW),
hasFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION), hasFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION),
hasData(allOf(hasScheme("content"), hasHost(TemporaryStorageProvider.AUTHORITY))), hasData(allOf(hasScheme("content"), hasHost(TemporaryFileProvider.AUTHORITY))),
hasType("text/plain") hasType("text/plain")
)) ))
)).respondWith(new ActivityResult(Activity.RESULT_OK, null)); )).respondWith(new ActivityResult(Activity.RESULT_OK, null));

View File

@@ -34,7 +34,7 @@ import org.junit.runners.MethodSorters;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider;
import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.ui.util.Notify.Style;
import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.Espresso.onView;
@@ -96,7 +96,7 @@ public class ViewKeyAdvShareTest {
hasType("text/plain"), hasType("text/plain"),
hasExtra(is(Intent.EXTRA_TEXT), is("openpgp4fpr:c619d53f7a5f96f391a84ca79d604d2f310716a3")), hasExtra(is(Intent.EXTRA_TEXT), is("openpgp4fpr:c619d53f7a5f96f391a84ca79d604d2f310716a3")),
hasExtra(is(Intent.EXTRA_STREAM), hasExtra(is(Intent.EXTRA_STREAM),
allOf(hasScheme("content"), hasHost(TemporaryStorageProvider.AUTHORITY))) allOf(hasScheme("content"), hasHost(TemporaryFileProvider.AUTHORITY)))
)) ))
)).respondWith(new ActivityResult(Activity.RESULT_OK, null)); )).respondWith(new ActivityResult(Activity.RESULT_OK, null));
onView(withId(R.id.view_key_action_fingerprint_share)).perform(click()); onView(withId(R.id.view_key_action_fingerprint_share)).perform(click());
@@ -113,7 +113,7 @@ public class ViewKeyAdvShareTest {
hasType("text/plain"), hasType("text/plain"),
hasExtra(is(Intent.EXTRA_TEXT), startsWith("----")), hasExtra(is(Intent.EXTRA_TEXT), startsWith("----")),
hasExtra(is(Intent.EXTRA_STREAM), hasExtra(is(Intent.EXTRA_STREAM),
allOf(hasScheme("content"), hasHost(TemporaryStorageProvider.AUTHORITY))) allOf(hasScheme("content"), hasHost(TemporaryFileProvider.AUTHORITY)))
)) ))
)).respondWith(new ActivityResult(Activity.RESULT_OK, null)); )).respondWith(new ActivityResult(Activity.RESULT_OK, null));
onView(withId(R.id.view_key_action_key_share)).perform(click()); onView(withId(R.id.view_key_action_key_share)).perform(click());

View File

@@ -845,7 +845,7 @@
<!-- Storage Provider for temporary decrypted files --> <!-- Storage Provider for temporary decrypted files -->
<provider <provider
android:name=".provider.TemporaryStorageProvider" android:name=".provider.TemporaryFileProvider"
android:authorities="${applicationId}.tempstorage" android:authorities="${applicationId}.tempstorage"
android:exported="true" android:exported="true"
android:writePermission="${applicationId}.WRITE_TEMPORARY_STORAGE" /> android:writePermission="${applicationId}.WRITE_TEMPORARY_STORAGE" />

View File

@@ -33,7 +33,7 @@ import android.widget.Toast;
import org.spongycastle.jce.provider.BouncyCastleProvider; import org.spongycastle.jce.provider.BouncyCastleProvider;
import org.sufficientlysecure.keychain.provider.KeychainDatabase; import org.sufficientlysecure.keychain.provider.KeychainDatabase;
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider;
import org.sufficientlysecure.keychain.service.KeyserverSyncAdapterService; import org.sufficientlysecure.keychain.service.KeyserverSyncAdapterService;
import org.sufficientlysecure.keychain.ui.ConsolidateDialogActivity; import org.sufficientlysecure.keychain.ui.ConsolidateDialogActivity;
import org.sufficientlysecure.keychain.ui.util.FormattingUtils; import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
@@ -102,7 +102,7 @@ public class KeychainApplication extends Application {
TlsHelper.addPinnedCertificate("pgp.mit.edu", getAssets(), "pgp.mit.edu.cer"); TlsHelper.addPinnedCertificate("pgp.mit.edu", getAssets(), "pgp.mit.edu.cer");
TlsHelper.addPinnedCertificate("api.keybase.io", getAssets(), "api.keybase.io.CA.cer"); TlsHelper.addPinnedCertificate("api.keybase.io", getAssets(), "api.keybase.io.CA.cer");
TemporaryStorageProvider.cleanUp(this); TemporaryFileProvider.cleanUp(this);
if (!checkConsolidateRecovery()) { if (!checkConsolidateRecovery()) {
// force DB upgrade, https://github.com/open-keychain/open-keychain/issues/1334 // force DB upgrade, https://github.com/open-keychain/open-keychain/issues/1334

View File

@@ -54,7 +54,7 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider;
import org.sufficientlysecure.keychain.service.ExportKeyringParcel; import org.sufficientlysecure.keychain.service.ExportKeyringParcel;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
@@ -111,7 +111,7 @@ public class ExportOperation extends BaseOperation<ExportKeyringParcel> {
Uri exportOutputUri = nonEncryptedOutput Uri exportOutputUri = nonEncryptedOutput
? exportInput.mOutputUri ? exportInput.mOutputUri
: TemporaryStorageProvider.createFile(mContext); : TemporaryFileProvider.createFile(mContext);
int exportedDataSize; int exportedDataSize;

View File

@@ -48,7 +48,7 @@ import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation;
import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider;
import org.sufficientlysecure.keychain.service.InputDataParcel; import org.sufficientlysecure.keychain.service.InputDataParcel;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
@@ -101,7 +101,7 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
decryptInput.setInputUri(input.getInputUri()); decryptInput.setInputUri(input.getInputUri());
currentInputUri = TemporaryStorageProvider.createFile(mContext); currentInputUri = TemporaryFileProvider.createFile(mContext);
decryptInput.setOutputUri(currentInputUri); decryptInput.setOutputUri(currentInputUri);
decryptResult = op.execute(decryptInput, cryptoInput); decryptResult = op.execute(decryptInput, cryptoInput);
@@ -117,7 +117,7 @@ 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) {
TemporaryStorageProvider.setMimeType(mContext, currentInputUri, TemporaryFileProvider.setMimeType(mContext, currentInputUri,
decryptResult.getDecryptionMetadata().getMimeType()); decryptResult.getDecryptionMetadata().getMimeType());
} }
@@ -195,7 +195,7 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
log.add(LogType.MSG_DATA_DETACHED_RAW, 3); log.add(LogType.MSG_DATA_DETACHED_RAW, 3);
uncheckedSignedDataUri = TemporaryStorageProvider.createFile(mContext, mFilename, "text/plain"); uncheckedSignedDataUri = TemporaryFileProvider.createFile(mContext, mFilename, "text/plain");
OutputStream out = mContext.getContentResolver().openOutputStream(uncheckedSignedDataUri, "w"); OutputStream out = mContext.getContentResolver().openOutputStream(uncheckedSignedDataUri, "w");
if (out == null) { if (out == null) {
@@ -297,7 +297,7 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
log.add(LogType.MSG_DATA_MIME_FILENAME, 3, mFilename); log.add(LogType.MSG_DATA_MIME_FILENAME, 3, mFilename);
} }
Uri uri = TemporaryStorageProvider.createFile(mContext, mFilename, bd.getMimeType()); Uri uri = TemporaryFileProvider.createFile(mContext, mFilename, bd.getMimeType());
OutputStream out = mContext.getContentResolver().openOutputStream(uri, "w"); OutputStream out = mContext.getContentResolver().openOutputStream(uri, "w");
if (out == null) { if (out == null) {

View File

@@ -43,14 +43,14 @@ import java.util.UUID;
/** /**
* TemporaryStorageProvider stores decrypted files inside the app's cache directory previously to * TemporaryStorageProvider stores decrypted files inside the app's cache directory previously to
* sharing them with other applications. * sharing them with other applications.
* * <p/>
* Security: * Security:
* - It is writable by OpenKeychain only (see Manifest), but exported for reading files * - It is writable by OpenKeychain only (see Manifest), but exported for reading files
* - It uses UUIDs as identifiers which makes predicting files from outside impossible * - It uses UUIDs as identifiers which makes predicting files from outside impossible
* - Querying a number of files is not allowed, only querying single files * - Querying a number of files is not allowed, only querying single files
* -> You can only open a file if you know the Uri containing the precise UUID, this Uri is only * -> You can only open a file if you know the Uri containing the precise UUID, this Uri is only
* revealed when the user shares a decrypted file with another app. * revealed when the user shares a decrypted file with another app.
* * <p/>
* Why is support lib's FileProvider not used? * Why is support lib's FileProvider not used?
* Because granting Uri permissions temporarily does not work correctly. See * Because granting Uri permissions temporarily does not work correctly. See
* - https://code.google.com/p/android/issues/detail?id=76683 * - https://code.google.com/p/android/issues/detail?id=76683
@@ -59,30 +59,33 @@ import java.util.UUID;
* - http://stackoverflow.com/q/18249007 * - http://stackoverflow.com/q/18249007
* - Comments at http://www.blogc.at/2014/03/23/share-private-files-with-other-apps-fileprovider/ * - Comments at http://www.blogc.at/2014/03/23/share-private-files-with-other-apps-fileprovider/
*/ */
public class TemporaryStorageProvider extends ContentProvider { public class TemporaryFileProvider extends ContentProvider {
private static final String DB_NAME = "tempstorage.db"; private static final String DB_NAME = "tempstorage.db";
private static final String TABLE_FILES = "files"; private static final String TABLE_FILES = "files";
private static final String COLUMN_ID = "id";
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 AUTHORITY = Constants.TEMPSTORAGE_AUTHORITY; public static final String AUTHORITY = Constants.TEMPSTORAGE_AUTHORITY;
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY); public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY);
private static final int DB_VERSION = 3; private static final int DB_VERSION = 3;
interface TemporaryFileColumns {
String COLUMN_UUID = "id";
String COLUMN_NAME = "name";
String COLUMN_TIME = "time";
String COLUMN_TYPE = "mimetype";
}
private static File cacheDir; private static File cacheDir;
public static Uri createFile(Context context, String targetName, String mimeType) { public static Uri createFile(Context context, String targetName, String mimeType) {
ContentValues contentValues = new ContentValues(); ContentValues contentValues = new ContentValues();
contentValues.put(COLUMN_NAME, targetName); contentValues.put(TemporaryFileColumns.COLUMN_NAME, targetName);
contentValues.put(COLUMN_TYPE, mimeType); contentValues.put(TemporaryFileColumns.COLUMN_TYPE, mimeType);
return context.getContentResolver().insert(CONTENT_URI, contentValues); return context.getContentResolver().insert(CONTENT_URI, contentValues);
} }
public static Uri createFile(Context context, String targetName) { public static Uri createFile(Context context, String targetName) {
ContentValues contentValues = new ContentValues(); ContentValues contentValues = new ContentValues();
contentValues.put(COLUMN_NAME, targetName); contentValues.put(TemporaryFileColumns.COLUMN_NAME, targetName);
return context.getContentResolver().insert(CONTENT_URI, contentValues); return context.getContentResolver().insert(CONTENT_URI, contentValues);
} }
@@ -93,13 +96,16 @@ public class TemporaryStorageProvider extends ContentProvider {
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(COLUMN_TYPE, mimetype); values.put(TemporaryFileColumns.COLUMN_TYPE, mimetype);
return context.getContentResolver().update(uri, values, null, null); return context.getContentResolver().update(uri, values, null, null);
} }
public static int cleanUp(Context context) { public static int cleanUp(Context context) {
return context.getContentResolver().delete(CONTENT_URI, COLUMN_TIME + "< ?", return context.getContentResolver().delete(
new String[]{Long.toString(System.currentTimeMillis() - Constants.TEMPFILE_TTL)}); CONTENT_URI,
TemporaryFileColumns.COLUMN_TIME + "< ?",
new String[]{Long.toString(System.currentTimeMillis() - Constants.TEMPFILE_TTL)}
);
} }
private class TemporaryStorageDatabase extends SQLiteOpenHelper { private class TemporaryStorageDatabase extends SQLiteOpenHelper {
@@ -111,10 +117,10 @@ public class TemporaryStorageProvider extends ContentProvider {
@Override @Override
public void onCreate(SQLiteDatabase db) { public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_FILES + " (" + db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_FILES + " (" +
COLUMN_ID + " TEXT PRIMARY KEY, " + TemporaryFileColumns.COLUMN_UUID + " TEXT PRIMARY KEY, " +
COLUMN_NAME + " TEXT, " + TemporaryFileColumns.COLUMN_NAME + " TEXT, " +
COLUMN_TYPE + " TEXT, " + TemporaryFileColumns.COLUMN_TYPE + " TEXT, " +
COLUMN_TIME + " INTEGER" + TemporaryFileColumns.COLUMN_TIME + " INTEGER" +
");"); ");");
} }
@@ -126,12 +132,12 @@ public class TemporaryStorageProvider extends ContentProvider {
case 1: case 1:
db.execSQL("DROP TABLE IF EXISTS files"); db.execSQL("DROP TABLE IF EXISTS files");
db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_FILES + " (" + db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_FILES + " (" +
COLUMN_ID + " TEXT PRIMARY KEY, " + TemporaryFileColumns.COLUMN_UUID + " TEXT PRIMARY KEY, " +
COLUMN_NAME + " TEXT, " + TemporaryFileColumns.COLUMN_NAME + " TEXT, " +
COLUMN_TIME + " INTEGER" + TemporaryFileColumns.COLUMN_TIME + " INTEGER" +
");"); ");");
case 2: case 2:
db.execSQL("ALTER TABLE files ADD COLUMN " + COLUMN_TYPE + " TEXT"); db.execSQL("ALTER TABLE files ADD COLUMN " + TemporaryFileColumns.COLUMN_TYPE + " TEXT");
} }
} }
} }
@@ -176,7 +182,9 @@ public class TemporaryStorageProvider extends ContentProvider {
return null; return null;
} }
Cursor fileName = db.getReadableDatabase().query(TABLE_FILES, new String[]{COLUMN_NAME}, COLUMN_ID + "=?", Cursor fileName = db.getReadableDatabase().query(TABLE_FILES,
new String[]{TemporaryFileColumns.COLUMN_NAME},
TemporaryFileColumns.COLUMN_UUID + "=?",
new String[]{uri.getLastPathSegment()}, null, null, null); new String[]{uri.getLastPathSegment()}, null, null, null);
if (fileName != null) { if (fileName != null) {
if (fileName.moveToNext()) { if (fileName.moveToNext()) {
@@ -200,7 +208,7 @@ public class TemporaryStorageProvider extends ContentProvider {
@Override @Override
public String getType(Uri uri) { public String getType(Uri uri) {
Cursor cursor = db.getReadableDatabase().query(TABLE_FILES, Cursor cursor = db.getReadableDatabase().query(TABLE_FILES,
new String[]{COLUMN_TYPE}, COLUMN_ID + "=?", new String[]{TemporaryFileColumns.COLUMN_TYPE}, TemporaryFileColumns.COLUMN_UUID + "=?",
new String[]{uri.getLastPathSegment()}, null, null, null); new String[]{uri.getLastPathSegment()}, null, null, null);
if (cursor != null) { if (cursor != null) {
try { try {
@@ -227,11 +235,11 @@ public class TemporaryStorageProvider extends ContentProvider {
@Override @Override
public Uri insert(Uri uri, ContentValues values) { public Uri insert(Uri uri, ContentValues values) {
if (!values.containsKey(COLUMN_TIME)) { if (!values.containsKey(TemporaryFileColumns.COLUMN_TIME)) {
values.put(COLUMN_TIME, System.currentTimeMillis()); values.put(TemporaryFileColumns.COLUMN_TIME, System.currentTimeMillis());
} }
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
values.put(COLUMN_ID, uuid); values.put(TemporaryFileColumns.COLUMN_UUID, uuid);
int insert = (int) db.getWritableDatabase().insert(TABLE_FILES, null, values); int insert = (int) db.getWritableDatabase().insert(TABLE_FILES, null, values);
if (insert == -1) { if (insert == -1) {
Log.e(Constants.TAG, "Insert failed!"); Log.e(Constants.TAG, "Insert failed!");
@@ -252,10 +260,10 @@ public class TemporaryStorageProvider extends ContentProvider {
return 0; return 0;
} }
selection = DatabaseUtil.concatenateWhere(selection, COLUMN_ID + "=?"); selection = DatabaseUtil.concatenateWhere(selection, TemporaryFileColumns.COLUMN_UUID + "=?");
selectionArgs = DatabaseUtil.appendSelectionArgs(selectionArgs, new String[]{uri.getLastPathSegment()}); selectionArgs = DatabaseUtil.appendSelectionArgs(selectionArgs, new String[]{uri.getLastPathSegment()});
Cursor files = db.getReadableDatabase().query(TABLE_FILES, new String[]{COLUMN_ID}, selection, Cursor files = db.getReadableDatabase().query(TABLE_FILES, new String[]{TemporaryFileColumns.COLUMN_UUID}, selection,
selectionArgs, null, null, null); selectionArgs, null, null, null);
if (files != null) { if (files != null) {
while (files.moveToNext()) { while (files.moveToNext()) {
@@ -269,14 +277,14 @@ public class TemporaryStorageProvider 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(COLUMN_TYPE)) { if (values.size() != 1 || !values.containsKey(TemporaryFileColumns.COLUMN_TYPE)) {
throw new UnsupportedOperationException("Update supported only for type field!"); throw new UnsupportedOperationException("Update supported only for 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!");
} }
return db.getWritableDatabase().update(TABLE_FILES, values, return db.getWritableDatabase().update(TABLE_FILES, values,
COLUMN_ID + " = ?", new String[]{uri.getLastPathSegment()}); TemporaryFileColumns.COLUMN_UUID + " = ?", new String[]{uri.getLastPathSegment()});
} }
@Override @Override

View File

@@ -51,7 +51,7 @@ import android.widget.TextView;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.operations.results.ExportResult; import org.sufficientlysecure.keychain.operations.results.ExportResult;
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider;
import org.sufficientlysecure.keychain.service.ExportKeyringParcel; import org.sufficientlysecure.keychain.service.ExportKeyringParcel;
import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment; import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment;
import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify;
@@ -427,7 +427,7 @@ public class BackupCodeFragment extends CryptoOperationFragment<ExportKeyringPar
} }
if (mCachedBackupUri == null) { if (mCachedBackupUri == null) {
mCachedBackupUri = TemporaryStorageProvider.createFile(activity); mCachedBackupUri = TemporaryFileProvider.createFile(activity);
cryptoOperation(); cryptoOperation();
return; return;
} }

View File

@@ -37,7 +37,7 @@ import android.widget.Toast;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.intents.OpenKeychainIntents; import org.sufficientlysecure.keychain.intents.OpenKeychainIntents;
import org.sufficientlysecure.keychain.pgp.PgpHelper; import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider;
import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.base.BaseActivity;
@@ -193,7 +193,7 @@ public class DecryptActivity extends BaseActivity {
@Nullable @Nullable
public Uri readToTempFile(String text) throws IOException { public Uri readToTempFile(String text) throws IOException {
Uri tempFile = TemporaryStorageProvider.createFile(this); Uri tempFile = TemporaryFileProvider.createFile(this);
OutputStream outStream = getContentResolver().openOutputStream(tempFile); OutputStream outStream = getContentResolver().openOutputStream(tempFile);
if (outStream == null) { if (outStream == null) {
return null; return null;

View File

@@ -57,7 +57,7 @@ import org.sufficientlysecure.keychain.operations.results.SignEncryptResult;
import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.PgpSecurityConstants; import org.sufficientlysecure.keychain.pgp.PgpSecurityConstants;
import org.sufficientlysecure.keychain.pgp.SignEncryptParcel; import org.sufficientlysecure.keychain.pgp.SignEncryptParcel;
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.ui.adapter.SpacesItemDecoration; import org.sufficientlysecure.keychain.ui.adapter.SpacesItemDecoration;
import org.sufficientlysecure.keychain.ui.base.CachingCryptoOperationFragment; import org.sufficientlysecure.keychain.ui.base.CachingCryptoOperationFragment;
@@ -466,7 +466,7 @@ public class EncryptFilesFragment
String targetName = (mEncryptFilenames String targetName = (mEncryptFilenames
? String.valueOf(filenameCounter) : FileHelper.getFilename(getActivity(), model.inputUri)) ? String.valueOf(filenameCounter) : FileHelper.getFilename(getActivity(), model.inputUri))
+ (mUseArmor ? Constants.FILE_EXTENSION_ASC : Constants.FILE_EXTENSION_PGP_MAIN); + (mUseArmor ? Constants.FILE_EXTENSION_ASC : Constants.FILE_EXTENSION_PGP_MAIN);
mOutputUris.add(TemporaryStorageProvider.createFile(getActivity(), targetName)); mOutputUris.add(TemporaryFileProvider.createFile(getActivity(), targetName));
filenameCounter++; filenameCounter++;
} }
return false; return false;
@@ -489,7 +489,7 @@ public class EncryptFilesFragment
String targetName = (mEncryptFilenames String targetName = (mEncryptFilenames
? String.valueOf(1) : FileHelper.getFilename(getActivity(), ? String.valueOf(1) : FileHelper.getFilename(getActivity(),
mFilesAdapter.getModelItem(0).inputUri)) + Constants.FILE_EXTENSION_ASC; mFilesAdapter.getModelItem(0).inputUri)) + Constants.FILE_EXTENSION_ASC;
mOutputUris.add(TemporaryStorageProvider.createFile(getActivity(), targetName, "text/plain")); mOutputUris.add(TemporaryFileProvider.createFile(getActivity(), targetName, "text/plain"));
return false; return false;
} }

View File

@@ -43,7 +43,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogEntryParcel; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogEntryParcel;
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogLevel; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogLevel;
import org.sufficientlysecure.keychain.operations.results.OperationResult.SubLogEntryParcel; import org.sufficientlysecure.keychain.operations.results.OperationResult.SubLogEntryParcel;
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider;
import org.sufficientlysecure.keychain.ui.dialog.ShareLogDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.ShareLogDialogFragment;
import org.sufficientlysecure.keychain.ui.util.FormattingUtils; import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify;
@@ -140,7 +140,7 @@ public class LogDisplayFragment extends ListFragment implements OnItemClickListe
// if there is no log temp file yet, create one // if there is no log temp file yet, create one
if (mLogTempFile == null) { if (mLogTempFile == null) {
mLogTempFile = TemporaryStorageProvider.createFile(getActivity(), "openkeychain_log.txt", "text/plain"); mLogTempFile = TemporaryFileProvider.createFile(getActivity(), "openkeychain_log.txt", "text/plain");
try { try {
OutputStream outputStream = activity.getContentResolver().openOutputStream(mLogTempFile); OutputStream outputStream = activity.getContentResolver().openOutputStream(mLogTempFile);
outputStream.write(log.getBytes()); outputStream.write(log.getBytes());

View File

@@ -57,7 +57,7 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider;
import org.sufficientlysecure.keychain.ui.util.FormattingUtils; import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify;
@@ -248,8 +248,8 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements
// Bluetooth Share will convert text/plain sent via EXTRA_TEXT to HTML // Bluetooth Share will convert text/plain sent via EXTRA_TEXT to HTML
// Add replacement extra to send a text/plain file instead. // Add replacement extra to send a text/plain file instead.
try { try {
TemporaryStorageProvider shareFileProv = new TemporaryStorageProvider(); TemporaryFileProvider shareFileProv = new TemporaryFileProvider();
Uri contentUri = TemporaryStorageProvider.createFile(activity, Uri contentUri = TemporaryFileProvider.createFile(activity,
KeyFormattingUtils.convertFingerprintToHex(mFingerprint) + Constants.FILE_EXTENSION_ASC); KeyFormattingUtils.convertFingerprintToHex(mFingerprint) + Constants.FILE_EXTENSION_ASC);
BufferedWriter contentWriter = new BufferedWriter(new OutputStreamWriter( BufferedWriter contentWriter = new BufferedWriter(new OutputStreamWriter(

View File

@@ -55,7 +55,7 @@ import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow;
import org.sufficientlysecure.keychain.pgp.WrappedSignature; import org.sufficientlysecure.keychain.pgp.WrappedSignature;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider;
import org.sufficientlysecure.keychain.service.ExportKeyringParcel; import org.sufficientlysecure.keychain.service.ExportKeyringParcel;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
@@ -296,7 +296,7 @@ public class ExportTest {
PipedOutputStream pipedOutStream = new PipedOutputStream(pipedInStream); PipedOutputStream pipedOutStream = new PipedOutputStream(pipedInStream);
when(mockResolver.openOutputStream(fakePipedUri)).thenReturn(pipedOutStream); when(mockResolver.openOutputStream(fakePipedUri)).thenReturn(pipedOutStream);
when(mockResolver.openInputStream(fakePipedUri)).thenReturn(pipedInStream); when(mockResolver.openInputStream(fakePipedUri)).thenReturn(pipedInStream);
when(mockResolver.insert(eq(TemporaryStorageProvider.CONTENT_URI), any(ContentValues.class))) when(mockResolver.insert(eq(TemporaryFileProvider.CONTENT_URI), any(ContentValues.class)))
.thenReturn(fakePipedUri); .thenReturn(fakePipedUri);
fakeOutputUri = Uri.parse("content://fake/out/1"); fakeOutputUri = Uri.parse("content://fake/out/1");

View File

@@ -43,7 +43,7 @@ import org.sufficientlysecure.keychain.WorkaroundBuildConfig;
import org.sufficientlysecure.keychain.operations.InputDataOperation; import org.sufficientlysecure.keychain.operations.InputDataOperation;
import org.sufficientlysecure.keychain.operations.results.InputDataResult; import org.sufficientlysecure.keychain.operations.results.InputDataResult;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider;
import org.sufficientlysecure.keychain.service.InputDataParcel; import org.sufficientlysecure.keychain.service.InputDataParcel;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
@@ -117,7 +117,7 @@ public class InputDataOperationTest {
Uri fakeOutputUri1 = Uri.parse("content://fake/out/1"); Uri fakeOutputUri1 = Uri.parse("content://fake/out/1");
Uri fakeOutputUri2 = Uri.parse("content://fake/out/2"); Uri fakeOutputUri2 = Uri.parse("content://fake/out/2");
when(mockResolver.insert(eq(TemporaryStorageProvider.CONTENT_URI), any(ContentValues.class))) when(mockResolver.insert(eq(TemporaryFileProvider.CONTENT_URI), any(ContentValues.class)))
.thenReturn(fakeOutputUri1, fakeOutputUri2); .thenReturn(fakeOutputUri1, fakeOutputUri2);
// application which returns mockresolver // application which returns mockresolver
@@ -145,10 +145,10 @@ public class InputDataOperationTest {
ContentValues contentValues = new ContentValues(); ContentValues contentValues = new ContentValues();
contentValues.put("name", "data.txt"); contentValues.put("name", "data.txt");
contentValues.put("mimetype", "text/plain"); contentValues.put("mimetype", "text/plain");
verify(mockResolver).insert(TemporaryStorageProvider.CONTENT_URI, contentValues); verify(mockResolver).insert(TemporaryFileProvider.CONTENT_URI, contentValues);
contentValues.put("name", (String) null); contentValues.put("name", (String) null);
contentValues.put("mimetype", "text/testvalue"); contentValues.put("mimetype", "text/testvalue");
verify(mockResolver).insert(TemporaryStorageProvider.CONTENT_URI, contentValues); verify(mockResolver).insert(TemporaryFileProvider.CONTENT_URI, contentValues);
// quoted-printable returns windows style line endings for some reason? // quoted-printable returns windows style line endings for some reason?
Assert.assertEquals("first part must have expected content", Assert.assertEquals("first part must have expected content",