aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/eu/siacs/conversations/crypto/OnPgpEngineResult.java11
-rw-r--r--src/eu/siacs/conversations/crypto/PgpEngine.java137
-rw-r--r--src/eu/siacs/conversations/entities/Message.java16
-rw-r--r--src/eu/siacs/conversations/persistance/FileBackend.java12
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java48
-rw-r--r--src/eu/siacs/conversations/ui/ContactDetailsActivity.java29
-rw-r--r--src/eu/siacs/conversations/ui/ConversationActivity.java143
-rw-r--r--src/eu/siacs/conversations/ui/ConversationFragment.java65
-rw-r--r--src/eu/siacs/conversations/ui/ManageAccountActivity.java10
-rw-r--r--src/eu/siacs/conversations/ui/UiCallback.java9
-rw-r--r--src/eu/siacs/conversations/ui/XmppActivity.java32
-rw-r--r--src/eu/siacs/conversations/utils/UIHelper.java8
12 files changed, 318 insertions, 202 deletions
diff --git a/src/eu/siacs/conversations/crypto/OnPgpEngineResult.java b/src/eu/siacs/conversations/crypto/OnPgpEngineResult.java
deleted file mode 100644
index 8e115839..00000000
--- a/src/eu/siacs/conversations/crypto/OnPgpEngineResult.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package eu.siacs.conversations.crypto;
-
-import org.openintents.openpgp.OpenPgpError;
-
-import android.app.PendingIntent;
-
-public interface OnPgpEngineResult {
- public void success();
- public void error(OpenPgpError openPgpError);
- public void userInputRequried(PendingIntent pi);
-}
diff --git a/src/eu/siacs/conversations/crypto/PgpEngine.java b/src/eu/siacs/conversations/crypto/PgpEngine.java
index 5a51a1e8..48750e24 100644
--- a/src/eu/siacs/conversations/crypto/PgpEngine.java
+++ b/src/eu/siacs/conversations/crypto/PgpEngine.java
@@ -14,12 +14,13 @@ import org.openintents.openpgp.OpenPgpSignatureResult;
import org.openintents.openpgp.util.OpenPgpApi;
import org.openintents.openpgp.util.OpenPgpApi.IOpenPgpCallback;
+import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.XmppConnectionService;
+import eu.siacs.conversations.ui.UiCallback;
import eu.siacs.conversations.xmpp.jingle.JingleFile;
-
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
@@ -34,7 +35,7 @@ public class PgpEngine {
this.mXmppConnectionService = service;
}
- public void decrypt(final Message message, final OnPgpEngineResult callback) {
+ public void decrypt(final Message message, final UiCallback callback) {
Log.d("xmppService","decrypting message "+message.getUuid());
Intent params = new Intent();
params.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
@@ -59,8 +60,7 @@ public class PgpEngine {
.getParcelableExtra(OpenPgpApi.RESULT_INTENT));
return;
case OpenPgpApi.RESULT_CODE_ERROR:
- callback.error((OpenPgpError) result
- .getParcelableExtra(OpenPgpApi.RESULT_ERROR));
+ callback.error(R.string.openpgp_error);
return;
default:
return;
@@ -97,8 +97,7 @@ public class PgpEngine {
.getParcelableExtra(OpenPgpApi.RESULT_INTENT));
return;
case OpenPgpApi.RESULT_CODE_ERROR:
- callback.error((OpenPgpError) result
- .getParcelableExtra(OpenPgpApi.RESULT_ERROR));
+ callback.error(R.string.openpgp_error);
return;
default:
return;
@@ -106,67 +105,26 @@ public class PgpEngine {
}
});
} catch (FileNotFoundException e) {
- callback.error(new OpenPgpError(0, "file not found: "+e.getMessage()));
+ callback.error(R.string.error_decrypting_file);
} catch (IOException e) {
- callback.error(new OpenPgpError(0, "io exception: "+e.getMessage()));
+ callback.error(R.string.error_decrypting_file);
}
}
}
- public void encrypt(Account account, final Message message,
- final OnPgpEngineResult callback) {
+ public void encrypt(final Message message,final UiCallback callback) {
long[] keys = { message.getConversation().getContact().getPgpKeyId() };
Intent params = new Intent();
params.setAction(OpenPgpApi.ACTION_ENCRYPT);
params.putExtra(OpenPgpApi.EXTRA_KEY_IDS, keys);
- params.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
- params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, account.getJid());
-
- InputStream is = new ByteArrayInputStream(message.getBody().getBytes());
- final OutputStream os = new ByteArrayOutputStream();
- api.executeApiAsync(params, is, os, new IOpenPgpCallback() {
-
- @Override
- public void onReturn(Intent result) {
- switch (result.getIntExtra(OpenPgpApi.RESULT_CODE,
- OpenPgpApi.RESULT_CODE_ERROR)) {
- case OpenPgpApi.RESULT_CODE_SUCCESS:
- StringBuilder encryptedMessageBody = new StringBuilder();
- String[] lines = os.toString().split("\n");
- for (int i = 3; i < lines.length - 1; ++i) {
- encryptedMessageBody.append(lines[i].trim());
- }
- message.setEncryptedBody(encryptedMessageBody.toString());
- callback.success();
- break;
- case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
- callback.userInputRequried((PendingIntent) result
- .getParcelableExtra(OpenPgpApi.RESULT_INTENT));
- break;
- case OpenPgpApi.RESULT_CODE_ERROR:
- callback.error((OpenPgpError) result
- .getParcelableExtra(OpenPgpApi.RESULT_ERROR));
- break;
- }
- }
- });
+ params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, message.getConversation().getAccount().getJid());
- }
+ if (message.getType() == Message.TYPE_TEXT) {
+ params.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
- public void encrypt(final Message message, final OnPgpEngineResult callback) {
- try {
- Log.d("xmppService","calling to encrypt file");
- JingleFile inputFile = this.mXmppConnectionService.getFileBackend().getJingleFile(message, true);
- JingleFile outputFile = this.mXmppConnectionService.getFileBackend().getJingleFile(message, false);
- outputFile.createNewFile();
- long[] keys = { message.getConversation().getContact().getPgpKeyId() };
- Intent params = new Intent();
- params.setAction(OpenPgpApi.ACTION_ENCRYPT);
- params.putExtra(OpenPgpApi.EXTRA_KEY_IDS, keys);
- params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, message.getConversation().getAccount().getJid());
- InputStream is = new FileInputStream(inputFile);
- OutputStream os = new FileOutputStream(outputFile);
+ InputStream is = new ByteArrayInputStream(message.getBody().getBytes());
+ final OutputStream os = new ByteArrayOutputStream();
api.executeApiAsync(params, is, os, new IOpenPgpCallback() {
@Override
@@ -174,6 +132,12 @@ public class PgpEngine {
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE,
OpenPgpApi.RESULT_CODE_ERROR)) {
case OpenPgpApi.RESULT_CODE_SUCCESS:
+ StringBuilder encryptedMessageBody = new StringBuilder();
+ String[] lines = os.toString().split("\n");
+ for (int i = 3; i < lines.length - 1; ++i) {
+ encryptedMessageBody.append(lines[i].trim());
+ }
+ message.setEncryptedBody(encryptedMessageBody.toString());
callback.success();
break;
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
@@ -181,19 +145,45 @@ public class PgpEngine {
.getParcelableExtra(OpenPgpApi.RESULT_INTENT));
break;
case OpenPgpApi.RESULT_CODE_ERROR:
- callback.error((OpenPgpError) result
- .getParcelableExtra(OpenPgpApi.RESULT_ERROR));
+ callback.error(R.string.openpgp_error);
break;
}
}
});
- } catch (FileNotFoundException e) {
- Log.d("xmppService","file not found: "+e.getMessage());
- } catch (IOException e) {
- Log.d("xmppService","io exception during file encrypt");
+ } else if (message.getType() == Message.TYPE_IMAGE) {
+ try {
+ JingleFile inputFile = this.mXmppConnectionService.getFileBackend().getJingleFile(message, true);
+ JingleFile outputFile = this.mXmppConnectionService.getFileBackend().getJingleFile(message, false);
+ outputFile.createNewFile();
+ InputStream is = new FileInputStream(inputFile);
+ OutputStream os = new FileOutputStream(outputFile);
+ api.executeApiAsync(params, is, os, new IOpenPgpCallback() {
+
+ @Override
+ public void onReturn(Intent result) {
+ switch (result.getIntExtra(OpenPgpApi.RESULT_CODE,
+ OpenPgpApi.RESULT_CODE_ERROR)) {
+ case OpenPgpApi.RESULT_CODE_SUCCESS:
+ callback.success();
+ break;
+ case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
+ callback.userInputRequried((PendingIntent) result
+ .getParcelableExtra(OpenPgpApi.RESULT_INTENT));
+ break;
+ case OpenPgpApi.RESULT_CODE_ERROR:
+ callback.error(R.string.openpgp_error);
+ break;
+ }
+ }
+ });
+ } catch (FileNotFoundException e) {
+ Log.d("xmppService","file not found: "+e.getMessage());
+ } catch (IOException e) {
+ Log.d("xmppService","io exception during file encrypt");
+ }
}
}
-
+
public long fetchKeyId(Account account, String status, String signature) {
if ((signature == null) || (api == null)) {
return 0;
@@ -242,7 +232,7 @@ public class PgpEngine {
}
public void generateSignature(final Account account, String status,
- final OnPgpEngineResult callback) {
+ final UiCallback callback) {
Intent params = new Intent();
params.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
params.setAction(OpenPgpApi.ACTION_SIGN);
@@ -268,22 +258,19 @@ public class PgpEngine {
.getParcelableExtra(OpenPgpApi.RESULT_INTENT));
return;
case OpenPgpApi.RESULT_CODE_ERROR:
- callback.error((OpenPgpError) result
- .getParcelableExtra(OpenPgpApi.RESULT_ERROR));
+ callback.error(R.string.openpgp_error);
return;
}
}
});
}
- public void hasKey(Contact contact, final OnPgpEngineResult callback) {
+ public void hasKey(Contact contact, final UiCallback callback) {
Intent params = new Intent();
params.setAction(OpenPgpApi.ACTION_GET_KEY);
params.putExtra(OpenPgpApi.EXTRA_KEY_ID, contact.getPgpKeyId());
params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, contact.getAccount().getJid());
- InputStream is = new ByteArrayInputStream(new byte[0]);
- OutputStream os = new ByteArrayOutputStream();
- api.executeApiAsync(params, is, os, new IOpenPgpCallback() {
+ api.executeApiAsync(params, null, null, new IOpenPgpCallback() {
@Override
public void onReturn(Intent result) {
@@ -296,11 +283,19 @@ public class PgpEngine {
.getParcelableExtra(OpenPgpApi.RESULT_INTENT));
return;
case OpenPgpApi.RESULT_CODE_ERROR:
- callback.error((OpenPgpError) result
- .getParcelableExtra(OpenPgpApi.RESULT_ERROR));
+ callback.error(R.string.openpgp_error);
return;
}
}
});
}
+
+ public PendingIntent getIntentForKey(Contact contact) {
+ Intent params = new Intent();
+ params.setAction(OpenPgpApi.ACTION_GET_KEY);
+ params.putExtra(OpenPgpApi.EXTRA_KEY_ID, contact.getPgpKeyId());
+ params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, contact.getAccount().getJid());
+ Intent result = api.executeApi(params, null, null);
+ return (PendingIntent) result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
+ }
}
diff --git a/src/eu/siacs/conversations/entities/Message.java b/src/eu/siacs/conversations/entities/Message.java
index a17d552f..33f7a8d4 100644
--- a/src/eu/siacs/conversations/entities/Message.java
+++ b/src/eu/siacs/conversations/entities/Message.java
@@ -1,7 +1,9 @@
package eu.siacs.conversations.entities;
+import eu.siacs.conversations.R;
import eu.siacs.conversations.xmpp.jingle.JingleConnection;
import android.content.ContentValues;
+import android.content.Context;
import android.database.Cursor;
public class Message extends AbstractEntity {
@@ -103,6 +105,20 @@ public class Message extends AbstractEntity {
public String getBody() {
return body;
}
+
+ public String getReadableBody(Context context) {
+ if ((encryption == ENCRYPTION_PGP)&&(type == TYPE_TEXT)) {
+ return ""+context.getText(R.string.encrypted_message_received);
+ } else if ((encryption == ENCRYPTION_OTR)&&(type == TYPE_IMAGE)) {
+ return ""+context.getText(R.string.encrypted_image_received);
+ } else if (encryption == ENCRYPTION_DECRYPTION_FAILED) {
+ return ""+context.getText(R.string.decryption_failed);
+ } else if (type == TYPE_IMAGE) {
+ return ""+context.getText(R.string.image_file);
+ } else {
+ return body.trim();
+ }
+ }
public long getTimeSent() {
return timeSent;
diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java
index 868e2398..becb1ee3 100644
--- a/src/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/eu/siacs/conversations/persistance/FileBackend.java
@@ -102,7 +102,7 @@ public class FileBackend {
boolean success = scalledBitmap.compress(
Bitmap.CompressFormat.WEBP, 75, os);
if (!success) {
- // Log.d("xmppService", "couldnt compress");
+ return null;
}
os.flush();
os.close();
@@ -112,14 +112,12 @@ public class FileBackend {
message.setBody(""+size+","+width+","+height);
return file;
} catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ return null;
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ return null;
+ } catch (SecurityException e) {
+ return null;
}
-
- return null;
}
public Bitmap getImageFromMessage(Message message) {
diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java
index 3581d189..d2742997 100644
--- a/src/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/eu/siacs/conversations/services/XmppConnectionService.java
@@ -17,8 +17,7 @@ import org.openintents.openpgp.util.OpenPgpServiceConnection;
import net.java.otr4j.OtrException;
import net.java.otr4j.session.Session;
import net.java.otr4j.session.SessionStatus;
-
-import eu.siacs.conversations.crypto.OnPgpEngineResult;
+import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.PgpEngine;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
@@ -33,6 +32,7 @@ import eu.siacs.conversations.persistance.OnPhoneContactsMerged;
import eu.siacs.conversations.ui.OnAccountListChangedListener;
import eu.siacs.conversations.ui.OnConversationListChangedListener;
import eu.siacs.conversations.ui.OnRosterFetchedListener;
+import eu.siacs.conversations.ui.UiCallback;
import eu.siacs.conversations.utils.ExceptionHelper;
import eu.siacs.conversations.utils.MessageParser;
import eu.siacs.conversations.utils.OnPhoneContactsLoadedListener;
@@ -446,45 +446,35 @@ public class XmppConnectionService extends Service {
return this.fileBackend;
}
- public Message attachImageToConversation(final Conversation conversation,
- final String presence, final Uri uri) {
- final Message message = new Message(conversation, "",Message.ENCRYPTION_NONE);
- message.setPresence(presence);
+ public Message attachImageToConversation(final Conversation conversation, final Uri uri, final UiCallback callback) {
+ final Message message;
+ if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
+ message = new Message(conversation, "",Message.ENCRYPTION_DECRYPTED);
+ } else {
+ message = new Message(conversation, "", Message.ENCRYPTION_NONE);
+ }
+ message.setPresence(conversation.getNextPresence());
message.setType(Message.TYPE_IMAGE);
message.setStatus(Message.STATUS_OFFERED);
new Thread(new Runnable() {
@Override
public void run() {
- getFileBackend().copyImageToPrivateStorage(message, uri);
- databaseBackend.createMessage(message);
- conversation.getMessages().add(message);
- if (convChangedListener != null) {
- convChangedListener.onConversationListChanged();
+ JingleFile file = getFileBackend().copyImageToPrivateStorage(message, uri);
+ if (file==null) {
+ callback.error(R.string.error_copying_image_file);
+ } else {
+ if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
+ getPgpEngine().encrypt(message, callback);
+ } else {
+ callback.success();
+ }
}
- sendMessage(message, null);
}
}).start();
return message;
}
- public Message attachEncryptedImageToConversation(final Conversation conversation, final String presence, final Uri uri, final OnPgpEngineResult callback) {
- Log.d(LOGTAG,"attach encrypted image");
- final Message message = new Message(conversation, "",Message.ENCRYPTION_DECRYPTED);
- message.setPresence(presence);
- message.setType(Message.TYPE_IMAGE);
- message.setStatus(Message.STATUS_OFFERED);
- new Thread(new Runnable() {
-
- @Override
- public void run() {
- getFileBackend().copyImageToPrivateStorage(message, uri);
- getPgpEngine().encrypt(message, callback);
- }
- }).start();
- return message;
- }
-
protected Conversation findMuc(String name, Account account) {
for (Conversation conversation : this.conversations) {
if (conversation.getContactJid().split("/")[0].equals(name)
diff --git a/src/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/eu/siacs/conversations/ui/ContactDetailsActivity.java
index 1ed3fa13..eaa9b8ee 100644
--- a/src/eu/siacs/conversations/ui/ContactDetailsActivity.java
+++ b/src/eu/siacs/conversations/ui/ContactDetailsActivity.java
@@ -4,10 +4,14 @@ import java.math.BigInteger;
import java.util.Iterator;
import java.util.Locale;
+import org.openintents.openpgp.util.OpenPgpUtils;
+
import android.app.AlertDialog;
+import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.IntentSender.SendIntentException;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract.CommonDataKinds;
@@ -26,6 +30,7 @@ import android.widget.QuickContactBadge;
import android.widget.TextView;
import android.widget.Toast;
import eu.siacs.conversations.R;
+import eu.siacs.conversations.crypto.PgpEngine;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Presences;
import eu.siacs.conversations.utils.UIHelper;
@@ -252,17 +257,29 @@ public class ContactDetailsActivity extends XmppActivity {
key.setText(otrFingerprint);
keys.addView(view);
}
- Log.d("gultsch", "pgp key id " + contact.getPgpKeyId());
if (contact.getPgpKeyId() != 0) {
View view = (View) inflater.inflate(R.layout.contact_key, null);
TextView key = (TextView) view.findViewById(R.id.key);
TextView keyType = (TextView) view.findViewById(R.id.key_type);
keyType.setText("PGP Key ID");
- BigInteger bi = new BigInteger("" + contact.getPgpKeyId());
- StringBuilder builder = new StringBuilder(bi.toString(16)
- .toUpperCase(Locale.US));
- builder.insert(8, " ");
- key.setText(builder.toString());
+ key.setText(OpenPgpUtils.convertKeyIdToHex(contact.getPgpKeyId()));
+ view.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ PgpEngine pgp = activity.xmppConnectionService.getPgpEngine();
+ if (pgp!=null) {
+ PendingIntent intent = pgp.getIntentForKey(contact);
+ if (intent!=null) {
+ try {
+ startIntentSenderForResult(intent.getIntentSender(), 0, null, 0, 0, 0);
+ } catch (SendIntentException e) {
+
+ }
+ }
+ }
+ }
+ });
keys.addView(view);
}
}
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java
index 99af97e2..88728245 100644
--- a/src/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/eu/siacs/conversations/ui/ConversationActivity.java
@@ -9,13 +9,13 @@ import java.util.List;
import org.openintents.openpgp.OpenPgpError;
import eu.siacs.conversations.R;
-import eu.siacs.conversations.crypto.OnPgpEngineResult;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.utils.ExceptionHelper;
import eu.siacs.conversations.utils.UIHelper;
+import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
@@ -53,6 +53,7 @@ import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
import android.widget.TextView;
import android.widget.ImageView;
+import android.widget.Toast;
public class ConversationActivity extends XmppActivity {
@@ -63,8 +64,10 @@ public class ConversationActivity extends XmppActivity {
public static final int REQUEST_SEND_MESSAGE = 0x75441;
public static final int REQUEST_DECRYPT_PGP = 0x76783;
- private static final int ATTACH_FILE = 0x48502;
+ private static final int REQUEST_ATTACH_FILE_DIALOG = 0x48502;
private static final int REQUEST_SEND_PGP_IMAGE = 0x53883;
+ private static final int REQUEST_ATTACH_FILE = 0x73824;
+ public static final int REQUEST_ENCRYPT_MESSAGE = 0x378018;
protected SlidingPaneLayout spl;
@@ -108,6 +111,7 @@ public class ConversationActivity extends XmppActivity {
protected ConversationActivity activity = this;
private DisplayMetrics metrics;
+ private Toast prepareImageToast;
public List<Conversation> getConversationList() {
return this.conversationList;
@@ -174,7 +178,11 @@ public class ConversationActivity extends XmppActivity {
Message latestMessage = conv.getLatestMessage();
if (latestMessage.getType() == Message.TYPE_TEXT) {
- convLastMsg.setText(conv.getLatestMessage().getBody());
+ if ((latestMessage.getEncryption() != Message.ENCRYPTION_PGP)&&(latestMessage.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED)) {
+ convLastMsg.setText(conv.getLatestMessage().getBody());
+ } else {
+ convLastMsg.setText(getText(R.string.encrypted_message_received));
+ }
convLastMsg.setVisibility(View.VISIBLE);
imagePreview.setVisibility(View.GONE);
} else if (latestMessage.getType() == Message.TYPE_IMAGE) {
@@ -329,7 +337,7 @@ public class ConversationActivity extends XmppActivity {
attachFileIntent.setType("image/*");
attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
Intent chooser = Intent.createChooser(attachFileIntent, getString(R.string.attach_file));
- startActivityForResult(chooser, ATTACH_FILE);
+ startActivityForResult(chooser, REQUEST_ATTACH_FILE_DIALOG);
}
}
@@ -345,11 +353,11 @@ public class ConversationActivity extends XmppActivity {
if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
if (hasPgp()) {
if (conversation.getContact().getPgpKeyId()!=0) {
- xmppConnectionService.getPgpEngine().hasKey(conversation.getContact(), new OnPgpEngineResult() {
+ xmppConnectionService.getPgpEngine().hasKey(conversation.getContact(), new UiCallback() {
@Override
public void userInputRequried(PendingIntent pi) {
- ConversationActivity.this.runIntent(pi, REQUEST_SEND_PGP_IMAGE);
+ ConversationActivity.this.runIntent(pi, REQUEST_ATTACH_FILE);
}
@Override
@@ -358,7 +366,7 @@ public class ConversationActivity extends XmppActivity {
}
@Override
- public void error(OpenPgpError openPgpError) {
+ public void error(int error) {
// TODO Auto-generated method stub
}
@@ -380,6 +388,31 @@ public class ConversationActivity extends XmppActivity {
}
} else if (getSelectedConversation().getNextEncryption() == Message.ENCRYPTION_NONE) {
attachFileDialog();
+ } else {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(getString(R.string.otr_file_transfer));
+ builder.setMessage(getString(R.string.otr_file_transfer_msg));
+ builder.setNegativeButton(getString(R.string.cancel), null);
+ if (conversation.getContact().getPgpKeyId()==0) {
+ builder.setPositiveButton(getString(R.string.send_unencrypted), new OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ conversation.setNextEncryption(Message.ENCRYPTION_NONE);
+ attachFile();
+ }
+ });
+ } else {
+ builder.setPositiveButton(getString(R.string.use_pgp_encryption), new OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ conversation.setNextEncryption(Message.ENCRYPTION_PGP);
+ attachFile();
+ }
+ });
+ }
+ builder.create().show();
}
}
@@ -448,7 +481,7 @@ public class ConversationActivity extends XmppActivity {
conversation.setNextEncryption(Message.ENCRYPTION_PGP);
item.setChecked(true);
} else {
- announcePgp(conversation.getAccount());
+ announcePgp(conversation.getAccount(),conversation);
}
}
break;
@@ -634,41 +667,78 @@ public class ConversationActivity extends XmppActivity {
if (selectedFragment != null) {
selectedFragment.hidePgpPassphraseBox();
}
- } else if (requestCode == ATTACH_FILE) {
+ } else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) {
+ prepareImageToast = Toast.makeText(getApplicationContext(), getText(R.string.preparing_image), Toast.LENGTH_LONG);
final Conversation conversation = getSelectedConversation();
- String presence = conversation.getNextPresence();
if (conversation.getNextEncryption() == Message.ENCRYPTION_NONE) {
- xmppConnectionService.attachImageToConversation(conversation, presence, data.getData());
- } else if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
- pendingMessage = xmppConnectionService.attachEncryptedImageToConversation(conversation, presence, data.getData(), new OnPgpEngineResult() {
+ prepareImageToast.show();
+ this.pendingMessage = xmppConnectionService.attachImageToConversation(conversation, data.getData(),new UiCallback() {
@Override
public void userInputRequried(PendingIntent pi) {
- ConversationActivity.this.runIntent(pi, ConversationActivity.REQUEST_SEND_PGP_IMAGE);
+
}
@Override
public void success() {
- conversation.getMessages().add(pendingMessage);
- pendingMessage.setStatus(Message.STATUS_OFFERED);
- xmppConnectionService.databaseBackend.createMessage(pendingMessage);
- xmppConnectionService.sendMessage(pendingMessage, null);
- xmppConnectionService.updateUi(conversation, false);
- pendingMessage = null;
+ sendPendingImageMessage();
}
@Override
- public void error(OpenPgpError openPgpError) {
- Log.d(LOGTAG,"pgp error"+openPgpError.getMessage());
+ public void error(int error) {
+ pendingMessage = null;
+ displayErrorDialog(error);
}
});
+ } else if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
+ prepareImageToast.show();
+ attachPgpFile(conversation,data.getData());
} else {
Log.d(LOGTAG,"unknown next message encryption: "+conversation.getNextEncryption());
}
+ } else if (requestCode == REQUEST_SEND_PGP_IMAGE) {
+
+ } else if (requestCode == REQUEST_ATTACH_FILE) {
+ attachFile();
+ } else if (requestCode == REQUEST_ANNOUNCE_PGP) {
+ announcePgp(getSelectedConversation().getAccount(),getSelectedConversation());
+ } else if (requestCode == REQUEST_ENCRYPT_MESSAGE) {
+ encryptTextMessage();
+ } else {
+ Log.d(LOGTAG,"unknown result code:"+requestCode);
}
}
}
+
+ private void attachPgpFile(Conversation conversation, Uri uri) {
+ pendingMessage = xmppConnectionService.attachImageToConversation(conversation, uri, new UiCallback() {
+
+ @Override
+ public void userInputRequried(PendingIntent pi) {
+ ConversationActivity.this.runIntent(pi, ConversationActivity.REQUEST_SEND_PGP_IMAGE);
+ }
+
+ @Override
+ public void success() {
+ sendPendingImageMessage();
+ }
+
+ @Override
+ public void error(int error) {
+ pendingMessage = null;
+ displayErrorDialog(error);
+ }
+ });
+ }
+ private void sendPendingImageMessage() {
+ pendingMessage.getConversation().getMessages().add(pendingMessage);
+ xmppConnectionService.databaseBackend.createMessage(pendingMessage);
+ xmppConnectionService.sendMessage(pendingMessage, null);
+ xmppConnectionService.updateUi(pendingMessage.getConversation(), false);
+ pendingMessage = null;
+ }
+
public void updateConversationList() {
conversationList.clear();
conversationList.addAll(xmppConnectionService.getConversations());
@@ -872,4 +942,33 @@ public class ConversationActivity extends XmppActivity {
return bitmapWorkerTaskReference.get();
}
}
+
+ public void encryptTextMessage() {
+ xmppConnectionService.getPgpEngine().encrypt(this.pendingMessage, new UiCallback() {
+
+ @Override
+ public void userInputRequried(
+ PendingIntent pi) {
+ activity.runIntent(
+ pi,
+ ConversationActivity.REQUEST_SEND_MESSAGE);
+ }
+
+ @Override
+ public void success() {
+ xmppConnectionService.sendMessage(pendingMessage, null);
+ pendingMessage = null;
+ ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager()
+ .findFragmentByTag("conversation");
+ if (selectedFragment != null) {
+ selectedFragment.clearInputField();
+ }
+ }
+
+ @Override
+ public void error(int error) {
+
+ }
+ });
+ }
}
diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java
index e370deb0..91a39ecc 100644
--- a/src/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/eu/siacs/conversations/ui/ConversationFragment.java
@@ -8,9 +8,7 @@ import java.util.Set;
import org.openintents.openpgp.OpenPgpError;
import net.java.otr4j.session.SessionStatus;
-
import eu.siacs.conversations.R;
-import eu.siacs.conversations.crypto.OnPgpEngineResult;
import eu.siacs.conversations.crypto.PgpEngine;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
@@ -198,8 +196,12 @@ public class ConversationFragment extends Fragment {
boolean error = false;
if (message.getType() == Message.TYPE_IMAGE) {
String[] fileParams = message.getBody().split(",");
- long size = Long.parseLong(fileParams[0]);
- filesize = size / 1024 + " KB";
+ try {
+ long size = Long.parseLong(fileParams[0]);
+ filesize = size / 1024 + " KB";
+ } catch (NumberFormatException e) {
+ filesize = "0 KB";
+ }
}
switch (message.getStatus()) {
case Message.STATUS_UNSEND:
@@ -492,7 +494,9 @@ public class ConversationFragment extends Fragment {
@Override
public void onStop() {
super.onStop();
- this.conversation.setNextMessage(chatMsg.getText().toString());
+ if (this.conversation!=null) {
+ this.conversation.setNextMessage(chatMsg.getText().toString());
+ }
}
public void onBackendConnected() {
@@ -554,7 +558,7 @@ public class ConversationFragment extends Fragment {
private void decryptMessage(final Message message) {
PgpEngine engine = activity.xmppConnectionService.getPgpEngine();
if (engine != null) {
- engine.decrypt(message, new OnPgpEngineResult() {
+ engine.decrypt(message, new UiCallback() {
@Override
public void userInputRequried(PendingIntent pi) {
@@ -570,9 +574,7 @@ public class ConversationFragment extends Fragment {
}
@Override
- public void error(OpenPgpError openPgpError) {
- Log.d("xmppService",
- "decryption error" + openPgpError.getMessage());
+ public void error(int error) {
message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
// updateMessages();
}
@@ -583,6 +585,9 @@ public class ConversationFragment extends Fragment {
}
public void updateMessages() {
+ if (getView()==null) {
+ return;
+ }
ConversationActivity activity = (ConversationActivity) getActivity();
if (this.conversation != null) {
for (Message message : this.conversation.getMessages()) {
@@ -664,56 +669,30 @@ public class ConversationFragment extends Fragment {
}
protected void sendPgpMessage(final Message message) {
+ activity.pendingMessage = message;
final ConversationActivity activity = (ConversationActivity) getActivity();
final XmppConnectionService xmppService = activity.xmppConnectionService;
final Contact contact = message.getConversation().getContact();
- final Account account = message.getConversation().getAccount();
if (activity.hasPgp()) {
if (contact.getPgpKeyId() != 0) {
xmppService.getPgpEngine().hasKey(contact,
- new OnPgpEngineResult() {
+ new UiCallback() {
@Override
public void userInputRequried(PendingIntent pi) {
activity.runIntent(
pi,
- ConversationActivity.REQUEST_SEND_MESSAGE);
+ ConversationActivity.REQUEST_ENCRYPT_MESSAGE);
}
@Override
public void success() {
- xmppService.getPgpEngine().encrypt(account,
- message, new OnPgpEngineResult() {
-
- @Override
- public void userInputRequried(
- PendingIntent pi) {
- activity.runIntent(
- pi,
- ConversationActivity.REQUEST_SEND_MESSAGE);
- }
-
- @Override
- public void success() {
- xmppService.sendMessage(
- message, null);
- chatMsg.setText("");
- }
-
- @Override
- public void error(
- OpenPgpError openPgpError) {
- // TODO Auto-generated method
- // stub
-
- }
- });
+ activity.encryptTextMessage();
}
@Override
- public void error(OpenPgpError openPgpError) {
- Log.d("xmppService", "openpgp error"
- + openPgpError.getMessage());
+ public void error(int error) {
+
}
});
@@ -809,4 +788,8 @@ public class ConversationFragment extends Fragment {
public void setText(String text) {
this.pastedText = text;
}
+
+ public void clearInputField() {
+ this.chatMsg.setText("");
+ }
}
diff --git a/src/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/eu/siacs/conversations/ui/ManageAccountActivity.java
index 8f4d9b9f..0b7dac58 100644
--- a/src/eu/siacs/conversations/ui/ManageAccountActivity.java
+++ b/src/eu/siacs/conversations/ui/ManageAccountActivity.java
@@ -6,7 +6,6 @@ import java.util.List;
import org.openintents.openpgp.OpenPgpError;
import eu.siacs.conversations.R;
-import eu.siacs.conversations.crypto.OnPgpEngineResult;
import eu.siacs.conversations.crypto.PgpEngine;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.ui.EditAccount.EditAccountListener;
@@ -279,7 +278,7 @@ public class ManageAccountActivity extends XmppActivity {
} else if (item.getItemId()==R.id.mgmt_account_announce_pgp) {
if (activity.hasPgp()) {
mode.finish();
- announcePgp(selectedAccountForActionMode);
+ announcePgp(selectedAccountForActionMode,null);
}
} else if (item.getItemId() == R.id.mgmt_otr_key) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
@@ -288,7 +287,10 @@ public class ManageAccountActivity extends XmppActivity {
View view = (View) getLayoutInflater().inflate(R.layout.otr_fingerprint, null);
if (fingerprintTxt!=null) {
TextView fingerprint = (TextView) view.findViewById(R.id.otr_fingerprint);
+ TextView noFingerprintView = (TextView) view.findViewById(R.id.otr_no_fingerprint);
fingerprint.setText(fingerprintTxt);
+ fingerprint.setVisibility(View.VISIBLE);
+ noFingerprintView.setVisibility(View.GONE);
}
builder.setView(view);
builder.setPositiveButton("Done", null);
@@ -458,8 +460,8 @@ public class ManageAccountActivity extends XmppActivity {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_ANNOUNCE_PGP) {
- announcePgp(selectedAccountForActionMode);
- }
+ announcePgp(selectedAccountForActionMode,null);
+ }
}
}
}
diff --git a/src/eu/siacs/conversations/ui/UiCallback.java b/src/eu/siacs/conversations/ui/UiCallback.java
new file mode 100644
index 00000000..f9273b96
--- /dev/null
+++ b/src/eu/siacs/conversations/ui/UiCallback.java
@@ -0,0 +1,9 @@
+package eu.siacs.conversations.ui;
+
+import android.app.PendingIntent;
+
+public interface UiCallback {
+ public void success();
+ public void error(int errorCode);
+ public void userInputRequried(PendingIntent pi);
+}
diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java
index 70b2e24e..dc894ad5 100644
--- a/src/eu/siacs/conversations/ui/XmppActivity.java
+++ b/src/eu/siacs/conversations/ui/XmppActivity.java
@@ -1,11 +1,11 @@
package eu.siacs.conversations.ui;
-import org.openintents.openpgp.OpenPgpError;
+import java.nio.channels.AlreadyConnectedException;
import eu.siacs.conversations.R;
-import eu.siacs.conversations.crypto.OnPgpEngineResult;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
+import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder;
import eu.siacs.conversations.utils.ExceptionHelper;
@@ -162,8 +162,8 @@ public abstract class XmppActivity extends Activity {
startActivity(viewConversationIntent);
}
- protected void announcePgp(final Account account) {
- xmppConnectionService.getPgpEngine().generateSignature(account, "online", new OnPgpEngineResult() {
+ protected void announcePgp(final Account account, final Conversation conversation) {
+ xmppConnectionService.getPgpEngine().generateSignature(account, "online", new UiCallback() {
@Override
public void userInputRequried(PendingIntent pi) {
@@ -178,13 +178,31 @@ public abstract class XmppActivity extends Activity {
public void success() {
xmppConnectionService.databaseBackend.updateAccount(account);
xmppConnectionService.sendPgpPresence(account, account.getPgpSignature());
+ if (conversation!=null) {
+ conversation.setNextEncryption(Message.ENCRYPTION_PGP);
+ }
}
@Override
- public void error(OpenPgpError openPgpError) {
- // TODO Auto-generated method stub
-
+ public void error(int error) {
+ displayErrorDialog(error);
+ }
+ });
+ }
+
+ protected void displayErrorDialog(final int errorCode) {
+ runOnUiThread(new Runnable() {
+
+ @Override
+ public void run() {
+ AlertDialog.Builder builder = new AlertDialog.Builder(XmppActivity.this);
+ builder.setIconAttribute(android.R.attr.alertDialogIcon);
+ builder.setTitle(getString(R.string.error));
+ builder.setMessage(errorCode);
+ builder.setNeutralButton(R.string.accept, null);
+ builder.create().show();
}
});
+
}
}
diff --git a/src/eu/siacs/conversations/utils/UIHelper.java b/src/eu/siacs/conversations/utils/UIHelper.java
index 1c52ff0b..8baa3c25 100644
--- a/src/eu/siacs/conversations/utils/UIHelper.java
+++ b/src/eu/siacs/conversations/utils/UIHelper.java
@@ -389,7 +389,7 @@ public class UIHelper {
context, true));
mBuilder.setContentTitle(conversation.getName(useSubject));
if (notify) {
- mBuilder.setTicker(conversation.getLatestMessage().getBody().trim());
+ mBuilder.setTicker(conversation.getLatestMessage().getReadableBody(context));
}
StringBuilder bigText = new StringBuilder();
List<Message> messages = conversation.getMessages();
@@ -397,10 +397,10 @@ public class UIHelper {
for (int i = messages.size() - 1; i >= 0; --i) {
if (!messages.get(i).isRead()) {
if (i == messages.size() - 1) {
- firstLine = messages.get(i).getBody().trim();
+ firstLine = messages.get(i).getReadableBody(context);
bigText.append(firstLine);
} else {
- firstLine = messages.get(i).getBody().trim();
+ firstLine = messages.get(i).getReadableBody(context);
bigText.insert(0, firstLine + "\n");
}
} else {
@@ -422,7 +422,7 @@ public class UIHelper {
names.append(unread.get(i).getName(useSubject));
}
style.addLine(Html.fromHtml("<b>" + unread.get(i).getName(useSubject)
- + "</b> " + unread.get(i).getLatestMessage().getBody().trim()));
+ + "</b> " + unread.get(i).getLatestMessage().getReadableBody(context)));
}
mBuilder.setContentTitle(unread.size() + " unread Conversations");
mBuilder.setContentText(names.toString());