syncthing-android icon indicating copy to clipboard operation
syncthing-android copied to clipboard

Unreliable charging detection

Open notgood opened this issue 4 years ago • 4 comments

My "Run Conditions": run on any Wi-Fi + only on AC. Tested on: Galaxy S10+ on stock Android 11, Galaxy S5 on Android 10 LineageOS.

On both devices AC vs battery detection logic is extremely unreliable, every now and then it goes to inverted state, i.e. syncthing service is being started when disconnected from power and being killed when connecting to AC.

Validated by running "logcat | grep -E 'RunConditionMonitor|SyncthingService|BatteryService'" in wireless ADB shell and plugging AC powersupply in and out repeatedly.

Looking at the RunConditionMonitor.java and logcat output, here is my guess: ACTION_POWER_CONNECTED and ACTION_POWER_DISCONNECTED are being received just fine and then code is trying to process BatteryManager.EXTRA_PLUGGED value, which is a bad idea to do instantly, since a lot of times battery status hasn't updated yet.

Quick google returned similar issue: https://stackoverflow.com/a/11868558

Perhaps this call to updateShouldRunDecision() should be fired async, schedule it for execution in a few seconds, let the battery status settle first. https://github.com/syncthing/syncthing-android/blob/00edf5f868512301ec770caeb5d07081dba3f1d1/app/src/main/java/com/nutomic/syncthingandroid/service/RunConditionMonitor.java#L121

notgood avatar Jan 17 '21 18:01 notgood

Same issue as #1540 and #1574

notgood avatar Jan 18 '21 17:01 notgood

This issue is fixed in fork, pulling this one-line commit would fix it for official build as well

Catfriend1/syncthing-android@0cd20ff4de68fac9511eb0670eb858007ba89723

notgood avatar Apr 13 '22 07:04 notgood

Hi, any chance of including this fix? Thanks!

mhcerri avatar Jul 25 '22 20:07 mhcerri

Yes include it, please.

pfsmorigo avatar Jul 25 '22 23:07 pfsmorigo

Thank you!

notgood avatar Aug 11 '22 18:08 notgood