Catfriend1 / syncthing-android

Syncthing-Fork - A Syncthing Wrapper for Android.
Mozilla Public License 2.0
1.25k stars 40 forks source link

App ignores battery saver setting, doesn't allow start with battery saver settings anyway #1049

Closed gradha closed 10 months ago

gradha commented 10 months ago

Trying to set up syncthing on a new android 14 device I noticed it was consuming battery overnight while the battery saver mode is turned on during schedule. After entering syncthing I noticed it ignores battery saver settings. As seen on this screenshot, the battery saver is on, but syncthing conditions say it's fine to run:

Screenshot_2023-11-26-00-36-09-812_com github catfriend1 syncthingandroid-Screenshot_2023-11-26-00-36-14-578_com github catfriend1 syncthingandroid

Then I figured out that maybe the battery saver setting is not being detected due to battery saver having been disabled:

Screenshot_2023-11-26-00-36-48-031_com miui powerkeeper

But when I turn again Battery Saver on this Xiaomi, I get a startup lockup where I can't progress further into the app, because it requests the battery saver to be turned off (which would be banned in G store):

Screenshot_2023-11-26-00-37-02-687_com github catfriend1 syncthingandroid

So, if detecting battery saver settings doesn't work when app is excluded, and I can't run the app unless it's excluded, detecting battery saver is useless for me. Or is there an additional setting that needs to be turned on/off?

Also, I went back to my Xiaomi Android 12 based device and battery saver setting doesn't work there either. I probably only noticed on the new device since I'm just setting it up and being blank nothing else was showing up in the battery usage log.

ForsakenHarmony commented 10 months ago

I don't understand why the app doesn't allow using it with battery saver enabled, I know it will not work reliably if the OS kills it, I still want to use it that way, because it eats 45% of my battery otherwise

Catfriend1 commented 10 months ago

I'm not sure if it is a good idea to run it 'battery optimized'... Os will pause the native process, likely with the database in inconsistent state, then later it will remove the app in low memory / resource condition, so the database could get damaged. When you then boot up the app again, it might be risky if Syncthing decides to delete / modify anything because the block db is broken. I don't like that.

Catfriend1 commented 10 months ago

Also, the wording of Xiaomi's miui optimization ui could be misleading. Battery optimization has nothing to so with "respect power save mode" which can be found in the run condition options screen.

ForsakenHarmony commented 10 months ago

@Catfriend1 I see where you're coming from, are you sure there's no way to tell the OS to send the process a SIGTERM (or the app an intent) so it can shut down safely?

I feel like if that isn't the case a lot of apps would run into problems with data corruption 🤔

Catfriend1 commented 10 months ago

I feel like if that isn't the case a lot of apps would run into problems with data corruption 🤔

The thing is, other apps are mainly using Java and Android library based stuff from the OS. Versus: Syncthing is a native compiled binary which "cannot talk" to the OS nor receive broadcast notifications from it to do the correct thing to stay consistent.

It // may // be, that behaviour of the ignore battery optim thingy changed over time. It came with Android 6 and might now be working differently. But I'm not sure I should "just" compile the app without this permission and let you feel what happens. Sure, I could, but it would be better someone disables the code, recompiles and provides me feedback on his make and model how it turned out to work (or not).