aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java2
-rw-r--r--src/main/java/de/pixart/messenger/entities/Conversation.java2
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java36
-rw-r--r--src/main/java/de/pixart/messenger/utils/ReplacingSerialSingleThreadExecutor.java2
-rw-r--r--src/main/java/de/pixart/messenger/utils/SerialSingleThreadExecutor.java15
5 files changed, 29 insertions, 28 deletions
diff --git a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
index 87d37788c..26c364eac 100644
--- a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
+++ b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
@@ -276,7 +276,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
this.messageCache = new HashMap<>();
this.sessions = new SessionMap(mXmppConnectionService, axolotlStore, account);
this.fetchStatusMap = new FetchStatusMap();
- this.executor = new SerialSingleThreadExecutor();
+ this.executor = new SerialSingleThreadExecutor("Axolotl");
}
public String getOwnFingerprint() {
diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java
index 833b1eb3b..2d4ab926d 100644
--- a/src/main/java/de/pixart/messenger/entities/Conversation.java
+++ b/src/main/java/de/pixart/messenger/entities/Conversation.java
@@ -886,7 +886,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
public boolean setAttribute(String key, String value) {
synchronized (this.attributes) {
try {
- this.attributes.put(key, value);
+ this.attributes.put(key, value == null ? "" : value);
return true;
} catch (JSONException e) {
return false;
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index 2e31ad2bb..2728cd8cd 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -159,9 +159,10 @@ 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";
- private final SerialSingleThreadExecutor mFileAddingExecutor = new SerialSingleThreadExecutor();
- private final SerialSingleThreadExecutor mVideoCompressionExecutor = new SerialSingleThreadExecutor();
- private final SerialSingleThreadExecutor mDatabaseExecutor = new SerialSingleThreadExecutor();
+ private final SerialSingleThreadExecutor mFileAddingExecutor = new SerialSingleThreadExecutor("FileAdding");
+ private final SerialSingleThreadExecutor mVideoCompressionExecutor = new SerialSingleThreadExecutor("VideoCompression");
+ private final SerialSingleThreadExecutor mDatabaseWriterExecutor = new SerialSingleThreadExecutor("DatabaseWriter");
+ private final SerialSingleThreadExecutor mDatabaseReaderExecutor = new SerialSingleThreadExecutor("DatabaseReader");
private final IBinder mBinder = new XmppConnectionBinder();
private final List<Conversation> conversations = new CopyOnWriteArrayList<>();
private final IqGenerator mIqGenerator = new IqGenerator(this);
@@ -937,7 +938,7 @@ public class XmppConnectionService extends Service {
public void expireOldMessages(final boolean resetHasMessagesLeftOnServer) {
mLastExpiryRun.set(SystemClock.elapsedRealtime());
- mDatabaseExecutor.execute(new Runnable() {
+ mDatabaseWriterExecutor.execute(new Runnable() {
@Override
public void run() {
long timestamp = getAutomaticMessageDeletionDate();
@@ -1582,7 +1583,7 @@ public class XmppConnectionService extends Service {
updateConversationUi();
}
};
- mDatabaseExecutor.execute(runnable);
+ mDatabaseReaderExecutor.execute(runnable); //will contain one write command (expiry) but that's fine
}
}
@@ -1733,7 +1734,7 @@ public class XmppConnectionService extends Service {
}
}
};
- mDatabaseExecutor.execute(runnable);
+ mDatabaseReaderExecutor.execute(runnable);
}
public List<Account> getAccounts() {
@@ -1846,7 +1847,7 @@ public class XmppConnectionService extends Service {
}
};
if (async) {
- mDatabaseExecutor.execute(runnable);
+ mDatabaseReaderExecutor.execute(runnable);
} else {
runnable.run();
}
@@ -1895,7 +1896,7 @@ public class XmppConnectionService extends Service {
loadMessagesFromDb = false;
}
final Conversation c = conversation;
- mDatabaseExecutor.execute(new Runnable() {
+ mDatabaseReaderExecutor.execute(new Runnable() {
@Override
public void run() {
if (loadMessagesFromDb) {
@@ -2078,7 +2079,7 @@ public class XmppConnectionService extends Service {
}
}
};
- mDatabaseExecutor.execute(runnable);
+ mDatabaseWriterExecutor.execute(runnable);
this.accounts.remove(account);
updateAccountUi();
getNotificationService().updateErrorNotification();
@@ -3271,7 +3272,7 @@ public class XmppConnectionService extends Service {
}
public void updateConversation(final Conversation conversation) {
- mDatabaseExecutor.execute(new Runnable() {
+ mDatabaseWriterExecutor.execute(new Runnable() {
@Override
public void run() {
databaseBackend.updateConversation(conversation);
@@ -3558,7 +3559,7 @@ public class XmppConnectionService extends Service {
}
}
};
- mDatabaseExecutor.execute(runnable);
+ mDatabaseWriterExecutor.execute(runnable);
updateUnreadCountBadge();
return true;
} else {
@@ -3638,7 +3639,7 @@ public class XmppConnectionService extends Service {
databaseBackend.writeRoster(account.getRoster());
}
};
- mDatabaseExecutor.execute(runnable);
+ mDatabaseWriterExecutor.execute(runnable);
}
@@ -3860,7 +3861,7 @@ public class XmppConnectionService extends Service {
}
};
- mDatabaseExecutor.execute(runnable);
+ mDatabaseWriterExecutor.execute(runnable);
}
public boolean sendBlockRequest(final Blockable blockable, boolean reportSpam) {
@@ -4076,15 +4077,6 @@ public class XmppConnectionService extends Service {
conversation.setBookmark(bookmark);
}
- public void clearStartTimeCounter() {
- mDatabaseExecutor.execute(new Runnable() {
- @Override
- public void run() {
- databaseBackend.clearStartTimeCounter(false);
- }
- });
- }
-
public boolean verifyFingerprints(Contact contact, List<XmppUri.Fingerprint> fingerprints) {
boolean needsRosterWrite = false;
boolean performedVerification = false;
diff --git a/src/main/java/de/pixart/messenger/utils/ReplacingSerialSingleThreadExecutor.java b/src/main/java/de/pixart/messenger/utils/ReplacingSerialSingleThreadExecutor.java
index bad93072d..22ad7f7a4 100644
--- a/src/main/java/de/pixart/messenger/utils/ReplacingSerialSingleThreadExecutor.java
+++ b/src/main/java/de/pixart/messenger/utils/ReplacingSerialSingleThreadExecutor.java
@@ -3,7 +3,7 @@ package de.pixart.messenger.utils;
public class ReplacingSerialSingleThreadExecutor extends SerialSingleThreadExecutor {
public ReplacingSerialSingleThreadExecutor(boolean prepareLooper) {
- super(prepareLooper);
+ super(ReplacingSerialSingleThreadExecutor.class.getName(), prepareLooper);
}
@Override
diff --git a/src/main/java/de/pixart/messenger/utils/SerialSingleThreadExecutor.java b/src/main/java/de/pixart/messenger/utils/SerialSingleThreadExecutor.java
index b4ecf6e5e..ea1fb81f1 100644
--- a/src/main/java/de/pixart/messenger/utils/SerialSingleThreadExecutor.java
+++ b/src/main/java/de/pixart/messenger/utils/SerialSingleThreadExecutor.java
@@ -1,22 +1,26 @@
package de.pixart.messenger.utils;
import android.os.Looper;
+import android.util.Log;
import java.util.ArrayDeque;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
+import de.pixart.messenger.Config;
+
public class SerialSingleThreadExecutor implements Executor {
final Executor executor = Executors.newSingleThreadExecutor();
protected final ArrayDeque<Runnable> tasks = new ArrayDeque<>();
private Runnable active;
+ private final String name;
- public SerialSingleThreadExecutor() {
- this(false);
+ public SerialSingleThreadExecutor(String name) {
+ this(name, false);
}
- public SerialSingleThreadExecutor(boolean prepareLooper) {
+ public SerialSingleThreadExecutor(String name, boolean prepareLooper) {
if (prepareLooper) {
execute(new Runnable() {
@Override
@@ -25,6 +29,7 @@ public class SerialSingleThreadExecutor implements Executor {
}
});
}
+ this.name = name;
}
public synchronized void execute(final Runnable r) {
@@ -45,6 +50,10 @@ public class SerialSingleThreadExecutor implements Executor {
protected synchronized void scheduleNext() {
if ((active = tasks.poll()) != null) {
executor.execute(active);
+ int remaining = tasks.size();
+ if (remaining > 0) {
+ Log.d(Config.LOGTAG, remaining + " remaining tasks on executor '" + name + "'");
+ }
}
}
} \ No newline at end of file