@Override public BackupState transition(SmsSyncState newState, Exception exception) { return new BackupState(newState, currentSyncedItems, itemsToSync, backupType, dataType, exception); }
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); }
@Test public void shouldCheckError() throws Exception { assertThat(new BackupState(SmsSyncState.ERROR, 0, 0, BackupType.REGULAR, DataType.SMS, new IOException("foo") ).isError()).isTrue(); assertThat(new BackupState(SmsSyncState.FINISHED_BACKUP, 0, 0, BackupType.REGULAR, DataType.SMS, null ).isError()).isFalse(); }
@Test public void shouldGetNotificationLabelError() throws Exception { assertThat(new BackupState(SmsSyncState.ERROR, 0, 0, BackupType.REGULAR, DataType.SMS, new IOException("foo")).getNotificationLabel(resources)) .isEqualTo("foo"); } }
@Test public void shouldGetNotificationLabelCalculating() throws Exception { assertThat(new BackupState(SmsSyncState.CALC, 0, 0, BackupType.REGULAR, DataType.SMS, null).getNotificationLabel(resources)).isEqualTo( resources.getString(R.string.status_calc_details) ); }
@Test public void shouldGetNotificationLabelLogin() throws Exception { assertThat(new BackupState(SmsSyncState.LOGIN, 0, 0, BackupType.REGULAR, DataType.SMS, null).getNotificationLabel(resources)).isEqualTo( resources.getString(R.string.status_login_details) ); }
@Test public void shouldGetErrorMessageRootCause() throws Exception { RuntimeException exception = new RuntimeException("foo", new IOException("bar")); BackupState state = new BackupState(SmsSyncState.ERROR, 0, 0, BackupType.REGULAR, DataType.SMS, exception); assertThat(state.getErrorMessage(resources)).isEqualTo("foo"); assertThat(state.getDetailedErrorMessage(resources)).isEqualTo("foo (exception: java.lang.RuntimeException: foo, underlying=java.io.IOException: bar)"); }
@Test public void shouldGetErrorMessage() throws Exception { BackupState state = new BackupState(SmsSyncState.ERROR, 0, 0, BackupType.REGULAR, DataType.SMS, new IOException("foo")); assertThat(state.getErrorMessage(resources)).isEqualTo("foo"); assertThat(state.getDetailedErrorMessage(resources)).isEqualTo("foo (exception: java.io.IOException: foo)"); }
publishProgress(new BackupState(BACKUP, backedUpItems, itemsToSync, backupType, cursor.type, null)); return new BackupState(FINISHED_BACKUP, backedUpItems, itemsToSync,
@Test public void shouldGetErrorMessagePrefix() throws Exception { BackupState state = new BackupState(SmsSyncState.ERROR, 0, 0, BackupType.REGULAR, DataType.SMS, new MessagingException("Unable to get IMAP prefix")); assertThat(state.getErrorMessage(resources)).isEqualTo("Temporary Gmail IMAP error, try again later."); }
@Test public void shouldGetErrorMessageRequiresWifi() throws Exception { BackupState state = new BackupState(SmsSyncState.ERROR, 0, 0, BackupType.REGULAR, DataType.SMS, new RequiresWifiException()); assertThat(state.getErrorMessage(resources)).isEqualTo("No Wifi connection"); }
private void backup(BackupType backupType) { getNotifier().cancel(NOTIFICATION_ID_WARNING); try { // set initial state state = 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(state.transition(ERROR, e)); } catch (ConnectivityException e) { moveToState(state.transition(ERROR, e)); } catch (RequiresLoginException e) { appLog(R.string.app_log_missing_credentials); moveToState(state.transition(ERROR, e)); } catch (BackupDisabledException e) { moveToState(state.transition(FINISHED_BACKUP, e)); } catch (MissingPermissionException e) { moveToState(state.transition(ERROR, e)); } }