ContentResolver.addPeriodicSync间隔向上舍入 [英] ContentResolver.addPeriodicSync interval round up

查看:340
本文介绍了ContentResolver.addPeriodicSync间隔向上舍入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的同步适配器工作得非常好,除了一件小事会在最近几个小时使我烦恼……对于我的应用程序,我希望同步适配器以10秒的间隔运行.

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);

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

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.

从日志文件中:

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

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

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 ?

发生在装有Android 5.0.2(Api级别22)的Motorola XT上.

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

使用模拟器Android 4.0.4(Api级别15)对其进行了尝试,并且它只执行了相同的操作而没有日志消息,并且间隔从60秒更改为30秒,而不是60秒.所以肯定有一些我不知道的限制.

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.

推荐答案

似乎无法添加间隔小于60秒的周期同步. (或者至少是4.4及更高版本.)

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);
}

这篇关于ContentResolver.addPeriodicSync间隔向上舍入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