aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain/src
diff options
context:
space:
mode:
authorDaniel Haß <mail@danielhass.de>2014-03-03 20:42:38 +0100
committerDaniel Haß <mail@danielhass.de>2014-03-03 20:42:38 +0100
commitd691d4c96548852c1797eff6426b378610b039d7 (patch)
treee244899d0cfbbfe87ed680206f323096606ef5dd /OpenPGP-Keychain/src
parentec8a3469fff2718e47f6214f5364a13d84664967 (diff)
downloadopen-keychain-d691d4c96548852c1797eff6426b378610b039d7.tar.gz
open-keychain-d691d4c96548852c1797eff6426b378610b039d7.tar.bz2
open-keychain-d691d4c96548852c1797eff6426b378610b039d7.zip
Added handling for other exceptions in the ImportListLoader.
Diffstat (limited to 'OpenPGP-Keychain/src')
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java9
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java25
-rw-r--r--OpenPGP-Keychain/src/main/res/values/strings.xml5
3 files changed, 35 insertions, 4 deletions
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java
index 009c26ce5..06925e5fa 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java
@@ -228,6 +228,15 @@ public class ImportKeysListFragment extends ListFragment implements
if(error instanceof ImportKeysListLoader.FileHasNoContent) {
AppMsg.makeText(getActivity(), R.string.error_import_file_no_content,
AppMsg.STYLE_ALERT).show();
+ } else if(error instanceof ImportKeysListLoader.NonPGPPart) {
+ AppMsg.makeText(getActivity(),
+ ((ImportKeysListLoader.NonPGPPart) error).getCount() + " " + getResources().
+ getQuantityString(R.plurals.error_import_non_pgp_part,
+ ((ImportKeysListLoader.NonPGPPart) error).getCount()),
+ new AppMsg.Style(AppMsg.LENGTH_LONG, R.color.confirm)).show();
+ } else {
+ AppMsg.makeText(getActivity(), R.string.error_generic_report_bug,
+ new AppMsg.Style(AppMsg.LENGTH_LONG, R.color.alert)).show();
}
break;
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java
index 19b17468b..98884689c 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java
@@ -20,7 +20,6 @@ package org.sufficientlysecure.keychain.ui.adapter;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.util.ArrayList;
-import java.util.List;
import org.spongycastle.openpgp.PGPKeyRing;
import org.spongycastle.openpgp.PGPObjectFactory;
@@ -33,14 +32,22 @@ import org.sufficientlysecure.keychain.util.PositionAwareInputStream;
import android.content.Context;
import android.support.v4.content.AsyncTaskLoader;
-import com.devspark.appmsg.AppMsg;
-
public class ImportKeysListLoader extends AsyncTaskLoader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> {
public static class FileHasNoContent extends Exception {
}
+ public static class NonPGPPart extends Exception {
+ private int count;
+ public NonPGPPart(int count) {
+ this.count = count;
+ }
+ public int getCount() {
+ return count;
+ }
+ }
+
Context mContext;
InputData mInputData;
@@ -101,6 +108,7 @@ public class ImportKeysListLoader extends AsyncTaskLoader<AsyncTaskResultWrapper
private void generateListOfKeyrings(InputData inputData) {
boolean isEmpty = true;
+ int nonPGPcounter = 0;
PositionAwareInputStream progressIn = new PositionAwareInputStream(
inputData.getInputStream());
@@ -127,16 +135,25 @@ public class ImportKeysListLoader extends AsyncTaskLoader<AsyncTaskResultWrapper
addToData(newKeyring);
} else {
Log.e(Constants.TAG, "Object not recognized as PGPKeyRing!");
+ nonPGPcounter++;
}
}
}
} catch (Exception e) {
Log.e(Constants.TAG, "Exception on parsing key file!", e);
+ entryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(data, e);
+ nonPGPcounter = 0;
}
if(isEmpty) {
Log.e(Constants.TAG, "File has no content!", new FileHasNoContent());
- entryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(data, new FileHasNoContent());
+ entryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>
+ (data, new FileHasNoContent());
+ }
+
+ if(nonPGPcounter > 0) {
+ entryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>
+ (data, new NonPGPPart(nonPGPcounter));
}
}
diff --git a/OpenPGP-Keychain/src/main/res/values/strings.xml b/OpenPGP-Keychain/src/main/res/values/strings.xml
index e8dc05f3b..14ed7c7da 100644
--- a/OpenPGP-Keychain/src/main/res/values/strings.xml
+++ b/OpenPGP-Keychain/src/main/res/values/strings.xml
@@ -290,10 +290,15 @@
<string name="error_keyserver_query">Querying keyserver failed</string>
<string name="error_keyserver_too_many_responses">Too many responses</string>
<string name="error_import_file_no_content">File has no content</string>
+ <string name="error_generic_report_bug">A generic error occurred, please create a new bug report for OpenKeychain.</string>
<plurals name="error_can_not_delete_info">
<item quantity="one">Please delete it from the \'My Keys\' screen!</item>
<item quantity="other">Please delete them from the \'My Keys\' screen!</item>
</plurals>
+ <plurals name="error_import_non_pgp_part">
+ <item quantity="one">part of the loaded file is a valid OpenPGP object but not a OpenPGP key</item>
+ <item quantity="other">parts of the loaded file are valid OpenPGP objects but not OpenPGP keys</item>
+ </plurals>
<!-- progress dialogs, usually ending in '…' -->
<string name="progress_done">done.</string>