improve openkeychain error reporting

This commit is contained in:
Daniel Gultsch 2018-10-25 18:16:02 +02:00
parent 03cd176c27
commit a3744ce4f8
3 changed files with 18 additions and 6 deletions

View File

@ -2,6 +2,8 @@ package eu.siacs.conversations.crypto;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Parcelable;
import android.support.annotation.StringRes;
import android.util.Log;
import org.openintents.openpgp.OpenPgpError;
@ -39,7 +41,8 @@ public class PgpEngine {
private static void logError(Account account, OpenPgpError error) {
if (error != null) {
Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": OpenKeychain error '" + error.getMessage() + "' code=" + error.getErrorId());
error.describeContents();
Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": OpenKeychain error '" + error.getMessage() + "' code=" + error.getErrorId()+" class="+error.getClass().getName());
} else {
Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": OpenKeychain error with no message");
}
@ -94,8 +97,16 @@ public class PgpEngine {
callback.userInputRequried(result.getParcelableExtra(OpenPgpApi.RESULT_INTENT), message);
break;
case OpenPgpApi.RESULT_CODE_ERROR:
logError(conversation.getAccount(), result.getParcelableExtra(OpenPgpApi.RESULT_ERROR));
callback.error(R.string.openpgp_error, message);
OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
String errorMessage = error != null ? error.getMessage() : null;
@StringRes final int res;
if (errorMessage != null && errorMessage.startsWith("Bad key for encryption")) {
res = R.string.bad_key_for_encryption;
} else {
res = R.string.openpgp_error;
}
logError(conversation.getAccount(), error);
callback.error(res, message);
break;
}
});
@ -174,7 +185,7 @@ public class PgpEngine {
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
return 0;
case OpenPgpApi.RESULT_CODE_ERROR:
logError(account, (OpenPgpError) result.getParcelableExtra(OpenPgpApi.RESULT_ERROR));
logError(account, result.getParcelableExtra(OpenPgpApi.RESULT_ERROR));
return 0;
}
return 0;

View File

@ -2537,7 +2537,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
public void error(final int error, Message message) {
getActivity().runOnUiThread(() -> {
doneSendingPgpMessage();
Toast.makeText(getActivity(), R.string.unable_to_connect_to_keychain, Toast.LENGTH_SHORT).show();
Toast.makeText(getActivity(), error == 0 ? R.string.unable_to_connect_to_keychain : error, Toast.LENGTH_SHORT).show();
});
}

View File

@ -121,7 +121,8 @@
<string name="pref_confirm_messages">Confirm Messages</string>
<string name="pref_confirm_messages_summary">Let your contacts know when you have received and read their messages</string>
<string name="pref_ui_options">UI</string>
<string name="openpgp_error">OpenKeychain reported an error</string>
<string name="openpgp_error">OpenKeychain reported an error.</string>
<string name="bad_key_for_encryption">Bad key for encryption.</string>
<string name="accept">Accept</string>
<string name="error">An error has occurred</string>
<string name="recording_error">Error</string>