ContentResolver.addPeriodicSync间隔向上舍入

har*_*ers 4 android intervals android-syncadapter

我的同步适配器确实工作得非常好,除了在过去的几个小时里有一些小问题让我失意...对于我的应用程序,我希望同步适配器以10秒的间隔运行.

ContentResolver.addPeriodicSync(mAccount, AUTHORITY, Bundle.EMPTY, 5);
Run Code Online (Sandbox Code Playgroud)

会发生什么是同步开始每60秒而不是请求的5秒.当我将其更改interval为70秒时,同步每70秒开始一次.

从日志文件:

W/ContentService? Requested poll frequency of 5 seconds being rounded up to 60 seconds.
Run Code Online (Sandbox Code Playgroud)

或者,为了确保ContentService占用我的间隔,当我将间隔更改为13秒时:

W/ContentService? Requested poll frequency of 13 seconds being rounded up to 60 seconds.
Run Code Online (Sandbox Code Playgroud)

有人知道这次回合的原因吗?

我的摩托罗拉XT搭载Android 5.0.2(Api等级22).

尝试使用模拟器Android 4.0.4(Api等级15),它只在没有日志消息的情况下执行相同的操作,而不是60秒,间隔更改为30秒.所以必须有一些我不知道的限制.

谢谢,如果需要更多信息,请与我们联系.

har*_*ers 8

似乎不可能添加间隔小于60秒的周期同步.(或者至少从4.4或更高.)

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);
}
Run Code Online (Sandbox Code Playgroud)