5

I'm working on a Voice over IP (VoIP) application using the SIP protocol which requires the application to be listening to incoming calls. This means the application must not sleep or die.

For old code, it seems the way to do this is to acquire a PARTIAL_WAKE_LOCK.

Now from Android 6.0 and higher, there's the new Doze. It is recommended that, if you don't want your app to go to standby, you should "whitelist" it by requesting the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission. This is specifically for VoIP applications according to the documentation.

These two different things seem to be related. I'm not sure how they are related, if they interfere with each other, if I should use one or the other or both, and if there are other considerations. Please explain.

Also, I am not allowed to use Push Notifications on this project. If you have other advice for saving the battery please let me know.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
Emmanuel
  • 16,791
  • 6
  • 48
  • 74

1 Answers1

3

In your case looks like you should be asking for whitelist, as the documentation you linked, it advises that GCM can collide with the SIP protocol. I would handle this case like a typical runtime permission. On some place of your app(the on create of your main screen for ex) ask for whitelist and the reason why you need it, if they dont want just disable functionality related to receive calls.

You should only use one of them at a time, you can always do it the hard way and handle the voip calls without sip, then you could handle incoming calls with push notifications from your server, but i dont think someone is up to that unless you need a top tier product.

There is no workaround for this, indeed the only good way is to do the heavy lifting by yourself, because its kinda popular on users to use battery optimizators / improved doze apps so you could get killed anyway.

marcos E.
  • 477
  • 4
  • 11
  • So if I understand what you're saying, I should use one or the other but not both? But Doze whitelisting starts at Android 6.0 (API level 23). So I should use PARTIAL_WAKE_LOCK only for older OS versions, and use Doze whitelisting for level 23? On this project I must use SIP and I can't use push notifications. – Emmanuel Aug 16 '17 at 14:29
  • 1
    Yep, use PARTIAL_WAVE_LOCK for all versions and for API >= 23 ask for whitelist – marcos E. Aug 17 '17 at 09:03
  • I didn't click on your answer on time so the bounty just disappeared. The stupid bounty rules will not let me send you the full bounty. I do not know why they decided to do it like that. I wish I could send you the full bounty now. – Emmanuel Sep 08 '17 at 16:22
  • 1
    dont worry @Emmanuel my answer wasnt that good tho, just a suggestion how to would I handle functionality for android >= M – marcos E. Sep 13 '17 at 12:24