Author Topic: Scheduled synch does not work properly for intervals below 5 minutes  (Read 6974 times)

d_d

  • Newbie
  • *
  • Posts: 1
Hi,

First of all - great app, the best email client on Android I know of.

I have a setting of sync every 1 minute. I recently switched from Android 5.0.1 to 6.0.1. On the former AquaMail was 100% reliably syncing every 1 minute. On Android 6.0.1 It is syncing every 1 mintute only when the charger is on, if I unplug it reverts to 5 minutes interval (which is not enough for my use case).

Now I am aware of the continued quest of the Android team to make life of people who want to schedule frequent repeating alarms miserable. I am aware of the doze mode in Android 6 for example but its not that, the phone is not in doze mode and another app on my phone is successfully scheduling alarms every 15 seconds using AlarmManager.setExact() at the time AquaMail reverts to 5 minute syncs. Aqua mail is also excluded from battery optimization. So I am sure this can be fixed.

I can provide logs if needed.

nica

  • Guest
Re: Scheduled synch does not work properly for intervals below 5 minutes
« Reply #1 on: March 20, 2017, 11:34:30 pm »
Hi, if you need to get incoming messages instantly, I recommend using the push service for the folder with an IMAP or EWS account.

Kostya Vasilyev

  • Hero Member
  • *****
  • Posts: 12740
Re: Scheduled synch does not work properly for intervals below 5 minutes
« Reply #2 on: March 21, 2017, 08:33:53 pm »
+1 to what @nica wrote.

Recent Android versions limit how often an app can work in the background -- even if it's excluded from Doze Mode. Google knows better :)
Creating debug logs for diagnostics: https://www.aqua-mail.com/troubleshooting/

The official FAQ: https://www.aqua-mail.com/faq/

Лог-файлы для диагностики: https://www.aqua-mail.com/ru/troubleshooting/

Вопросы и ответы: https://www.aqua-mail.com/ru/faq/

teglicha

  • Newbie
  • *
  • Posts: 13
Re: Scheduled synch does not work properly for intervals below 5 minutes
« Reply #3 on: April 12, 2017, 07:44:26 pm »
Hi.
I have the same issue. But my scheduling period is 1 hour. My ref.point setting is 00:00 . This setup worked perfectly before (but I've been using an older version, before the major changes). Now I'm on Android 6.0.1.
AquaMail syncs (checks in the background) imap accounts not at exact hour boundary but fluctuates +- 5-6 minutes.
I'm also sure this can be fixed (if made on purpose?!) because other apps are able to schedule their alarms/actions at the exact minute, even second.
Could anyone shed more light on this issue?

StR

  • Hero Member
  • *****
  • Posts: 1558
Re: Scheduled synch does not work properly for intervals below 5 minutes
« Reply #4 on: April 13, 2017, 04:47:16 am »
You may want to read the FAQ, the item "Persistent network errors or the app not checking mail (any phone, with specifics for Android 6+, Xiaomi MIUI, Huawei)".
http://www.aqua-mail.com/?page_id=227


teglicha

  • Newbie
  • *
  • Posts: 13
Re: Scheduled synch does not work properly for intervals below 5 minutes
« Reply #5 on: April 13, 2017, 11:07:16 am »
Thanks.
But all those things are looked after. Xiaomi phone. Battery optimizer/saver is off, Cleam master thing is disabled (Cleaner), and threr is no button or anything in Mail/Receiving about any Doze mode, I guess it is whitelisted.
The problem is AquaMail checks for mail not at exact hour but anything between :00 and :09.
Again, other apps (like reminder apps) are exact always, below the minute.
Anyway, I guess I'll have to get used to that. If this is a Marshmallow issue of some kind, I'll have to say older Androids were better.

P.S. Today it's worse. It won't even check. I started it tens of times after the "exact hour" just to make sure it's running, nothing. Before, if any network error during check, it would  display a red exclamation next to accounts in main screen. Now it just displays the last time it checked and nothing more.
Xiaomi redmi 4 phone. I disabled battery saver/optimizations, included aquamail in exceptions beforehand (just in case), Cleaner(master) is disabled, in settings there is no button to allow Doze, etc.
Memory optimizaion in Developer in MIUI is set to Low. Aqua is added to Autostart permissions.
Other apps are scheduling themselves just fine.
I can manually initiate a check through the program and it connects and checks for mail correctly, it only quit auto-checking on a schedule every hour.
Aqua is the best email client, I was very happy before, I'm a Pro customer.
Unfortunately it seems I'll be on a journey to find an alternative client. This cannot be tolerated, even if MIUI is at fault. If other client fails too then I'll take my words back.
Thanks.

P.S.2. Maybe if I could send the debug log of a 5-minute_late_scheduled_check situation so Kostya would analyze and come up with what's wrong...?!
« Last Edit: April 14, 2017, 09:37:04 am by teglicha »

StR

  • Hero Member
  • *****
  • Posts: 1558
Re: Scheduled synch does not work properly for intervals below 5 minutes
« Reply #6 on: April 15, 2017, 05:01:34 am »
The symptoms you describe sound like something else is still not allowing Aquamail to run at the scheduled time. And since one of the known issues that you were not able to confirm yet is the doze mode, I would recommend verifying that.
(Note that the fact that Aquamail displays only "the last time it checked and nothing more", suggests that it was not allowed to run at the scheduled time, - so it didn't have a chance to connect.)
I don't have 6.x Android, so, I cannot advise you on how to find the option (beyond the FAQ). But if Aquamail has not prompted you to whitelist Aquamail, that's what I'd check first to make sure Aquamail is whitelisted.
If you cannot find the button in Aquamail, - check it (and whitelist) directly in Android settings. Follow e.g. these instructions how to do that:
http://www.valuewalk.com/2015/11/how-to-stop-apps-from-using-doze-on-android-6-0-marshmallow/

Note that some other email apps store your messages (and your login/password information) on their servers in the cloud, and that allows to work around the doze mode in a different way. But would you like your messages to be stored in the cloud by the mail-app company?


teglicha

  • Newbie
  • *
  • Posts: 13
Re: Scheduled synch does not work properly for intervals below 5 minutes
« Reply #7 on: April 15, 2017, 11:59:14 am »
Thanks for the reply.
No signs of such "Doze" mode here. I turned off all battery optimizations and savers in MIUI.
In fact, now it checks every cycle, just most of the times it is late by about 1 to ~10 minutes after the moment it should check. I set it up to do it every 30 minutes with ref.point 00:00 and no settle-in-time.
I turned On debugging and when there was 10 minutes offset I turned it back Off and took a look at the debug txt file. It shows Aqua correctly "thinks" its next schedule to be at 10:30 (as example). Then I see the "intent" seems to have happened at 10:40 (and not 10:30). E.g. I think this is when the OS called for Aqua to do its thing.
Strange thing is about half of the times it checks on time, maybe not to the second but down to the minute.
I wonder if this is something new in latest versions.. Previously I had JB4.2 AOSP with older Aqua version (2-3 months old before the major changes) and it was working perfectly. I have the feeling it just has some new bug by not scheduling itself at the right times sometimes. If not most, but half of the cases it checks at the expected hour:minute. Although not at the exact second (zero second).
Otherwise I still find it the best email appm that's why I'm looking for the cause for this behavior.
For the sake of this I'm testing other email apps to see if they behave like this.

P.S. It's 12:54 and Aqua's last check was 12:00. It missed 12:30. This is unacceptable, I'm sorry.
P.S.2. Today it missed 2 or 3 schedules EVEN while I was actively using the phone at those exact times.

P.S.3. Trying a competitor email client. The one with the sky color in the name. It schedules and checks for mail exactly at the second. Every time! So it seems the problem is in Aqua. Where could I file a bugreport? I still want to use Aqua as it has finer control on mail handling.

P.S.4. It seems the more actively I'm using the phone (especially during and around the time it should execute its schedule), the more frequently it misses its schedules.
The other email client works perfectly on time, no matter for how long the phone is asleep, or using it actively.
« Last Edit: April 16, 2017, 12:30:21 pm by teglicha »

Kostya Vasilyev

  • Hero Member
  • *****
  • Posts: 12740
Re: Scheduled synch does not work properly for intervals below 5 minutes
« Reply #8 on: April 16, 2017, 01:56:40 pm »
Re: MIUI

We had reports of this or similar issues on Xiaomi devices.

Based on a couple of debug logs, the phone's software doesn't call our code at the right times (late) or at all (sometimes).
Creating debug logs for diagnostics: https://www.aqua-mail.com/troubleshooting/

The official FAQ: https://www.aqua-mail.com/faq/

Лог-файлы для диагностики: https://www.aqua-mail.com/ru/troubleshooting/

Вопросы и ответы: https://www.aqua-mail.com/ru/faq/

teglicha

  • Newbie
  • *
  • Posts: 13
Re: Scheduled synch does not work properly for intervals below 5 minutes
« Reply #9 on: April 16, 2017, 04:56:48 pm »
Reminder apps are working correctly, every single time. THey schedule an alarm to notify about an event.
How do they do that without a glitch, on the same phone(s), numerous times a day?
Just asking, not blaming anyone.

Also, I'm not android programmer, but this issue is dribing me crazy and before I change phone for another brand, I'd like to dig some more. I found opinions of using some different approach, spawning a service or something... no matter it would consume some RAM... I don't know, this is very frustrating, and it seems it doesn't affect your app only.
« Last Edit: April 16, 2017, 05:03:43 pm by teglicha »

mikeone

  • Hero Member
  • *****
  • Posts: 2762
Re: Scheduled synch does not work properly for intervals below 5 minutes
« Reply #10 on: April 16, 2017, 05:37:08 pm »
Do these 'reminder apps' need connection to a server?

teglicha

  • Newbie
  • *
  • Posts: 13
Re: Scheduled synch does not work properly for intervals below 5 minutes
« Reply #11 on: April 16, 2017, 10:03:14 pm »
Do these 'reminder apps' need connection to a server?
No. Why?
Kostya said Android didn't call the app's code at the right times in the first place. It hadn't have the chance to be called, what left to try to connect to a server.

Kostya Vasilyev

  • Hero Member
  • *****
  • Posts: 12740
Re: Scheduled synch does not work properly for intervals below 5 minutes
« Reply #12 on: April 18, 2017, 08:14:16 pm »
Yes, some manufacturers -- e.g. Huawei, Xiaomi -- deliberately break Android in order to get better (lower) battery usage.

They usually provide a way to turn it off, app by app, and sometimes it works but sometimes it doesn't. There is information on this in the FAQ, near the end.

I do know however that on _some_ Xiaomi models, even this doesn't always help.

Re: BlueMail (Type Mail, etc.)

Uses a completely different approach, which has some good sides but also some bad sides (wrt. to privacy, and also expensive to implement and support: Cloud Magic is $50/year so that's how much it costs or thereabout, and yet there are cloud based mail apps that are free and don't even contain ads...).

And them some apps may get special treatment from these "manufacturer specific optimizations". I have seen code on a Samsung phone that made exceptions for Gmail, Google+, WhatsApp and a few other apps.

I'm sure that none of this helps the original post author, who just wants Aqua Mail to work on his Xiaomi.

Sorry we don't have a "workaround" except Xiaomi's official "white list Aqua Mail in the phone's settings", and if that doesn't work, sorry there isn't anything else I can suggest.
Creating debug logs for diagnostics: https://www.aqua-mail.com/troubleshooting/

The official FAQ: https://www.aqua-mail.com/faq/

Лог-файлы для диагностики: https://www.aqua-mail.com/ru/troubleshooting/

Вопросы и ответы: https://www.aqua-mail.com/ru/faq/

teglicha

  • Newbie
  • *
  • Posts: 13
Re: Scheduled synch does not work properly for intervals below 5 minutes
« Reply #13 on: April 19, 2017, 06:57:02 pm »
Hi, and thanks.
I have to admit, bluemail, type, droidmail were what I tested. All of them failed the same way, to use scheduled check reliably.
I switched to push mail and for now it works as expected, 2-3 days later.

Just out of curiosity, I contacted the author of the reminder app I'm using (on JB4.2 before, now on my xiaomi). His app has no problem to be called/awaken by Android on the specified moment in time, always. As a side note - not actually on time to the second but exactly 30 seconds ahead of its scheduled moment. This 30 sec offset was present on JB4.2 as well.
And I've done that because as I got it, aquamail's code wasn't called on time (if at all) by the OS in the first place, so it shouldn't have to do with the fact Aqua uses the network there.

This is the code he is using successfully.
Code: [Select] [nofollow]
    public static void setExactAlarm(final Context ctxt, final int type, final long triggerAtMillis, final PendingIntent pi) {
        final AlarmManager alarms = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE);

        if (VersionUtils.isMarshmellow23__6_0_OrLater()) {
            alarms.setExactAndAllowWhileIdle(type, triggerAtMillis, pi);
        } else if (VersionUtils.isKitKat19__4_4_OrLater()) {
            alarms.setExact(type, triggerAtMillis, pi);
        } else {
            alarms.set(type, triggerAtMillis, pi);
        }
    }

I don't want to sound teaching or something, not at all. Just if this could ring any bells as to how this problem could be resolved.
Thanks.
« Last Edit: April 19, 2017, 07:02:48 pm by teglicha »

Kostya Vasilyev

  • Hero Member
  • *****
  • Posts: 12740
Re: Scheduled synch does not work properly for intervals below 5 minutes
« Reply #14 on: April 21, 2017, 10:10:14 pm »
RE: I don't want to sound teaching or something, not at all. Just if this could ring any bells as to how this problem could be resolved.

Aqua Mail uses setAllowWhileIdle

The "exact" versions -- setExactAndAllowWhileIdle and setExact -- are undesirable because they prevent Android from "coalescing" nearby wake-up alarms.

Creating debug logs for diagnostics: https://www.aqua-mail.com/troubleshooting/

The official FAQ: https://www.aqua-mail.com/faq/

Лог-файлы для диагностики: https://www.aqua-mail.com/ru/troubleshooting/

Вопросы и ответы: https://www.aqua-mail.com/ru/faq/