syncthing/syncthing-android

App cannot detect current network when in background due to missing ACCESS_BACKGROUND_LOCATION permission

wertziop opened this issue · 15 comments

Syncthing app is configuered to start only on connection of a specific wifi ssid:
config options are: "Bei WLAN-Verbindung ausführen" AND "In festgelegtem WLAN-Netzwerk ausführen" (sorry, app is in german)

that means: use only wifi connectivity, don't use metered wifi, use only a specified ssid (which is displayed correctly)
other options: respect energy saving mode

[edit]

the real issue here

detecting the type and properties of connectivity (wifi, ssid of wifi, mobile data, metered, unmetered) depends on the global device discovery. this should be an independent task.

what I've observed

  1. connect to specified wifi
  2. start app
  3. permanent android notification comes up saying "syncthing is activated"
  4. disconnect wifi
  5. permanent android notification says "syncthing is deactivated"
  6. reconnect to specified wifi
  7. permanent android notification still says "syncthing is deactivated"
  8. tab on notification brings app in foreground with error popup saying something like "syncthing is disabled, reason: the ssid is not in white list."
  9. after reopen settings page and close it without changing anything, it reactivates.

what I've expected

  • after 6.) it should reactivate automatically without any user interaction.
  • change of network type should be independent from use of network, e.g local/global discovery

nice to have

  • no permanent notifications, that means: only notfications on status changes, otherwise silent background operation

the app has all rights, the battery management is "unlimited" and the "stop app when idle" is disabled
the app is configured to only do local discoveries

Version Information

App Version: 1.23.6.3
Syncthing Version: v1.23.6
Android Version: Android 13 / CalyxOS-Version 4.11.3

Is location enabled in the Android settings? If not, then you need to enable it, as otherwise Wi-Fi connectivity detection in the Syncthing app won't work.

the app is configured to only do local discoveries

This is unrelated to the issue at hand, but local discovery is broken in newer versions of Android, so if you disable global discovery (and relays), you will effectively have no discovery at all.

the dependency of ssid and location service is android bullshit, that's clear.
But why does the check of connectivity depends on the discovery? that's a completely different functionality, imho.
connectivity: which network I'm using at the moment? is it cheap, what's the name, dows it changed lately, etc.
discovery: use the network and do some magic.

i'll edit the issue, to clarify that point.

But why does the check of connectivity depends on the discovery? that's a completely different functionality, imho.

It does not. That's why I said it was an unrelated comment 🙃. The only thing that should have an impact here is whether you've got location services enabled in the Android settings and whether the app is allowed to access location. If both of those are true but the problem still persists, then it may also be something related to CalyxOS which is supposed to harden privacy, security, etc. which could possibly result in apps being unable to determine whether Wi-Fi is connected or not. This is just a speculation on my part though.

it has all necessary rights and location service works properly.
I've tested it just now: global discover AND nat traversal is on: wifi ssid detection works
one or the other is off: wifi ssid detection does not work.

if you think i've done something wrong, or messed my config up, you're free to close this issue. I will not continue to test it.

I can confirm the issue - still - with Syncthing Version 1.273.7 under Android 12 at a Poco X3 pro.

A configured, right SSID, will not be detected after "coming home"...
Without a configured SSID, a "now/new" available Wifi-Connection is detected, syncthing starts working...

Allow access to location all the time I think, worked for me

bt90 commented

I think we need to request the ACCESS_BACKGROUND_LOCATION permission.

We declare it in the manifest but don't request it in the startup wizard.

https://developer.android.com/training/location/permissions#request-background-location

I can also confirm the problem about automatically recognise the allowed ssid.
Once configured it works as expected. But some hours later the app pretend to have wrong working conditions.
Then i can only help myself with two options

  • switch off the ssid dependency and allow all wlan networks
  • or force android to stop the app and open it again. Then the ssid is again evaluated once as expected. But this trick was always needed to get another sync run started.

Using a "realme 7 (5G)" with Android 12.

Screenshot_2023-12-23-13-35-50-72_fc704e6b13c4fb26bf5e411f75da84f2
Screenshot_2023-12-23-13-21-01-71_21b5f25b12d299480f48e4a9d6a069e0

I was about to create an bug about this, and found this issue.

The app can detect that Syncthing battery settings are not set to Unrestricted, and notifies the user to change it.
On the other hand, it does not detect that location privilege is not set to "Allow all the time". Instead, upon start, it says something like "syncthing is disabled, reason: the ssid is not in white list".

The check should be performed only when the location services are really needed, i.e. when conditional run ("Run on wifi") is checked.

It took me several hours to figure out the problem. This simple check would have helped to solve the problem immediately.