Draft: Use NetworkCallback to get SSID on SDK 31+
Summary
Since Android 12 the current method of reading Wi-Fi SSID doesn't work and NetworkCallback
with FLAG_INCLUDE_LOCATION_INFO
must be used on these newer Android versions to get SSID. Unfortunately this requires changing how TrustedNetworkHelper
is used, because synchronous API is no longer available.
Incorporates changes from !203 (closed), because I'm already changing SSID-related code.
BUG: 446037
BUG: 436904 (not 100% sure, because it was reported on Android 10)
Test Plan
- Open KDE Connect on Android 12 or 13
- Click the menu button
- Click "Trusted networks" in the menu
- Uncheck "Allow all"
- Add current network to trusted networks list
- Go back to the main screen and check if the network is trusted
Before:
When the list of trusted networks is open and "Allow all" is unchecked there is no button to add a network to the list on Android 12 and newer. If the system was updated e.g. from Android 11 and current network is on the trusted networks list, it is treated as not trusted (warning on the main screen).
After:
The button "Add {SSID}" is visible when "Allow all" is unchecked, the device is connected to a Wi-Fi network and the application has location permissions. The button (dis)appears when the network status changes (connected/disconnected).
When the current network is trusted, the "Not on a trusted network" warning does not appear on the main screen and "Other devices running KDE Connect in your same network should appear here" is shown instead.
No change in visible behaviour on Android 11 and older.
Remaining problems
-
Sometimes after opening the application and always just after granting the permission the NetworkCallback
is not executed and the SSID is not updated, except in theTrustedNetworksActivity
, where the callback is re-registered when permissions are granted.