summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Holgate <matt@emobix.co.uk>2014-07-03 11:11:35 +0100
committerMatt Holgate <matt@emobix.co.uk>2014-07-03 11:11:35 +0100
commit3b2bc7c15844af39ac08fe5b0a9681ba1cce2dc0 (patch)
tree452d0e9d2167618fa301adda1ab20650e6a456d9
parent4f9f55bf8176ffbe75c958a93e1cc47c70f50e89 (diff)
downloadmupdf-3b2bc7c15844af39ac08fe5b0a9681ba1cce2dc0.tar.xz
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).
-rw-r--r--platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java3
-rw-r--r--platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java8
2 files changed, 10 insertions, 1 deletions
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();
}