1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 05:02:26 -05:00

Don't use dummy file path when resolving intents

This commit is contained in:
cketti 2014-11-18 23:02:20 +01:00
parent d9b6e10cbe
commit 56c30095e2
2 changed files with 11 additions and 9 deletions

View File

@ -15,7 +15,13 @@ public class TemporaryAttachmentStore {
private static String TEMPORARY_ATTACHMENT_DIRECTORY = "attachments"; private static String TEMPORARY_ATTACHMENT_DIRECTORY = "attachments";
private static long MAX_FILE_AGE = 12 * 60 * 60 * 1000; // 12h private static long MAX_FILE_AGE = 12 * 60 * 60 * 1000; // 12h
public static File getFile(Context context, String attachmentName) throws IOException { public static File getFile(Context context, String attachmentName) {
File directory = getTemporaryAttachmentDirectory(context);
String filename = FileHelper.sanitizeFilename(attachmentName);
return new File(directory, filename);
}
public static File getFileForWriting(Context context, String attachmentName) throws IOException {
File directory = createOrCleanAttachmentDirectory(context); File directory = createOrCleanAttachmentDirectory(context);
String filename = FileHelper.sanitizeFilename(attachmentName); String filename = FileHelper.sanitizeFilename(attachmentName);
return new File(directory, filename); return new File(directory, filename);

View File

@ -286,7 +286,7 @@ public class AttachmentView extends FrameLayout implements OnClickListener, OnLo
Intent viewIntent; Intent viewIntent;
if (resolvedIntentInfo.hasResolvedActivities() && resolvedIntentInfo.containsFileUri()) { if (resolvedIntentInfo.hasResolvedActivities() && resolvedIntentInfo.containsFileUri()) {
try { try {
File tempFile = TemporaryAttachmentStore.getFile(context, name); File tempFile = TemporaryAttachmentStore.getFileForWriting(context, name);
writeAttachmentToStorage(tempFile); writeAttachmentToStorage(tempFile);
viewIntent = createViewIntentForFileUri(resolvedIntentInfo.getMimeType(), Uri.fromFile(tempFile)); viewIntent = createViewIntentForFileUri(resolvedIntentInfo.getMimeType(), Uri.fromFile(tempFile));
} catch (IOException e) { } catch (IOException e) {
@ -310,8 +310,9 @@ public class AttachmentView extends FrameLayout implements OnClickListener, OnLo
return new IntentAndResolvedActivitiesCount(contentUriIntent, contentUriActivitiesCount); return new IntentAndResolvedActivitiesCount(contentUriIntent, contentUriActivitiesCount);
} }
Uri dummyFileUri = getDummyFileUri(); File tempFile = TemporaryAttachmentStore.getFile(context, name);
Intent fileUriIntent = createViewIntentForFileUri(mimeType, dummyFileUri); Uri tempFileUri = Uri.fromFile(tempFile);
Intent fileUriIntent = createViewIntentForFileUri(mimeType, tempFileUri);
int fileUriActivitiesCount = getResolvedIntentActivitiesCount(fileUriIntent); int fileUriActivitiesCount = getResolvedIntentActivitiesCount(fileUriIntent);
if (fileUriActivitiesCount > 0) { if (fileUriActivitiesCount > 0) {
@ -321,11 +322,6 @@ public class AttachmentView extends FrameLayout implements OnClickListener, OnLo
return new IntentAndResolvedActivitiesCount(contentUriIntent, contentUriActivitiesCount); return new IntentAndResolvedActivitiesCount(contentUriIntent, contentUriActivitiesCount);
} }
private Uri getDummyFileUri() {
File dummyFile = new File(FileHelper.sanitizeFilename(name));
return Uri.fromFile(dummyFile);
}
private Intent createViewIntentForAttachmentProviderUri(String mimeType) { private Intent createViewIntentForAttachmentProviderUri(String mimeType) {
Uri uri = AttachmentProvider.getAttachmentUriForViewing(account, part.getAttachmentId(), mimeType, name); Uri uri = AttachmentProvider.getAttachmentUriForViewing(account, part.getAttachmentId(), mimeType, name);