Skip to content

Commit

Permalink
Merge pull request #571 from hannesa2/deprecation
Browse files Browse the repository at this point in the history
Remove deprecation
  • Loading branch information
hannesa2 authored Feb 23, 2024
2 parents 5131f6d + 1bb72ae commit 2206a44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.os.Build
import android.os.Bundle
import android.os.IBinder
import android.os.PowerManager
import info.mqtt.android.service.extension.parcelableExtra
import info.mqtt.android.service.room.MqMessageDatabase
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -237,7 +238,7 @@ class MqttService : Service(), MqttTraceHandler {
// run till explicitly stopped, restart when process restarted
registerBroadcastReceivers()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val foregroundServiceNotification = intent?.getParcelableExtra<Notification>(MQTT_FOREGROUND_SERVICE_NOTIFICATION)
val foregroundServiceNotification = intent?.parcelableExtra<Notification>(MQTT_FOREGROUND_SERVICE_NOTIFICATION)
if (foregroundServiceNotification != null) {
isForegroundStarted = true
startForeground(
Expand Down Expand Up @@ -328,6 +329,7 @@ class MqttService : Service(), MqttTraceHandler {
*/
private fun stopService() {
if (isForegroundStarted) {
@Suppress("DEPRECATION")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
stopForeground(Service.STOP_FOREGROUND_REMOVE)
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package info.mqtt.android.service.extension

import android.content.Intent
import android.os.Bundle
import java.io.Serializable
import android.os.Build
Expand All @@ -17,3 +18,9 @@ inline fun <reified T : Serializable> Bundle.serializable(key: String): T? = whe
SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getSerializable(key, T::class.java)
else -> getSerializable(key) as? T
}

@Suppress("DEPRECATION")
inline fun <reified T> Intent.parcelableExtra(key: String): T? = when {
SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getParcelableExtra(key, T::class.java)
else -> getParcelableExtra(key) as? T
}

0 comments on commit 2206a44

Please sign in to comment.