From 3b2bc7c15844af39ac08fe5b0a9681ba1cce2dc0 Mon Sep 17 00:00:00 2001 From: Matt Holgate Date: Thu, 3 Jul 2014 11:11:35 +0100 Subject: Android: Prevent editing of files opened from a memory buffer. Memory buffers are used for implementing content:// URLs, which are (in most cases) readonly. If we ever encounter a read/write content:// URL in the future, we could consider supporting saving to it. (An example of a content:// URI is an email attachment, where IPC is used to transfer the file from the email client, rather than relying on a local file). --- platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java | 3 ++- platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java b/platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java index 062bb03b..681ea317 100644 --- a/platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java +++ b/platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java @@ -260,6 +260,7 @@ public class MuPDFActivity extends Activity implements FilePicker.FilePickerSupp byte buffer[] = null; if (Intent.ACTION_VIEW.equals(intent.getAction())) { Uri uri = intent.getData(); + System.out.println("URI to open is: " + uri); if (uri.toString().startsWith("content://")) { String reason = null; try { @@ -492,7 +493,7 @@ public class MuPDFActivity extends Activity implements FilePicker.FilePickerSupp } }); - if (core.fileFormat().startsWith("PDF") && core.isUnencryptedPDF()) + if (core.fileFormat().startsWith("PDF") && core.isUnencryptedPDF() && !core.wasOpenedFromBuffer()) { mAnnotButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { diff --git a/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java b/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java index 0532b61d..750540b7 100644 --- a/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java +++ b/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java @@ -22,6 +22,7 @@ public class MuPDFCore private byte fileBuffer[]; private String file_format; private boolean isUnencryptedPDF; + private final boolean wasOpenedFromBuffer; /* The native functions */ private native long openFile(String filename); @@ -112,6 +113,7 @@ public class MuPDFCore } file_format = fileFormatInternal(); isUnencryptedPDF = isUnencryptedPDFInternal(); + wasOpenedFromBuffer = false; } public MuPDFCore(Context context, byte buffer[], String magic) throws Exception { @@ -123,6 +125,7 @@ public class MuPDFCore } file_format = fileFormatInternal(); isUnencryptedPDF = isUnencryptedPDFInternal(); + wasOpenedFromBuffer = true; } public int countPages() @@ -143,6 +146,11 @@ public class MuPDFCore return isUnencryptedPDF; } + public boolean wasOpenedFromBuffer() + { + return wasOpenedFromBuffer; + } + private synchronized int countPagesSynchronized() { return countPagesInternal(); } -- cgit v1.2.3