kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
fix companion pairing
rodzic
910f090335
commit
a2f5d74bfc
|
@ -4,6 +4,7 @@ import android.bluetooth.BluetoothAdapter
|
||||||
import android.bluetooth.BluetoothGattCharacteristic
|
import android.bluetooth.BluetoothGattCharacteristic
|
||||||
import android.bluetooth.BluetoothGattService
|
import android.bluetooth.BluetoothGattService
|
||||||
import android.bluetooth.BluetoothManager
|
import android.bluetooth.BluetoothManager
|
||||||
|
import android.companion.CompanionDeviceManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
@ -109,9 +110,13 @@ class BluetoothInterface(val service: RadioInterfaceService, val address: String
|
||||||
|
|
||||||
/** Return true if this address is still acceptable. For BLE that means, still bonded */
|
/** Return true if this address is still acceptable. For BLE that means, still bonded */
|
||||||
override fun addressValid(context: Context, rest: String): Boolean {
|
override fun addressValid(context: Context, rest: String): Boolean {
|
||||||
val allPaired =
|
val allPaired = if (hasCompanionDeviceApi(context)) {
|
||||||
getBluetoothAdapter(context)?.bondedDevices.orEmpty().map { it.address }.toSet()
|
val deviceManager = context.getSystemService(CompanionDeviceManager::class.java)
|
||||||
|
deviceManager.associations.map { it }.toSet()
|
||||||
|
} else {
|
||||||
|
getBluetoothAdapter(context)?.bondedDevices.orEmpty()
|
||||||
|
.map { it.address }.toSet()
|
||||||
|
}
|
||||||
return if (!allPaired.contains(rest)) {
|
return if (!allPaired.contains(rest)) {
|
||||||
warn("Ignoring stale bond to ${rest.anonymize}")
|
warn("Ignoring stale bond to ${rest.anonymize}")
|
||||||
false
|
false
|
||||||
|
|
Ładowanie…
Reference in New Issue