vicolo-dev / chrono

A modern and powerful clock, alarms, timer and stopwatch app for Android!
GNU General Public License v3.0
370 stars 15 forks source link

Alarm not ringing or ringing later than specified #183

Open Rafee-M opened 4 months ago

Rafee-M commented 4 months ago

Describe the bug The alarm seems to ring ~10 minutes late or doesn't ring at all sometimes

To Reproduce Steps to reproduce the behavior:

  1. Set an alarm more than 30 minutes away
  2. Wait

Expected behavior Ring at specified time

Smartphone Information

Additional context I had enabled foreground, background usage, turned off optimization, enabled auto launch. Still the alarm ringing is a hit or miss. In contast, I gave Simple Clock only foreground usage and it still seems to ring at specified times

Screenshots

Example 1: At 8:30 AM an alarm was set for 9:35 AM. It rang at 9:39 only after unlocking the phone and opening Chrono

Untssitled Untitled

Example 2: A notification for upcoming alarm at 11:15 AM (set at 10:30 AM) was receieved. But the alarm failed to ring. Opening the app also didn't make the alarm ring as well. Screenshot_2024-04-19-11-29-13-07

https://github.com/vicolo-dev/chrono/assets/69535896/43aac825-14e0-4826-ae0e-75e262609b9e

Battery settings for Chrono: (Simple Clock only had the Foreground activity enabled)

Untiasatled

AhsanSarwar45 commented 4 months ago

Have you tried everything listed here: https://dontkillmyapp.com/oneplus

And here: https://oneplus.gadgethacks.com/how-to/disable-setting-if-notifications-are-delayed-your-oneplus-0192639/

Especially the Advanced Optimization thing.

I don't own a OnePlus device but can you also make sure that 'Show on Lock Screen' or something similar and 'Show Fullscreen Notifications' or something similar is enabled for the app?

Rafee-M commented 4 months ago

Have you tried everything listed here: https://dontkillmyapp.com/oneplus

Pretty much

Especially the Advanced Optimization thing.

That is not a thing in current OxygenOS. The only settings related to battery is the one shown in the screenshot and also Special App Access > Battery Optimization.

I don't own a OnePlus device but can you also make sure that 'Show on Lock Screen' or something similar and 'Show Fullscreen Notifications' or something similar is enabled for the app?

Yeah it is. Besides, the alarm does show up on lock screen if it's set not too far long (~20 minutes?). Like I've mentioned I didn't face the same thing with Simple Clock. Maybe they're doing something extra to get the alarm go off?

Other battery settings:

