×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    Regular Contributor
    Join Date
    Dec 2012
    Posts
    66

    Timer independent of system time even in background and offline mode

    I have a functionality of disabling the app for 30 mins if user enters passcode wrong three times. So what i did was start a timer when this happens and write [current system time] and [timer elapsed time] while closing app. On app resume and add difference between previously written [current system time] and [current system time] to [timer elapsed time]. Now if [timer elapsed time] is greater than 30 mins enable app else start timer with remaining time.

    The problem with above implementation is it gets completely messed up the moment user changes system time, speciall to some past time. So to be independent of user actions i want to make this feature system time independent. I cannot use network time since phone may or maynot be connected to network. Also need to taken care of time elapsed when app is closed.
    I saw few apps doing this, for example Real Football 2013.

    I am sure someone out here know how to achieve this.

    Regards,
    Vinay

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,737

    Re: Timer independent of system time even in background and offline mode

    Such thing doubtfully exists. If your application works in offline mode, it can not reliably detect user tampering with the clock.
    I saw few apps doing this, for example Real Football 2013.
    I do not know that app, but it can not do magic. Even if it leaves some fake background task in the memory, that can be killed with restarting the device, then you can set the clock to anything, start the app, and it has no means to detect your (wrong)doings. All of this in offline mode of course.

  3. #3
    Nokia Developer Champion
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    297

    Re: Timer independent of system time even in background and offline mode

    why don't you store the "DateTime.Now" in the IsolationStorageSettings, and check it directly in your Timer
    Code:
    settings["TimeBlocked"] = DateTime.Now;
    then in you timer's event
    Code:
    var timeElapsed = (settings["TimeBlocked"] as DateTime)- DateTime.Now;
    when the timeElapsed is superior to 30min, stop the timer, allow the connexion, and set the TimeBlocked to null.
    like this even if your app is closed it still exist in the settings, each time you open it, check if TimeBlocked is null, if it's not null check if the timeElapsed is superior to 30min, if not, set the timer to check every second.

    hope it helps
    Yassine,

  4. #4
    Regular Contributor
    Join Date
    Dec 2012
    Posts
    66

    Re: Timer independent of system time even in background and offline mode

    Hi wizard_hu_,
    Quote Originally Posted by wizard_hu_ View Post
    Such thing doubtfully exists. If your application works in offline mode, it can not reliably detect user tampering with the clock.I do not know that app, but it can not do magic. Even if it leaves some fake background task in the memory, that can be killed with restarting the device, then you can set the clock to anything, start the app, and it has no means to detect your (wrong)doings. All of this in offline mode of course.
    I have tried these scenarios with the app. After reading your post i again gave it a try. Steps i followed was:
    1. Enable flight mode. Timer reading are 1:22:50. Wait for say 2-3 minutes.
    2. Switch off device. Keep it off for 10 minutes.
    3. Switch on device.
    4. Change time to some future date.
    5. Start the app (Real football 2013)

    Voila.! Timer displays 1:18:04. which actually should have been close to 1:12:00 I guess it did not considers the time phone was off.

    Also it is not using periodic task. I can say this considering below observations.
    1. Open game and timer is 00:58:03
    2. Close app. Wait for 5-6 mins.
    3. Change time to some future date.
    4. Open game again and timer is 00:44:32

    If it would have been using periodic agents. Timer can at max update every 30 mins. And i am sure ResourceIntensiveAgents do not run on windows phone device yet.

    By the way its a XNA app, a game more precisely. Its from Gameloft. So are there any possibilities of the game using some custom made API's by Microsoft specifically for this game or maybe they got special permission for executing some functions in background..??


    Note: All the above tests were made with flight and battery saver mode on.

    Regards,
    Vinay
    Last edited by vinayppatil; 2013-04-05 at 06:01.

  5. #5
    Regular Contributor
    Join Date
    Dec 2012
    Posts
    66

    Re: Timer independent of system time even in background and offline mode

    Hi Yassine,
    Quote Originally Posted by Loukt View Post
    why don't you store the "DateTime.Now" in the IsolationStorageSettings, and check it directly in your Timer
    Code:
    settings["TimeBlocked"] = DateTime.Now;
    then in you timer's event
    Code:
    var timeElapsed = (settings["TimeBlocked"] as DateTime)- DateTime.Now;
    when the timeElapsed is superior to 30min, stop the timer, allow the connexion, and set the TimeBlocked to null.
    like this even if your app is closed it still exist in the settings, each time you open it, check if TimeBlocked is null, if it's not null check if the timeElapsed is superior to 30min, if not, set the timer to check every second.

    hope it helps
    Yassine,
    Basically what i need is "Timer independent of system time" but i guess the implementation you suggested is system time dependent. It will go wrong after user changes system time. Please correct if i am wrong.

    Regards,
    Vinay

  6. #6
    Nokia Developer Champion
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    297

    Re: Timer independent of system time even in background and offline mode

    Yes you're right,
    a work arround would be getting time from server when you block the acces for 30min, storing it in the settings, then put a timeElapsed (as timespan) which your going to inscrease in the timer event. now if the user get back to the app, again your going to check if TimeBocked is null, if not, you get the time for server and compare if it's over than 30min, if not you set the timeElapsed to the difference between TimeBlocked and server Time, and start increasing it in the timer event again.

    Yassine,

  7. #7
    Regular Contributor
    Join Date
    Dec 2012
    Posts
    66

    Re: Timer independent of system time even in background and offline mode

    Hi Yassine,

    Quote Originally Posted by Loukt View Post
    Yes you're right,
    a work arround would be getting time from server when you block the acces for 30min, storing it in the settings, then put a timeElapsed (as timespan) which your going to inscrease in the timer event. now if the user get back to the app, again your going to check if TimeBocked is null, if not, you get the time for server and compare if it's over than 30min, if not you set the timeElapsed to the difference between TimeBlocked and server Time, and start increasing it in the timer event again.

    Yassine,
    In that case offline mode wont work right? Look at the post tile "Timer independent of system time even in background and offline mode".

    Regards,
    Vinay

  8. #8
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    517

    Re: Timer independent of system time even in background and offline mode

    Basically you have only two sources of time: either a server or the local time. No way around that. If your user runs the App and it gets blocked for 30 minutes and he exits your App and changes the system time to > 30 minutes into the future the App can't detect it in offline mode and can only assume that the time has elapsed. If they change the time to something prior to the lock date you can detect that because it will give you a negative number and you can block access in that case too.

    But having any kind of background timer can't be done on the Windows Phone platform and I believe you would be hard pressed to get something like this to work even on less constrained platforms like Android or Desktop Windows.

  9. #9
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,737

    Re: Timer independent of system time even in background and offline mode

    What you are describing is very simple: the timer is running only when the application is running. When it started from 1:22, and you waited a couple minutes, that may have been a bit more than 2-3, like 4. and 1:22-0:04 is 1:18. And the 10-minute power off time, and set-the-time-ahead do not matter at all, since the application was not running.
    To achieve this, simply save the timer value (not a timestamp) when exiting the app. And read the value back when it starts. (And yes, while the application is running you can use a timestamp saved at the start of the current execution, just do not save it).

  10. #10
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Location
    Portugal
    Posts
    957

    Re: Timer independent of system time even in background and offline mode

    Just save 2 date/time fields and a control field or number of changes on date/time.

    First Date/Time the date/time it was blocked. Second Date/Time the last time the user attempted to login. When testing not only test for elapsed time since block but also compare the date/time of last execution and block the user from accessing the app if the system date is inferior. The user has to change the date/hour to the correct hour sometime right?

    So you would have something like this:

    First lock:

    UnLocked date/time: 05-04-2013 12:30
    Last app run: 05-04-2013 12:00
    Last date/time change event: 0
    User tries to login in app after 20 minutes:

    UnLocked date/time: 05-04-2013 12:30
    Last app run: 05-04-2013 12:20
    Last date/time change event: 0
    User changes hour to 13:30

    UnLocked date/time: null
    Last app run: 05-04-2013 13:30
    Last date/time change event: 0
    Use changes hour again to correct time: 05-04-2013 12:22
    UnLocked date/time: Null
    Last app run: 05-04-2013 13:30
    Last app run > 05-04-2013 12:22 then
    Last date/time change event: +2
    UnLocked date/time = now + (30 minutes * last date/time event)
    Whet this does is that the user every time it changes the clock forward and then backward again the next unlock will take double the time to happen.

    Eventually the user will give up trying to do the same again or it will just be such a pain that will eventually will not do it again.

  11. #11
    Regular Contributor
    Join Date
    Dec 2012
    Posts
    66

    Re: Timer independent of system time even in background and offline mode

    Hi wizard,
    Quote Originally Posted by wizard_hu_ View Post
    What you are describing is very simple: the timer is running only when the application is running. When it started from 1:22, and you waited a couple minutes, that may have been a bit more than 2-3, like 4. and 1:22-0:04 is 1:18. And the 10-minute power off time, and set-the-time-ahead do not matter at all, since the application was not running.
    To achieve this, simply save the timer value (not a timestamp) when exiting the app. And read the value back when it starts. (And yes, while the application is running you can use a timestamp saved at the start of the current execution, just do not save it).
    No. I personally play this game almost daily. And i can assure it works seamless in background when phone is on even without network. I would have advised you to test it personally but the bad part is its 809MB in size. Anyways as long as its timer functionality is considered, it works.

    Regards,
    Vinay

  12. #12
    Regular Contributor
    Join Date
    Dec 2012
    Posts
    66

    Re: Timer independent of system time even in background and offline mode

    Good trick João. Taking advantage of the part that user will definitely fall back to original time. Sounds good to me. Will think over it. Can be used in case if i wont be able to dig out timer functionality of Real Football 2013.

    Regards,
    Vinay

  13. #13
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Location
    Portugal
    Posts
    957

    Re: Timer independent of system time even in background and offline mode

    Quote Originally Posted by vinayppatil View Post
    Good trick João. Taking advantage of the part that user will definitely fall back to original time. Sounds good to me. Will think over it. Can be used in case if i wont be able to dig out timer functionality of Real Football 2013.

    Regards,
    Vinay
    Glad I could help. Let us know about the solution you decided on. In fact that may be a nice Wiki article for a common problem. Accept the challenge?

  14. #14
    Registered User
    Join Date
    Jan 2009
    Location
    Melbourne, Australia
    Posts
    2,571

    Re: Timer independent of system time even in background and offline mode

    Would setting a block flag and then using a 30 minute periodic task to reset it work (if they try again then clear that task and recreate another double length one).

    Yes, are you happy to write a wiki article on this, it is an interesting question?

  15. #15
    Regular Contributor
    Join Date
    Dec 2012
    Posts
    66

    Re: Timer independent of system time even in background and offline mode

    Hi,
    Quote Originally Posted by hamishwillee View Post
    Would setting a block flag and then using a 30 minute periodic task to reset it work (if they try again then clear that task and recreate another double length one).

    Yes, are you happy to write a wiki article on this, it is an interesting question?
    I created and implemented a small algorithm on it. Which makes use of periodic task too.
    Yes i am more than happy to write the article.

    Regards,
    Vinay

Similar Threads

  1. QGraphicsGeoMap offline mode
    By smitis in forum Qt
    Replies: 3
    Last Post: 2012-03-29, 06:57
  2. Replies: 8
    Last Post: 2009-10-21, 08:55
  3. How to set a device in offline mode?
    By bijen.singh@dbydx.com in forum Symbian
    Replies: 2
    Last Post: 2008-09-10, 20:24
  4. Offline mode.
    By naimidrees in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2008-07-23, 08:58
  5. Offline mode and demo mode
    By teura666 in forum General Development Questions
    Replies: 1
    Last Post: 2006-01-12, 19:59

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×