diff --git a/AndroidManifest.xml b/AndroidManifest.xml index c7f564bc8..8c90d0929 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="11" + android:versionName="0.2" > + + + android:visibility="gone"/> diff --git a/res/menu/conversations.xml b/res/menu/conversations.xml index 58fd3bfa9..68bcc9576 100644 --- a/res/menu/conversations.xml +++ b/res/menu/conversations.xml @@ -4,13 +4,13 @@ android:id="@+id/action_add" android:orderInCategory="10" android:icon="@drawable/ic_action_add" - android:showAsAction="always" + android:showAsAction="ifRoom" android:title="@string/action_add" /> diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml index ac33ac3b9..c6209625a 100644 --- a/res/values-de/strings.xml +++ b/res/values-de/strings.xml @@ -28,7 +28,7 @@ Teile mit… Klick um noch einmal zu fragen OTR Fingerabdruck - Es wurde noch kein OTR Fingerabdruck erzeugt. Beginne einfach eine verschlüsselte Unterhaltung an. + Es wurde noch kein OTR-Fingerabdruck erzeugt. Beginne einfach eine verschlüsselte Unterhaltung um einen Fingerabdruck zu erzeugen. Beginne Unterhaltung Kontakte einladen Lade zu bestehender Konferenz ein diff --git a/res/values-es/strings.xml b/res/values-es/strings.xml index 021247fad..2c5691875 100644 --- a/res/values-es/strings.xml +++ b/res/values-es/strings.xml @@ -2,10 +2,10 @@ Conversations - Configuración + Ajustes Nueva conversación Gestionar cuentas - Terminar esta conversación + Terminar conversación Detalles del contacto Detalles de la conferencia Conversación segura @@ -21,66 +21,75 @@ Participante Visitante Introduce un nuevo nombre: - Quieres eliminar a %s de tu lista. La conversación asociada a esta cuenta no se eliminará. - El servidor %s te presentó con un certificado no confiable, posiblemente auto firmado. - Info del servidor - Registrar nueva cuenta en el servidor + ¿Quieres eliminar a %s de tu lista?. La conversación asociada a esta cuenta no se eliminará. + El servidor %s presenta un certificado no confiable, posiblemente auto firmado. + Información del servidor + Registrar nueva cuenta en servidor Compartir con Pulsa para preguntar otra vez Huella dactilar OTR - No se ha generado una huella dactilar OTR Fingerprint. Simplemente continúa y comienza una conversación encriptada + No se ha generado una huella dactilar OTR. Simplemente continúa y comienza una conversación encriptada Comenzar conversación Invitar contactos Invitar a conferencia existente Crear nueva conferencia Cancelar Crear \u0026 Invitar - ¿Quieres crear una nueva conferencia con una dirección generada aleatoriamente e invitar a los contactos seleccionados a ella? + ¿Quieres crear una nueva conferencia con una dirección generada aleatoriamente e invitar a los contactos seleccionados a ella? No hay conferencias existentes Invitación enviada - Cuenta fuera de línea - Tienes que estar en línea para invitar a gente a las conferencias + Cuenta desconectada + Debes estar conectado para invitar a contactos a la conferencia Conversations se ha detenido. - Enviando volcados de pilas ayudas al continuo desarrollo de Conversations\nAviso: Esto usará tu cuenta XMPP para enviar el volcado de pila al desarrollador. + Enviando volcados de pilas ayudas al desarrollo de Conversations\nAviso: Esto usará tu cuenta XMPP para enviar el volcado de pila al desarrollador. Enviar ahora No preguntar de nuevo No se ha podido conectar a la cuenta No se ha podido conectar a múltiples cuentas - Toca aquí para gestionar tus cuentas - Adjuntar archivo + Pulsa aquí para gestionar tus cuentas + Enviar archivo El contacto no está en tu lista. ¿Quieres añadirlo? Añadir contacto - entrega infructuosa + Error al enviar rechazado Recibiendo archivo de imagen. Espera por favor… - Preparando imagen para transmisión. Espera por favor… - Limpiar historia - Limpiar historia de conversación - ¿Quieres borrar todos los mensajes de esta conversación?\n\nAviso: Esto no tendrá influencia en los mensajes guardados en otros dispositivos o servidores. + Preparando imagen para enviar + Limpiar historial + Limpiar historial de conversación + ¿Quieres borrar todos los mensajes de esta conversación?\n\nAviso: Esto no afectará a los mensajes guardados en otros dispositivos o servidores. Borrar mensajes Terminar esta conversación más tarde - Elegir presencia para contacto + Selecciona recurso del contacto Enviar mensaje a conferencia - Enviar mensaje en texto plano + Enviar mensaje de texto Enviar mensaje encriptado con OTR Enviar mensaje encriptado con openPGP - Tu apodo se ha cambiado + Tu apodo se ha modificado Descargar imagen Error cargando imagen (Archivo no encontrado) - Archivo de imagen ofrecida para descarga + Archivo de imagen ofrecido para descarga No conectado - Tienes que estar en línea para enviar %s pero tu cuenta asociada a esta conversación está fuera de línea. - No puede ejecutar esta acción estando fuera de línea + Debes estar conectado para enviar %s pero tu cuenta asociada a esta conversación está desconectada. + No puedes ejecutar esta acción estando desconectado archivos Mensajes encriptados con OTR Gestionar cuenta - Tu contacto está fuera de línea - Desgraciadamente no es posible enviar mensajes encriptados con OTR a un contacto fuera de línea.\n¿Quieres enviar el mensaje en texto plano? - Desgraciadamente no es posible enviar archivos a un contacto fuera de línea. + Tu contacto está desconectado + Desgraciadamente no es posible enviar mensajes encriptados con OTR a un contacto desconectado.\n¿Quieres enviar el mensaje en texto plano? + Desgraciadamente no es posible enviar archivos a un contacto desconectado. Enviar sin encriptar - Falló la desencriptación. Tal vez no tengas la clave privada apropiada. - OpenKeychain - Conversations utiliza una tercera app llamada OpenKeychain para encriptar y desencriptar mensajes y para gestionar tus claves publicas.\n\nOpenKeychain está licenciado bajo GPLv3 y disponible en F-Droid y Google Play.\n\n(Por favor reinicia Conversations después) - Reiniciar - Instalar - + Falló la desencriptación. Tal vez no tengas la clave privada apropiada. + OpenKeychain + Conversations utiliza una aplicación de terceros llamada OpenKeychain para encriptar y desencriptar mensajes y gestionar tus claves públicas.\n\nOpenKeychain está publicado bajo licencia GPLv3 y disponible on F-Droid y Google Play.\n\n(Por favor, reinicie Conversations después.) + Reiniciar + Instalar + ofreciendo… + Clave openPGP no encontrada + Conversations no ha podido encriptar tus mensajes porque tu contacto no está anunciando su clave publica.\n\nPor favor, pide a tu contacto que configure openPGP. + Mensaje encriptado recibido. Pulsa para desencriptar y ver. + Imagen encriptada recibida. Pulsa para desencriptar y ver. + Imagen recibida. Pulsa para ver + Encriptación con OTR no disponible + Desafortunadamente la encriptación con OTR no está disponible para transferencia de archivos. Puedes selecionar encriptación con openPGP o no usar encriptación. + Usa encriptación con openPGP + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 61134d29c..8020a01e4 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -53,7 +53,7 @@ unsuccessful delivery rejected Receiving image file. Please wait… - Preparing image for transmission. Please wait… + Preparing image for transmission Clear history Clear Conversation History Do you want to delete all messages within this Conversation?\n\nWarning: This will not influence messages stored on other devices or servers. @@ -86,4 +86,38 @@ offering… No openPGP Key found Conversations is unable to encrypt your messages because your contact is not announcing his or hers public key.\n\nPlease ask your contact to setup openPGP. + Encrypted message received. Touch to view and decrypt. + Encrypted image received. Touch to view and decrypt. + Image received. Touch to view + OTR encryption not available + Unfortunaly OTR encryption is not available for file transfer. You can choose either openPGP or no encryption. + Use openPGP encryption + XMPP resource + The name this client identifies itself with + Accept files + Automatically accept files smaller than… + Notification Settings + Notifications + Notify when a new message arrives + Vibrate + Also vibrate when a new message arrives + Sound + Play ringtone with notification + Conference notifications + Always notify when a new conference message arrives instead of only when highlighted + Notification grace period + Disable notifications for a short time after a carbon copy was received + UI Options + Use Phones self contact picture + You may no longer be able to distinguish which account you are using in a conversation + Conference name + Use room’s subject to identify Conferences + Advanced Options + Never send crash reports + By sending in stack traces you are helping the ongoing development of Conversations + OpenKeychain reporeted an error + I/O Error decrypting file + Error copying image file. + Accept + An error has occurred diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 6268350a2..b1b560c60 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -10,69 +10,69 @@ /> + android:title="@string/pref_notification_settings"> + android:title="@string/pref_conference_notifications" + android:summary="@string/pref_conference_notifications_summary"/> + android:title="@string/pref_ui_options"> diff --git a/src/eu/siacs/conversations/crypto/OnPgpEngineResult.java b/src/eu/siacs/conversations/crypto/OnPgpEngineResult.java deleted file mode 100644 index 8e1158390..000000000 --- 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 5a51a1e86..48750e240 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 a17d552f9..33f7a8d49 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 868e23985..becb1ee3b 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 3581d189a..d2742997d 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 1ed3fa131..eaa9b8eec 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 99af97e20..887282450 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 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 e370deb0c..91a39ecc9 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 8f4d9b9fe..0b7dac586 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 000000000..f9273b96a --- /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 70b2e24eb..dc894ad5a 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 1c52ff0b5..8baa3c254 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 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("" + unread.get(i).getName(useSubject) - + " " + unread.get(i).getLatestMessage().getBody().trim())); + + " " + unread.get(i).getLatestMessage().getReadableBody(context))); } mBuilder.setContentTitle(unread.size() + " unread Conversations"); mBuilder.setContentText(names.toString());