-
-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug at AlarmScheduler#fireAlarmsInThePast #533
Comments
To elaborate a little bit more on the reasons why this bug may have risen... This is my guess... as to the reason WHY they chose to manage the Intent queue manually.... And so, the cache, called 'queue' in 'AlarmsScheduler.class' was created. Each time an alarm gets fired, this queue via the method replaceAlram() schedules the next Intent. The clear way would be to use a unique requestCode for each PendingIntent and erase this cache. BTW this project is how I learned about StateMachines and it is awesome design. I'll see if I can find an easy solution. |
Hello @Skylarkarms , thank you for writing the issue and for your PR. I am trying to understand the problem. Could you perhaps capture some logs for me? |
The way to capture the bug properly would be to, via reflection, read the PendingIntent queue inside AlarmManager, otherwise the only way is to trust in its only method Logs were giving null upon the onReceive() was being fired by an scheduled intent. This meant that the PendingIntents were overriding their place in the AlarmManager queue by using the same requestCode. Here is a small glance into the logs in this reddit post I made, in which I could positively confirmed that the IntentManager behind the AlarmManager is persisting the scheduled Intents upon App closing. This means that the queue inside the project's AlarmScheduler was not needed. and so, the bug fixes itself by getting rid of this queue. As I said, there must be a reason of the why that queue is being used, and I guess it's because this id persistence ability requires a different method of Intent scheduling for some Android version, that the code is not accounting for. the main bug discussed in this report can be repeated by enabling a sequence of alarms (any number) BUT the FIRST and LAST must have the same exact time, use a time proximate to current time. Of course, another alternative is changing the fireAlarmsInThePast() and allow the foreach consumer to fire JUST the alarms with repeating time, and not the ones in the middle. |
Context
There are multiple reasons for using a queue in
BugI assume the bug you are referring too occurs when the
Impact
|
Absolutely agree with the fact that the changes were too drastic, I thought the scheduler behavior made it seem as if the alarms were supposed to stack inside the Manager, what was really happening is that they were being pushed to the queue stack, and only the head was the one being appointed to the Manager. I don't know If I should maybe close this. but I'll still do. |
I am so sorry to bother you, I just want to let you know that this entire bug was my own fault. I went back to see my changes and I placed some faulty references in order to Log things and in the process, I messed with the while loop: This is so amateurish I am...
This means that my logged version was the one with the bug, not yours. Please I beg your pardon for my mistake... 🙏 |
Hey @Skylarkarms, thank you for clarifying this. I welcome discussions and contributions, so there is no need for excuses :) BTW, looking at my code here:
I can see that it definitely can benefit from a refactoring. It is hard to understand. If you want, you can try refactoring it and I will be glad to do a code review.
If you are interested, there are also many items here: https://github.com/users/yuriykulikov/projects/2 |
Hi @yuriykulikov Now that I think more clearly about this, the name of the field being "setter" I believe is self-explanatory. I don't think programming syntax and semantics needs to be easy in order for programmers to understand more easily, but even if we use easy-to-interpret words, these words would still be hiding complex behavior behind these systems. In this case the complexity relies in that the underlying Manager CAN handle scheduling, but because of the Android system's limitations... the project decided to hide it under a "setter" interface instead of an "addition/offering/scheduling/etc..." one. So, if we are not aware of this minutiae it becomes harder to catch up, even on the significance of the simplest of words such as "setter" since they are bound to their vast context just to be able to understand. This is why it is so difficult to make programming related questions (lol), but you immediately caught up on what I was missing. |
Description:
If a sequence of alarms is set AND as long as the FIRST and LAST alarms in the sequence have the exact same time... ALL ALARMS will be fired at once; once the time for one of BOTH (with the same time) to be fired finally arrives.
To Reproduce:
Given:
Set 3 alarms:
When:
Then
*Wait till the time comes...
Expected and observed behavior
fireAlarmsInThePast() Will check the first item at the queue:
queue.peek()
It will ask if it is before now:
.before(now)
It will return true since 2 of the alarms are set to the exact same time.... one of them is placed at the head of the queue.
By the time the second call arrives... the epochMillis will be set AFTER the call which will answer TRUE to the question: "Is this call supposed to be set in the past?", TRUE... because calls are not solved concurrently so the sequence of the second call may be late by a couple millis (This is my speculation of the why this method even exist...).
Finally, it will poll EVERYTHING and setter.fireNow() will set the alarm in the middle of the queue by accident.
I have no solution since I am yet to fully understand the architecture, one of the things I don't understand is why this queue is not being re-populated by alarms that where set before re-installing the app and opening it again.
Maybe this is a second possible bug. Maybe not since I am re-installing the app, but this is most likely a bug since the DB is not getting cleared, so it should be repopulated by the previous enabled alarms(?).
The text was updated successfully, but these errors were encountered: