Clock icon indicating copy to clipboard operation
Clock copied to clipboard

Timer will continue to run if it is set to less than 5 seconds.

Open quadratz opened this issue 3 years ago • 27 comments

Steps to reproduce:

  1. Set timer to less than 5 seconds and click Start.
  2. The timer exceeds the applied limit (resulting in a negative value).
  3. The timer always stops and ringing at exactly the 5th second, regardless of the setting.

Expectation:

  • The timer should stop and sound at the exact time set.

quadratz avatar Feb 06 '22 11:02 quadratz

I also made some tests, I find the same error as you. I am currently unable to find the solution.

qw123wh avatar Feb 06 '22 12:02 qw123wh

can you assign me ?

GokhanKabar avatar Feb 07 '22 13:02 GokhanKabar

Hi @qw123wh @CikiMomogi , i am interested by the issue , i would like to know if you are still active on the project because i can fin a solution . Thank you

Aladin056 avatar Feb 07 '22 13:02 Aladin056

@GokhanKabar @Aladin056 the project is active, if you can solve the issue of pull requests, I will then join them to the main branch. I am looking for collaborators for this project, I have some nice ideas to make this app even more functional. Your help is greatly appreciated

qw123wh avatar Feb 07 '22 17:02 qw123wh

Impossible to find the cause... 😭

BlackyHawky avatar May 19 '24 12:05 BlackyHawky

I test the app and i have some notes:

The timer will continue counting negative (when foreground or background) if set to 1 or 2 secs. When reaching -4 or higher, it will ring and sound only if in foreground, otherwise will continue counting negative.

ghost avatar May 28 '24 21:05 ghost

I test the app and i have some notes:

The timer will continue counting negative (when foreground or background) if set to 1 or 2 secs. When reaching -4 or higher, it will ring and sound only if in foreground, otherwise will continue counting negative.

I've also noticed this, but I can't find the part of the code that causes this bad behavior.

Note: it seems to be the same on the LineageOS clock application.

BlackyHawky avatar May 28 '24 21:05 BlackyHawky

No, @BlackyHawky

I have another phone (with LineageOS 18.1 -Android 11- on it), and this problem is not found in the Clock app, except when you set the timer for 1 second (i think because the 1 sec. timer is very low or small to handle correctly)

ghost avatar May 29 '24 09:05 ghost

@MaroEldawwy6 Check out the video below; this is the application compiled from the official LineageOS repository.

It'll confirm what I've said...

Watch video

https://github.com/BlackyHawky/Clock/assets/139015663/f458393e-6947-4c89-8480-1ce3d36bdeec

BlackyHawky avatar May 29 '24 19:05 BlackyHawky

@BlackyHawky I found the solution,

https://github.com/botxxxx/lib-com.android.deskclock/commit/5f19c681d835959ffea71274408ffcf315f7592e

I tested it on the old AOSP clock, the first on the repository that I haven't updated for 3 years; the changes of TimerItemFragment.java works. Now see if you can adapt this to the new code, since the TimerItemFragment.java file no longer exists

qw123wh avatar May 31 '24 18:05 qw123wh

@qw123wh You are magic !!!! 🎉🎉 It's an excellent search that unfortunately only works if the application remains in the foreground.

Did you find the same thing?

BlackyHawky avatar May 31 '24 18:05 BlackyHawky

@BlackyHawky Yes same problem, I didn't notice it. Partially resolved.

Create a branch with the modification, then we may find some solution to solve it completely

qw123wh avatar May 31 '24 20:05 qw123wh

Create a branch with the modification, then we may find some solution to solve it completely

Or simply include the modification that works and change the title of this issue.

@Nilsu11 It seems to me that you use or have used Omniclock. Am I right? If so, can you confirm that everything works on this app? Do you have the source of the repository?

BlackyHawky avatar Jun 03 '24 14:06 BlackyHawky

Yes, I used it. In Omniclock the issue also exists.

