Merge pull request #316 from danielhass/import-error
Show error if file import has no content
This commit is contained in:
@@ -219,27 +219,44 @@ public class ImportKeysListFragment extends ListFragment implements
|
|||||||
} else {
|
} else {
|
||||||
setListShownNoAnimation(true);
|
setListShownNoAnimation(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Exception error = data.getError();
|
||||||
|
|
||||||
switch (loader.getId()) {
|
switch (loader.getId()) {
|
||||||
case LOADER_ID_BYTES:
|
case LOADER_ID_BYTES:
|
||||||
|
|
||||||
|
if(error == null){
|
||||||
|
// No error
|
||||||
|
} else 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;
|
break;
|
||||||
|
|
||||||
case LOADER_ID_SERVER_QUERY:
|
case LOADER_ID_SERVER_QUERY:
|
||||||
|
|
||||||
Exception error = data.getError();
|
if(error == null) {
|
||||||
|
|
||||||
if(error == null){
|
|
||||||
AppMsg.makeText(
|
AppMsg.makeText(
|
||||||
getActivity(), getResources().getQuantityString(R.plurals.keys_found,
|
getActivity(), getResources().getQuantityString(R.plurals.keys_found,
|
||||||
mAdapter.getCount(), mAdapter.getCount()),
|
mAdapter.getCount(), mAdapter.getCount()),
|
||||||
AppMsg.STYLE_INFO
|
AppMsg.STYLE_INFO
|
||||||
).show();
|
).show();
|
||||||
} else if(error instanceof KeyServer.InsufficientQuery){
|
} else if(error instanceof KeyServer.InsufficientQuery) {
|
||||||
AppMsg.makeText(getActivity(), R.string.error_keyserver_insufficient_query,
|
AppMsg.makeText(getActivity(), R.string.error_keyserver_insufficient_query,
|
||||||
AppMsg.STYLE_ALERT).show();
|
AppMsg.STYLE_ALERT).show();
|
||||||
}else if(error instanceof KeyServer.QueryException){
|
} else if(error instanceof KeyServer.QueryException) {
|
||||||
AppMsg.makeText(getActivity(), R.string.error_keyserver_query,
|
AppMsg.makeText(getActivity(), R.string.error_keyserver_query,
|
||||||
AppMsg.STYLE_ALERT).show();
|
AppMsg.STYLE_ALERT).show();
|
||||||
}else if(error instanceof KeyServer.TooManyResponses){
|
} else if(error instanceof KeyServer.TooManyResponses) {
|
||||||
AppMsg.makeText(getActivity(), R.string.error_keyserver_too_many_responses,
|
AppMsg.makeText(getActivity(), R.string.error_keyserver_too_many_responses,
|
||||||
AppMsg.STYLE_ALERT).show();
|
AppMsg.STYLE_ALERT).show();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,21 @@ import android.content.Context;
|
|||||||
import android.support.v4.content.AsyncTaskLoader;
|
import android.support.v4.content.AsyncTaskLoader;
|
||||||
|
|
||||||
public class ImportKeysListLoader extends AsyncTaskLoader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> {
|
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;
|
Context mContext;
|
||||||
|
|
||||||
InputData mInputData;
|
InputData mInputData;
|
||||||
@@ -91,6 +106,10 @@ public class ImportKeysListLoader extends AsyncTaskLoader<AsyncTaskResultWrapper
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private void generateListOfKeyrings(InputData inputData) {
|
private void generateListOfKeyrings(InputData inputData) {
|
||||||
|
|
||||||
|
boolean isEmpty = true;
|
||||||
|
int nonPgpCounter = 0;
|
||||||
|
|
||||||
PositionAwareInputStream progressIn = new PositionAwareInputStream(
|
PositionAwareInputStream progressIn = new PositionAwareInputStream(
|
||||||
inputData.getInputStream());
|
inputData.getInputStream());
|
||||||
|
|
||||||
@@ -102,6 +121,7 @@ public class ImportKeysListLoader extends AsyncTaskLoader<AsyncTaskResultWrapper
|
|||||||
|
|
||||||
// read all available blocks... (asc files can contain many blocks with BEGIN END)
|
// read all available blocks... (asc files can contain many blocks with BEGIN END)
|
||||||
while (bufferedInput.available() > 0) {
|
while (bufferedInput.available() > 0) {
|
||||||
|
isEmpty = false;
|
||||||
InputStream in = PGPUtil.getDecoderStream(bufferedInput);
|
InputStream in = PGPUtil.getDecoderStream(bufferedInput);
|
||||||
PGPObjectFactory objectFactory = new PGPObjectFactory(in);
|
PGPObjectFactory objectFactory = new PGPObjectFactory(in);
|
||||||
|
|
||||||
@@ -115,11 +135,25 @@ public class ImportKeysListLoader extends AsyncTaskLoader<AsyncTaskResultWrapper
|
|||||||
addToData(newKeyring);
|
addToData(newKeyring);
|
||||||
} else {
|
} else {
|
||||||
Log.e(Constants.TAG, "Object not recognized as PGPKeyRing!");
|
Log.e(Constants.TAG, "Object not recognized as PGPKeyRing!");
|
||||||
|
nonPgpCounter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(Constants.TAG, "Exception on parsing key file!", 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(nonPgpCounter > 0) {
|
||||||
|
entryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>
|
||||||
|
(data, new NonPgpPart(nonPgpCounter));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -296,10 +296,16 @@
|
|||||||
<string name="error_keyserver_insufficient_query">Insufficient server query</string>
|
<string name="error_keyserver_insufficient_query">Insufficient server query</string>
|
||||||
<string name="error_keyserver_query">Querying keyserver failed</string>
|
<string name="error_keyserver_query">Querying keyserver failed</string>
|
||||||
<string name="error_keyserver_too_many_responses">Too many responses</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">
|
<plurals name="error_can_not_delete_info">
|
||||||
<item quantity="one">Please delete it from the \'My Keys\' screen!</item>
|
<item quantity="one">Please delete it from the \'My Keys\' screen!</item>
|
||||||
<item quantity="other">Please delete them from the \'My Keys\' screen!</item>
|
<item quantity="other">Please delete them from the \'My Keys\' screen!</item>
|
||||||
</plurals>
|
</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 '…' -->
|
<!-- progress dialogs, usually ending in '…' -->
|
||||||
<string name="progress_done">done.</string>
|
<string name="progress_done">done.</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user