Display over other apps: (Chrono doesn't show up here and Simple Clock was disabled as well

Special App Access > Battery Optimization:

Rafee-M commented 4 months ago

App Ops and Uses permissions of Simple Clock are given below. The only thing stood out to me was the "Start Foreground" option. And Chrono seems to have quite a bit more Uses permissions.

App Ops:

Uses Permissions:

AhsanSarwar45 commented 4 months ago

Thanks, I'll take a look what SimpleClock does differently. Also, when did this issue first started for you? After 0.4.0/0.4.1 update or before that?

Rafee-M commented 4 months ago

Also, when did this issue first started for you? After 0.4.0/0.4.1 update or before that?

I had some reliability issues as well, so that is why I was going back and forth between Chrono and Simple Clock.

Also, I have resolved the issue with the alarm by disabling the "Battery Optimization" option inside App Manager. Not sure what setting it enables/disables, but it does use root permissions. For now, the issue seems to have been resolved for me. Feel free to close it! Also, there seems to be an issue with the timer as well. I'll try to do some more testing and create a new issue.

The App Manager option:

https://github.com/vicolo-dev/chrono/assets/69535896/92d6aefc-d709-43de-a3ac-c56d8b7cb4f5

jfmcbrayer commented 4 months ago

I have this same behavior on a Moto G7 running LineageOS, I'm afraid. It only started happening after upgrading from LineageOS 20 (Android 13) to LineageOS 21 (Android 14). Battery optimization is off, and notifications are on.

What specifically happens is that the alarm does not go off at all, but the upcoming alarm notification is shown. The alarm does not go off after opening the app.

I don't know if this will help - Android 14 seems to have broken a lot of things that use background processing for me, from alarms to offline music players.

AhsanSarwar45 commented 4 months ago

I don't know if this will help - Android 14 seems to have broken a lot of things that use background processing for me, from alarms to offline music players.

Don't have a real Android 14 device at the moment but I've tested it on a stock android 14 emulator, and it works well there. So probably a real device specific optimization.

aronovgj commented 4 months ago

I had this happen on my Pixel 7 pro. Did not happen before 0.4.0. I disabled battery optimization in app manager, will see if that helps. Though I had it disabled anyway.

aronovgj commented 4 months ago

The alarm didn't go off 3 nights in a row. It works after not touching the phone for about half an hour. Tinkering with app manager did not help. Trying to figure out if the issue is connected with turning on rising volume.

AhsanSarwar45 commented 4 months ago

I mentioned it in another issue, but will also mention it here. I am currently looking at adding a foreground service (optional in the settings), which will show a peristent notification and hopefully prevent the app from being killed. It will help in fixing alarm reliability issues.

Also, if possible, can you guys run the benchmark in DontKillMyApp from the app store and report the results?

It would also be helpful if you guys can suggest opensource apps that work correctly in the background on your devices, and whether they do it through a persistent notification (foreground service).

jfmcbrayer commented 4 months ago

I think the apps I have that are not having problems with being killed on Android 14 all have foreground services (and thus persistent notifications). I'm talking about music apps here, though, not clock apps. The only other clock app I have tried is LineageOS stock, which rings, but only silently.

aronovgj commented 4 months ago

Don't kill my app returns 100%.

K9 Mail runs well on my phone. I think it also uses a foreground service.

I deleted the old alarm that was failing and created a new one without rising volume and alarm worked this morning. Might be luck. Not sure.

jfmcbrayer commented 4 months ago

On my device, DontKillMyApp returns 100%.

I also created an alarm without rising volume after I saw the previous comment this morning, and it worked correctly (my phone had been asleep for about an hour). The same thing fixes the silent alarms on the stock LineageOS/AOSP clock, so I'm guessing this is an exception that is being handled differently by the two clocks.

AhsanSarwar45 commented 4 months ago

I deleted the old alarm that was failing and created a new one without rising volume and alarm worked this morning. Might be luck. Not sure.

If you turn on rising volume, and create an instant alarm (which rings after 5 second, button can be turned on through settings -> developers options -> show instant alarm button), does the alarm still not work?

aronovgj commented 4 months ago

Turn on rising volume where? Do I set it in default settings or do I create an alarm first?

I turned it on in the default settings and it works with instant alarm. It just fails after not touching it for a longer time. As already mentioned, after about one hour it still works but after a whole night it doesn't. But there is a notification showing that the alarm rang. It is like the app fails to increase the volume.

Rafee-M commented 4 months ago

It would also be helpful if you guys can suggest opensource apps that work correctly

  1. Simple Clock
  2. Fairemail (uses persistent notification)
  3. tasks.org (Reminders)

Note: As of now the alarm and timers (except timer notification) has been working flawlessly after the App Manager setting

jfmcbrayer commented 4 months ago

Instant alarm with rising volume works for me. Overnight with rising volume does not.

jfmcbrayer commented 4 months ago

And I'm afraid I spoke too soon. Even with rising volume turned off, my alarms have failed to go off for the last two days. So I think these are separate problems that are interacting with each other.

aronovgj commented 4 months ago

After like two weeks it failed again for me

TheLastZombie commented 4 months ago

This is a complete shot in the dark, but if you open the Android system settings and go to Apps → Special app access (might be located somewhere else on non-stock Android ROMs) there's a permission called Alarms and reminders, with the following description:

ResizedImage_Screenshot_20240509-080008(1344)x(579)2024-05-09_08-00-21_4398

Maybe Chrono needs to request this permission? It currently doesn't.

theotheroracle commented 4 months ago

also having this issue on lineage android 14, on a oneplus 6, battery optimization disabled

Rafee-M commented 4 months ago

go to Apps → Special app access (might be located somewhere else on non-stock Android ROMs)

Not available on OxygenOS 13

AhsanSarwar45 commented 3 months ago

This is a complete shot in the dark, but if you open the Android system settings and go to Apps → Special app access (might be located somewhere else on non-stock Android ROMs) there's a permission called Alarms and reminders, with the following description:

ResizedImage_Screenshot_20240509-080008(1344)x(579)2024-05-09_08-00-21_4398

Maybe Chrono needs to request this permission? It currently doesn't.

I think this refers to the SCHEDULE_EXACT_ALARM permission, which is only required for apps that aren't alarm clock apps. For alarm clock apps, this permission isn't needed and we instead use USE_EXACT_ALARM which is granted automatically by the system. Anyhow, if setting an alarm 1 minute into the future rings correctly, this likely isn't the issue in your case.

AhsanSarwar45 commented 3 months ago

Just a bit of update, all my current research does lead to this being a battery optimization issue specific to some roms, which would need either a foreground service, or something else that I'm not aware of, to work correctly. I've planned out how the foreground service will be implemented. Currently finishing up the 0.5.0 version which brings widgets and localization and language support. After that, all my focus will be on implementing foreground service and fixing this issue.

jgilmore commented 3 months ago

There's an open source clock/alarm app that works at here Apache 2.0 licensed. Might want to look at what they're doing?

Yes, I'm having these issues. Tried everything that "don't kill my app" recommends. And the test returns 100%. Alarms almost never work. Neither do timers. On a moto stylus 4G 2021 running android 11.

So I'm using "Clock" now.

TBat commented 3 months ago

Getting this same problem on my Pixel 6,running GrapheneOS on Android 14. Chrono App version is 0.4.2

Timers won't go off after the screen times out. I can see the notification icon on the lock screen, but it won't ring with the fullscreen alert until I unlock my phone.

STVGecko commented 3 months ago

This is a continuation of the #286


Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

I don't know why, alarms often don't go off, usually when they're close by.

Describe the solution you'd like On several other alarm applications, it is possible to define an application as "alarm and reminder" in "special access" (see photo below).

It says:

"Alarms and reminders

Allow this application to set alarms and schedule actions at certain times. It will then run in the background, which can battery.

If authorisation is disabled, existing alarms and events alarms and events programmed by the the app will not work."

334299083-be69bfa0-10da-44f8-9554-be29b329cbc2

Off-topic: do you know how to reduce the size of photos on github for this type of issues ?

joedavid0 commented 2 months ago

I have also encountered this issue on my Pixel 8 with GrapheneOS. Already two times this week, the alarm did not go off at all

AhsanSarwar45 commented 2 months ago

Hi everyone. I have added option to enable foreground notification in v0.5.2-beta1. You can turn it one by going to Settings > General > Reliability > Show Foreground Notification. Please try it and let me know if it helps in any ways.

Also let me know if you experience increased battery consumption by turning on foreground notification (compared to having it off). A little bit increase is expected, but too much increase will be an issue so I will try dialing down the frequency in that case.

I have also added another alarm permission. The docs said it is not needed on newer android versions so I had disabled it on new Android versions previously, but I have re-enabled it now, because why not. It might also help.

AhsanSarwar45 commented 2 months ago

Not sure if this will fix issue on devices where alarm does not ring after screens time out. Let me know if thats the case.

STVGecko commented 2 months ago

Hi everyone. I have added option to enable foreground notification in v0.5.2-beta1. You can turn it one by going to Settings > General > Reliability > Show Foreground Notification. Please try it and let me know if it helps in any ways.

Also let me know if you experience increased battery consumption by turning on foreground notification (compared to having it off). A little bit increase is expected, but too much increase will be an issue so I will try dialing down the frequency in that case.

I have also added another alarm permission. The docs said it is not needed on newer android versions so I had disabled it on new Android versions previously, but I have re-enabled it now, because why not. It might also help.

Hello, having tested the application thoroughly, I'm starting to get some answers about the alarms that don't ring or "later than specified".

First of all, you need to know that if you activate the "Rising Volume" option in Settings > Alarm >Default Settings > Sound & Vibration > More > Rising Volume, the alarm sounds progressively, as its name suggests. As a result, there is a risk that the alarm will not be heard.

Then there's the 'Audio Channel' option (same path as above), which I recommend setting to 'alarm' so that you don't unintentionally deactivate it.

Finally, it's good to know that the "Vibration" option (same path as above) works even if you activate the hidden android option "Sensor off". https://www.guidingtech.com/turn-off-android-phone-sensors/

I hope these setting tips help. My phone is a Samsung S22.

aronovgj commented 2 months ago

Little bit confused about the service notification. In other apps I am used to being able to deactivate the notification while the service still keeps running so that the notification isn't there all the time. I deactivated the notification and the alarm did not go off. But it sounds like the notification itself is supposed to stop the issue instead of a service?

AhsanSarwar45 commented 2 months ago

Little bit confused about the service notification. In other apps I am used to being able to deactivate the notification while the service still keeps running so that the notification isn't there all the time. I deactivated the notification and the alarm did not go off. But it sounds like the notification itself is supposed to stop the issue instead of a service?

Can you give examples of apps where this is possible? Because as far as I am aware, Android doesn't allow any foreground service to run without the notification itself because it would defeat the entire purpose of this functionality.

aronovgj commented 2 months ago

Little bit confused about the service notification. In other apps I am used to being able to deactivate the notification while the service still keeps running so that the notification isn't there all the time. I deactivated the notification and the alarm did not go off. But it sounds like the notification itself is supposed to stop the issue instead of a service?

Can you give examples of apps where this is possible? Because as far as I am aware, Android doesn't allow any foreground service to run without the notification itself because it would defeat the entire purpose of this functionality.

Yes, one example is K9. It was rewritten some time ago and they had issues with it syncing in background until they introduced the push service. It still works with notification off. Here are their docs regarding this push notification and how to disable it. Below they have a paragraph explaining that you can disable push. So disabling the notification is definitely not the same as disabling the service.

https://docs.k9mail.app/en/6.400/settings/push/#notification

aronovgj commented 2 months ago

Alarm didn't go off with notification turned on either.

jfmcbrayer commented 2 months ago

I'm sorry to say that it didn't go off for me, either. I gave it a couple of days to be sure.

aronovgj commented 2 months ago

https://github.com/yuriykulikov/AlarmClock

This one works for me too reliably. I think it doesn't even use a foreground service.

AhsanSarwar45 commented 1 month ago

Unfortunately, its currently not entirely possible for me to see exactly whats causing this, as none of the devices I own are able to reproduce it. If anyone facing the issue is comfortable with doing dev on flutter and android, that would be appreciated.

theotheroracle commented 1 month ago

I'm familiar with flutter Dev and have an affected device, how can I help ?

AhsanSarwar45 commented 1 month ago

I'm familiar with flutter Dev and have an affected device, how can I help ?

Sorry for the late reply. Its a pretty involved process where you will have to debug what's causing it to not ring on your device. Whether its because of the alarm isolate failing to trigger on time, or not triggering at all, or throwing some other error. You can use flutter logs and observe the logs at the time the alarm was supposed to ring. You can also check the source code of other such apps that are working on your device, and try seeing what they are doing differently, difference in permissions, services etc, and then trying to add those permissions to Chrono to see whether it makes a difference.

mtalexan commented 1 month ago

I'm having the same problem on a Pixel Fold running CalyxOS.

After the Android 14 upgrade, a lot of my apps started having problems like this, whether I was using Stock ROM, GrapheneOS, or CalyxOS.

I'm having trouble finding the official reference, but I believe Android 14 introduced a massive change to battery optimization and background apps. There used to be a radio button for users to pick between three options: off, optimized, and unoptimized. As of Android 14, I believe they say "unoptimized" is now no longer an option, there's only a toggle to pick between the former "off" and "optimized".
Associated with this change, they added some exceptions though. Certain behaviors can cause the "optimized" state be treated like "unoptimized" for that app, but I don't remember exactly what was included. The one key behavior they did mention was foreground notifications, but they changed how even those qualified. I believe minimum priority persistent notifications no longer qualify.

So if I'm not mistaken, I believe Android 14 rules are now that you need a foreground service with a persistent notification at non-minimum priority, and the user is free to modify that notification to set it to be silent and configure all their persistent silent notifications to be minimized if they don't want it visible in the status bar at all times.

STVGecko commented 1 month ago

I think I've solved part of the problem!

My alarm didn't go off either, specifically around 7, 8 or even 9 o'clock. In my case, I had an alarm set for 8.14am that wasn't ringing.

In fact I've realised that my alarms only go off if their "type" is set to "Daily" and not "On Specified week days".

As you'll see from the attached photos, I've set the alarm to 7.34am so that it sounds on Mondays, Tuesdays, Wednesdays, Thursdays and Fridays. However, the alarm doesn't sound on these days and displays a notification which, as mentioned in a previous comment.

@Rafee-M :

A notification for upcoming alarm at 11:15 AM (set at 10:30 AM) was receieved. But the alarm failed to ring. Opening the app also didn't make the alarm ring as well.

Here's how I solved the problem:

-click on the problematic alarm/ringtone -Schedule>Type>Click on the arrow -Select "Daily"

1

2

3

-> as a result, the alarm sounds (I've managed to sound an alarm at 7.34am, 8.24am and 10am.

When in doubt, I also recommend activating the alarm's "vibration" function.

It's also good to know that the "on specific dates" type works.

Don't hesitate to try this method on your own, in the hope that it will help you. Have a nice day :)

mtalexan commented 1 month ago

I wouldn't call that a solution (use "Daily" instead of "Specific Days"), but it does narrow down the problem.

I can confirm all my alarms were for Specific Days as well. My Alarm Logs show that the alarms were scheduled, and were rescheduled if I rebooted. Rebooting only a couple hours before the Specific Days alarm is supposed to ring still doesn't solve the problem though, even though the logs show it rescheduling the upcoming alarm at boot.

aronovgj commented 4 weeks ago

I can confirm that it seems to work OK for daily but not for specific days. Alarms are not going off at the set time exactly but it seems to go off like half a minute too late. Which is good enough for me.