This commit is contained in:
Daniel Gultsch 2014-05-22 09:36:00 +02:00
parent 1db807ef58
commit f0d2ca260e
2 changed files with 36 additions and 24 deletions

View file

@ -288,5 +288,6 @@ public class Contact {
public static final int IN_ROSTER = 8; public static final int IN_ROSTER = 8;
public static final int PENDING_SUBSCRIPTION_REQUEST = 16; public static final int PENDING_SUBSCRIPTION_REQUEST = 16;
public static final int DIRTY_PUSH = 32; public static final int DIRTY_PUSH = 32;
public static final int DIRTY_DELETE = 64;
} }
} }

View file

@ -110,7 +110,8 @@ public class XmppConnectionService extends Service {
@Override @Override
public void onChange(boolean selfChange) { public void onChange(boolean selfChange) {
super.onChange(selfChange); super.onChange(selfChange);
Intent intent = new Intent(getApplicationContext(), XmppConnectionService.class); Intent intent = new Intent(getApplicationContext(),
XmppConnectionService.class);
intent.setAction(ACTION_MERGE_PHONE_CONTACTS); intent.setAction(ACTION_MERGE_PHONE_CONTACTS);
startService(intent); startService(intent);
} }
@ -243,7 +244,8 @@ public class XmppConnectionService extends Service {
} else if (account.getStatus() == Account.STATUS_REGISTRATION_SUCCESSFULL) { } else if (account.getStatus() == Account.STATUS_REGISTRATION_SUCCESSFULL) {
databaseBackend.updateAccount(account); databaseBackend.updateAccount(account);
reconnectAccount(account, true); reconnectAccount(account, true);
} else if (account.getStatus() != Account.STATUS_CONNECTING) { } else if ((account.getStatus() != Account.STATUS_CONNECTING)
&& (account.getStatus() != Account.STATUS_NO_INTERNET)) {
int next = account.getXmppConnection().getTimeToNextAttempt(); int next = account.getXmppConnection().getTimeToNextAttempt();
Log.d(LOGTAG, account.getJid() Log.d(LOGTAG, account.getJid()
+ ": error connecting account. try again in " + next + ": error connecting account. try again in " + next
@ -508,10 +510,12 @@ public class XmppConnectionService extends Service {
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
this.wakeLock.acquire(); this.wakeLock.acquire();
if ((intent!=null)&&(ACTION_MERGE_PHONE_CONTACTS.equals(intent.getAction()))) { if ((intent != null)
&& (ACTION_MERGE_PHONE_CONTACTS.equals(intent.getAction()))) {
mergePhoneContactsWithRoster(); mergePhoneContactsWithRoster();
return START_STICKY; return START_STICKY;
} else if ((intent!=null)&&(Intent.ACTION_SHUTDOWN.equals(intent.getAction()))){ } else if ((intent != null)
&& (Intent.ACTION_SHUTDOWN.equals(intent.getAction()))) {
logoutAndSave(); logoutAndSave();
return START_NOT_STICKY; return START_NOT_STICKY;
} }
@ -625,10 +629,11 @@ public class XmppConnectionService extends Service {
} }
} }
Context context = getApplicationContext(); Context context = getApplicationContext();
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlarmManager alarmManager = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, EventReceiver.class); Intent intent = new Intent(context, EventReceiver.class);
alarmManager.cancel(PendingIntent.getBroadcast(context, 0, intent, 0)); alarmManager.cancel(PendingIntent.getBroadcast(context, 0, intent, 0));
Log.d(LOGTAG,"good bye"); Log.d(LOGTAG, "good bye");
stopSelf(); stopSelf();
} }
@ -1192,13 +1197,6 @@ public class XmppConnectionService extends Service {
contact.setOption(Contact.Options.ASKING); contact.setOption(Contact.Options.ASKING);
} }
pushContactToServer(contact); pushContactToServer(contact);
if (autoGrant) {
requestPresenceUpdatesFrom(contact);
if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
Log.d("xmppService", "contact had pending subscription");
sendPresenceUpdatesTo(contact);
}
}
} }
public void pushContactToServer(Contact contact) { public void pushContactToServer(Contact contact) {
@ -1208,18 +1206,31 @@ public class XmppConnectionService extends Service {
iq.query("jabber:iq:roster").addChild(contact.asElement()); iq.query("jabber:iq:roster").addChild(contact.asElement());
account.getXmppConnection().sendIqPacket(iq, null); account.getXmppConnection().sendIqPacket(iq, null);
contact.resetOption(Contact.Options.DIRTY_PUSH); contact.resetOption(Contact.Options.DIRTY_PUSH);
if (contact.getOption(Contact.Options.ASKING)) {
requestPresenceUpdatesFrom(contact);
}
if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
Log.d("xmppService", "contact had pending subscription");
sendPresenceUpdatesTo(contact);
}
contact.resetOption(Contact.Options.DIRTY_PUSH);
} else { } else {
contact.setOption(Contact.Options.DIRTY_PUSH); contact.setOption(Contact.Options.DIRTY_PUSH);
} }
} }
public void deleteContactOnServer(Contact contact) { public void deleteContactOnServer(Contact contact) {
IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
Element item = iq.query("jabber:iq:roster").addChild("item");
item.setAttribute("jid", contact.getJid());
item.setAttribute("subscription", "remove");
Account account = contact.getAccount(); Account account = contact.getAccount();
account.getXmppConnection().sendIqPacket(iq, null); if (account.getStatus() == Account.STATUS_ONLINE) {
IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
Element item = iq.query("jabber:iq:roster").addChild("item");
item.setAttribute("jid", contact.getJid());
item.setAttribute("subscription", "remove");
account.getXmppConnection().sendIqPacket(iq, null);
contact.resetOption(Contact.Options.DIRTY_DELETE);
} else {
contact.setOption(Contact.Options.DIRTY_DELETE);
}
} }
public void requestPresenceUpdatesFrom(Contact contact) { public void requestPresenceUpdatesFrom(Contact contact) {