private void prepareForIdle() { pushReceiver.setPushActive(getServerId(), true); idling = true; }
@Override public void refresh() { synchronized (folderPushers) { for (ImapFolderPusher folderPusher : folderPushers) { try { folderPusher.refresh(); } catch (Exception e) { Timber.e(e, "Got exception while refreshing for %s", folderPusher.getServerId()); } } } }
public ImapFolderPusher(ImapStore store, String serverId, PushReceiver pushReceiver, PowerManager powerManager) { super(store, serverId); this.pushReceiver = pushReceiver; String tag = "ImapFolderPusher " + store.getStoreConfig().toString() + ":" + getServerId(); wakeLock = powerManager.newWakeLock(tag); wakeLock.setReferenceCounted(false); }
@Override public void stop() { if (K9MailLib.isDebug()) { Timber.i("Requested stop of IMAP pusher"); } synchronized (folderPushers) { for (ImapFolderPusher folderPusher : folderPushers) { try { if (K9MailLib.isDebug()) { Timber.i("Requesting stop of IMAP folderPusher %s", folderPusher.getServerId()); } folderPusher.stop(); } catch (Exception e) { Timber.e(e, "Got exception while stopping %s", folderPusher.getServerId()); } } folderPushers.clear(); } }
private void reacquireWakeLockAndCleanUp() { wakeLock.acquire(PUSH_WAKE_LOCK_TIMEOUT); clearStoredUntaggedResponses(); idling = false; pushReceiver.setPushActive(getServerId(), false); try { connection.close(); } catch (Exception me) { Timber.e(me, "Got exception while closing for exception for %s", getLogId()); } connection = null; }
private long getOldUidNext() { long oldUidNext = -1L; try { String serializedPushState = pushReceiver.getPushState(getServerId()); ImapPushState pushState = ImapPushState.parse(serializedPushState); oldUidNext = pushState.uidNext; if (K9MailLib.isDebug()) { Timber.i("Got oldUidNext %d for %s", oldUidNext, getLogId()); } } catch (Exception e) { Timber.e(e, "Unable to get oldUidNext for %s", getLogId()); } return oldUidNext; } }
pushReceiver.pushError("Push error for " + getServerId(), e); } catch (Exception e) { reacquireWakeLockAndCleanUp(); Timber.i("Got exception while idling, but stop is set for %s", getLogId()); } else { pushReceiver.pushError("Push error for " + getServerId(), e); Timber.e("Got exception while idling for %s", getLogId()); if (idleFailureCount > IDLE_FAILURE_COUNT_LIMIT) { Timber.e("Disabling pusher for %s after %d consecutive errors", getLogId(), idleFailureCount); pushReceiver.pushError("Push disabled for " + getServerId() + " after " + idleFailureCount + " consecutive errors", e); stop = true; pushReceiver.setPushActive(getServerId(), false);