mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-24 01:32:16 -05:00
Added handling for other exceptions in the ImportListLoader.
This commit is contained in:
parent
ec8a3469ff
commit
d691d4c965
@ -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;
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user