Search in sources :

Example 1 with DataType

use of com.zegoggles.smssync.mail.DataType in project sms-backup-plus by jberkel.

the class MainSettings method summarizeAutoBackupSettings.

private String summarizeAutoBackupSettings() {
    final List<String> enabled = new ArrayList<String>();
    for (DataType dataType : preferences.getDataTypePreferences().enabled()) {
        enabled.add(getString(dataType.resId));
    }
    StringBuilder summary = new StringBuilder();
    if (!enabled.isEmpty()) {
        summary.append(getString(R.string.ui_enable_auto_sync_summary, TextUtils.join(", ", enabled)));
        if (App.isInstalledOnSDCard(getContext())) {
            summary.append(' ').append(getString(R.string.sd_card_disclaimer));
        }
    } else {
        summary.append(getString(R.string.ui_enable_auto_sync_no_enabled_summary));
    }
    return summary.toString();
}
Also used : ArrayList(java.util.ArrayList) DataType(com.zegoggles.smssync.mail.DataType)

Example 2 with DataType

use of com.zegoggles.smssync.mail.DataType in project sms-backup-plus by jberkel.

the class BackupTask method skip.

private BackupState skip(Iterable<DataType> types) {
    appLog(R.string.app_log_skip_backup_skip_messages);
    for (DataType type : types) {
        try {
            preferences.getDataTypePreferences().setMaxSyncedDate(type, fetcher.getMostRecentTimestamp(type));
        } catch (SecurityException e) {
            return new BackupState(ERROR, 0, 0, MANUAL, type, e);
        }
    }
    Log.i(TAG, "All messages skipped.");
    return new BackupState(FINISHED_BACKUP, 0, 0, MANUAL, null, null);
}
Also used : BackupState(com.zegoggles.smssync.service.state.BackupState) DataType(com.zegoggles.smssync.mail.DataType)

Example 3 with DataType

use of com.zegoggles.smssync.mail.DataType in project sms-backup-plus by jberkel.

the class DataTypePreferences method clearLastSyncData.

public void clearLastSyncData() {
    SharedPreferences.Editor editor = sharedPreferences.edit();
    for (DataType type : DataType.values()) {
        editor.remove(type.maxSyncedPreference);
    }
    editor.commit();
}
Also used : SharedPreferences(android.content.SharedPreferences) DataType(com.zegoggles.smssync.mail.DataType)

Example 4 with DataType

use of com.zegoggles.smssync.mail.DataType in project sms-backup-plus by jberkel.

the class RestoreTask method restore.

private RestoreState restore(RestoreConfig config) {
    final BackupImapStore imapStore = config.imapStore;
    int currentRestoredItem = config.currentRestoredItem;
    try {
        publishProgress(LOGIN);
        imapStore.checkSettings();
        publishProgress(CALC);
        final List<Message> msgs = new ArrayList<Message>();
        if (config.restoreSms) {
            msgs.addAll(imapStore.getFolder(SMS, preferences.getDataTypePreferences()).getMessages(config.maxRestore, config.restoreOnlyStarred, null));
        }
        if (config.restoreCallLog) {
            msgs.addAll(imapStore.getFolder(CALLLOG, preferences.getDataTypePreferences()).getMessages(config.maxRestore, config.restoreOnlyStarred, null));
        }
        final int itemsToRestoreCount = config.maxRestore <= 0 ? msgs.size() : Math.min(msgs.size(), config.maxRestore);
        if (itemsToRestoreCount > 0) {
            for (; currentRestoredItem < itemsToRestoreCount && !isCancelled(); currentRestoredItem++) {
                DataType dataType = importMessage(msgs.get(currentRestoredItem));
                // help gc
                msgs.set(currentRestoredItem, null);
                publishProgress(new RestoreState(RESTORE, currentRestoredItem, itemsToRestoreCount, 0, 0, dataType, null));
                if (currentRestoredItem % 50 == 0) {
                    // clear cache periodically otherwise SD card fills up
                    service.clearCache();
                }
            }
            updateAllThreadsIfAnySmsRestored();
        } else {
            Log.d(TAG, "nothing to restore");
        }
        final int restoredCount = smsIds.size() + callLogIds.size();
        return new RestoreState(isCancelled() ? CANCELED_RESTORE : FINISHED_RESTORE, currentRestoredItem, itemsToRestoreCount, restoredCount, Math.max(0, uids.size() - restoredCount), null, null);
    } catch (XOAuth2AuthenticationFailedException e) {
        return handleAuthError(config, currentRestoredItem, e);
    } catch (AuthenticationFailedException e) {
        return transition(SmsSyncState.ERROR, e);
    } catch (MessagingException e) {
        Log.e(TAG, ERROR, e);
        updateAllThreadsIfAnySmsRestored();
        return transition(SmsSyncState.ERROR, e);
    } catch (IllegalStateException e) {
        // usually memory problems (Couldn't init cursor window)
        return transition(SmsSyncState.ERROR, e);
    } finally {
        imapStore.closeFolders();
    }
}
Also used : Message(com.fsck.k9.mail.Message) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException) XOAuth2AuthenticationFailedException(com.fsck.k9.mail.store.imap.XOAuth2AuthenticationFailedException) MessagingException(com.fsck.k9.mail.MessagingException) BackupImapStore(com.zegoggles.smssync.mail.BackupImapStore) ArrayList(java.util.ArrayList) RestoreState(com.zegoggles.smssync.service.state.RestoreState) XOAuth2AuthenticationFailedException(com.fsck.k9.mail.store.imap.XOAuth2AuthenticationFailedException) DataType(com.zegoggles.smssync.mail.DataType)

