aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-04-12 20:56:39 +0200
committerChristian Schneppe <christian@pix-art.de>2018-04-12 20:56:39 +0200
commitbdc3e725d1610d14374dc7983a612673d980e979 (patch)
treeb1fb509d17d7ddc8438c92a437fc02510e7696bd /src/main
parent681511379f85b3b01cf548bfb7493c8283e2072d (diff)
presist http upload availibility
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Account.java5
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java441
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/XmppConnection.java9
3 files changed, 183 insertions, 272 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Account.java b/src/main/java/de/pixart/messenger/entities/Account.java
index 222e33b3b..ef42ceeb7 100644
--- a/src/main/java/de/pixart/messenger/entities/Account.java
+++ b/src/main/java/de/pixart/messenger/entities/Account.java
@@ -60,16 +60,15 @@ public class Account extends AbstractEntity {
public static final int OPTION_MAGIC_CREATE = 4;
public static final int OPTION_REQUIRES_ACCESS_MODE_CHANGE = 5;
public static final int OPTION_LOGGED_IN_SUCCESSFULLY = 6;
+ public static final int OPTION_HTTP_UPLOAD_AVAILABLE = 7;
public final HashSet<Pair<String, String>> inProgressDiscoFetches = new HashSet<>();
public boolean httpUploadAvailable(long filesize) {
- //make httpUpload independent from filesize
- filesize = 0;
return xmppConnection != null && xmppConnection.getFeatures().httpUpload(filesize);
}
public boolean httpUploadAvailable() {
- return httpUploadAvailable(0);
+ return isOptionSet(OPTION_HTTP_UPLOAD_AVAILABLE) || httpUploadAvailable(0);
}
public void setDisplayName(String displayName) {
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index b6c5047ae..211ecc5fa 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -106,7 +106,6 @@ import de.pixart.messenger.parser.MessageParser;
import de.pixart.messenger.parser.PresenceParser;
import de.pixart.messenger.persistance.DatabaseBackend;
import de.pixart.messenger.persistance.FileBackend;
-import de.pixart.messenger.ui.ConversationsActivity;
import de.pixart.messenger.ui.SettingsActivity;
import de.pixart.messenger.ui.UiCallback;
import de.pixart.messenger.utils.ConversationsFileObserver;
@@ -149,10 +148,6 @@ import rocks.xmpp.addr.Jid;
public class XmppConnectionService extends Service {
- static {
- URL.setURLStreamHandlerFactory(new AesGcmURLStreamHandlerFactory());
- }
-
public static final String ACTION_REPLY_TO_CONVERSATION = "reply_to_conversations";
public static final String ACTION_MARK_AS_READ = "mark_as_read";
public static final String ACTION_SNOOZE = "snooze";
@@ -163,6 +158,12 @@ public class XmppConnectionService extends Service {
public static final String ACTION_GCM_TOKEN_REFRESH = "gcm_token_refresh";
public static final String ACTION_GCM_MESSAGE_RECEIVED = "gcm_message_received";
private static final String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts";
+
+ static {
+ URL.setURLStreamHandlerFactory(new AesGcmURLStreamHandlerFactory());
+ }
+
+ public final CountDownLatch restoredFromDatabaseLatch = new CountDownLatch(1);
private final SerialSingleThreadExecutor mFileAddingExecutor = new SerialSingleThreadExecutor("FileAdding");
private final SerialSingleThreadExecutor mVideoCompressionExecutor = new SerialSingleThreadExecutor("VideoCompression");
private final SerialSingleThreadExecutor mDatabaseWriterExecutor = new SerialSingleThreadExecutor("DatabaseWriter");
@@ -175,11 +176,7 @@ public class XmppConnectionService extends Service {
private final HashSet<Jid> mLowPingTimeoutMode = new HashSet<>();
public DatabaseBackend databaseBackend;
private ReplacingSerialSingleThreadExecutor mContactMergerExecutor = new ReplacingSerialSingleThreadExecutor(true);
- private WakeLock wakeLock;
private long mLastActivity = 0;
- ConversationsActivity mConversationsActivity;
-
-
private ContentObserver contactObserver = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
@@ -212,10 +209,6 @@ public class XmppConnectionService extends Service {
}
};
private MessageGenerator mMessageGenerator = new MessageGenerator(this);
- private PresenceGenerator mPresenceGenerator = new PresenceGenerator(this);
- private List<Account> accounts;
- private JingleConnectionManager mJingleConnectionManager = new JingleConnectionManager(
- this);
public OnContactStatusChanged onContactStatusChanged = new OnContactStatusChanged() {
@Override
@@ -239,13 +232,21 @@ public class XmppConnectionService extends Service {
}
}
};
+ private PresenceGenerator mPresenceGenerator = new PresenceGenerator(this);
+ private List<Account> accounts;
+ private JingleConnectionManager mJingleConnectionManager = new JingleConnectionManager(this);
+ private final OnJinglePacketReceived jingleListener = new OnJinglePacketReceived() {
+
+ @Override
+ public void onJinglePacketReceived(Account account, JinglePacket packet) {
+ mJingleConnectionManager.deliverPacket(account, packet);
+ }
+ };
public HttpConnectionManager mHttpConnectionManager = new HttpConnectionManager(this);
private AvatarService mAvatarService = new AvatarService(this);
private MessageArchiveService mMessageArchiveService = new MessageArchiveService(this);
private PushManagementService mPushManagementService = new PushManagementService(this);
private OnConversationUpdate mOnConversationUpdate = null;
-
-
private final ConversationsFileObserver fileObserver = new ConversationsFileObserver(
Environment.getExternalStorageDirectory().getAbsolutePath()
) {
@@ -254,13 +255,6 @@ public class XmppConnectionService extends Service {
markFileDeleted(path);
}
};
- private final OnJinglePacketReceived jingleListener = new OnJinglePacketReceived() {
-
- @Override
- public void onJinglePacketReceived(Account account, JinglePacket packet) {
- mJingleConnectionManager.deliverPacket(account, packet);
- }
- };
private final OnMessageAcknowledged mOnMessageAcknowledgedListener = new OnMessageAcknowledged() {
@Override
@@ -302,7 +296,10 @@ public class XmppConnectionService extends Service {
}
}
}
- if (account.setOption(Account.OPTION_LOGGED_IN_SUCCESSFULLY, true)) {
+ boolean needsUpdating = account.setOption(Account.OPTION_LOGGED_IN_SUCCESSFULLY, true);
+ needsUpdating |= account.setOption(Account.OPTION_HTTP_UPLOAD_AVAILABLE, account.getXmppConnection().getFeatures().httpUpload(0));
+ if (needsUpdating) {
+ Log.d(Config.LOGTAG, "account needed updating");
databaseBackend.updateAccount(account);
}
account.getRoster().clearPresences();
@@ -409,6 +406,17 @@ public class XmppConnectionService extends Service {
}
};
+ private OpenPgpServiceConnection pgpServiceConnection;
+ private PgpEngine mPgpEngine = null;
+ private WakeLock wakeLock;
+ private PowerManager pm;
+ private LruCache<String, Bitmap> mBitmapCache;
+ private EventReceiver mEventReceiver = new EventReceiver();
+
+ private static String generateFetchKey(Account account, final Avatar avatar) {
+ return account.getJid().asBareJid() + "_" + avatar.owner + "_" + avatar.sha1sum;
+ }
+
private boolean isInLowPingTimeoutMode(Account account) {
synchronized (mLowPingTimeoutMode) {
return mLowPingTimeoutMode.contains(account.getJid().asBareJid());
@@ -425,18 +433,6 @@ public class XmppConnectionService extends Service {
toggleForegroundService();
}
- private OpenPgpServiceConnection pgpServiceConnection;
- private PgpEngine mPgpEngine = null;
- private PowerManager pm;
- private LruCache<String, Bitmap> mBitmapCache;
- private EventReceiver mEventReceiver = new EventReceiver();
-
- public final CountDownLatch restoredFromDatabaseLatch = new CountDownLatch(1);
-
- private static String generateFetchKey(Account account, final Avatar avatar) {
- return account.getJid().asBareJid() + "_" + avatar.owner + "_" + avatar.sha1sum;
- }
-
public boolean areMessagesInitialized() {
return this.restoredFromDatabaseLatch.getCount() == 0;
}
@@ -538,26 +534,22 @@ public class XmppConnectionService extends Service {
}
message.setCounterpart(conversation.getNextCounterpart());
message.setType(Message.TYPE_IMAGE);
- mFileAddingExecutor.execute(new Runnable() {
-
- @Override
- public void run() {
- try {
- getFileBackend().copyImageToPrivateStorage(message, uri);
- if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
- final PgpEngine pgpEngine = getPgpEngine();
- if (pgpEngine != null) {
- pgpEngine.encrypt(message, callback);
- } else if (callback != null) {
- callback.error(R.string.unable_to_connect_to_keychain, null);
- }
- } else {
- sendMessage(message);
- callback.success(message);
+ mFileAddingExecutor.execute(() -> {
+ try {
+ getFileBackend().copyImageToPrivateStorage(message, uri);
+ if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
+ final PgpEngine pgpEngine = getPgpEngine();
+ if (pgpEngine != null) {
+ pgpEngine.encrypt(message, callback);
+ } else if (callback != null) {
+ callback.error(R.string.unable_to_connect_to_keychain, null);
}
- } catch (final FileBackend.FileCopyException e) {
- callback.error(e.getResId(), message);
+ } else {
+ sendMessage(message);
+ callback.success(message);
}
+ } catch (final FileBackend.FileCopyException e) {
+ callback.error(e.getResId(), message);
}
});
}
@@ -998,23 +990,20 @@ public class XmppConnectionService extends Service {
public void expireOldMessages(final boolean resetHasMessagesLeftOnServer) {
mLastExpiryRun.set(SystemClock.elapsedRealtime());
- mDatabaseWriterExecutor.execute(new Runnable() {
- @Override
- public void run() {
- long timestamp = getAutomaticMessageDeletionDate();
- if (timestamp > 0) {
- databaseBackend.expireOldMessages(timestamp);
- synchronized (XmppConnectionService.this.conversations) {
- for (Conversation conversation : XmppConnectionService.this.conversations) {
- conversation.expireOldMessages(timestamp);
- if (resetHasMessagesLeftOnServer) {
- conversation.messagesLoaded.set(true);
- conversation.setHasMessagesLeftOnServer(true);
- }
+ mDatabaseWriterExecutor.execute(() -> {
+ long timestamp = getAutomaticMessageDeletionDate();
+ if (timestamp > 0) {
+ databaseBackend.expireOldMessages(timestamp);
+ synchronized (XmppConnectionService.this.conversations) {
+ for (Conversation conversation : XmppConnectionService.this.conversations) {
+ conversation.expireOldMessages(timestamp);
+ if (resetHasMessagesLeftOnServer) {
+ conversation.messagesLoaded.set(true);
+ conversation.setHasMessagesLeftOnServer(true);
}
}
- updateConversationUi();
}
+ updateConversationUi();
}
});
}
@@ -1114,12 +1103,7 @@ public class XmppConnectionService extends Service {
restoreFromDatabase();
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactObserver);
- new Thread(new Runnable() {
- @Override
- public void run() {
- fileObserver.startWatching();
- }
- }).start();
+ new Thread(() -> fileObserver.startWatching()).start();
if (Config.supportOpenPgp()) {
this.pgpServiceConnection = new OpenPgpServiceConnection(this, "org.sufficientlysecure.keychain", new OpenPgpServiceConnection.OnBound() {
@Override
@@ -1220,12 +1204,7 @@ public class XmppConnectionService extends Service {
}
databaseBackend.writeRoster(account.getRoster());
if (account.getXmppConnection() != null) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- disconnect(account, false);
- }
- }).start();
+ new Thread(() -> disconnect(account, false)).start();
}
}
if (stop || activeAccounts == 0) {
@@ -1590,97 +1569,78 @@ public class XmppConnectionService extends Service {
}
long diffConversationsRestore = SystemClock.elapsedRealtime() - startTimeConversationsRestore;
Log.d(Config.LOGTAG, "finished restoring conversations in " + diffConversationsRestore + "ms");
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- long deletionDate = getAutomaticMessageDeletionDate();
- mLastExpiryRun.set(SystemClock.elapsedRealtime());
- if (deletionDate > 0) {
- Log.d(Config.LOGTAG, "deleting messages that are older than " + AbstractGenerator.getTimestamp(deletionDate));
- databaseBackend.expireOldMessages(deletionDate);
- }
- Log.d(Config.LOGTAG, "restoring roster...");
- for (Account account : accounts) {
- databaseBackend.readRoster(account.getRoster());
- account.initAccountServices(XmppConnectionService.this); //roster needs to be loaded at this stage
- }
- getBitmapCache().evictAll();
- loadPhoneContacts();
- Log.d(Config.LOGTAG, "restoring messages...");
- final long startMessageRestore = SystemClock.elapsedRealtime();
- for (Conversation conversation : conversations) {
- conversation.addAll(0, databaseBackend.getMessages(conversation, Config.PAGE_SIZE));
- checkDeletedFiles(conversation);
- conversation.findUnsentTextMessages(new Conversation.OnMessageFound() {
-
- @Override
- public void onMessageFound(Message message) {
- markMessage(message, Message.STATUS_WAITING);
- }
- });
- conversation.findUnreadMessages(new Conversation.OnMessageFound() {
- @Override
- public void onMessageFound(Message message) {
- mNotificationService.pushFromBacklog(message);
- }
- });
- }
- mNotificationService.finishBacklog(false);
- restoredFromDatabaseLatch.countDown();
- final long diffMessageRestore = SystemClock.elapsedRealtime() - startMessageRestore;
- Log.d(Config.LOGTAG, "finished restoring messages in " + diffMessageRestore + "ms");
- updateConversationUi();
+ Runnable runnable = () -> {
+ long deletionDate = getAutomaticMessageDeletionDate();
+ mLastExpiryRun.set(SystemClock.elapsedRealtime());
+ if (deletionDate > 0) {
+ Log.d(Config.LOGTAG, "deleting messages that are older than " + AbstractGenerator.getTimestamp(deletionDate));
+ databaseBackend.expireOldMessages(deletionDate);
}
+ Log.d(Config.LOGTAG, "restoring roster...");
+ for (Account account : accounts) {
+ databaseBackend.readRoster(account.getRoster());
+ account.initAccountServices(XmppConnectionService.this); //roster needs to be loaded at this stage
+ }
+ getBitmapCache().evictAll();
+ loadPhoneContacts();
+ Log.d(Config.LOGTAG, "restoring messages...");
+ final long startMessageRestore = SystemClock.elapsedRealtime();
+ for (Conversation conversation : conversations) {
+ conversation.addAll(0, databaseBackend.getMessages(conversation, Config.PAGE_SIZE));
+ checkDeletedFiles(conversation);
+ conversation.findUnsentTextMessages(message -> markMessage(message, Message.STATUS_WAITING));
+ conversation.findUnreadMessages(message -> mNotificationService.pushFromBacklog(message));
+ }
+ mNotificationService.finishBacklog(false);
+ restoredFromDatabaseLatch.countDown();
+ final long diffMessageRestore = SystemClock.elapsedRealtime() - startMessageRestore;
+ Log.d(Config.LOGTAG, "finished restoring messages in " + diffMessageRestore + "ms");
+ updateConversationUi();
};
mDatabaseReaderExecutor.execute(runnable); //will contain one write command (expiry) but that's fine
}
}
public void loadPhoneContacts() {
- mContactMergerExecutor.execute(new Runnable() {
+ mContactMergerExecutor.execute(() -> PhoneHelper.loadPhoneContacts(XmppConnectionService.this, new OnPhoneContactsLoadedListener() {
@Override
- public void run() {
- PhoneHelper.loadPhoneContacts(XmppConnectionService.this, new OnPhoneContactsLoadedListener() {
- @Override
- public void onPhoneContactsLoaded(List<Bundle> phoneContacts) {
- Log.d(Config.LOGTAG, "start merging phone contacts with roster");
- for (Account account : accounts) {
- List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts();
- for (Bundle phoneContact : phoneContacts) {
- Jid jid;
- try {
- jid = Jid.of(phoneContact.getString("jid"));
- } catch (final IllegalArgumentException e) {
- continue;
- }
- final Contact contact = account.getRoster().getContact(jid);
- String systemAccount = phoneContact.getInt("phoneid")
- + "#"
- + phoneContact.getString("lookup");
- contact.setSystemAccount(systemAccount);
- boolean needsCacheClean = contact.setPhotoUri(phoneContact.getString("photouri"));
- needsCacheClean |= contact.setSystemName(phoneContact.getString("displayname"));
- if (needsCacheClean) {
- getAvatarService().clear(contact);
- }
- withSystemAccounts.remove(contact);
- }
- for (Contact contact : withSystemAccounts) {
- contact.setSystemAccount(null);
- boolean needsCacheClean = contact.setPhotoUri(null);
- needsCacheClean |= contact.setSystemName(null);
- if (needsCacheClean) {
- getAvatarService().clear(contact);
- }
- }
+ public void onPhoneContactsLoaded(List<Bundle> phoneContacts) {
+ Log.d(Config.LOGTAG, "start merging phone contacts with roster");
+ for (Account account : accounts) {
+ List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts();
+ for (Bundle phoneContact : phoneContacts) {
+ Jid jid;
+ try {
+ jid = Jid.of(phoneContact.getString("jid"));
+ } catch (final IllegalArgumentException e) {
+ continue;
}
- Log.d(Config.LOGTAG, "finished merging phone contacts");
- mShortcutService.refresh(mInitialAddressbookSyncCompleted.compareAndSet(false, true));
- updateAccountUi();
+ final Contact contact = account.getRoster().getContact(jid);
+ String systemAccount = phoneContact.getInt("phoneid")
+ + "#"
+ + phoneContact.getString("lookup");
+ contact.setSystemAccount(systemAccount);
+ boolean needsCacheClean = contact.setPhotoUri(phoneContact.getString("photouri"));
+ needsCacheClean |= contact.setSystemName(phoneContact.getString("displayname"));
+ if (needsCacheClean) {
+ getAvatarService().clear(contact);
+ }
+ withSystemAccounts.remove(contact);
}
- });
+ for (Contact contact : withSystemAccounts) {
+ contact.setSystemAccount(null);
+ boolean needsCacheClean = contact.setPhotoUri(null);
+ needsCacheClean |= contact.setSystemName(null);
+ if (needsCacheClean) {
+ getAvatarService().clear(contact);
+ }
+ }
+ }
+ Log.d(Config.LOGTAG, "finished merging phone contacts");
+ mShortcutService.refresh(mInitialAddressbookSyncCompleted.compareAndSet(false, true));
+ updateAccountUi();
}
- });
+ }));
}
public List<Conversation> getConversations() {
@@ -1688,16 +1648,12 @@ public class XmppConnectionService extends Service {
}
private void checkDeletedFiles(Conversation conversation) {
- conversation.findMessagesWithFiles(new Conversation.OnMessageFound() {
-
- @Override
- public void onMessageFound(Message message) {
- if (!getFileBackend().isFileAvailable(message)) {
- message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
- final int s = message.getStatus();
- if (s == Message.STATUS_WAITING || s == Message.STATUS_OFFERED || s == Message.STATUS_UNSEND) {
- markMessage(message, Message.STATUS_SEND_FAILED);
- }
+ conversation.findMessagesWithFiles(message -> {
+ if (!getFileBackend().isFileAvailable(message)) {
+ message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
+ final int s = message.getStatus();
+ if (s == Message.STATUS_WAITING || s == Message.STATUS_OFFERED || s == Message.STATUS_UNSEND) {
+ markMessage(message, Message.STATUS_SEND_FAILED);
}
}
});
@@ -1706,22 +1662,19 @@ public class XmppConnectionService extends Service {
private void markFileDeleted(final String path) {
Log.d(Config.LOGTAG, "deleted file " + path);
for (Conversation conversation : getConversations()) {
- conversation.findMessagesWithFiles(new Conversation.OnMessageFound() {
- @Override
- public void onMessageFound(Message message) {
- DownloadableFile file = fileBackend.getFile(message);
- if (file.getAbsolutePath().equals(path)) {
- if (!file.exists()) {
- message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
- final int s = message.getStatus();
- if (s == Message.STATUS_WAITING || s == Message.STATUS_OFFERED || s == Message.STATUS_UNSEND) {
- markMessage(message, Message.STATUS_SEND_FAILED);
- } else {
- updateConversationUi();
- }
+ conversation.findMessagesWithFiles(message -> {
+ DownloadableFile file = fileBackend.getFile(message);
+ if (file.getAbsolutePath().equals(path)) {
+ if (!file.exists()) {
+ message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
+ final int s = message.getStatus();
+ if (s == Message.STATUS_WAITING || s == Message.STATUS_OFFERED || s == Message.STATUS_UNSEND) {
+ markMessage(message, Message.STATUS_SEND_FAILED);
} else {
- Log.d(Config.LOGTAG, "found matching message for file " + path + " but file still exists");
+ updateConversationUi();
}
+ } else {
+ Log.d(Config.LOGTAG, "found matching message for file " + path + " but file still exists");
}
}
});
@@ -3408,12 +3361,7 @@ public class XmppConnectionService extends Service {
}
public void reconnectAccountInBackground(final Account account) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- reconnectAccount(account, false, true);
- }
- }).start();
+ new Thread(() -> reconnectAccount(account, false, true)).start();
}
public void invite(Conversation conversation, Jid contact) {
@@ -3653,12 +3601,9 @@ public class XmppConnectionService extends Service {
}
final List<Message> readMessages = conversation.markRead();
if (readMessages.size() > 0) {
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- for (Message message : readMessages) {
- databaseBackend.updateMessage(message);
- }
+ Runnable runnable = () -> {
+ for (Message message : readMessages) {
+ databaseBackend.updateMessage(message);
}
};
mDatabaseWriterExecutor.execute(runnable);
@@ -3670,20 +3615,16 @@ public class XmppConnectionService extends Service {
}
public synchronized void updateUnreadCountBadge() {
- new Thread(new Runnable() {
-
- @Override
- public void run() {
- int count = unreadCount();
- if (unreadCount != count) {
- Log.d(Config.LOGTAG, "update unread count to " + count);
- if (count > 0) {
- ShortcutBadger.applyCount(getApplicationContext(), count);
- } else {
- ShortcutBadger.removeCount(getApplicationContext());
- }
- unreadCount = count;
+ new Thread(() -> {
+ int count = unreadCount();
+ if (unreadCount != count) {
+ Log.d(Config.LOGTAG, "update unread count to " + count);
+ if (count > 0) {
+ ShortcutBadger.applyCount(getApplicationContext(), count);
+ } else {
+ ShortcutBadger.removeCount(getApplicationContext());
}
+ unreadCount = count;
}
}).start();
}
@@ -3730,24 +3671,13 @@ public class XmppConnectionService extends Service {
setMemorizingTrustManager(tm);
}
- public PowerManager getPowerManager() {
- return this.pm;
- }
-
public LruCache<String, Bitmap> getBitmapCache() {
return this.mBitmapCache;
}
public void syncRosterToDisk(final Account account) {
- Runnable runnable = new Runnable() {
-
- @Override
- public void run() {
- databaseBackend.writeRoster(account.getRoster());
- }
- };
+ Runnable runnable = () -> databaseBackend.writeRoster(account.getRoster());
mDatabaseWriterExecutor.execute(runnable);
-
}
public Collection<String> getKnownHosts() {
@@ -3961,13 +3891,10 @@ public class XmppConnectionService extends Service {
conversation.clearMessages();
conversation.setHasMessagesLeftOnServer(false); //avoid messages getting loaded through mam
conversation.setLastClearHistory(clearDate, reference);
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- databaseBackend.deleteMessagesInConversation(conversation);
- databaseBackend.updateConversation(conversation);
+ Runnable runnable = () -> {
+ databaseBackend.deleteMessagesInConversation(conversation);
+ databaseBackend.updateConversation(conversation);
- }
};
mDatabaseWriterExecutor.execute(runnable);
}
@@ -4037,12 +3964,9 @@ public class XmppConnectionService extends Service {
String displayName = account.getDisplayName();
if (displayName != null && !displayName.isEmpty()) {
IqPacket publish = mIqGenerator.publishNick(displayName);
- sendIqPacket(account, publish, new OnIqPacketReceived() {
- @Override
- public void onIqPacketReceived(Account account, IqPacket packet) {
- if (packet.getType() == IqPacket.TYPE.ERROR) {
- Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not publish nick");
- }
+ sendIqPacket(account, publish, (account1, packet) -> {
+ if (packet.getType() == IqPacket.TYPE.ERROR) {
+ Log.d(Config.LOGTAG, account1.getJid().asBareJid() + ": could not publish nick");
}
});
}
@@ -4073,20 +3997,17 @@ public class XmppConnectionService extends Service {
request.setTo(jid);
request.query("http://jabber.org/protocol/disco#info");
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": making disco request for " + key.second + " to " + jid);
- sendIqPacket(account, request, new OnIqPacketReceived() {
- @Override
- public void onIqPacketReceived(Account account, IqPacket discoPacket) {
- if (discoPacket.getType() == IqPacket.TYPE.RESULT) {
- ServiceDiscoveryResult disco = new ServiceDiscoveryResult(discoPacket);
- if (presence.getVer().equals(disco.getVer())) {
- databaseBackend.insertDiscoveryResult(disco);
- injectServiceDiscorveryResult(account.getRoster(), presence.getHash(), presence.getVer(), disco);
- } else {
- Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": mismatch in caps for contact " + jid + " " + presence.getVer() + " vs " + disco.getVer());
- }
+ sendIqPacket(account, request, (account1, discoPacket) -> {
+ if (discoPacket.getType() == IqPacket.TYPE.RESULT) {
+ ServiceDiscoveryResult disco1 = new ServiceDiscoveryResult(discoPacket);
+ if (presence.getVer().equals(disco1.getVer())) {
+ databaseBackend.insertDiscoveryResult(disco1);
+ injectServiceDiscorveryResult(account1.getRoster(), presence.getHash(), presence.getVer(), disco1);
+ } else {
+ Log.d(Config.LOGTAG, account1.getJid().asBareJid() + ": mismatch in caps for contact " + jid + " " + presence.getVer() + " vs " + disco1.getVer());
}
- account.inProgressDiscoFetches.remove(key);
}
+ account1.inProgressDiscoFetches.remove(key);
});
}
}
@@ -4106,15 +4027,12 @@ public class XmppConnectionService extends Service {
final boolean legacy = account.getXmppConnection().getFeatures().mamLegacy();
IqPacket request = new IqPacket(IqPacket.TYPE.GET);
request.addChild("prefs",legacy ? Namespace.MAM_LEGACY : Namespace.MAM);
- sendIqPacket(account, request, new OnIqPacketReceived() {
- @Override
- public void onIqPacketReceived(Account account, IqPacket packet) {
- Element prefs = packet.findChild("prefs",legacy ? Namespace.MAM_LEGACY : Namespace.MAM);
- if (packet.getType() == IqPacket.TYPE.RESULT && prefs != null) {
- callback.onPreferencesFetched(prefs);
- } else {
- callback.onPreferencesFetchFailed();
- }
+ sendIqPacket(account, request, (account1, packet) -> {
+ Element prefs = packet.findChild("prefs",legacy ? Namespace.MAM_LEGACY : Namespace.MAM);
+ if (packet.getType() == IqPacket.TYPE.RESULT && prefs != null) {
+ callback.onPreferencesFetched(prefs);
+ } else {
+ callback.onPreferencesFetchFailed();
}
});
}
@@ -4228,12 +4146,6 @@ public class XmppConnectionService extends Service {
return getPreferences().getBoolean(SettingsActivity.SHOW_FOREGROUND_SERVICE, getResources().getBoolean(R.bool.show_foreground_service));
}
- public void pushMamPreferences(Account account, Element prefs) {
- IqPacket set = new IqPacket(IqPacket.TYPE.SET);
- set.addChild(prefs);
- sendIqPacket(account, set, null);
- }
-
public void ScheduleAutomaticExport() {
//start export log service every day at given time
if (Config.ExportLogs) {
@@ -4287,7 +4199,11 @@ public class XmppConnectionService extends Service {
return mShortcutService;
}
-
+ public void pushMamPreferences(Account account, Element prefs) {
+ IqPacket set = new IqPacket(IqPacket.TYPE.SET);
+ set.addChild(prefs);
+ sendIqPacket(account, set, null);
+ }
public interface OnMamPreferencesFetched {
void onPreferencesFetched(Element prefs);
@@ -4340,10 +4256,7 @@ public class XmppConnectionService extends Service {
}
public interface OnCaptchaRequested {
- void onCaptchaRequested(Account account,
- String id,
- Data data,
- Bitmap captcha);
+ void onCaptchaRequested(Account account, String id, Data data, Bitmap captcha);
}
public interface OnRosterUpdate {
diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
index 515f0b3c6..03005b6e3 100644
--- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
+++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
@@ -37,6 +37,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Random;
+import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -143,8 +144,8 @@ public class XmppConnection implements Runnable {
private final HashMap<Jid, ServiceDiscoveryResult> disco = new HashMap<>();
private final SparseArray<AbstractAcknowledgeableStanza> mStanzaQueue = new SparseArray<>();
private final Hashtable<String, Pair<IqPacket, OnIqPacketReceived>> packetCallbacks = new Hashtable<>();
- private final ArrayList<OnAdvancedStreamFeaturesLoaded> advancedStreamFeaturesLoadedListeners = new ArrayList<>();
- private final XmppConnectionService mXmppConnectionService;
+ private final Set<OnAdvancedStreamFeaturesLoaded> advancedStreamFeaturesLoadedListeners = new HashSet<>();
+ private final XmppConnectionService mXmppConnectionService;
private Socket socket;
private XmlReader tagReader;
private TagWriter tagWriter = new TagWriter();
@@ -1462,9 +1463,7 @@ public class XmppConnection implements Runnable {
}
public void addOnAdvancedStreamFeaturesAvailableListener(final OnAdvancedStreamFeaturesLoaded listener) {
- if (!this.advancedStreamFeaturesLoadedListeners.contains(listener)) {
- this.advancedStreamFeaturesLoadedListeners.add(listener);
- }
+ this.advancedStreamFeaturesLoadedListeners.add(listener);
}
private void forceCloseSocket() {