protected Preferences getPreferences(Context context) { return new Preferences(context); }
public MessageConverter(Context context, Preferences preferences, String userEmail, PersonLookup personLookup, ContactAccessor contactAccessor) { this.context = context; markAsReadType = preferences.getMarkAsReadType(); this.personLookup = personLookup; markAsReadOnRestore = preferences.getMarkAsReadOnRestore(); String referenceUid = preferences.getReferenceUid(); if (referenceUid == null) { referenceUid = generateReferenceValue(); preferences.setReferenceUid(referenceUid); } final ContactGroup backupContactGroup = preferences.getBackupContactGroup(); ContactGroupIds allowedIds = contactAccessor.getGroupContactIds(context.getContentResolver(), backupContactGroup); if (LOCAL_LOGV) Log.v(TAG, "whitelisted ids for backup: " + allowedIds); messageGenerator = new MessageGenerator(context, new Address(userEmail), preferences.getEmailAddressStyle(), new HeaderGenerator(referenceUid, App.getVersionCode(context)), personLookup, preferences.getMailSubjectPrefix(), allowedIds, new MmsSupport(context.getContentResolver(), personLookup), preferences.getCallLogType(), preferences.getDataTypePreferences()); }
private void rescheduleJobs() { backupJobs.cancelAll(); if (preferences.isAutoBackupEnabled()) { backupJobs.scheduleRegular(); if (preferences.getIncomingTimeoutSecs() > 0 && !preferences.isUseOldScheduler()) { backupJobs.scheduleContentTriggerJob(); } } }
private void backupRequested(Context context, Intent intent) { if (new Preferences(context).isAllow3rdPartyIntegration()) { Log.d(TAG, "backup requested via broadcast intent"); new BackupJobs(context).scheduleImmediate(); } else { Log.d(TAG, "backup requested via broadcast intent but ignored"); } } }
public @Nullable Job scheduleBootup() { if (!preferences.isAutoBackupEnabled()) { Log.d(TAG, "auto backup no longer enabled, canceling all jobs"); cancelAll(); return null; } else if (preferences.isUseOldScheduler()) { return schedule(BOOT_BACKUP_DELAY, REGULAR, false); } else { // everything else should be persistent by GCM return null; } }
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { final int themeResId = new Preferences(this).getAppTheme(); setTheme(themeResId); if (VERSION.SDK_INT >= 26) { setNavBarColor(themeResId); } super.onCreate(savedInstanceState); }
private void idle() { syncDetailsLabel.setText(getLastSyncText(preferences.getDataTypePreferences().getMostRecentSyncedDate())); statusLabel.setText(R.string.status_idle); statusLabel.setTextColor(idleColor); statusIcon.setImageDrawable(idle); }
@Test public void shouldTestForFirstBackupCallLog() throws Exception { preferences.getDataTypePreferences().setMaxSyncedDate(CALLLOG, 1234); assertThat(preferences.isFirstBackup()).isFalse(); } }
private void mockScheduled() { when(authPreferences.isLoginInformationSet()).thenReturn(true); when(preferences.isAutoBackupEnabled()).thenReturn(true); when(preferences.isFirstBackup()).thenReturn(false); when(preferences.isUseOldScheduler()).thenReturn(true); } }
private String summarizeBackupScheduleSettings(boolean isEnabled) { if (!isEnabled) { return null; } final StringBuilder summary = new StringBuilder(); final ListPreference regSchedule = (ListPreference) findPreference(REGULAR_TIMEOUT_SECONDS.key); final ListPreference incomingSchedule = (ListPreference) findPreference(INCOMING_TIMEOUT_SECONDS.key); // values are out-of sync regSchedule.setValue(String.valueOf(preferences.getRegularTimeoutSecs())); incomingSchedule.setValue(String.valueOf(preferences.getIncomingTimeoutSecs())); summary.append(regSchedule.getTitle()) .append(": ") .append(regSchedule.getEntry()) .append(", ") .append(incomingSchedule.getTitle()) .append(": ") .append(incomingSchedule.getEntry()); if (preferences.isWifiOnly()) { summary.append(" (") .append(findPreference(WIFI_ONLY.key).getTitle()) .append(")"); } return summary.toString(); }
@Before public void before() { initMocks(this); sentNotifications = new ArrayList<NotificationCompat.Builder>(); service = new SmsBackupService() { @Override public Context getApplicationContext() { return RuntimeEnvironment.application; } @Override public Resources getResources() { return getApplicationContext().getResources(); } @Override protected BackupTask getBackupTask() { return backupTask; } @Override protected BackupJobs getBackupJobs() { return backupJobs; } @Override protected Preferences getPreferences() { return preferences; } @Override public int checkPermission(String permission, int pid, int uid) { return PERMISSION_GRANTED; } @Override protected AuthPreferences getAuthPreferences() { return authPreferences; } @Override protected void notifyUser(int icon, NotificationCompat.Builder builder) { sentNotifications.add(builder); } }; shadowConnectivityManager = shadowOf(service.getConnectivityManager()); shadowWifiManager = shadowOf(service.getWifiManager()); service.onCreate(); when(authPreferences.getStoreUri()).thenReturn("imap+ssl+://xoauth:foooo@imap.gmail.com:993"); when(authPreferences.isLoginInformationSet()).thenReturn(true); when(preferences.getBackupContactGroup()).thenReturn(ContactGroup.EVERYBODY); when(preferences.isUseOldScheduler()).thenReturn(true); when(preferences.getDataTypePreferences()).thenReturn(dataTypePreferences); when(dataTypePreferences.enabled()).thenReturn(EnumSet.of(DataType.SMS)); }
private boolean shouldSchedule(Context context) { final Preferences preferences = getPreferences(context); final boolean autoBackupEnabled = preferences.isAutoBackupEnabled(); final boolean loginInformationSet = getAuthPreferences(context).isLoginInformationSet(); final boolean firstBackup = preferences.isFirstBackup(); final boolean schedule = (autoBackupEnabled && loginInformationSet && !firstBackup); if (!schedule) { final String message = "Not set up to back up. " + "autoBackup=" + autoBackupEnabled + ", loginInfoSet=" + loginInformationSet + ", firstBackup=" + firstBackup; log(context, message, preferences.isAppLogDebug()); } return schedule; }
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; }
private BackupConfig getBackupConfig(BackupType backupType, EnumSet<DataType> enabledTypes, BackupImapStore imapStore) { return new BackupConfig( imapStore, 0, getPreferences().getMaxItemsPerSync(), getPreferences().getBackupContactGroup(), backupType, enabledTypes, getPreferences().isAppLogDebug() ); }
private boolean shouldRun(JobParameters jobParameters) { if (BackupType.fromName(jobParameters.getTag()) == REGULAR) { final Preferences prefs = new Preferences(this); final boolean autoBackupEnabled = prefs.isAutoBackupEnabled(); if (!autoBackupEnabled) { // was disabled in meantime, cancel getBackupJobs().cancelRegular(); } return autoBackupEnabled; } else { return true; } }
@Test public void shouldScheduleIncoming() throws Exception { when(preferences.isAutoBackupEnabled()).thenReturn(true); when(preferences.getIncomingTimeoutSecs()).thenReturn(2000); Job job = subject.scheduleIncoming(); verifyJobScheduled(job, 2000, "INCOMING"); }
@Test public void shouldScheduleRegular() throws Exception { when(preferences.isAutoBackupEnabled()).thenReturn(true); when(preferences.getRegularTimeoutSecs()).thenReturn(2000); Job job = subject.scheduleRegular(); verifyJobScheduled(job, 2000, "REGULAR"); }
@Override public void onCreate() { super.onCreate(); setupStrictMode(); gcmAvailable = GooglePlayServices.isAvailable(this); preferences = new Preferences(this); preferences.migrate(); backupJobs = new BackupJobs(this); if (gcmAvailable) { setBroadcastReceiversEnabled(false); } else { Log.v(TAG, "Google Play Services not available, forcing use of old scheduler"); preferences.setUseOldScheduler(true); } K9MailLib.setDebugStatus(new K9MailLib.DebugStatus() { @Override public boolean enabled() { return preferences.isAppLogDebug(); } @Override public boolean debugSensitive() { return false; } }); if (gcmAvailable && DEBUG) { getContentResolver().registerContentObserver(Consts.SMS_PROVIDER, true, new LoggingContentObserver()); getContentResolver().registerContentObserver(Consts.CALLLOG_PROVIDER, true, new LoggingContentObserver()); } register(this); }
@Nullable private Job schedule(int inSeconds, BackupType backupType, boolean force) { if (LOCAL_LOGV) { Log.v(TAG, "scheduleBackup(" + inSeconds + ", " + backupType + ", " + force + ")"); } if (force || (preferences.isAutoBackupEnabled() && inSeconds > 0)) { final Job job = createJob(inSeconds, backupType); if (schedule(job) != null) { if (LOCAL_LOGV) { Log.v(TAG, "Scheduled backup job " + job + ", tag: " + job.getTag() + " due " + "" + (inSeconds > 0 ? "in " + inSeconds + " seconds" : "now")); } } return job; } else { if (LOCAL_LOGV) Log.v(TAG, "Not scheduling backup because auto backup is disabled."); return null; } }
BackupTask(@NonNull SmsBackupService service) { final Context context = service.getApplicationContext(); this.service = service; this.authPreferences = service.getAuthPreferences(); this.preferences = service.getPreferences(); this.fetcher = new BackupItemsFetcher( context.getContentResolver(), new BackupQueryBuilder(preferences.getDataTypePreferences())); PersonLookup personLookup = new PersonLookup(service.getContentResolver()); this.contactAccessor = new ContactAccessor(); this.converter = new MessageConverter(context, service.getPreferences(), authPreferences.getUserEmail(), personLookup, contactAccessor); if (preferences.isCallLogCalendarSyncEnabled()) { calendarSyncer = new CalendarSyncer( CalendarAccessor.Get.instance(service.getContentResolver()), preferences.getCallLogCalendarId(), personLookup, new CallFormatter(context.getResources()) ); } else { calendarSyncer = null; } this.tokenRefresher = new TokenRefresher(service, new OAuth2Client(authPreferences.getOAuth2ClientId()), authPreferences); }