Search in sources :

Example 1 with TracingPowerManager

use of com.fsck.k9.mail.power.TracingPowerManager in project k-9 by k9mail.

the class MessagingController method checkMail.

/**
     * Checks mail for one or multiple accounts. If account is null all accounts
     * are checked.
     */
public void checkMail(final Context context, final Account account, final boolean ignoreLastCheckedTime, final boolean useManualWakeLock, final MessagingListener listener) {
    TracingWakeLock twakeLock = null;
    if (useManualWakeLock) {
        TracingPowerManager pm = TracingPowerManager.getPowerManager(context);
        twakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "K9 MessagingController.checkMail");
        twakeLock.setReferenceCounted(false);
        twakeLock.acquire(K9.MANUAL_WAKE_LOCK_TIMEOUT);
    }
    final TracingWakeLock wakeLock = twakeLock;
    for (MessagingListener l : getListeners()) {
        l.checkMailStarted(context, account);
    }
    putBackground("checkMail", listener, new Runnable() {

        @Override
        public void run() {
            try {
                Timber.i("Starting mail check");
                Preferences prefs = Preferences.getPreferences(context);
                Collection<Account> accounts;
                if (account != null) {
                    accounts = new ArrayList<>(1);
                    accounts.add(account);
                } else {
                    accounts = prefs.getAvailableAccounts();
                }
                for (final Account account : accounts) {
                    checkMailForAccount(context, account, ignoreLastCheckedTime, listener);
                }
            } catch (Exception e) {
                Timber.e(e, "Unable to synchronize mail");
                addErrorMessage(account, null, e);
            }
            putBackground("finalize sync", null, new Runnable() {

                @Override
                public void run() {
                    Timber.i("Finished mail sync");
                    if (wakeLock != null) {
                        wakeLock.release();
                    }
                    for (MessagingListener l : getListeners()) {
                        l.checkMailFinished(context, account);
                    }
                }
            });
        }
    });
}
Also used : SearchAccount(com.fsck.k9.search.SearchAccount) Account(com.fsck.k9.Account) TracingPowerManager(com.fsck.k9.mail.power.TracingPowerManager) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Preferences(com.fsck.k9.Preferences) TracingWakeLock(com.fsck.k9.mail.power.TracingPowerManager.TracingWakeLock) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) UnavailableStorageException(com.fsck.k9.mailstore.UnavailableStorageException) IOException(java.io.IOException) MessagingException(com.fsck.k9.mail.MessagingException) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException)

Example 2 with TracingPowerManager

use of com.fsck.k9.mail.power.TracingPowerManager in project k-9 by k9mail.

the class CoreReceiver method getWakeLock.

private static Integer getWakeLock(Context context) {
    TracingPowerManager pm = TracingPowerManager.getPowerManager(context);
    TracingWakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "CoreReceiver getWakeLock");
    wakeLock.setReferenceCounted(false);
    wakeLock.acquire(K9.BOOT_RECEIVER_WAKE_LOCK_TIMEOUT);
    Integer tmpWakeLockId = wakeLockSeq.getAndIncrement();
    wakeLocks.put(tmpWakeLockId, wakeLock);
    Timber.v("CoreReceiver Created wakeLock %d", tmpWakeLockId);
    return tmpWakeLockId;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TracingPowerManager(com.fsck.k9.mail.power.TracingPowerManager) TracingWakeLock(com.fsck.k9.mail.power.TracingPowerManager.TracingWakeLock)

Example 3 with TracingPowerManager

use of com.fsck.k9.mail.power.TracingPowerManager in project k-9 by k9mail.

the class FolderList method checkMail.

/**
    * This class is responsible for reloading the list of local messages for a
    * given folder, notifying the adapter that the message have been loaded and
    * queueing up a remote update of the folder.
     */
private void checkMail(FolderInfoHolder folder) {
    TracingPowerManager pm = TracingPowerManager.getPowerManager(this);
    final TracingWakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "FolderList checkMail");
    wakeLock.setReferenceCounted(false);
    wakeLock.acquire(K9.WAKE_LOCK_TIMEOUT);
    MessagingListener listener = new SimpleMessagingListener() {

        @Override
        public void synchronizeMailboxFinished(Account account, String folder, int totalMessagesInMailbox, int numNewMessages) {
            if (!account.equals(mAccount)) {
                return;
            }
            wakeLock.release();
        }

        @Override
        public void synchronizeMailboxFailed(Account account, String folder, String message) {
            if (!account.equals(mAccount)) {
                return;
            }
            wakeLock.release();
        }
    };
    MessagingController.getInstance(getApplication()).synchronizeMailbox(mAccount, folder.name, listener, null);
    sendMail(mAccount);
}
Also used : Account(com.fsck.k9.Account) BaseAccount(com.fsck.k9.BaseAccount) TracingPowerManager(com.fsck.k9.mail.power.TracingPowerManager) MessagingListener(com.fsck.k9.controller.MessagingListener) SimpleMessagingListener(com.fsck.k9.controller.SimpleMessagingListener) SimpleMessagingListener(com.fsck.k9.controller.SimpleMessagingListener) TracingWakeLock(com.fsck.k9.mail.power.TracingPowerManager.TracingWakeLock)

Example 4 with TracingPowerManager

use of com.fsck.k9.mail.power.TracingPowerManager in project k-9 by k9mail.

the class CoreService method acquireWakeLock.

/**
     * Acquires a wake lock.
     *
     * @param context
     *         A {@link Context} instance. Never {@code null}.
     * @param tag
     *         The tag to supply to {@link TracingPowerManager}.
     * @param timeout
     *         The wake lock timeout.
     *
     * @return A new {@link TracingWakeLock} instance.
     */
protected static TracingWakeLock acquireWakeLock(Context context, String tag, long timeout) {
    TracingPowerManager pm = TracingPowerManager.getPowerManager(context);
    TracingWakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, tag);
    wakeLock.setReferenceCounted(false);
    wakeLock.acquire(timeout);
    return wakeLock;
}
Also used : TracingPowerManager(com.fsck.k9.mail.power.TracingPowerManager) TracingWakeLock(com.fsck.k9.mail.power.TracingPowerManager.TracingWakeLock)

Example 5 with TracingPowerManager

use of com.fsck.k9.mail.power.TracingPowerManager in project k-9 by k9mail.

the class DatabaseUpgradeService method acquireWakelock.

/**
     * Acquire a partial wake lock so the CPU won't go to sleep when the screen is turned off.
     */
private void acquireWakelock() {
    TracingPowerManager pm = TracingPowerManager.getPowerManager(this);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_TAG);
    mWakeLock.setReferenceCounted(false);
    mWakeLock.acquire(WAKELOCK_TIMEOUT);
}
Also used : TracingPowerManager(com.fsck.k9.mail.power.TracingPowerManager)

Aggregations

TracingPowerManager (com.fsck.k9.mail.power.TracingPowerManager)5 TracingWakeLock (com.fsck.k9.mail.power.TracingPowerManager.TracingWakeLock)4 Account (com.fsck.k9.Account)2 BaseAccount (com.fsck.k9.BaseAccount)1 Preferences (com.fsck.k9.Preferences)1 MessagingListener (com.fsck.k9.controller.MessagingListener)1 SimpleMessagingListener (com.fsck.k9.controller.SimpleMessagingListener)1 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)1 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)1 MessagingException (com.fsck.k9.mail.MessagingException)1 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)1 SearchAccount (com.fsck.k9.search.SearchAccount)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1