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;
}
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) {
Timber.v("MessageProvider/delete: %s", uri);
// Note: can only delete a message
List<String> segments = uri.getPathSegments();
int accountId = Integer.parseInt(segments.get(1));
long folderId = Long.parseLong(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 (myAccount == null) {
Timber.e("Could not find account with id %d", accountId);
}
if (myAccount != null) {
MessageReference messageReference = new MessageReference(myAccount.getUuid(), folderId, msgUid);
MessagingController controller = MessagingController.getInstance(getContext());
controller.deleteMessage(messageReference);
}
// 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 MessageProvider method init.
public static void init() {
Timber.v("Registering content resolver notifier");
final Context context = DI.get(Context.class);
MessagingController messagingController = DI.get(MessagingController.class);
messagingController.addListener(new SimpleMessagingListener() {
@Override
public void folderStatusChanged(Account account, long folderId) {
context.getContentResolver().notifyChange(CONTENT_URI, null);
}
});
}
Aggregations