forrestguice / SuntimesWidget

Android app (and widget collection) that displays sunlight and moonlight times.
GNU General Public License v3.0
329 stars 61 forks source link

Various alarm issues #628

Closed jackthebean closed 1 year ago

jackthebean commented 1 year ago

Describe the bug 1 I have set up multiple repeating alarms for Civil Twilight am and pm, both solstices and both equinoxes (see attached)
Screenshot_20220930_100754_com forrestguice suntimeswidget

Sometimes, twice so far in about 5 days, I get a notification, as attached, Screenshot_20220927_125144_eu faircode email warning me that the alarm is due in some hours. The first time I swiped the notification (or possibly clicked dismiss) and the notification did disappear. However the alarm also did not ring as I expected.

why do/did these notifications sometimes appear?

why does dismissing them remove that alarm? though maybe that was connected to the 2nd issue.

The 2nd time I got the notification warning I ignored it and it self disappeared and, I think, the next twilight pm alarm did not go off.

2 The last 4 civil twilight am and pm alarms have not rung at all.

The alarms are still showing but not activating at all.

They worked fine for first 6? events.

To Reproduce Steps to reproduce the behavior: Created twilight am and pm alarms on repeat every day (except Sunday for am)

Expected behavior Expected alarm

Screenshots If applicable, add screenshots to help explain the problem.

Version Info:

Additional context Add any other information about the problem here.

forrestguice commented 1 year ago

Thanks for the report @jackthebean. I'm sorry to hear those alarms aren't working reliably.

Its an old problem that seems to get worse with each Android version. The alarms work by registering a PendingIntent with AlarmManager, however the OS might decide to unschedule these at any time (trying to save battery). It also causes widgets to stop updating. To avoid this pitfall its necessary to disable battery optimization (Suntimes -> Settings -> Alarms should display a warning in orange). Hopefully whitelisting the app will make your alarms more reliable.

I think the 'repeating' option might be a factor too. Each alarm is (re)scheduled when initially enabled, when eventually triggered, or when the device reboots. If an alarm fails to trigger its ends a chain of events and doesn't get scheduled again. Meanwhile the alarm list continues to show these items as enabled (not ideal). You should be able to restore individual alarms by toggling them disabled/enabled. Rebooting the device should restore them all.

Sometimes, twice so far in about 5 days, I get a notification, as attached,

This is a "reminder notification" that should always appear within ~10 hours of an alarm (to change or disable Settings -> Alarms -> Reminder within). Tapping 'dismiss' should dismiss the alarm before it sounds (and trigger a reschedule for repeating alarms). If you schedule an alarm for within ~10 hours it should cause the notification to appear immediately. It doesn't sound like that's happening reliably either though (these too might be unscheduled same as the alarm). Its also possible there is some bug when dismissing early that caused these alarms to become unscheduled..

I wish I had something more definitive. It seems to happen a lot depending on the device (https://dontkillmyapp.com/), so I'm considering ways to make things more robust.

jackthebean commented 1 year ago

Thanks for the reply.

I have now disabled battery optimisation, disabled and reenabled the alarms and will see what happens.

Incidentally the phone had been rebooted a few times since the alarms stopped working and it did not reset them.

Re the notification I think it would be helpful if the message was 'Dismiss alarm' rather than just dismiss as unclear whether it was dismiss alarm or dismiss warning/notification.  Personally I don't feel a need for the notification for all the alarm types and so would be good if that was optional.

I only dismissed the alarm via the notification once and so while that might have unscheduled that alarm it should not have affected the others.

Also when creating an alarm there is a tick icon to save what has been set.  However when then making the subsequent settings or editing the alarm there is an icon of 2 ticks AND one of a save/floppy icon.  What is the difference?  Looks as if 2 ticks mean activate but 1 tick seems to mean 'apply' and then takes you to the final setup screen.

I just edited the morning civil twilight alarm to change the days of the week it activates and sometimes I got the 2 ticks and the floppy icon.  Other times I got the floppy icon and a X icon.  So 2 ticks means enable, 1 tick means apply and save icon means save?  Might be helpful of clicking those buttons brought up brief confirmation of action taken.

Rob

On 02/10/2022 03:54, Forrest Guice wrote:

Thanks for the report @jackthebean https://github.com/jackthebean. I'm sorry to hear those alarms aren't working reliably.

Its an old problem that seems to get worse with each Android version. The alarms work by registering a PendingIntent with AlarmManager https://developer.android.com/reference/android/app/AlarmManager, however the OS might decide to unschedule these at any time (trying to save battery). It also causes widgets to stop updating. To avoid this pitfall its necessary to disable battery optimization (|Suntimes -> Settings -> Alarms| should display a warning in orange). Hopefully whitelisting the app will make your alarms more reliable.

I think the 'repeating' option might be a factor too. Each alarm is (re)scheduled when it initially enabled, when eventually triggered, or when the device reboots. If an alarm fails to trigger its ends a chain of events and doesn't get scheduled again. Meanwhile the alarm list continues to show these items as enabled (not ideal). You should be able to restore individual alarms by toggling them disabled/enabled. Rebooting the device should restore them all.

Sometimes, twice so far in about 5 days, I get a notification, as
attached,

This is a "reminder notification" that should always appear within ~10 hours of an alarm (to change or disable |Settings -> Alarms -> Reminder within|). Tapping 'dismiss' should dismiss the alarm before it sounds (and trigger a reschedule for repeating alarms). If you schedule an alarm for within ~10 hours it should cause the notification to appear immediately. It doesn't sound like that's happening reliably either though (these too might be unscheduled same as the alarm). Its also possible there is some bug when dismissing early that caused these alarms to become unscheduled..

— Reply to this email directly, view it on GitHub https://github.com/forrestguice/SuntimesWidget/issues/628#issuecomment-1264536382, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACLSW3W2AVZF764UMPZJEQTWBD2N7ANCNFSM6AAAAAAQZSPSVA. You are receiving this because you were mentioned.Message ID: @.***>

forrestguice commented 1 year ago

Incidentally the phone had been rebooted a few times since the alarms stopped working and it did not reset them.

That's not good to hear. The way I test BOOT_COMPLETED is by enabling an alarm within the next few hours (so the reminder is displayed), and then reboot the device. After a few minutes the scheduling service should finally get its turn and the reminder notification should reappear on its own.

I only dismissed the alarm via the notification once and so while that might have unscheduled that alarm it should not have affected the others.

You are right about that, it would only affect that one alarm. It indicates the problem isn't in that 'dismiss early' feature. I entertained that possibility because its relatively untested code.

I have now disabled battery optimisation, disabled and reenabled the alarms and will see what happens.

Fingers crossed. I think the OS is unscheduling your alarms so that should help. I'm guessing alarms worked the first week because the app was getting more use and hadn't yet been subject to aggressive 'optimization'. Similar to how my newer device keeps suggesting I uninstall apps I haven't opened recently - not helpful but annoying.

Re the notification I think it would be helpful if the message was 'Dismiss alarm' rather than just dismiss as unclear whether it was dismiss alarm or dismiss warning/notification.

Agreed this text should be changed. I was thinking 'Dismiss Early' on these reminders, and 'Dismiss' on the alarm notification itself.

Personally I don't feel a need for the notification for all the alarm types and so would be good if that was optional.

I'm guessing you mean an individual option for each alarm. I've been resistant to adding more options that require modifying the alarm database. Settings -> Alarms -> Reminder within -> Never will disable it for all alarms though. I'm thinking these reminders might include a 'settings' button to navigate directly to alarm settings. It would make configuring or disabling them easier. The app suffers from a lot of options that are poorly advertised.

Also when creating an alarm there is a tick icon to save what has been set.

That first dialog is 'event selection' - its tick just means proceed with the choice (usually to the edit alarm screen, but it might be to some other alarm app). That dialog gets displayed in a couple places in addition to the alarm's screen's + button. Its reused in the main app (Set Alarm), and from the edit alarm activity (Options -> Set Event, or clicking on that chip).

However when then making the subsequent settings or editing the alarm there is an icon of 2 ticks AND one of a save/floppy icon. What is the difference? Looks as if 2 ticks mean activate but 1 tick seems to mean 'apply' and then takes you to the final setup screen.

That's pretty much it. In the first scenario the alarm is disabled. The double tick means 'save and enable' and the floppy icon means 'save '. In the second scenario the alarm is already enabled so the floppy icon (with accent color) is 'save (and remain enabled), while the X icon is 'disable' (but also saves).

I think this entire two-step setup is a bit awkward (others have also commented), but an improvement over the initial version. There wasn't an 'edit screen' and modifications were made from the list itself (and required enabling as a separate step). It could probably use another redesign, but that's not something I anticipate doing soon.

Might be helpful of clicking those buttons brought up brief confirmation of action taken.

There should be tooltips already. It should be possible to press and hold each icon (and text should appear). That's an Android feature though, so maybe its not always available. I'm thinking the edit screen needs a help dialog though. A single sentence immediately next to each icon would go a long way.

I appreciate the feedback. It's hard to really examine things like UI and UX without fresh perspective.

forrestguice commented 1 year ago

Might be helpful of clicking those buttons brought up brief confirmation of action taken.

I somehow read this wrong the first time. You aren't referring to tooltips, but a confirmation dialog (with apply and cancel buttons). That would definitely clear up confusion. It also adds to the number of clicks needed to add/edit alarms, which is something I've been trying to reduce.

jackthebean commented 1 year ago

I was not suggesting a new apply or cancel popup. Rather just a brief message popping up saying 'Enabled' or 'Saved' or whatever. Rob

2 Oct 2022 19:32:25 Forrest Guice @.***>:

Might be helpful of clicking those buttons brought up brief confirmation of action taken.

I somehow read this wrong the first time. You aren't referring to tooltips, but a confirmation dialog (with apply and cancel buttons). That would definitely clear up confusion. It also adds to the number of clicks needed to add/edit alarms, which is something I've been trying to reduce.

— Reply to this email directly, view it on GitHub[https://github.com/forrestguice/SuntimesWidget/issues/628#issuecomment-1264705948], or unsubscribe[https://github.com/notifications/unsubscribe-auth/ACLSW3Q2UPXVEBMMMIIZ2BLWBHILRANCNFSM6AAAAAAQZSPSVA]. You are receiving this because you were mentioned.[Tracking image][https://github.com/notifications/beacon/ACLSW3U4CGCYVVJCPIRV6A3WBHILRA5CNFSM6AAAAAAQZSPSVCWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTSLMHQZY.gif]

forrestguice commented 1 year ago

Got it. We can do that. They call messages like those 'toasts' (for some reason).

jackthebean commented 1 year ago

Sorry, replied to the other message before seeing this one.

First of all thanks for the detailed and personal responses. Appreciate that but am still well aware that not all my requests will be actioned!

Don't think app was getting more use in that first week. I installed it weeks ago and had a good play then but just recently went in and set just those alarms and all seemed to work fine at first.

I would still not know what 'Dismiss early' meant. I would just suggest 'Dismiss alarm' on the notification.

How about a setting of just 0hrs and 0mins for the notification which would mean no notification at all. Then no extra button or step.

Would not want to set the notifications to global never personally as while I don't want it for the daily alarms it will be good for the less common ones such as equinox or solstice.

Checked for the tooltips just now and they work and are useful. Had never occurred to me to try a long touch.

Evening civil twilight one worked tonight and will let you know if still working in a week or so.

Great app and thanks for it. Always happy to try things out and give feedback.

Rob

jackthebean commented 1 year ago

The alarms have stopped again. Would be really good if this could be fixed as unreliable alarms are pretty useless. Would it be better if the alarms were written into the Calendar. Would only get a notification rather than an alarm?

jackthebean commented 1 year ago

Disabled and reenabled all the alarms and they started working again but stopped working after what seemed like the same amount of time/alarms as last time. About 3 days/6 alarms? Does that help?

jackthebean commented 1 year ago

Is it relevant that sometimes the alarms have, in Suntimes Alarms app, the name I thought I created them with ie the system entered "morning civil twilight (start)" and other times just shows as 'Alarm'? Screenshot_20221013_104656_com forrestguice suntimeswidget See attached.

forrestguice commented 1 year ago

Is it relevant that sometimes the alarms have, in Suntimes Alarms app, the name I thought I created them with ie the system entered "morning civil twilight (start)" and other times just shows as 'Alarm'?

If created from "Set Alarm" the alarms are assigned a label that is the same as the event. If created from the + button then "Alarm" or "Notification" is shown instead (until a label is set from the edit screen). I don't really like it, but it can be blamed on allowing "set alarm" to specify another app (where the label is both expected and useful).

Disabled and reenabled all the alarms and they started working again but stopped working after what seemed like the same amount of time/alarms as last time. About 3 days/6 alarms? Does that help?

Yes. Any observations you can make might be helpful. I appreciate this. I assume the device wasn't rebooted during this period.

The alarms have stopped again. Would be really good if this could be fixed as unreliable alarms are pretty useless.

I hear you. I don't have a solution at the moment, but effort will be made to fix this, and similar issues (recent comments on #494 report unreliable repeating moon phase alarms).

Would it be better if the alarms were written into the Calendar. Would only get a notification rather than an alarm?

You might have better luck assigning them to a Calendar event. In my own experience those aren't reliable either, but if they failed it wouldn't be a Suntimes issue (but it might provide some insight).

jackthebean commented 1 year ago

Sorry, can't be sure if phone rebooted or not in the ?3day/6 alarm working period. Think not however. Thanks,

forrestguice commented 1 year ago

I'm looking closely at https://dontkillmyapp.com/huawei. I think your device (Honor View 20) runs emui 10, so the solutions for emui 9+ might fix things. However, if your device is running this "PowerGenie" thing, it seems the only fix is to plug the phone in with a usb cable and then disable/uninstall it via adb.

Also, under Samsung devices I found the following (very familiar sounding) detail..

We record significantly increased number of app killing on Samsung’s since Android Pie flavor. The hints show adaptive battery being much more eager than in stock Android. After 3 days any unused app will not be able to start from background (e.g. alarms will not work anymore).

I'm curious how often the app itself is launched (either the "main" activity, or the "alarms" activity). Maybe periodically launching the app (or even just leaving it in the recent list) would extend the time period that alarms continue working.

jackthebean commented 1 year ago

I have made the changed recommended/discussed on your link in the section "App Launch on some EMUI 8, 9 and 10 devices (Huawei P20, Huawei P20 Lite, Huawei Mate 10…)" and will let you know what happened. After making those changes I disabled and reenabled the am and pm alarms.

jackthebean commented 1 year ago

Wondering if this issue is fixed. Think alarms have been OK since the last change to the settings. Might it be due to the last update? If so should I reverse those changes?

forrestguice commented 1 year ago

@jackthebean The issue remains afaik. The latest patch does fix a bug in the reboot code. I discovered that it was skipping alarms/notifications that were already "sounding" (so these were never rescheduled). I've been telling people a reboot should fix things, but that should actually be true now :\ After discovering that bug, I realized I could force items to become stale just by turning the device off with notifications still in the tray.

A device with aggressive battery optimization can still choose to kill the alarms (which are then in a similar state as above). The difference is these alarms should now recover after reboot. If your alarms are now reliable, it must have something to do with the battery optimization recommendations. I would keep those applied.

islam2hamy commented 1 year ago

Hi all ,

   Please add this permission

android.permission.REQUEST_IGNORE_BATTER>Y_OPTIMIZATIONS

I think it will help in that

@forrestguice

Originally posted by @islam2hamy in https://github.com/forrestguice/SuntimesWidget/issues/494#issuecomment-1255359025

@forrestguice could you please create a test apk with this permission , so we can test it and see if it fix this ?

islam2hamy commented 1 year ago

B.t.w. if the alarm type is 'notification' , it is work good with last release The problem now is with alarm type 'alarm'

forrestguice commented 1 year ago

could you please create a test apk with this permission , so we can test it and see if it fix this ?

@islam2hamy I doubt this will do anything, but there is no harm in trying. I've added a debug apk to #494.

islam2hamy commented 1 year ago

This is a "reminder notification" that should always appear within ~10 hours of an alarm (to change or disable Settings -> Alarms -> Reminder within).

How to disable "reminder notification" ?

forrestguice commented 1 year ago

@islam2hamy Settings -> Alarms -> Reminder within, then scroll the picker all the way past 1 to never.

jackthebean commented 1 year ago

BTW would be nice if there was this option for each alarm. In my case I don't want the reminder for daily alarms but useful for more rare ones.

Although can be useful way to see if alarm will actually alarm. But when that fixed....

And helpful if reminder could be dismissed without dismissing the alarm.

islam2hamy commented 1 year ago

Screenshot-com-forrestguice-suntimeswidget

Where ?

forrestguice commented 1 year ago

@islam2hamy hrm, good question.. It should be the very first entry. I'll see if I can figure out why its missing.

islam2hamy commented 1 year ago

B.t.w. if the alarm type is 'notification' , it is work good with last release The problem now is with alarm type 'alarm'

@forrestguice Sorry it is my mistake , It wasn't because of the alarm type 'alarm' , it is because of set alarm from "interval midpoints" and "natural hour" . And it is still not fixed #494

forrestguice commented 1 year ago

And helpful if reminder could be dismissed without dismissing the alarm.

@jackthebean It will be possible to swipe it away with v0.14.11.

jackthebean commented 1 year ago

Thanks for all the improvements.