Closed akostadinov closed 5 years ago
I think this feature is next to be developed. I've looked into different approaches and stopped short each time.
Alarms are currently set by intent via the AlarmClock - its a very limited interface that allows adding alarms (but not updating or removing them). I thought I could get notifications, offsets, repetition, and the other good stuff "for free" by scheduling through the Calendar instead. While testing a first draft of that I realized my phone (and almost every other Android phone) suffers from a Calendar notification bug that causes notification to randomly fail, Calendar alarms not to sound, etc. ...not a reliable way to wake up in the morning. ..so its back to the drawing board.
The other approach is to schedule alarms using AlarmManager. This is much more capable than using the AlarmClock intent, but there isn't a UI. Using it to its full potential essentially means implementing my own AlarmClock. That's something I wanted to avoid, but now it seems like its actually the easiest option.
Related: #140, #250
I assume it would be necessary because it will also prevent users messing up the alarms using the clock app UI. Calendar notification issues are a lot :/ I'm surprised Google doesn't take this more seriously.
I ended up writing an entire AlarmClock. Here's a link to the beta; https://github.com/forrestguice/SuntimesWidget_beta/releases/tag/v0.11.0-beta.1
@forrestguice , amazing! I just installed it and setup an alarm for one hour before sunrise every day. Lets see.
A few notes:
Please take my feedback in a very friendly way. I don't think any other app like suntimes exist and some UI imperfections can't make me less happy about it. It now has all the options and works very reliably so far. Thank you a lot for creating and maintaining this beautiful piece of software!
This morning it didn't ring. As soon as I turned on screen alarm started to sound. What I did is to remove app from the list of apps that can be killed in the background and will report how it works after a few days.
Thank you. This is good feedback. Agreed the current UI is hard to use. It could use some refinement. I was shooting for "functional", which leaves a lot of room for improvement.
I think a "shared" default location setting sounds like a good idea. Maybe call it the "Home" location, as an option in the drop-down alongside "current location" and "user defined".
Its a bummer that it didn't ring this morning. I am however reassured that it sounded once the device was awake. That seems like it might be an important clue. How were things testing up until then? No stuck notifications?
Thinking out loud.. I can think of a couple reasons why the alarm might not sound. It seems that maybe the process was killed at some point which killed the AlarmManager timeouts. Its also possible the device rebooted in the middle of the night (same effect). The timeouts are re-added on BOOT_COMPLETED
, but there is also a LOCKED_BOOT_COMPLETED
for Android 7.0+ that isn't handled. I think on those newer devices BOOT_COMPLETED
doesn't run until after the device is unlocked. That seems like a surefire way to miss the alarm. Another way to miss an alarm is to reboot minutes before it occurs - the BOOT_COMPLETED
code seems to lag by several minutes, by which time the alarm time has come and gone.. hrm. However in both those cases I think the alarm is just rescheduled, it doesn't sound immediately, its just missed. The fact it started to go off once the screen was turned on suggests the timeouts were still active but failed to wake the device, and once the device was awake they triggered immediately.
There are a lot of little details that need to come together. A lot that can go wrong. I'm a little hesitant to "put it out there" knowing it might not sound, or worse, sound at the wrong time.
Keep me posted on how things test.
First of all, I'm using Samsung Galaxy S9 dual sim with Android 8 (no update yet to 9 for me). I am also using scheduled do not disturb mode.
Besides whitelisting in power control, I also whitelisted Suntimes in do not disturb to no avail. But ATM I can't find where I did this and whether I only listed Suntimes or together with Suntimes Alarms. I am travelling atm and hopefully will have time to investigate soon. Also I can try turning off do not disturb mode just to make sure the issue comes from it or not.
As a little clarification, I just use the power button to turn screen on and alarm starts. No need to unlock or something. I don't think phone is restarting overnight because I would need to enter SIM card pin code on such occasion. Also recent apps would be gone.
Another thing is a menu option "DO NOT DISTURBED" -> "App rules". It is presently empty, not sure whether it can be useful in this situation somehow. I'll first try to make sure do not disturb mode has anything to do with this.
wrt central location setting, perhaps what you suggest "Home localtion" would work.
At this point I suspect "doze mode" or "deep sleep". I don't think the timeouts are waking the device up, but once it is awake they are expired and trigger immediately. Thats why everything seems to work fine when actively testing, but then fails when it matters. :\ It doesn't sound like the reboot or lockscreen issues (these are useful details), but I'm not sure about "do not disturb" - that's another detail I haven't even looked at.
Hopefully these docs describe the problem. It happens on Android 6.0+ when you schedule using setExact
(which is what I'm doing). Apparently I should be calling setExactAndAllowWhileIdle
instead.
I've discovered that I can trigger the sleep/doze mode manually using adb - I'll test this and see if I can't reproduce it everytime (and hopefully fix by changing a single method call, heh).
FYI turning off "do not disturb" did not help. Probably what you've got is the issue. If you can produce a test build with setExactAndAllowWhileIdle
I can try it out.
https://github.com/forrestguice/SuntimesWidget_beta/releases/tag/v0.11.0-beta.2
I'm not sure this actually fixes it. :\ I've had some trouble testing doze on the emulator (its not acting as expected). I think "snooze" is also broken in doze (or at least delayed to 15min increments).
There was a huge snow storm here (northern Arizona) these last few days, which is a rarity. I actually haven't spent much time debugging this yet - instead I built an igloo by making over 80 snow blocks using a sytrofoam cooler, heh. It is already starting to melt and won't last the week. Still worth it. :)
Installed and will report back in the following days.
Please send some pictures of the igloo! We have snow sometimes around here and will be fun to do this. We also got some snow but not enough to do anything meaningful.
Good news! It is indeed working now. I have listed app as "do not disturb" custom exception as well disabled power saving for it. But only with v0.11.0-beta.2
. The previous beta didn't work even though it had same settings.
Also the snooze button works as expected. When I touch it, it writes "snoozing for 10 minutes", then it rings exactly after 10 minutes. One interesting thing is that other notifications I can slide them left, then I see 2 buttons and I can snooze for a custom period with them. But this is really not important for me personally. I'd say that 10 minute snooze is the ideal setting on my end.
Now my two nit picks are that:
Thank you very much for writing this amazing app! I think it has everything I can think of in terms of functionality now. I don't think anything else can match it or even get close to it.
That's great news. I think it might ready for an initial release. Here's the latest build: https://github.com/forrestguice/SuntimesWidget_beta/releases/tag/v0.11.0-beta.3
Here's what's changed..
The screen should turn itself on now (but its tied to the fullscreen notification). I'm guessing it will still fail if the system decides to show a heads-up notification instead. It doesn't use a wakelock (which I want to avoid), so I don't think there is anything keeping the screen from going right back to sleep a minute later.
For api21+ it now calls setAlarmClock
to trigger the alarm itself (the remaining timeouts still use setExactAndAllowWhileIdle
). The reminder notification should now be much smaller / moved to its own area in the tray. That should help with the clutter while still allowing a reminder. The other notifications (ringing, snoozing, timed-out) are bound to a foreground service, which does keep the app from dying in the middle of an alarm, but the upcoming reminders don't use that mechanism.
Another benefit of setAlarmClock
is that doze should be interrupted even sooner (up to an hour before the alarm), and alarms within 15min of each other won't get grouped into a maintenance window. I think this a bug lurking in the v0.11.0-beta.2
. Suppose two notifications are set for 5-10 minutes of each other, the first will trigger on time, but the second will be pushed back 15min, thanks for battery optimization (that is apparently applied even when the app is white-listed). Supposing the app isn't on the whitelist then that first alarm might also be pushed back 15min. I've added something to the prefs to strongly suggest that the app be white-listed.
I think it should be possible to get consistent behavior across all devices if we use AlarmManagerCompat
, but that would require bumping the support library versions (which won't happen until after dropping support for api10) (#122).
https://www.flickr.com/gp/147180438@N05/X0G97P I've built a couple of these snow shelters now. Its got its own technique, "Arizona igloo", because there is so little to work with. I bet someone from an area with real snow would laugh.
This was definitely the largest one I've made (and also the fastest to melt). Its been really warm out. All that snow is practically gone.
I have tested beta 3. Old alarm didn't turn on screen. I removed it then created a new one. It also didin't turn on the screen. I think it is not important to keep screen on for more than a minute.
On the bright side I don't notice the notification bar any more, only the alarm icon in status bar. Which is really great.
I'd be happy to test other test builds if you have other ideas. Or if you are bored from this small detail on my end it is perfectly fine to use the app as it is atm.
Thanks again!
P.S. I'm really inspired to try building an iglu whenever I can find enough snow. Hopefully next winter.
One other small glitch I noticed:
Missing label for the checkbox when opening the alarm app. If I tap it, then labels show up.
No recent alarm failures, that is encouraging. I've tested and fixed some issues with older devices. Those devices also had trouble turning the screen on (but managed to get it working by adding some additional flags). I doubt the problem is resolved for newer devices.
I'm going to cut a release anyway. Its not perfect (but it never will be) - I think if I didn't resist perfectionist tendencies I'd probably never release anything. ;) I do anticipate a bunch of new items in the issue tracker, which is fine.
Thanks again!
You are very welcome. Thank you for helping me test. This was invaluable.
btw the glitch you noticed was intentional, but I'm rethinking that decision. When the list has a lot of items it looks very cluttered, so the labels are hidden until an alarm is selected. I can see how that might appear to be broken though.
For latest releases, does the screen turn itself on, or is this still an issue? It works when I test in the emulator (but that doesn't mean much). I want to open another issue if its still not working right.
Is version you ask me to try in f-droid now? I'm still on the beta and will need to remove it completely then install from f-droid. That's why trying to make sure it is already there :)
ahh, sorry for the confusion. The official release is now available on F-Droid - that version should be at v0.11.1.
Having to uninstall/reinstall is annoying I know. If I were to setup "reproducible builds" I could sign everything with my own key and the transition would be smooth, but making a reproducible android build actually seems really challenging. :\
I want to set a daily alarm for half an hour before sunrise. Presently I can set alarm for some event but not with an offset as well it is one-time alarm.