tryed to fix more otr bugs. new resource setting

This commit is contained in:
Daniel Gultsch 2014-03-21 22:14:52 +01:00
parent 079712060c
commit a9e34d3492
8 changed files with 69 additions and 72 deletions

View file

@ -1,17 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<array name="conversation_encryption_type_entries"> <array name="resources">
<item>None</item> <item>Mobile</item>
<item>OpenPGP</item> <item>Phone</item>
<item>Off the record</item> <item>Tablet</item>
</array> <item>Conversations</item>
<array name="conversation_encryption_type_values"> <item>Android</item>
<item>none</item>
<item>pgp</item>
<item>otr</item>
</array>
<array name="manage_account_options">
<item>Delete</item>
<item>Disable</item>
</array> </array>
</resources> </resources>

View file

@ -1,20 +1,20 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory <PreferenceCategory
android:title="Security and Privacy Options"> android:title="General">
<ListPreference
android:key="default_conversation_encryption_type"
android:title="Default conversation encryption"
android:dialogTitle="Default conversation encryption"
android:entries="@array/conversation_encryption_type_entries"
android:entryValues="@array/conversation_encryption_type_values"
android:defaultValue="none"/>
<CheckBoxPreference <CheckBoxPreference
android:key="grant_new_contacts" android:key="grant_new_contacts"
android:title="Grant presence updates" android:title="Grant presence updates"
android:summary="Preemptivly grant and ask for presence subscription for contacts you created" android:summary="Preemptivly grant and ask for presence subscription for contacts you created"
android:defaultValue="true" android:defaultValue="true"
/> />
<ListPreference
android:key="resource"
android:title="XMPP Resource"
android:summary="The name this client identifies itself"
android:entries="@array/resources"
android:entryValues="@array/resources"
android:defaultValue="Mobile"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:title="Notification Settings"> android:title="Notification Settings">

View file

@ -52,7 +52,7 @@ public class Account extends AbstractEntity{
protected String password; protected String password;
protected int options = 0; protected int options = 0;
protected String rosterVersion; protected String rosterVersion;
protected String resource; protected String resource = "mobile";
protected int status = -1; protected int status = -1;
protected JSONObject keys = new JSONObject(); protected JSONObject keys = new JSONObject();
@ -137,6 +137,10 @@ public class Account extends AbstractEntity{
this.resource = resource; this.resource = resource;
} }
public String getResource() {
return this.resource;
}
public String getJid() { public String getJid() {
return username+"@"+server; return username+"@"+server;
} }

View file

