fix decrypt view intents, save mimetype in storage provider, and thumbnail loading in decrypt list
This commit is contained in:
@@ -18,6 +18,12 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.provider;
|
package org.sufficientlysecure.keychain.provider;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import android.content.ClipDescription;
|
import android.content.ClipDescription;
|
||||||
import android.content.ContentProvider;
|
import android.content.ContentProvider;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
@@ -29,6 +35,7 @@ import android.database.sqlite.SQLiteDatabase;
|
|||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.CancellationSignal;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.provider.OpenableColumns;
|
import android.provider.OpenableColumns;
|
||||||
|
|
||||||
@@ -36,11 +43,6 @@ import org.sufficientlysecure.keychain.Constants;
|
|||||||
import org.sufficientlysecure.keychain.util.DatabaseUtil;
|
import org.sufficientlysecure.keychain.util.DatabaseUtil;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class TemporaryStorageProvider extends ContentProvider {
|
public class TemporaryStorageProvider extends ContentProvider {
|
||||||
|
|
||||||
private static final String DB_NAME = "tempstorage.db";
|
private static final String DB_NAME = "tempstorage.db";
|
||||||
@@ -73,6 +75,12 @@ public class TemporaryStorageProvider extends ContentProvider {
|
|||||||
return context.getContentResolver().insert(BASE_URI, contentValues);
|
return context.getContentResolver().insert(BASE_URI, contentValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int setMimeType(Context context, Uri uri, String mimetype) {
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(COLUMN_TYPE, mimetype);
|
||||||
|
return context.getContentResolver().update(uri, values, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
public static int cleanUp(Context context) {
|
public static int cleanUp(Context context) {
|
||||||
return context.getContentResolver().delete(BASE_URI, COLUMN_TIME + "< ?",
|
return context.getContentResolver().delete(BASE_URI, COLUMN_TIME + "< ?",
|
||||||
new String[]{Long.toString(System.currentTimeMillis() - Constants.TEMPFILE_TTL)});
|
new String[]{Long.toString(System.currentTimeMillis() - Constants.TEMPFILE_TTL)});
|
||||||
@@ -218,12 +226,6 @@ public class TemporaryStorageProvider extends ContentProvider {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int setMimeType(Uri uri, String mimetype) {
|
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
values.put(COLUMN_TYPE, mimetype);
|
|
||||||
return update(uri, values, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@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(COLUMN_TYPE)) {
|
||||||
@@ -240,4 +242,5 @@ public class TemporaryStorageProvider extends ContentProvider {
|
|||||||
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
|
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
|
||||||
return openFileHelper(uri, mode);
|
return openFileHelper(uri, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,10 +25,14 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.ClipDescription;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.LabeledIntent;
|
import android.content.pm.LabeledIntent;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Point;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
@@ -270,12 +274,54 @@ public class DecryptListFragment
|
|||||||
|
|
||||||
private void processResult(final Uri uri, final DecryptVerifyResult result) {
|
private void processResult(final Uri uri, final DecryptVerifyResult result) {
|
||||||
|
|
||||||
Drawable icon = null;
|
new AsyncTask<Void, Void, Drawable>() {
|
||||||
OnClickListener onFileClick = null, onKeyClick = null;
|
@Override
|
||||||
|
protected Drawable doInBackground(Void... params) {
|
||||||
|
|
||||||
if (result.getDecryptMetadata() != null && result.getDecryptMetadata().getMimeType() != null) {
|
Context context = getActivity();
|
||||||
icon = loadIcon(result.getDecryptMetadata().getMimeType());
|
if (result.getDecryptMetadata() == null || context == null) {
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String type = result.getDecryptMetadata().getMimeType();
|
||||||
|
Uri outputUri = mOutputUris.get(uri);
|
||||||
|
if (type == null || outputUri == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
TemporaryStorageProvider.setMimeType(context, outputUri, type);
|
||||||
|
|
||||||
|
if (ClipDescription.compareMimeTypes(type, "image/*")) {
|
||||||
|
int px = FormattingUtils.dpToPx(context, 48);
|
||||||
|
Bitmap bitmap = FileHelper.getThumbnail(context, outputUri, new Point(px, px));
|
||||||
|
return new BitmapDrawable(context.getResources(), bitmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
|
intent.setType(type);
|
||||||
|
|
||||||
|
final List<ResolveInfo> matches =
|
||||||
|
context.getPackageManager().queryIntentActivities(intent, 0);
|
||||||
|
//noinspection LoopStatementThatDoesntLoop
|
||||||
|
for (ResolveInfo match : matches) {
|
||||||
|
return match.loadIcon(getActivity().getPackageManager());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Drawable icon) {
|
||||||
|
processResult(uri, result, icon);
|
||||||
|
}
|
||||||
|
}.execute();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processResult(final Uri uri, DecryptVerifyResult result, Drawable icon) {
|
||||||
|
|
||||||
|
OnClickListener onFileClick = null, onKeyClick = null;
|
||||||
|
|
||||||
OpenPgpSignatureResult sigResult = result.getSignatureResult();
|
OpenPgpSignatureResult sigResult = result.getSignatureResult();
|
||||||
if (sigResult != null) {
|
if (sigResult != null) {
|
||||||
@@ -300,7 +346,7 @@ public class DecryptListFragment
|
|||||||
onFileClick = new OnClickListener() {
|
onFileClick = new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
displayUri(uri);
|
displayWithViewIntent(uri);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -309,7 +355,7 @@ public class DecryptListFragment
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayUri(final Uri uri) {
|
public void displayWithViewIntent(final Uri uri) {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity == null || mCurrentInputUri != null) {
|
if (activity == null || mCurrentInputUri != null) {
|
||||||
return;
|
return;
|
||||||
@@ -340,18 +386,7 @@ public class DecryptListFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
intent.putExtra(DisplayTextActivity.EXTRA_METADATA, result);
|
|
||||||
intent.setDataAndType(outputUri, "text/plain");
|
intent.setDataAndType(outputUri, "text/plain");
|
||||||
|
|
||||||
String plaintext;
|
|
||||||
try {
|
|
||||||
plaintext = FileHelper.readTextFromUri(activity, outputUri, result.getCharset());
|
|
||||||
} catch (IOException e) {
|
|
||||||
Notify.create(activity, R.string.error_preparing_data, Style.ERROR).show();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
intent.putExtra(Intent.EXTRA_TEXT, plaintext);
|
|
||||||
|
|
||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,7 +399,9 @@ public class DecryptListFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
LabeledIntent internalIntent = new LabeledIntent(
|
LabeledIntent internalIntent = new LabeledIntent(
|
||||||
new Intent(intent).setClass(activity, DisplayTextActivity.class),
|
new Intent(intent)
|
||||||
|
.setClass(activity, DisplayTextActivity.class)
|
||||||
|
.putExtra(DisplayTextActivity.EXTRA_METADATA, result),
|
||||||
BuildConfig.APPLICATION_ID, R.string.view_internal, R.drawable.ic_launcher);
|
BuildConfig.APPLICATION_ID, R.string.view_internal, R.drawable.ic_launcher);
|
||||||
|
|
||||||
Intent chooserIntent = Intent.createChooser(intent, getString(R.string.intent_show));
|
Intent chooserIntent = Intent.createChooser(intent, getString(R.string.intent_show));
|
||||||
@@ -376,20 +413,13 @@ public class DecryptListFragment
|
|||||||
|
|
||||||
}.execute();
|
}.execute();
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Intent intent = new Intent(activity, DisplayTextActivity.class);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
intent.setAction(Intent.ACTION_VIEW);
|
intent.setDataAndType(outputUri, metadata.getMimeType());
|
||||||
|
|
||||||
// put output uri as stream, and grant permission to other apps to use it
|
|
||||||
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
intent.putExtra(Intent.EXTRA_STREAM, outputUri);
|
|
||||||
intent.setType(metadata.getMimeType());
|
|
||||||
|
|
||||||
// put metadata, although this is not likely to be used
|
|
||||||
intent.putExtra(DisplayTextActivity.EXTRA_METADATA, result);
|
|
||||||
|
|
||||||
Intent chooserIntent = Intent.createChooser(intent, getString(R.string.intent_show));
|
Intent chooserIntent = Intent.createChooser(intent, getString(R.string.intent_show));
|
||||||
|
chooserIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
activity.startActivity(chooserIntent);
|
activity.startActivity(chooserIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -763,18 +793,4 @@ public class DecryptListFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Drawable loadIcon(String mimeType) {
|
|
||||||
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
||||||
intent.setType(mimeType);
|
|
||||||
|
|
||||||
final List<ResolveInfo> matches = getActivity()
|
|
||||||
.getPackageManager().queryIntentActivities(intent, 0);
|
|
||||||
//noinspection LoopStatementThatDoesntLoop
|
|
||||||
for (ResolveInfo match : matches) {
|
|
||||||
return match.loadIcon(getActivity().getPackageManager());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
package org.sufficientlysecure.keychain.ui;
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -31,6 +33,9 @@ import org.sufficientlysecure.keychain.R;
|
|||||||
import org.sufficientlysecure.keychain.intents.OpenKeychainIntents;
|
import org.sufficientlysecure.keychain.intents.OpenKeychainIntents;
|
||||||
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
||||||
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
|
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
|
||||||
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
|
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||||
|
import org.sufficientlysecure.keychain.util.FileHelper;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
public class DisplayTextActivity extends BaseActivity {
|
public class DisplayTextActivity extends BaseActivity {
|
||||||
@@ -66,15 +71,19 @@ public class DisplayTextActivity extends BaseActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(Constants.TAG, "ACTION_DECRYPT_TEXT");
|
|
||||||
|
|
||||||
DecryptVerifyResult result = intent.getParcelableExtra(EXTRA_METADATA);
|
DecryptVerifyResult result = intent.getParcelableExtra(EXTRA_METADATA);
|
||||||
String plaintext = intent.getStringExtra(Intent.EXTRA_TEXT);
|
|
||||||
|
|
||||||
if (plaintext != null && result != null) {
|
String plaintext;
|
||||||
|
try {
|
||||||
|
plaintext = FileHelper.readTextFromUri(this, intent.getData(), result.getCharset());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Toast.makeText(this, R.string.error_preparing_data, Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plaintext != null) {
|
||||||
loadFragment(plaintext, result);
|
loadFragment(plaintext, result);
|
||||||
} else {
|
} else {
|
||||||
Log.e(Constants.TAG, "Invalid data error!");
|
|
||||||
Toast.makeText(this, R.string.error_invalid_data, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, R.string.error_invalid_data, Toast.LENGTH_LONG).show();
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user