From fe5a96ba63259b3ef6a741e0ecee7a6ca6d4b549 Mon Sep 17 00:00:00 2001 From: Erdem Yerebasmaz <4012752+erdemyerebasmaz@users.noreply.github.com> Date: Thu, 4 Jan 2024 14:02:16 +0300 Subject: [PATCH] Disconnect Breez SDK on shutdown --- .../java/com/cBreez/client/BreezForegroundService.kt | 2 ++ .../main/java/com/cBreez/client/BreezSdkConnector.kt | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/android/app/src/main/java/com/cBreez/client/BreezForegroundService.kt b/android/app/src/main/java/com/cBreez/client/BreezForegroundService.kt index dc4df5288..c0bb2d35b 100644 --- a/android/app/src/main/java/com/cBreez/client/BreezForegroundService.kt +++ b/android/app/src/main/java/com/cBreez/client/BreezForegroundService.kt @@ -14,6 +14,7 @@ import com.cBreez.client.BreezNotificationHelper.Companion.notifyForegroundServi import com.cBreez.client.BreezNotificationHelper.Companion.notifyPaymentReceived import com.cBreez.client.BreezNotificationHelper.Companion.registerNotificationChannels import com.cBreez.client.BreezSdkConnector.Companion.connectSDK +import com.cBreez.client.BreezSdkConnector.Companion.disconnectSDK import com.cBreez.client.Constants.EXTRA_REMOTE_MESSAGE import com.cBreez.client.Constants.NOTIFICATION_ID_FOREGROUND_SERVICE import com.google.firebase.messaging.RemoteMessage @@ -96,6 +97,7 @@ class BreezForegroundService : Service() { private fun shutdown() { Logger.tag(TAG).debug { "Shutting down Breez foreground service" } stopForeground(STOP_FOREGROUND_REMOVE) + disconnectSDK() stopSelf() } diff --git a/android/app/src/main/java/com/cBreez/client/BreezSdkConnector.kt b/android/app/src/main/java/com/cBreez/client/BreezSdkConnector.kt index 4a7e70804..bbfffea9a 100644 --- a/android/app/src/main/java/com/cBreez/client/BreezSdkConnector.kt +++ b/android/app/src/main/java/com/cBreez/client/BreezSdkConnector.kt @@ -68,5 +68,15 @@ class BreezSdkConnector { val result: ByteArray = storageCipher.decrypt(data) return String(result, charset) } + + internal fun disconnectSDK() { + if(breezSDK != null){ + // Connect to the Breez SDK make it ready for use + Logger.tag(TAG).debug { "Disconnecting Breez SDK" } + breezSDK!!.disconnect() + Logger.tag(TAG).debug { "Disconnected from Breez SDK" } + breezSDK = null + } + } } } \ No newline at end of file