fix: centralize and strictly enforce connection limits (#618)

This commit is contained in:
callebtc
2026-01-15 16:00:48 +07:00
committed by GitHub
parent 83fbcca557
commit c64ea0a021
4 changed files with 103 additions and 131 deletions
@@ -46,22 +46,6 @@ class BluetoothGattServerManager(
// State management
private var isActive = false
// Enforce a server connection limit by canceling the oldest connections (best-effort)
fun enforceServerLimit(maxServer: Int) {
if (maxServer <= 0) return
try {
// Use connection tracker to get actual connected server devices
val servers = connectionTracker.getConnectedDevices().values.filter { !it.isClient }
if (servers.size > maxServer) {
val excess = servers.size - maxServer
// Disconnect oldest
servers.sortedBy { it.connectedAt }.take(excess).forEach { d ->
try { gattServer?.cancelConnection(d.device) } catch (_: Exception) { }
}
}
} catch (_: Exception) { }
}
/**
* Disconnect a specific device (used by ConnectionManager to enforce overall limits)
*/