From 391a4e0b6dbb728fbd1459100825dcfec1b32d18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sylwester=20Zieli=C5=84ski?= <43586003+sylwester-zielinski@users.noreply.github.com> Date: Mon, 16 Oct 2023 15:41:41 +0200 Subject: [PATCH] Fix crashes observed on Firebase console (#130) * Switch getParcelableExtra to IntentCompat * Fix MissingForegroundServiceTypeException * Fix UART server * Move foreground service permissions to one place --- .../nrftoolbox/NrfToolboxApplication.kt | 2 + lib_service/src/main/AndroidManifest.xml | 4 +- .../android/service/NotificationService.kt | 7 - profile_cgms/src/main/AndroidManifest.xml | 11 +- .../android/cgms/repository/CGMService.kt | 3 +- profile_csc/src/main/AndroidManifest.xml | 8 +- .../android/csc/repository/CSCService.kt | 3 +- profile_hrs/src/main/AndroidManifest.xml | 8 +- .../android/hrs/service/HRSService.kt | 3 +- profile_hts/src/main/AndroidManifest.xml | 8 +- .../android/hts/repository/HTSService.kt | 3 +- profile_prx/src/main/AndroidManifest.xml | 8 +- .../android/prx/repository/PRXService.kt | 3 +- profile_rscs/src/main/AndroidManifest.xml | 8 +- .../android/rscs/repository/RSCSService.kt | 3 +- profile_uart/src/main/AndroidManifest.xml | 8 +- .../no/nordicsemi/android/uart/UartServer.kt | 158 ++---------------- .../android/uart/repository/UARTService.kt | 3 +- 18 files changed, 67 insertions(+), 184 deletions(-) diff --git a/app/src/debug/java/no/nordicsemi/android/nrftoolbox/NrfToolboxApplication.kt b/app/src/debug/java/no/nordicsemi/android/nrftoolbox/NrfToolboxApplication.kt index 24cfd5e9..3ab3b539 100644 --- a/app/src/debug/java/no/nordicsemi/android/nrftoolbox/NrfToolboxApplication.kt +++ b/app/src/debug/java/no/nordicsemi/android/nrftoolbox/NrfToolboxApplication.kt @@ -51,5 +51,7 @@ class NrfToolboxApplication : Application() { super.onCreate() analytics.logEvent(AppOpenEvent) + + uartServer.start(this) } } diff --git a/lib_service/src/main/AndroidManifest.xml b/lib_service/src/main/AndroidManifest.xml index 54555f08..3931a3c2 100644 --- a/lib_service/src/main/AndroidManifest.xml +++ b/lib_service/src/main/AndroidManifest.xml @@ -34,7 +34,9 @@ - + + + \ No newline at end of file diff --git a/lib_service/src/main/java/no/nordicsemi/android/service/NotificationService.kt b/lib_service/src/main/java/no/nordicsemi/android/service/NotificationService.kt index 4337189d..e4f203aa 100644 --- a/lib_service/src/main/java/no/nordicsemi/android/service/NotificationService.kt +++ b/lib_service/src/main/java/no/nordicsemi/android/service/NotificationService.kt @@ -37,8 +37,6 @@ import android.app.NotificationManager import android.app.PendingIntent import android.content.Intent import android.os.Build -import android.os.Build.VERSION.SDK_INT -import android.os.Parcelable import androidx.annotation.RequiresApi import androidx.core.app.NotificationCompat import androidx.core.content.ContextCompat @@ -135,11 +133,6 @@ abstract class NotificationService : LifecycleService() { nm.cancel(NOTIFICATION_ID) } - inline fun Intent.parcelable(key: String): T? = when { - SDK_INT >= 33 -> getParcelableExtra(key, T::class.java) - else -> @Suppress("DEPRECATION") getParcelableExtra(key) as? T - } - companion object { private const val NOTIFICATION_ID = 200 } diff --git a/profile_cgms/src/main/AndroidManifest.xml b/profile_cgms/src/main/AndroidManifest.xml index b1ff5f80..10b325bc 100644 --- a/profile_cgms/src/main/AndroidManifest.xml +++ b/profile_cgms/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - - - - + - \ No newline at end of file + diff --git a/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMService.kt b/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMService.kt index 23a4fdee..724527de 100644 --- a/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMService.kt +++ b/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMService.kt @@ -33,6 +33,7 @@ package no.nordicsemi.android.cgms.repository import android.annotation.SuppressLint import android.content.Intent +import androidx.core.content.IntentCompat import androidx.lifecycle.lifecycleScope import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.flow.catch @@ -107,7 +108,7 @@ internal class CGMService : NotificationService() { repository.setServiceRunning(true) - val device = intent!!.getParcelableExtra(DEVICE_DATA)!! + val device = IntentCompat.getParcelableExtra(intent!!, DEVICE_DATA, ServerDevice::class.java)!! startGattClient(device) diff --git a/profile_csc/src/main/AndroidManifest.xml b/profile_csc/src/main/AndroidManifest.xml index 31ce6f56..dfa65a53 100644 --- a/profile_csc/src/main/AndroidManifest.xml +++ b/profile_csc/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - -