kraigs-android / kraigsandroid

Kraig's android applications
26 stars 26 forks source link

Untimely alarms on Samsung S20 Android 10 #141

Closed gowenfawr closed 3 years ago

gowenfawr commented 4 years ago

Hello,

Long-time user of Alarm Klock on my S7. Now I've upgraded to an S20 and the alarms are going off in an untimely manner - my 8:58 PM alarm went off around 9:50 last night, and my 8:58 AM alarm went off around 9:20 this morning.

Alarm Klock is entered in the "Apps that won't be put to sleep" under Battery settings.

It doesn't make a difference whether I'm using the phone or not.

How can I help debug this?

kraigs-android commented 4 years ago

Which version of the app are you using? There were some android-10 related changes that caused similar sounding issues, but they were all fixed (as far as I know) last year in version 2.7.

If you're already using that version, my guess is that the problem is related to some kind of power saving application. Logs (from adb logcat or similar) would be helpful to debug/verify this.

gowenfawr commented 4 years ago

I'm running version 2.7.

I ran several tests today; the first three it worked normally, and on the fourth it was delayed and only went off when I entered the Alarm Klock app. The sequence of events was as follows:

Attached is the adb log covering that timeframe. alarmklock.txt I'm not used to adb but timestamps seem a little crazy, hope that's normal.

The only known difference between the tests that worked and the one that didn't is that more time elapsed between setting the alarm and testing - when I set it 2 or 3 minutes ahead, it worked every time.

kraigs-android commented 4 years ago

I don't see anything obviously wrong in that log file. The only strange thing seems to be these lines:

06-08 14:03:13.688  1160 10427 D PowerManagerService: [api] acquire WakeLock SCREEN_DIM_WAKE_LOCK           'wake id 1' ACQUIRE_CAUSES_WAKEUP (uid=10321 pid=17718 pkg=com.angrydoughnuts.android.alarmclock)
06-08 14:03:13.688 17718 17718 I AlarmNotificationService: Acquired lock 1 for alarm 7

This shows the wakeup event delivered to the application at 14:03:13.688, which is over 3 minutes after you said the alarm was scheduled. It's possible that the application set the wrong time for the wakeup (there isn't a log message for this, unfortunately), but that seems unlikely. That code hasn't changed in years and shouldn't be impacted by any other environmental factors.

What's more likely is that the android notification service is delaying the app's wake ups. This service has changed numerous times over the years and has very aggressive power saving features. If an abusive application tries to schedule too many wakeups at exact times, the operating system will begin delaying and batching them together as a power saving mechanism. This is consistent with your observation that the first few work and later ones do not.

There's a bunch of documentation about this here: https://developer.android.com/reference/android/app/AlarmManager. In particular, the documentation for setExactAndAllowWhileIdle (which is what this app uses to schedule alarms) has a comment about delaying notifications if they occur too frequently by up to 15 minutes...

After having a look at that, do the restrictions described sound like the alarm scheduling pattern you are trying?

gowenfawr commented 4 years ago

The restrictions described sound bizarre. The last paragraph reads as "We'll make it go off when we want, not when you asked. And more so if in idle." The previous paragraph makes it sound like this enforced flexibility is related to scheduling alarms close together, but the last paragraph sounds wider.

My experience over the last two days has been:

08:00 - on time 08:45 - on time 08:58 - on time 20:58 - delayed 2-20 minutes both days

I just un-checked and re-checked the 20:58 alarm to see if "scheduling" it by itself (not at the same time as I initially set them all) makes a difference. I'll check back in in a couple days to see how things are running.

gowenfawr commented 4 years ago

Just to close the loop on this, after a month, my alarms (4 regular daily, 1-2 dynamic every other day or so) are going off on target. The last late alarm I had was about two weeks ago. So insofar as there's a problem here, it seems weighted toward initial setup of multiple alarms.

If you need more testing done in this area, ping me and I'll see what I can do.

Thanks for a great app, gowen