@ -7,6 +7,7 @@ import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Random; import java.util.Random;
import org.openintents.openpgp.util.OpenPgpApi; import org.openintents.openpgp.util.OpenPgpApi;
@ -550,6 +551,9 @@ public class XmppConnectionService extends Service {
} }
public XmppConnection createConnection(Account account) { public XmppConnection createConnection(Account account) {
SharedPreferences sharedPref = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
account.setResource(sharedPref.getString("resource", "mobile").toLowerCase(Locale.getDefault()));
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
XmppConnection connection = new XmppConnection(account, pm); XmppConnection connection = new XmppConnection(account, pm);
connection.setOnMessagePacketReceivedListener(this.messageListener); connection.setOnMessagePacketReceivedListener(this.messageListener);
@ -588,7 +592,7 @@ public class XmppConnectionService extends Service {
return connection; return connection;
} }
public void sendMessage(Message message, String presence) { synchronized public void sendMessage(Message message, String presence) {
Account account = message.getConversation().getAccount(); Account account = message.getConversation().getAccount();
Conversation conv = message.getConversation(); Conversation conv = message.getConversation();
boolean saveInDb = false; boolean saveInDb = false;

View file

@ -388,52 +388,54 @@ public class ConversationFragment extends Fragment {
public void updateMessages() { public void updateMessages() {
ConversationActivity activity = (ConversationActivity) getActivity(); ConversationActivity activity = (ConversationActivity) getActivity();
List<Message> encryptedMessages = new LinkedList<Message>(); if (this.conversation != null) {
for (Message message : this.conversation.getMessages()) { List<Message> encryptedMessages = new LinkedList<Message>();
if (message.getEncryption() == Message.ENCRYPTION_PGP) { for (Message message : this.conversation.getMessages()) {
encryptedMessages.add(message); if (message.getEncryption() == Message.ENCRYPTION_PGP) {
} encryptedMessages.add(message);
}
if (encryptedMessages.size() > 0) {
DecryptMessage task = new DecryptMessage();
Message[] msgs = new Message[encryptedMessages.size()];
task.execute(encryptedMessages.toArray(msgs));
}
this.messageList.clear();
this.messageList.addAll(this.conversation.getMessages());
this.messageListAdapter.notifyDataSetChanged();
if (conversation.getMode() == Conversation.MODE_SINGLE) {
if (messageList.size() >= 1) {
int latestEncryption = this.conversation.getLatestMessage()
.getEncryption();
if (latestEncryption == Message.ENCRYPTION_DECRYPTED) {
conversation.nextMessageEncryption = Message.ENCRYPTION_PGP;
} else {
conversation.nextMessageEncryption = latestEncryption;
} }
makeFingerprintWarning(latestEncryption);
} }
} else { if (encryptedMessages.size() > 0) {
if (conversation.getMucOptions().getError() != 0) { DecryptMessage task = new DecryptMessage();
mucError.setVisibility(View.VISIBLE); Message[] msgs = new Message[encryptedMessages.size()];
if (conversation.getMucOptions().getError() == MucOptions.ERROR_NICK_IN_USE) { task.execute(encryptedMessages.toArray(msgs));
mucErrorText.setText(getString(R.string.nick_in_use)); }
this.messageList.clear();
this.messageList.addAll(this.conversation.getMessages());
this.messageListAdapter.notifyDataSetChanged();
if (conversation.getMode() == Conversation.MODE_SINGLE) {
if (messageList.size() >= 1) {
int latestEncryption = this.conversation.getLatestMessage()
.getEncryption();
if (latestEncryption == Message.ENCRYPTION_DECRYPTED) {
conversation.nextMessageEncryption = Message.ENCRYPTION_PGP;
} else {
conversation.nextMessageEncryption = latestEncryption;
}
makeFingerprintWarning(latestEncryption);
} }
} else { } else {
mucError.setVisibility(View.GONE); if (conversation.getMucOptions().getError() != 0) {
mucError.setVisibility(View.VISIBLE);
if (conversation.getMucOptions().getError() == MucOptions.ERROR_NICK_IN_USE) {
mucErrorText.setText(getString(R.string.nick_in_use));
}
} else {
mucError.setVisibility(View.GONE);
}
}
getActivity().invalidateOptionsMenu();
updateChatMsgHint();
int size = this.messageList.size();
if (size >= 1)
messagesView.setSelection(size - 1);
if (!activity.shouldPaneBeOpen()) {
conversation.markRead();
// TODO update notifications
UIHelper.updateNotification(getActivity(),
activity.getConversationList(), null, false);
activity.updateConversationList();
} }
}
getActivity().invalidateOptionsMenu();
updateChatMsgHint();
int size = this.messageList.size();
if (size >= 1)
messagesView.setSelection(size - 1);
if (!activity.shouldPaneBeOpen()) {
conversation.markRead();
// TODO update notifications
UIHelper.updateNotification(getActivity(),
activity.getConversationList(), null, false);
activity.updateConversationList();
} }
} }

View file

@ -2,7 +2,6 @@ package eu.siacs.conversations.utils;
import java.util.List; import java.util.List;
import net.java.otr4j.OtrException;
import net.java.otr4j.session.Session; import net.java.otr4j.session.Session;
import net.java.otr4j.session.SessionStatus; import net.java.otr4j.session.SessionStatus;
import android.util.Log; import android.util.Log;
@ -89,11 +88,7 @@ public class MessageParser {
Log.d(LOGTAG,"otr session stoped"); Log.d(LOGTAG,"otr session stoped");
} }
} catch (Exception e) { } catch (Exception e) {
Log.d(LOGTAG,"otr execption"); if (!justStarted) {
if (justStarted) {
Log.d(LOGTAG,"ran into safeguard");
} else {
Log.d(LOGTAG,"resett otr session");
conversation.resetOtrSession(); conversation.resetOtrSession();
} }
return null; return null;

View file

@ -524,7 +524,7 @@ public class XmppConnection implements Runnable {
private void sendBindRequest() throws IOException { private void sendBindRequest() throws IOException {
IqPacket iq = new IqPacket(IqPacket.TYPE_SET); IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
iq.addChild("bind", "urn:ietf:params:xml:ns:xmpp-bind").addChild("resource").setContent("Conversations"); iq.addChild("bind", "urn:ietf:params:xml:ns:xmpp-bind").addChild("resource").setContent(account.getResource());
this.sendIqPacket(iq, new OnIqPacketReceived() { this.sendIqPacket(iq, new OnIqPacketReceived() {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(Account account, IqPacket packet) {

View file

@ -1,6 +1,5 @@
package eu.siacs.conversations.xmpp.stanzas; package eu.siacs.conversations.xmpp.stanzas;
import android.graphics.YuvImage;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;