use of com.fsck.k9.K9 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;
}
use of com.fsck.k9.K9 in project k-9 by k9mail.
the class CoreService method onStartCommand.
@Override
public final int onStartCommand(Intent intent, int flags, int startId) {
/*
* When a process is killed due to low memory, it's later restarted and services that were
* started with START_STICKY are started with the intent being null.
*
* For now we just ignore these restart events. This should be fine because all necessary
* services are started from K9.onCreate() when the Application object is initialized.
*
* See issue 3750
*/
if (intent == null) {
stopSelf(startId);
return START_NOT_STICKY;
}
// Acquire new wake lock
TracingWakeLock wakeLock = acquireWakeLock(this, "CoreService onStart", K9.MAIL_SERVICE_WAKE_LOCK_TIMEOUT);
Timber.i("CoreService: %s.onStart(%s, %d)", className, intent, startId);
// If we were started by BootReceiver, release the wake lock acquired there.
int wakeLockId = intent.getIntExtra(BootReceiver.WAKE_LOCK_ID, -1);
if (wakeLockId != -1) {
BootReceiver.releaseWakeLock(this, wakeLockId);
}
// If we were passed an ID from our own wake lock registry, retrieve that wake lock and
// release it.
int coreWakeLockId = intent.getIntExtra(WAKE_LOCK_ID, -1);
if (coreWakeLockId != -1) {
Timber.d("Got core wake lock id %d", coreWakeLockId);
// Remove wake lock from the registry
TracingWakeLock coreWakeLock = sWakeLocks.remove(coreWakeLockId);
// Release wake lock
if (coreWakeLock != null) {
Timber.d("Found core wake lock with id %d, releasing", coreWakeLockId);
coreWakeLock.release();
}
}
// Run the actual start-code of the service
mImmediateShutdown = true;
int startFlag;
try {
startFlag = startService(intent, startId);
} finally {
try {
// Release the wake lock acquired at the start of this method
wakeLock.release();
} catch (Exception e) {
/* ignore */
}
try {
// this service.
if (mAutoShutdown && mImmediateShutdown && startId != -1) {
stopSelf(startId);
startFlag = START_NOT_STICKY;
}
} catch (Exception e) {
/* ignore */
}
}
return startFlag;
}
use of com.fsck.k9.K9 in project k-9 by k9mail.
the class Account method getStats.
/**
* @return <code>null</code> if not available
* @throws MessagingException
* @see {@link #isAvailable(Context)}
*/
public AccountStats getStats(Context context) throws MessagingException {
if (!isAvailable(context)) {
return null;
}
AccountStats stats = new AccountStats();
ContentResolver cr = context.getContentResolver();
Uri uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + getUuid() + "/stats");
String[] projection = { StatsColumns.UNREAD_COUNT, StatsColumns.FLAGGED_COUNT };
// Create LocalSearch instance to exclude special folders (Trash, Drafts, Spam, Outbox,
// Sent) and limit the search to displayable folders.
LocalSearch search = new LocalSearch();
excludeSpecialFolders(search);
limitToDisplayableFolders(search);
// Use the LocalSearch instance to create a WHERE clause to query the content provider
StringBuilder query = new StringBuilder();
List<String> queryArgs = new ArrayList<>();
ConditionsTreeNode conditions = search.getConditions();
SqlQueryBuilder.buildWhereClause(this, conditions, query, queryArgs);
String selection = query.toString();
String[] selectionArgs = queryArgs.toArray(new String[0]);
Cursor cursor = cr.query(uri, projection, selection, selectionArgs, null);
try {
if (cursor != null && cursor.moveToFirst()) {
stats.unreadMessageCount = cursor.getInt(0);
stats.flaggedMessageCount = cursor.getInt(1);
}
} finally {
Utility.closeQuietly(cursor);
}
LocalStore localStore = getLocalStore();
if (K9.measureAccounts()) {
stats.size = localStore.getSize();
}
return stats;
}
use of com.fsck.k9.K9 in project k-9 by k9mail.
the class K9 method loadPrefs.
/**
* Load preferences into our statics.
*
* If you're adding a preference here, odds are you'll need to add it to
* {@link com.fsck.k9.preferences.GlobalSettings}, too.
*
* @param prefs Preferences to load
*/
public static void loadPrefs(Preferences prefs) {
Storage storage = prefs.getStorage();
setDebug(storage.getBoolean("enableDebugLogging", BuildConfig.DEVELOPER_MODE));
DEBUG_SENSITIVE = storage.getBoolean("enableSensitiveLogging", false);
mAnimations = storage.getBoolean("animations", true);
mGesturesEnabled = storage.getBoolean("gesturesEnabled", false);
mUseVolumeKeysForNavigation = storage.getBoolean("useVolumeKeysForNavigation", false);
mUseVolumeKeysForListNavigation = storage.getBoolean("useVolumeKeysForListNavigation", false);
mStartIntegratedInbox = storage.getBoolean("startIntegratedInbox", false);
mMeasureAccounts = storage.getBoolean("measureAccounts", true);
mCountSearchMessages = storage.getBoolean("countSearchMessages", true);
mHideSpecialAccounts = storage.getBoolean("hideSpecialAccounts", false);
mMessageListSenderAboveSubject = storage.getBoolean("messageListSenderAboveSubject", false);
mMessageListCheckboxes = storage.getBoolean("messageListCheckboxes", false);
mMessageListStars = storage.getBoolean("messageListStars", true);
mMessageListPreviewLines = storage.getInt("messageListPreviewLines", 2);
mAutofitWidth = storage.getBoolean("autofitWidth", true);
mQuietTimeEnabled = storage.getBoolean("quietTimeEnabled", false);
mNotificationDuringQuietTimeEnabled = storage.getBoolean("notificationDuringQuietTimeEnabled", true);
mQuietTimeStarts = storage.getString("quietTimeStarts", "21:00");
mQuietTimeEnds = storage.getString("quietTimeEnds", "7:00");
mShowCorrespondentNames = storage.getBoolean("showCorrespondentNames", true);
mShowContactName = storage.getBoolean("showContactName", false);
sShowContactPicture = storage.getBoolean("showContactPicture", true);
mChangeContactNameColor = storage.getBoolean("changeRegisteredNameColor", false);
mContactNameColor = storage.getInt("registeredNameColor", 0xff00008f);
mMessageViewFixedWidthFont = storage.getBoolean("messageViewFixedWidthFont", false);
mMessageViewReturnToList = storage.getBoolean("messageViewReturnToList", false);
mMessageViewShowNext = storage.getBoolean("messageViewShowNext", false);
mWrapFolderNames = storage.getBoolean("wrapFolderNames", false);
mHideUserAgent = storage.getBoolean("hideUserAgent", false);
mHideTimeZone = storage.getBoolean("hideTimeZone", false);
sOpenPgpProvider = storage.getString("openPgpProvider", NO_OPENPGP_PROVIDER);
sOpenPgpSupportSignOnly = storage.getBoolean("openPgpSupportSignOnly", false);
mConfirmDelete = storage.getBoolean("confirmDelete", false);
mConfirmDiscardMessage = storage.getBoolean("confirmDiscardMessage", true);
mConfirmDeleteStarred = storage.getBoolean("confirmDeleteStarred", false);
mConfirmSpam = storage.getBoolean("confirmSpam", false);
mConfirmDeleteFromNotification = storage.getBoolean("confirmDeleteFromNotification", true);
mConfirmMarkAllRead = storage.getBoolean("confirmMarkAllRead", true);
try {
String value = storage.getString("sortTypeEnum", Account.DEFAULT_SORT_TYPE.name());
mSortType = SortType.valueOf(value);
} catch (Exception e) {
mSortType = Account.DEFAULT_SORT_TYPE;
}
boolean sortAscending = storage.getBoolean("sortAscending", Account.DEFAULT_SORT_ASCENDING);
mSortAscending.put(mSortType, sortAscending);
String notificationHideSubject = storage.getString("notificationHideSubject", null);
if (notificationHideSubject == null) {
// If the "notificationHideSubject" setting couldn't be found, the app was probably
// updated. Look for the old "keyguardPrivacy" setting and map it to the new enum.
sNotificationHideSubject = (storage.getBoolean("keyguardPrivacy", false)) ? NotificationHideSubject.WHEN_LOCKED : NotificationHideSubject.NEVER;
} else {
sNotificationHideSubject = NotificationHideSubject.valueOf(notificationHideSubject);
}
String notificationQuickDelete = storage.getString("notificationQuickDelete", null);
if (notificationQuickDelete != null) {
sNotificationQuickDelete = NotificationQuickDelete.valueOf(notificationQuickDelete);
}
String lockScreenNotificationVisibility = storage.getString("lockScreenNotificationVisibility", null);
if (lockScreenNotificationVisibility != null) {
sLockScreenNotificationVisibility = LockScreenNotificationVisibility.valueOf(lockScreenNotificationVisibility);
}
String splitViewMode = storage.getString("splitViewMode", null);
if (splitViewMode != null) {
sSplitViewMode = SplitViewMode.valueOf(splitViewMode);
}
mAttachmentDefaultPath = storage.getString("attachmentdefaultpath", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString());
sUseBackgroundAsUnreadIndicator = storage.getBoolean("useBackgroundAsUnreadIndicator", true);
sThreadedViewEnabled = storage.getBoolean("threadedView", true);
fontSizes.load(storage);
try {
setBackgroundOps(BACKGROUND_OPS.valueOf(storage.getString("backgroundOperations", BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC.name())));
} catch (Exception e) {
setBackgroundOps(BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC);
}
sColorizeMissingContactPictures = storage.getBoolean("colorizeMissingContactPictures", true);
sMessageViewArchiveActionVisible = storage.getBoolean("messageViewArchiveActionVisible", false);
sMessageViewDeleteActionVisible = storage.getBoolean("messageViewDeleteActionVisible", true);
sMessageViewMoveActionVisible = storage.getBoolean("messageViewMoveActionVisible", false);
sMessageViewCopyActionVisible = storage.getBoolean("messageViewCopyActionVisible", false);
sMessageViewSpamActionVisible = storage.getBoolean("messageViewSpamActionVisible", false);
sPgpInlineDialogCounter = storage.getInt("pgpInlineDialogCounter", 0);
sPgpSignOnlyDialogCounter = storage.getInt("pgpSignOnlyDialogCounter", 0);
int themeValue = storage.getInt("theme", Theme.LIGHT.ordinal());
// necessary.
if (themeValue == Theme.DARK.ordinal() || themeValue == android.R.style.Theme) {
K9.setK9Theme(Theme.DARK);
} else {
K9.setK9Theme(Theme.LIGHT);
}
themeValue = storage.getInt("messageViewTheme", Theme.USE_GLOBAL.ordinal());
K9.setK9MessageViewThemeSetting(Theme.values()[themeValue]);
themeValue = storage.getInt("messageComposeTheme", Theme.USE_GLOBAL.ordinal());
K9.setK9ComposerThemeSetting(Theme.values()[themeValue]);
K9.setUseFixedMessageViewTheme(storage.getBoolean("fixedMessageViewTheme", true));
}
use of com.fsck.k9.K9 in project k-9 by k9mail.
the class K9 method onCreate.
@Override
public void onCreate() {
if (K9.DEVELOPER_MODE) {
StrictMode.enableDefaults();
}
PRNGFixes.apply();
super.onCreate();
app = this;
Globals.setContext(this);
K9MailLib.setDebugStatus(new K9MailLib.DebugStatus() {
@Override
public boolean enabled() {
return DEBUG;
}
@Override
public boolean debugSensitive() {
return DEBUG_SENSITIVE;
}
});
checkCachedDatabaseVersion();
Preferences prefs = Preferences.getPreferences(this);
loadPrefs(prefs);
/*
* We have to give MimeMessage a temp directory because File.createTempFile(String, String)
* doesn't work in Android and MimeMessage does not have access to a Context.
*/
BinaryTempFileBody.setTempDirectory(getCacheDir());
LocalKeyStore.setKeyStoreLocation(getDir("KeyStore", MODE_PRIVATE).toString());
/*
* Enable background sync of messages
*/
setServicesEnabled(this);
registerReceivers();
MessagingController.getInstance(this).addListener(new SimpleMessagingListener() {
private void broadcastIntent(String action, Account account, String folder, Message message) {
Uri uri = Uri.parse("email://messages/" + account.getAccountNumber() + "/" + Uri.encode(folder) + "/" + Uri.encode(message.getUid()));
Intent intent = new Intent(action, uri);
intent.putExtra(K9.Intents.EmailReceived.EXTRA_ACCOUNT, account.getDescription());
intent.putExtra(K9.Intents.EmailReceived.EXTRA_FOLDER, folder);
intent.putExtra(K9.Intents.EmailReceived.EXTRA_SENT_DATE, message.getSentDate());
intent.putExtra(K9.Intents.EmailReceived.EXTRA_FROM, Address.toString(message.getFrom()));
intent.putExtra(K9.Intents.EmailReceived.EXTRA_TO, Address.toString(message.getRecipients(Message.RecipientType.TO)));
intent.putExtra(K9.Intents.EmailReceived.EXTRA_CC, Address.toString(message.getRecipients(Message.RecipientType.CC)));
intent.putExtra(K9.Intents.EmailReceived.EXTRA_BCC, Address.toString(message.getRecipients(Message.RecipientType.BCC)));
intent.putExtra(K9.Intents.EmailReceived.EXTRA_SUBJECT, message.getSubject());
intent.putExtra(K9.Intents.EmailReceived.EXTRA_FROM_SELF, account.isAnIdentity(message.getFrom()));
K9.this.sendBroadcast(intent);
Timber.d("Broadcasted: action=%s account=%s folder=%s message uid=%s", action, account.getDescription(), folder, message.getUid());
}
private void updateUnreadWidget() {
try {
UnreadWidgetProvider.updateUnreadCount(K9.this);
} catch (Exception e) {
Timber.e(e, "Error while updating unread widget(s)");
}
}
private void updateMailListWidget() {
try {
MessageListWidgetProvider.triggerMessageListWidgetUpdate(K9.this);
} catch (RuntimeException e) {
if (BuildConfig.DEBUG) {
throw e;
} else {
Timber.e(e, "Error while updating message list widget");
}
}
}
@Override
public void synchronizeMailboxRemovedMessage(Account account, String folder, Message message) {
broadcastIntent(K9.Intents.EmailReceived.ACTION_EMAIL_DELETED, account, folder, message);
updateUnreadWidget();
updateMailListWidget();
}
@Override
public void messageDeleted(Account account, String folder, Message message) {
broadcastIntent(K9.Intents.EmailReceived.ACTION_EMAIL_DELETED, account, folder, message);
updateUnreadWidget();
updateMailListWidget();
}
@Override
public void synchronizeMailboxNewMessage(Account account, String folder, Message message) {
broadcastIntent(K9.Intents.EmailReceived.ACTION_EMAIL_RECEIVED, account, folder, message);
updateUnreadWidget();
updateMailListWidget();
}
@Override
public void folderStatusChanged(Account account, String folderName, int unreadMessageCount) {
updateUnreadWidget();
updateMailListWidget();
// let observers know a change occurred
Intent intent = new Intent(K9.Intents.EmailReceived.ACTION_REFRESH_OBSERVER, null);
intent.putExtra(K9.Intents.EmailReceived.EXTRA_ACCOUNT, account.getDescription());
intent.putExtra(K9.Intents.EmailReceived.EXTRA_FOLDER, folderName);
K9.this.sendBroadcast(intent);
}
});
notifyObservers();
}
Aggregations