add more logging to pgp engine

This commit is contained in:
Daniel Gultsch 2016-08-30 13:12:09 +02:00
parent b747afb44c
commit af329eff46
2 changed files with 21 additions and 16 deletions

View File

@ -4,6 +4,7 @@ import android.app.PendingIntent;
import android.content.Intent; import android.content.Intent;
import android.util.Log; import android.util.Log;
import org.openintents.openpgp.OpenPgpError;
import org.openintents.openpgp.OpenPgpSignatureResult; import org.openintents.openpgp.OpenPgpSignatureResult;
import org.openintents.openpgp.util.OpenPgpApi; import org.openintents.openpgp.util.OpenPgpApi;
import org.openintents.openpgp.util.OpenPgpApi.IOpenPgpCallback; import org.openintents.openpgp.util.OpenPgpApi.IOpenPgpCallback;
@ -15,7 +16,6 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URL;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
@ -24,7 +24,6 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.DownloadableFile; import eu.siacs.conversations.entities.DownloadableFile;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.http.HttpConnectionManager;
import eu.siacs.conversations.persistance.FileBackend; import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.ui.UiCallback; import eu.siacs.conversations.ui.UiCallback;
@ -92,6 +91,7 @@ public class PgpEngine {
message); message);
break; break;
case OpenPgpApi.RESULT_CODE_ERROR: case OpenPgpApi.RESULT_CODE_ERROR:
logError(conversation.getAccount(), (OpenPgpError) result.getParcelableExtra(OpenPgpApi.RESULT_ERROR));
callback.error(R.string.openpgp_error, message); callback.error(R.string.openpgp_error, message);
break; break;
} }
@ -129,6 +129,7 @@ public class PgpEngine {
message); message);
break; break;
case OpenPgpApi.RESULT_CODE_ERROR: case OpenPgpApi.RESULT_CODE_ERROR:
logError(conversation.getAccount(), (OpenPgpError) result.getParcelableExtra(OpenPgpApi.RESULT_ERROR));
callback.error(R.string.openpgp_error, message); callback.error(R.string.openpgp_error, message);
break; break;
} }
@ -178,6 +179,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));
return 0; return 0;
} }
return 0; return 0;
@ -200,6 +202,7 @@ public class PgpEngine {
account); account);
return; return;
case OpenPgpApi.RESULT_CODE_ERROR: case OpenPgpApi.RESULT_CODE_ERROR:
logError(account, (OpenPgpError) result.getParcelableExtra(OpenPgpApi.RESULT_ERROR));
callback.error(R.string.openpgp_error, account); callback.error(R.string.openpgp_error, account);
} }
} }
@ -256,6 +259,7 @@ public class PgpEngine {
account); account);
return; return;
case OpenPgpApi.RESULT_CODE_ERROR: case OpenPgpApi.RESULT_CODE_ERROR:
logError(account, (OpenPgpError) result.getParcelableExtra(OpenPgpApi.RESULT_ERROR));
callback.error(R.string.unable_to_connect_to_keychain, account); callback.error(R.string.unable_to_connect_to_keychain, account);
} }
} }
@ -280,27 +284,30 @@ public class PgpEngine {
contact); contact);
return; return;
case OpenPgpApi.RESULT_CODE_ERROR: case OpenPgpApi.RESULT_CODE_ERROR:
logError(contact.getAccount(), (OpenPgpError) result.getParcelableExtra(OpenPgpApi.RESULT_ERROR));
callback.error(R.string.openpgp_error, contact); callback.error(R.string.openpgp_error, contact);
} }
} }
}); });
} }
public PendingIntent getIntentForKey(Contact contact) { private static void logError(Account account, OpenPgpError error) {
Intent params = new Intent(); if (error != null) {
params.setAction(OpenPgpApi.ACTION_GET_KEY); Log.d(Config.LOGTAG,account.getJid().toBareJid().toString()+": OpenKeychain error '"+error.getMessage()+"' code="+error.getErrorId());
params.putExtra(OpenPgpApi.EXTRA_KEY_ID, contact.getPgpKeyId()); } else {
Intent result = api.executeApi(params, null, null); Log.d(Config.LOGTAG,account.getJid().toBareJid().toString()+": OpenKeychain error with no message");
return (PendingIntent) result }
.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
} }
public PendingIntent getIntentForKey(Account account, long pgpKeyId) { public PendingIntent getIntentForKey(Contact contact) {
return getIntentForKey(contact.getPgpKeyId());
}
public PendingIntent getIntentForKey(long pgpKeyId) {
Intent params = new Intent(); Intent params = new Intent();
params.setAction(OpenPgpApi.ACTION_GET_KEY); params.setAction(OpenPgpApi.ACTION_GET_KEY);
params.putExtra(OpenPgpApi.EXTRA_KEY_ID, pgpKeyId); params.putExtra(OpenPgpApi.EXTRA_KEY_ID, pgpKeyId);
Intent result = api.executeApi(params, null, null); Intent result = api.executeApi(params, null, null);
return (PendingIntent) result return (PendingIntent) result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
} }
} }

View File

@ -637,12 +637,10 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
private void viewPgpKey(User user) { private void viewPgpKey(User user) {
PgpEngine pgp = xmppConnectionService.getPgpEngine(); PgpEngine pgp = xmppConnectionService.getPgpEngine();
if (pgp != null) { if (pgp != null) {
PendingIntent intent = pgp.getIntentForKey( PendingIntent intent = pgp.getIntentForKey(user.getPgpKeyId());
mConversation.getAccount(), user.getPgpKeyId());
if (intent != null) { if (intent != null) {
try { try {
startIntentSenderForResult(intent.getIntentSender(), 0, startIntentSenderForResult(intent.getIntentSender(), 0, null, 0, 0, 0);
null, 0, 0, 0);
} catch (SendIntentException ignored) { } catch (SendIntentException ignored) {
} }