account for rounding errors when rescheduling wake up

This commit is contained in:
iNPUTmice 2015-01-19 11:17:27 +01:00
parent fc2e458053
commit 7af588c8b3
1 changed files with 153 additions and 150 deletions

View File

@ -100,9 +100,8 @@ import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
public class XmppConnectionService extends Service implements OnPhoneContactsLoadedListener { public class XmppConnectionService extends Service implements OnPhoneContactsLoadedListener {
public static final String ACTION_CLEAR_NOTIFICATION = "clear_notification"; public static final String ACTION_CLEAR_NOTIFICATION = "clear_notification";
private static final String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts";
public static final String ACTION_DISABLE_FOREGROUND = "disable_foreground"; public static final String ACTION_DISABLE_FOREGROUND = "disable_foreground";
private static final String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts";
private ContentObserver contactObserver = new ContentObserver(null) { private ContentObserver contactObserver = new ContentObserver(null) {
@Override @Override
public void onChange(boolean selfChange) { public void onChange(boolean selfChange) {
@ -114,6 +113,56 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
}; };
private final IBinder mBinder = new XmppConnectionBinder(); private final IBinder mBinder = new XmppConnectionBinder();
private final List<Conversation> conversations = new CopyOnWriteArrayList<>();
private final FileObserver fileObserver = new FileObserver(
FileBackend.getConversationsImageDirectory()) {
@Override
public void onEvent(int event, String path) {
if (event == FileObserver.DELETE) {
markFileDeleted(path.split("\\.")[0]);
}
}
};
private final OnJinglePacketReceived jingleListener = new OnJinglePacketReceived() {
@Override
public void onJinglePacketReceived(Account account, JinglePacket packet) {
mJingleConnectionManager.deliverPacket(account, packet);
}
};
private final OnBindListener mOnBindListener = new OnBindListener() {
@Override
public void onBind(final Account account) {
account.getRoster().clearPresences();
account.pendingConferenceJoins.clear();
account.pendingConferenceLeaves.clear();
fetchRosterFromServer(account);
fetchBookmarks(account);
sendPresencePacket(account, mPresenceGenerator.sendPresence(account));
connectMultiModeConversations(account);
updateConversationUi();
}
};
private final OnMessageAcknowledged mOnMessageAcknowledgedListener = new OnMessageAcknowledged() {
@Override
public void onMessageAcknowledged(Account account, String uuid) {
for (final Conversation conversation : getConversations()) {
if (conversation.getAccount() == account) {
Message message = conversation.findUnsentMessageWithUuid(uuid);
if (message != null) {
markMessage(message, Message.STATUS_SEND);
if (conversation.setLastMessageTransmitted(System.currentTimeMillis())) {
databaseBackend.updateConversation(conversation);
}
}
}
}
}
};
private final IqGenerator mIqGenerator = new IqGenerator(this);
public DatabaseBackend databaseBackend; public DatabaseBackend databaseBackend;
public OnContactStatusChanged onContactStatusChanged = new OnContactStatusChanged() { public OnContactStatusChanged onContactStatusChanged = new OnContactStatusChanged() {
@ -142,7 +191,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
private MessageGenerator mMessageGenerator = new MessageGenerator(this); private MessageGenerator mMessageGenerator = new MessageGenerator(this);
private PresenceGenerator mPresenceGenerator = new PresenceGenerator(this); private PresenceGenerator mPresenceGenerator = new PresenceGenerator(this);
private List<Account> accounts; private List<Account> accounts;
private final List<Conversation> conversations = new CopyOnWriteArrayList<>();
private JingleConnectionManager mJingleConnectionManager = new JingleConnectionManager( private JingleConnectionManager mJingleConnectionManager = new JingleConnectionManager(
this); this);
private HttpConnectionManager mHttpConnectionManager = new HttpConnectionManager( private HttpConnectionManager mHttpConnectionManager = new HttpConnectionManager(
@ -212,7 +260,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
getNotificationService().updateErrorNotification(); getNotificationService().updateErrorNotification();
} }
}; };
private int accountChangedListenerCount = 0; private int accountChangedListenerCount = 0;
private OnRosterUpdate mOnRosterUpdate = null; private OnRosterUpdate mOnRosterUpdate = null;
private OnUpdateBlocklist mOnUpdateBlocklist = null; private OnUpdateBlocklist mOnUpdateBlocklist = null;
@ -221,62 +268,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
private OnMucRosterUpdate mOnMucRosterUpdate = null; private OnMucRosterUpdate mOnMucRosterUpdate = null;
private int mucRosterChangedListenerCount = 0; private int mucRosterChangedListenerCount = 0;
private SecureRandom mRandom; private SecureRandom mRandom;
private final FileObserver fileObserver = new FileObserver(
FileBackend.getConversationsImageDirectory()) {
@Override
public void onEvent(int event, String path) {
if (event == FileObserver.DELETE) {
markFileDeleted(path.split("\\.")[0]);
}
}
};
private final OnJinglePacketReceived jingleListener = new OnJinglePacketReceived() {
@Override
public void onJinglePacketReceived(Account account, JinglePacket packet) {
mJingleConnectionManager.deliverPacket(account, packet);
}
};
private OpenPgpServiceConnection pgpServiceConnection; private OpenPgpServiceConnection pgpServiceConnection;
private PgpEngine mPgpEngine = null; private PgpEngine mPgpEngine = null;
private WakeLock wakeLock; private WakeLock wakeLock;
private PowerManager pm; private PowerManager pm;
private final OnBindListener mOnBindListener = new OnBindListener() {
@Override
public void onBind(final Account account) {
account.getRoster().clearPresences();
account.pendingConferenceJoins.clear();
account.pendingConferenceLeaves.clear();
fetchRosterFromServer(account);
fetchBookmarks(account);
sendPresencePacket(account,mPresenceGenerator.sendPresence(account));
connectMultiModeConversations(account);
updateConversationUi();
}
};
private final OnMessageAcknowledged mOnMessageAcknowledgedListener = new OnMessageAcknowledged() {
@Override
public void onMessageAcknowledged(Account account, String uuid) {
for (final Conversation conversation : getConversations()) {
if (conversation.getAccount() == account) {
Message message = conversation.findUnsentMessageWithUuid(uuid);
if (message != null) {
markMessage(message, Message.STATUS_SEND);
if (conversation.setLastMessageTransmitted(System.currentTimeMillis())) {
databaseBackend.updateConversation(conversation);
}
}
}
}
}
};
private LruCache<String, Bitmap> mBitmapCache; private LruCache<String, Bitmap> mBitmapCache;
private final IqGenerator mIqGenerator = new IqGenerator(this);
private Thread mPhoneContactMergerThread; private Thread mPhoneContactMergerThread;
public PgpEngine getPgpEngine() { public PgpEngine getPgpEngine() {
@ -548,7 +544,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
protected void scheduleWakeUpCall(int seconds, int requestCode) { protected void scheduleWakeUpCall(int seconds, int requestCode) {
final long timeToWake = SystemClock.elapsedRealtime() + seconds * 1000; final long timeToWake = SystemClock.elapsedRealtime() + (seconds + 1) * 1000;
Context context = getApplicationContext(); Context context = getApplicationContext();
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
@ -958,11 +954,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}).start(); }).start();
} }
public interface OnMoreMessagesLoaded {
public void onMoreMessagesLoaded(int count,Conversation conversation);
public void informUser(int r);
}
public List<Account> getAccounts() { public List<Account> getAccounts() {
return this.accounts; return this.accounts;
} }
@ -977,23 +968,23 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
public Conversation find(final Iterable<Conversation> haystack, final Account account, final Jid jid) { public Conversation find(final Iterable<Conversation> haystack, final Account account, final Jid jid) {
if (jid == null ) { if (jid == null) {
return null; return null;
} }
for (final Conversation conversation : haystack) { for (final Conversation conversation : haystack) {
if ((account == null || conversation.getAccount() == account) if ((account == null || conversation.getAccount() == account)
&& (conversation.getJid().toBareJid().equals(jid.toBareJid()))) { && (conversation.getJid().toBareJid().equals(jid.toBareJid()))) {
return conversation; return conversation;
} }
} }
return null; return null;
} }
public Conversation findOrCreateConversation(final Account account, final Jid jid,final boolean muc) { public Conversation findOrCreateConversation(final Account account, final Jid jid, final boolean muc) {
return this.findOrCreateConversation(account,jid,muc,null); return this.findOrCreateConversation(account, jid, muc, null);
} }
public Conversation findOrCreateConversation(final Account account, final Jid jid,final boolean muc, final MessageArchiveService.Query query) { public Conversation findOrCreateConversation(final Account account, final Jid jid, final boolean muc, final MessageArchiveService.Query query) {
synchronized (this.conversations) { synchronized (this.conversations) {
Conversation conversation = find(account, jid); Conversation conversation = find(account, jid);
if (conversation != null) { if (conversation != null) {
@ -1097,11 +1088,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}); });
} }
public interface OnAccountPasswordChanged {
public void onPasswordChangeSucceeded();
public void onPasswordChangeFailed();
}
public void deleteAccount(final Account account) { public void deleteAccount(final Account account) {
synchronized (this.conversations) { synchronized (this.conversations) {
for (final Conversation conversation : conversations) { for (final Conversation conversation : conversations) {
@ -1290,7 +1276,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
&& (conversation.getAccount() == account)) { && (conversation.getAccount() == account)) {
conversation.resetMucOptions(); conversation.resetMucOptions();
joinMuc(conversation); joinMuc(conversation);
} }
} }
} }
@ -1308,11 +1294,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
PresencePacket packet = new PresencePacket(); PresencePacket packet = new PresencePacket();
packet.setFrom(conversation.getAccount().getJid()); packet.setFrom(conversation.getAccount().getJid());
packet.setTo(joinJid); packet.setTo(joinJid);
Element x = packet.addChild("x","http://jabber.org/protocol/muc"); Element x = packet.addChild("x", "http://jabber.org/protocol/muc");
if (conversation.getMucOptions().getPassword() != null) { if (conversation.getMucOptions().getPassword() != null) {
x.addChild("password").setContent(conversation.getMucOptions().getPassword()); x.addChild("password").setContent(conversation.getMucOptions().getPassword());
} }
x.addChild("history").setAttribute("since",PresenceGenerator.getTimestamp(conversation.getLastMessageTransmitted())); x.addChild("history").setAttribute("since", PresenceGenerator.getTimestamp(conversation.getLastMessageTransmitted()));
String sig = account.getPgpSignature(); String sig = account.getPgpSignature();
if (sig != null) { if (sig != null) {
packet.addChild("status").setContent("online"); packet.addChild("status").setContent("online");
@ -1417,7 +1403,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
return server; return server;
} }
} }
for(Account other : getAccounts()) { for (Account other : getAccounts()) {
if (other != account && other.getXmppConnection() != null) { if (other != account && other.getXmppConnection() != null) {
server = other.getXmppConnection().getMucServer(); server = other.getXmppConnection().getMucServer();
if (server != null) { if (server != null) {
@ -1435,12 +1421,12 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
String server = findConferenceServer(account); String server = findConferenceServer(account);
if (server == null) { if (server == null) {
if (callback != null) { if (callback != null) {
callback.error(R.string.no_conference_server_found,null); callback.error(R.string.no_conference_server_found, null);
} }
return; return;
} }
String name = new BigInteger(75,getRNG()).toString(32); String name = new BigInteger(75, getRNG()).toString(32);
Jid jid = Jid.fromParts(name,server,null); Jid jid = Jid.fromParts(name, server, null);
final Conversation conversation = findOrCreateConversation(account, jid, true); final Conversation conversation = findOrCreateConversation(account, jid, true);
joinMuc(conversation); joinMuc(conversation);
Bundle options = new Bundle(); Bundle options = new Bundle();
@ -1451,8 +1437,8 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
pushConferenceConfiguration(conversation, options, new OnConferenceOptionsPushed() { pushConferenceConfiguration(conversation, options, new OnConferenceOptionsPushed() {
@Override @Override
public void onPushSucceeded() { public void onPushSucceeded() {
for(Jid invite : jids) { for (Jid invite : jids) {
invite(conversation,invite); invite(conversation, invite);
} }
if (callback != null) { if (callback != null) {
callback.success(conversation); callback.success(conversation);
@ -1474,7 +1460,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
} else { } else {
if (callback != null) { if (callback != null) {
callback.error(R.string.not_connected_try_again,null); callback.error(R.string.not_connected_try_again, null);
} }
} }
} }
@ -1503,11 +1489,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}); });
} }
public void pushConferenceConfiguration(final Conversation conversation,final Bundle options, final OnConferenceOptionsPushed callback) { public void pushConferenceConfiguration(final Conversation conversation, final Bundle options, final OnConferenceOptionsPushed callback) {
IqPacket request = new IqPacket(IqPacket.TYPE.GET); IqPacket request = new IqPacket(IqPacket.TYPE.GET);
request.setTo(conversation.getJid().toBareJid()); request.setTo(conversation.getJid().toBareJid());
request.query("http://jabber.org/protocol/muc#owner"); request.query("http://jabber.org/protocol/muc#owner");
sendIqPacket(conversation.getAccount(),request,new OnIqPacketReceived() { sendIqPacket(conversation.getAccount(), request, new OnIqPacketReceived() {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() != IqPacket.TYPE.ERROR) { if (packet.getType() != IqPacket.TYPE.ERROR) {
@ -1552,7 +1538,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
if (!mucOptions.persistent() && self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) { if (!mucOptions.persistent() && self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
Bundle options = new Bundle(); Bundle options = new Bundle();
options.putString("muc#roomconfig_persistentroom", "1"); options.putString("muc#roomconfig_persistentroom", "1");
this.pushConferenceConfiguration(conference,options,null); this.pushConferenceConfiguration(conference, options, null);
} }
} }
@ -1573,7 +1559,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void changeAffiliationsInConference(final Conversation conference, MucOptions.Affiliation before, MucOptions.Affiliation after) { public void changeAffiliationsInConference(final Conversation conference, MucOptions.Affiliation before, MucOptions.Affiliation after) {
List<Jid> jids = new ArrayList<>(); List<Jid> jids = new ArrayList<>();
for(MucOptions.User user : conference.getMucOptions().getUsers()) { for (MucOptions.User user : conference.getMucOptions().getUsers()) {
if (user.getAffiliation() == before) { if (user.getAffiliation() == before) {
jids.add(user.getJid()); jids.add(user.getJid());
} }
@ -1582,14 +1568,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
sendIqPacket(conference.getAccount(), request, null); sendIqPacket(conference.getAccount(), request, null);
} }
public interface OnAffiliationChanged {
public void onAffiliationChangedSuccessful(Jid jid);
public void onAffiliationChangeFailed(Jid jid, int resId);
}
public void changeRoleInConference(final Conversation conference, final String nick, MucOptions.Role role, final OnRoleChanged callback) { public void changeRoleInConference(final Conversation conference, final String nick, MucOptions.Role role, final OnRoleChanged callback) {
IqPacket request = this.mIqGenerator.changeRole(conference, nick, role.toString()); IqPacket request = this.mIqGenerator.changeRole(conference, nick, role.toString());
Log.d(Config.LOGTAG,request.toString()); Log.d(Config.LOGTAG, request.toString());
sendIqPacket(conference.getAccount(), request, new OnIqPacketReceived() { sendIqPacket(conference.getAccount(), request, new OnIqPacketReceived() {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(Account account, IqPacket packet) {
@ -1603,11 +1584,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}); });
} }
public interface OnRoleChanged{
public void onRoleChangedSuccessful(String nick);
public void onRoleChangeFailed(String nick, int resid);
}
public void disconnect(Account account, boolean force) { public void disconnect(Account account, boolean force) {
if ((account.getStatus() == Account.State.ONLINE) if ((account.getStatus() == Account.State.ONLINE)
|| (account.getStatus() == Account.State.DISABLED)) { || (account.getStatus() == Account.State.DISABLED)) {
@ -1628,7 +1604,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
} }
account.getXmppConnection().disconnect(force); account.getXmppConnection().disconnect(force);
} }
} }
@Override @Override
@ -1667,8 +1643,8 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
final Session otrSession = conversation.getOtrSession(); final Session otrSession = conversation.getOtrSession();
Log.d(Config.LOGTAG, Log.d(Config.LOGTAG,
account.getJid().toBareJid() + " otr session established with " account.getJid().toBareJid() + " otr session established with "
+ conversation.getJid() + "/" + conversation.getJid() + "/"
+ otrSession.getSessionID().getUserID()); + otrSession.getSessionID().getUserID());
conversation.findUnsentMessagesWithOtrEncryption(new Conversation.OnMessageFound() { conversation.findUnsentMessagesWithOtrEncryption(new Conversation.OnMessageFound() {
@Override @Override
@ -1710,7 +1686,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
try { try {
packet.setBody(otrSession packet.setBody(otrSession
.transformSending(CryptoHelper.FILETRANSFER .transformSending(CryptoHelper.FILETRANSFER
+ CryptoHelper.bytesToHex(symmetricKey))); + CryptoHelper.bytesToHex(symmetricKey)));
sendMessagePacket(account, packet); sendMessagePacket(account, packet);
conversation.setSymmetricKey(symmetricKey); conversation.setSymmetricKey(symmetricKey);
return true; return true;
@ -1728,8 +1704,8 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
if (account.getStatus() == Account.State.ONLINE) { if (account.getStatus() == Account.State.ONLINE) {
final boolean ask = contact.getOption(Contact.Options.ASKING); final boolean ask = contact.getOption(Contact.Options.ASKING);
final boolean sendUpdates = contact final boolean sendUpdates = contact
.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST) .getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)
&& contact.getOption(Contact.Options.PREEMPTIVE_GRANT); && contact.getOption(Contact.Options.PREEMPTIVE_GRANT);
final IqPacket iq = new IqPacket(IqPacket.TYPE.SET); final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
iq.query(Xmlns.ROSTER).addChild(contact.asElement()); iq.query(Xmlns.ROSTER).addChild(contact.asElement());
account.getXmppConnection().sendIqPacket(iq, null); account.getXmppConnection().sendIqPacket(iq, null);
@ -1745,12 +1721,12 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
public void publishAvatar(final Account account, public void publishAvatar(final Account account,
final Uri image, final Uri image,
final UiCallback<Avatar> callback) { final UiCallback<Avatar> callback) {
final Bitmap.CompressFormat format = Config.AVATAR_FORMAT; final Bitmap.CompressFormat format = Config.AVATAR_FORMAT;
final int size = Config.AVATAR_SIZE; final int size = Config.AVATAR_SIZE;
final Avatar avatar = getFileBackend() final Avatar avatar = getFileBackend()
.getPepAvatar(image, size, format); .getPepAvatar(image, size, format);
if (avatar != null) { if (avatar != null) {
avatar.height = size; avatar.height = size;
avatar.width = size; avatar.width = size;
@ -1772,12 +1748,12 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void onIqPacketReceived(Account account, IqPacket result) { public void onIqPacketReceived(Account account, IqPacket result) {
if (result.getType() == IqPacket.TYPE.RESULT) { if (result.getType() == IqPacket.TYPE.RESULT) {
final IqPacket packet = XmppConnectionService.this.mIqGenerator final IqPacket packet = XmppConnectionService.this.mIqGenerator
.publishAvatarMetadata(avatar); .publishAvatarMetadata(avatar);
sendIqPacket(account, packet, new OnIqPacketReceived() { sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override @Override
public void onIqPacketReceived(Account account, public void onIqPacketReceived(Account account,
IqPacket result) { IqPacket result) {
if (result.getType() == IqPacket.TYPE.RESULT) { if (result.getType() == IqPacket.TYPE.RESULT) {
if (account.setAvatar(avatar.getFilename())) { if (account.setAvatar(avatar.getFilename())) {
databaseBackend.updateAccount(account); databaseBackend.updateAccount(account);
@ -1807,14 +1783,14 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
public void fetchAvatar(Account account, final Avatar avatar, public void fetchAvatar(Account account, final Avatar avatar,
final UiCallback<Avatar> callback) { final UiCallback<Avatar> callback) {
IqPacket packet = this.mIqGenerator.retrieveAvatar(avatar); IqPacket packet = this.mIqGenerator.retrieveAvatar(avatar);
sendIqPacket(account, packet, new OnIqPacketReceived() { sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket result) { public void onIqPacketReceived(Account account, IqPacket result) {
final String ERROR = account.getJid().toBareJid() final String ERROR = account.getJid().toBareJid()
+ ": fetching avatar for " + avatar.owner + " failed "; + ": fetching avatar for " + avatar.owner + " failed ";
if (result.getType() == IqPacket.TYPE.RESULT) { if (result.getType() == IqPacket.TYPE.RESULT) {
avatar.image = mIqParser.avatarData(result); avatar.image = mIqParser.avatarData(result);
if (avatar.image != null) { if (avatar.image != null) {
@ -1828,7 +1804,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
updateAccountUi(); updateAccountUi();
} else { } else {
Contact contact = account.getRoster() Contact contact = account.getRoster()
.getContact(avatar.owner); .getContact(avatar.owner);
contact.setAvatar(avatar.getFilename()); contact.setAvatar(avatar.getFilename());
getAvatarService().clear(contact); getAvatarService().clear(contact);
updateConversationUi(); updateConversationUi();
@ -1863,7 +1839,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
public void checkForAvatar(Account account, public void checkForAvatar(Account account,
final UiCallback<Avatar> callback) { final UiCallback<Avatar> callback) {
IqPacket packet = this.mIqGenerator.retrieveAvatarMetaData(null); IqPacket packet = this.mIqGenerator.retrieveAvatarMetaData(null);
this.sendIqPacket(account, packet, new OnIqPacketReceived() { this.sendIqPacket(account, packet, new OnIqPacketReceived() {
@ -1929,7 +1905,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
Thread thread = new Thread(account.getXmppConnection()); Thread thread = new Thread(account.getXmppConnection());
thread.start(); thread.start();
scheduleWakeUpCall(Config.CONNECT_TIMEOUT,account.getUuid().hashCode()); scheduleWakeUpCall(Config.CONNECT_TIMEOUT, account.getUuid().hashCode());
} else { } else {
account.getRoster().clearPresences(); account.getRoster().clearPresences();
account.setXmppConnection(null); account.setXmppConnection(null);
@ -1958,7 +1934,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
public boolean markMessage(final Account account, final Jid recipient, final String uuid, public boolean markMessage(final Account account, final Jid recipient, final String uuid,
final int status) { final int status) {
if (uuid == null) { if (uuid == null) {
return false; return false;
} else { } else {
@ -1966,20 +1942,20 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
if (conversation.getJid().equals(recipient) if (conversation.getJid().equals(recipient)
&& conversation.getAccount().equals(account)) { && conversation.getAccount().equals(account)) {
return markMessage(conversation, uuid, status); return markMessage(conversation, uuid, status);
} }
} }
return false; return false;
} }
} }
public boolean markMessage(Conversation conversation, String uuid, public boolean markMessage(Conversation conversation, String uuid,
int status) { int status) {
if (uuid == null) { if (uuid == null) {
return false; return false;
} else { } else {
Message message = conversation.findSentMessageWithUuid(uuid); Message message = conversation.findSentMessageWithUuid(uuid);
if (message!=null) { if (message != null) {
markMessage(message,status); markMessage(message, status);
return true; return true;
} else { } else {
return false; return false;
@ -1990,9 +1966,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void markMessage(Message message, int status) { public void markMessage(Message message, int status) {
if (status == Message.STATUS_SEND_FAILED if (status == Message.STATUS_SEND_FAILED
&& (message.getStatus() == Message.STATUS_SEND_RECEIVED || message && (message.getStatus() == Message.STATUS_SEND_RECEIVED || message
.getStatus() == Message.STATUS_SEND_DISPLAYED)) { .getStatus() == Message.STATUS_SEND_DISPLAYED)) {
return; return;
} }
message.setStatus(status); message.setStatus(status);
databaseBackend.updateMessage(message); databaseBackend.updateMessage(message);
updateConversationUi(); updateConversationUi();
@ -2000,7 +1976,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public SharedPreferences getPreferences() { public SharedPreferences getPreferences() {
return PreferenceManager return PreferenceManager
.getDefaultSharedPreferences(getApplicationContext()); .getDefaultSharedPreferences(getApplicationContext());
} }
public boolean forceEncryption() { public boolean forceEncryption() {
@ -2076,11 +2052,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
final Message markable = conversation.getLatestMarkableMessage(); final Message markable = conversation.getLatestMarkableMessage();
this.markRead(conversation); this.markRead(conversation);
if (confirmMessages() && markable != null && markable.getRemoteMsgId() != null) { if (confirmMessages() && markable != null && markable.getRemoteMsgId() != null) {
Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid()+ ": sending read marker to " + markable.getCounterpart().toString()); Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": sending read marker to " + markable.getCounterpart().toString());
Account account = conversation.getAccount(); Account account = conversation.getAccount();
final Jid to = markable.getCounterpart(); final Jid to = markable.getCounterpart();
MessagePacket packet = mMessageGenerator.confirm(account, to, markable.getRemoteMsgId()); MessagePacket packet = mMessageGenerator.confirm(account, to, markable.getRemoteMsgId());
this.sendMessagePacket(conversation.getAccount(),packet); this.sendMessagePacket(conversation.getAccount(), packet);
} }
updateConversationUi(); updateConversationUi();
} }
@ -2176,7 +2152,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
return this.mIqGenerator; return this.mIqGenerator;
} }
public IqParser getIqParser() { return this.mIqParser; } public IqParser getIqParser() {
return this.mIqParser;
}
public JingleConnectionManager getJingleConnectionManager() { public JingleConnectionManager getJingleConnectionManager() {
return this.mJingleConnectionManager; return this.mJingleConnectionManager;
@ -2235,33 +2213,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}).start(); }).start();
} }
public interface OnConversationUpdate {
public void onConversationUpdate();
}
public interface OnAccountUpdate {
public void onAccountUpdate();
}
public interface OnRosterUpdate {
public void onRosterUpdate();
}
public interface OnMucRosterUpdate {
public void onMucRosterUpdate();
}
public interface OnConferenceOptionsPushed {
public void onPushSucceeded();
public void onPushFailed();
}
public class XmppConnectionBinder extends Binder {
public XmppConnectionService getService() {
return XmppConnectionService.this;
}
}
public void sendBlockRequest(final Blockable blockable) { public void sendBlockRequest(final Blockable blockable) {
if (blockable != null && blockable.getBlockedJid() != null) { if (blockable != null && blockable.getBlockedJid() != null) {
final Jid jid = blockable.getBlockedJid(); final Jid jid = blockable.getBlockedJid();
@ -2292,4 +2243,56 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}); });
} }
} }
public interface OnMoreMessagesLoaded {
public void onMoreMessagesLoaded(int count, Conversation conversation);
public void informUser(int r);
}
public interface OnAccountPasswordChanged {
public void onPasswordChangeSucceeded();
public void onPasswordChangeFailed();
}
public interface OnAffiliationChanged {
public void onAffiliationChangedSuccessful(Jid jid);
public void onAffiliationChangeFailed(Jid jid, int resId);
}
public interface OnRoleChanged {
public void onRoleChangedSuccessful(String nick);
public void onRoleChangeFailed(String nick, int resid);
}
public interface OnConversationUpdate {
public void onConversationUpdate();
}
public interface OnAccountUpdate {
public void onAccountUpdate();
}
public interface OnRosterUpdate {
public void onRosterUpdate();
}
public interface OnMucRosterUpdate {
public void onMucRosterUpdate();
}
public interface OnConferenceOptionsPushed {
public void onPushSucceeded();
public void onPushFailed();
}
public class XmppConnectionBinder extends Binder {
public XmppConnectionService getService() {
return XmppConnectionService.this;
}
}
} }