aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/services
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2016-05-31 21:38:06 +0200
committerChristian Schneppe <christian@pix-art.de>2016-05-31 21:38:06 +0200
commitc23642b8cd2c06c5f3e9cf7f88d31ed5c6f78614 (patch)
treea7c53e5dd6dd6e85213cff834d35316a29617753 /src/main/java/eu/siacs/conversations/services
parent2cdc31a6887f242dfe4faca91af63ffd4e74ef67 (diff)
parentea6a008b39b0f669f66f3c8aec08b4deb3ece154 (diff)
Merge remote-tracking branch 'refs/remotes/siacs/master'
Diffstat (limited to 'src/main/java/eu/siacs/conversations/services')
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java107
1 files changed, 54 insertions, 53 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 4a8d813e1..42dea8da6 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -96,6 +96,7 @@ import eu.siacs.conversations.utils.ExceptionHelper;
import eu.siacs.conversations.utils.OnPhoneContactsLoadedListener;
import eu.siacs.conversations.utils.PRNGFixes;
import eu.siacs.conversations.utils.PhoneHelper;
+import eu.siacs.conversations.utils.ReplacingSerialSingleThreadExecutor;
import eu.siacs.conversations.utils.SerialSingleThreadExecutor;
import eu.siacs.conversations.utils.Xmlns;
import eu.siacs.conversations.xml.Element;
@@ -123,7 +124,7 @@ import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
import me.leolin.shortcutbadger.ShortcutBadger;
-public class XmppConnectionService extends Service implements OnPhoneContactsLoadedListener {
+public class XmppConnectionService extends Service {
public static final String ACTION_CLEAR_NOTIFICATION = "clear_notification";
public static final String ACTION_DISABLE_FOREGROUND = "disable_foreground";
@@ -135,6 +136,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public static final String ACTION_GCM_MESSAGE_RECEIVED = "gcm_message_received";
private final SerialSingleThreadExecutor mFileAddingExecutor = new SerialSingleThreadExecutor();
private final SerialSingleThreadExecutor mDatabaseExecutor = new SerialSingleThreadExecutor();
+ private ReplacingSerialSingleThreadExecutor mContactMergerExecutor = new ReplacingSerialSingleThreadExecutor(true);
private final IBinder mBinder = new XmppConnectionBinder();
private final List<Conversation> conversations = new CopyOnWriteArrayList<>();
private final IqGenerator mIqGenerator = new IqGenerator(this);
@@ -350,7 +352,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
private WakeLock wakeLock;
private PowerManager pm;
private LruCache<String, Bitmap> mBitmapCache;
- private Thread mPhoneContactMergerThread;
private EventReceiver mEventReceiver = new EventReceiver();
private boolean mRestoredFromDatabase = false;
@@ -1148,53 +1149,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
sendIqPacket(account, iqPacket, mDefaultIqHandler);
}
- public void onPhoneContactsLoaded(final List<Bundle> phoneContacts) {
- if (mPhoneContactMergerThread != null) {
- mPhoneContactMergerThread.interrupt();
- }
- mPhoneContactMergerThread = new Thread(new Runnable() {
- @Override
- public void run() {
- Log.d(Config.LOGTAG, "start merging phone contacts with roster");
- for (Account account : accounts) {
- List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts();
- for (Bundle phoneContact : phoneContacts) {
- if (Thread.interrupted()) {
- Log.d(Config.LOGTAG, "interrupted merging phone contacts");
- return;
- }
- Jid jid;
- try {
- jid = Jid.fromString(phoneContact.getString("jid"));
- } catch (final InvalidJidException e) {
- continue;
- }
- final Contact contact = account.getRoster().getContact(jid);
- String systemAccount = phoneContact.getInt("phoneid")
- + "#"
- + phoneContact.getString("lookup");
- contact.setSystemAccount(systemAccount);
- if (contact.setPhotoUri(phoneContact.getString("photouri"))) {
- getAvatarService().clear(contact);
- }
- contact.setSystemName(phoneContact.getString("displayname"));
- withSystemAccounts.remove(contact);
- }
- for (Contact contact : withSystemAccounts) {
- contact.setSystemAccount(null);
- contact.setSystemName(null);
- if (contact.setPhotoUri(null)) {
- getAvatarService().clear(contact);
- }
- }
- }
- Log.d(Config.LOGTAG, "finished merging phone contacts");
- updateAccountUi();
- }
- });
- mPhoneContactMergerThread.start();
- }
-
private void restoreFromDatabase() {
synchronized (this.conversations) {
final Map<String, Account> accountLookupTable = new Hashtable<>();
@@ -1215,7 +1169,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
account.initAccountServices(XmppConnectionService.this); //roster needs to be loaded at this stage
}
getBitmapCache().evictAll();
- Looper.prepare();
loadPhoneContacts();
Log.d(Config.LOGTAG, "restoring messages");
for (Conversation conversation : conversations) {
@@ -1239,9 +1192,47 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public void loadPhoneContacts() {
- PhoneHelper.loadPhoneContacts(getApplicationContext(),
- new CopyOnWriteArrayList<Bundle>(),
- XmppConnectionService.this);
+ mContactMergerExecutor.execute(new Runnable() {
+ @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.fromString(phoneContact.getString("jid"));
+ } catch (final InvalidJidException e) {
+ continue;
+ }
+ final Contact contact = account.getRoster().getContact(jid);
+ String systemAccount = phoneContact.getInt("phoneid")
+ + "#"
+ + phoneContact.getString("lookup");
+ contact.setSystemAccount(systemAccount);
+ if (contact.setPhotoUri(phoneContact.getString("photouri"))) {
+ getAvatarService().clear(contact);
+ }
+ contact.setSystemName(phoneContact.getString("displayname"));
+ withSystemAccounts.remove(contact);
+ }
+ for (Contact contact : withSystemAccounts) {
+ contact.setSystemAccount(null);
+ contact.setSystemName(null);
+ if (contact.setPhotoUri(null)) {
+ getAvatarService().clear(contact);
+ }
+ }
+ }
+ Log.d(Config.LOGTAG, "finished merging phone contacts");
+ updateAccountUi();
+ }
+ });
+ }
+ });
}
public List<Conversation> getConversations() {
@@ -3120,6 +3111,16 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
return contacts;
}
+ public Conversation findFirstMuc(Jid jid) {
+ for(Conversation conversation : getConversations()) {
+ if (conversation.getJid().toBareJid().equals(jid.toBareJid())
+ && conversation.getMode() == Conversation.MODE_MULTI) {
+ return conversation;
+ }
+ }
+ return null;
+ }
+
public NotificationService getNotificationService() {
return this.mNotificationService;
}