mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-03-31 04:04:46 -04:00
list devices from adapter.bondedDevices (#536)
This commit is contained in:
@@ -251,8 +251,8 @@ class BTScanModel @Inject constructor(
|
||||
// Include a placeholder for "None"
|
||||
addDevice(DeviceListEntry(context.getString(R.string.none), "n", true))
|
||||
|
||||
// Include CompanionDeviceManager valid associations
|
||||
addDeviceAssociations()
|
||||
// Include paired Bluetooth devices
|
||||
addBluetoothDevices()
|
||||
|
||||
// Include Network Service Discovery
|
||||
nsdRepository.resolvedList?.forEach { service ->
|
||||
@@ -324,17 +324,13 @@ class BTScanModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
fun addDeviceAssociations() {
|
||||
if (hasCompanionDeviceApi) deviceManager?.associations?.forEach { bleAddress ->
|
||||
val bleDevice = getDeviceListEntry("x$bleAddress", true)
|
||||
// Disassociate after pairing is removed (if BLE is disabled, assume bonded)
|
||||
if (!bleDevice.bonded) {
|
||||
debug("Forgetting old BLE association ${bleAddress.anonymize}")
|
||||
deviceManager?.disassociate(bleAddress)
|
||||
@SuppressLint("MissingPermission")
|
||||
private fun addBluetoothDevices() {
|
||||
bluetoothRepository.getBondedDevices()
|
||||
?.filter { it.name.matches(Regex("^\\S+\$")) }
|
||||
?.forEach {
|
||||
addDevice(DeviceListEntry(it.name, "x${it.address}", true))
|
||||
}
|
||||
addDevice(bleDevice)
|
||||
}
|
||||
}
|
||||
|
||||
private val _spinner = MutableLiveData(false)
|
||||
|
||||
@@ -65,6 +65,13 @@ class BluetoothRepository @Inject constructor(
|
||||
return bluetoothAdapterLazy.get()?.bluetoothLeScanner
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
fun getBondedDevices(): Set<BluetoothDevice>? {
|
||||
return bluetoothAdapterLazy.get()
|
||||
?.takeIf { application.hasBluetoothPermission() }
|
||||
?.bondedDevices
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
internal suspend fun updateBluetoothState() {
|
||||
val newState: BluetoothState = bluetoothAdapterLazy.get()?.takeIf {
|
||||
|
||||
Reference in New Issue
Block a user