Search in sources :

Example 1 with BackupState

use of com.zegoggles.smssync.service.state.BackupState 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 2 with BackupState

use of com.zegoggles.smssync.service.state.BackupState in project sms-backup-plus by jberkel.

the class BackupTaskTest method shouldBackupMultipleTypes.

@Test
public void shouldBackupMultipleTypes() throws Exception {
    mockFetch(SMS, 1);
    mockFetch(MMS, 2);
    when(store.getFolder(notNull(DataType.class), same(dataTypePreferences))).thenReturn(folder);
    when(converter.convertMessages(any(Cursor.class), any(DataType.class))).thenReturn(result(SMS, 1));
    BackupState finalState = task.doInBackground(getBackupConfig(EnumSet.of(SMS, MMS)));
    assertThat(finalState.currentSyncedItems).isEqualTo(3);
    verify(folder, times(3)).appendMessages(anyListOf(Message.class));
}
Also used : BackupState(com.zegoggles.smssync.service.state.BackupState) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) DataType(com.zegoggles.smssync.mail.DataType) BackupItemsFetcher.emptyCursor(com.zegoggles.smssync.service.BackupItemsFetcher.emptyCursor) Cursor(android.database.Cursor) MatrixCursor(android.database.MatrixCursor) Test(org.junit.Test)

Example 3 with BackupState

use of com.zegoggles.smssync.service.state.BackupState in project sms-backup-plus by jberkel.

the class BackupTaskTest method shouldSkipItems.

@Test
public void shouldSkipItems() throws Exception {
    when(fetcher.getMostRecentTimestamp(any(DataType.class))).thenReturn(-23L);
    BackupState finalState = task.doInBackground(new BackupConfig(store, 0, 100, new ContactGroup(-1), BackupType.SKIP, EnumSet.of(SMS), false));
    verify(dataTypePreferences).setMaxSyncedDate(DataType.SMS, -23);
    verifyZeroInteractions(dataTypePreferences);
    assertThat(finalState).isNotNull();
    assertThat(finalState.isFinished()).isTrue();
}
Also used : BackupState(com.zegoggles.smssync.service.state.BackupState) DataType(com.zegoggles.smssync.mail.DataType) ContactGroup(com.zegoggles.smssync.contacts.ContactGroup) Test(org.junit.Test)

Example 4 with BackupState

use of com.zegoggles.smssync.service.state.BackupState 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)

Example 5 with BackupState

use of com.zegoggles.smssync.service.state.BackupState in project sms-backup-plus by jberkel.

the class BackupTask method backupCursors.

private BackupState backupCursors(BackupCursors cursors, BackupImapStore store, BackupType backupType, int itemsToSync) throws MessagingException {
    Log.i(TAG, String.format(Locale.ENGLISH, "Starting backup (%d messages)", itemsToSync));
    publish(LOGIN);
    store.checkSettings();
    try {
        publish(CALC);
        int backedUpItems = 0;
        while (!isCancelled() && cursors.hasNext()) {
            BackupCursors.CursorAndType cursor = cursors.next();
            if (LOCAL_LOGV)
                Log.v(TAG, "backing up: " + cursor);
            ConversionResult result = converter.convertMessages(cursor.cursor, cursor.type);
            if (!result.isEmpty()) {
                List<Message> messages = result.getMessages();
                if (LOCAL_LOGV) {
                    Log.v(TAG, String.format(Locale.ENGLISH, "sending %d %s message(s) to server.", messages.size(), cursor.type));
                }
                store.getFolder(cursor.type, preferences.getDataTypePreferences()).appendMessages(messages);
                if (cursor.type == CALLLOG && calendarSyncer != null) {
                    calendarSyncer.syncCalendar(result);
                }
                preferences.getDataTypePreferences().setMaxSyncedDate(cursor.type, result.getMaxDate());
                backedUpItems += messages.size();
            } else {
                Log.w(TAG, "no messages converted");
                itemsToSync -= 1;
            }
            publishProgress(new BackupState(BACKUP, backedUpItems, itemsToSync, backupType, cursor.type, null));
        }
        return new BackupState(FINISHED_BACKUP, backedUpItems, itemsToSync, backupType, null, null);
    } finally {
        store.closeFolders();
    }
}
Also used : BackupState(com.zegoggles.smssync.service.state.BackupState) ConversionResult(com.zegoggles.smssync.mail.ConversionResult) Message(com.fsck.k9.mail.Message)

Aggregations

BackupState (com.zegoggles.smssync.service.state.BackupState)6 DataType (com.zegoggles.smssync.mail.DataType)5 Message (com.fsck.k9.mail.Message)3 Test (org.junit.Test)3 Cursor (android.database.Cursor)2 MatrixCursor (android.database.MatrixCursor)2 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)2 BackupItemsFetcher.emptyCursor (com.zegoggles.smssync.service.BackupItemsFetcher.emptyCursor)2 MessagingException (com.fsck.k9.mail.MessagingException)1 ContactGroup (com.zegoggles.smssync.contacts.ContactGroup)1 ConversionResult (com.zegoggles.smssync.mail.ConversionResult)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