aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/ui
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-06-13 13:32:14 +0200
committerChristian Schneppe <christian@pix-art.de>2016-06-14 21:27:06 +0200
commit3e748bc49a25c2700e6929286f7041e9c571d7f3 (patch)
treea965a4b18ddebf614ce4f7ef525124fcd336e200 /src/main/java/eu/siacs/conversations/ui
parentdd3b9084af4483d6c1d27313d0d582b4e502fb00 (diff)
refactored pgp decryption
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationFragment.java89
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java4
2 files changed, 18 insertions, 75 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
index 6d304f15b..c97576db4 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
@@ -11,7 +11,6 @@ import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
import android.os.Handler;
-import android.support.annotation.Nullable;
import android.text.InputType;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
@@ -212,49 +211,25 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
return -1;
}
-
- private final int KEYCHAIN_UNLOCK_NOT_REQUIRED = 0;
- private final int KEYCHAIN_UNLOCK_REQUIRED = 1;
- private final int KEYCHAIN_UNLOCK_PENDING = 2;
- private int keychainUnlock = KEYCHAIN_UNLOCK_NOT_REQUIRED;
protected OnClickListener clickToDecryptListener = new OnClickListener() {
@Override
public void onClick(View v) {
- if (keychainUnlock == KEYCHAIN_UNLOCK_REQUIRED
- && activity.hasPgp() && !conversation.getAccount().getPgpDecryptionService().isRunning()) {
- keychainUnlock = KEYCHAIN_UNLOCK_PENDING;
- updateSnackBar(conversation);
- Message message = getLastPgpDecryptableMessage();
- if (message != null) {
- activity.xmppConnectionService.getPgpEngine().decrypt(message, new UiCallback<Message>() {
- @Override
- public void success(Message object) {
- conversation.getAccount().getPgpDecryptionService().onKeychainUnlocked();
- keychainUnlock = KEYCHAIN_UNLOCK_NOT_REQUIRED;
- }
-
- @Override
- public void error(int errorCode, Message object) {
- keychainUnlock = KEYCHAIN_UNLOCK_NOT_REQUIRED;
- }
-
- @Override
- public void userInputRequried(PendingIntent pi, Message object) {
- try {
- activity.startIntentSenderForResult(pi.getIntentSender(),
- ConversationActivity.REQUEST_DECRYPT_PGP, null, 0, 0, 0);
- } catch (SendIntentException e) {
- keychainUnlock = KEYCHAIN_UNLOCK_NOT_REQUIRED;
- updatePgpMessages();
- }
- }
- });
+ PendingIntent pendingIntent = conversation.getAccount().getPgpDecryptionService().getPendingIntent();
+ if (pendingIntent != null) {
+ try {
+ activity.startIntentSenderForResult(pendingIntent.getIntentSender(),
+ ConversationActivity.REQUEST_DECRYPT_PGP,
+ null,
+ 0,
+ 0,
+ 0);
+ } catch (SendIntentException e) {
+ Toast.makeText(activity,R.string.unable_to_connect_to_keychain, Toast.LENGTH_SHORT).show();
+ conversation.getAccount().getPgpDecryptionService().continueDecryption(true);
}
- } else {
- keychainUnlock = KEYCHAIN_UNLOCK_NOT_REQUIRED;
- updatePgpMessages();
}
+ updateSnackBar(conversation);
}
};
protected OnClickListener clickToVerify = new OnClickListener() {
@@ -731,7 +706,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
message.setEncryption(Message.ENCRYPTION_PGP);
activity.updateConversationList();
updateMessages();
- conversation.getAccount().getPgpDecryptionService().add(message);
+ conversation.getAccount().getPgpDecryptionService().decrypt(message);
}
protected void privateMessageWith(final Jid counterpart) {
@@ -798,7 +773,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
this.conversation.trim();
}
- this.keychainUnlock = KEYCHAIN_UNLOCK_NOT_REQUIRED;
this.conversation = conversation;
boolean canWrite = this.conversation.getMode() == Conversation.MODE_SINGLE || this.conversation.getMucOptions().participating();
this.mEditMessage.setEnabled(canWrite);
@@ -918,7 +892,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
default:
break;
}
- } else if (keychainUnlock == KEYCHAIN_UNLOCK_REQUIRED) {
+ } else if (account.hasPendingPgpIntent(conversation)) {
showSnackbar(R.string.openpgp_messages_found, R.string.decrypt, clickToDecryptListener);
} else if (mode == Conversation.MODE_SINGLE
&& conversation.smpRequested()) {
@@ -941,7 +915,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
final ConversationActivity activity = (ConversationActivity) getActivity();
if (this.conversation != null) {
conversation.populateWithMessages(ConversationFragment.this.messageList);
- updatePgpMessages();
updateSnackBar(conversation);
updateStatusMessages();
this.messageListAdapter.notifyDataSetChanged();
@@ -954,29 +927,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
}
- public void updatePgpMessages() {
- if (keychainUnlock != KEYCHAIN_UNLOCK_PENDING) {
- if (getLastPgpDecryptableMessage() != null
- && !conversation.getAccount().getPgpDecryptionService().isRunning()) {
- keychainUnlock = KEYCHAIN_UNLOCK_REQUIRED;
- } else {
- keychainUnlock = KEYCHAIN_UNLOCK_NOT_REQUIRED;
- }
- }
- }
-
- @Nullable
- private Message getLastPgpDecryptableMessage() {
- for (final Message message : this.messageList) {
- if (message.getEncryption() == Message.ENCRYPTION_PGP
- && (message.getStatus() == Message.STATUS_RECEIVED || message.getStatus() >= Message.STATUS_SEND)
- && message.getTransferable() == null) {
- return message;
- }
- }
- return null;
- }
-
private void messageSent() {
mEditMessage.setText("");
updateChatMsgHint();
@@ -1433,9 +1383,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
final Intent data) {
if (resultCode == Activity.RESULT_OK) {
if (requestCode == ConversationActivity.REQUEST_DECRYPT_PGP) {
- activity.getSelectedConversation().getAccount().getPgpDecryptionService().onKeychainUnlocked();
- keychainUnlock = KEYCHAIN_UNLOCK_NOT_REQUIRED;
- updatePgpMessages();
+ activity.getSelectedConversation().getAccount().getPgpDecryptionService().continueDecryption(true);
} else if (requestCode == ConversationActivity.REQUEST_TRUST_KEYS_TEXT) {
final String body = mEditMessage.getText().toString();
Message message = new Message(conversation, body, conversation.getNextEncryption());
@@ -1444,11 +1392,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
int choice = data.getIntExtra("choice", ConversationActivity.ATTACHMENT_CHOICE_INVALID);
activity.selectPresenceToAttachFile(choice, conversation.getNextEncryption());
}
- } else {
- if (requestCode == ConversationActivity.REQUEST_DECRYPT_PGP) {
- keychainUnlock = KEYCHAIN_UNLOCK_NOT_REQUIRED;
- updatePgpMessages();
- }
}
}
diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
index a2e440628..e5f7a529f 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
@@ -698,8 +698,8 @@ public class MessageAdapter extends ArrayAdapter<Message> {
} else displayOpenableMessage(viewHolder, message);
}
} else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
- if (activity.hasPgp()) {
- if (account.getPgpDecryptionService().isRunning()) {
+ if (account.isPgpDecryptionServiceConnected()) {
+ if (!account.hasPendingPgpIntent(conversation)) {
displayInfoMessage(viewHolder, activity.getString(R.string.message_decrypting), darkBackground);
} else {
displayInfoMessage(viewHolder, activity.getString(R.string.pgp_message), darkBackground);