jensstein / oandbackup

backup manager for android
Other
539 stars 193 forks source link

Fix scheduled backups being run at wrong times #197

Closed nikwen closed 6 years ago

nikwen commented 6 years ago

Fixes #132 and #159

132 and #159, which are both the same issue, consist of two sub-issues, each of which is fixed by a separate commit in this PR for readability.

Commit 1: Remove unnecessary and buggy else-if in BootReceiver#onReceive()

Description of the bug (reffering to the code before this commit):

Let's say a backup is scheduled for 2am and repeatTime is 1 day. Let's say the backup runs properly at 2am and the device reboots at 8am. Then the BootReceiver#onReceive() method will be run and timeLeft will be greater than 15 minutes and smaller than 24 hours, so the code in the else-if will be executed. As hourOfDay is negative (value is -6 hours), another backup will be scheduled to be run in 15 minutes, which is not needed, and (which will be fixed by commit 2) it will be run at the same wrong time again the next day since it has repeat set to AlarmManager.INTERVAL_DAY.

Description of the fix:

After removing the else-if, backups will be scheduled to be run 15 minutes after boot if they haven't been run yet (e.g. because the device was turned off), or it will simply schedule a backup at the proper time in the future if they have already been run.

Commit 2: Fix the time at which the backup will be run the next time in ScheduleService#onStartCommand()

Description of the bug (reffering to the code before this commit):

If a backup is scheduled in BootReceiver#onReceive() to be run after 15 minutes, it will repeat at the same time in the future instead of at the time which the user specified for the backup.

Description of the fix:

We fix the time at which the backup will be run the next time in ScheduleService#onStartCommand().

jensstein commented 6 years ago

thank you so much for the contribution and the very thorough descriptions of your commits :)

nikwen commented 6 years ago

@jensstein Thank you for reviewing and merging the pull request. :) Also thanks for tagging a new version. :)