Automatically reconnect to trusted networks in the background on API 29+
Problem
On Android 10 (API 29) or later, when a trusted network has been configured, if the mobile device rejoins the network while KDE Connect is running in the background, it doesn't reconnect to any paired devices in the trusted network. It only reconnects when the user brings the app to the foreground.
Cause
Android 10 introduced a separate permission for background location access.
When KDE Connect is running in the background with API 29+, TrustedNetworkHelper.currentSSID
fails to get the SSID because it doesn't have the required permission. This prevents KDE Connect from verifying whether a network is trusted.
Solution
Make KDE Connect request for background location access permission.
To request for background location access, an app must declare it in the manifest, or else the option to to enable background location access won't appear in settings.
As a side note, the permission request dialog in TrustedNetworksActivity
doesn't require changes because after Android 11, the option to allow background location no longer shows up in a dialog. It has to be manually enabled in settings.
Test Plan
Before:
On Android 10 or later, configure a trusted network and pair with a device in it. Let KDE Connect run in the background. Disconnect from the trusted network and then rejoin. KDE Connect won't automatically reconnect to the paired device.
After:
Do the same steps as above, except after configuring the trust network, go into settings and allow KDE Connect to access location all the time. After KDE Connect rejoins the trusted network, it should automatically reconnect to the paired device.