Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ContentResolver.addPeriodicSync interval round up

My sync adapter does work perfectly well except for one little thing which bugs the sh*t out of me for the last few hours... For my app i want the sync adapter to run with an interval of 10 seconds.

ContentResolver.addPeriodicSync(mAccount, AUTHORITY, Bundle.EMPTY, 5);

What happens is that the sync starts every 60 seconds instead of the requested 5 seconds. When i change the interval to 70 seconds then the sync starts every 70 seconds.

From the log file:

W/ContentService﹕ Requested poll frequency of 5 seconds being rounded up to 60 seconds.

Or, to be sure that the ContentService is taking about my interval, when i change the interval to 13 seconds:

W/ContentService﹕ Requested poll frequency of 13 seconds being rounded up to 60 seconds.

Does someone has any knowledge about the reason of this round up ?

Happens on my Motorola XT with Android 5.0.2 (Api level 22).

Tried it with the emulator, Android 4.0.4 (Api level 15), and it does the same thing only without the log message and instead of 60 seconds the interval is changed to 30 seconds. So there must be some limitation i am not aware of.

Thanks, let me know if more information is required.

like image 779
harco gijsbers Avatar asked Jan 07 '23 19:01

harco gijsbers


1 Answers

It seems to be that it is not possible to add a period sync with an interval lesser than 60 seconds. (Or least from 4.4 and higher.)

https://android.googlesource.com/platform/frameworks/base/+/kitkat-mr1-release/services/java/com/android/server/content/ContentService.java

if (request.isPeriodic()) {
    mContext.enforceCallingOrSelfPermission(
        Manifest.permission.WRITE_SYNC_SETTINGS,
        "no permission to write the sync settings");
    if (runAtTime < 60) {
        Slog.w(TAG, "Requested poll frequency of " + runAtTime
            + " seconds being rounded up to 60 seconds.");
        runAtTime = 60;
    }
    PeriodicSync syncToAdd =
        new PeriodicSync(account, provider, extras, runAtTime, flextime);
    getSyncManager().getSyncStorageEngine().addPeriodicSync(syncToAdd, userId);
}
like image 161
harco gijsbers Avatar answered Jan 17 '23 23:01

harco gijsbers