aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/Config.java6
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlService.java34
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlServiceImpl.java189
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlServiceStub.java81
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java92
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/Message.java24
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/MucOptions.java13
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/Roster.java16
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/Transferable.java9
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java7
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java144
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java20
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/parser/PresenceParser.java8
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java7
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/ExportLogsService.java2
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java82
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConferenceDetailsActivity.java2
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java2
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java122
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java34
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java14
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ExportLogsPreference.java7
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java4
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/PublishProfilePictureActivity.java60
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java89
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java3
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/TrustKeysActivity.java189
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java18
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java60
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/UIHelper.java5
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java8
31 files changed, 874 insertions, 477 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/Config.java b/src/main/java/de/thedevstack/conversationsplus/Config.java
index 71227be0..2f35ad6e 100644
--- a/src/main/java/de/thedevstack/conversationsplus/Config.java
+++ b/src/main/java/de/thedevstack/conversationsplus/Config.java
@@ -22,10 +22,6 @@ public final class Config {
return (ENCRYPTION_MASK & OPENPGP) != 0;
}
- public static boolean supportOpenPgpOnly() {
- return supportOpenPgp() && !multipleEncryptionChoices();
- }
-
public static boolean supportOtr() {
return (ENCRYPTION_MASK & OTR) != 0;
}
@@ -45,7 +41,7 @@ public final class Config {
public static final String CONFERENCE_DOMAIN_LOCK = null; //only allow conference creation for this domain
public static final boolean LOCK_DOMAINS_IN_CONVERSATIONS = false; //only add contacts and conferences for own domains
- public static final boolean SINGLE_ACCOUNT = false; //set to true to allow only one account
+ public static final boolean LOCK_SETTINGS = false; //set to true to disallow account and settings editing
public static final boolean DISALLOW_REGISTRATION_IN_UI = false; //hide the register checkbox
public static final boolean ALLOW_NON_TLS_CONNECTIONS = false; //very dangerous. you should have a good reason to set this to true
diff --git a/src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlService.java b/src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlService.java
index 987cf940..49cd6033 100644
--- a/src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlService.java
+++ b/src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlService.java
@@ -9,6 +9,7 @@ import org.whispersystems.libaxolotl.state.PreKeyRecord;
import org.whispersystems.libaxolotl.state.SignedPreKeyRecord;
import java.security.cert.X509Certificate;
+import java.util.List;
import java.util.Set;
import de.thedevstack.conversationsplus.entities.Account;
@@ -30,6 +31,8 @@ public interface AxolotlService extends OnAdvancedStreamFeaturesLoaded {
String PEP_BUNDLES = PEP_PREFIX + ".bundles";
String PEP_VERIFICATION = PEP_PREFIX + ".verification";
+ int NUM_KEYS_TO_PUBLISH = 100;
+
enum FetchStatus {
PENDING,
SUCCESS,
@@ -38,15 +41,10 @@ public interface AxolotlService extends OnAdvancedStreamFeaturesLoaded {
ERROR
}
- boolean fetchMapHasErrors(Contact contact);
-
String getOwnFingerprint();
Set<IdentityKey> getKeysWithTrust(XmppAxolotlSession.Trust trust);
- Set<IdentityKey> getKeysWithTrust(XmppAxolotlSession.Trust trust, Contact contact);
-
- long getNumTrustedKeys(Contact contact);
Set<String> getFingerprintsForOwnSessions();
@@ -77,8 +75,6 @@ public interface AxolotlService extends OnAdvancedStreamFeaturesLoaded {
void publishBundlesIfNeeded(boolean announce, boolean wipe);
- boolean isContactAxolotlCapable(Contact contact);
-
XmppAxolotlSession.Trust getFingerprintTrust(String fingerprint);
X509Certificate getFingerprintCertificate(String fingerprint);
@@ -87,24 +83,36 @@ public interface AxolotlService extends OnAdvancedStreamFeaturesLoaded {
Set<AxolotlAddress> findDevicesWithoutSession(Conversation conversation);
- Set<AxolotlAddress> findDevicesWithoutSession(Jid contactJid);
-
boolean createSessionsIfNeeded(Conversation conversation);
boolean trustedSessionVerified(Conversation conversation);
- boolean hasPendingKeyFetches(Account account, Contact contact);
-
@Nullable
XmppAxolotlMessage encrypt(Message message);
void preparePayloadMessage(Message message, boolean delay);
- void prepareKeyTransportMessage(Contact contact, OnMessageCreatedCallback onMessageCreatedCallback);
-
XmppAxolotlMessage fetchAxolotlMessageFromCache(Message message);
XmppAxolotlMessage.XmppAxolotlPlaintextMessage processReceivingPayloadMessage(XmppAxolotlMessage message);
XmppAxolotlMessage.XmppAxolotlKeyTransportMessage processReceivingKeyTransportMessage(XmppAxolotlMessage message);
+
+ boolean fetchMapHasErrors(List<Jid> jids);
+
+ Set<IdentityKey> getKeysWithTrust(XmppAxolotlSession.Trust trust, Jid jid);
+
+ Set<IdentityKey> getKeysWithTrust(XmppAxolotlSession.Trust trust, List<Jid> jids);
+
+ long getNumTrustedKeys(Jid jid);
+
+ boolean anyTargetHasNoTrustedKeys(List<Jid> jids);
+
+ boolean isConversationAxolotlCapable(Conversation conversation);
+
+ List<Jid> getCryptoTargets(Conversation conversation);
+
+ boolean hasPendingKeyFetches(Account account, List<Jid> jids);
+
+ void prepareKeyTransportMessage(Conversation conversation, OnMessageCreatedCallback onMessageCreatedCallback);
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlServiceImpl.java b/src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlServiceImpl.java
index 5a05b34c..2463a795 100644
--- a/src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlServiceImpl.java
+++ b/src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlServiceImpl.java
@@ -50,7 +50,6 @@ import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket;
public class AxolotlServiceImpl implements AxolotlService {
- public static final int NUM_KEYS_TO_PUBLISH = 100;
public static final int publishTriesThreshold = 3;
private final Account account;
@@ -74,13 +73,14 @@ public class AxolotlServiceImpl implements AxolotlService {
}
@Override
- public boolean fetchMapHasErrors(Contact contact) {
- Jid jid = contact.getJid().toBareJid();
- if (deviceIds.get(jid) != null) {
- for (Integer foreignId : this.deviceIds.get(jid)) {
- AxolotlAddress address = new AxolotlAddress(jid.toString(), foreignId);
- if (fetchStatusMap.getAll(address).containsValue(FetchStatus.ERROR)) {
- return true;
+ public boolean fetchMapHasErrors(List<Jid> jids) {
+ for(Jid jid : jids) {
+ if (deviceIds.get(jid) != null) {
+ for (Integer foreignId : this.deviceIds.get(jid)) {
+ AxolotlAddress address = new AxolotlAddress(jid.toString(), foreignId);
+ if (fetchStatusMap.getAll(address).containsValue(FetchStatus.ERROR)) {
+ return true;
+ }
}
}
}
@@ -219,24 +219,41 @@ public class AxolotlServiceImpl implements AxolotlService {
this.executor = new SerialSingleThreadExecutor();
}
- @Override
public String getOwnFingerprint() {
return axolotlStore.getIdentityKeyPair().getPublicKey().getFingerprint().replaceAll("\\s", "");
}
- @Override
public Set<IdentityKey> getKeysWithTrust(XmppAxolotlSession.Trust trust) {
return axolotlStore.getContactKeysWithTrust(account.getJid().toBareJid().toString(), trust);
}
@Override
- public Set<IdentityKey> getKeysWithTrust(XmppAxolotlSession.Trust trust, Contact contact) {
- return axolotlStore.getContactKeysWithTrust(contact.getJid().toBareJid().toString(), trust);
+ public Set<IdentityKey> getKeysWithTrust(XmppAxolotlSession.Trust trust, Jid jid) {
+ return axolotlStore.getContactKeysWithTrust(jid.toBareJid().toString(), trust);
+ }
+
+ @Override
+ public Set<IdentityKey> getKeysWithTrust(XmppAxolotlSession.Trust trust, List<Jid> jids) {
+ Set<IdentityKey> keys = new HashSet<>();
+ for(Jid jid : jids) {
+ keys.addAll(axolotlStore.getContactKeysWithTrust(jid.toString(), trust));
+ }
+ return keys;
+ }
+
+ @Override
+ public long getNumTrustedKeys(Jid jid) {
+ return axolotlStore.getContactNumTrustedKeys(jid.toBareJid().toString());
}
@Override
- public long getNumTrustedKeys(Contact contact) {
- return axolotlStore.getContactNumTrustedKeys(contact.getJid().toBareJid().toString());
+ public boolean anyTargetHasNoTrustedKeys(List<Jid> jids) {
+ for(Jid jid : jids) {
+ if (axolotlStore.getContactNumTrustedKeys(jid.toBareJid().toString()) == 0) {
+ return true;
+ }
+ }
+ return false;
}
private AxolotlAddress getAddressForJid(Jid jid) {
@@ -248,12 +265,19 @@ public class AxolotlServiceImpl implements AxolotlService {
return new HashSet<>(this.sessions.getAll(ownAddress).values());
}
- private Set<XmppAxolotlSession> findSessionsforContact(Contact contact) {
+ private Set<XmppAxolotlSession> findSessionsForContact(Contact contact) {
AxolotlAddress contactAddress = getAddressForJid(contact.getJid());
return new HashSet<>(this.sessions.getAll(contactAddress).values());
}
- @Override
+ private Set<XmppAxolotlSession> findSessionsForConversation(Conversation conversation) {
+ HashSet<XmppAxolotlSession> sessions = new HashSet<>();
+ for(Jid jid : conversation.getAcceptedCryptoTargets()) {
+ sessions.addAll(this.sessions.getAll(getAddressForJid(jid)).values());
+ }
+ return sessions;
+ }
+
public Set<String> getFingerprintsForOwnSessions() {
Set<String> fingerprints = new HashSet<>();
for (XmppAxolotlSession session : findOwnSessions()) {
@@ -262,26 +286,22 @@ public class AxolotlServiceImpl implements AxolotlService {
return fingerprints;
}
- @Override
public Set<String> getFingerprintsForContact(final Contact contact) {
Set<String> fingerprints = new HashSet<>();
- for (XmppAxolotlSession session : findSessionsforContact(contact)) {
+ for (XmppAxolotlSession session : findSessionsForContact(contact)) {
fingerprints.add(session.getFingerprint());
}
return fingerprints;
}
- private boolean hasAny(Contact contact) {
- AxolotlAddress contactAddress = getAddressForJid(contact.getJid());
- return sessions.hasAny(contactAddress);
+ private boolean hasAny(Jid jid) {
+ return sessions.hasAny(getAddressForJid(jid));
}
- @Override
public boolean isPepBroken() {
return this.pepBroken;
}
- @Override
public void regenerateKeys(boolean wipeOther) {
axolotlStore.regenerate();
sessions.clear();
@@ -289,19 +309,17 @@ public class AxolotlServiceImpl implements AxolotlService {
publishBundlesIfNeeded(true, wipeOther);
}
- @Override
public int getOwnDeviceId() {
return axolotlStore.getLocalRegistrationId();
}
- @Override
public Set<Integer> getOwnDeviceIds() {
return this.deviceIds.get(account.getJid().toBareJid());
}
private void setTrustOnSessions(final Jid jid, @NonNull final Set<Integer> deviceIds,
- final XmppAxolotlSession.Trust from,
- final XmppAxolotlSession.Trust to) {
+ final XmppAxolotlSession.Trust from,
+ final XmppAxolotlSession.Trust to) {
for (Integer deviceId : deviceIds) {
AxolotlAddress address = new AxolotlAddress(jid.toBareJid().toString(), deviceId);
XmppAxolotlSession session = sessions.get(address);
@@ -312,7 +330,6 @@ public class AxolotlServiceImpl implements AxolotlService {
}
}
- @Override
public void registerDevices(final Jid jid, @NonNull final Set<Integer> deviceIds) {
if (jid.toBareJid().equals(account.getJid().toBareJid())) {
if (!deviceIds.isEmpty()) {
@@ -355,7 +372,6 @@ public class AxolotlServiceImpl implements AxolotlService {
mXmppConnectionService.keyStatusUpdated(null);
}
- @Override
public void wipeOtherPepDevices() {
if (pepBroken) {
Log.d(Config.LOGTAG, getLogprefix(account) + "wipeOtherPepDevices called, but PEP is broken. Ignoring... ");
@@ -373,12 +389,10 @@ public class AxolotlServiceImpl implements AxolotlService {
});
}
- @Override
public void purgeKey(final String fingerprint) {
axolotlStore.setFingerprintTrust(fingerprint.replaceAll("\\s", ""), XmppAxolotlSession.Trust.COMPROMISED);
}
- @Override
public void publishOwnDeviceIdIfNeeded() {
if (pepBroken) {
Log.d(Config.LOGTAG, getLogprefix(account) + "publishOwnDeviceIdIfNeeded called, but PEP is broken. Ignoring... ");
@@ -401,7 +415,6 @@ public class AxolotlServiceImpl implements AxolotlService {
});
}
- @Override
public void publishOwnDeviceId(Set<Integer> deviceIds) {
Set<Integer> deviceIdsCopy = new HashSet<>(deviceIds);
if (!deviceIdsCopy.contains(getOwnDeviceId())) {
@@ -431,7 +444,6 @@ public class AxolotlServiceImpl implements AxolotlService {
}
}
- @Override
public void publishDeviceVerificationAndBundle(final SignedPreKeyRecord signedPreKeyRecord,
final Set<PreKeyRecord> preKeyRecords,
final boolean announceAfter,
@@ -457,7 +469,6 @@ public class AxolotlServiceImpl implements AxolotlService {
}
}
- @Override
public void publishBundlesIfNeeded(final boolean announce, final boolean wipe) {
if (pepBroken) {
Log.d(Config.LOGTAG, getLogprefix(account) + "publishBundlesIfNeeded called, but PEP is broken. Ignoring... ");
@@ -597,23 +608,36 @@ public class AxolotlServiceImpl implements AxolotlService {
}
@Override
- public boolean isContactAxolotlCapable(Contact contact) {
- Jid jid = contact.getJid().toBareJid();
- return hasAny(contact) ||
- (deviceIds.containsKey(jid) && !deviceIds.get(jid).isEmpty());
+ public boolean isConversationAxolotlCapable(Conversation conversation) {
+ final List<Jid> jids = getCryptoTargets(conversation);
+ for(Jid jid : jids) {
+ if (!hasAny(jid) && (!deviceIds.containsKey(jid) || deviceIds.get(jid).isEmpty())) {
+ return false;
+ }
+ }
+ return jids.size() > 0;
}
@Override
+ public List<Jid> getCryptoTargets(Conversation conversation) {
+ final List<Jid> jids;
+ if (conversation.getMode() == Conversation.MODE_SINGLE) {
+ jids = Arrays.asList(conversation.getJid().toBareJid());
+ } else {
+ jids = conversation.getMucOptions().getMembers();
+ jids.remove(account.getJid().toBareJid());
+ }
+ return jids;
+ }
+
public XmppAxolotlSession.Trust getFingerprintTrust(String fingerprint) {
return axolotlStore.getFingerprintTrust(fingerprint);
}
- @Override
public X509Certificate getFingerprintCertificate(String fingerprint) {
return axolotlStore.getFingerprintCertificate(fingerprint);
}
- @Override
public void setFingerprintTrust(String fingerprint, XmppAxolotlSession.Trust trust) {
axolotlStore.setFingerprintTrust(fingerprint, trust);
}
@@ -758,36 +782,32 @@ public class AxolotlServiceImpl implements AxolotlService {
}
}
- @Override
public Set<AxolotlAddress> findDevicesWithoutSession(final Conversation conversation) {
- return findDevicesWithoutSession(conversation.getContact().getJid().toBareJid());
- }
-
- @Override
- public Set<AxolotlAddress> findDevicesWithoutSession(final Jid contactJid) {
- Log.d(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(account) + "Finding devices without session for " + contactJid);
Set<AxolotlAddress> addresses = new HashSet<>();
- if (deviceIds.get(contactJid) != null) {
- for (Integer foreignId : this.deviceIds.get(contactJid)) {
- AxolotlAddress address = new AxolotlAddress(contactJid.toString(), foreignId);
- if (sessions.get(address) == null) {
- IdentityKey identityKey = axolotlStore.loadSession(address).getSessionState().getRemoteIdentityKey();
- if (identityKey != null) {
- Log.d(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(account) + "Already have session for " + address.toString() + ", adding to cache...");
- XmppAxolotlSession session = new XmppAxolotlSession(account, axolotlStore, address, identityKey);
- sessions.put(address, session);
- } else {
- Log.d(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(account) + "Found device " + contactJid + ":" + foreignId);
- if (fetchStatusMap.get(address) != FetchStatus.ERROR) {
- addresses.add(address);
+ for(Jid jid : getCryptoTargets(conversation)) {
+ Log.d(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(account) + "Finding devices without session for " + jid);
+ if (deviceIds.get(jid) != null) {
+ for (Integer foreignId : this.deviceIds.get(jid)) {
+ AxolotlAddress address = new AxolotlAddress(jid.toString(), foreignId);
+ if (sessions.get(address) == null) {
+ IdentityKey identityKey = axolotlStore.loadSession(address).getSessionState().getRemoteIdentityKey();
+ if (identityKey != null) {
+ Log.d(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(account) + "Already have session for " + address.toString() + ", adding to cache...");
+ XmppAxolotlSession session = new XmppAxolotlSession(account, axolotlStore, address, identityKey);
+ sessions.put(address, session);
} else {
- Log.d(Config.LOGTAG,getLogprefix(account)+"skipping over "+address+" because it's broken");
+ Log.d(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(account) + "Found device " + jid + ":" + foreignId);
+ if (fetchStatusMap.get(address) != FetchStatus.ERROR) {
+ addresses.add(address);
+ } else {
+ Log.d(Config.LOGTAG, getLogprefix(account) + "skipping over " + address + " because it's broken");
+ }
}
}
}
+ } else {
+ Log.w(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(account) + "Have no target devices in PEP!");
}
- } else {
- Log.w(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(account) + "Have no target devices in PEP!");
}
if (deviceIds.get(account.getJid().toBareJid()) != null) {
for (Integer ownId : this.deviceIds.get(account.getJid().toBareJid())) {
@@ -813,7 +833,6 @@ public class AxolotlServiceImpl implements AxolotlService {
return addresses;
}
- @Override
public boolean createSessionsIfNeeded(final Conversation conversation) {
Log.i(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(account) + "Creating axolotl sessions if needed...");
boolean newSessions = false;
@@ -835,9 +854,8 @@ public class AxolotlServiceImpl implements AxolotlService {
return newSessions;
}
- @Override
public boolean trustedSessionVerified(final Conversation conversation) {
- Set<XmppAxolotlSession> sessions = findSessionsforContact(conversation.getContact());
+ Set<XmppAxolotlSession> sessions = findSessionsForConversation(conversation);
sessions.addAll(findOwnSessions());
boolean verified = false;
for(XmppAxolotlSession session : sessions) {
@@ -853,26 +871,32 @@ public class AxolotlServiceImpl implements AxolotlService {
}
@Override
- public boolean hasPendingKeyFetches(Account account, Contact contact) {
+ public boolean hasPendingKeyFetches(Account account, List<Jid> jids) {
AxolotlAddress ownAddress = new AxolotlAddress(account.getJid().toBareJid().toString(), 0);
- AxolotlAddress foreignAddress = new AxolotlAddress(contact.getJid().toBareJid().toString(), 0);
- return fetchStatusMap.getAll(ownAddress).containsValue(FetchStatus.PENDING)
- || fetchStatusMap.getAll(foreignAddress).containsValue(FetchStatus.PENDING);
-
+ if (fetchStatusMap.getAll(ownAddress).containsValue(FetchStatus.PENDING)) {
+ return true;
+ }
+ for(Jid jid : jids) {
+ AxolotlAddress foreignAddress = new AxolotlAddress(jid.toBareJid().toString(), 0);
+ if (fetchStatusMap.getAll(foreignAddress).containsValue(FetchStatus.PENDING)) {
+ return true;
+ }
+ }
+ return false;
}
@Nullable
- private XmppAxolotlMessage buildHeader(Contact contact) {
+ private XmppAxolotlMessage buildHeader(Conversation conversation) {
final XmppAxolotlMessage axolotlMessage = new XmppAxolotlMessage(
- contact.getJid().toBareJid(), getOwnDeviceId());
+ account.getJid().toBareJid(), getOwnDeviceId());
- Set<XmppAxolotlSession> contactSessions = findSessionsforContact(contact);
+ Set<XmppAxolotlSession> remoteSessions = findSessionsForConversation(conversation);
Set<XmppAxolotlSession> ownSessions = findOwnSessions();
- if (contactSessions.isEmpty()) {
+ if (remoteSessions.isEmpty()) {
return null;
}
Log.d(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(account) + "Building axolotl foreign keyElements...");
- for (XmppAxolotlSession session : contactSessions) {
+ for (XmppAxolotlSession session : remoteSessions) {
Log.v(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(account) + session.getRemoteAddress().toString());
axolotlMessage.addDevice(session);
}
@@ -885,10 +909,9 @@ public class AxolotlServiceImpl implements AxolotlService {
return axolotlMessage;
}
- @Override
@Nullable
public XmppAxolotlMessage encrypt(Message message) {
- XmppAxolotlMessage axolotlMessage = buildHeader(message.getContact());
+ XmppAxolotlMessage axolotlMessage = buildHeader(message.getConversation());
if (axolotlMessage != null) {
final String content;
@@ -908,7 +931,6 @@ public class AxolotlServiceImpl implements AxolotlService {
return axolotlMessage;
}
- @Override
public void preparePayloadMessage(final Message message, final boolean delay) {
executor.execute(new Runnable() {
@Override
@@ -927,17 +949,16 @@ public class AxolotlServiceImpl implements AxolotlService {
}
@Override
- public void prepareKeyTransportMessage(final Contact contact, final OnMessageCreatedCallback onMessageCreatedCallback) {
+ public void prepareKeyTransportMessage(final Conversation conversation, final OnMessageCreatedCallback onMessageCreatedCallback) {
executor.execute(new Runnable() {
@Override
public void run() {
- XmppAxolotlMessage axolotlMessage = buildHeader(contact);
+ XmppAxolotlMessage axolotlMessage = buildHeader(conversation);
onMessageCreatedCallback.run(axolotlMessage);
}
});
}
- @Override
public XmppAxolotlMessage fetchAxolotlMessageFromCache(Message message) {
XmppAxolotlMessage axolotlMessage = messageCache.get(message.getUuid());
if (axolotlMessage != null) {
@@ -970,7 +991,6 @@ public class AxolotlServiceImpl implements AxolotlService {
return session;
}
- @Override
public XmppAxolotlMessage.XmppAxolotlPlaintextMessage processReceivingPayloadMessage(XmppAxolotlMessage message) {
XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = null;
@@ -993,7 +1013,6 @@ public class AxolotlServiceImpl implements AxolotlService {
return plaintextMessage;
}
- @Override
public XmppAxolotlMessage.XmppAxolotlKeyTransportMessage processReceivingKeyTransportMessage(XmppAxolotlMessage message) {
XmppAxolotlMessage.XmppAxolotlKeyTransportMessage keyTransportMessage;
@@ -1018,4 +1037,4 @@ public class AxolotlServiceImpl implements AxolotlService {
}
}
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlServiceStub.java b/src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlServiceStub.java
index a07905ab..858cdf08 100644
--- a/src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlServiceStub.java
+++ b/src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlServiceStub.java
@@ -10,6 +10,7 @@ import org.whispersystems.libaxolotl.state.SignedPreKeyRecord;
import java.security.cert.X509Certificate;
import java.util.Collections;
+import java.util.List;
import java.util.Set;
import de.thedevstack.conversationsplus.entities.Account;
@@ -24,11 +25,6 @@ import de.thedevstack.conversationsplus.xmpp.jid.Jid;
public class AxolotlServiceStub implements AxolotlService {
@Override
- public boolean fetchMapHasErrors(Contact contact) {
- return false;
- }
-
- @Override
public String getOwnFingerprint() {
return null;
}
@@ -39,16 +35,6 @@ public class AxolotlServiceStub implements AxolotlService {
}
@Override
- public Set<IdentityKey> getKeysWithTrust(XmppAxolotlSession.Trust trust, Contact contact) {
- return Collections.emptySet();
- }
-
- @Override
- public long getNumTrustedKeys(Contact contact) {
- return 0;
- }
-
- @Override
public Set<String> getFingerprintsForOwnSessions() {
return Collections.emptySet();
}
@@ -114,11 +100,6 @@ public class AxolotlServiceStub implements AxolotlService {
}
@Override
- public boolean isContactAxolotlCapable(Contact contact) {
- return false;
- }
-
- @Override
public XmppAxolotlSession.Trust getFingerprintTrust(String fingerprint) {
return XmppAxolotlSession.Trust.TRUSTED;
}
@@ -139,11 +120,6 @@ public class AxolotlServiceStub implements AxolotlService {
}
@Override
- public Set<AxolotlAddress> findDevicesWithoutSession(Jid contactJid) {
- return Collections.emptySet();
- }
-
- @Override
public boolean createSessionsIfNeeded(Conversation conversation) {
return false;
}
@@ -153,11 +129,6 @@ public class AxolotlServiceStub implements AxolotlService {
return false;
}
- @Override
- public boolean hasPendingKeyFetches(Account account, Contact contact) {
- return false;
- }
-
@Nullable
@Override
public XmppAxolotlMessage encrypt(Message message) {
@@ -170,11 +141,6 @@ public class AxolotlServiceStub implements AxolotlService {
}
@Override
- public void prepareKeyTransportMessage(Contact contact, OnMessageCreatedCallback onMessageCreatedCallback) {
-
- }
-
- @Override
public XmppAxolotlMessage fetchAxolotlMessageFromCache(Message message) {
return null;
}
@@ -190,6 +156,51 @@ public class AxolotlServiceStub implements AxolotlService {
}
@Override
+ public boolean fetchMapHasErrors(List<Jid> jids) {
+ return false;
+ }
+
+ @Override
+ public Set<IdentityKey> getKeysWithTrust(XmppAxolotlSession.Trust trust, Jid jid) {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Set<IdentityKey> getKeysWithTrust(XmppAxolotlSession.Trust trust, List<Jid> jids) {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public long getNumTrustedKeys(Jid jid) {
+ return 0;
+ }
+
+ @Override
+ public boolean anyTargetHasNoTrustedKeys(List<Jid> jids) {
+ return false;
+ }
+
+ @Override
+ public boolean isConversationAxolotlCapable(Conversation conversation) {
+ return false;
+ }
+
+ @Override
+ public List<Jid> getCryptoTargets(Conversation conversation) {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public boolean hasPendingKeyFetches(Account account, List<Jid> jids) {
+ return false;
+ }
+
+ @Override
+ public void prepareKeyTransportMessage(Conversation conversation, OnMessageCreatedCallback onMessageCreatedCallback) {
+
+ }
+
+ @Override
public void onAdvancedStreamFeaturesAvailable(Account account) {
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java b/src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java
index 0b70d938..b822ef0e 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java
@@ -9,11 +9,13 @@ import net.java.otr4j.session.SessionID;
import net.java.otr4j.session.SessionImpl;
import net.java.otr4j.session.SessionStatus;
+import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.security.interfaces.DSAPublicKey;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
@@ -49,6 +51,7 @@ public class Conversation extends AbstractEntity implements Blockable {
public static final String ATTRIBUTE_MUC_PASSWORD = "muc_password";
public static final String ATTRIBUTE_MUTED_TILL = "muted_till";
public static final String ATTRIBUTE_ALWAYS_NOTIFY = "always_notify";
+ public static final String ATTRIBUTE_CRYPTO_TARGETS = "crypto_targets";
private String name;
private String contactUuid;
@@ -306,6 +309,18 @@ public class Conversation extends AbstractEntity implements Blockable {
return this.mFirstMamReference;
}
+ public List<Jid> getAcceptedCryptoTargets() {
+ if (mode == MODE_SINGLE) {
+ return Arrays.asList(getJid().toBareJid());
+ } else {
+ return getJidListAttribute(ATTRIBUTE_CRYPTO_TARGETS);
+ }
+ }
+
+ public void setAcceptedCryptoTargets(List<Jid> acceptedTargets) {
+ setAttribute(ATTRIBUTE_CRYPTO_TARGETS, acceptedTargets);
+ }
+
public void setCorrectingMessage(Message correctingMessage) {
this.correctingMessage = correctingMessage;
}
@@ -652,8 +667,8 @@ public class Conversation extends AbstractEntity implements Blockable {
final AxolotlService axolotlService = getAccount().getAxolotlService();
int next = this.getIntAttribute(ATTRIBUTE_NEXT_ENCRYPTION, -1);
if (next == -1) {
- if (Config.X509_VERIFICATION && mode == MODE_SINGLE) {
- if (axolotlService != null && axolotlService.isContactAxolotlCapable(getContact())) {
+ if (Config.X509_VERIFICATION) {
+ if (axolotlService != null && axolotlService.isConversationAxolotlCapable(this)) {
return Message.ENCRYPTION_AXOLOTL;
} else {
return Message.ENCRYPTION_NONE;
@@ -666,16 +681,20 @@ public class Conversation extends AbstractEntity implements Blockable {
next = outgoing;
}
}
- if (!Config.supportUnencrypted()
- && (mode == MODE_SINGLE || Config.supportOpenPgpOnly())
- && next <= 0) {
- if (Config.supportOmemo() && (axolotlService != null && axolotlService.isContactAxolotlCapable(getContact()) || !Config.multipleEncryptionChoices())) {
+
+ if (!Config.supportUnencrypted() && next <= 0) {
+ if (Config.supportOmemo()
+ && (axolotlService != null && axolotlService.isConversationAxolotlCapable(this) || !Config.multipleEncryptionChoices())) {
return Message.ENCRYPTION_AXOLOTL;
- } else if (Config.supportOtr()) {
+ } else if (Config.supportOtr() && mode == MODE_SINGLE) {
return Message.ENCRYPTION_OTR;
- } else if (Config.supportOpenPgp()) {
+ } else if (Config.supportOpenPgp()
+ && (mode == MODE_SINGLE) || !Config.multipleEncryptionChoices()) {
return Message.ENCRYPTION_PGP;
}
+ } else if (next == Message.ENCRYPTION_AXOLOTL
+ && (!Config.supportOmemo() || axolotlService == null || !axolotlService.isConversationAxolotlCapable(this))) {
+ next = Message.ENCRYPTION_NONE;
}
return next;
}
@@ -779,20 +798,59 @@ public class Conversation extends AbstractEntity implements Blockable {
}
public boolean setAttribute(String key, String value) {
- try {
- this.attributes.put(key, value);
- return true;
- } catch (JSONException e) {
- return false;
+ synchronized (this.attributes) {
+ try {
+ this.attributes.put(key, value);
+ return true;
+ } catch (JSONException e) {
+ return false;
+ }
+ }
+ }
+
+ public boolean setAttribute(String key, List<Jid> jids) {
+ JSONArray array = new JSONArray();
+ for(Jid jid : jids) {
+ array.put(jid.toBareJid().toString());
+ }
+ synchronized (this.attributes) {
+ try {
+ this.attributes.put(key, array);
+ return true;
+ } catch (JSONException e) {
+ e.printStackTrace();
+ return false;
+ }
}
}
public String getAttribute(String key) {
- try {
- return this.attributes.getString(key);
- } catch (JSONException e) {
- return null;
+ synchronized (this.attributes) {
+ try {
+ return this.attributes.getString(key);
+ } catch (JSONException e) {
+ return null;
+ }
+ }
+ }
+
+ public List<Jid> getJidListAttribute(String key) {
+ ArrayList<Jid> list = new ArrayList<>();
+ synchronized (this.attributes) {
+ try {
+ JSONArray array = this.attributes.getJSONArray(key);
+ for (int i = 0; i < array.length(); ++i) {
+ try {
+ list.add(Jid.fromString(array.getString(i)));
+ } catch (InvalidJidException e) {
+ //ignored
+ }
+ }
+ } catch (JSONException e) {
+ //ignored
+ }
}
+ return list;
}
public int getIntAttribute(String key, int defaultValue) {
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Message.java b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
index d03cab92..f1da885e 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
@@ -51,6 +51,7 @@ public class Message extends AbstractEntity {
public static final String STATUS = "status";
public static final String TYPE = "type";
public static final String CARBON = "carbon";
+ public static final String OOB = "oob";
public static final String EDITED = "edited";
public static final String REMOTE_MSG_ID = "remoteMsgId";
public static final String SERVER_MSG_ID = "serverMsgId";
@@ -71,6 +72,7 @@ public class Message extends AbstractEntity {
protected int status;
protected int type;
protected boolean carbon = false;
+ protected boolean oob = false;
protected String edited = null;
protected String relativeFilePath;
protected boolean read = true;
@@ -106,7 +108,8 @@ public class Message extends AbstractEntity {
null,
null,
true,
- null);
+ null,
+ false);
this.conversation = conversation;
}
@@ -115,7 +118,7 @@ public class Message extends AbstractEntity {
final int encryption, final int status, final int type, final boolean carbon,
final String remoteMsgId, final String relativeFilePath,
final String serverMsgId, final String fingerprint, final boolean read,
- final String edited) {
+ final String edited, final boolean oob) {
this.uuid = uuid;
this.conversationUuid = conversationUUid;
this.counterpart = counterpart;
@@ -132,6 +135,7 @@ public class Message extends AbstractEntity {
this.axolotlFingerprint = fingerprint;
this.read = read;
this.edited = edited;
+ this.oob = oob;
}
public static Message fromCursor(Cursor cursor) {
@@ -172,7 +176,8 @@ public class Message extends AbstractEntity {
cursor.getString(cursor.getColumnIndex(SERVER_MSG_ID)),
cursor.getString(cursor.getColumnIndex(FINGERPRINT)),
cursor.getInt(cursor.getColumnIndex(READ)) > 0,
- cursor.getString(cursor.getColumnIndex(EDITED)));
+ cursor.getString(cursor.getColumnIndex(EDITED)),
+ cursor.getInt(cursor.getColumnIndex(OOB)) > 0);
}
public static Message createStatusMessage(Conversation conversation, String body) {
@@ -210,6 +215,7 @@ public class Message extends AbstractEntity {
values.put(FINGERPRINT, axolotlFingerprint);
values.put(READ,read ? 1 : 0);
values.put(EDITED, edited);
+ values.put(OOB, oob ? 1 : 0);
return values;
}
@@ -543,6 +549,10 @@ public class Message extends AbstractEntity {
return edited;
}
+ public void setOob(boolean isOob) {
+ this.oob = isOob;
+ }
+
public enum Decision {
MUST,
SHOULD,
@@ -565,7 +575,7 @@ public class Message extends AbstractEntity {
if (dotPosition != -1) {
String extension = filename.substring(dotPosition + 1);
// we want the real file extension, not the crypto one
- if (Arrays.asList(Transferable.VALID_CRYPTO_EXTENSIONS).contains(extension)) {
+ if (Transferable.VALID_CRYPTO_EXTENSIONS.contains(extension)) {
return extractRelevantExtension(filename.substring(0,dotPosition));
} else {
return extension;
@@ -604,6 +614,8 @@ public class Message extends AbstractEntity {
URL url = new URL(body);
if (!url.getProtocol().equalsIgnoreCase("http") && !url.getProtocol().equalsIgnoreCase("https")) {
return Decision.NEVER;
+ } else if (oob) {
+ return Decision.MUST;
}
String extension = extractRelevantExtension(url);
if (extension == null) {
@@ -618,8 +630,8 @@ public class Message extends AbstractEntity {
} else {
return Decision.NEVER;
}
- } else if (Arrays.asList(Transferable.VALID_IMAGE_EXTENSIONS).contains(extension)
- || Arrays.asList(Transferable.WELL_KNOWN_EXTENSIONS).contains(extension)) {
+ } else if (Transferable.VALID_IMAGE_EXTENSIONS.contains(extension)
+ || Transferable.WELL_KNOWN_EXTENSIONS.contains(extension)) {
return Decision.SHOULD;
} else {
return Decision.NEVER;
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/MucOptions.java b/src/main/java/de/thedevstack/conversationsplus/entities/MucOptions.java
index f0eb83de..128e5423 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/MucOptions.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/MucOptions.java
@@ -4,9 +4,11 @@ import android.annotation.SuppressLint;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.xmpp.forms.Data;
@@ -245,7 +247,8 @@ public class MucOptions {
private Account account;
private final Map<String, User> users = Collections.synchronizedMap(new LinkedHashMap<String, User>());
- private List<String> features = new ArrayList<>();
+ private final Set<Jid> members = Collections.synchronizedSet(new HashSet<Jid>());
+ private final List<String> features = new ArrayList<>();
private Data form = new Data();
private Conversation conversation;
private boolean isOnline = false;
@@ -501,4 +504,12 @@ public class MucOptions {
public Conversation getConversation() {
return this.conversation;
}
+
+ public void putMember(Jid jid) {
+ members.add(jid);
+ }
+
+ public List<Jid> getMembers() {
+ return new ArrayList<>(members);
+ }
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Roster.java b/src/main/java/de/thedevstack/conversationsplus/entities/Roster.java
index b1cb78b4..ec1a9426 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/Roster.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/Roster.java
@@ -9,7 +9,7 @@ import de.thedevstack.conversationsplus.xmpp.jid.Jid;
public class Roster {
final Account account;
- final HashMap<String, Contact> contacts = new HashMap<>();
+ final HashMap<Jid, Contact> contacts = new HashMap<>();
private String version = null;
public Roster(Account account) {
@@ -21,7 +21,7 @@ public class Roster {
return null;
}
synchronized (this.contacts) {
- Contact contact = contacts.get(jid.toBareJid().toString());
+ Contact contact = contacts.get(jid.toBareJid());
if (contact != null && contact.showInRoster()) {
return contact;
} else {
@@ -32,15 +32,13 @@ public class Roster {
public Contact getContact(final Jid jid) {
synchronized (this.contacts) {
- final Jid bareJid = jid.toBareJid();
- if (contacts.containsKey(bareJid.toString())) {
- return contacts.get(bareJid.toString());
- } else {
- Contact contact = new Contact(bareJid);
+ if (!contacts.containsKey(jid.toBareJid())) {
+ Contact contact = new Contact(jid.toBareJid());
contact.setAccount(account);
- contacts.put(bareJid.toString(), contact);
+ contacts.put(contact.getJid().toBareJid(), contact);
return contact;
}
+ return contacts.get(jid.toBareJid());
}
}
@@ -80,7 +78,7 @@ public class Roster {
contact.setAccount(account);
contact.setOption(Contact.Options.IN_ROSTER);
synchronized (this.contacts) {
- contacts.put(contact.getJid().toBareJid().toString(), contact);
+ contacts.put(contact.getJid().toBareJid(), contact);
}
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Transferable.java b/src/main/java/de/thedevstack/conversationsplus/entities/Transferable.java
index b03d0fe0..8e2ca20e 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/Transferable.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/Transferable.java
@@ -1,10 +1,13 @@
package de.thedevstack.conversationsplus.entities;
+import java.util.Arrays;
+import java.util.List;
+
public interface Transferable {
- String[] VALID_IMAGE_EXTENSIONS = {"webp", "jpeg", "jpg", "png", "jpe"};
- String[] VALID_CRYPTO_EXTENSIONS = {"pgp", "gpg", "otr"};
- String[] WELL_KNOWN_EXTENSIONS = {"pdf","m4a","mp4"};
+ List<String> VALID_IMAGE_EXTENSIONS = Arrays.asList("webp", "jpeg", "jpg", "png", "jpe");
+ List<String> VALID_CRYPTO_EXTENSIONS = Arrays.asList("pgp", "gpg", "otr");
+ List<String> WELL_KNOWN_EXTENSIONS = Arrays.asList("pdf","m4a","mp4","3gp","aac","amr","mp3");
int STATUS_UNKNOWN = 0x200;
int STATUS_CHECKING = 0x201;
diff --git a/src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java b/src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java
index df46f2b7..9df0cc21 100644
--- a/src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java
+++ b/src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java
@@ -292,4 +292,11 @@ public class IqGenerator extends AbstractGenerator {
enable.addChild(data);
return packet;
}
+
+ public IqPacket queryAffiliation(Conversation conversation, String affiliation) {
+ IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
+ packet.setTo(conversation.getJid().toBareJid());
+ packet.query("http://jabber.org/protocol/muc#admin").addChild("item").setAttribute("affiliation",affiliation);
+ return packet;
+ }
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java b/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java
index 0462defd..e7fbb5cd 100644
--- a/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java
+++ b/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java
@@ -3,13 +3,17 @@ package de.thedevstack.conversationsplus.http;
import android.content.Intent;
import android.net.Uri;
import android.os.PowerManager;
+import android.util.Log;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
import java.net.MalformedURLException;
+import java.net.Proxy;
import java.net.URL;
import java.util.Arrays;
import java.util.concurrent.CancellationException;
@@ -70,75 +74,76 @@ public class HttpDownloadConnection implements Transferable {
}
public void init(Message message, boolean interactive) {
- this.message = message;
- this.message.setTransferable(this);
- try {
- if (message.hasFileOnRemoteHost()) {
- mUrl = message.getFileParams().url;
- } else {
- mUrl = new URL(message.getBody());
- }
- String[] parts = mUrl.getPath().toLowerCase().split("\\.");
- String lastPart = parts.length >= 1 ? parts[parts.length - 1] : null;
- String secondToLast = parts.length >= 2 ? parts[parts.length -2] : null;
- if ("pgp".equals(lastPart) || "gpg".equals(lastPart)) {
- this.message.setEncryption(Message.ENCRYPTION_PGP);
- } else if (message.getEncryption() != Message.ENCRYPTION_OTR
- && message.getEncryption() != Message.ENCRYPTION_AXOLOTL) {
- this.message.setEncryption(Message.ENCRYPTION_NONE);
- }
- String extension;
- if (Arrays.asList(VALID_CRYPTO_EXTENSIONS).contains(lastPart)) {
- extension = secondToLast;
- } else {
- extension = lastPart;
- }
- message.setRelativeFilePath(message.getUuid()+"."+extension);
- this.file = FileBackend.getFile(message, false);
- String reference = mUrl.getRef();
- if (reference != null && reference.length() == 96) {
- this.file.setKeyAndIv(CryptoHelper.hexToBytes(reference));
- }
+ this.message = message;
+ this.message.setTransferable(this);
+ try {
+ if (message.hasFileOnRemoteHost()) {
+ mUrl = message.getFileParams().url;
+ } else {
+ mUrl = new URL(message.getBody());
+ }
+ String[] parts = mUrl.getPath().toLowerCase().split("\\.");
+ String lastPart = parts.length >= 1 ? parts[parts.length - 1] : null;
+ String secondToLast = parts.length >= 2 ? parts[parts.length -2] : null;
+ if ("pgp".equals(lastPart) || "gpg".equals(lastPart)) {
+ this.message.setEncryption(Message.ENCRYPTION_PGP);
+ } else if (message.getEncryption() != Message.ENCRYPTION_OTR
+ && message.getEncryption() != Message.ENCRYPTION_AXOLOTL) {
+ this.message.setEncryption(Message.ENCRYPTION_NONE);
+ }
+ String extension;
+ if (VALID_CRYPTO_EXTENSIONS.contains(lastPart)) {
+ extension = secondToLast;
+ } else {
+ extension = lastPart;
+ }
+ message.setRelativeFilePath(message.getUuid()+"."+extension);
+ this.file = FileBackend.getFile(message, false);
+ String reference = mUrl.getRef();
+ if (reference != null && reference.length() == 96) {
+ this.file.setKeyAndIv(CryptoHelper.hexToBytes(reference));
+ }
- if ((this.message.getEncryption() == Message.ENCRYPTION_OTR
- || this.message.getEncryption() == Message.ENCRYPTION_AXOLOTL)
- && this.file.getKey() == null) {
- this.message.setEncryption(Message.ENCRYPTION_NONE);
- }
- checkFileSize(interactive);
- } catch (MalformedURLException e) {
- this.cancel();
- }
+ if ((this.message.getEncryption() == Message.ENCRYPTION_OTR
+ || this.message.getEncryption() == Message.ENCRYPTION_AXOLOTL)
+ && this.file.getKey() == null) {
+ this.message.setEncryption(Message.ENCRYPTION_NONE);
+ }
+ checkFileSize(interactive);
+ } catch (MalformedURLException e) {
+ this.cancel();
+ }
}
private void checkFileSize(boolean interactive) {
new Thread(new FileSizeChecker(interactive)).start();
}
+ @Override
public void cancel() {
- this.canceled = true;
- mHttpConnectionManager.finishConnection(this);
- if (message.isFileOrImage()) {
- message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
- } else {
- message.setTransferable(null);
- }
- mXmppConnectionService.updateConversationUi();
+ this.canceled = true;
+ mHttpConnectionManager.finishConnection(this);
+ if (message.isFileOrImage()) {
+ message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
+ } else {
+ message.setTransferable(null);
+ }
+ mXmppConnectionService.updateConversationUi();
}
private void finish() {
- Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
- intent.setData(Uri.fromFile(file));
- mXmppConnectionService.sendBroadcast(intent);
- message.setTransferable(null);
- mHttpConnectionManager.finishConnection(this);
- if (message.getEncryption() == Message.ENCRYPTION_PGP) {
- message.getConversation().getAccount().getPgpDecryptionService().add(message);
- }
- mXmppConnectionService.updateConversationUi();
- if (acceptedAutomatically) {
- mXmppConnectionService.getNotificationService().push(message);
- }
+ Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
+ intent.setData(Uri.fromFile(file));
+ mXmppConnectionService.sendBroadcast(intent);
+ message.setTransferable(null);
+ mHttpConnectionManager.finishConnection(this);
+ if (message.getEncryption() == Message.ENCRYPTION_PGP) {
+ message.getConversation().getAccount().getPgpDecryptionService().add(message);
+ }
+ mXmppConnectionService.updateConversationUi();
+ if (acceptedAutomatically) {
+ mXmppConnectionService.getNotificationService().push(message);
+ }
}
private void changeStatus(int status) {
@@ -152,7 +157,7 @@ public class HttpDownloadConnection implements Transferable {
mXmppConnectionService.showErrorToastInUi(R.string.download_failed_server_not_found);
} else if (e instanceof java.net.ConnectException) {
mXmppConnectionService.showErrorToastInUi(R.string.download_failed_could_not_connect);
- } else if (!(e instanceof CancellationException)) {
+ } else if (!(e instanceof CancellationException)) {
mXmppConnectionService.showErrorToastInUi(R.string.download_failed_file_not_found);
}
}
@@ -176,7 +181,7 @@ public class HttpDownloadConnection implements Transferable {
HttpDownloadConnection.this.mXmppConnectionService.getNotificationService().push(message);
return;
} catch (IOException e) {
- Logging.d(Config.LOGTAG, "io exception in http file size checker: " + e.getMessage());
+ Log.d(Config.LOGTAG, "io exception in http file size checker: " + e.getMessage());
if (interactive) {
showToastForException(e);
}
@@ -184,7 +189,8 @@ public class HttpDownloadConnection implements Transferable {
return;
}
file.setExpectedSize(size);
- if (size != -1
+ if (mHttpConnectionManager.hasStoragePermission()
+ && size != -1
&& size <= ConversationsPlusPreferences.autoAcceptFileSize()
&& mXmppConnectionService.isDownloadAllowedInConnection()) {
HttpDownloadConnection.this.acceptedAutomatically = true;
@@ -221,13 +227,14 @@ public class HttpDownloadConnection implements Transferable {
return -1;
}
}
+
}
private class FileDownloader implements Runnable {
private boolean interactive = false;
- private OutputStream os;
+ private OutputStream os;
public FileDownloader(boolean interactive) {
this.interactive = interactive;
@@ -243,10 +250,10 @@ public class HttpDownloadConnection implements Transferable {
} catch (SSLHandshakeException e) {
changeStatus(STATUS_OFFER);
} catch (Exception e) {
- if (interactive) {
- showToastForException(e);
- }
- cancel();
+ if (interactive) {
+ showToastForException(e);
+ }
+ cancel();
}
}
@@ -312,11 +319,12 @@ public class HttpDownloadConnection implements Transferable {
MessageUtil.updateFileParams(message, mUrl);
mXmppConnectionService.updateMessage(message);
}
+
}
public void updateProgress(int i) {
- this.mProgress = i;
- mXmppConnectionService.updateConversationUi();
+ this.mProgress = i;
+ mXmppConnectionService.updateConversationUi();
}
@Override
diff --git a/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java b/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java
index ee6ef8b6..e64fe6a4 100644
--- a/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java
+++ b/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java
@@ -8,6 +8,7 @@ import de.tzur.conversations.Settings;
import net.java.otr4j.session.Session;
import net.java.otr4j.session.SessionStatus;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Set;
@@ -109,7 +110,7 @@ public class MessageParser extends AbstractParser implements
}
}
- private Message parseAxolotlChat(Element axolotlMessage, Jid from, String id, Conversation conversation, int status) {
+ private Message parseAxolotlChat(Element axolotlMessage, Jid from, Conversation conversation, int status) {
Message finishedMessage = null;
AxolotlService service = conversation.getAccount().getAxolotlService();
XmppAxolotlMessage xmppAxolotlMessage = XmppAxolotlMessage.fromElement(axolotlMessage, from.toBareJid());
@@ -117,7 +118,7 @@ public class MessageParser extends AbstractParser implements
if(plaintextMessage != null) {
finishedMessage = new Message(conversation, plaintextMessage.getPlaintext(), Message.ENCRYPTION_AXOLOTL, status);
finishedMessage.setAxolotlFingerprint(plaintextMessage.getFingerprint());
- Log.d(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(finishedMessage.getConversation().getAccount())+" Received Message with session fingerprint: "+plaintextMessage.getFingerprint());
+ Logging.d(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(finishedMessage.getConversation().getAccount())+" Received Message with session fingerprint: "+plaintextMessage.getFingerprint());
}
return finishedMessage;
@@ -296,6 +297,8 @@ public class MessageParser extends AbstractParser implements
final String body = packet.getBody();
final Element mucUserElement = packet.findChild("x", "http://jabber.org/protocol/muc#user");
final String pgpEncrypted = packet.findChildContent("x", "jabber:x:encrypted");
+ final Element oob = packet.findChild("x", "jabber:x:oob");
+ final boolean isOob = oob!= null && body != null && body.equals(oob.findChildContent("url"));
final Element axolotlEncrypted = packet.findChild(XmppAxolotlMessage.CONTAINERTAG, AxolotlService.PEP_PREFIX);
int status;
final Jid counterpart;
@@ -361,7 +364,17 @@ public class MessageParser extends AbstractParser implements
} else if (pgpEncrypted != null && Config.supportOpenPgp()) {
message = new Message(conversation, pgpEncrypted, Message.ENCRYPTION_PGP, status);
} else if (axolotlEncrypted != null && Config.supportOmemo()) {
- message = parseAxolotlChat(axolotlEncrypted, from, remoteMsgId, conversation, status);
+ Jid origin;
+ if (conversation.getMode() == Conversation.MODE_MULTI) {
+ origin = conversation.getMucOptions().getTrueCounterpart(counterpart.getResourcepart());
+ if (origin == null) {
+ Log.d(Config.LOGTAG,"axolotl message in non anonymous conference received");
+ return;
+ }
+ } else {
+ origin = from;
+ }
+ message = parseAxolotlChat(axolotlEncrypted, origin, conversation, status);
if (message == null) {
return;
}
@@ -378,6 +391,7 @@ public class MessageParser extends AbstractParser implements
message.setServerMsgId(serverMsgId);
message.setCarbon(isCarbon);
message.setTime(timestamp);
+ message.setOob(isOob);
message.markable = packet.hasChild("markable", "urn:xmpp:chat-markers:0");
if (conversation.getMode() == Conversation.MODE_MULTI) {
Jid trueCounterpart = conversation.getMucOptions().getTrueCounterpart(counterpart.getResourcepart());
diff --git a/src/main/java/de/thedevstack/conversationsplus/parser/PresenceParser.java b/src/main/java/de/thedevstack/conversationsplus/parser/PresenceParser.java
index 79ffa9bf..f575aaac 100644
--- a/src/main/java/de/thedevstack/conversationsplus/parser/PresenceParser.java
+++ b/src/main/java/de/thedevstack/conversationsplus/parser/PresenceParser.java
@@ -66,10 +66,14 @@ public class PresenceParser extends AbstractParser implements
Element item = x.findChild("item");
if (item != null && !from.isBareJid()) {
mucOptions.setError(MucOptions.Error.NONE);
- MucOptions.User user = new MucOptions.User(mucOptions,from);
+ MucOptions.User user = new MucOptions.User(mucOptions, from);
user.setAffiliation(item.getAttribute("affiliation"));
user.setRole(item.getAttribute("role"));
- user.setJid(item.getAttributeAsJid("jid"));
+ Jid real = item.getAttributeAsJid("jid");
+ if (real != null) {
+ user.setJid(real);
+ mucOptions.putMember(real.toBareJid());
+ }
if (codes.contains(MucOptions.STATUS_CODE_SELF_PRESENCE) || packet.getFrom().equals(mucOptions.getConversation().getJid())) {
mucOptions.setOnline();
mucOptions.setSelf(user);
diff --git a/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java b/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java
index 52f60e88..b6accd1e 100644
--- a/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java
+++ b/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java
@@ -52,7 +52,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
private static DatabaseBackend instance = null;
private static final String DATABASE_NAME = "history";
- private static final int DATABASE_VERSION = 24;
+ private static final int DATABASE_VERSION = 25;
private static String CREATE_CONTATCS_STATEMENT = "create table "
+ Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, "
@@ -164,6 +164,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
+ Message.CARBON + " INTEGER, "
+ Message.EDITED + " TEXT, "
+ Message.READ + " NUMBER DEFAULT 1, "
+ + Message.OOB + " INTEGER, "
+ Message.REMOTE_MSG_ID + " TEXT, FOREIGN KEY("
+ Message.CONVERSATION + ") REFERENCES "
+ Conversation.TABLENAME + "(" + Conversation.UUID
@@ -376,6 +377,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
if (oldVersion < 24 && newVersion >= 24) {
db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.EDITED + " TEXT");
}
+
+ if (oldVersion < 25 && newVersion >= 25) {
+ db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.OOB + " INTEGER");
+ }
}
public static synchronized DatabaseBackend getInstance(Context context) {
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/ExportLogsService.java b/src/main/java/de/thedevstack/conversationsplus/services/ExportLogsService.java
index 0b898125..18930d1c 100644
--- a/src/main/java/de/thedevstack/conversationsplus/services/ExportLogsService.java
+++ b/src/main/java/de/thedevstack/conversationsplus/services/ExportLogsService.java
@@ -46,9 +46,9 @@ public class ExportLogsService extends Service {
new Thread(new Runnable() {
@Override
public void run() {
- running.set(false);
export();
stopForeground(true);
+ running.set(false);
stopSelf();
}
}).start();
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
index df5f72f5..36c4892f 100644
--- a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
+++ b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
@@ -258,6 +258,14 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
@Override
public void onBind(final Account account) {
+ synchronized (mInProgressAvatarFetches) {
+ for (Iterator<String> iterator = mInProgressAvatarFetches.iterator(); iterator.hasNext(); ) {
+ final String KEY = iterator.next();
+ if (KEY.startsWith(account.getJid().toBareJid() + "_")) {
+ iterator.remove();
+ }
+ }
+ }
account.getRoster().clearPresences();
mJingleConnectionManager.cancelInTransmission();
fetchRosterFromServer(account);
@@ -569,6 +577,10 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
return getPreferences().getBoolean("xa_on_silent_mode", false);
}
+ private boolean treatVibrateAsSilent() {
+ return getPreferences().getBoolean("treat_vibrate_as_silent", false);
+ }
+
private boolean awayWhenScreenOff() {
return getPreferences().getBoolean("away_when_screen_off", false);
}
@@ -599,7 +611,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
private boolean isPhoneSilenced() {
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
- return audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT;
+ if (treatVibrateAsSilent()) {
+ return audioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
+ } else {
+ return audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT;
+ }
}
private void resetAllAttemptCounts(boolean reallyAll) {
@@ -1768,8 +1784,8 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
private void join(Conversation conversation) {
Account account = conversation.getAccount();
- final String nick = conversation.getMucOptions().getProposedNick();
- final Jid joinJid = conversation.getMucOptions().createJoinJid(nick);
+ final MucOptions mucOptions = conversation.getMucOptions();
+ final Jid joinJid = mucOptions.getSelf().getFullJid();
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": joining conversation " + joinJid.toString());
PresencePacket packet = new PresencePacket();
packet.setFrom(conversation.getAccount().getJid());
@@ -1779,7 +1795,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
x.addChild("password").setContent(conversation.getMucOptions().getPassword());
}
- if (conversation.getMucOptions().mamSupport()) {
+ if (mucOptions.mamSupport()) {
// Use MAM instead of the limited muc history to get history
x.addChild("history").setAttribute("maxchars", "0");
} else {
@@ -1798,9 +1814,13 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
conversation.setContactJid(joinJid);
databaseBackend.updateConversation(conversation);
}
- if (conversation.getMucOptions().mamSupport()) {
+
+ if (mucOptions.mamSupport()) {
getMessageArchiveService().catchupMUC(conversation);
}
+ if (mucOptions.membersOnly() && mucOptions.nonanonymous()) {
+ fetchConferenceMembers(conversation);
+ }
sendUnsentMessages(conversation);
}
@@ -1824,6 +1844,37 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
}
+ private void fetchConferenceMembers(final Conversation conversation) {
+ final Account account = conversation.getAccount();
+ final String[] affiliations = {"member","admin","owner"};
+ OnIqPacketReceived callback = new OnIqPacketReceived() {
+
+ private int i = 0;
+
+ @Override
+ public void onIqPacketReceived(Account account, IqPacket packet) {
+ Element query = packet.query("http://jabber.org/protocol/muc#admin");
+ if (packet.getType() == IqPacket.TYPE.RESULT && query != null) {
+ for(Element child : query.getChildren()) {
+ if ("item".equals(child.getName())) {
+ conversation.getMucOptions().putMember(child.getAttributeAsJid("jid"));
+ }
+ }
+ } else {
+ Log.d(Config.LOGTAG,account.getJid().toBareJid()+": could not request affiliation "+affiliations[i]+" in "+conversation.getJid().toBareJid());
+ }
+ ++i;
+ if (i >= affiliations.length) {
+ Log.d(Config.LOGTAG,account.getJid().toBareJid()+": retrieved members for "+conversation.getJid().toBareJid()+": "+conversation.getMucOptions().getMembers());
+ }
+ }
+ };
+ for(String affiliation : affiliations) {
+ sendIqPacket(account, mIqGenerator.queryAffiliation(conversation, affiliation), callback);
+ }
+ Log.d(Config.LOGTAG,account.getJid().toBareJid()+": fetching members for "+conversation.getName());
+ }
+
public void providePasswordForMuc(Conversation conversation, String password) {
if (conversation.getMode() == Conversation.MODE_MULTI) {
conversation.getMucOptions().setPassword(password);
@@ -1897,7 +1948,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
account.pendingConferenceLeaves.remove(conversation);
if (account.getStatus() == Account.State.ONLINE || now) {
PresencePacket packet = new PresencePacket();
- packet.setTo(conversation.getJid());
+ packet.setTo(conversation.getMucOptions().getSelf().getFullJid());
packet.setFrom(conversation.getAccount().getJid());
packet.setAttribute("type", "unavailable");
sendPresencePacket(conversation.getAccount(), packet);
@@ -1997,9 +2048,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
sendIqPacket(conversation.getAccount(), request, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
- if (packet.getType() == IqPacket.TYPE.RESULT) {
+ Element query = packet.findChild("query","http://jabber.org/protocol/disco#info");
+ if (packet.getType() == IqPacket.TYPE.RESULT && query != null) {
ArrayList<String> features = new ArrayList<>();
- Element query = packet.query();
for (Element child : query.getChildren()) {
if (child != null && child.getName().equals("feature")) {
String var = child.getAttribute("var");
@@ -2016,6 +2067,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
if (callback != null) {
callback.onConferenceConfigurationFetched(conversation);
}
+ Log.d(Config.LOGTAG,account.getJid().toBareJid()+": fetched muc configuration for "+conversation.getJid().toBareJid()+" - "+features.toString());
updateConversationUi();
} else if (packet.getType() == IqPacket.TYPE.ERROR) {
if (callback != null) {
@@ -2280,22 +2332,13 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
private void reconnectAccount(final Account account, final boolean force, final boolean interactive) {
synchronized (account) {
XmppConnection connection = account.getXmppConnection();
- if (connection != null) {
- disconnect(account, force);
- } else {
+ if (connection == null) {
connection = createConnection(account);
account.setXmppConnection(connection);
}
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
- synchronized (this.mInProgressAvatarFetches) {
- for (Iterator<String> iterator = this.mInProgressAvatarFetches.iterator(); iterator.hasNext(); ) {
- final String KEY = iterator.next();
- if (KEY.startsWith(account.getJid().toBareJid() + "_")) {
- iterator.remove();
- }
- }
- }
if (!force) {
+ disconnect(account, false);
try {
Logging.d(Config.LOGTAG, "wait for disconnect");
Thread.sleep(500); //sleep wait for disconnect
@@ -2308,6 +2351,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
thread.start();
scheduleWakeUpCall(Config.CONNECT_DISCO_TIMEOUT, account.getUuid().hashCode());
} else {
+ disconnect(account, force);
account.getRoster().clearPresences();
connection.resetEverything();
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConferenceDetailsActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConferenceDetailsActivity.java
index c1b5ccc6..12ff2a52 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ConferenceDetailsActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConferenceDetailsActivity.java
@@ -334,7 +334,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.muc_details, menu);
- return true;
+ return super.onCreateOptionsMenu(menu);
}
@Override
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java
index aaa19fc5..a18fd848 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java
@@ -297,7 +297,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
edit.setVisible(false);
delete.setVisible(false);
}
- return true;
+ return super.onCreateOptionsMenu(menu);
}
private void populateView() {
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
index 1a4ccb8c..1546de27 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
@@ -415,7 +415,7 @@ public class ConversationActivity extends XmppActivity
menuContactDetails.setVisible(false);
menuAttach.setVisible(getSelectedConversation().getAccount().httpUploadAvailable() && getSelectedConversation().getMucOptions().participating());
menuInviteContact.setVisible(getSelectedConversation().getMucOptions().canInvite());
- menuSecure.setVisible(Config.supportOpenPgp() && Config.multipleEncryptionChoices()); //only if pgp is supported we have a choice
+ menuSecure.setVisible((Config.supportOpenPgp() || Config.supportOmemo()) && Config.multipleEncryptionChoices()); //only if pgp is supported we have a choice
} else {
menuMucDetails.setVisible(false);
menuSecure.setVisible(Config.multipleEncryptionChoices());
@@ -427,7 +427,7 @@ public class ConversationActivity extends XmppActivity
}
}
}
- return true;
+ return super.onCreateOptionsMenu(menu);
}
protected void selectPresenceToAttachFile(final int attachmentChoice, final int encryption) {
@@ -863,8 +863,8 @@ public class ConversationActivity extends XmppActivity
axolotl.setVisible(Config.supportOmemo());
if (conversation.getMode() == Conversation.MODE_MULTI) {
otr.setVisible(false);
- axolotl.setVisible(false);
- } else if (!conversation.getAccount().getAxolotlService().isContactAxolotlCapable(conversation.getContact())) {
+ }
+ if (!conversation.getAccount().getAxolotlService().isConversationAxolotlCapable(conversation)) {
axolotl.setEnabled(false);
}
switch (conversation.getNextEncryption()) {
@@ -1343,49 +1343,64 @@ public class ConversationActivity extends XmppActivity
}
} else {
- mPendingImageUris.clear();
- mPendingFileUris.clear();
- if (requestCode == ConversationActivity.REQUEST_DECRYPT_PGP) {
- mConversationFragment.onActivityResult(requestCode, resultCode, data);
- }
- if (requestCode == REQUEST_BATTERY_OP) {
- setNeverAskForBatteryOptimizationsAgain();
- }
- }
- }
-
- private void setNeverAskForBatteryOptimizationsAgain() {
- getPreferences().edit().putBoolean("show_battery_optimization", false).commit();
- }
-
- private void openBatteryOptimizationDialogIfNeeded() {
- if (showBatteryOptimizationWarning() && getPreferences().getBoolean("show_battery_optimization", true)) {
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle(R.string.battery_optimizations_enabled);
- builder.setMessage(R.string.battery_optimizations_enabled_dialog);
- builder.setPositiveButton(R.string.next, new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
- Uri uri = Uri.parse("package:" + getPackageName());
- intent.setData(uri);
- startActivityForResult(intent, REQUEST_BATTERY_OP);
- }
- });
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
- builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
- @Override
- public void onDismiss(DialogInterface dialog) {
- setNeverAskForBatteryOptimizationsAgain();
- }
- });
- }
- builder.create().show();
- }
- }
+ mPendingImageUris.clear();
+ mPendingFileUris.clear();
+ if (requestCode == ConversationActivity.REQUEST_DECRYPT_PGP) {
+ mConversationFragment.onActivityResult(requestCode, resultCode, data);
+ }
+ if (requestCode == REQUEST_BATTERY_OP) {
+ setNeverAskForBatteryOptimizationsAgain();
+ }
+ }
+ }
+
+ private void setNeverAskForBatteryOptimizationsAgain() {
+ getPreferences().edit().putBoolean("show_battery_optimization", false).commit();
+ }
+
+ private void openBatteryOptimizationDialogIfNeeded() {
+ if (hasAccountWithoutPush()
+ && isOptimizingBattery()
+ && getPreferences().getBoolean("show_battery_optimization", true)) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.battery_optimizations_enabled);
+ builder.setMessage(R.string.battery_optimizations_enabled_dialog);
+ builder.setPositiveButton(R.string.next, new OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
+ Uri uri = Uri.parse("package:" + getPackageName());
+ intent.setData(uri);
+ startActivityForResult(intent, REQUEST_BATTERY_OP);
+ }
+ });
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
+ builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
+ @Override
+ public void onDismiss(DialogInterface dialog) {
+ setNeverAskForBatteryOptimizationsAgain();
+ }
+ });
+ }
+ builder.create().show();
+ }
+ }
+
+ private boolean hasAccountWithoutPush() {
+ for(Account account : xmppConnectionService.getAccounts()) {
+ if (account.getStatus() != Account.State.DISABLED
+ && !xmppConnectionService.getPushManagementService().available(account)) {
+ return true;
+ }
+ }
+ return false;
+ }
private void attachLocationToConversation(Conversation conversation, Uri uri) {
- xmppConnectionService.attachLocationToConversation(conversation, uri, new UiCallback<Message>() {
+ if (conversation == null) {
+ return;
+ }
+ xmppConnectionService.attachLocationToConversation(conversation,uri, new UiCallback<Message>() {
@Override
public void success(Message message) {
@@ -1502,18 +1517,23 @@ public class ConversationActivity extends XmppActivity
protected boolean trustKeysIfNeeded(int requestCode, int attachmentChoice) {
AxolotlService axolotlService = mSelectedConversation.getAccount().getAxolotlService();
- Contact contact = mSelectedConversation.getContact();
+ final List<Jid> targets = axolotlService.getCryptoTargets(mSelectedConversation);
+ boolean hasUnaccepted = !mSelectedConversation.getAcceptedCryptoTargets().containsAll(targets);
boolean hasUndecidedOwn = !axolotlService.getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED).isEmpty();
- boolean hasUndecidedContact = !axolotlService.getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED,contact).isEmpty();
+ boolean hasUndecidedContacts = !axolotlService.getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED, targets).isEmpty();
boolean hasPendingKeys = !axolotlService.findDevicesWithoutSession(mSelectedConversation).isEmpty();
- boolean hasNoTrustedKeys = axolotlService.getNumTrustedKeys(mSelectedConversation.getContact()) == 0;
- if(hasUndecidedOwn || hasUndecidedContact || hasPendingKeys || hasNoTrustedKeys) {
+ boolean hasNoTrustedKeys = axolotlService.anyTargetHasNoTrustedKeys(targets);
+ if(hasUndecidedOwn || hasUndecidedContacts || hasPendingKeys || hasNoTrustedKeys || hasUnaccepted) {
axolotlService.createSessionsIfNeeded(mSelectedConversation);
Intent intent = new Intent(getApplicationContext(), TrustKeysActivity.class);
- intent.putExtra("contact", mSelectedConversation.getContact().getJid().toBareJid().toString());
+ String[] contacts = new String[targets.size()];
+ for(int i = 0; i < contacts.length; ++i) {
+ contacts[i] = targets.get(i).toString();
+ }
+ intent.putExtra("contacts", contacts);
intent.putExtra(EXTRA_ACCOUNT, mSelectedConversation.getAccount().getJid().toBareJid().toString());
intent.putExtra("choice", attachmentChoice);
- intent.putExtra("has_no_trusted", hasNoTrustedKeys);
+ intent.putExtra("conversation",mSelectedConversation.getUuid());
startActivityForResult(intent, requestCode);
return true;
} else {
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
index 2828e27e..44132ce3 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
@@ -8,6 +8,7 @@ import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.IntentSender;
import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
import android.support.annotation.Nullable;
@@ -23,6 +24,8 @@ import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
+import android.widget.AbsListView;
+import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ImageButton;
@@ -43,6 +46,7 @@ import java.util.Collections;
import java.util.List;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
+import de.thedevstack.conversationsplus.http.HttpDownloadConnection;
import de.thedevstack.conversationsplus.ui.dialogs.MessageDetailsDialog;
import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
@@ -521,6 +525,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
private void populateContextMenu(ContextMenu menu) {
final Message m = this.selectedMessage;
+ final Transferable t = m.getTransferable();
if (m.getType() != Message.TYPE_STATUS) {
activity.getMenuInflater().inflate(R.menu.message_context, menu);
menu.setHeaderTitle(R.string.message_options);
@@ -532,19 +537,18 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
MenuItem downloadFile = menu.findItem(R.id.download_file);
MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
if ((m.getType() == Message.TYPE_TEXT || m.getType() == Message.TYPE_PRIVATE)
- && m.getTransferable() == null
+ && t == null
&& !GeoHelper.isGeoUri(m.getBody())
&& m.treatAsDownloadable() != Message.Decision.MUST) {
copyText.setVisible(true);
}
-
if (m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
retryDecryption.setVisible(true);
}
if ((m.getType() != Message.TYPE_TEXT
&& m.getType() != Message.TYPE_PRIVATE
- && m.getTransferable() == null)
+ && t == null)
|| (GeoHelper.isGeoUri(m.getBody()))) {
shareWith.setVisible(true);
}
@@ -553,15 +557,16 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
if (m.hasFileOnRemoteHost()
|| GeoHelper.isGeoUri(m.getBody())
- || m.treatAsDownloadable() == Message.Decision.MUST) {
+ || m.treatAsDownloadable() == Message.Decision.MUST
+ || (t != null && t instanceof HttpDownloadConnection)) {
copyUrl.setVisible(true);
}
- if ((m.getType() == Message.TYPE_TEXT && m.getTransferable() == null && m.treatAsDownloadable() != Message.Decision.NEVER)
- || (m.isFileOrImage() && m.getTransferable() instanceof TransferablePlaceholder && m.hasFileOnRemoteHost())){
+ if ((m.getType() == Message.TYPE_TEXT && t == null && m.treatAsDownloadable() != Message.Decision.NEVER)
+ || (m.isFileOrImage() && t instanceof TransferablePlaceholder && m.hasFileOnRemoteHost())){
downloadFile.setVisible(true);
downloadFile.setTitle(activity.getString(R.string.download_x_file,UIHelper.getFileDescriptionString(activity, m)));
}
- if ((m.getTransferable() != null && !(m.getTransferable() instanceof TransferablePlaceholder))
+ if ((t != null && !(t instanceof TransferablePlaceholder))
|| (m.isFileOrImage() && (m.getStatus() == Message.STATUS_WAITING
|| m.getStatus() == Message.STATUS_OFFERED))) {
cancelTransmission.setVisible(true);
@@ -757,6 +762,17 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
swipeLayout.setRefreshing(false);
}
+ private OnClickListener mEnableAccountListener = new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ final Account account = conversation == null ? null : conversation.getAccount();
+ if (account != null) {
+ account.setOption(Account.OPTION_DISABLED, false);
+ activity.xmppConnectionService.updateAccount(account);
+ }
+ }
+ };
+
private OnClickListener mUnblockClickListener = new OnClickListener() {
@Override
public void onClick(final View v) {
@@ -802,7 +818,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
final Account account = conversation.getAccount();
final Contact contact = conversation.getContact();
final int mode = conversation.getMode();
- if (conversation.isBlocked()) {
+ if (account.getStatus() == Account.State.DISABLED) {
+ showSnackbar(R.string.this_account_is_disabled, R.string.enable, this.mEnableAccountListener);
+ } else if (conversation.isBlocked()) {
showSnackbar(R.string.contact_blocked, R.string.unblock, this.mUnblockClickListener);
} else if (!contact.showInRoster() && contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
showSnackbar(R.string.contact_added_you, R.string.add_back, this.mAddBackClickListener);
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java
index 7da2e889..ac06544a 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java
@@ -501,7 +501,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
clearDevices.setVisible(false);
mamPrefs.setVisible(false);
}
- return true;
+ return super.onCreateOptionsMenu(menu);
}
@Override
@@ -621,6 +621,13 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
}
+ mPassword.setEnabled(!Config.LOCK_SETTINGS);
+ mAccountJid.setEnabled(!Config.LOCK_SETTINGS);
+ mHostname.setEnabled(!Config.LOCK_SETTINGS);
+ mPort.setEnabled(!Config.LOCK_SETTINGS);
+ mPasswordConfirm.setEnabled(!Config.LOCK_SETTINGS);
+ mRegisterNew.setEnabled(!Config.LOCK_SETTINGS);
+
if (!mInitMode) {
this.mAvatar.setVisibility(View.VISIBLE);
this.mAvatar.setImageBitmap(AvatarService.getInstance().get(this.mAccount, getPixel(72)));
@@ -643,11 +650,12 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} else {
detailsAccountJid.setText(this.mAccount.getJid().toBareJid().toString());
}
+ Features features = this.mAccount.getXmppConnection().getFeatures();
this.mStats.setVisibility(View.VISIBLE);
- this.mBatteryOptimizations.setVisibility(showBatteryOptimizationWarning() ? View.VISIBLE : View.GONE);
+ boolean showOptimizingWarning = !xmppConnectionService.getPushManagementService().available(mAccount) && isOptimizingBattery();
+ this.mBatteryOptimizations.setVisibility(showOptimizingWarning ? View.VISIBLE : View.GONE);
this.mSessionEst.setText(UIHelper.readableTimeDifferenceFull(this, this.mAccount.getXmppConnection()
.getLastSessionEstablished()));
- Features features = this.mAccount.getXmppConnection().getFeatures();
if (features.rosterVersioning()) {
this.mServerInfoRosterVersion.setText(R.string.server_info_available);
} else {
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ExportLogsPreference.java b/src/main/java/de/thedevstack/conversationsplus/ui/ExportLogsPreference.java
index eabb7518..54fe3910 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ExportLogsPreference.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ExportLogsPreference.java
@@ -1,7 +1,10 @@
package de.thedevstack.conversationsplus.ui;
+import android.Manifest;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.os.Build;
import android.preference.Preference;
import android.util.AttributeSet;
@@ -22,6 +25,10 @@ public class ExportLogsPreference extends Preference {
}
protected void onClick() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
+ && getContext().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
+ return;
+ }
final Intent startIntent = new Intent(getContext(), ExportLogsService.class);
getContext().startService(startIntent);
super.onClick();
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java
index 431111f5..e376b6b3 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java
@@ -155,9 +155,9 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
addAccount.setVisible(false);
addAccountWithCertificate.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
} else {
- addAccount.setVisible(!Config.SINGLE_ACCOUNT);
+ addAccount.setVisible(!Config.LOCK_SETTINGS);
}
- addAccountWithCertificate.setVisible(!Config.SINGLE_ACCOUNT);
+ addAccountWithCertificate.setVisible(!Config.LOCK_SETTINGS);
if (!accountsLeftToEnable()) {
enableAll.setVisible(false);
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/PublishProfilePictureActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/PublishProfilePictureActivity.java
index 9b827861..6bf8c590 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/PublishProfilePictureActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/PublishProfilePictureActivity.java
@@ -7,6 +7,8 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
@@ -32,7 +34,8 @@ import de.thedevstack.conversationsplus.xmpp.pep.Avatar;
public class PublishProfilePictureActivity extends XmppActivity {
- private static final int REQUEST_CHOOSE_FILE = 0xac23;
+ private static final int REQUEST_CHOOSE_FILE_AND_CROP = 0xac23;
+ private static final int REQUEST_CHOOSE_FILE = 0xac24;
private ImageView avatar;
private TextView accountTextView;
private TextView hintOrWarning;
@@ -137,7 +140,7 @@ public class PublishProfilePictureActivity extends XmppActivity {
@Override
public void onClick(View v) {
if (hasStoragePermission(REQUEST_CHOOSE_FILE)) {
- chooseAvatar();
+ chooseAvatar(false);
}
}
@@ -145,20 +148,22 @@ public class PublishProfilePictureActivity extends XmppActivity {
this.defaultUri = PhoneHelper.getSefliUri(getApplicationContext());
}
- private void chooseAvatar() {
+ private void chooseAvatar(boolean crop) {
Intent attachFileIntent = new Intent();
attachFileIntent.setType("image/*");
attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
Intent chooser = Intent.createChooser(attachFileIntent, getString(R.string.attach_file));
- startActivityForResult(chooser, REQUEST_CHOOSE_FILE);
+ startActivityForResult(chooser, crop ? REQUEST_CHOOSE_FILE_AND_CROP : REQUEST_CHOOSE_FILE);
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
if (grantResults.length > 0)
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- if (requestCode == REQUEST_CHOOSE_FILE) {
- chooseAvatar();
+ if (requestCode == REQUEST_CHOOSE_FILE_AND_CROP) {
+ chooseAvatar(true);
+ } else if (requestCode == REQUEST_CHOOSE_FILE) {
+ chooseAvatar(false);
}
} else {
Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show();
@@ -166,11 +171,29 @@ public class PublishProfilePictureActivity extends XmppActivity {
}
@Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.publish_avatar, menu);
+ return super.onCreateOptionsMenu(menu);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(final MenuItem item) {
+ if (item.getItemId() == R.id.action_crop_image) {
+ if (hasStoragePermission(REQUEST_CHOOSE_FILE_AND_CROP)) {
+ chooseAvatar(true);
+ }
+ return true;
+ } else {
+ return onOptionsItemSelected(item);
+ }
+ }
+
+ @Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
- case REQUEST_CHOOSE_FILE:
+ case REQUEST_CHOOSE_FILE_AND_CROP:
Uri source = data.getData();
String original = FileUtils.getPath(this, source);
if (original != null) {
@@ -180,9 +203,17 @@ public class PublishProfilePictureActivity extends XmppActivity {
final int size = getPixel(192);
Crop.of(source, destination).asSquare().withMaxSize(size, size).start(this);
break;
+ case REQUEST_CHOOSE_FILE:
+ this.avatarUri = data.getData();
+ if (xmppConnectionServiceBound) {
+ loadImageIntoPreview(this.avatarUri);
+ }
+ break;
case Crop.REQUEST_CROP:
this.avatarUri = Uri.fromFile(new File(getCacheDir(), "croppedAvatar"));
- loadImageIntoPreview(this.avatarUri);
+ if (xmppConnectionServiceBound) {
+ loadImageIntoPreview(this.avatarUri);
+ }
break;
}
} else {
@@ -247,21 +278,10 @@ public class PublishProfilePictureActivity extends XmppActivity {
}
}
- private Bitmap loadScaledBitmap(Uri uri, int reqSize) throws FileNotFoundException {
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options);
- int rotation = ExifHelper.getOrientation(getContentResolver().openInputStream(uri));
- options.inSampleSize = ImageUtil.calcSampleSize(options, reqSize);
- options.inJustDecodeBounds = false;
- Bitmap bm = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options);
- return ImageUtil.rotate(bm,rotation);
- }
-
protected void loadImageIntoPreview(Uri uri) {
Bitmap bm = null;
try {
- bm = loadScaledBitmap(uri, getPixel(192));
+ bm = ImageUtil.cropCenterSquare(uri, getPixel(192));
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java
index e8c9587b..ff7e11d1 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java
@@ -3,23 +3,30 @@ package de.thedevstack.conversationsplus.ui;
import android.app.AlertDialog;
import android.app.FragmentManager;
import android.content.DialogInterface;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
+import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceManager;
+import android.preference.PreferenceScreen;
+import android.util.Log;
import android.widget.Toast;
import java.security.KeyStoreException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.List;
import java.util.Locale;
import de.duenndns.ssl.MemorizingTrustManager;
+import de.thedevstack.conversationsplus.services.ExportLogsService;
import de.tzur.conversations.Settings;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.Account;
@@ -28,6 +35,8 @@ import github.ankushsachdeva.emojicon.EmojiconHandler;
public class SettingsActivity extends XmppActivity implements
OnSharedPreferenceChangeListener {
+
+ public static final int REQUEST_WRITE_LOGS = 0xbf8701;
private SettingsFragment mSettingsFragment;
@Override
@@ -62,34 +71,34 @@ public class SettingsActivity extends XmppActivity implements
final Preference removeCertsPreference = mSettingsFragment.findPreference("remove_trusted_certificates");
removeCertsPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- final MemorizingTrustManager mtm = xmppConnectionService.getMemorizingTrustManager();
- final ArrayList<String> aliases = Collections.list(mtm.getCertificates());
- if (aliases.size() == 0) {
- displayToast(getString(R.string.toast_no_trusted_certs));
- return true;
- }
- final ArrayList selectedItems = new ArrayList<Integer>();
- final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(SettingsActivity.this);
- dialogBuilder.setTitle(getResources().getString(R.string.dialog_manage_certs_title));
- dialogBuilder.setMultiChoiceItems(aliases.toArray(new CharSequence[aliases.size()]), null,
- new DialogInterface.OnMultiChoiceClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int indexSelected,
- boolean isChecked) {
- if (isChecked) {
- selectedItems.add(indexSelected);
- } else if (selectedItems.contains(indexSelected)) {
- selectedItems.remove(Integer.valueOf(indexSelected));
- }
- if (selectedItems.size() > 0)
- ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true);
- else {
- ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
- }
- }
- });
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ final MemorizingTrustManager mtm = xmppConnectionService.getMemorizingTrustManager();
+ final ArrayList<String> aliases = Collections.list(mtm.getCertificates());
+ if (aliases.size() == 0) {
+ displayToast(getString(R.string.toast_no_trusted_certs));
+ return true;
+ }
+ final ArrayList selectedItems = new ArrayList<Integer>();
+ final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(SettingsActivity.this);
+ dialogBuilder.setTitle(getResources().getString(R.string.dialog_manage_certs_title));
+ dialogBuilder.setMultiChoiceItems(aliases.toArray(new CharSequence[aliases.size()]), null,
+ new DialogInterface.OnMultiChoiceClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int indexSelected,
+ boolean isChecked) {
+ if (isChecked) {
+ selectedItems.add(indexSelected);
+ } else if (selectedItems.contains(indexSelected)) {
+ selectedItems.remove(Integer.valueOf(indexSelected));
+ }
+ if (selectedItems.size() > 0)
+ ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true);
+ else {
+ ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
+ }
+ }
+ });
dialogBuilder.setPositiveButton(
getResources().getString(R.string.dialog_manage_certs_positivebutton), new DialogInterface.OnClickListener() {
@@ -137,8 +146,12 @@ public class SettingsActivity extends XmppActivity implements
}
@Override
- public void onSharedPreferenceChanged(SharedPreferences preferences,
- String name) {
+ public void onSharedPreferenceChanged(SharedPreferences preferences, String name) {
+ final List<String> resendPresence = Arrays.asList(
+ "confirm_messages_list",
+ "xa_on_silent_mode",
+ "away_when_screen_off",
+ "treat_vibrate_as_silent");
// need to synchronize the settings class first
Settings.synchronizeSettingsClassWithPreferences(preferences, name);
if (name.equals("resource")) {
@@ -159,9 +172,7 @@ public class SettingsActivity extends XmppActivity implements
}
} else if (name.equals("keep_foreground_service")) {
xmppConnectionService.toggleForegroundService();
- } else if (name.equals("confirm_messages_list")
- || name.equals("xa_on_silent_mode")
- || name.equals("away_when_screen_off")) {
+ } else if (resendPresence.contains(name)) {
if (xmppConnectionServiceBound) {
if (name.equals("away_when_screen_off")) {
xmppConnectionService.toggleScreenEventReceiver();
@@ -177,6 +188,18 @@ public class SettingsActivity extends XmppActivity implements
}
+ @Override
+ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
+ if (grantResults.length > 0)
+ if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ if (requestCode == REQUEST_WRITE_LOGS) {
+ getApplicationContext().startService(new Intent(getApplicationContext(), ExportLogsService.class));
+ }
+ } else {
+ Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show();
+ }
+ }
+
private void displayToast(final String msg) {
runOnUiThread(new Runnable() {
@Override
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java
index f8c624be..d3086d66 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java
@@ -534,7 +534,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
mSearchEditText.append(mInitialJid);
filter(mInitialJid);
}
- return true;
+ return super.onCreateOptionsMenu(menu);
}
@Override
@@ -742,6 +742,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
Presence.Status s = p == null ? Presence.Status.OFFLINE : p.getStatus();
if (contact.showInRoster() && contact.match(needle)
&& (!this.mHideOfflineContacts
+ || (needle != null && !needle.trim().isEmpty())
|| s.compareTo(Presence.Status.OFFLINE) < 0)) {
this.contacts.add(contact);
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/TrustKeysActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/TrustKeysActivity.java
index 167b207f..a3f674be 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/TrustKeysActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/TrustKeysActivity.java
@@ -12,7 +12,9 @@ import android.widget.Toast;
import org.whispersystems.libaxolotl.IdentityKey;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -21,31 +23,29 @@ import de.thedevstack.conversationsplus.crypto.axolotl.AxolotlService;
import de.thedevstack.conversationsplus.crypto.axolotl.XmppAxolotlSession;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Contact;
+import de.thedevstack.conversationsplus.entities.Conversation;
import de.thedevstack.conversationsplus.xmpp.OnKeyStatusUpdated;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdated {
- private Jid accountJid;
- private Jid contactJid;
+ private List<Jid> contactJids;
- private Contact contact;
private Account mAccount;
+ private Conversation mConversation;
private TextView keyErrorMessage;
private LinearLayout keyErrorMessageCard;
private TextView ownKeysTitle;
private LinearLayout ownKeys;
private LinearLayout ownKeysCard;
- private TextView foreignKeysTitle;
private LinearLayout foreignKeys;
- private LinearLayout foreignKeysCard;
private Button mSaveButton;
private Button mCancelButton;
private AxolotlService.FetchStatus lastFetchReport = AxolotlService.FetchStatus.SUCCESS;
private final Map<String, Boolean> ownKeysToTrust = new HashMap<>();
- private final Map<String, Boolean> foreignKeysToTrust = new HashMap<>();
+ private final Map<Jid,Map<String, Boolean>> foreignKeysToTrust = new HashMap<>();
private final OnClickListener mSaveButtonListener = new OnClickListener() {
@Override
@@ -70,25 +70,16 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate
}
@Override
- protected String getShareableUri() {
- if (contact != null) {
- return contact.getShareableUri();
- } else {
- return "";
- }
- }
-
- @Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_trust_keys);
- try {
- this.accountJid = Jid.fromString(getIntent().getExtras().getString(EXTRA_ACCOUNT));
- } catch (final InvalidJidException ignored) {
- }
- try {
- this.contactJid = Jid.fromString(getIntent().getExtras().getString("contact"));
- } catch (final InvalidJidException ignored) {
+ this.contactJids = new ArrayList<>();
+ for(String jid : getIntent().getStringArrayExtra("contacts")) {
+ try {
+ this.contactJids.add(Jid.fromString(jid));
+ } catch (InvalidJidException e) {
+ e.printStackTrace();
+ }
}
keyErrorMessageCard = (LinearLayout) findViewById(R.id.key_error_message_card);
@@ -96,9 +87,7 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate
ownKeysTitle = (TextView) findViewById(R.id.own_keys_title);
ownKeys = (LinearLayout) findViewById(R.id.own_keys_details);
ownKeysCard = (LinearLayout) findViewById(R.id.own_keys_card);
- foreignKeysTitle = (TextView) findViewById(R.id.foreign_keys_title);
- foreignKeys = (LinearLayout) findViewById(R.id.foreign_keys_details);
- foreignKeysCard = (LinearLayout) findViewById(R.id.foreign_keys_card);
+ foreignKeys = (LinearLayout) findViewById(R.id.foreign_keys);
mCancelButton = (Button) findViewById(R.id.cancel_button);
mCancelButton.setOnClickListener(mCancelButtonListener);
mSaveButton = (Button) findViewById(R.id.save_button);
@@ -119,7 +108,7 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate
boolean hasForeignKeys = false;
for(final String fingerprint : ownKeysToTrust.keySet()) {
hasOwnKeys = true;
- addFingerprintRowWithListeners(ownKeys, contact.getAccount(), fingerprint, false,
+ addFingerprintRowWithListeners(ownKeys, mAccount, fingerprint, false,
XmppAxolotlSession.Trust.fromBoolean(ownKeysToTrust.get(fingerprint)), false,
new CompoundButton.OnCheckedChangeListener() {
@Override
@@ -132,30 +121,44 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate
null
);
}
- for(final String fingerprint : foreignKeysToTrust.keySet()) {
- hasForeignKeys = true;
- addFingerprintRowWithListeners(foreignKeys, contact.getAccount(), fingerprint, false,
- XmppAxolotlSession.Trust.fromBoolean(foreignKeysToTrust.get(fingerprint)), false,
- new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- foreignKeysToTrust.put(fingerprint, isChecked);
- lockOrUnlockAsNeeded();
- }
- },
- null,
- null
- );
- }
- if(hasOwnKeys) {
- ownKeysTitle.setText(accountJid.toString());
- ownKeysCard.setVisibility(View.VISIBLE);
- }
- if(hasForeignKeys) {
- foreignKeysTitle.setText(contactJid.toString());
- foreignKeysCard.setVisibility(View.VISIBLE);
+ synchronized (this.foreignKeysToTrust) {
+ for (Map.Entry<Jid, Map<String, Boolean>> entry : foreignKeysToTrust.entrySet()) {
+ hasForeignKeys = true;
+ final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.keys_card, foreignKeys, false);
+ final Jid jid = entry.getKey();
+ final TextView header = (TextView) layout.findViewById(R.id.foreign_keys_title);
+ final LinearLayout keysContainer = (LinearLayout) layout.findViewById(R.id.foreign_keys_details);
+ final TextView informNoKeys = (TextView) layout.findViewById(R.id.no_keys_to_accept);
+ header.setText(jid.toString());
+ final Map<String, Boolean> fingerprints = entry.getValue();
+ for (final String fingerprint : fingerprints.keySet()) {
+ addFingerprintRowWithListeners(keysContainer, mAccount, fingerprint, false,
+ XmppAxolotlSession.Trust.fromBoolean(fingerprints.get(fingerprint)), false,
+ new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ fingerprints.put(fingerprint, isChecked);
+ lockOrUnlockAsNeeded();
+ }
+ },
+ null,
+ null
+ );
+ }
+ if (fingerprints.size() == 0) {
+ informNoKeys.setVisibility(View.VISIBLE);
+ informNoKeys.setText(getString(R.string.no_keys_just_confirm,mAccount.getRoster().getContact(jid).getDisplayName()));
+ } else {
+ informNoKeys.setVisibility(View.GONE);
+ }
+ foreignKeys.addView(layout);
+ }
}
+
+ ownKeysTitle.setText(mAccount.getJid().toBareJid().toString());
+ ownKeysCard.setVisibility(hasOwnKeys ? View.VISIBLE : View.GONE);
+ foreignKeys.setVisibility(hasForeignKeys ? View.VISIBLE : View.GONE);
if(hasPendingKeyFetches()) {
setFetching();
lock();
@@ -163,13 +166,15 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate
if (!hasForeignKeys && hasNoOtherTrustedKeys()) {
keyErrorMessageCard.setVisibility(View.VISIBLE);
if (lastFetchReport == AxolotlService.FetchStatus.ERROR
- || contact.getAccount().getAxolotlService().fetchMapHasErrors(contact)) {
+ || mAccount.getAxolotlService().fetchMapHasErrors(contactJids)) {
keyErrorMessage.setText(R.string.error_no_keys_to_trust_server_error);
} else {
keyErrorMessage.setText(R.string.error_no_keys_to_trust);
}
- ownKeys.removeAllViews(); ownKeysCard.setVisibility(View.GONE);
- foreignKeys.removeAllViews(); foreignKeysCard.setVisibility(View.GONE);
+ ownKeys.removeAllViews();
+ ownKeysCard.setVisibility(View.GONE);
+ foreignKeys.removeAllViews();
+ foreignKeys.setVisibility(View.GONE);
}
lockOrUnlockAsNeeded();
setDone();
@@ -177,46 +182,58 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate
}
private boolean reloadFingerprints() {
+ List<Jid> acceptedTargets = mConversation == null ? new ArrayList<Jid>() : mConversation.getAcceptedCryptoTargets();
ownKeysToTrust.clear();
- foreignKeysToTrust.clear();
AxolotlService service = this.mAccount.getAxolotlService();
Set<IdentityKey> ownKeysSet = service.getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED);
- Set<IdentityKey> foreignKeysSet = service.getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED, contact);
- if (hasNoOtherTrustedKeys() && ownKeysSet.size() == 0) {
- foreignKeysSet.addAll(service.getKeysWithTrust(XmppAxolotlSession.Trust.UNTRUSTED, contact));
- }
for(final IdentityKey identityKey : ownKeysSet) {
if(!ownKeysToTrust.containsKey(identityKey)) {
ownKeysToTrust.put(identityKey.getFingerprint().replaceAll("\\s", ""), false);
}
}
- for(final IdentityKey identityKey : foreignKeysSet) {
- if(!foreignKeysToTrust.containsKey(identityKey)) {
- foreignKeysToTrust.put(identityKey.getFingerprint().replaceAll("\\s", ""), false);
+ synchronized (this.foreignKeysToTrust) {
+ foreignKeysToTrust.clear();
+ for (Jid jid : contactJids) {
+ Set<IdentityKey> foreignKeysSet = service.getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED, jid);
+ if (hasNoOtherTrustedKeys(jid) && ownKeysSet.size() == 0) {
+ foreignKeysSet.addAll(service.getKeysWithTrust(XmppAxolotlSession.Trust.UNTRUSTED, jid));
+ }
+ Map<String, Boolean> foreignFingerprints = new HashMap<>();
+ for (final IdentityKey identityKey : foreignKeysSet) {
+ if (!foreignFingerprints.containsKey(identityKey)) {
+ foreignFingerprints.put(identityKey.getFingerprint().replaceAll("\\s", ""), false);
+ }
+ }
+ if (foreignFingerprints.size() > 0 || !acceptedTargets.contains(jid)) {
+ foreignKeysToTrust.put(jid, foreignFingerprints);
+ }
}
}
- return ownKeysSet.size() + foreignKeysSet.size() > 0;
+ return ownKeysSet.size() + foreignKeysToTrust.size() > 0;
}
@Override
public void onBackendConnected() {
- if ((accountJid != null) && (contactJid != null)) {
- this.mAccount = xmppConnectionService.findAccountByJid(accountJid);
- if (this.mAccount == null) {
- return;
- }
- this.contact = this.mAccount.getRoster().getContact(contactJid);
+ Intent intent = getIntent();
+ this.mAccount = extractAccount(intent);
+ if (this.mAccount != null && intent != null) {
+ String uuid = intent.getStringExtra("conversation");
+ this.mConversation = xmppConnectionService.findConversationByUuid(uuid);
reloadFingerprints();
populateView();
}
}
private boolean hasNoOtherTrustedKeys() {
+ return mAccount == null || mAccount.getAxolotlService().anyTargetHasNoTrustedKeys(contactJids);
+ }
+
+ private boolean hasNoOtherTrustedKeys(Jid contact) {
return mAccount == null || mAccount.getAxolotlService().getNumTrustedKeys(contact) == 0;
}
private boolean hasPendingKeyFetches() {
- return mAccount != null && contact != null && mAccount.getAxolotlService().hasPendingKeyFetches(mAccount,contact);
+ return mAccount != null && mAccount.getAxolotlService().hasPendingKeyFetches(mAccount, contactJids);
}
@@ -262,14 +279,28 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate
private void commitTrusts() {
for(final String fingerprint :ownKeysToTrust.keySet()) {
- contact.getAccount().getAxolotlService().setFingerprintTrust(
+ mAccount.getAxolotlService().setFingerprintTrust(
fingerprint,
XmppAxolotlSession.Trust.fromBoolean(ownKeysToTrust.get(fingerprint)));
}
- for(final String fingerprint:foreignKeysToTrust.keySet()) {
- contact.getAccount().getAxolotlService().setFingerprintTrust(
- fingerprint,
- XmppAxolotlSession.Trust.fromBoolean(foreignKeysToTrust.get(fingerprint)));
+ List<Jid> acceptedTargets = mConversation == null ? new ArrayList<Jid>() : mConversation.getAcceptedCryptoTargets();
+ synchronized (this.foreignKeysToTrust) {
+ for (Map.Entry<Jid, Map<String, Boolean>> entry : foreignKeysToTrust.entrySet()) {
+ Jid jid = entry.getKey();
+ Map<String, Boolean> value = entry.getValue();
+ if (!acceptedTargets.contains(jid)) {
+ acceptedTargets.add(jid);
+ }
+ for (final String fingerprint : value.keySet()) {
+ mAccount.getAxolotlService().setFingerprintTrust(
+ fingerprint,
+ XmppAxolotlSession.Trust.fromBoolean(value.get(fingerprint)));
+ }
+ }
+ }
+ if (mConversation != null && mConversation.getMode() == Conversation.MODE_MULTI) {
+ mConversation.setAcceptedCryptoTargets(acceptedTargets);
+ xmppConnectionService.updateConversation(mConversation);
}
}
@@ -284,11 +315,17 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate
}
private void lockOrUnlockAsNeeded() {
- if (hasNoOtherTrustedKeys() && !foreignKeysToTrust.values().contains(true)){
- lock();
- } else {
- unlock();
+ synchronized (this.foreignKeysToTrust) {
+ for (Jid jid : contactJids) {
+ Map<String, Boolean> fingerprints = foreignKeysToTrust.get(jid);
+ if (hasNoOtherTrustedKeys(jid) && (fingerprints == null || !fingerprints.values().contains(true))) {
+ lock();
+ return;
+ }
+ }
}
+ unlock();
+
}
private void setDone() {
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java
index 1fbb3b1d..cf029ee3 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java
@@ -41,6 +41,7 @@ import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.text.InputType;
import android.util.DisplayMetrics;
+import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
@@ -378,7 +379,20 @@ public abstract class XmppActivity extends Activity {
}
}
- protected boolean showBatteryOptimizationWarning() {
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ final MenuItem menuSettings = menu.findItem(R.id.action_settings);
+ final MenuItem menuManageAccounts = menu.findItem(R.id.action_accounts);
+ if (menuSettings != null) {
+ menuSettings.setVisible(!Config.LOCK_SETTINGS);
+ }
+ if (menuManageAccounts != null) {
+ menuManageAccounts.setVisible(!Config.LOCK_SETTINGS);
+ }
+ return super.onCreateOptionsMenu(menu);
+ }
+
+ protected boolean isOptimizingBattery() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
return !pm.isIgnoringBatteryOptimizations(getPackageName());
@@ -786,7 +800,7 @@ public abstract class XmppActivity extends Activity {
+ "\n\n" + CryptoHelper.prettifyFingerprint(fingerprint.substring(2))
+ "\n\n" + getString(R.string.purge_key_desc_part2));
builder.setNegativeButton(getString(R.string.cancel), null);
- builder.setPositiveButton(getString(R.string.accept),
+ builder.setPositiveButton(getString(R.string.purge_key),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java
index 6a141f11..79f3412d 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java
@@ -17,6 +17,7 @@ import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
+import android.text.util.Linkify;
import android.util.DisplayMetrics;
import android.util.Patterns;
import android.view.View;
@@ -31,9 +32,11 @@ import android.widget.TextView;
import android.widget.Toast;
import java.lang.ref.WeakReference;
+import java.net.URL;
import java.util.List;
import java.util.concurrent.RejectedExecutionException;
import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.R;
@@ -57,6 +60,11 @@ public class MessageAdapter extends ArrayAdapter<Message> {
private static final int RECEIVED = 1;
private static final int STATUS = 2;
private static final int NULL = 3;
+ private static final Pattern XMPP_PATTERN = Pattern
+ .compile("xmpp\\:(?:(?:["
+ + Patterns.GOOD_IRI_CHAR
+ + "\\;\\/\\?\\@\\&\\=\\#\\~\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])"
+ + "|(?:\\%[a-fA-F0-9]{2}))+");
private ConversationActivity activity;
@@ -322,12 +330,40 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
viewHolder.messageBody.setText(span);
}
- int urlCount = 0;
- Matcher matcher = Patterns.WEB_URL.matcher(body);
- while (matcher.find()) {
- urlCount++;
+ int patternMatchCount = 0;
+ int oldAutoLinkMask = viewHolder.messageBody.getAutoLinkMask();
+ Matcher matcher = null;
+
+ // first check if we have a match on XMPP_PATTERN so we do not have to check for EMAIL_ADDRESSES
+ matcher = XMPP_PATTERN.matcher(body);
+ if ((Linkify.EMAIL_ADDRESSES & oldAutoLinkMask) != 0 && matcher.find()) {
+ oldAutoLinkMask -= Linkify.EMAIL_ADDRESSES;
}
- viewHolder.messageBody.setTextIsSelectable(urlCount <= 1);
+
+ // count matches for all patterns
+ if ((Linkify.WEB_URLS & oldAutoLinkMask) != 0) {
+ matcher = Patterns.WEB_URL.matcher(body);
+ while (matcher.find()) {
+ patternMatchCount++;
+ }
+ }
+ if ((Linkify.EMAIL_ADDRESSES & oldAutoLinkMask) != 0) {
+ matcher = Patterns.EMAIL_ADDRESS.matcher(body);
+ while (matcher.find()) {
+ patternMatchCount++;
+ }
+ }
+ if ((Linkify.PHONE_NUMBERS & oldAutoLinkMask) != 0) {
+ matcher = Patterns.PHONE.matcher(body);
+ while (matcher.find()) {
+ patternMatchCount++;
+ }
+ }
+
+ viewHolder.messageBody.setTextIsSelectable(patternMatchCount <= 1);
+ viewHolder.messageBody.setAutoLinkMask(0);
+ Linkify.addLinks(viewHolder.messageBody, XMPP_PATTERN, "xmpp");
+ viewHolder.messageBody.setAutoLinkMask(oldAutoLinkMask);
} else {
viewHolder.messageBody.setText("");
viewHolder.messageBody.setTextIsSelectable(false);
@@ -574,7 +610,19 @@ public class MessageAdapter extends ArrayAdapter<Message> {
if (GeoHelper.isGeoUri(message.getBody())) {
displayLocationMessage(viewHolder,message);
} else if (message.treatAsDownloadable() == Message.Decision.MUST) {
- displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message)));
+ try {
+ URL url = new URL(message.getBody());
+ displayDownloadableMessage(viewHolder,
+ message,
+ activity.getString(R.string.check_x_filesize_on_host,
+ UIHelper.getFileDescriptionString(activity, message),
+ url.getHost()));
+ } catch (Exception e) {
+ displayDownloadableMessage(viewHolder,
+ message,
+ activity.getString(R.string.check_x_filesize,
+ UIHelper.getFileDescriptionString(activity, message)));
+ }
} else {
displayTextMessage(viewHolder, message, darkBackground);
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/UIHelper.java b/src/main/java/de/thedevstack/conversationsplus/utils/UIHelper.java
index e1915e99..44dc4774 100644
--- a/src/main/java/de/thedevstack/conversationsplus/utils/UIHelper.java
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/UIHelper.java
@@ -183,10 +183,13 @@ public class UIHelper {
UIHelper.getMessageDisplayName(message) + " "), false);
} else if (GeoHelper.isGeoUri(message.getBody())) {
if (message.getStatus() == Message.STATUS_RECEIVED) {
- return new Pair<>(context.getString(R.string.received_location),true);
+ return new Pair<>(context.getString(R.string.received_location), true);
} else {
return new Pair<>(context.getString(R.string.location), true);
}
+ } else if (message.treatAsDownloadable() == Message.Decision.MUST) {
+ return new Pair<>(context.getString(R.string.x_file_offered_for_download,
+ getFileDescriptionString(context,message)),true);
} else{
return new Pair<>(message.getBody(), false);
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java
index de5f3ab1..b57653d4 100644
--- a/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java
@@ -221,7 +221,7 @@ public class JingleConnection implements Transferable {
public void init(final Message message) {
if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
Conversation conversation = message.getConversation();
- conversation.getAccount().getAxolotlService().prepareKeyTransportMessage(conversation.getContact(), new OnMessageCreatedCallback() {
+ conversation.getAccount().getAxolotlService().prepareKeyTransportMessage(conversation, new OnMessageCreatedCallback() {
@Override
public void run(XmppAxolotlMessage xmppAxolotlMessage) {
if (xmppAxolotlMessage != null) {
@@ -326,14 +326,14 @@ public class JingleConnection implements Transferable {
String[] filename = fileNameElement.getContent()
.toLowerCase(Locale.US).toLowerCase().split("\\.");
String extension = filename[filename.length - 1];
- if (Arrays.asList(VALID_IMAGE_EXTENSIONS).contains(extension)) {
+ if (VALID_IMAGE_EXTENSIONS.contains(extension)) {
message.setType(Message.TYPE_IMAGE);
message.setRelativeFilePath(message.getUuid()+"."+extension);
- } else if (Arrays.asList(VALID_CRYPTO_EXTENSIONS).contains(
+ } else if (VALID_CRYPTO_EXTENSIONS.contains(
filename[filename.length - 1])) {
if (filename.length == 3) {
extension = filename[filename.length - 2];
- if (Arrays.asList(VALID_IMAGE_EXTENSIONS).contains(extension)) {
+ if (VALID_IMAGE_EXTENSIONS.contains(extension)) {
message.setType(Message.TYPE_IMAGE);
message.setRelativeFilePath(message.getUuid()+"."+extension);
} else {