@BlackyHawky LineageOS deskclock has fixed it!! (little delay after time's up the ringtone plays)

Nilsu11 avatar Jun 03 '24 15:06 Nilsu11

LineageOS deskclock has fixed it!! (little delay after time's up the ringtone plays)

@Nilsu11 I hadn't seen that you'd updated your comment.

Where did you find the fix?

I'm using a version compiled from the official repository for testing and the bug is still there.

BlackyHawky avatar Jun 07 '24 03:06 BlackyHawky

I'm using an official Lineageos build. On my phone it works.

Nilsu11 avatar Jun 07 '24 04:06 Nilsu11

I'm using an official Lineageos build. On my phone it works.

Can you tell me what version of the app it is? ( Even if I'm not sure it helps... )

BlackyHawky avatar Jun 07 '24 20:06 BlackyHawky

I'm using an official Lineageos build. On my phone it works.

Can you tell me what version of the app it is? ( Even if I'm not sure it helps... )

21-20240527-NIGHTLY-oriole App version it tells me 14.

Nilsu11 avatar Jun 08 '24 08:06 Nilsu11

@Nilsu11 extract the apk from your phone and send it here so we can test it too.

odmfl avatar Jun 08 '24 08:06 odmfl

DeskClock.apk.zip

Nilsu11 avatar Jun 08 '24 09:06 Nilsu11

DeskClock.apk.zip

@Nilsu11 I tested the apk I always have the same problem, if you set 3 seconds it sounds at -2.

odmfl avatar Jun 08 '24 09:06 odmfl

@odmfl @BlackyHawky It's now fixed in OmniClock

Nilsu11 avatar Jun 08 '24 14:06 Nilsu11

@Nilsu11 Does this work when the app is minimized and with the screen off?

Here, the file you modified in Omniclock was modified in 2016 with commit f4c174d... 😅

BlackyHawky avatar Jun 08 '24 16:06 BlackyHawky

@BlackyHawky Yes it works. I mean something like this commit. This change should do something similar like the one from before. I used the TimerReceiver just as central point, where the message, that the timer starts is delivered. In OmniClock there sadly isn't a void to do this but just the TimerReceiver. I didn't check it on Android Studio nor compile it. This is just to visualize, what I mean.

Nilsu11 avatar Jun 08 '24 18:06 Nilsu11

Unfortunately it only works if you don't pause the timer.

Steps to reproduce:

  • set timer to 3 seconds;
  • press pause and wait;
  • the timer alarm will trigger while it is paused.

In any case, it seems that you are not far from the solution!

BlackyHawky avatar Jun 08 '24 22:06 BlackyHawky

@BlackyHawky If you put an if clause into the place, where the state is set to timer expire, to check the state the timer can expire from, this issue should be resolved (Hopefully you know what I mean).

I will demonstrate this in OmniClock, but it will have to wait for another commit I am currently working on (This will take a week or two).

Nilsu11 avatar Jun 11 '24 19:06 Nilsu11

(Hopefully you know what I mean).

No I don't. 😅

...but it will have to wait for another commit I am currently working on (This will take a week or two).

This issue was created over 2 years ago, so we're in no hurry. 😉

BlackyHawky avatar Jun 16 '24 16:06 BlackyHawky

@BlackyHawky Can you try replacing the if else clause here with this?

if (nextExpiringTimer == null) {
    // Cancel the existing timer expiration callback.
    final PendingIntent pi = PendingIntent.getService(mContext,
                    0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_NO_CREATE | PendingIntent.FLAG_IMMUTABLE);
    if (pi != null) {
        mAlarmManager.cancel(pi);
        pi.cancel();
    }
} else if (nextExpiringTimer.getRemainingTime() < 5) {
    startService(intent);
} else if (nextExpiringTimer.getRemainingTime() < 5000) {
    new Handler().postDelayed(new Runnable() {
        public void run () {
            updateAlarmManager();
        }
    }, nextExpiringTimer.getRemainingTime());
} else {
    // Update the existing timer expiration callback.
    final PendingIntent pi = PendingIntent.getService(mContext,
                    0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
    schedulePendingIntent(mAlarmManager, nextExpiringTimer.getExpirationTime(), pi);
}

Nilsu11 avatar Sep 06 '24 04:09 Nilsu11

@Nilsu11 I've tested it but it doesn't work properly when the application is reduced.

Moreover, a long value is missing to apply the new Handler function ; perhaps I should set the value to nextExpiringTimer.getRemainingTime() ?

Then, are you sure about nextExpiringTimer.getRemainingTime() < 5 and nextExpiringTimer.getRemainingTime() < 5000 ? Why are these values different?

Finally, should i apply this commit as well?

BlackyHawky avatar Sep 07 '24 14:09 BlackyHawky

@BlackyHawky Sorry, yes, I forgot you are right the long value should be nextExpiringTimer.getRemainingTime()

As for the different values the 5 is for 5 ms. It actually should be 0 but for good measure I used 5. It shouldn't make a difference. The purpose is to start the timer service directly if the time is below 5ms. Before one would have waited 5 seconds when the time is already up. The 5000 is because of the delay of the AlarmManager necessary which should trigger the method again to check if there still is time's up status or not.

No, it's either one or the other. The solution to the timer problem is looking if there is a timer to expire at the remaining time if it is under 5 seconds (min. delay when using alarmManager to trigger something).

Nilsu11 avatar Sep 07 '24 15:09 Nilsu11