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);
}
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;
}
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;
}
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;
}
Aggregations