Search in sources :

Example 11 with MessagingController

use of com.fsck.k9.controller.MessagingController in project k-9 by k9mail.

the class WearNotificationsTest method setUp.

@Before
public void setUp() throws Exception {
    account = createAccount();
    notification = createNotification();
    builder = createNotificationBuilder(notification);
    actionCreator = createNotificationActionCreator();
    NotificationController controller = createNotificationController(RuntimeEnvironment.application, builder);
    MessagingController messagingController = createMessagingController();
    wearNotifications = new TestWearNotifications(controller, actionCreator, messagingController);
}
Also used : MessagingController(com.fsck.k9.controller.MessagingController) Before(org.junit.Before)

Example 12 with MessagingController

use of com.fsck.k9.controller.MessagingController in project k-9 by k9mail.

the class WearNotificationsTest method createMessagingController.

private MessagingController createMessagingController() {
    MessagingController messagingController = mock(MessagingController.class);
    when(messagingController.isMoveCapable(account)).thenReturn(true);
    return messagingController;
}
Also used : MessagingController(com.fsck.k9.controller.MessagingController)

Example 13 with MessagingController

use of com.fsck.k9.controller.MessagingController in project k-9 by k9mail.

the class MessageProvider method delete.

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    if (K9.app == null) {
        return 0;
    }
    Timber.v("MessageProvider/delete: %s", uri);
    // Note: can only delete a message
    List<String> segments = uri.getPathSegments();
    int accountId = Integer.parseInt(segments.get(1));
    String folderName = segments.get(2);
    String msgUid = segments.get(3);
    // get account
    Account myAccount = null;
    for (Account account : Preferences.getPreferences(getContext()).getAccounts()) {
        if (account.getAccountNumber() == accountId) {
            myAccount = account;
            if (!account.isAvailable(getContext())) {
                Timber.w("not deleting messages because account is unavailable at the moment");
                return 0;
            }
        }
    }
    if (myAccount == null) {
        Timber.e("Could not find account with id %d", accountId);
    }
    if (myAccount != null) {
        MessageReference messageReference = new MessageReference(myAccount.getUuid(), folderName, msgUid, null);
        MessagingController controller = MessagingController.getInstance(getContext());
        controller.deleteMessage(messageReference, null);
    }
    // FIXME return the actual number of deleted messages
    return 0;
}
Also used : SearchAccount(com.fsck.k9.search.SearchAccount) Account(com.fsck.k9.Account) MessagingController(com.fsck.k9.controller.MessagingController) MessageReference(com.fsck.k9.activity.MessageReference)

Example 14 with MessagingController

use of com.fsck.k9.controller.MessagingController in project k-9 by k9mail.

the class CoreService method execute.

/**
     * Execute a task in the background thread.
     *
     * @param context
     *         A {@link Context} instance. Never {@code null}.
     * @param runner
     *         The code to be executed in the background thread.
     * @param wakeLockTime
     *         The timeout for the wake lock that will be acquired by this method.
     * @param startId
     *         The {@code startId} value received in {@link #onStart(Intent, int)} or {@code null}
     *         if you don't want the service to be shut down after {@code runner} has been executed
     *         (e.g. because you need to run another background task).<br>
     *         If this parameter is {@code null} you need to call {@code setAutoShutdown(false)}
     *         otherwise the auto shutdown code will stop the service.
     */
public void execute(Context context, final Runnable runner, int wakeLockTime, final Integer startId) {
    boolean serviceShutdownScheduled = false;
    final boolean autoShutdown = mAutoShutdown;
    // Acquire a new wakelock
    final TracingWakeLock wakeLock = acquireWakeLock(context, "CoreService execute", wakeLockTime);
    // Wrap the supplied runner with code to release the wake lock and stop the service if
    // appropriate.
    Runnable myRunner = new Runnable() {

        public void run() {
            try {
                // Get the sync status
                boolean oldIsSyncDisabled = MailService.isSyncDisabled();
                Timber.d("CoreService (%s) running Runnable %d with startId %d", className, runner.hashCode(), startId);
                // Run the supplied code
                runner.run();
                // MessagingController
                if (MailService.isSyncDisabled() != oldIsSyncDisabled) {
                    MessagingController.getInstance(getApplication()).systemStatusChanged();
                }
            } finally {
                // Making absolutely sure stopSelf() will be called
                try {
                    Timber.d("CoreService (%s) completed Runnable %d with startId %d", className, runner.hashCode(), startId);
                    wakeLock.release();
                } finally {
                    if (autoShutdown && startId != null) {
                        stopSelf(startId);
                    }
                }
            }
        }
    };
    // TODO: remove this. we never set mThreadPool to null
    if (mThreadPool == null) {
        Timber.e("CoreService.execute (%s) called with no thread pool available; " + "running Runnable %d in calling thread", className, runner.hashCode());
        synchronized (this) {
            myRunner.run();
            serviceShutdownScheduled = startId != null;
        }
    } else {
        Timber.d("CoreService (%s) queueing Runnable %d with startId %d", className, runner.hashCode(), startId);
        try {
            mThreadPool.execute(myRunner);
            serviceShutdownScheduled = startId != null;
        } catch (RejectedExecutionException e) {
            // onDestroy(). Still, this should not happen!
            if (!mShutdown) {
                throw e;
            }
            Timber.i("CoreService: %s is shutting down, ignoring rejected execution exception: %s", className, e.getMessage());
        }
    }
    mImmediateShutdown = !serviceShutdownScheduled;
}
Also used : TracingWakeLock(com.fsck.k9.mail.power.TracingPowerManager.TracingWakeLock) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

MessagingController (com.fsck.k9.controller.MessagingController)8 MessageReference (com.fsck.k9.activity.MessageReference)5 Account (com.fsck.k9.Account)4 SearchAccount (com.fsck.k9.search.SearchAccount)3 BaseAccount (com.fsck.k9.BaseAccount)2 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1 Intent (android.content.Intent)1 RemoteViews (android.widget.RemoteViews)1 AccountStats (com.fsck.k9.AccountStats)1 Preferences (com.fsck.k9.Preferences)1 MessageReferenceHelper.toMessageReferenceList (com.fsck.k9.activity.MessageReferenceHelper.toMessageReferenceList)1 MessageReferenceHelper.toMessageReferenceStringList (com.fsck.k9.activity.MessageReferenceHelper.toMessageReferenceStringList)1 UnreadWidgetConfiguration (com.fsck.k9.activity.UnreadWidgetConfiguration)1 SimpleMessagingListener (com.fsck.k9.controller.SimpleMessagingListener)1 Contacts (com.fsck.k9.helper.Contacts)1 Message (com.fsck.k9.mail.Message)1 TransportProvider (com.fsck.k9.mail.TransportProvider)1 TracingWakeLock (com.fsck.k9.mail.power.TracingPowerManager.TracingWakeLock)1 NotificationController (com.fsck.k9.notification.NotificationController)1