diff options
author | Paul Gardiner <paulg.artifex@glidos.net> | 2013-08-22 15:04:18 +0100 |
---|---|---|
committer | Paul Gardiner <paulg.artifex@glidos.net> | 2013-08-27 09:53:40 +0100 |
commit | ae69f90ec82a8f19557c385c1bb25a3fb4fd5ae3 (patch) | |
tree | c620c60d892dfdc0621aef412f1cb6da4d633c88 /platform | |
parent | 57ceaf3fe8ea3c180d52d6c01b083bc293835664 (diff) | |
download | mupdf-ae69f90ec82a8f19557c385c1bb25a3fb4fd5ae3.tar.xz |
Android: add signature checking
Diffstat (limited to 'platform')
7 files changed, 125 insertions, 8 deletions
diff --git a/platform/android/jni/mupdf.c b/platform/android/jni/mupdf.c index 889abe07..a5bae5a7 100644 --- a/platform/android/jni/mupdf.c +++ b/platform/android/jni/mupdf.c @@ -42,7 +42,8 @@ enum NONE, TEXT, LISTBOX, - COMBOBOX + COMBOBOX, + SIGNATURE }; typedef struct rect_node_s rect_node; @@ -747,6 +748,7 @@ static char *widget_type_string(int t) case PDF_WIDGET_TYPE_TEXT: return "text"; case PDF_WIDGET_TYPE_LISTBOX: return "listbox"; case PDF_WIDGET_TYPE_COMBOBOX: return "combobox"; + case PDF_WIDGET_TYPE_SIGNATURE: return "signature"; default: return "non-widget"; } } @@ -2169,11 +2171,55 @@ JNI_FN(MuPDFCore_getFocusedWidgetTypeInternal)(JNIEnv * env, jobject thiz) case PDF_WIDGET_TYPE_TEXT: return TEXT; case PDF_WIDGET_TYPE_LISTBOX: return LISTBOX; case PDF_WIDGET_TYPE_COMBOBOX: return COMBOBOX; + case PDF_WIDGET_TYPE_SIGNATURE: return SIGNATURE; } return NONE; } +JNIEXPORT jboolean JNICALL +JNI_FN(MuPDFCore_getFocusedWidgetSignatureState)(JNIEnv * env, jobject thiz) +{ + globals *glo = get_globals(env, thiz); + pdf_document *idoc = pdf_specifics(glo->doc); + pdf_widget *focus; + + if (idoc == NULL) + return JNI_FALSE; + + focus = pdf_focused_widget(idoc); + + if (focus == NULL) + return JNI_FALSE; + + return pdf_dict_gets(((pdf_annot *)focus)->obj, "V") ? JNI_TRUE : JNI_FALSE; +} + +JNIEXPORT jstring JNICALL +JNI_FN(MuPDFCore_checkFocusedSignatureInternal)(JNIEnv * env, jobject thiz) +{ + globals *glo = get_globals(env, thiz); + pdf_document *idoc = pdf_specifics(glo->doc); + pdf_widget *focus; + char ebuf[256] = "Failed"; + + if (idoc == NULL) + goto exit; + + focus = pdf_focused_widget(idoc); + + if (focus == NULL) + goto exit; + + if (pdf_check_signature(idoc, focus, glo->current_path, ebuf, sizeof(ebuf))) + { + strcpy(ebuf, "Signature is valid"); + } + +exit: + return (*env)->NewStringUTF(env, ebuf); +} + JNIEXPORT jobject JNICALL JNI_FN(MuPDFCore_waitForAlertInternal)(JNIEnv * env, jobject thiz) { diff --git a/platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java b/platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java index 5590d1a1..28aecd84 100644 --- a/platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java +++ b/platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java @@ -25,7 +25,6 @@ import android.view.animation.Animation; import android.view.animation.TranslateAnimation; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; -import android.widget.Button; import android.widget.EditText; import android.widget.ImageButton; import android.widget.RelativeLayout; diff --git a/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java b/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java index e362d1e7..7b1b8e41 100644 --- a/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java +++ b/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java @@ -49,6 +49,8 @@ public class MuPDFCore private native void setFocusedWidgetChoiceSelectedInternal(String [] selected); private native String [] getFocusedWidgetChoiceSelected(); private native String [] getFocusedWidgetChoiceOptions(); + private native boolean getFocusedWidgetSignatureState(); + private native String checkFocusedSignatureInternal(); private native int setFocusedWidgetTextInternal(String text); private native String getFocusedWidgetTextInternal(); private native int getFocusedWidgetTypeInternal(); @@ -183,6 +185,8 @@ public class MuPDFCore case LISTBOX: case COMBOBOX: return new PassClickResultChoice(changed, getFocusedWidgetChoiceOptions(), getFocusedWidgetChoiceSelected()); + case SIGNATURE: + return new PassClickResultSignature(changed, getFocusedWidgetSignatureState()); default: return new PassClickResult(changed); } @@ -201,6 +205,10 @@ public class MuPDFCore setFocusedWidgetChoiceSelectedInternal(selected); } + public synchronized String checkFocusedSignature() { + return checkFocusedSignatureInternal(); + } + public synchronized LinkInfo [] getPageLinks(int page) { return getPageLinksInternal(page); } diff --git a/platform/android/src/com/artifex/mupdfdemo/MuPDFPageView.java b/platform/android/src/com/artifex/mupdfdemo/MuPDFPageView.java index 043b90ab..2cb3974b 100644 --- a/platform/android/src/com/artifex/mupdfdemo/MuPDFPageView.java +++ b/platform/android/src/com/artifex/mupdfdemo/MuPDFPageView.java @@ -17,6 +17,7 @@ import android.widget.EditText; abstract class PassClickResultVisitor { public abstract void visitText(PassClickResultText result); public abstract void visitChoice(PassClickResultChoice result); + public abstract void visitSignature(PassClickResultSignature result); } class PassClickResult { @@ -58,6 +59,19 @@ class PassClickResultChoice extends PassClickResult { } } +class PassClickResultSignature extends PassClickResult { + public final boolean isSigned; + + public PassClickResultSignature(boolean _changed, boolean _isSigned) { + super(_changed); + isSigned = _isSigned; + } + + public void acceptVisitor(PassClickResultVisitor visitor) { + visitor.visitSignature(this); + } +} + public class MuPDFPageView extends PageView implements MuPDFView { private final MuPDFCore mCore; private AsyncTask<Void,Void,PassClickResult> mPassClick; @@ -68,6 +82,8 @@ public class MuPDFPageView extends PageView implements MuPDFView { private AsyncTask<Void,Void,Annotation[]> mLoadAnnotations; private AlertDialog.Builder mTextEntryBuilder; private AlertDialog.Builder mChoiceEntryBuilder; + private AlertDialog.Builder mSigningDialogBuilder; + private AlertDialog.Builder mSignatureReportBuilder; private AlertDialog mTextEntry; private EditText mEditText; private AsyncTask<String,Void,Boolean> mSetWidgetText; @@ -75,6 +91,7 @@ public class MuPDFPageView extends PageView implements MuPDFView { private AsyncTask<PointF[],Void,Void> mAddStrikeOut; private AsyncTask<PointF[][],Void,Void> mAddInk; private AsyncTask<Integer,Void,Void> mDeleteAnnotation; + private AsyncTask<Void,Void,String> mCheckSignature; private Runnable changeReporter; public MuPDFPageView(Context c, MuPDFCore core, Point parentSize) { @@ -112,6 +129,24 @@ public class MuPDFPageView extends PageView implements MuPDFView { mChoiceEntryBuilder = new AlertDialog.Builder(c); mChoiceEntryBuilder.setTitle(getContext().getString(R.string.choose_value)); + + mSigningDialogBuilder = new AlertDialog.Builder(c); + mSigningDialogBuilder.setTitle("Select certificate and sign?"); + mSigningDialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + + }); + mSignatureReportBuilder = new AlertDialog.Builder(c); + mSignatureReportBuilder.setTitle("Signature checked"); + mSignatureReportBuilder.setPositiveButton(R.string.okay, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); } public LinkInfo hitLink(float x, float y) { @@ -160,6 +195,28 @@ public class MuPDFPageView extends PageView implements MuPDFView { dialog.show(); } + private void invokeSignatureCheckingDialog() { + mCheckSignature = new AsyncTask<Void,Void,String> () { + @Override + protected String doInBackground(Void... params) { + return mCore.checkFocusedSignature(); + } + @Override + protected void onPostExecute(String result) { + AlertDialog report = mSignatureReportBuilder.create(); + report.setMessage(result); + report.show(); + } + }; + + mCheckSignature.execute(); + } + + private void invokeSigningDialog() { + AlertDialog dialog = mSigningDialogBuilder.create(); + dialog.show(); + } + public void setChangeReporter(Runnable reporter) { changeReporter = reporter; } @@ -227,6 +284,14 @@ public class MuPDFPageView extends PageView implements MuPDFView { public void visitChoice(PassClickResultChoice result) { invokeChoiceDialog(result.options); } + + @Override + public void visitSignature(PassClickResultSignature result) { + if (result.isSigned) + invokeSignatureCheckingDialog(); + else + invokeSigningDialog(); + } }); } }; diff --git a/platform/android/src/com/artifex/mupdfdemo/ReaderView.java b/platform/android/src/com/artifex/mupdfdemo/ReaderView.java index f4f54722..9ec572a3 100644 --- a/platform/android/src/com/artifex/mupdfdemo/ReaderView.java +++ b/platform/android/src/com/artifex/mupdfdemo/ReaderView.java @@ -482,10 +482,10 @@ public class ReaderView if (!mScaling) mGestureDetector.onTouchEvent(event); - if ((event.getAction() & event.ACTION_MASK) == MotionEvent.ACTION_DOWN) { + if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { mUserInteracting = true; } - if ((event.getAction() & event.ACTION_MASK) == MotionEvent.ACTION_UP) { + if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { mScrollDisabled = false; mUserInteracting = false; diff --git a/platform/android/src/com/artifex/mupdfdemo/SafeAnimatorInflater.java b/platform/android/src/com/artifex/mupdfdemo/SafeAnimatorInflater.java index 7c6a7ebc..7f715bb4 100644 --- a/platform/android/src/com/artifex/mupdfdemo/SafeAnimatorInflater.java +++ b/platform/android/src/com/artifex/mupdfdemo/SafeAnimatorInflater.java @@ -1,12 +1,10 @@ package com.artifex.mupdfdemo; import android.animation.Animator; -import android.view.View; -import android.view.animation.Animation; import android.animation.AnimatorInflater; import android.animation.AnimatorSet; -import android.view.View; import android.app.Activity; +import android.view.View; public class SafeAnimatorInflater { diff --git a/platform/android/src/com/artifex/mupdfdemo/WidgetType.java b/platform/android/src/com/artifex/mupdfdemo/WidgetType.java index 5a22975d..882a38f2 100644 --- a/platform/android/src/com/artifex/mupdfdemo/WidgetType.java +++ b/platform/android/src/com/artifex/mupdfdemo/WidgetType.java @@ -4,5 +4,6 @@ public enum WidgetType { NONE, TEXT, LISTBOX, - COMBOBOX + COMBOBOX, + SIGNATURE } |