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

View file

@ -100,9 +100,8 @@ import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
public class XmppConnectionService extends Service implements OnPhoneContactsLoadedListener {
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";
private static final String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts";
private ContentObserver contactObserver = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
@ -114,6 +113,56 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
};
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 OnContactStatusChanged onContactStatusChanged = new OnContactStatusChanged() {
@ -142,7 +191,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
private MessageGenerator mMessageGenerator = new MessageGenerator(this);
private PresenceGenerator mPresenceGenerator = new PresenceGenerator(this);
private List<Account> accounts;
private final List<Conversation> conversations = new CopyOnWriteArrayList<>();
private JingleConnectionManager mJingleConnectionManager = new JingleConnectionManager(
this);
private HttpConnectionManager mHttpConnectionManager = new HttpConnectionManager(
@ -212,7 +260,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
getNotificationService().updateErrorNotification();
}
};
private int accountChangedListenerCount = 0;
private OnRosterUpdate mOnRosterUpdate = null;
private OnUpdateBlocklist mOnUpdateBlocklist = null;
@ -221,62 +268,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
private OnMucRosterUpdate mOnMucRosterUpdate = null;
private int mucRosterChangedListenerCount = 0;
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 PgpEngine mPgpEngine = null;
private WakeLock wakeLock;
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 final IqGenerator mIqGenerator = new IqGenerator(this);
private Thread mPhoneContactMergerThread;
public PgpEngine getPgpEngine() {
@ -548,7 +544,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
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();
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
@ -958,11 +954,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}).start();
}
public interface OnMoreMessagesLoaded {
public void onMoreMessagesLoaded(int count,Conversation conversation);
public void informUser(int r);
}
public List<Account> getAccounts() {
return this.accounts;
}
@ -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) {
synchronized (this.conversations) {
for (final Conversation conversation : conversations) {
@ -1582,11 +1568,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
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) {
IqPacket request = this.mIqGenerator.changeRole(conference, nick, role.toString());
Log.d(Config.LOGTAG, request.toString());
@ -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) {
if ((account.getStatus() == Account.State.ONLINE)
|| (account.getStatus() == Account.State.DISABLED)) {
@ -2176,7 +2152,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
return this.mIqGenerator;
}
public IqParser getIqParser() { return this.mIqParser; }
public IqParser getIqParser() {
return this.mIqParser;
}
public JingleConnectionManager getJingleConnectionManager() {
return this.mJingleConnectionManager;
@ -2235,33 +2213,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}).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) {
if (blockable != null && blockable.getBlockedJid() != null) {
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;
}
}
}