From fb59ec6db64a658a1b3e383faa3f433b6234c042 Mon Sep 17 00:00:00 2001 From: Graham Jones Date: Mon, 25 Mar 2024 22:56:56 +0000 Subject: [PATCH] Added check that characteristic is not null before reading it. Displays warning on Logcat if it is null rather than crashing. --- app/src/main/AndroidManifest.xml | 2 +- .../openseizuredetector/SdDataSourceBLE.java | 24 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5ee9a9f..8d42d03 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,7 +2,7 @@ + android:versionName="4.2.4b"> diff --git a/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java b/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java index 093c949..61c61c0 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java @@ -368,17 +368,21 @@ public class SdDataSourceBLE extends SdDataSource { * @param gattCharacteristic - the characteristic to be read. */ private void executeReadCharacteristic(BluetoothGattCharacteristic gattCharacteristic) { - boolean retVal = mBluetoothGatt.readCharacteristic(gattCharacteristic); - if (retVal) { - Log.d(TAG, "executeReadCharacteristic - read initiated successfully"); + if (gattCharacteristic != null) { + boolean retVal = mBluetoothGatt.readCharacteristic(gattCharacteristic); + if (retVal) { + Log.d(TAG, "executeReadCharacteristic - read initiated successfully"); + } else { + Log.d(TAG, "executeReadCharacteristic - read initiation failed - waiting, then re-trying"); + mHandler.postDelayed(new Runnable() { + public void run() { + Log.w(TAG, "Executing delayed read of characteristic"); + executeReadCharacteristic(gattCharacteristic); + } + }, 100); + } } else { - Log.d(TAG, "executeReadCharacteristic - read initiation failed - waiting, then re-trying"); - mHandler.postDelayed(new Runnable() { - public void run() { - Log.w(TAG, "Executing delayed read of characteristic"); - executeReadCharacteristic(gattCharacteristic); - } - }, 100); + Log.i(TAG,"ExecuteReadCharacteristic() - gatCharacteristic is null, so not doing anything"); } }