Skip to content

Commit

Permalink
Fix crashes observed on Firebase console (#130)
Browse files Browse the repository at this point in the history
* Switch getParcelableExtra to IntentCompat

* Fix MissingForegroundServiceTypeException

* Fix UART server

* Move foreground service permissions to one place
  • Loading branch information
sylwester-zielinski committed Oct 16, 2023
1 parent 9c1ac06 commit 391a4e0
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@ class NrfToolboxApplication : Application() {
super.onCreate()

analytics.logEvent(AppOpenEvent)

uartServer.start(this)
}
}
4 changes: 3 additions & 1 deletion lib_service/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE" />

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -135,11 +133,6 @@ abstract class NotificationService : LifecycleService() {
nm.cancel(NOTIFICATION_ID)
}

inline fun <reified T : Parcelable> 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
}
Expand Down
11 changes: 6 additions & 5 deletions profile_cgms/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2022, Nordic Semiconductor
~ All rights reserved.
~
Expand Down Expand Up @@ -31,8 +30,10 @@
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<service android:name=".repository.CGMService" />
<service
android:name=".repository.CGMService"
android:exported="false"
android:foregroundServiceType="connectedDevice" />
</application>
</manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -107,7 +108,7 @@ internal class CGMService : NotificationService() {

repository.setServiceRunning(true)

val device = intent!!.getParcelableExtra<ServerDevice>(DEVICE_DATA)!!
val device = IntentCompat.getParcelableExtra(intent!!, DEVICE_DATA, ServerDevice::class.java)!!

startGattClient(device)

Expand Down
8 changes: 5 additions & 3 deletions profile_csc/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2022, Nordic Semiconductor
~ All rights reserved.
~
Expand Down Expand Up @@ -37,7 +36,10 @@
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

<application>
<service android:name=".repository.CSCService" />
<service
android:name=".repository.CSCService"
android:exported="false"
android:foregroundServiceType="connectedDevice" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ package no.nordicsemi.android.csc.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
Expand Down Expand Up @@ -73,7 +74,7 @@ internal class CSCService : NotificationService() {

repository.setServiceRunning(true)

val device = intent!!.getParcelableExtra<ServerDevice>(DEVICE_DATA)!!
val device = IntentCompat.getParcelableExtra(intent!!, DEVICE_DATA, ServerDevice::class.java)!!

startGattClient(device)

Expand Down
8 changes: 5 additions & 3 deletions profile_hrs/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2022, Nordic Semiconductor
~ All rights reserved.
~
Expand Down Expand Up @@ -33,7 +32,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<service android:name=".service.HRSService" />
<service
android:name=".service.HRSService"
android:exported="false"
android:foregroundServiceType="connectedDevice" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ package no.nordicsemi.android.hrs.service

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
Expand Down Expand Up @@ -75,7 +76,7 @@ internal class HRSService : NotificationService() {

repository.setServiceRunning(true)

val device = intent!!.getParcelableExtra<ServerDevice>(DEVICE_DATA)!!
val device = IntentCompat.getParcelableExtra(intent!!, DEVICE_DATA, ServerDevice::class.java)!!

startGattClient(device)

Expand Down
8 changes: 5 additions & 3 deletions profile_hts/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2022, Nordic Semiconductor
~ All rights reserved.
~
Expand Down Expand Up @@ -33,7 +32,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<service android:name=".repository.HTSService" />
<service
android:name=".repository.HTSService"
android:exported="false"
android:foregroundServiceType="connectedDevice" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ package no.nordicsemi.android.hts.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
Expand Down Expand Up @@ -73,7 +74,7 @@ internal class HTSService : NotificationService() {

repository.setServiceRunning(true)

val device = intent!!.getParcelableExtra<ServerDevice>(DEVICE_DATA)!!
val device = IntentCompat.getParcelableExtra(intent!!, DEVICE_DATA, ServerDevice::class.java)!!

startGattClient(device)

Expand Down
8 changes: 5 additions & 3 deletions profile_prx/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2022, Nordic Semiconductor
~ All rights reserved.
~
Expand Down Expand Up @@ -33,6 +32,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<service android:name=".repository.PRXService"/>
<service
android:name=".repository.PRXService"
android:exported="false"
android:foregroundServiceType="connectedDevice" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ package no.nordicsemi.android.prx.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
Expand Down Expand Up @@ -92,7 +93,7 @@ internal class PRXService : NotificationService() {

repository.setServiceRunning(true)

val device = intent!!.getParcelableExtra<ServerDevice>(DEVICE_DATA)!!
val device = IntentCompat.getParcelableExtra(intent!!, DEVICE_DATA, ServerDevice::class.java)!!

startServer(device)

Expand Down
8 changes: 5 additions & 3 deletions profile_rscs/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2022, Nordic Semiconductor
~ All rights reserved.
~
Expand Down Expand Up @@ -33,6 +32,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<service android:name=".repository.RSCSService"/>
<service
android:name=".repository.RSCSService"
android:exported="false"
android:foregroundServiceType="connectedDevice" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ package no.nordicsemi.android.rscs.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
Expand Down Expand Up @@ -73,7 +74,7 @@ internal class RSCSService : NotificationService() {

repository.setServiceRunning(true)

val device = intent!!.getParcelableExtra<ServerDevice>(DEVICE_DATA)!!
val device = IntentCompat.getParcelableExtra(intent!!, DEVICE_DATA, ServerDevice::class.java)!!

startGattClient(device)

Expand Down
8 changes: 5 additions & 3 deletions profile_uart/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2022, Nordic Semiconductor
~ All rights reserved.
~
Expand Down Expand Up @@ -33,7 +32,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<service android:name=".repository.UARTService" />
<service
android:name=".repository.UARTService"
android:exported="false"
android:foregroundServiceType="connectedDevice" />
</application>

</manifest>
Loading

0 comments on commit 391a4e0

Please sign in to comment.