title: Make timer to work in the background on app lock/sleep
body: <p><strong>Problem definition</strong></p>
  
  <p>App is an ionic4 capacitor app which uses few cordova plugins as well. I have a timer feature associated with a bluetooth device that has to keep running even when the phone goes to sleep or in locked mode. Using the cordova-background-mode plugin the app works in the background, but as soon as phone is locked or in sleep the timer stops working. When the screen resumes, the timer continues from where it stopped.</p>
  
  <p>I cannot use the platform pause and resume events in my case as just taking the difference and adding up with the time will provide wrong values with my use case. The use case if explained below:</p>
  
  <p>This app is used with the height adjusting table connected via bluetooth, where a user can use the app to adjust the height and also track the time when he is in standing position. (The timer starts running when the table reaches a certain height - achieved using the startNotification method of ble). The height adjusting table also has button to control its height.</p>
  
  <p>Use case (Why I cannot use the platform resume and pause events along with timestamps) :</p>
  
  <ol>
  <li>Desk is in standing position. Timer starts running.</li>
  <li>I lock my phone (timestamp created - on pause event trigger)</li>
  <li>I go in sitting position for 1h (The table also has buttons to control the height, so this is referred to when the user uses that to reduce the height and is in sitting position, but the phone is still locked/sleep and is not notified about the change)</li>
  <li>I go back to standing position for 20min</li>
  <li>I unlock my phone. (Second time stamp created - on resume event trigger)</li>
  <li>Now it will show 1hour 20min standing time even though I stood only 20min</li>
  </ol>
  
  <p>How can I make wake the phone or notify when the ble device state changes even when the phone is locked? I tried by including the script inside the startNotification method which would create a timestamp in the DB when the height is adjusted. But this doesn't work if the phone is locked/sleep. It requires the phone to be unlocked to send any DB updates.</p>
  
  <p>That's when I tried to use the foreground plugin (cordova-plugin-foreground-service) along with the background mode, but it did not result in a DB service on changes of the state of the device.</p>
  
  <p><strong>Expected behavior</strong>
  The timer should either run in the background like the music player app which continues to play even on phone lock. Or it should be able to create a DB call on state change of the device. Any of the above approaches would be fine, but the correct time has to be tracked.</p>
  
  <p>Been stuck on this issue since quite a long time now. Is it possible to keep the timer running in the background like the music app? Or is there any other way to compute the correct time?</p>
  
  <p>Ps. Keeping the phone awake is not considered as an option at the moment. </p>