juha-h / baresip-studio

baresip library based SIP client for Android
BSD 3-Clause "New" or "Revised" License
283 stars 71 forks source link

Wakelock is active when no accounts are registered #268

Closed jvandenbroek closed 2 years ago

jvandenbroek commented 2 years ago

After the very nice implementation of using intents to (un)register accounts (https://github.com/juha-h/baresip-studio/issues/257), I've noticed that the partial wakelock stays active after unregistering, which prevents the device to go to deep sleep and does drain the battery quite a bit. I would imagine there is no need for such wakelock when no accounts are registered.

juha-h commented 2 years ago

I'll take a look after a few days when I'm back at "office".

juha-h commented 2 years ago

Question: why can't you use tasker to quit baresip when you don't need any accounts being registered and then start it again when you need registered accounts?

juha-h commented 2 years ago

Partial wakelock prevents Android from killing baresip foreground service when the device is in doze mode. So it does not sound like a good idea to release the lock except when baresip app is terminated at Quit.

jvandenbroek commented 2 years ago

Question: why can't you use tasker to quit baresip when you don't need any accounts being registered and then start it again when you need registered accounts?

That would be fine for me, yes. Maybe an intent for launching and stopping baresip could be implemented? Afaik it's only possible to start apps in foreground with Tasker. There is an option to kill an app, but that works best with rooted devices (which I have, so in my case will probably work fine, but maybe others would like this as well). I have other apps that react on a start / stop intents, so it should be possible to register some kind of listener without the app being started.

I'll test the Tasker start/kill action next days, if that works fine I'll let you know.

jvandenbroek commented 2 years ago

Well I think the launch / kill app works fine for me after testing a few days, seems to be reliable. Guess you're right, no need to change the wakelock behaviour.

juha-h commented 2 years ago

Should I still add intent action for quiting bare sip?

gdt commented 2 years ago

I am not trying to use baresip with Easer, but I think you should. Adnroid norms are that an app which is not doing anything should not use power, and since baresip isn't like that every reasonable mechanism to get it to stop should be available.

juha-h commented 2 years ago

Greg Troxel writes:

I am not trying to use baresip with Easer, but I think you should. Adnroid norms are that an app which is not doing anything should not use power, and since baresip isn't like that every reasonable mechanism to get it to stop should be available.

Even if no accounts register, baresip is still listening for incoming requests at all enabled interfaces.

gdt commented 2 years ago

A fair point about listening for local calls. Still, that argues for making it easy to shut down by all reasonable mechanisms.

juha-h commented 2 years ago

Greg Troxel writes:

A fair point about listening for local calls. Still, that argues for making it easy to shut down by all reasonable mechanisms.

I checked and quit is implemented in MainActivity. It would be too much work to allow quiting baresip from intent receiver.

juha-h commented 2 years ago

PR https://github.com/juha-h/baresip-studio/commit/52da111a716bf030d18534c09f1d6dec7a698397 added QUIT action to intent receiver.