mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Merge remote-tracking branch 'remotes/origin/master'
This commit is contained in:
commit
0acf037000
18 changed files with 240 additions and 260 deletions
|
|
@ -122,12 +122,6 @@ class BluetoothInterface(
|
|||
usbRepository: UsbRepository, // Temporary until dependency injection transition is completed
|
||||
rest: String
|
||||
): Boolean {
|
||||
/* val allPaired = if (hasCompanionDeviceApi(context)) {
|
||||
val deviceManager: CompanionDeviceManager by lazy {
|
||||
context.getSystemService(Context.COMPANION_DEVICE_SERVICE) as CompanionDeviceManager
|
||||
}
|
||||
deviceManager.associations.map { it }.toSet()
|
||||
} else { */
|
||||
val allPaired = getBluetoothAdapter(context)?.bondedDevices.orEmpty()
|
||||
.map { it.address }.toSet()
|
||||
return if (!allPaired.contains(rest)) {
|
||||
|
|
@ -137,63 +131,6 @@ class BluetoothInterface(
|
|||
true
|
||||
}
|
||||
|
||||
|
||||
/// Return the device we are configured to use, or null for none
|
||||
/*
|
||||
@SuppressLint("NewApi")
|
||||
fun getBondedDeviceAddress(context: Context): String? =
|
||||
if (hasCompanionDeviceApi(context)) {
|
||||
// Use new companion API
|
||||
|
||||
val deviceManager = context.getSystemService(CompanionDeviceManager::class.java)
|
||||
val associations = deviceManager.associations
|
||||
val result = associations.firstOrNull()
|
||||
debug("reading bonded devices: $result")
|
||||
result
|
||||
} else {
|
||||
// Use classic API and a preferences string
|
||||
|
||||
val allPaired =
|
||||
getBluetoothAdapter(context)?.bondedDevices.orEmpty().map { it.address }.toSet()
|
||||
|
||||
// If the user has unpaired our device, treat things as if we don't have one
|
||||
val address = InterfaceService.getPrefs(context).getString(DEVADDR_KEY, null)
|
||||
|
||||
if (address != null && !allPaired.contains(address)) {
|
||||
warn("Ignoring stale bond to ${address.anonymize}")
|
||||
null
|
||||
} else
|
||||
address
|
||||
}
|
||||
*/
|
||||
|
||||
/// Can we use the modern BLE scan API?
|
||||
fun hasCompanionDeviceApi(context: Context): Boolean =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val res =
|
||||
context.packageManager.hasSystemFeature(PackageManager.FEATURE_COMPANION_DEVICE_SETUP)
|
||||
debug("CompanionDevice API available=$res")
|
||||
res
|
||||
} else {
|
||||
warn("CompanionDevice API not available, falling back to classic scan")
|
||||
false
|
||||
}
|
||||
|
||||
/** FIXME - when adding companion device support back in, use this code to set companion device from setBondedDevice
|
||||
* if (BluetoothInterface.hasCompanionDeviceApi(this)) {
|
||||
// We only keep an association to one device at a time...
|
||||
if (addr != null) {
|
||||
val deviceManager = getSystemService(CompanionDeviceManager::class.java)
|
||||
|
||||
deviceManager.associations.forEach { old ->
|
||||
if (addr != old) {
|
||||
BluetoothInterface.debug("Forgetting old BLE association $old")
|
||||
deviceManager.disassociate(old)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* this is created in onCreate()
|
||||
* We do an ugly hack of keeping it in the singleton so we can share it for the rare software update case
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue