private void idle() { syncDetailsLabel.setText(getLastSyncText(preferences.getDataTypePreferences().getMostRecentSyncedDate())); statusLabel.setText(R.string.status_idle); statusLabel.setTextColor(idleColor); statusIcon.setImageDrawable(idle); }
private @NonNull List<ObservedUri> observedUris() { List<ObservedUri> observedUris = new ArrayList<ObservedUri>(); observedUris.add(new ObservedUri(SMS_PROVIDER, FLAG_NOTIFY_FOR_DESCENDANTS)); if (preferences.getDataTypePreferences().isBackupEnabled(DataType.CALLLOG) && preferences.isCallLogBackupAfterCallEnabled()) { observedUris.add(new ObservedUri(CALLLOG_PROVIDER, FLAG_NOTIFY_FOR_DESCENDANTS)); } return observedUris; }
@Override public void onStop() { super.onStop(); preferences.getDataTypePreferences().registerDataTypeListener(null); }
private EnumSet<DataType> getEnabledBackupTypes() throws BackupDisabledException { EnumSet<DataType> dataTypes = getPreferences().getDataTypePreferences().enabled(); if (dataTypes.isEmpty()) { throw new BackupDisabledException(); } return dataTypes; }
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(); }
private void importSms(final Message message) throws IOException, MessagingException { if (LOCAL_LOGV) Log.v(TAG, "importSms(" + message + ")"); final ContentValues values = converter.messageToContentValues(message); final Integer type = values.getAsInteger(Telephony.TextBasedSmsColumns.TYPE); // only restore inbox messages and sent messages - otherwise sms might get sent on restore if (type != null && (type == Telephony.TextBasedSmsColumns.MESSAGE_TYPE_INBOX || type == Telephony.TextBasedSmsColumns.MESSAGE_TYPE_SENT) && !smsExists(values)) { final Uri uri = resolver.insert(Consts.SMS_PROVIDER, values); if (uri != null) { smsIds.add(uri.getLastPathSegment()); Long timestamp = values.getAsLong(Telephony.TextBasedSmsColumns.DATE); if (timestamp != null && preferences.getDataTypePreferences().getMaxSyncedDate(SMS) < timestamp) { preferences.getDataTypePreferences().setMaxSyncedDate(SMS, timestamp); } if (LOCAL_LOGV) Log.v(TAG, "inserted " + uri); } } else { if (LOCAL_LOGV) Log.d(TAG, "ignoring sms"); } }
private void updateImapFolderLabelFromPref() { String imapFolder = preferences.getDataTypePreferences().getFolder(SMS); findPreference(SMS.folderPreference).setTitle(imapFolder); }
private void updateImapCallogFolderLabelFromPref() { String imapFolder = preferences.getDataTypePreferences().getFolder(CALLLOG); findPreference(CALLLOG.folderPreference).setTitle(imapFolder); }
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); }
@Subscribe public void onSettingsReset(SettingsResetEvent event) { preferences.getDataTypePreferences().clearLastSyncData(); preferences.reset(); updateConnected(); }
@Test public void shouldCatchNullPointerExceptions() throws Exception { preferences.getDataTypePreferences().setBackupEnabled(true, SMS); when(resolver.query(any(Uri.class), any(String[].class), anyString(), any(String[].class), anyString())) .thenThrow(new NullPointerException()); mockEmptyQuery(); assertThat(fetcher.getItemsForDataType(SMS, null, -1).getCount()).isEqualTo(0); }
@Test public void shouldCatchSQLiteExceptions() throws Exception { preferences.getDataTypePreferences().setBackupEnabled(true, SMS); when(resolver.query(any(Uri.class), any(String[].class), anyString(), any(String[].class), anyString())) .thenThrow(new SQLiteException()); mockEmptyQuery(); assertThat(fetcher.getItemsForDataType(SMS, null, -1).getCount()).isEqualTo(0); }
@Before public void before() { initMocks(this); config = getBackupConfig(EnumSet.of(SMS)); when(service.getApplicationContext()).thenReturn(RuntimeEnvironment.application); when(service.getState()).thenReturn(state); when(preferences.getDataTypePreferences()).thenReturn(dataTypePreferences); task = new BackupTask(service, fetcher, converter, syncer, authPreferences, preferences, accessor, tokenRefresher); context = RuntimeEnvironment.application; }
private void updateLastBackupTimes() { for (DataType type : DataType.values()) { findPreference(type.backupEnabledPreference).setSummary( getLastSyncText(preferences.getDataTypePreferences().getMaxSyncedDate(type)) ); } }
@Test public void shouldGetItemsForDataType() throws Exception { preferences.getDataTypePreferences().setBackupEnabled(true, SMS); assertThat(fetcher.getItemsForDataType(SMS, null, -1).getCount()).isEqualTo(0); verifyZeroInteractions(resolver); }
@Before public void before() { initMocks(this); ShadowPackageManager pm = shadowOf(RuntimeEnvironment.application.getPackageManager()); Intent executeIntent = new Intent("com.firebase.jobdispatcher.ACTION_EXECUTE"); executeIntent.setClassName(RuntimeEnvironment.application, "com.zegoggles.smssync.service.SmsJobService"); ResolveInfo ri = new ResolveInfo(); ServiceInfo si = new ServiceInfo(); si.packageName = "com.zegoggles.smssync.service.SmsJobService"; ri.serviceInfo = si; ri.isDefault = true; pm.addResolveInfoForIntent(executeIntent, ri); subject = new BackupJobs(RuntimeEnvironment.application, preferences); when(preferences.getDataTypePreferences()).thenReturn(dataTypePreferences); }
@Test public void shouldTestForFirstBackupCallLog() throws Exception { preferences.getDataTypePreferences().setMaxSyncedDate(CALLLOG, 1234); assertThat(preferences.isFirstBackup()).isFalse(); } }
@Subscribe public void onAccountRemoved(AccountRemovedEvent event) { authPreferences.clearOauth2Data(); preferences.getDataTypePreferences().clearLastSyncData(); findAutoBackupPreference().setChecked(false); updateConnected(); updateAutoBackupPreferences(); }
@Test public void shouldTestForFirstBackupMMS() throws Exception { preferences.getDataTypePreferences().setMaxSyncedDate(MMS, 1234); assertThat(preferences.isFirstBackup()).isFalse(); }
@Test public void shouldTestForFirstBackupSMS() throws Exception { preferences.getDataTypePreferences().setMaxSyncedDate(SMS, 1234); assertThat(preferences.isFirstBackup()).isFalse(); }