Preventing timer manipulation from end user with a

2020-04-30 11:54发布

问题:

How can one ensure that a task that is supposed to run for x amount of time on an android os be run for that x period without user manipulation of date and time? For example, if I want this timer to run for 24 hours solid and then advise the user that 24h has passed, even if the phone is off for an hour, the user then turns it back on and sets the system time forward 2 hours, this timer would still indicate when that solid 24 hour period had passed without the user manipulating the system date/time and without connecting to the internet to verify the proper amount of time has passed.

Thanks

回答1:

Here is flow/algorithm.

1) You need to store time of timer first initiated some where, probably database and let timer run for 24 hours.
    a) assuming phone not turned off, timer continues
    b) Assuming phone turned off and turned on
        b1) Get initial timer started time from database, then calculate how much time left for 24 hours. 
        b2) Initiate timer again with left time.