improve openkeychain error reporting
This commit is contained in:
parent
03cd176c27
commit
a3744ce4f8
|
@ -2,6 +2,8 @@ package eu.siacs.conversations.crypto;
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
import android.support.annotation.StringRes;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.openintents.openpgp.OpenPgpError;
|
import org.openintents.openpgp.OpenPgpError;
|
||||||
|
@ -39,7 +41,8 @@ public class PgpEngine {
|
||||||
|
|
||||||
private static void logError(Account account, OpenPgpError error) {
|
private static void logError(Account account, OpenPgpError error) {
|
||||||
if (error != null) {
|
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 {
|
} else {
|
||||||
Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": OpenKeychain error with no message");
|
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);
|
callback.userInputRequried(result.getParcelableExtra(OpenPgpApi.RESULT_INTENT), message);
|
||||||
break;
|
break;
|
||||||
case OpenPgpApi.RESULT_CODE_ERROR:
|
case OpenPgpApi.RESULT_CODE_ERROR:
|
||||||
logError(conversation.getAccount(), result.getParcelableExtra(OpenPgpApi.RESULT_ERROR));
|
OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
|
||||||
callback.error(R.string.openpgp_error, message);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -174,7 +185,7 @@ public class PgpEngine {
|
||||||
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
|
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
|
||||||
return 0;
|
return 0;
|
||||||
case OpenPgpApi.RESULT_CODE_ERROR:
|
case OpenPgpApi.RESULT_CODE_ERROR:
|
||||||
logError(account, (OpenPgpError) result.getParcelableExtra(OpenPgpApi.RESULT_ERROR));
|
logError(account, result.getParcelableExtra(OpenPgpApi.RESULT_ERROR));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -2537,7 +2537,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
||||||
public void error(final int error, Message message) {
|
public void error(final int error, Message message) {
|
||||||
getActivity().runOnUiThread(() -> {
|
getActivity().runOnUiThread(() -> {
|
||||||
doneSendingPgpMessage();
|
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();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,7 +121,8 @@
|
||||||
<string name="pref_confirm_messages">Confirm Messages</string>
|
<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_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="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="accept">Accept</string>
|
||||||
<string name="error">An error has occurred</string>
|
<string name="error">An error has occurred</string>
|
||||||
<string name="recording_error">Error</string>
|
<string name="recording_error">Error</string>
|
||||||
|
|
Loading…
Reference in a new issue