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);
}
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));
}
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();
}
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));
}
}
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();
}
}
Aggregations