disable server, but client works

This commit is contained in:
callebtc
2025-07-09 21:10:20 +02:00
parent 250772a693
commit 90750c2635
2 changed files with 32 additions and 35 deletions
@@ -128,7 +128,7 @@ class BluetoothConnectionManager(
try { try {
isActive = true isActive = true
setupGattServer() // setupGattServer()
// Start power manager and services // Start power manager and services
connectionScope.launch { connectionScope.launch {
@@ -804,7 +804,7 @@ class BluetoothConnectionManager(
try { try {
Log.d(TAG, "Attempting GATT connection to $deviceAddress with autoConnect=false") Log.d(TAG, "Attempting GATT connection to $deviceAddress with autoConnect=false")
val gatt = device.connectGatt(context, false, gattCallback) val gatt = device.connectGatt(context, false, gattCallback, BluetoothDevice.TRANSPORT_LE)
if (gatt == null) { if (gatt == null) {
Log.e(TAG, "connectGatt returned null for $deviceAddress") Log.e(TAG, "connectGatt returned null for $deviceAddress")
pendingConnections.remove(deviceAddress) pendingConnections.remove(deviceAddress)
@@ -113,39 +113,36 @@ class PowerManager(private val context: Context) {
* Get scan settings optimized for current power mode * Get scan settings optimized for current power mode
*/ */
fun getScanSettings(): ScanSettings { fun getScanSettings(): ScanSettings {
return when (currentMode) { // CRITICAL FIX: Set reportDelay to 0 for all modes.
PowerMode.PERFORMANCE -> ScanSettings.Builder() // When using a custom duty cycle, we want scan results delivered immediately,
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) // not batched. A non-zero report delay can conflict with the scan window,
// causing missed results if the scan stops before the delay is met.
val builder = ScanSettings.Builder()
.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
when (currentMode) {
PowerMode.PERFORMANCE -> builder
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE) .setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE)
.setNumOfMatches(ScanSettings.MATCH_NUM_MAX_ADVERTISEMENT) .setNumOfMatches(ScanSettings.MATCH_NUM_MAX_ADVERTISEMENT)
.setReportDelay(50) // Reduced from 10ms
.build()
PowerMode.BALANCED -> ScanSettings.Builder() PowerMode.BALANCED -> builder
.setScanMode(ScanSettings.SCAN_MODE_BALANCED) .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
.setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE) .setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE)
.setNumOfMatches(ScanSettings.MATCH_NUM_ONE_ADVERTISEMENT) .setNumOfMatches(ScanSettings.MATCH_NUM_ONE_ADVERTISEMENT)
.setReportDelay(200)
.build()
PowerMode.POWER_SAVER -> ScanSettings.Builder() PowerMode.POWER_SAVER -> builder
.setScanMode(ScanSettings.SCAN_MODE_LOW_POWER) .setScanMode(ScanSettings.SCAN_MODE_LOW_POWER)
.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
.setMatchMode(ScanSettings.MATCH_MODE_STICKY) .setMatchMode(ScanSettings.MATCH_MODE_STICKY)
.setNumOfMatches(ScanSettings.MATCH_NUM_ONE_ADVERTISEMENT) .setNumOfMatches(ScanSettings.MATCH_NUM_ONE_ADVERTISEMENT)
.setReportDelay(1000)
.build()
PowerMode.ULTRA_LOW_POWER -> ScanSettings.Builder() PowerMode.ULTRA_LOW_POWER -> builder
.setScanMode(ScanSettings.SCAN_MODE_OPPORTUNISTIC) .setScanMode(ScanSettings.SCAN_MODE_OPPORTUNISTIC)
.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
.setMatchMode(ScanSettings.MATCH_MODE_STICKY) .setMatchMode(ScanSettings.MATCH_MODE_STICKY)
.setNumOfMatches(ScanSettings.MATCH_NUM_ONE_ADVERTISEMENT) .setNumOfMatches(ScanSettings.MATCH_NUM_ONE_ADVERTISEMENT)
.setReportDelay(5000)
.build()
} }
return builder.setReportDelay(0).build()
} }
/** /**