private static void a(Context paramContext, Account paramAccount) { String str = paramAccount.name; long l = Math.max(a, ((hyi)mbb.a(paramContext, hyi.class)).c(aun.b, str).longValue()); Iterator localIterator = ContentResolver.getPeriodicSyncs(paramAccount, "com.google.android.apps.photos.GooglePhotoDownsyncProvider").iterator(); int i = 0; if (localIterator.hasNext()) { PeriodicSync localPeriodicSync = (PeriodicSync)localIterator.next(); if (localPeriodicSync.period == l) {} for (int j = 1;; j = 0) { if (j == 0) { ContentResolver.removePeriodicSync(paramAccount, "com.google.android.apps.photos.GooglePhotoDownsyncProvider", localPeriodicSync.extras); } i |= j; break; } } if (i == 0) { Bundle localBundle = new Bundle(); localBundle.putBoolean("sync_periodic", true); ContentResolver.addPeriodicSync(paramAccount, "com.google.android.apps.photos.GooglePhotoDownsyncProvider", localBundle, l); } }
/** * Test if periodic sync is already configured * @param intervalInMinute interval in minute * @return true if already exists */ private boolean periodicSyncExists( int intervalInMinute ) { boolean exists = false; long syncInSecond = intervalInMinute * SECONDS_PER_MINUTE; List<PeriodicSync> periodicSyncs = ContentResolver.getPeriodicSyncs(mAccount, mAuthority); if ( periodicSyncs != null && !periodicSyncs.isEmpty()) { for( PeriodicSync periodicSync : periodicSyncs ) { if (periodicSync.period == syncInSecond) { exists = true ; } } } return exists; }
@Implementation public static void addPeriodicSync(Account account, String authority, Bundle extras, long pollFrequency) { validateSyncExtrasBundle(extras); getStatus(account, authority, true).syncs.add(new PeriodicSync(account, authority, extras, pollFrequency)); }
@Test public void shouldGetPeriodSyncs() throws Exception { assertThat(ContentResolver.getPeriodicSyncs(a, AUTHORITY).size()).isEqualTo(0); ContentResolver.addPeriodicSync(a, AUTHORITY, new Bundle(), 6000l); List<PeriodicSync> syncs = ContentResolver.getPeriodicSyncs(a, AUTHORITY); assertThat(syncs.size()).isEqualTo(1); PeriodicSync first = syncs.get(0); assertThat(first.account).isEqualTo(a); assertThat(first.authority).isEqualTo(AUTHORITY); assertThat(first.period).isEqualTo(6000l); assertNotNull(first.extras); }
/** * Create a new Account and activate the automatic sync * * @param account * null is not allowed * @param accountManager * null is not allowed * @param password * null is not allowed */ public static boolean createAccount(Context context, final Account account, AccountManager accountManager, String password) { boolean added = accountManager.addAccountExplicitly(account, password, null); if (added) { List<PeriodicSync> syncs = ContentResolver.getPeriodicSyncs( account, ContactsContract.AUTHORITY); if (syncs != null) { // Remove default syncs. for (PeriodicSync periodicSync : syncs) { ContentResolver.removePeriodicSync(account, ContactsContract.AUTHORITY, periodicSync.extras); } } SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(context); int synctime; try { synctime = settings.getInt("pref_synctime", DEFAULT_SYNCINTERVAL); } catch (ClassCastException e) { LogHelper.logI(TAG, "Invalid SyncTime-Settingvalue", e); synctime = DEFAULT_SYNCINTERVAL; } if (synctime != 0) { addPeriodicSync(ContactsContract.AUTHORITY, Bundle.EMPTY, synctime, context); } // Set contacts sync for this account. ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true); } else { LogHelper.logI(TAG, "Account " + account.name + " is already available."); } return added; }
public static void applySyncInterval(Context context) { Account mAccount = AppUtils.getAccount(context); if (mAccount != null) { List<PeriodicSync> syncs = ContentResolver.getPeriodicSyncs( mAccount, CalendarContractWrapper.AUTHORITY()); for (PeriodicSync sync : syncs) { Log.d(TAG, "old sync: " + sync.period); } // Inform the system that this account supports sync // ContentResolver.setIsSyncable(mAccount, // CalendarContractWrapper.AUTHORITY(), 1); // Remove old sync periode ContentResolver.removePeriodicSync(mAccount, CalendarContractWrapper.AUTHORITY(), new Bundle()); ContentResolver.removePeriodicSync(mAccount, KusssContentContract.AUTHORITY, new Bundle()); // Turn on periodic syncing int interval = getSyncInterval(context); ContentResolver.addPeriodicSync(mAccount, CalendarContractWrapper.AUTHORITY(), new Bundle(), 60 * 60 * interval); ContentResolver.addPeriodicSync(mAccount, KusssContentContract.AUTHORITY, new Bundle(), 60 * 60 * interval); } AppUtils.updateSyncAlarm(context, true); }
@Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { ((TextView) this.accountSpinner.getSelectedView()).setBackgroundColor(0xFFB6B6B6); Account account = Listactivity.accounts[pos]; // Check periodic sync. If set to 86400 (once a day), set it to 900 (15 minutes) // this is due to bad upgrade to v4 which handles offline mode and syncing // Remove this code after V4.0 if version no more used List<PeriodicSync> currentSyncs = ContentResolver.getPeriodicSyncs (account, AUTHORITY); for (PeriodicSync onesync : currentSyncs) { if (onesync.period == 86400) { ContentResolver.setIsSyncable(account, AUTHORITY, 1); ContentResolver.setSyncAutomatically(account, AUTHORITY, true); ContentResolver.addPeriodicSync(account, AUTHORITY, new Bundle(), 60); Toast.makeText(getApplicationContext(), "Recreating this account is recommended to manage sync interval. Set to 15 minutes in the meantime", Toast.LENGTH_LONG).show(); } } // End of code Listactivity.imapNotes2Account.SetAccountname(account.name); Listactivity.imapNotes2Account.SetUsername(Listactivity.accountManager.getUserData (account, "username")); String pwd = Listactivity.accountManager.getPassword(account); Listactivity.imapNotes2Account.SetPassword(pwd); Listactivity.imapNotes2Account.SetServer(Listactivity.accountManager.getUserData (account, "server")); Listactivity.imapNotes2Account.SetPortnum(Listactivity.accountManager.getUserData (account, "portnum")); Listactivity.imapNotes2Account.SetSecurity(Listactivity.accountManager.getUserData (account, "security")); Listactivity.imapNotes2Account.SetUsesticky(accountManager.getUserData (account, "usesticky")); Listactivity.imapNotes2Account.SetSyncinterval(Listactivity.accountManager.getUserData (account, "syncinterval")); Listactivity.imapNotes2Account.SetaccountHasChanged(); Listactivity.imapNotes2Account.SetAccount(account); this.RefreshList(); }
/** * Test if periodic sync is already configured * * @param intervalInMinute interval in minute * @return true if already exists */ private boolean periodicSyncExists(int intervalInMinute) { boolean exists = false; long syncInSecond = intervalInMinute * SECONDS_PER_MINUTE; List<PeriodicSync> periodicSyncs = ContentResolver.getPeriodicSyncs(mAccount, mAuthority); if (periodicSyncs != null && !periodicSyncs.isEmpty()) { for (PeriodicSync periodicSync : periodicSyncs) { if (periodicSync.period == syncInSecond) { exists = true; } } } return exists; }
@Implementation public static List<PeriodicSync> getPeriodicSyncs(Account account, String authority) { return getStatus(account, authority, true).syncs; }
private List<PeriodicSync> getPeriodicSyncs(User user) { Account account = new Account(user.getUsername(), syncAccountType); return ShadowContentResolver.getPeriodicSyncs(account, syncContentAuthority); }