The interval ContentResolver.addPeriodicSync is rounded

My sync adapter works just fine, except for one small thing that sh * t has beaten me over the past few hours. For my application, I want the sync adapter to work at intervals of 10 seconds.

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

It happens that synchronization starts every 60 seconds instead of the requested 5 seconds. When I change interval to 70 seconds, synchronization starts every 70 seconds.

From the log file:

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

Or, to make sure ContentService uses 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 anyone know the reason for this round?

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

I tried it with Android 4.0.4 emulator (Api level 15), and it does the same thing only without a log message, and instead of 60 seconds, the interval changes to 30 seconds. Therefore, there must be some kind of restriction that I do not know about.

Thank you, let me know if more information is required.

+4
source share
2 answers

It seems that it is not possible to synchronize the period with an interval of less than 60 seconds. (Or, at least, from 4.4 and above.)

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); } 
+8
source

W / ContentService: requested polling rate 300 seconds rounded to 900.

It seems that on Android 7 and 8, the minimum frequency is 15 minutes. Before Android 6, we had a round of up to 60 seconds, which is worthy.

I also noticed that we have a note on the poll frequency, which is at least 1h.

pollFrequency long: number of seconds in seconds ... A minimum period of 1 hour is applied.

It seems to me that this does not correspond to me.

0
source

All Articles