Search in sources :

Example 16 with Storage

use of com.fsck.k9.preferences.Storage in project k-9 by k9mail.

the class MailService method reschedulePoll.

private void reschedulePoll(final boolean hasConnectivity, final boolean doBackground, boolean considerLastCheckEnd) {
    if (!(hasConnectivity && doBackground)) {
        Timber.i("No connectivity, canceling check for %s", getApplication().getPackageName());
        nextCheck = -1;
        cancel();
        return;
    }
    Preferences prefs = Preferences.getPreferences(MailService.this);
    Storage storage = prefs.getStorage();
    int previousInterval = storage.getInt(PREVIOUS_INTERVAL, -1);
    long lastCheckEnd = storage.getLong(LAST_CHECK_END, -1);
    long now = System.currentTimeMillis();
    if (lastCheckEnd > now) {
        Timber.i("The database claims that the last time mail was checked was in the future (%tc). To try to get " + "things back to normal, the last check time has been reset to: %tc", lastCheckEnd, now);
        lastCheckEnd = now;
    }
    int shortestInterval = -1;
    for (Account account : prefs.getAvailableAccounts()) {
        if (account.getAutomaticCheckIntervalMinutes() != -1 && account.getFolderSyncMode() != FolderMode.NONE && (account.getAutomaticCheckIntervalMinutes() < shortestInterval || shortestInterval == -1)) {
            shortestInterval = account.getAutomaticCheckIntervalMinutes();
        }
    }
    StorageEditor editor = storage.edit();
    editor.putInt(PREVIOUS_INTERVAL, shortestInterval);
    editor.commit();
    if (shortestInterval == -1) {
        Timber.i("No next check scheduled for package %s", getApplication().getPackageName());
        nextCheck = -1;
        pollingRequested = false;
        cancel();
    } else {
        long delay = (shortestInterval * (60 * 1000));
        long base = (previousInterval == -1 || lastCheckEnd == -1 || !considerLastCheckEnd ? System.currentTimeMillis() : lastCheckEnd);
        long nextTime = base + delay;
        Timber.i("previousInterval = %d, shortestInterval = %d, lastCheckEnd = %tc, considerLastCheckEnd = %b", previousInterval, shortestInterval, lastCheckEnd, considerLastCheckEnd);
        nextCheck = nextTime;
        pollingRequested = true;
        try {
            Timber.i("Next check for package %s scheduled for %tc", getApplication().getPackageName(), nextTime);
        } catch (Exception e) {
            // I once got a NullPointerException deep in new Date();
            Timber.e(e, "Exception while logging");
        }
        Intent i = new Intent(this, MailService.class);
        i.setAction(ACTION_CHECK_MAIL);
        BootReceiver.scheduleIntent(MailService.this, nextTime, i);
    }
}
Also used : Account(com.fsck.k9.Account) Storage(com.fsck.k9.preferences.Storage) Intent(android.content.Intent) Preferences(com.fsck.k9.Preferences) StorageEditor(com.fsck.k9.preferences.StorageEditor)

Example 17 with Storage

use of com.fsck.k9.preferences.Storage 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));
}
Also used : Storage(com.fsck.k9.preferences.Storage)

Example 18 with Storage

use of com.fsck.k9.preferences.Storage in project k-9 by k9mail.

the class LocalFolder method refresh.

public void refresh(String name, PreferencesHolder prefHolder) {
    String id = getPrefId(name);
    Storage storage = this.localStore.getStorage();
    try {
        prefHolder.displayClass = FolderClass.valueOf(storage.getString(id + ".displayMode", prefHolder.displayClass.name()));
    } catch (Exception e) {
        Timber.e(e, "Unable to load displayMode for %s", getName());
    }
    if (prefHolder.displayClass == FolderClass.NONE) {
        prefHolder.displayClass = FolderClass.NO_CLASS;
    }
    try {
        prefHolder.syncClass = FolderClass.valueOf(storage.getString(id + ".syncMode", prefHolder.syncClass.name()));
    } catch (Exception e) {
        Timber.e(e, "Unable to load syncMode for %s", getName());
    }
    if (prefHolder.syncClass == FolderClass.NONE) {
        prefHolder.syncClass = FolderClass.INHERITED;
    }
    try {
        prefHolder.notifyClass = FolderClass.valueOf(storage.getString(id + ".notifyMode", prefHolder.notifyClass.name()));
    } catch (Exception e) {
        Timber.e(e, "Unable to load notifyMode for %s", getName());
    }
    if (prefHolder.notifyClass == FolderClass.NONE) {
        prefHolder.notifyClass = FolderClass.INHERITED;
    }
    try {
        prefHolder.pushClass = FolderClass.valueOf(storage.getString(id + ".pushMode", prefHolder.pushClass.name()));
    } catch (Exception e) {
        Timber.e(e, "Unable to load pushMode for %s", getName());
    }
    if (prefHolder.pushClass == FolderClass.NONE) {
        prefHolder.pushClass = FolderClass.INHERITED;
    }
    prefHolder.inTopGroup = storage.getBoolean(id + ".inTopGroup", prefHolder.inTopGroup);
    prefHolder.integrate = storage.getBoolean(id + ".integrate", prefHolder.integrate);
}
Also used : Storage(com.fsck.k9.preferences.Storage) WrappedException(com.fsck.k9.mailstore.LockableDatabase.WrappedException) IOException(java.io.IOException) MessagingException(com.fsck.k9.mail.MessagingException)

Example 19 with Storage

use of com.fsck.k9.preferences.Storage in project k-9 by k9mail.

the class LockableDatabase method execute.

