PgpService: feed result intent back into decryption
This commit is contained in:
parent
4596cad3cb
commit
8696cf2235
|
@ -25,13 +25,13 @@ import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
|
|
||||||
public class PgpDecryptionService {
|
public class PgpDecryptionService {
|
||||||
|
|
||||||
private final XmppConnectionService mXmppConnectionService;
|
|
||||||
private OpenPgpApi openPgpApi = null;
|
|
||||||
|
|
||||||
protected final ArrayDeque<Message> messages = new ArrayDeque();
|
protected final ArrayDeque<Message> messages = new ArrayDeque();
|
||||||
protected final HashSet<Message> pendingNotifications = new HashSet<>();
|
protected final HashSet<Message> pendingNotifications = new HashSet<>();
|
||||||
Message currentMessage;
|
private final XmppConnectionService mXmppConnectionService;
|
||||||
|
private OpenPgpApi openPgpApi = null;
|
||||||
|
private Message currentMessage;
|
||||||
private PendingIntent pendingIntent;
|
private PendingIntent pendingIntent;
|
||||||
|
private Intent userInteractionResult;
|
||||||
|
|
||||||
|
|
||||||
public PgpDecryptionService(XmppConnectionService service) {
|
public PgpDecryptionService(XmppConnectionService service) {
|
||||||
|
@ -51,7 +51,7 @@ public class PgpDecryptionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void decrypt(final List<Message> list) {
|
public synchronized void decrypt(final List<Message> list) {
|
||||||
for(Message message : list) {
|
for (Message message : list) {
|
||||||
if (message.getEncryption() == Message.ENCRYPTION_PGP) {
|
if (message.getEncryption() == Message.ENCRYPTION_PGP) {
|
||||||
messages.add(message);
|
messages.add(message);
|
||||||
}
|
}
|
||||||
|
@ -69,10 +69,10 @@ public class PgpDecryptionService {
|
||||||
this.pendingNotifications.remove(message);
|
this.pendingNotifications.remove(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void giveUpCurrentDecryption(){
|
public void giveUpCurrentDecryption() {
|
||||||
Message message;
|
Message message;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if(currentMessage != null) {
|
if (currentMessage != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
message = messages.peekFirst();
|
message = messages.peekFirst();
|
||||||
|
@ -81,7 +81,7 @@ public class PgpDecryptionService {
|
||||||
}
|
}
|
||||||
discard(message);
|
discard(message);
|
||||||
}
|
}
|
||||||
synchronized (message){
|
synchronized (message) {
|
||||||
if (message.getEncryption() == Message.ENCRYPTION_PGP) {
|
if (message.getEncryption() == Message.ENCRYPTION_PGP) {
|
||||||
message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
|
message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,12 @@ public class PgpDecryptionService {
|
||||||
continueDecryption();
|
continueDecryption();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized void continueDecryption(Intent userInteractionResult) {
|
||||||
|
this.pendingIntent = null;
|
||||||
|
this.userInteractionResult = userInteractionResult;
|
||||||
|
continueDecryption();
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void continueDecryption() {
|
public synchronized void continueDecryption() {
|
||||||
if (currentMessage == null) {
|
if (currentMessage == null) {
|
||||||
decryptNext();
|
decryptNext();
|
||||||
|
@ -126,7 +132,7 @@ public class PgpDecryptionService {
|
||||||
|
|
||||||
private void executeApi(Message message) {
|
private void executeApi(Message message) {
|
||||||
synchronized (message) {
|
synchronized (message) {
|
||||||
Intent params = new Intent();
|
Intent params = userInteractionResult != null ? userInteractionResult : new Intent();
|
||||||
params.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
|
params.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
|
||||||
if (message.getType() == Message.TYPE_TEXT) {
|
if (message.getType() == Message.TYPE_TEXT) {
|
||||||
InputStream is = new ByteArrayInputStream(message.getBody().getBytes());
|
InputStream is = new ByteArrayInputStream(message.getBody().getBytes());
|
||||||
|
@ -221,7 +227,7 @@ public class PgpDecryptionService {
|
||||||
if (pendingIntent == null) {
|
if (pendingIntent == null) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
for(Message message : messages) {
|
for (Message message : messages) {
|
||||||
if (message.getConversation() == conversation) {
|
if (message.getConversation() == conversation) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1746,7 +1746,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
|
||||||
final Intent data) {
|
final Intent data) {
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
if (requestCode == ConversationActivity.REQUEST_DECRYPT_PGP) {
|
if (requestCode == ConversationActivity.REQUEST_DECRYPT_PGP) {
|
||||||
activity.getSelectedConversation().getAccount().getPgpDecryptionService().continueDecryption(true);
|
activity.getSelectedConversation().getAccount().getPgpDecryptionService().continueDecryption(data);
|
||||||
} else if (requestCode == ConversationActivity.REQUEST_TRUST_KEYS_TEXT) {
|
} else if (requestCode == ConversationActivity.REQUEST_TRUST_KEYS_TEXT) {
|
||||||
final String body = mEditMessage.getText().toString();
|
final String body = mEditMessage.getText().toString();
|
||||||
Message message = new Message(conversation, body, conversation.getNextEncryption());
|
Message message = new Message(conversation, body, conversation.getNextEncryption());
|
||||||
|
|
Loading…
Reference in a new issue