diff options
author | Fred Quintana <fredq@google.com> | 2010-01-27 12:17:49 -0800 |
---|---|---|
committer | Fred Quintana <fredq@google.com> | 2010-02-05 15:16:20 -0800 |
commit | c5d1c6db61f208b206b260f897bb5bbc64be4d97 (patch) | |
tree | 91a5ffe88326b446f57b7249ddf1406b8654d2f6 /core/java/android/content/ContentResolver.java | |
parent | 0a45a09814dea0398647f26497ecff54a77c5f8c (diff) | |
download | frameworks_base-c5d1c6db61f208b206b260f897bb5bbc64be4d97.zip frameworks_base-c5d1c6db61f208b206b260f897bb5bbc64be4d97.tar.gz frameworks_base-c5d1c6db61f208b206b260f897bb5bbc64be4d97.tar.bz2 |
add sync polling
- added the ability to specify that a sync (of account/authority/extras)
should occur at a given frequency
- the existing daily poll code was replaced with seeding each
account/authority with a 24 hour periodic sync
- enhanced the "adb shell dumpsys content" output to show the
periodic syncs and when they will next run
Diffstat (limited to 'core/java/android/content/ContentResolver.java')
-rw-r--r-- | core/java/android/content/ContentResolver.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/core/java/android/content/ContentResolver.java b/core/java/android/content/ContentResolver.java index eb2d7b1..b5587ed 100644 --- a/core/java/android/content/ContentResolver.java +++ b/core/java/android/content/ContentResolver.java @@ -42,6 +42,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.List; import java.util.ArrayList; +import java.util.Collection; /** @@ -966,6 +967,65 @@ public abstract class ContentResolver { } /** + * Specifies that a sync should be requested with the specified the account, authority, + * and extras at the given frequency. If there is already another periodic sync scheduled + * with the account, authority and extras then a new periodic sync won't be added, instead + * the frequency of the previous one will be updated. + * <p> + * These periodic syncs honor the "syncAutomatically" and "masterSyncAutomatically" settings. + * Although these sync are scheduled at the specified frequency, it may take longer for it to + * actually be started if other syncs are ahead of it in the sync operation queue. This means + * that the actual start time may drift. + * + * @param account the account to specify in the sync + * @param authority the provider to specify in the sync request + * @param extras extra parameters to go along with the sync request + * @param pollFrequency how frequently the sync should be performed, in seconds. + */ + public static void addPeriodicSync(Account account, String authority, Bundle extras, + long pollFrequency) { + validateSyncExtrasBundle(extras); + try { + getContentService().addPeriodicSync(account, authority, extras, pollFrequency); + } catch (RemoteException e) { + // exception ignored; if this is thrown then it means the runtime is in the midst of + // being restarted + } + } + + /** + * Remove a periodic sync. Has no affect if account, authority and extras don't match + * an existing periodic sync. + * + * @param account the account of the periodic sync to remove + * @param authority the provider of the periodic sync to remove + * @param extras the extras of the periodic sync to remove + */ + public static void removePeriodicSync(Account account, String authority, Bundle extras) { + validateSyncExtrasBundle(extras); + try { + getContentService().removePeriodicSync(account, authority, extras); + } catch (RemoteException e) { + throw new RuntimeException("the ContentService should always be reachable", e); + } + } + + /** + * Get the list of information about the periodic syncs for the given account and authority. + * + * @param account the account whose periodic syncs we are querying + * @param authority the provider whose periodic syncs we are querying + * @return a list of PeriodicSync objects. This list may be empty but will never be null. + */ + public static List<PeriodicSync> getPeriodicSyncs(Account account, String authority) { + try { + return getContentService().getPeriodicSyncs(account, authority); + } catch (RemoteException e) { + throw new RuntimeException("the ContentService should always be reachable", e); + } + } + + /** * Check if this account/provider is syncable. * @return >0 if it is syncable, 0 if not, and <0 if the state isn't known yet. */ |