Example 5 with DataType

use of com.zegoggles.smssync.mail.DataType in project sms-backup-plus by jberkel.

the class SmsBackupService method backup.

private void backup(BackupType backupType) {
    getNotifier().cancel(NOTIFICATION_ID_WARNING);
    try {
        // set initial state
        mState = new BackupState(INITIAL, 0, 0, backupType, null, null);
        EnumSet<DataType> enabledTypes = getEnabledBackupTypes();
        checkPermissions(enabledTypes);
        if (backupType != SKIP) {
            checkCredentials();
            if (getPreferences().isUseOldScheduler()) {
                legacyCheckConnectivity();
            }
        }
        appLog(R.string.app_log_start_backup, backupType);
        getBackupTask().execute(getBackupConfig(backupType, enabledTypes, getBackupImapStore()));
    } catch (MessagingException e) {
        Log.w(TAG, e);
        moveToState(mState.transition(ERROR, e));
    } catch (ConnectivityException e) {
        moveToState(mState.transition(ERROR, e));
    } catch (RequiresLoginException e) {
        appLog(R.string.app_log_missing_credentials);
        moveToState(mState.transition(ERROR, e));
    } catch (BackupDisabledException e) {
        moveToState(mState.transition(FINISHED_BACKUP, e));
    } catch (MissingPermissionException e) {
        moveToState(mState.transition(ERROR, e));
    }
}
Also used : BackupState(com.zegoggles.smssync.service.state.BackupState) MissingPermissionException(com.zegoggles.smssync.service.exception.MissingPermissionException) MessagingException(com.fsck.k9.mail.MessagingException) RequiresLoginException(com.zegoggles.smssync.service.exception.RequiresLoginException) BackupDisabledException(com.zegoggles.smssync.service.exception.BackupDisabledException) DataType(com.zegoggles.smssync.mail.DataType) ConnectivityException(com.zegoggles.smssync.service.exception.ConnectivityException)

Aggregations

DataType (com.zegoggles.smssync.mail.DataType)7 MessagingException (com.fsck.k9.mail.MessagingException)3 BackupState (com.zegoggles.smssync.service.state.BackupState)2 ArrayList (java.util.ArrayList)2 SharedPreferences (android.content.SharedPreferences)1 Cursor (android.database.Cursor)1 NonNull (android.support.annotation.NonNull)1 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)1 FetchProfile (com.fsck.k9.mail.FetchProfile)1 Message (com.fsck.k9.mail.Message)1 XOAuth2AuthenticationFailedException (com.fsck.k9.mail.store.imap.XOAuth2AuthenticationFailedException)1 BackupImapStore (com.zegoggles.smssync.mail.BackupImapStore)1 BackupDisabledException (com.zegoggles.smssync.service.exception.BackupDisabledException)1 ConnectivityException (com.zegoggles.smssync.service.exception.ConnectivityException)1 MissingPermissionException (com.zegoggles.smssync.service.exception.MissingPermissionException)1 RequiresLoginException (com.zegoggles.smssync.service.exception.RequiresLoginException)1 RestoreState (com.zegoggles.smssync.service.state.RestoreState)1 IOException (java.io.IOException)1