/**
     * Execute a DB callback in a shared context (doesn't prevent concurrent
     * shared executions), taking care of locking the DB storage.
     *
     * <p>
     * Can be instructed to start a transaction if none is currently active in
     * the current thread. Callback will participate in any active transaction (no
     * inner transaction created).
     * </p>
     *
     * @param transactional
     *            <code>true</code> the callback must be executed in a
     *            transactional context.
     * @param callback
     *            Never <code>null</code>.
     * @return Whatever {@link DbCallback#doDbWork(SQLiteDatabase)} returns.
     * @throws UnavailableStorageException
     */
public <T> T execute(final boolean transactional, final DbCallback<T> callback) throws MessagingException {
    lockRead();
    final boolean doTransaction = transactional && inTransaction.get() == null;
    try {
        final boolean debug = K9.isDebug();
        if (doTransaction) {
            inTransaction.set(Boolean.TRUE);
            mDb.beginTransaction();
        }
        try {
            final T result = callback.doDbWork(mDb);
            if (doTransaction) {
                mDb.setTransactionSuccessful();
            }
            return result;
        } finally {
            if (doTransaction) {
                final long begin;
                if (debug) {
                    begin = System.currentTimeMillis();
                } else {
                    begin = 0L;
                }
                // not doing endTransaction in the same 'finally' block of unlockRead() because endTransaction() may throw an exception
                mDb.endTransaction();
                if (debug) {
                    Timber.v("LockableDatabase: Transaction ended, took %d ms / %s", currentTimeMillis() - begin, new Exception().getStackTrace()[1]);
                }
            }
        }
    } finally {
        if (doTransaction) {
            inTransaction.set(null);
        }
        unlockRead();
    }
}
Also used : SQLiteException(android.database.sqlite.SQLiteException) MessagingException(com.fsck.k9.mail.MessagingException)

Example 20 with Storage

use of com.fsck.k9.preferences.Storage in project k-9 by k9mail.

the class MigrationTo41 method update41Metadata.

private static void update41Metadata(SQLiteDatabase db, MigrationsHelper migrationsHelper, int id, String name) {
    Storage storage = migrationsHelper.getStorage();
    Account account = migrationsHelper.getAccount();
    String accountUuid = account.getUuid();
    Folder.FolderClass displayClass = Folder.FolderClass.NO_CLASS;
    Folder.FolderClass syncClass = Folder.FolderClass.INHERITED;
    Folder.FolderClass pushClass = Folder.FolderClass.SECOND_CLASS;
    boolean inTopGroup = false;
    boolean integrate = false;
    if (account.getInboxFolderName().equals(name)) {
        displayClass = Folder.FolderClass.FIRST_CLASS;
        syncClass = Folder.FolderClass.FIRST_CLASS;
        pushClass = Folder.FolderClass.FIRST_CLASS;
        inTopGroup = true;
        integrate = true;
    }
    try {
        displayClass = Folder.FolderClass.valueOf(storage.getString(accountUuid + "." + name + ".displayMode", displayClass.name()));
        syncClass = Folder.FolderClass.valueOf(storage.getString(accountUuid + "." + name + ".syncMode", syncClass.name()));
        pushClass = Folder.FolderClass.valueOf(storage.getString(accountUuid + "." + name + ".pushMode", pushClass.name()));
        inTopGroup = storage.getBoolean(accountUuid + "." + name + ".inTopGroup", inTopGroup);
        integrate = storage.getBoolean(accountUuid + "." + name + ".integrate", integrate);
    } catch (Exception e) {
        Timber.e(e, " Throwing away an error while trying to upgrade folder metadata");
    }
    if (displayClass == Folder.FolderClass.NONE) {
        displayClass = Folder.FolderClass.NO_CLASS;
    }
    if (syncClass == Folder.FolderClass.NONE) {
        syncClass = Folder.FolderClass.INHERITED;
    }
    if (pushClass == Folder.FolderClass.NONE) {
        pushClass = Folder.FolderClass.INHERITED;
    }
    db.execSQL("UPDATE folders SET integrate = ?, top_group = ?, poll_class=?, push_class =?, display_class = ? WHERE id = ?", new Object[] { integrate, inTopGroup, syncClass, pushClass, displayClass, id });
}
Also used : Account(com.fsck.k9.Account) Storage(com.fsck.k9.preferences.Storage) Folder(com.fsck.k9.mail.Folder) SQLiteException(android.database.sqlite.SQLiteException)

Aggregations

MessagingException (com.fsck.k9.mail.MessagingException)12 Storage (com.fsck.k9.preferences.Storage)10 Account (com.fsck.k9.Account)9 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)8 InvalidSettingValueException (com.fsck.k9.preferences.Settings.InvalidSettingValueException)7 Preferences (com.fsck.k9.Preferences)6 StorageEditor (com.fsck.k9.preferences.StorageEditor)6 IOException (java.io.IOException)6 LocalFolder (com.fsck.k9.mailstore.LocalFolder)5 WrappedException (com.fsck.k9.mailstore.LockableDatabase.WrappedException)5 Cursor (android.database.Cursor)4 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 EmailProviderCacheCursor (com.fsck.k9.cache.EmailProviderCacheCursor)4 Folder (com.fsck.k9.mail.Folder)4 LocalMessage (com.fsck.k9.mailstore.LocalMessage)4 LocalStore (com.fsck.k9.mailstore.LocalStore)4 LockableDatabase (com.fsck.k9.mailstore.LockableDatabase)4 Map (java.util.Map)4 TreeMap (java.util.TreeMap)4 SuppressLint (android.annotation.SuppressLint)3