From c62cbaa1c240a9c472b9314eecc0f9c573a40c9e Mon Sep 17 00:00:00 2001 From: eddy Date: Sun, 26 Jul 2026 16:44:21 +0200 Subject: [PATCH] Add GATT status code logging in callbacks Log warning when status != GATT_SUCCESS in onConnectionStateChange, onServicesDiscovered, and onMtuChanged. Service discovery failure now shows 'Servicefout' and returns early to prevent MTU request on failed discovery. Reviewed in codereview.md (recommendation 5.2). --- .../src/main/java/com/eddy/atomrelay/MainActivity.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/android/app/src/main/java/com/eddy/atomrelay/MainActivity.kt b/android/app/src/main/java/com/eddy/atomrelay/MainActivity.kt index b5342d5..20f3c86 100644 --- a/android/app/src/main/java/com/eddy/atomrelay/MainActivity.kt +++ b/android/app/src/main/java/com/eddy/atomrelay/MainActivity.kt @@ -71,6 +71,9 @@ class MainActivity : AppCompatActivity() { private val gattCallback = object : BluetoothGattCallback() { @SuppressLint("MissingPermission") override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) { + if (status != BluetoothGatt.GATT_SUCCESS) { + Log.w(TAG, "GATT connection state change error: status=$status newState=$newState") + } if (newState == BluetoothProfile.STATE_CONNECTED) { Log.d(TAG, "GATT connected") bluetoothGatt = gatt @@ -92,12 +95,20 @@ class MainActivity : AppCompatActivity() { @SuppressLint("MissingPermission") override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) { + if (status != BluetoothGatt.GATT_SUCCESS) { + Log.w(TAG, "Service discovery failed (status=$status)") + runOnUiThread { statusText.text = "Servicefout" } + return + } Log.d(TAG, "Services discovered, requesting MTU...") gatt.requestMtu(256) } @SuppressLint("MissingPermission") override fun onMtuChanged(gatt: BluetoothGatt, mtu: Int, status: Int) { + if (status != BluetoothGatt.GATT_SUCCESS) { + Log.w(TAG, "MTU negotiation failed (status=$status)") + } Log.d(TAG, "MTU changed to $mtu") val service = gatt.getService(SERVICE_UUID) if (service != null) {